Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751283AbdLZLrO (ORCPT ); Tue, 26 Dec 2017 06:47:14 -0500 Received: from mail-ve1eur01on0122.outbound.protection.outlook.com ([104.47.1.122]:5872 "EHLO EUR01-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750776AbdLZLrM (ORCPT ); Tue, 26 Dec 2017 06:47:12 -0500 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=aryabinin@virtuozzo.com; Subject: Re: linux/master crashes on boot with KASAN=y To: Andy Lutomirski Cc: Jakub Kicinski , Thomas Gleixner , Ingo Molnar , LKML References: <20171223000143.0af3366d@cakuba.netronome.com> <41c68406-ad05-1db7-b0dd-a2e616448ee1@virtuozzo.com> From: Andrey Ryabinin Message-ID: Date: Tue, 26 Dec 2017 14:47:09 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: HE1PR08CA0055.eurprd08.prod.outlook.com (2603:10a6:7:2a::26) To AM4PR08MB2819.eurprd08.prod.outlook.com (2603:10a6:205:d::25) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f6f0b68c-e624-489e-1ed1-08d54c566561 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(4534020)(4602075)(7168020)(4627115)(201703031133081)(201702281549075)(5600026)(4604075)(2017052603307)(7153060);SRVR:AM4PR08MB2819; X-Microsoft-Exchange-Diagnostics: 1;AM4PR08MB2819;3:JWVpdmlDmVRj7Cc+2E3xTX4vBjbHL9f7OwB0HAZ0gomOMXy0S8+IXca/uJCziZPC4qvbE67tKMh0NOPog+JfZ7Tu6rPSUxYuL/WsD/f6XY9wkFZAnm7lm7YOKpJun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j/dfNcKzdb6DCPn041X5Zrtmu3tMv/k5sqQSH8Ip6pRuXf6FW2bZwSWXEp0b+EVZo/lQgpPn/yVACz3uSiLNhf+jLbVURx5dhoZBKrlj61SqHnMBOGg17jyE68aG9lWjpsw/YHS6AZlVtklCShv9q7HBv0=;4:CZUMHyoUfgfxDy9AjsKGVPCEnbfeE1L5bCBpN3LSlVs8eONZ9kKH74Z1BoDD8q79I0bDJAmFfvouEXkIHgV6NKzqjHOTxxrND96Dj9NYeaof3s6/DAkaO5238dEMu/Yz9G9MWMyrUQ+Ch/EbyJxOhorqTB0YUtIq7KV7KOVxfV0k+enYb4bPJTjyBgti+4VC7pqA0RqqPK9z7WCIeO4uLgbisV9PWcSCuStiuNEOHx6IcPYBnVPVsL/VTdtQbguXv3Jn9w+u5UGO2QrfvvJFiw== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040470)(2401047)(8121501046)(5005006)(10201501046)(3002001)(93006095)(93001095)(3231023)(944501075)(6041268)(20161123560045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123558120)(6072148)(201708071742011);SRVR:AM4PR08MB2819;BCL:0;PCL:0;RULEID:(100000803101)(100110400095);SRVR:AM4PR08MB2819; X-Forefront-PRVS: 053315510E X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(6049001)(366004)(39840400004)(346002)(376002)(39380400002)(396003)(189003)(199004)(24454002)(68736007)(36756003)(97736004)(7736002)(64126003)(6116002)(25786009)(3846002)(316002)(2906002)(106356001)(81166006)(229853002)(230700001)(105586002)(6486002)(83506002)(77096006)(31686004)(6246003)(16576012)(478600001)(66066001)(575784001)(59450400001)(65826007)(54906003)(50466002)(86362001)(47776003)(76176011)(53546011)(8676002)(386003)(65956001)(65806001)(58126008)(55236004)(8936002)(16526018)(31696002)(5660300001)(305945005)(4326008)(52146003)(53936002)(2486003)(52116002)(81156014)(6916009)(2950100002)(23676004);DIR:OUT;SFP:1102;SCL:1;SRVR:AM4PR08MB2819;H:[172.16.25.12];FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtBTTRQUjA4TUIyODE5OzIzOjQzRjBESlJuaU4zL3YzQUttVElOYUpqWnlO?= =?utf-8?B?d1UxVnZNZEp3VnNuaXVHQlo0bUlKU2IwblpPeWV0UGV1NFNkd0ZCa0JYeTBX?= =?utf-8?B?MUFmOFRWRG10clY0VnpkWWNERUtsejF5TmxRUFUxK3Exam9FRTlHRklRazVj?= =?utf-8?B?VFZydVRrK3VCbThBaGF2RTdXTHh4Q2NVQ3BGdHRmWVZPdmtzaDd4SU1JOEwy?= =?utf-8?B?blFTbkJDcElDcWNUN216aFl0d2hvRk5lVjlqZXY4RmJ1Wjl2MjR2SWY1V2Jh?= =?utf-8?B?ckRJajNnNWxuSVh1RjFlcFNZM1UrK3dTb2VrWFJPZkV3WFJsaTFkZ1c3Vng2?= =?utf-8?B?RGQwNEVaakhGTlZWUmxqQXQ0U1d3ckhsa2FpMnFxeFgxbDNMbDFJNjRvZVVE?= =?utf-8?B?UDhtTG1vQWZCUEo4NURlRCt1eGtVVGVRaUJ6eW9tb2RZYnRRcjBBbHNEOEZN?= =?utf-8?B?WjN3RmdRZ0QwampKSWgvUDFMWjkrY3BON3ZmMnpOWnU2M2RRSHBPeXh2Zlpv?= =?utf-8?B?MTdVUEwwRlMzL2NhSjlkT3pXSCtKYmNJZjZCUmdoRDdVV3RaYWJETVRTdUcr?= =?utf-8?B?dFNGdWF2Q09hOVAwUXkwaUMxd1M3S0h3VXJYTHZ6amdUWmthOG5Pc08yQkh2?= =?utf-8?B?cFUzTUl2Wjg2anBWNGtNTjdCNVc5dGJoWUJsMzdLMzR5ZDRPYmcrNjk5UWxh?= =?utf-8?B?MG9KdmtmZWs1Q3UrSEd0TjNZdUNWRW9vTkVWMHJ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h2oV4RcxkJHJCywbaw9qMyF+xzj8cNd6O9DkviccJPZz0tBQ1swNkSMQDdIWuuUyOU+tugekqBFj4GkyAfbTcyZgLBmwOPyaxXDsmcMmk4EA7f6P6YRdmZCC/ayqRi48LK+AaYy6qJpubEyZLVeXyI2ne1C0r4GBQZQcvGKpgoIn1AWlYFSaZwLTvQofVevJmOoMDBahrNzuDlrYAlCOmsAUCwv/R SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;AM4PR08MB2819;20:svww5y9C9DSx5ma1kyw5XO2NsJsP0CAknJAGe69GTmqua08Q0Guma274p0ZhT9hj99DjEbtMHR9cytyTg0z97iGacl+TSOYFF6x536jFvStIdNZ4NWkUTNUFL6SBHoljJFsUsWt2Zqlpjp0zCM5WVcSO3mW0B3Kxl6ZvU/nLVHA= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Dec 2017 11:47:09.0492 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f6f0b68c-e624-489e-1ed1-08d54c566561 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR08MB2819 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3346 Lines: 80 On 12/24/2017 04:48 AM, Andy Lutomirski wrote: > On Sat, Dec 23, 2017 at 4:41 AM, Andrey Ryabinin > wrote: >> On 12/23/2017 11:01 AM, Jakub Kicinski wrote: >>> Hi! >>> >>> I bisected a crash on boot to this: >>> >>> commit 21506525fb8ddb0342f2a2370812d47f6a1f3833 (HEAD, refs/bisect/bad) >>> Author: Andy Lutomirski >>> Date: Mon Dec 4 15:07:16 2017 +0100 >>> >>> x86/kasan/64: Teach KASAN about the cpu_entry_area >> >> >> Thanks. >> There is nothing wrong with this patch, it just uncovered older bug. >> The actual problem comes from f06bdd4001c2 ("x86/mm: Adapt MODULES_END based on fixmap section size") >> which is made kasan_mem_to_shadow(MODULES_END) potentially unaligned to page boundary. >> And when we feed unaligned address to kasan_populate_zero_shadow() it doesn't do the right thing. >> >> Could you tell me if the fix bellow works for you? >> >> --- >> arch/x86/include/asm/kasan.h | 8 ++++++++ >> arch/x86/include/asm/pgtable_64_types.h | 4 +++- >> 2 files changed, 11 insertions(+), 1 deletion(-) >> >> diff --git a/arch/x86/include/asm/kasan.h b/arch/x86/include/asm/kasan.h >> index b577dd0916aa..0c580e4b2ccc 100644 >> --- a/arch/x86/include/asm/kasan.h >> +++ b/arch/x86/include/asm/kasan.h >> @@ -5,6 +5,14 @@ >> #include >> #define KASAN_SHADOW_OFFSET _AC(CONFIG_KASAN_SHADOW_OFFSET, UL) >> >> +#ifndef KASAN_SHADOW_SCALE_SHIFT >> +# ifdef CONFIG_KASAN >> +# define KASAN_SHADOW_SCALE_SHIFT 3 >> +# else >> +# define KASAN_SHADOW_SCALE_SHIFT 0 >> +# endif >> +#endif >> + >> /* >> * Compiler uses shadow offset assuming that addresses start >> * from 0. Kernel addresses don't start from 0, so shadow >> diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h >> index 6d5f45dcd4a1..d34a90d6c374 100644 >> --- a/arch/x86/include/asm/pgtable_64_types.h >> +++ b/arch/x86/include/asm/pgtable_64_types.h >> @@ -6,6 +6,7 @@ >> >> #ifndef __ASSEMBLY__ >> #include >> +#include >> #include >> >> /* >> @@ -96,7 +97,8 @@ typedef struct { pteval_t pte; } pte_t; >> #define VMALLOC_END (VMALLOC_START + _AC((VMALLOC_SIZE_TB << 40) - 1, UL)) >> #define MODULES_VADDR (__START_KERNEL_map + KERNEL_IMAGE_SIZE) >> /* The module sections ends with the start of the fixmap */ >> -#define MODULES_END __fix_to_virt(__end_of_fixed_addresses + 1) >> +#define MODULES_END (__fix_to_virt(__end_of_fixed_addresses + 1) & \ >> + ~((PAGE_SIZE << KASAN_SHADOW_SCALE_SHIFT) - 1)) > > Could this be #define MODULES_END KASAN_ROUND_DOWN(__fix_to_virt(...)) instead? > Actually, we could simply set fixed MODULES_END, as it was before f06bdd4001c2 ("x86/mm: Adapt MODULES_END based on fixmap section size"). AFAICS, the whole point of f06bdd4001c2 was to move MODULES_END down if NR_CPUS is big. But since 92a0f81d8957 ("x86/cpu_entry_area: Move it out of the fixmap") cpu_entry_area is not in fixmap anymore. So it should be fine to set fixed MODULES_END. The only concern I have is 4.14 stable, where 21506525f ("x86/kasan/64: Teach KASAN about the cpu_entry_area") was backported. Is 92a0f81d8957 ("x86/cpu_entry_area: Move it out of the fixmap") also a candidate for stable? If so, fixed MODULES_END seems like a better choice.