From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg0-f70.google.com (mail-pg0-f70.google.com [74.125.83.70]) by kanga.kvack.org (Postfix) with ESMTP id 0533E2806D9 for ; Tue, 18 Apr 2017 17:22:21 -0400 (EDT) Received: by mail-pg0-f70.google.com with SMTP id r129so2953239pgr.18 for ; Tue, 18 Apr 2017 14:22:20 -0700 (PDT) Received: from NAM01-BN3-obe.outbound.protection.outlook.com (mail-bn3nam01on0040.outbound.protection.outlook.com. [104.47.33.40]) by mx.google.com with ESMTPS id d20si298228plj.104.2017.04.18.14.22.19 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 18 Apr 2017 14:22:20 -0700 (PDT) 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: owner-linux-mm@kvack.org List-ID: 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: Rik van Riel , Radim =?utf-8?b?S3LEjW3DocWZ?= , Toshimitsu Kani , Arnd Bergmann , Jonathan Corbet , Matt Fleming , "Michael S. Tsirkin" , Joerg Roedel , Konrad Rzeszutek Wilk , Paolo Bonzini , Larry Woodman , Brijesh Singh , Ingo Molnar , Borislav Petkov , Andy Lutomirski , "H. Peter Anvin" , Andrey Ryabinin , Alexander Potapenko , Dave Young , Thomas Gleixner , 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 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org