lkml.org 
[lkml]   [2019]   [May]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH, RFC 39/62] keys/mktme: Find new PCONFIG targets during memory hotplug
    Date
    From: Alison Schofield <alison.schofield@intel.com>

    Introduce a helper function that detects a newly added PCONFIG
    target. This will be used in the MKTME memory hotplug notifier
    to determine if a new PCONFIG target has been added that needs
    to have its Key Table programmed.

    Signed-off-by: Alison Schofield <alison.schofield@intel.com>
    Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
    ---
    security/keys/mktme_keys.c | 39 ++++++++++++++++++++++++++++++++++++++
    1 file changed, 39 insertions(+)

    diff --git a/security/keys/mktme_keys.c b/security/keys/mktme_keys.c
    index 3dfc0647f1e5..2c975c48fe44 100644
    --- a/security/keys/mktme_keys.c
    +++ b/security/keys/mktme_keys.c
    @@ -543,6 +543,45 @@ static int mktme_cpu_teardown(unsigned int cpu)
    return ret;
    }

    +static int mktme_get_new_pconfig_target(void)
    +{
    + unsigned long *prev_map, *tmp_map;
    + int new_target; /* New PCONFIG target to program */
    +
    + /* Save the current mktme_target_map bitmap */
    + prev_map = bitmap_alloc(topology_max_packages(), GFP_KERNEL);
    + bitmap_copy(prev_map, mktme_target_map, sizeof(mktme_target_map));
    +
    + /* Update the global targets - includes mktme_target_map */
    + mktme_update_pconfig_targets();
    +
    + /* Nothing to do if the target bitmap is unchanged */
    + if (bitmap_equal(prev_map, mktme_target_map, sizeof(prev_map))) {
    + new_target = -1;
    + goto free_prev;
    + }
    +
    + /* Find the change in the target bitmap */
    + tmp_map = bitmap_alloc(topology_max_packages(), GFP_KERNEL);
    + bitmap_andnot(tmp_map, prev_map, mktme_target_map,
    + sizeof(prev_map));
    +
    + /* There should only be one new target */
    + if (bitmap_weight(tmp_map, sizeof(tmp_map)) != 1) {
    + pr_err("%s: expected %d new target, got %d\n", __func__, 1,
    + bitmap_weight(tmp_map, sizeof(tmp_map)));
    + new_target = -1;
    + goto free_tmp;
    + }
    + new_target = find_first_bit(tmp_map, sizeof(tmp_map));
    +
    +free_tmp:
    + bitmap_free(tmp_map);
    +free_prev:
    + bitmap_free(prev_map);
    + return new_target;
    +}
    +
    static int __init init_mktme(void)
    {
    int ret, cpuhp;
    --
    2.20.1
    \
     
     \ /
      Last update: 2019-05-08 16:46    [W:4.109 / U:0.160 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site