Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752609AbdLDSdI (ORCPT ); Mon, 4 Dec 2017 13:33:08 -0500 Received: from mail-bl2nam02on0049.outbound.protection.outlook.com ([104.47.38.49]:32496 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751208AbdLDSdG (ORCPT ); Mon, 4 Dec 2017 13:33:06 -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> From: Tom Lendacky Message-ID: Date: Mon, 4 Dec 2017 12:33:01 -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: <20171204163445.qt5dqcrrkilnhowz@black.fi.intel.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: DM5PR21CA0067.namprd21.prod.outlook.com (10.175.112.157) To CY4PR12MB1141.namprd12.prod.outlook.com (10.168.163.149) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: ebd9d0c2-16b1-47ea-30f7-08d53b45754f X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(48565401081)(5600026)(4604075)(2017052603286);SRVR:CY4PR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PZRreBVJzLx5HNfmlXTQ1PiBLV/1n7O4pV0o64NvkWljjJXUCKXfBmfqi+E+E198MWX98y2nulYDPRjH71DtZCqBIiNmryIAFnFt4AhlR7P/ruidAozVhnsjkoUDHDt9WAn4w8q94btmXawCzeriy9Z+OhLic2gZraaVa8L6rgPNuaMz9usTCwmK8zxzHNR3U4e9RuF0AlkFH9bNwGqRFFvwUb+DnDv/NJf45CPkzE27yjCprDUsoO3WWFtQPJl83Vs9I3+QwxW/+yfDTvb4gLBFfFAEdcmSVJ7uhWObqiNK6FC4HDx4FCINf4WedVp6UoIyM2X5wXVo2jkAbg3YMTKKYYVczdVvDb61EHjBJsKzwsoDc8cD5RSxLOA2yI1NFEaKbKJFOj8i+cg;4:8HCAYqnZ68PGwq5TPs7hatkMXXM6ZQD2/FtErOJBj7FUMmxXMHEA3+z3uzKKTOaBF331lYDFjlc0ZiwbOk7sAvNorWQzVmZ5zvuQ1StQSL3t5ItZw2YITKiidGUAJLnaAvmnyykW7iOn/X+LTTqFLlTk0WwBnDOWlKCG17T93sjHMFtCv8bFOavv9iFz2pxJSZC/NxyEGrnv5a117AZycoKWBDTBA/VCaINHBYhJmXotvm77Us9u/FhMEwB1Gf81N2sTCAiYv37RyvPE8LcRaA== 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)(3002001)(3231022)(10201501046)(93006095)(93001095)(6055026)(6041248)(20161123560025)(20161123558100)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123562025)(20161123564025)(20161123555025)(6072148)(201708071742011);SRVR:CY4PR12MB1141;BCL:0;PCL:0;RULEID:(100000803101)(100110400095);SRVR:CY4PR12MB1141; X-Forefront-PRVS: 051158ECBB X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(979002)(6009001)(6049001)(39860400002)(376002)(366004)(346002)(52314003)(199003)(24454002)(189002)(86362001)(575784001)(229853002)(72206003)(50466002)(31696002)(47776003)(66066001)(105586002)(106356001)(65806001)(65956001)(33646002)(316002)(23676004)(52146003)(93886005)(58126008)(16576012)(64126003)(54906003)(6486002)(16526018)(90366009)(97736004)(54356011)(76176011)(4326008)(2906002)(52116002)(2486003)(77096006)(6246003)(5660300001)(7736002)(81156014)(189998001)(65826007)(2950100002)(6916009)(6666003)(53546010)(230700001)(81166006)(305945005)(8676002)(53936002)(3846002)(478600001)(67846002)(3260700006)(25786009)(8936002)(101416001)(68736007)(83506002)(31686004)(36756003)(6116002)(969003)(989001)(999001)(1009001)(1019001);DIR:OUT;SFP:1101;SCL:1;SRVR:CY4PR12MB1141;H:[10.236.65.116];FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtDWTRQUjEyTUIxMTQxOzIzOmd6UE9pYlVudTJnZnA4bjA0SjhWdTNqaVZ6?= =?utf-8?B?WFVCQkNQL3JudXlkVUtMdldrUlBLbmo3QmRwN0JsMGxFS01jTzBIRGFyME9t?= =?utf-8?B?Y242TEZweGNMdGZjckpnWUxweXJRbUY3aXJoNi9xZVpaWHFyaG5nVlo4cUtj?= =?utf-8?B?TmhlZHlhZHpCTjVvd21mUDRVbjVjQk4wU1JUc2pvazlIdzZNUnlEcDFMTUt5?= =?utf-8?B?ZlhLSnZFM0ZtL3NFZUR0Rzc5dnRiaDRGRStkU3ZXck5jbWN6OG1yMmpreVI3?= =?utf-8?B?VGFQdkZmcnRlcVBmL0ZSOGNIRktjckx6VStvNXVVSUxsS0ZYOUgxWFB5a2d1?= =?utf-8?B?dW9uSldnWUp4VkZYUWFKS1J3UEgvZkl6dWx4SEZvZlExYmtrZjBjOVhybE9W?= =?utf-8?B?QS9zVU0wTHJDS1pSVFhHTnJ1MU4wOGlXakxwZUhYSy9KMHN5dlc5MUNIcHpP?= =?utf-8?B?WlBIRjlkN0FiRVV2Z3pYSFlMTHA1T2g3djkwN0E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8lil6qhZtob1cy2+sa2cm3gwicqfRIk3YvjbV30KDgZ+20yOiqyj7oPQAHhEMibdSWuX0+/Gwzx5kQVJJbnbuEcJ/ih4WZ3unGXE2W0/EUb9i8GFqCfSOSGK3h8vpH0HWJtb5kn+W4IJeP+BfJoM6ouEgkgSjoTuVE2ws7r529wDrlp6yJac6 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Dec 2017 18:33:04.2512 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ebd9d0c2-16b1-47ea-30f7-08d53b45754f X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d 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: 5717 Lines: 174 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. > + > +/* > + * 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. Thanks, Tom > + > #include > #include > #include > @@ -489,73 +506,42 @@ static void __init sme_clear_pgd(pgd_t *pgd_base, unsigned long start, > static void __init *sme_populate_pgd(pgd_t *pgd_base, void *pgtable_area, > unsigned long vaddr, pmdval_t pmd_val) > { > - pgd_t *pgd_p; > - p4d_t *p4d_p; > - pud_t *pud_p; > - pmd_t *pmd_p; > - > - pgd_p = pgd_base + pgd_index(vaddr); > - if (native_pgd_val(*pgd_p)) { > - if (IS_ENABLED(CONFIG_X86_5LEVEL)) > - p4d_p = (p4d_t *)(native_pgd_val(*pgd_p) & ~PTE_FLAGS_MASK); > - else > - pud_p = (pud_t *)(native_pgd_val(*pgd_p) & ~PTE_FLAGS_MASK); > - } else { > - pgd_t pgd; > - > - if (IS_ENABLED(CONFIG_X86_5LEVEL)) { > - p4d_p = pgtable_area; > - memset(p4d_p, 0, sizeof(*p4d_p) * PTRS_PER_P4D); > - pgtable_area += sizeof(*p4d_p) * PTRS_PER_P4D; > - > - pgd = native_make_pgd((pgdval_t)p4d_p + PGD_FLAGS); > - } else { > - pud_p = pgtable_area; > - memset(pud_p, 0, sizeof(*pud_p) * PTRS_PER_PUD); > - pgtable_area += sizeof(*pud_p) * PTRS_PER_PUD; > - > - pgd = native_make_pgd((pgdval_t)pud_p + PGD_FLAGS); > - } > - native_set_pgd(pgd_p, pgd); > + pgd_t *pgd; > + p4d_t *p4d; > + pud_t *pud; > + pmd_t *pmd; > + > + pgd = pgd_base + pgd_index(vaddr); > + if (pgd_none(*pgd)) { > + p4d = pgtable_area; > + memset(p4d, 0, sizeof(*p4d) * PTRS_PER_P4D); > + pgtable_area += sizeof(*p4d) * PTRS_PER_P4D; > + set_pgd(pgd, __pgd(PGD_FLAGS | __pa(p4d))); > } > > - if (IS_ENABLED(CONFIG_X86_5LEVEL)) { > - p4d_p += p4d_index(vaddr); > - if (native_p4d_val(*p4d_p)) { > - pud_p = (pud_t *)(native_p4d_val(*p4d_p) & ~PTE_FLAGS_MASK); > - } else { > - p4d_t p4d; > - > - pud_p = pgtable_area; > - memset(pud_p, 0, sizeof(*pud_p) * PTRS_PER_PUD); > - pgtable_area += sizeof(*pud_p) * PTRS_PER_PUD; > - > - p4d = native_make_p4d((pudval_t)pud_p + P4D_FLAGS); > - native_set_p4d(p4d_p, p4d); > - } > + p4d = p4d_offset(pgd, vaddr); > + if (p4d_none(*p4d)) { > + pud = pgtable_area; > + memset(pud, 0, sizeof(*pud) * PTRS_PER_PUD); > + pgtable_area += sizeof(*pud) * PTRS_PER_PUD; > + set_p4d(p4d, __p4d(P4D_FLAGS | __pa(pud))); > } > > - pud_p += pud_index(vaddr); > - if (native_pud_val(*pud_p)) { > - if (native_pud_val(*pud_p) & _PAGE_PSE) > - goto out; > - > - pmd_p = (pmd_t *)(native_pud_val(*pud_p) & ~PTE_FLAGS_MASK); > - } else { > - pud_t pud; > - > - pmd_p = pgtable_area; > - memset(pmd_p, 0, sizeof(*pmd_p) * PTRS_PER_PMD); > - pgtable_area += sizeof(*pmd_p) * PTRS_PER_PMD; > - > - pud = native_make_pud((pmdval_t)pmd_p + PUD_FLAGS); > - native_set_pud(pud_p, pud); > + pud = pud_offset(p4d, vaddr); > + if (pud_none(*pud)) { > + pmd = pgtable_area; > + memset(pmd, 0, sizeof(*pmd) * PTRS_PER_PMD); > + pgtable_area += sizeof(*pmd) * PTRS_PER_PMD; > + set_pud(pud, __pud(PUD_FLAGS | __pa(pmd))); > } > + if (pud_large(*pud)) > + goto out; > > - pmd_p += pmd_index(vaddr); > - if (!native_pmd_val(*pmd_p) || !(native_pmd_val(*pmd_p) & _PAGE_PSE)) > - native_set_pmd(pmd_p, native_make_pmd(pmd_val)); > + pmd = pmd_offset(pud, vaddr); > + if (pmd_large(*pmd)) > + goto out; > > + set_pmd(pmd, __pmd(pmd_val)); > out: > return pgtable_area; > } >