Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933723AbcKORI6 (ORCPT ); Tue, 15 Nov 2016 12:08:58 -0500 Received: from mail-bn3nam01on0058.outbound.protection.outlook.com ([104.47.33.58]:17600 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750998AbcKORIu (ORCPT ); Tue, 15 Nov 2016 12:08:50 -0500 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Thomas.Lendacky@amd.com; Subject: Re: [RFC PATCH v3 04/20] x86: Handle reduction in physical address size with SME To: Borislav Petkov References: <20161110003426.3280.2999.stgit@tlendack-t1.amdoffice.net> <20161110003513.3280.12104.stgit@tlendack-t1.amdoffice.net> <20161115121035.GD24857@8bytes.org> <20161115121456.f4slpk4i2jl3e2ke@pd.tnic> <20161115153338.a2cxmatnpqcgiaiy@pd.tnic> <20161115163350.jal7sd6ghbmk5sqc@pd.tnic> CC: Joerg Roedel , , , , , , , , , , Rik van Riel , =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , Arnd Bergmann , Jonathan Corbet , Matt Fleming , Konrad Rzeszutek Wilk , Paolo Bonzini , Larry Woodman , Ingo Molnar , Andy Lutomirski , "H. Peter Anvin" , Andrey Ryabinin , Alexander Potapenko , Thomas Gleixner , Dmitry Vyukov From: Tom Lendacky Message-ID: <92827ace-20c5-8549-e667-9fa2becaa1ff@amd.com> Date: Tue, 15 Nov 2016 11:08:37 -0600 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <20161115163350.jal7sd6ghbmk5sqc@pd.tnic> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN2PR17CA0035.namprd17.prod.outlook.com (10.169.188.173) To BN6PR12MB1138.namprd12.prod.outlook.com (10.168.226.140) X-Microsoft-Exchange-Diagnostics: 1;BN6PR12MB1138;2:jxSbf/UHLsgkS4XpvXQWaoXURNlbI+oNeiwmV8tJGYFE6J+1YAxulNg7gr6NZgFjZZSDk3TYIraCQon5FniV/2musP3j8wnoHV/sYXWmzdlIv31O68IulognRr2eDIu8mquIRwMcsFJCPAunjBImb6C9qjkyyh26Rm7vE2t/xR0=;3:+VN8pKGIKw5Har9ml4/5uOKK6qZQ5EwuMQWbQrSbew+d8s9kgfju/8ej+AWDU/qBlBL0BesRe2waQybWt+7S0R2TuNcJgQa0zTj//Fm1B/2lascuCommvRLI+6v6I/yLLa7L6vh5BNCeD+HUa7FlIrP0NYxTmd9lEz5r7Red3Pw=;25:1sJaUVKrhwTnRMOEHMaC5aD9JjBelHClcn/p/qAnq2LUTEmOt11944nTYIDNGFovqzE6FWcJbkUoaVx/yhNhpj2+u2QjlSivx5t0LkT2Bs1P1dWsCs6f1XD0q1YntZlqH/Pudqs7oOi2/em/gbevqkT0vlEHR3rJwC9JJfUF7pJoe9u9DHLYz1pg674Y6BbtMgj3zOAEY1RFTyIXOz70SohS4oMJF1t3zlq6uuTpBDaiTL/dBzc2uMV/K2sG16cvq0vzp4vwRDTMlVxqo8B6unMW7ljMcqEKt64nyQETJIb4cGBBiPG3WuJXcHkoJnnA5qMJBIT5YEj6F5eB9uYJkrbbFoDJ4oz7cq5qGCyntaJzAZEhgOwOaBwCQWCEHVpik4EGjK8prRuXgHiudGMbLVAf5CZmkx7dcfLPaZG1UuBzF6ZIjeu34fQbmwErcGiz X-MS-Office365-Filtering-Correlation-Id: 8d002b1b-1f07-4b91-c118-08d40d7a0e19 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:BN6PR12MB1138; X-Microsoft-Exchange-Diagnostics: 1;BN6PR12MB1138;31:YKy43UJAN38bW9iTwfdWfiT0o0d+xh5KANM0iQ1q74DhRLW+o3sjRhFMkLLcAyT48BtOQ/o+7M5S+xLAVXaRiQUJGt5ML20w6YTfmqbqc+jmp3dh7KDvskV1yNgBBv6qSJ96S1dWEPiXGe73ADNpXoeU5AJziLhk5/fIWM+Bq+rJ6ugiYML5fWWk5kJrASStDKjZ3W7Qp5vKy0i/GCTvATOsRVdvxkKy1VCJZm3oMuwG1sFKMAVGb3q5w6s1aGQ82UpeHhS9jCO8p8Ph+WsA/w==;20:mbrJMnNyagxULNNGCns5FkEOId2BbhQwjjea+eOOKjzonPjIti08qPQrT27j8bvh/ug49KKRllYwpi32rgJvVtgqjkkzoXEU4Qcm5AimTjM9W/HNALah0zlI6L7f0GE4Ma69yehaVcd0UThh/39Z40EOeVVN6SSFleCRxuumTICFnBOBslrsVFteuYXc1dUEQwzZysWUPROr/a0oMzx9BcjyXFp0HvaEV+iFCggFhzr2Ff1U4rKk4KBeR8RXuMJNy+3SnbkLB5es4zBFevXwEKGFj8Hv0tvYGtLQwWpSM5x4tj5v7MEczBiXL1DmfoEa6k8pPe6cGaEyb1+kRzbkPLtvDqdUyajugGbPUOY8iXoUKRU4R7b2Vbq7MuZdvzTXtX/E5fGVfkmmmRzyYz3xA0fyJ+/NCZEV3jdd96ynb4N1bH/xFdO6EQFxBbo1ZZvsfwChur5Xuq0aWFIL8hyPyclApfQ0q/wBtyb33cr8+LPxkYavF1pnRKnjziuAE4cP X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6060326)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6055026)(6061324);SRVR:BN6PR12MB1138;BCL:0;PCL:0;RULEID:;SRVR:BN6PR12MB1138; X-Microsoft-Exchange-Diagnostics: 1;BN6PR12MB1138;4:KjN1ZUqbJzcopTXDTSjmXHY85G3ajpq61Soi3cvHt24pLxFElqJlKQ4bh8uLutEOt0mo0v2pCFDlLe/qV1tYy9VYOhjZpbRM3J7JHub9h4EXyEpKdjYN9qaMo3tpN6QX19nxtJtUDg4FXm6uC59wQHf0CR+w4JMnOedbdYjt+mpR9VUT2x98lBNmNxWcrbPj3fCYIZPvKkgTMop2HZuycYpTD5wIux2gncy39LxLm76IN/V4QqdL4oGlWN9kMJV9I5kXXibiE3xUv23N65dwZhBVhxXUdnXtdTbVjQLlzaacMIx1pCAqqMknpRmUSeNGRTP068zxwpwJEA79/3VhTpdfD02meLnkKh1AEyAHN3gV8rvOJ+ERCsu/7fjSI5nlIlK4HhG/puXJ8cYQivBZKzJnBauJ0/9OFLAWRCDFAXJfS3XRYAYxTHlBtySKun/i X-Forefront-PRVS: 012792EC17 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4630300001)(6009001)(6049001)(7916002)(199003)(24454002)(377454003)(189002)(189998001)(3846002)(31686004)(42186005)(6116002)(64126003)(106356001)(65806001)(105586002)(66066001)(47776003)(77096005)(83506001)(230700001)(6666003)(68736007)(50466002)(93886004)(33646002)(65826007)(2950100002)(110136003)(6916009)(305945005)(5660300001)(65956001)(36756003)(31696002)(97736004)(229853002)(2906002)(4001350100001)(92566002)(101416001)(86362001)(7736002)(23676002)(81166006)(81156014)(7416002)(54356999)(50986999)(4326007)(8676002)(7846002)(76176999)(217873001);DIR:OUT;SFP:1101;SCL:1;SRVR:BN6PR12MB1138;H:[10.236.64.222];FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtCTjZQUjEyTUIxMTM4OzIzOiszWDdybXVJUTJwL09SbFVzMG9zNHZUaC9X?= =?utf-8?B?aldaakcrd3FvVWUza09KdXBCK3BwYXlQeE5mbUJsWisrT1hRRFI5aFNzb21w?= =?utf-8?B?SHpzMFZhU2I4eFpXNGU3cythY09HL0xRc1dENTA0MDUyd1hkTnV5cEsrTnBZ?= =?utf-8?B?dnUrSS83Wnk3UkNFQVpzRXZYZGg2aHdwTDh5aW8vdmg4VXNNcVRrUlNwQVJY?= =?utf-8?B?WDd1Rzdtbjlna2tvM0N6RVpqZS9COHJVe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NRrLEG2yeBxB5JFZek0PvTMH+Zz1U0g0hxwgpk X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Nov 2016 17:08:42.2768 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR12MB1138 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2210 Lines: 71 On 11/15/2016 10:33 AM, Borislav Petkov wrote: > On Tue, Nov 15, 2016 at 10:06:16AM -0600, Tom Lendacky wrote: >> Yes, but that doesn't relate to the physical address space reduction. >> >> Once the SYS_CFG MSR bit for SME is set, even if the encryption bit is >> never used, there is a physical reduction of the address space. So when >> checking whether to adjust the physical address bits I can't rely on the >> sme_me_mask, I have to look at the MSR. >> >> But when I'm looking to decide whether to encrypt or decrypt something, >> I use the sme_me_mask to decide if that is needed. If the sme_me_mask >> is not set then the encrypt/decrypt op shouldn't be performed. >> >> I might not be grasping the point you're trying to make... > > Ok, let me try to summarize how I see it. There are a couple of states: > > * CPUID bit in 0x8000001f - that's SME supported > > * Reduction of address space - MSR bit. That could be called "SME > BIOS-eenabled". > > * SME active. That's both of the above and is sme_me_mask != 0. > > Right? Correct. > > So you said previously "The feature may be present and enabled even if > it is not currently active." > > But then you say "active" below > >>> And in patch 12 you have: >>> >>> + /* >>> + * If memory encryption is active, the trampoline area will need to >>> + * be in un-encrypted memory in order to bring up other processors >>> + * successfully. >>> + */ >>> + sme_early_mem_dec(__pa(base), size); >>> + sme_set_mem_unenc(base, size); > > and test sme_me_mask. Which makes sense now after having explained which > hw setting controls what. > > So can we agree on the nomenclature for all the different SME states > first and use those throughout the code? And hold those states down in > Documentation/x86/amd-memory-encryption.txt so that it is perfectly > clear to people looking at the code. Yup, that sounds good. I'll update the documentation to clarify the various states/modes of SME. > > Also, if we need to check those states more than once, we should add > inline helpers: > > sme_supported() > sme_bios_enabled() > sme_active() > > How does that sound? Sounds good. Thanks, Tom >