From patchwork Tue Apr 18 21:22:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Lendacky X-Patchwork-Id: 9686407 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E40EF602C2 for ; Tue, 18 Apr 2017 21:22:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D3DAF28354 for ; Tue, 18 Apr 2017 21:22:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C60692094F; Tue, 18 Apr 2017 21:22:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 38B3D2094F for ; Tue, 18 Apr 2017 21:22:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932951AbdDRVWb (ORCPT ); Tue, 18 Apr 2017 17:22:31 -0400 Received: from mail-co1nam03on0060.outbound.protection.outlook.com ([104.47.40.60]:61408 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1757967AbdDRVWU (ORCPT ); Tue, 18 Apr 2017 17:22:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=7RsOHrl6UT6OPaiMBQVn3Dlhmmc6PBCLcV759yWmq5c=; b=H5vwzwGib3EXl8VZmWplBsS5Z+CVejTBQ+hDc9SWqEVBZr5k08EgCv6kSpwI+QIvd+AxCvvNJrxhBCceTRhiOVB+Ht1zdfVUvA9x5fhdHrb5FPCzM6vtDf2nVP/H3xz65zsAp013wjtdprwbGWPj49RzpvumdzAwucxZi6Bi/bA= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=none action=none header.from=amd.com; Received: from tlendack-t1.amdoffice.net (165.204.77.1) by CY4PR12MB1141.namprd12.prod.outlook.com (10.168.163.149) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1034.10; Tue, 18 Apr 2017 21:22:15 +0000 From: Tom Lendacky Subject: [PATCH v5 31/32] x86: Add sysfs support for Secure Memory Encryption To: , , , , , , , , , 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 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> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: BN6PR03CA0045.namprd03.prod.outlook.com (10.175.124.31) To CY4PR12MB1141.namprd12.prod.outlook.com (10.168.163.149) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 903d3f7a-154a-4bc1-8ce7-08d486a0fe6d X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081)(201703131423075)(201703031133081); SRVR:CY4PR12MB1141; X-Microsoft-Exchange-Diagnostics: 1; CY4PR12MB1141; 3:wfhyc2kInh3mIFX4ZSyrmFz+kV6kUbHJMIkDEO/5UzdUjiAqasa1Tj5Z2OGdTIDWK+cCCtskz9LPQQqC2Cvc+klx8IRSnB5k3XwwMeUMcYkp2hzLAzcjQXo7Lh2I2pZCRGb5j0PYuMHHFcXPWqtuyufyYECJdOSSDT1RNQb9WqTUZd/6mIOTIDt3ddsy1+AX/WPofPYNEBxwiJVPAnxGfOlqwAo4fCD6hQ6vpOuNe83T9uJOSBjaHaOqrMLa73UKJ2SLhNm3tuVBa8WTwvLgo7GRztUUmWOK7W0+hkulwruHqe6OtVu0/rJh+fp0GT5hj6MBdBMPM8ffMXOyciIe6siJeeQN3ptmjks+JrCYAAs=; 25:34uRQyjBChs53jcf17mnQ8K7S4zZjEHqt0lESm384LISPxj3yb2dG2SnMF31Zvtn0cpeLLtXgRWSC6tY0nS19OHn/uqn+tCihy+dVU3cbjlthfRhW52FU6VlUC4UMW+WXeyuduKYpPTYqtttJuaL5ZJUAF+mO1ZrjSUlgAuznXyi8wq6vI3rkYI6+ATGV5ybhOpB3W2yZF4srPis9saa8mWdzu4IsoF09xPmj7iw9vAUpY8KHxlNAuVO3OIlujoVYocPJ4Z7FN4uekpmWywvpo7FUKBuTn7H3sW3TNCz3AUlW+IjqchZ0wVynhxeSrNbOakW70wUoo/IuVWucVFWXGz3FZRKP4eb4ssqTY8p2O3eI2/4VokefLvp5/CvHc95clbMxGAujhwc/FzziTY8HlU3I8xBb0lOzUXNsOJ7PgQmNdGlLEy094SeXqRoFjndqSolXDwJRoEB6ZFNiRSOxQ== X-Microsoft-Exchange-Diagnostics: 1; CY4PR12MB1141; 31:F37ha0j1HcQY+XgnzclDKo3h//2amGbL0SIhI0CRioLVdEtOiHdOEaE2SS+3tK9wsxXb7jFNFQSzNFbdheIWhZKXMQ2/UrmkbPojFQ3t8AcTmeYqQmTYQOnDDJKi4i55AqSy+v0tvN2NKbEF9bqHGZjYGYZaBFB3ynTX80hY6qSXV5bV5I4ZZsUrjQ20FKJKpjZdWQ4MwF5FlT00PvAoSOhbLXJuvaF+n+ayL5gUc0SYV4eYbnn3eWNWc2oy7yWj; 20:WB+Wq+TNBQrkkM/YrFzOrVXeMO23VCEU9ncYVn8Yuybr9x5nboZHyDBhExcyvtDSr1/+WKORkAtAaVYKdHC4gxtSF/tmYaJ7LnY9/3dx9YQg5jVxfjU+3OguXtL5H1axi3/Wx32v8cXcyVx3GZTBRZ9Q1lsoPlJETKp3oWb2HdG9v6KANqTPQV+mZFScXtcQlDnO0o6s5RNWSqGlaWWe6N//aIXw/a9NjQgcQ0dXxij83djD7l2JkW4wMy88Yce/CUPpHnc9szdGxK0dQ8TUppOloBZcUvg3gERh+Y/3slQ9ui39zcMtNP0CnJCpIZzjNer0BPHFqqafemrGI6krG6WDXogPFVJbanyGGL0nrYXAvdiqOf+kV31LW+7Lg68Ium1Qlhv6a44kYu4JC+u+QP3Q2uehjkoFllPcLTMOv63vpQD1MSrIhlPa9W5ZCzAudbLLfX5ZnceqzFm19h5KDAWKCbVKFkqpdUcx3S8YS11wzb+7Rb1/IvhzpuY6nN9A X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040450)(601004)(2401047)(8121501046)(5005006)(10201501046)(93006095)(93001095)(3002001)(6055026)(6041248)(20161123562025)(20161123564025)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(20161123555025)(6072148); SRVR:CY4PR12MB1141; BCL:0; PCL:0; RULEID:; SRVR:CY4PR12MB1141; X-Microsoft-Exchange-Diagnostics: 1; CY4PR12MB1141; 4:pPC1+Kax1mB/p6lJiORNoxC0A6fQHmHeIkhkIQUf99l7gaoRjO/6dDoqIPBgmVamTKlH6kfbxKCTvzyloyYYJV8kgN0poOESR2YeKTNGOWtIleyi3fyIjgAomqcXYHiGuc276yCe4plutl4a1ZSKLB0/NOe2tKLVWwjJ1IsNfTQvgx3z7VTFmTKww/u6r04bBDciBtY6Z3erm0V9GDVgMVB+dlyMOozOHGGERF48y7TvgPjn+VWWLScvoB7gDPPe5UAfzhA7GeJNBg5QfO4aMTMeRupuBaMsyuCqJqW4R2XbyazgLYKeNjbswlntn6p4VuBot2s0X+ZvWQmB4F5p0DzLhSu2dSHCK1QfkfBtdVWqZJlPxhDEOsnB2BgLatYY8n/P6nI6RrRbwMcBhwKm6uDaZ21o9fMWDETWe8eq55Krf3yOK96NeRyAX8cVLPBZsk4R12xyhk/NSmd3PonEzYWI7S9VcIY4N0QTl/T2Yr6bFm3YgbOZ43Fgx/xCGXqehviynfp83S3P5zBifVNZ59S37yJiJmb7B3tMafj4Ln5noFpR7OUdRxcJXKyrpRNFXRty7enmittd99PEGY2Dovg1ZYMB6/E14bn6BAzWhktQrFpoHQ7D+sDRPPj5+SCx+qRlY9EOiSkwUMOKdN9YiP4+kC/aakNxqouUDp0sibwx5g8VPc9b6LknyPUQzZ0Fh1iOwJdp65eiLnG9snqRFdQnJMacyzbBfqX4MxemDoh4wOIBZL9YFrb3Q9UANFVejTo+8gratP3VNRe/4sQDug== X-Forefront-PRVS: 028166BF91 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(39450400003)(39860400002)(39850400002)(39840400002)(39400400002)(39410400002)(42186005)(3846002)(305945005)(25786009)(7406005)(50466002)(7736002)(38730400002)(2906002)(4001350100001)(230700001)(53416004)(86362001)(2950100002)(5660300001)(103116003)(23676002)(6116002)(7416002)(2201001)(33646002)(1076002)(50986999)(54356999)(81166006)(6666003)(55016002)(76176999)(97746001)(83506001)(66066001)(189998001)(9686003)(4326008)(6506006)(47776003)(53936002)(54906002)(8676002)(921003)(71626007)(1121003); DIR:OUT; SFP:1101; SCL:1; SRVR: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XYHWFK0N3fw0gwsCkE3eyH9TF7sZCp6SmPzH7ljqawqG9atduqtqvVb7MmS/m62Boc6Zy1HDYDu/dIKR/XzDrLSE9lROT/M9b7+BegC7QVPQusFu6BbDfoe9f818/NignYYV0radUnO4nwDwvkbyrXwh8f1pOr38Rdn8KxyzBpYiE0ogGvTPEDRBbLGwTI3oSHrxeoAi+e/czfIIG0HqvhtLo8obc504xvMsJDEOH+L43Hl6DVcWpAY0U5q33GZiHqkAXEdWtlibgZkIDXL0LuJbnx0NzGwiDiYmJwcK9e+c6njaYxrbuG4x2300MO1koxfIfAeg1SYDnLbAHnIr9Bwq0DhGnquCVkKcbamew5MYHaonqd9Putrh7ESDueyeyiKEekRxMAm/EX5PSp7wCI97ay3pu35bfSoj7+4rwB0XROuzYF7JAdehQBil0JGjTHWsSvniOkqArsujb9DcSZJyzyyMsI4Zv5nZJltQ=; 5:SqgHzvXKDcre4VPRG1EGhAYzfqazeiwPp4f2nejmGLDdUuEc+ltP0y+M73pzslV/WW7atuwy6BVRbWshbOL9hJIcsExLXe/U7IGEf9Cq/eWeiQEOStx1bLATmqa7LlqbneqcmIxfMRSInUGfiWp3Zw==; 24:Qyjg4Yl5LI/N7egMP3A4YaONB73h36NFAWXCBn19WB/4gcoQVEc84V2+T4j6fNsswaaAPKuz30c91i1FdapaPQkdlMcIqjohpJqT9HfpT8s= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; CY4PR12MB1141; 7:5Jk9sKxKlcqPHh/3P0YGfZhpfWjiCU7LsXWVaKQ93SQ2oCPy5rLa52+XSmK7MIcBgOL6Sl7ftczt7uxdbt7ENq8sm0FifW88+GdwVIrBmjLwXiJDSwSfnPbHniHOVDqAsl/YPQ3durcp85BfqBneo+OFqOJKqm3TZOTrqd+Zwyqzy4VYvLxagxch7tJLAXd2jMgvKXIzOa1iiI7JvuV8a9ifZOTX10fhRGy/513MD+qjznGypd0zg5jf832rR2qhvCa7rthIEa2fGjVAfcI4ExeY3/qulUpQfPnlvOaRkPoz4ePkRz36kuxK9kZwyPuaJdt3lDh+8gosxaVcyONmwA==; 20:ihHoO5krHDLezkD+24rqWOnWLcGVlLSNrDUirstUb7ZRM46tOAL04wUyCkm4+WUOBBgNROfayXRfkX3s9/PiiBSwf52Snf69vAeyAu3KYfl8n56AZcf3JA+VoCqcg1jJKXrS3XLMeNoFNoAmjkXxn4lRZ0gKrj3P+3tyhj/zdYWNWLVXAUBz26W1wKKd2yVqiUlprd+udd/RmgpvZvXytZlb43hxUcKN1WHjqQUhQ0H++vrKlNbRNgd4DVA/WNI0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Apr 2017 21:22:15.7469 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1141 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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