Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753487AbdHQSVy (ORCPT ); Thu, 17 Aug 2017 14:21:54 -0400 Received: from mail-dm3nam03on0078.outbound.protection.outlook.com ([104.47.41.78]:45760 "EHLO NAM03-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752820AbdHQSVv (ORCPT ); Thu, 17 Aug 2017 14:21:51 -0400 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Thomas.Lendacky@amd.com; Subject: Re: [RFC Part1 PATCH v3 07/17] x86/mm: Include SEV for encryption memory attribute changes To: David Laight , "'Borislav Petkov'" , Brijesh Singh Cc: "linux-efi@vger.kernel.org" , =?UTF-8?Q?Radim_Krcm=c3=a1r?= , "kvm@vger.kernel.org" , Fenghua Yu , Matt Fleming , David Howells , Paul Mackerras , "H . Peter Anvin" , Christoph Lameter , Jonathan Corbet , "x86@kernel.org" , Piotr Luc , Ingo Molnar , Dave Airlie , Laura Abbott , Kees Cook , Arnd Bergmann , Konrad Rzeszutek Wilk , Reza Arbab , Andy Lutomirski , Thomas Gleixner , Tony Luck , Ard Biesheuvel , "linux-kernel@vger.kernel.org" , Eric Biederman , Tejun Heo , Paolo Bonzini , Andrew Morton , "linuxppc-dev@lists.ozlabs.org" , "Kirill A . Shutemov" , Lu Baolu References: <20170724190757.11278-1-brijesh.singh@amd.com> <20170724190757.11278-8-brijesh.singh@amd.com> <20170727145841.GG28553@nazgul.tnic> <063D6719AE5E284EB5DD2968C1650D6DD0045508@AcuExch.aculab.com> From: Tom Lendacky Message-ID: <786b615a-941c-ae83-e02b-01ece58af5b3@amd.com> Date: Thu, 17 Aug 2017 13:21:39 -0500 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <063D6719AE5E284EB5DD2968C1650D6DD0045508@AcuExch.aculab.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [165.204.78.1] X-ClientProxiedBy: MWHPR1701CA0001.namprd17.prod.outlook.com (10.172.58.11) To CY4PR12MB1141.namprd12.prod.outlook.com (10.168.163.149) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 939b1c42-31c7-4803-5c87-08d4e59cd2a1 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254152)(48565401081)(300000503095)(300135400095)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095);SRVR:CY4PR12MB1141; X-Microsoft-Exchange-Diagnostics: 1;CY4PR12MB1141;3:Jxea9VUbaviT6of3iVpM2dlSNtm37RMHLQf5ROc+w+69hHAwjSrtelRCAyV/tXpX78LwJbE1FGQfsJM2jMifihmcnlGZs1KJsVU/aZf+H0DvJH9riYT8IEBgvafaaRQmRPg7H0LMCfuzN22hRaZwfE6/lJslClOEUXpIxbCI262vXCIO2AuumV/SFsH67PT0i+J09R3U51fQy0S1zECSxC4FjFd7PxzTWpVfzU5PYoOmPyIQYcTOqX2lKxtQeD23;25:j18tkmtbtjnnXsmZsleWvCw9o+jOCjrrD20LEvzaF6HxHGgACK2o+Ti5buhiE6WkelsybmXHrTqIV0eO1kmmsr9dCBweP8PJHQ+IPmnTyYQUREyHk+Qnhjdrc2ViEH8Q2ITnn0XjDqknotEC6ymFDeQnkYpJvsH6OEwPM1Gw2SDCaR4un+6P65hQzwi26ZVmI4mRrwEy1caDwUPXatISRYJbiljco1JVaKsbWFtIn7mbU9aB6Uj7b5m/YH8mOMd/AOzJlAeC7+bYJiATRO5cR/ZSwzm+h4aIK1rnNdlVbtbyUzUevapAoLwd5gWFkQ6oKENQRg4S8cn9aS8h1GndGQ==;31:wwTTgw2pEXWvGtYGgg8v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jKC9eSWvjbE4mdR8= X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(8121501046)(5005006)(10201501046)(100000703101)(100105400095)(93006095)(93001095)(3002001)(6055026)(6041248)(20161123558100)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123564025)(20161123555025)(20161123562025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:CY4PR12MB1141;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:CY4PR12MB1141; X-Forefront-PRVS: 0402872DA1 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(7370300001)(4630300001)(6049001)(6009001)(39860400002)(54094003)(189002)(199003)(24454002)(377454003)(23676002)(54356999)(6246003)(50986999)(76176999)(50466002)(54906002)(101416001)(189998001)(53936002)(65826007)(229853002)(7416002)(7406005)(5660300001)(33646002)(6666003)(6636002)(2950100002)(36756003)(47776003)(31686004)(68736007)(42186005)(106356001)(66066001)(90366009)(65806001)(6486002)(105586002)(65956001)(77096006)(72206003)(86362001)(2906002)(3260700006)(25786009)(31696002)(6116002)(3846002)(53546010)(93886005)(230700001)(81156014)(81166006)(8676002)(7350300001)(83506001)(305945005)(7736002)(4001350100001)(478600001)(4326008)(97736004)(64126003);DIR:OUT;SFP:1101;SCL:1;SRVR:CY4PR12MB1141;H:[10.236.64.250];FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtDWTRQUjEyTUIxMTQxOzIzOnNsOFVHMXBzNVVQa3lzMTR5UldVdC95OG1k?= =?utf-8?B?VlZKWWN0UWR6cHVaUGk4S1lNZTF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0fkxXHIaQ9NM3kZEFFSBtQln3+zKJfeKuYTa+D9HhMZ35VO1XkWON+FY3TQAtrecM9/lHK7i8bphaC/6ruRsCdXEwWoSkWlNlcr+6KZLIDVss/WU= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;CY4PR12MB1141;20:jSFaAWVvpjA+0F0OFC2daREz93PjW1J9L6ZeWJMmKDgpPV/qz/dsdLDNKhgG1UrH0PVKdVAep6LcQqSoKmGhqSpEwbNt5XJA83Lv7smsoM5WCdZAxE0TMOabNvCWYMxwyPLbSiEZPbQqgJu/bqpmmuEhakDLN3YsJScQN8L/vml15+QGpq3Oz0N+9qzaUU6fMRC7tOLsvqVF8RXzooy6qP4TVtWaRvNZabLNJP709hGJbrLNpTdqDqWtD0ChCD1g X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Aug 2017 18:21:44.1437 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1141 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1732 Lines: 53 On 7/28/2017 3:47 AM, David Laight wrote: > From: Borislav Petkov >> Sent: 27 July 2017 15:59 >> On Mon, Jul 24, 2017 at 02:07:47PM -0500, Brijesh Singh wrote: >>> From: Tom Lendacky >>> >>> The current code checks only for sme_active() when determining whether >>> to perform the encryption attribute change. Include sev_active() in this >>> check so that memory attribute changes can occur under SME and SEV. >>> >>> Signed-off-by: Tom Lendacky >>> Signed-off-by: Brijesh Singh >>> --- >>> arch/x86/mm/pageattr.c | 4 ++-- >>> 1 file changed, 2 insertions(+), 2 deletions(-) >>> >>> diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c >>> index dfb7d65..b726b23 100644 >>> --- a/arch/x86/mm/pageattr.c >>> +++ b/arch/x86/mm/pageattr.c >>> @@ -1781,8 +1781,8 @@ static int __set_memory_enc_dec(unsigned long addr, int numpages, bool enc) >>> unsigned long start; >>> int ret; >>> >>> - /* Nothing to do if the SME is not active */ >>> - if (!sme_active()) >>> + /* Nothing to do if SME and SEV are not active */ >>> + if (!sme_active() && !sev_active()) >> >> This is the second place which does >> >> if (!SME && !SEV) >> >> I wonder if, instead of sprinking those, we should have a >> >> if (mem_enc_active()) >> >> or so which unifies all those memory encryption logic tests and makes >> the code more straightforward for readers who don't have to pay >> attention to SME vs SEV ... > > If any of the code paths are 'hot' it would make sense to be checking > a single memory location. The function would check a single variable/memory location and making it an inline function would accomplish that. Thanks, Tom > > David >