Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751409AbdH1Ltb (ORCPT ); Mon, 28 Aug 2017 07:49:31 -0400 Received: from mail-by2nam03on0089.outbound.protection.outlook.com ([104.47.42.89]:59936 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751146AbdH1Lt2 (ORCPT ); Mon, 28 Aug 2017 07:49:28 -0400 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; Cc: brijesh.singh@amd.com, linux-kernel@vger.kernel.org, x86@kernel.org, linux-efi@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org, Thomas Gleixner , Ingo Molnar , "H . Peter Anvin" , Andy Lutomirski , Tony Luck , Piotr Luc , Fenghua Yu , Lu Baolu , Reza Arbab , David Howells , Matt Fleming , "Kirill A . Shutemov" , Laura Abbott , Ard Biesheuvel , Andrew Morton , Eric Biederman , Benjamin Herrenschmidt , Paul Mackerras , Konrad Rzeszutek Wilk , Jonathan Corbet , Dave Airlie , Kees Cook , Paolo Bonzini , =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , Arnd Bergmann , Tejun Heo , Christoph Lameter Subject: Re: [RFC Part1 PATCH v3 15/17] x86: Add support for changing memory encryption attribute in early boot To: Borislav Petkov , Tom Lendacky References: <20170724190757.11278-1-brijesh.singh@amd.com> <20170724190757.11278-16-brijesh.singh@amd.com> <20170828105119.xs73tinknqcmrgvk@pd.tnic> From: Brijesh Singh Message-ID: <4b3cec09-ab6a-0400-00fe-328b36564942@amd.com> Date: Mon, 28 Aug 2017 06:49:19 -0500 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <20170828105119.xs73tinknqcmrgvk@pd.tnic> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-Language: en-US X-Originating-IP: [70.112.153.56] X-ClientProxiedBy: DM5PR04CA0044.namprd04.prod.outlook.com (10.171.152.158) To BY2PR12MB0145.namprd12.prod.outlook.com (10.162.82.18) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 086cdd94-8151-41b2-df34-08d4ee0ad452 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:BY2PR12MB0145; X-Microsoft-Exchange-Diagnostics: 1;BY2PR12MB0145;3:QkbR/7piUxNqctNQuLeL+ogQV/myrVMgLeP4dYRqOXoT2ktCvGLelm0k9O6DP6DX7Eli2pOYPgaIp9gFzBW/YsBZFfGzUHW19Fiawo4CDwgLzO23LERvGQcykDdNA5k2lNnt3gL8CUDLzowuWpWkQ1CXkA8nS5SuEfvIwFCBm1YxLa218yDXZak9RnK3X+AvGEE4BF4X0328JYLi1e93Iw2bBbXk9M37CfDJZ5wGTmF7vZbrYNAauItcmdshUWBx;25:JzQ97UrHIk8JBp6esO7kXIPcPMKE0AYf3ejgM1vev0LESrUOgwrvTJxI3UYDqSID1baUa5mkiUjptIqLTKtGspWCo6rC0sbABnQ1LQouXPC8R84rNfzyTUBT3dmqCVN2Zn4J8wqvS0q+6HsJOPAuf5NYHeYubb04L4zgdCgWobdKGEZQHq4uZYEfhrSfV3sVE0yk+zgyXfPhWYO7ner/Igaqw9QZgBhP0CZR13d1iGnpKghH+kmja7/3rMUcb4Qoiii7R17tTyLJ+yKJSXlEv6rDVQ9HEIZNO1kqX1lRaiCIH/7tsuUm9a1klxEst1HSTD+MP/hzX8T+nECzCeBYEw==;31:JvFhg84bgABejep4WlZWLisyVELdbsPcPt5067O1kO0iXjz1vq+bz357PWkhvexoG3bBSHHvVCCbv5HQrahToeYQqICcGqKbhPH946Af3vPrEtBIOTdXJJcYvhFIMjKup/xMVWNMD1E92dD9kCdLIwRHz/hR7H9K8Uhp8Bit/obJf307wM2B6cTiq7wlhGnezJJR6JL0iy1dycJqi9yen6yVBH+znrNxnSrdq11tkKA= X-MS-TrafficTypeDiagnostic: BY2PR12MB0145: X-Microsoft-Exchange-Diagnostics: 1;BY2PR12MB0145;20:m+H+/3/AwooWpntIhmvsqTzaDei7Dam7RM2ag/5UvVBw8CvafpSxlXSe7THurSM8wLAWEd8m/QQ6/rT+xpkbhMt0759ZJONKxIWEiZLhTx+CVWeh9mFDmUJqiwi76ZXQU5JeFFZe4UGNaLiR4BaAODyYdd7i3bYkxusZk9jHn2b3LDKRsyO5J8ZgZYrUTRzV0rpVHIOHXaNz/jT9A1v28ze1K9GxCqMUVZIfeerhtpF50Shuusp1w0QUTHejW8kT4Nu9Q0d2pagfLLqwFx8LoOUaJ/7RWiQsddmV5pcnto7dIRyDmCbt8d+HVZN8NaM/HAEWKa7t/N58KvYUfq027ALZyOmMYtB+0EANOaP0drNinxAdPm3bxuo+Pf1vIYl75igVebYVJ4H1pWULDx4CNVcC5GCx+ccgZRxWvIObz1X2mEuD0xyDwBditZokvMZ3ummzWZgofl66FV94ohuW1xRWAAzcVNdHAtCqojyyrQbEwP3gdwoLq6HpUy1Z6YBp;4:5WGLoYvbGixf2xmRpTQgieLYgR85YWh5tUAzpDGRo4ZKBvyDJMfDgreuQXTOM58pmZd86obxTt+RnIVnuAIX+ChuDfKrvgLBjm6izIyC/PQnuzRKBeM8NdVy77zyYf9fH8rfn6uHoeELZmigj5upPgo26CgA6HqfK41CmXLfn5s/iI/jkGt+SRDYYsmVmX7glsNnLWzLmA/rQIFxSYJwIfPrcNricSVFisSo97/+HYp7LzOcNIZ9CpWTF3dgYVEr X-Exchange-Antispam-Report-Test: UriScan:; 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)(3002001)(100000703101)(100105400095)(93006095)(93001095)(6055026)(6041248)(20161123562025)(20161123558100)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123564025)(20161123555025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:BY2PR12MB0145;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:BY2PR12MB0145; X-Forefront-PRVS: 0413C9F1ED X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(7370300001)(4630300001)(6009001)(39860400002)(199003)(189002)(377454003)(24454002)(66066001)(64126003)(86362001)(6246003)(65826007)(7406005)(54356999)(53936002)(50466002)(42186005)(7350300001)(54906002)(5660300001)(4001350100001)(50986999)(97736004)(76176999)(6636002)(6116002)(189998001)(3846002)(23676002)(31696002)(230700001)(36756003)(2906002)(6512007)(305945005)(106356001)(81166006)(68736007)(6486002)(101416001)(229853002)(7416002)(33646002)(7736002)(2950100002)(81156014)(25786009)(53546010)(4326008)(47776003)(105586002)(65956001)(478600001)(6506006)(8676002)(65806001)(83506001)(31686004);DIR:OUT;SFP:1101;SCL:1;SRVR:BY2PR12MB0145;H:Brijeshs-MacBook-Pro.local;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtCWTJQUjEyTUIwMTQ1OzIzOlR4c1NJNVFrc0NFdmtnelk3a1lGMVFmWEM4?= =?utf-8?B?d21za1ZvYk02S1VCWkp0d2tzL1hnTUZpZE9qVzlSeEFYSHJEanhvbzRDdzJF?= =?utf-8?B?WkVzRTh6YzhEeGJXNytLNTlVdVF2Z1g5VVhwZGNHNGsxSGFTRFp0MzM2YTN6?= =?utf-8?B?WVJkK0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o7F6jJVtj6lFUwF0yFBhxJhw8DjDmi7JPA0MtoN2P2nJEeknZidbpJb9PU6z X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Aug 2017 11:49:21.2710 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR12MB0145 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1058 Lines: 44 Hi Boris, On 8/28/17 5:51 AM, Borislav Petkov wrote: [..] > +static int __init early_set_memory_enc_dec(resource_size_t paddr, >> + unsigned long size, bool enc) >> +{ >> + unsigned long vaddr, vaddr_end, vaddr_next; >> + unsigned long psize, pmask; >> + int split_page_size_mask; >> + pte_t *kpte; >> + int level; >> + >> + vaddr = (unsigned long)__va(paddr); >> + vaddr_next = vaddr; >> + vaddr_end = vaddr + size; >> + >> + /* >> + * We are going to change the physical page attribute from C=1 to C=0 >> + * or vice versa. Flush the caches to ensure that data is written into >> + * memory with correct C-bit before we change attribute. >> + */ >> + clflush_cache_range(__va(paddr), size); >> + >> + for (; vaddr < vaddr_end; vaddr = vaddr_next) { >> + kpte = lookup_address(vaddr, &level); >> + if (!kpte || pte_none(*kpte)) >> + return 1; > Return before flushing TLBs? Perhaps you mean > > ret = 1; > goto out; > > here and out does > > __flush_tlb_all(); > return ret; thanks, good catch. I will fix in next rev. -Brijesh