Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753967AbdLHOoG (ORCPT ); Fri, 8 Dec 2017 09:44:06 -0500 Received: from mail-sn1nam01on0049.outbound.protection.outlook.com ([104.47.32.49]:39907 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753601AbdLHOoE (ORCPT ); Fri, 8 Dec 2017 09:44:04 -0500 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Thomas.Lendacky@amd.com; Subject: Re: [PATCH] x86/mm: Rewrite sme_populate_pgd() in a more sensible way To: "Kirill A. Shutemov" Cc: "Kirill A. Shutemov" , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org, Borislav Petkov , Brijesh Singh , linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20171204112323.47019-1-kirill.shutemov@linux.intel.com> <20171204145755.6xu2w6a6og56rq5v@node.shutemov.name> <20171204163445.qt5dqcrrkilnhowz@black.fi.intel.com> <20171204185027.gn6gu3b5vdq7lxx3@node.shutemov.name> From: Tom Lendacky Message-ID: <950a7099-54ac-8c47-a8c9-5b33067f9472@amd.com> Date: Fri, 8 Dec 2017 08:43:55 -0600 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: <20171204185027.gn6gu3b5vdq7lxx3@node.shutemov.name> 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: MWHPR2201CA0072.namprd22.prod.outlook.com (10.174.103.25) To DM5PR12MB1147.namprd12.prod.outlook.com (10.168.236.142) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 59f7ea89-feca-4742-dfdf-08d53e4a1fad X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(5600026)(4604075)(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(48565401081)(2017052603307);SRVR:DM5PR12MB1147; X-Microsoft-Exchange-Diagnostics: 1;DM5PR12MB1147;3:lbzEWG8UaLaZNxuMJ/TkoXVHNeIE0IsrCQirzFARU+1hVVR3EpUqGmCITCRJYj7QP2XDgcaJGCzXkPvXlwxopIN8XJiOH0qFn94q/XKX4r7wDpweePmdy46YWj15N04GW7SbQgaTa6nfidm3DL8RUzDXXIcTfzg2KlfdB4hFcbr74Rif3fUb9fsGOJXFA95NxXZxRoDu7xmdAoT82C6qmXP8F9a4pfhfbw6RewiOP6BKz6jAkAwlBd3u0hE4W5Lp;25:HvA3L86LWyE6ghgEv8HOh+T7huU511wVeVMaD1EcG082/fMwFth7QeDnXkHz8eTAFWld0Nf6Kt2YaOi6vSrwtoGhdlinx8G+EDNO3o2uWxQeyVPWUIw7Lr9AXuOxciXNC4U2S+vdB6jYojq6BN90bS7KUBbQELdJPWnBwKuyk2PkuC5pSrOa/qpzqeokzBl2nxB5lOn4D/1x0QWLihEKgnnhiHpjVIp1MOMe06c8we0HIJJS8JVkk4dUaP5vBQcSNHFk2BQ6yZGIkW9SvahLsxdut44XNSgvut/WRjTyHfxMx12IEwM+mD922fj+D6kah9GSnYztNX56CwEZ6YegjQ==;31:SBBh7Gi50EI5YNbQbSwABWSKP1AGyYHE/XAalU2VDD0o09rOMTr0xkmrEuKqr/KrPmz244commTubhrVWuuEkjmwbnyOXn5XR4mFum8Pmt9/ayXdAfO2srVTJAENfvJAWqajOqAJVCJaRDc8RcSxZeWmeTVNhYvjJnfwYIXM0hWefBNIgA9yZJ9cSMqagGcXprExOl918lmzOgLczh33CnKxRigteOr/7AJgO6iNi1M= X-MS-TrafficTypeDiagnostic: DM5PR12MB1147: X-Microsoft-Exchange-Diagnostics: 1;DM5PR12MB1147;20:QZe9ZlxcU6+fu4NO66pvQwJERkV/ka8UbeZ5UR2XCxr3GFAMYuIYf9QlcvA2cVmazHSuPbdcSkTmCCP2ACk7+4mfnN9g6lgjloeQNkxCyXARAxC4syoUXh8d3TLqfaz/MvKzKG+gMBkmdgYc9G4GiH8l/WrL0moVx0I8aAh1vzLoV3VF0expkmzD/M4463gQLKfm4eaQhpnv+yuh4dHDYV83P1B5jp7H7ZSOPbNBvluuGHGdXVpCSzucGe71FY0TxrgZOYjVUUMOFNo0LFnWdcXcbDr7hWfd1XgttI4Wemgv6ZpjZUi9rXO8qAqE0yM35MhT/YsD4wt6lIkpI1qdnBQy/x5btocszWUdkcpAEh1c302XQ5RgBiqLeWopa3v4jCC2YAso+pn6vAvLN7GrHxGQg2GCz0l7SG/cta1+/3VuVdXmSaZPNx3z4seWTqSwQXSWCWdv7VmjSc+xBxlySejC7PfMCkET6tJwif5LyWpR8SO9K3rvNR+FA8TCjjPy;4:2SVXGbvLy5tpnvu4rSbh3wwHUmIOE767qtvo1kJc8OoD4YcViKPatmjDQBq0KKLN3aguWwbDgMRpQRDN2EYFgqU/KjLqfmIzGsNEOyYI01dj4cwuy/jy5O8L1czqJDwaPYYUSYq97apBLbfvu8WOowewL/8cO32TGbYuQBgQJuSbVXnmBN5khd6V/rM+fCAcVPQLnIOGjAeNjonlLbGayA/yy69OG+dpfX54ggglKuOPty7rCfAMf2HBjP6khk/PV1YLehrduu+fzf/3gzw06A== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040450)(2401047)(8121501046)(5005006)(93006095)(93001095)(3002001)(3231022)(10201501046)(6055026)(6041248)(20161123564025)(20161123560025)(20161123562025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123558100)(20161123555025)(6072148)(201708071742011);SRVR:DM5PR12MB1147;BCL:0;PCL:0;RULEID:(100000803101)(100110400095);SRVR:DM5PR12MB1147; X-Forefront-PRVS: 0515208626 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(6049001)(39860400002)(346002)(376002)(366004)(24454002)(189003)(199004)(52314003)(68736007)(53936002)(31696002)(16576012)(478600001)(316002)(2906002)(86362001)(575784001)(64126003)(50466002)(93886005)(6486002)(229853002)(90366009)(77096006)(8676002)(72206003)(81156014)(81166006)(65806001)(65956001)(6116002)(3260700006)(25786009)(36756003)(6666003)(305945005)(3846002)(7736002)(76176011)(33646002)(6916009)(47776003)(2950100002)(67846002)(97736004)(53546010)(105586002)(8936002)(16526018)(6246003)(58126008)(5660300001)(54906003)(23676004)(66066001)(83506002)(106356001)(4326008)(31686004)(230700001)(52146003)(2486003)(65826007)(52116002);DIR:OUT;SFP:1101;SCL:1;SRVR:DM5PR12MB1147;H:[10.236.65.116];FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtETTVQUjEyTUIxMTQ3OzIzOjF3dlVNdUlNbFF3QW9BNVgxYmNjZnJtNWF5?= =?utf-8?B?SHk1S2RqSU9FbTJURWJoM0cvWnptenFCbnFnUlRNMXBMdm9ZZG5VMG4weGJY?= =?utf-8?B?bnhMQ3FSZzh5Ky9DTTlpRUJNc1lQSi8vQW95UUlKT0wzSFhKRXFod25OR1py?= =?utf-8?B?dHA3NTF0MFhtMHdLMkhxa3RycHM0RWxzZFpkRjMyVEhwc0pWbzF2RW1pL1BL?= =?utf-8?B?QTJmWFpNTmJqemRmbGhPdU5RS1l4cFhjNUFDL2plOGpiOU1QQmF5T1lFT1Jn?= =?utf-8?B?eXNKYUt6S3NuN0VDS0c5VFE4Q1F1T2JaeG5XZjJyS1lOQ0pxeG80aGU1cmZQ?= =?utf-8?B?aUgwU0FOMDdlSGtQRU4wd0kwYzVtSjZIb1FpRmlPblZiY29pZG5zSkRwNWdT?= =?utf-8?B?YlI1T1FlQys1NDhoY2RRV3VJeGRoOFE0TXdnL2taclFQbmtBSE9NWXl5bzFB?= =?utf-8?B?Q2p4c1RTaFJUQjBOQnBNNndVR0FGOUZvQm9McUNGankrMTd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1Bz0+X3DUGYhGwuKvCFphb0Urpn0/Rj+tT9Y/PKs=;5:fDnswT/PvK5JVr2FuEmg5se/FC/Uy9sNBCz7YoN6xt97e9PnNbLvGLeETlJZJGVjYz5oVMPUE2o4sRSGHDchSzpHkBamFfvsTUOcgRTLZyLN65QCKGVjuP5z8TSftRLDNa8sDbBEcoSTOLE1A6hFy9hf29W+Iecc1TKZIlgUgWM=;24:wBiws3uLCHXXUyn7OPyl8BKBBz0MaID5+PLdqpyTiKYTdLcfgipuBUyRgE+HJOejc6NDcoIOaihvwHjXgfsmvV9z4mb6zOYosUAFVO7wWbo=;7:qNQAieNIOPOjH9SYjIC8xKpiNRit1inc7x4bVYrmxGkRdiAv/BG4JWphnN5wyF5jDQxXM0iJkvUT26yIm/dTHWwj+kwrUp4jywvDjzPv0UhFhJUyv+O+t/xfoWrLT1WQeAfPtbUcBrbT9R5LZQ8ZRO9MIybddeBjjH1xOVpDSPfDBTGB96lZ5BsAnYMeg0zDb0B5lt3zTswSvsH7ZFlTVFoTO+5rPjI71PN5LLnfFLm1X3x5HS06msEqeSjlHQ5b SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;DM5PR12MB1147;20:s/OazlbYOdLlnSnJTtuPluIw1VlNOb5zIuzkCzSOwaFlkcisbKO9Nu7nGxryJXOWsfSOhtD38Bz26oykLeCN/pb6+hJM0ASnVDI4EjhPE8Y+jZNCITZQAMYE4wMensOIE/saFf8f1a/oh0Ffl9dk1yRZziodAL3ZCyUukwSjr2RUgRL+pTCeGm8yjGbrwh04LOEzlyVbfPwA6rGpPS/N17sdHES74lXVv+LUl2mE0mAVUshjgSfgWJK+8AWBBRMx X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Dec 2017 14:44:00.8095 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 59f7ea89-feca-4742-dfdf-08d53e4a1fad X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1147 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3082 Lines: 77 On 12/4/2017 12:50 PM, Kirill A. Shutemov wrote: > On Mon, Dec 04, 2017 at 12:33:01PM -0600, Tom Lendacky wrote: >> On 12/4/2017 10:34 AM, Kirill A. Shutemov wrote: >>> On Mon, Dec 04, 2017 at 04:00:26PM +0000, Tom Lendacky wrote: >>>> On 12/4/2017 8:57 AM, Kirill A. Shutemov wrote: >>>>> On Mon, Dec 04, 2017 at 08:19:11AM -0600, Tom Lendacky wrote: >>>>>> On 12/4/2017 5:23 AM, Kirill A. Shutemov wrote: >>>>>>> sme_populate_pgd() open-codes a lot of things that are not needed to be >>>>>>> open-coded. >>>>>>> >>>>>>> Let's rewrite it in a more stream-lined way. >>>>>>> >>>>>>> This would also buy us boot-time switching between support between >>>>>>> paging modes, when rest of the pieces will be upstream. >>>>>> >>>>>> Hi Kirill, >>>>>> >>>>>> Unfortunately, some of these can't be changed. The use of p4d_offset(), >>>>>> pud_offset(), etc., use non-identity mapped virtual addresses which cause >>>>>> failures at this point of the boot process. >>>>> >>>>> Wat? Virtual address is virtual address. p?d_offset() doesn't care about >>>>> what mapping you're using. >>>> >>>> Yes it does. For example, pmd_offset() issues a pud_page_addr() call, >>>> which does a __va() returning a non-identity mapped address (0xffff88...). >>>> Only identity mapped virtual addresses have been setup at this point, so >>>> the use of that virtual address panics the kernel. >>> >>> Stupid me. You are right. >>> >>> What about something like this: >>> >>> diff --git a/arch/x86/mm/mem_encrypt.c b/arch/x86/mm/mem_encrypt.c >>> index d9a9e9fc75dd..65e0d68f863f 100644 >>> --- a/arch/x86/mm/mem_encrypt.c >>> +++ b/arch/x86/mm/mem_encrypt.c >>> @@ -12,6 +12,23 @@ >>> #define DISABLE_BRANCH_PROFILING >>> +/* >>> + * Since we're dealing with identity mappings, physical and virtual >>> + * addresses are the same, so override these defines which are ultimately >>> + * used by the headers in misc.h. >>> + */ >>> +#define __pa(x) ((unsigned long)(x)) >>> +#define __va(x) ((void *)((unsigned long)(x))) >> >> No, you can't do this. There are routines in this file that are called >> after the kernel has switched to its standard virtual address map where >> this definition of __va() will likely cause a failure. > > Let's than split it up into separate compilation unit. > >>> +/* >>> + * Special hack: we have to be careful, because no indirections are >>> + * allowed here, and paravirt_ops is a kind of one. As it will only run in >>> + * baremetal anyway, we just keep it from happening. (This list needs to >>> + * be extended when new paravirt and debugging variants are added.) >>> + */ >>> +#undef CONFIG_PARAVIRT >>> +#undef CONFIG_PARAVIRT_SPINLOCKS >> >> I'd really, really like to avoid doing something like this. > > Any other proposals? > > Current code is way too hairy and hard to modify. I'd like to hear some other opinions, but if there are none, I don't see an issue with splitting this up, I guess. I just dislike doing some of these hacks, but if it makes things cleaner and simpler to understand, then I guess I can't really object. Thanks, Tom >