[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20190508144422.13171-40-kirill.shutemov@linux.intel.com>
Date: Wed, 8 May 2019 17:43:59 +0300
From: "Kirill A. Shutemov" <kirill.shutemov@...ux.intel.com>
To: Andrew Morton <akpm@...ux-foundation.org>, x86@...nel.org,
Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>,
"H. Peter Anvin" <hpa@...or.com>, Borislav Petkov <bp@...en8.de>,
Peter Zijlstra <peterz@...radead.org>,
Andy Lutomirski <luto@...capital.net>,
David Howells <dhowells@...hat.com>
Cc: Kees Cook <keescook@...omium.org>,
Dave Hansen <dave.hansen@...el.com>,
Kai Huang <kai.huang@...ux.intel.com>,
Jacob Pan <jacob.jun.pan@...ux.intel.com>,
Alison Schofield <alison.schofield@...el.com>,
linux-mm@...ck.org, kvm@...r.kernel.org, keyrings@...r.kernel.org,
linux-kernel@...r.kernel.org,
"Kirill A . Shutemov" <kirill.shutemov@...ux.intel.com>
Subject: [PATCH, RFC 39/62] keys/mktme: Find new PCONFIG targets during memory hotplug
From: Alison Schofield <alison.schofield@...el.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@...el.com>
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@...ux.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
Powered by blists - more mailing lists