From mboxrd@z Thu Jan 1 00:00:00 1970 Return-path: Received: from mail-co1nam03on0044.outbound.protection.outlook.com ([104.47.40.44] helo=NAM03-CO1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1d0aa7-0004Kl-Uo for kexec@lists.infradead.org; Tue, 18 Apr 2017 21:22:41 +0000 From: Tom Lendacky Subject: [PATCH v5 31/32] x86: Add sysfs support for Secure Memory Encryption Date: Tue, 18 Apr 2017 16:22:12 -0500 Message-ID: <20170418212212.10190.73484.stgit@tlendack-t1.amdoffice.net> In-Reply-To: <20170418211612.10190.82788.stgit@tlendack-t1.amdoffice.net> References: <20170418211612.10190.82788.stgit@tlendack-t1.amdoffice.net> MIME-Version: 1.0 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "kexec" Errors-To: kexec-bounces+dwmw2=infradead.org@lists.infradead.org To: linux-arch@vger.kernel.org, linux-efi@vger.kernel.org, kvm@vger.kernel.org, linux-doc@vger.kernel.org, x86@kernel.org, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-mm@kvack.org, iommu@lists.linux-foundation.org Cc: Thomas Gleixner , Rik van Riel , Brijesh Singh , Toshimitsu Kani , Arnd Bergmann , Jonathan Corbet , Matt Fleming , Joerg Roedel , Radim =?utf-8?b?S3LEjW3DocWZ?= , Konrad Rzeszutek Wilk , Andrey Ryabinin , Ingo Molnar , "Michael S. Tsirkin" , Andy Lutomirski , "H. Peter Anvin" , Borislav Petkov , Paolo Bonzini , Alexander Potapenko , Dave Young , Larry Woodman , Dmitry Vyukov Add sysfs support for SME so that user-space utilities (kdump, etc.) can determine if SME is active. A new directory will be created: /sys/kernel/mm/sme/ And two entries within the new directory: /sys/kernel/mm/sme/active /sys/kernel/mm/sme/encryption_mask Signed-off-by: Tom Lendacky --- arch/x86/mm/mem_encrypt.c | 49 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/arch/x86/mm/mem_encrypt.c b/arch/x86/mm/mem_encrypt.c index 0ff41a4..7dc4e98 100644 --- a/arch/x86/mm/mem_encrypt.c +++ b/arch/x86/mm/mem_encrypt.c @@ -18,6 +18,8 @@ #include #include #include +#include +#include #include #include @@ -25,6 +27,7 @@ #include #include #include +#include /* * Since SME related variables are set early in the boot process they must @@ -38,6 +41,52 @@ static char sme_early_buffer[PAGE_SIZE] __aligned(PAGE_SIZE); /* + * Sysfs support for SME. + * Create an sme directory under /sys/kernel/mm + * Create two sme entries under /sys/kernel/mm/sme: + * active - returns 0 if not active, 1 if active + * encryption_mask - returns the encryption mask in use + */ +static ssize_t active_show(struct kobject *kobj, struct kobj_attribute *attr, + char *buf) +{ + return sprintf(buf, "%u\n", sme_active()); +} +static struct kobj_attribute active_attr = __ATTR_RO(active); + +static ssize_t encryption_mask_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + return sprintf(buf, "0x%016lx\n", sme_me_mask); +} +static struct kobj_attribute encryption_mask_attr = __ATTR_RO(encryption_mask); + +static struct attribute *sme_attrs[] = { + &active_attr.attr, + &encryption_mask_attr.attr, + NULL +}; + +static struct attribute_group sme_attr_group = { + .attrs = sme_attrs, + .name = "sme", +}; + +static int __init sme_sysfs_init(void) +{ + int ret; + + ret = sysfs_create_group(mm_kobj, &sme_attr_group); + if (ret) { + pr_err("SME sysfs initialization failed\n"); + return ret; + } + + return 0; +} +subsys_initcall(sme_sysfs_init); + +/* * This routine does not change the underlying encryption setting of the * page(s) that map this memory. It assumes that eventually the memory is * meant to be accessed as either encrypted or decrypted but the contents _______________________________________________ kexec mailing list kexec@lists.infradead.org http://lists.infradead.org/mailman/listinfo/kexec