Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751209AbdFAOyr (ORCPT ); Thu, 1 Jun 2017 10:54:47 -0400 Received: from mail-eopbgr40129.outbound.protection.outlook.com ([40.107.4.129]:62000 "EHLO EUR03-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751078AbdFAOyn (ORCPT ); Thu, 1 Jun 2017 10:54:43 -0400 Authentication-Results: googlegroups.com; dkim=none (message not signed) header.d=none;googlegroups.com; dmarc=none action=none header.from=virtuozzo.com; Subject: Re: KASAN vs. boot-time switching between 4- and 5-level paging To: "Kirill A. Shutemov" References: <20170525203334.867-1-kirill.shutemov@linux.intel.com> <20170525203334.867-8-kirill.shutemov@linux.intel.com> <20170526221059.o4kyt3ijdweurz6j@node.shutemov.name> <71e11033-f95c-887f-4e4e-351bcc3df71e@virtuozzo.com> <75acbed7-6a08-692f-61b5-2b44f66ec0d8@virtuozzo.com> CC: Dmitry Vyukov , Alexander Potapenko , "Kirill A. Shutemov" , Linus Torvalds , Andrew Morton , "x86@kernel.org" , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , Andi Kleen , Dave Hansen , Andy Lutomirski , , "linux-mm@kvack.org" , LKML , kasan-dev From: Andrey Ryabinin Message-ID: Date: Thu, 1 Jun 2017 17:56:30 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: <75acbed7-6a08-692f-61b5-2b44f66ec0d8@virtuozzo.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: AM5PR0502CA0020.eurprd05.prod.outlook.com (2603:10a6:203:91::30) To VI1PR0801MB2735.eurprd08.prod.outlook.com (2a01:111:e400:7b7c::28) X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1PR0801MB2735: X-MS-Office365-Filtering-Correlation-Id: e9f6d5e6-a717-498f-80b9-08d4a8fe1faa X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(201703131423075)(201703031133081);SRVR:VI1PR0801MB2735; X-Microsoft-Exchange-Diagnostics: 1;VI1PR0801MB2735;3:VypRIxJicnqgM3MTFq6vGJ6b3hDtg0Hs4FYehzXCNCGh/WaSmQiSrGIOJvxNzcro8Fp6aIv1i9PChvz59r2QrRyotTU0PzOjvUymDke1pxaKwFay/pVpwd22VdaLq9DmWanohu1B+5/RZ3YShmSfb5HuCeKZqodkkBoioAvf9b2dfGnOTsoOEkMLu9C5eWk2F3SFGDJVj9mx4sajX6inAqD9QKIug9hT3kjjTuyfsVg7/vH1WhQEZOpHT06cx+jtaUMS8u5RF6/Iaea8X+Kyz9Gfm4X2gG6PaGHAp35pfwxSYm+0a8urt2U7mBykYxSN/micp0mwpBySbNdgs7f/mg==;25:4XSUPXX2BzR3Z7SVigHp0+HQjs2WGg30bt8H/c7qyqgsolDC2uEA2yCj+GrL97NkPZuMV+HdkDm0ZzPL8taK0hLIRaPPedr9QqtS/aSXoGtarupDGXXZPRL9TEbmV07ezOD8Fs6axKFWM8DVQfYE8UnVcY7ffKWMtpfRSbSajSXzg1u7GXP8EHLt79gNCDFvHM2pJNPBu/Nn8eXFZyog1DR+tGdejxAarPbUrxSBB9Vs1ser/f2573NJpzrIOI3eowpkbFsecU0iT87nvjP9L6CDKGIo/nQgEEdnSRnvhHiXBpB6Px9HUvZXYAeEJu5dJqb1ptMoIA8U2IMIp1j0W4cHl0rHL8HoF/TcNLTYBGT4gd/c0srJ9SQx7IVio+Ug9LsQLQC8G+tYz3tUXnqfitoCAs/6qf9s4tnFFRNQhOVo6H9YJ1FzVTq1YgERQAegd/zBtpiX5CcHUM+DYNU7vJC+FK0/rfFcmQqyi21oGaU= X-Microsoft-Exchange-Diagnostics: 1;VI1PR0801MB2735;31:6T+u27hvcQeIs2HKepV8t5eYMnrqZxWA6X+kW3FKDk9fk1mKlfqNRSc2TFhE0g0QXu1JtCXjbDttGYOvwPnmXeXlGiC5NhdCSJ431ap6VQiV6rJ/sQRtQR06caSWMQCAuNG38tWLXNeYksFgY3bwcURBOEIbi0CuOFq52ye+CLdFerwJYr3f9HOFgxw15+nNCxUTlCULtj4lZrfD2CDiEfNjwy1m04BVXItfHxZD+NTaH1VZiF9luVSI+j0zxSqG;20:jHxV7E+DGznvn+BMDGY09HnRXQz3T3AOj4eaDuhTeYyGKZUEW0V5OVOAND+2SOEHgbDO8Akr/8GVek9f48aggQTdmKASWfHhiEySuLU8jzPgnC8jUA7rMqaAKPuMOooWZeua42NHrDMcFg9Unyt+qZLuy2yl6mmU6LKV8wQV11dBWG0W+3SEXLrxF7FfQNmObSq7dG21YqVBhOaJAW1Zm+DZmDJ8BAu1PZ4x6pwsbd0rDcHmVbTmgoySLzyrphUiXuN7HOtlRkXWx4PFBeZ9x+FFPR0n+EzHKAC0Uxzl64Ad+dcq0Gl1Q59pWwmynCCWwiDzfAPORJCnee0k0kPg7HJFlpQzmiuxnqsLfosnxfM8OS+L2n2C4XkDGZC6t2RJt04yBxmxRaewsczV8zZoRsh8p1ZMsTQ7GzRunxFQeHU= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(84791874153150); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(100000700100)(100105000095)(100000701100)(100105300095)(100000702100)(100105100095)(6040450)(601004)(2401047)(5005006)(8121501046)(100000703100)(100105400095)(3002001)(93006095)(93001095)(10201501046)(6041248)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123562025)(20161123555025)(20161123558100)(20161123564025)(20161123560025)(6072148)(100000704100)(100105200095)(100000705100)(100105500095);SRVR:VI1PR0801MB2735;BCL:0;PCL:0;RULEID:(100000800100)(100110000095)(100000801100)(100110300095)(100000802100)(100110100095)(100000803100)(100110400095)(100000804100)(100110200095)(100000805100)(100110500095);SRVR:VI1PR0801MB2735; X-Microsoft-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moxa1JiMkR1czJQOThDREgvY3hWL2REbHZ2?= =?utf-8?B?YlYxcVJVZEFaKzNpMDZlMlg1N1UrVWs0M28xeGE4bC9mekNkYWM4NWo2M2Iy?= =?utf-8?B?YUh4TlhtbkI4K1RDTDlETHJqbEdVR1pXUEtTaEE0UGpIWlREanI4Y24vRzl4?= =?utf-8?B?RHEwT1NsS04yejRocnUrMXpJNi9vR0FMK0ppU0NFVXg4Sk9TK3paWHRPY2Vq?= =?utf-8?B?K1lhejd1UjFIMlJOVEZiRlVIRTUrUlJUTmx6SFY5aFNXS3VpYkp0MmxDSTVT?= =?utf-8?B?MCtIN1FMdlJUbHpoTmRHRFJ2alY2NkltMFU4VFByVDZPOEU2Z2ljdmhJL1JF?= =?utf-8?B?aVVYVXBpRld3cUZ2d2JYc0JjZ2pmN3dHS1ZnZmhkYUU5VDRMRzNpMUROVlNj?= =?utf-8?B?TjR2V3owa0w1ZkZIMmdNZFIrZG9YeDV3MDdydEdzMjYwU1MvcEppQ3NtbENv?= =?utf-8?B?TXppaVg0NVl1Q1UvdjVWblJkc2wxYmlWeUtYanAxUDlCeXQrRDFKVjIzSkFi?= =?utf-8?B?VXpKWEpUT3l5MDJCbzZNUFdFbDdoSFhPdHpKNWprQkh0NEs0M3R3WTEvZUJp?= =?utf-8?B?M1ZuSmlDS0tidWVPQ0E2TnhuUUhKTFlkbnNkTklIVDJ2THh1cDhQMEVoZzB5?= =?utf-8?B?Z2NpdG0xWEU1K0RBWlloVklqT290dEZEaDdyaGo3U0tGdmkzRU55d3lMTE84?= =?utf-8?B?dGEyNWZZUWVwTXVhcEl5VzVvbE1wZmdBM3pZcnllU201ZjRZNythWHNMWWYw?= =?utf-8?Q?=3D?= X-Forefront-PRVS: 0325F6C77B X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(4630300001)(6009001)(6049001)(39450400003)(39830400002)(39400400002)(54094003)(377454003)(24454002)(305945005)(7736002)(54906002)(42186005)(31686004)(229853002)(6916009)(2950100002)(6666003)(33646002)(23676002)(110136004)(6486002)(77096006)(66066001)(53936002)(8676002)(38730400002)(47776003)(65806001)(6246003)(65956001)(189998001)(7416002)(25786009)(53546009)(65826007)(5660300001)(36756003)(6116002)(81166006)(83506001)(50466002)(4001350100001)(4326008)(3846002)(478600001)(76176999)(31696002)(93886004)(230700001)(86362001)(2906002)(50986999)(561944003)(54356999);DIR:OUT;SFP:1102;SCL:1;SRVR:VI1PR0801MB2735;H:[172.16.25.12];FPR:;SPF:None;MLV:sfv;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtWSTFQUjA4MDFNQjI3MzU7MjM6ejBqR0pad25ORVpHS2lYWmlNL2ptU2cy?= =?utf-8?B?cG52Nm4vZ2taUjJXNVphcTdwclp1SWQvTTVJL0xvbTBqdGhYUW9yR0lVK2Zr?= =?utf-8?B?MTdvZE4rRkM4UWNzNE1qcEx4RWdXS1dMLy9qOUc4SGNNQmZOV0pNaFlvN2pS?= =?utf-8?B?NzhBU0p3d1NJQVgvODg4ZmJUUHJUQXczQm90cVlDQkhsREREWlFZMG5sWTNI?= =?utf-8?B?WUpXOFFWdDFyNWlxUmU5dkxmTlVmalRJWG5vWTZ2VXBHWUE3Vk5UeSttK2dt?= =?utf-8?B?V0NiWlkyYUFoSHdQZnFkaHJWYndQWVJncmRjVnRZUDBYd1lqVURtYnZ0S1Jl?= =?utf-8?B?MERlZE9zQmNWSWFmaklDemhibmFpclc0VjY4Ny9vUEdsaXdQTWFwWFpxV0Nm?= =?utf-8?B?TmJLVjhCWlNzMGhESUZ4eitTY0FLT3FjYVpvMmNESXcraEtkcjFKVXlHWndB?= =?utf-8?B?S25BWnZKaHJJTDYzaHlub0VqS3drUi8rMmEyM0ZBandqTmU5N2JwL3JMejFl?= =?utf-8?B?RWFIMDlZajlZRVpmK0hmK29HZnlEeUpuL2dNTFNpUFZxcjRsa3dvejVHMG9U?= =?utf-8?B?MXQ0Zzg1Y2ttRStYaGhTaElpaE1hakprKzVrY3IvU1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dBR54zMoqcAi2UkW56kMiDJrQUmRzUVP3Y40OKklcrU= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Jun 2017 14:54:35.7978 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0801MB2735 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 6113 Lines: 183 On 05/29/2017 03:46 PM, Andrey Ryabinin wrote: > On 05/29/2017 02:45 PM, Andrey Ryabinin wrote: >>>>>> Looks like KASAN will be a problem for boot-time paging mode switching. >>>>>> It wants to know CONFIG_KASAN_SHADOW_OFFSET at compile-time to pass to >>>>>> gcc -fasan-shadow-offset=. But this value varies between paging modes... >>>>>> >>>>>> I don't see how to solve it. Folks, any ideas? >>>>> >>>>> +kasan-dev >>>>> >>>>> I wonder if we can use the same offset for both modes. If we use >>>>> 0xFFDFFC0000000000 as start of shadow for 5 levels, then the same >>>>> offset that we use for 4 levels (0xdffffc0000000000) will also work >>>>> for 5 levels. Namely, ending of 5 level shadow will overlap with 4 >>>>> level mapping (both end at 0xfffffbffffffffff), but 5 level mapping >>>>> extends towards lower addresses. The current 5 level start of shadow >>>>> is actually close -- 0xffd8000000000000 and it seems that the required >>>>> space after it is unused at the moment (at least looking at mm.txt). >>>>> So just try to move it to 0xFFDFFC0000000000? >>>>> >>>> >>>> Yeah, this should work, but note that 0xFFDFFC0000000000 is not PGDIR aligned address. Our init code >>>> assumes that kasan shadow stars and ends on the PGDIR aligned address. >>>> Fortunately this is fixable, we'd need two more pages for page tables to map unaligned start/end >>>> of the shadow. >>> >>> I think we can extend the shadow backwards (to the current address), >>> provided that it does not affect shadow offset that we pass to >>> compiler. >> >> I thought about this. We can round down shadow start to 0xffdf000000000000, but we can't >> round up shadow end, because in that case shadow would end at 0xffffffffffffffff. >> So we still need at least one more page to cover unaligned end. > > Actually, I'm wrong here. I assumed that we would need an additional page to store p4d entries, > but in fact we don't need it, as such page should already exist. It's the same last pgd where kernel image > is mapped. > Something like bellow might work. It's just a proposal to demonstrate the idea, so some code might look ugly. And it's only build-tested. Based on top of: git://git.kernel.org/pub/scm/linux/kernel/git/kas/linux.git la57/integration --- arch/x86/Kconfig | 1 - arch/x86/mm/kasan_init_64.c | 74 ++++++++++++++++++++++++++++++++------------- 2 files changed, 53 insertions(+), 22 deletions(-) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 11bd0498f64c..3456f2fdda52 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -291,7 +291,6 @@ config ARCH_SUPPORTS_DEBUG_PAGEALLOC config KASAN_SHADOW_OFFSET hex depends on KASAN - default 0xdff8000000000000 if X86_5LEVEL default 0xdffffc0000000000 config HAVE_INTEL_TXT diff --git a/arch/x86/mm/kasan_init_64.c b/arch/x86/mm/kasan_init_64.c index 88215ac16b24..d79a7ea83d05 100644 --- a/arch/x86/mm/kasan_init_64.c +++ b/arch/x86/mm/kasan_init_64.c @@ -15,6 +15,10 @@ extern pgd_t early_top_pgt[PTRS_PER_PGD]; extern struct range pfn_mapped[E820_MAX_ENTRIES]; +#if CONFIG_PGTABLE_LEVELS == 5 +p4d_t tmp_p4d_table[PTRS_PER_P4D] __initdata __aligned(PAGE_SIZE); +#endif + static int __init map_range(struct range *range) { unsigned long start; @@ -35,8 +39,9 @@ static void __init clear_pgds(unsigned long start, unsigned long end) { pgd_t *pgd; + unsigned long pgd_end = end & PGDIR_MASK; - for (; start < end; start += PGDIR_SIZE) { + for (; start < pgd_end; start += PGDIR_SIZE) { pgd = pgd_offset_k(start); /* * With folded p4d, pgd_clear() is nop, use p4d_clear() @@ -47,29 +52,50 @@ static void __init clear_pgds(unsigned long start, else pgd_clear(pgd); } + + pgd = pgd_offset_k(start); + for (; start < end; start += P4D_SIZE) + p4d_clear(p4d_offset(pgd, start)); +} + +static void __init kasan_early_p4d_populate(pgd_t *pgd, + unsigned long addr, + unsigned long end) +{ + p4d_t *p4d; + unsigned long next; + + if (pgd_none(*pgd)) + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa_nodebug(kasan_zero_p4d))); + + /* early p4d_offset() + * TODO: we need helpers for this shit + */ + if (CONFIG_PGTABLE_LEVELS == 5) + p4d = ((p4d_t*)((__pa_nodebug(pgd->pgd) & PTE_PFN_MASK) + __START_KERNEL_map)) + + p4d_index(addr); + else + p4d = (p4d_t*)pgd; + do { + next = p4d_addr_end(addr, end); + + if (p4d_none(*p4d)) + set_p4d(p4d, __p4d(_KERNPG_TABLE | + __pa_nodebug(kasan_zero_pud))); + } while (p4d++, addr = next, addr != end && p4d_none(*p4d)); } static void __init kasan_map_early_shadow(pgd_t *pgd) { - int i; - unsigned long start = KASAN_SHADOW_START; + unsigned long addr = KASAN_SHADOW_START & PGDIR_MASK; unsigned long end = KASAN_SHADOW_END; + unsigned long next; - for (i = pgd_index(start); start < end; i++) { - switch (CONFIG_PGTABLE_LEVELS) { - case 4: - pgd[i] = __pgd(__pa_nodebug(kasan_zero_pud) | - _KERNPG_TABLE); - break; - case 5: - pgd[i] = __pgd(__pa_nodebug(kasan_zero_p4d) | - _KERNPG_TABLE); - break; - default: - BUILD_BUG(); - } - start += PGDIR_SIZE; - } + pgd = pgd + pgd_index(addr); + do { + next = pgd_addr_end(addr, end); + kasan_early_p4d_populate(pgd, addr, next); + } while (pgd++, addr = next, addr != end); } #ifdef CONFIG_KASAN_INLINE @@ -120,14 +146,20 @@ void __init kasan_init(void) #ifdef CONFIG_KASAN_INLINE register_die_notifier(&kasan_die_notifier); #endif - memcpy(early_top_pgt, init_top_pgt, sizeof(early_top_pgt)); +#if CONFIG_PGTABLE_LEVELS == 5 + memcpy(tmp_p4d_table, (void*)pgd_page_vaddr(*pgd_offset_k(KASAN_SHADOW_END)), + sizeof(tmp_p4d_table)); + set_pgd(&early_top_pgt[pgd_index(KASAN_SHADOW_END)], + __pgd(__pa(tmp_p4d_table) | _KERNPG_TABLE)); +#endif + load_cr3(early_top_pgt); __flush_tlb_all(); - clear_pgds(KASAN_SHADOW_START, KASAN_SHADOW_END); + clear_pgds(KASAN_SHADOW_START & PGDIR_MASK, KASAN_SHADOW_END); - kasan_populate_zero_shadow((void *)KASAN_SHADOW_START, + kasan_populate_zero_shadow((void *)(KASAN_SHADOW_START & PGDIR_MASK), kasan_mem_to_shadow((void *)PAGE_OFFSET)); for (i = 0; i < E820_MAX_ENTRIES; i++) { -- 2.13.0