From patchwork Tue Apr 26 16:43:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 12827524 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1B9EEC433F5 for ; Tue, 26 Apr 2022 16:46:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A19BD6B0081; Tue, 26 Apr 2022 12:46:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9C9836B0082; Tue, 26 Apr 2022 12:46:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8913A6B0083; Tue, 26 Apr 2022 12:46:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.a.hostedemail.com [64.99.140.24]) by kanga.kvack.org (Postfix) with ESMTP id 7D0E36B0081 for ; Tue, 26 Apr 2022 12:46:11 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 5CEC660F5E for ; Tue, 26 Apr 2022 16:46:11 +0000 (UTC) X-FDA: 79399607742.13.CB16390 Received: from mail-ed1-f74.google.com (mail-ed1-f74.google.com [209.85.208.74]) by imf18.hostedemail.com (Postfix) with ESMTP id AECE91C004B for ; Tue, 26 Apr 2022 16:46:06 +0000 (UTC) Received: by mail-ed1-f74.google.com with SMTP id co27-20020a0564020c1b00b00425ab566200so8065809edb.6 for ; Tue, 26 Apr 2022 09:46:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=SGOwGjYq/2PwacKh0/9At0yFevcHrzg9FDlShmi+vnk=; b=fSZ4zfvDJJmqaIzU1XL0WfStwXr6OPa8V+ga0qTz0UlsIHyG9I6Fr6ZEbs9vmLiuhO ClbMCWmC+tznTOah7YoL3txE0BplWerCcj5Pt/KeycPvVB+sF+pTOE13LG7aV8CaSZd6 CtB276fuSEgHwCIg/10uWG7rSCD98aAcUKoO+LU4U8ks8bUI5/GdxxpoNac4ZhTkb0E1 grtFS0KyEl74V0H8NCr4jzX10gmxpamQ+wZyHKObaL9HWxab3p+XWx1x2TN57EUQX6a4 MV6fXbcDTcGpFO2Dt7YM5K3PDMZSDsLSt5fDbOOZGvHfv6pU1T6bZgqLE57A40M5bQwM 0uLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=SGOwGjYq/2PwacKh0/9At0yFevcHrzg9FDlShmi+vnk=; b=b6Jh/Bet4rdd2jctK+8qEJwn2cHdAAQSFa4+ighVumGB2VxrLgdi0/OCafCdJB7bqB qR5iYMMsOJFRRDrhKKTVwXb3V3U/2LdIYMLyQj8gqdjREnW26FRkjCdI1UPMD+nC99ur uFA5F4mjKFnl5LEZxQS4auIwB+mSwW3+HZczhpFjS8vjJJs0ObJdNLN/vt9gei3sl3IF MMZxNeX7mKbVGNxdI/+WA2UrGoQWMB/wYrBSFtQWH+Xeo6IIdRAhxd86Ct2MBt7bV630 e/MlMsxqMByVnJCh+D6P3qHIkGPdWFIHW4TDBzkCbSK7ncaG2CVnoZ6tOUxfYRWBvhQ4 sGGw== X-Gm-Message-State: AOAM530jiYuTBZDuX3T1pHckoLDDLHOYWeurnxUYm9lxQmmngT5VRJRy ADzNjXONk6Ra8z6QB5sFL4M1wckASZw= X-Google-Smtp-Source: ABdhPJw9NptsR6xC76SX+4t0lKzp8AK1gzotC/X9LsmKWQ/MoVeg5tjW3Iafs+1NkdThy9tu1emAPZFww8w= X-Received: from glider.muc.corp.google.com ([2a00:79e0:15:13:d580:abeb:bf6d:5726]) (user=glider job=sendgmr) by 2002:a05:6402:84a:b0:423:fe99:8c53 with SMTP id b10-20020a056402084a00b00423fe998c53mr25385277edz.195.1650991569448; Tue, 26 Apr 2022 09:46:09 -0700 (PDT) Date: Tue, 26 Apr 2022 18:43:11 +0200 In-Reply-To: <20220426164315.625149-1-glider@google.com> Message-Id: <20220426164315.625149-43-glider@google.com> Mime-Version: 1.0 References: <20220426164315.625149-1-glider@google.com> X-Mailer: git-send-email 2.36.0.rc2.479.g8af0fa9b8e-goog Subject: [PATCH v3 42/46] x86: kmsan: sync metadata pages on page fault From: Alexander Potapenko To: glider@google.com Cc: Alexander Viro , Andrew Morton , Andrey Konovalov , Andy Lutomirski , Arnd Bergmann , Borislav Petkov , Christoph Hellwig , Christoph Lameter , David Rientjes , Dmitry Vyukov , Eric Dumazet , Greg Kroah-Hartman , Herbert Xu , Ilya Leoshkevich , Ingo Molnar , Jens Axboe , Joonsoo Kim , Kees Cook , Marco Elver , Mark Rutland , Matthew Wilcox , "Michael S. Tsirkin" , Pekka Enberg , Peter Zijlstra , Petr Mladek , Steven Rostedt , Thomas Gleixner , Vasily Gorbik , Vegard Nossum , Vlastimil Babka , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org X-Rspamd-Queue-Id: AECE91C004B X-Stat-Signature: rz7zxj681dxdfi3s1ydgrdrw4aim991s X-Rspam-User: Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=fSZ4zfvD; spf=pass (imf18.hostedemail.com: domain of 30SFoYgYKCM4052xyB08805y.w86527EH-664Fuw4.8B0@flex--glider.bounces.google.com designates 209.85.208.74 as permitted sender) smtp.mailfrom=30SFoYgYKCM4052xyB08805y.w86527EH-664Fuw4.8B0@flex--glider.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspamd-Server: rspam09 X-HE-Tag: 1650991566-531087 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: KMSAN assumes shadow and origin pages for every allocated page are accessible. For pages between [VMALLOC_START, VMALLOC_END] those metadata pages start at KMSAN_VMALLOC_SHADOW_START and KMSAN_VMALLOC_ORIGIN_START, therefore we must sync a bigger memory region. Signed-off-by: Alexander Potapenko --- v2: -- addressed reports from kernel test robot Link: https://linux-review.googlesource.com/id/Ia5bd541e54f1ecc11b86666c3ec87c62ac0bdfb8 --- arch/x86/mm/fault.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c index d0074c6ed31a3..f2250a32a10ca 100644 --- a/arch/x86/mm/fault.c +++ b/arch/x86/mm/fault.c @@ -260,7 +260,7 @@ static noinline int vmalloc_fault(unsigned long address) } NOKPROBE_SYMBOL(vmalloc_fault); -void arch_sync_kernel_mappings(unsigned long start, unsigned long end) +static void __arch_sync_kernel_mappings(unsigned long start, unsigned long end) { unsigned long addr; @@ -284,6 +284,27 @@ void arch_sync_kernel_mappings(unsigned long start, unsigned long end) } } +void arch_sync_kernel_mappings(unsigned long start, unsigned long end) +{ + __arch_sync_kernel_mappings(start, end); +#ifdef CONFIG_KMSAN + /* + * KMSAN maintains two additional metadata page mappings for the + * [VMALLOC_START, VMALLOC_END) range. These mappings start at + * KMSAN_VMALLOC_SHADOW_START and KMSAN_VMALLOC_ORIGIN_START and + * have to be synced together with the vmalloc memory mapping. + */ + if (start >= VMALLOC_START && end < VMALLOC_END) { + __arch_sync_kernel_mappings( + start - VMALLOC_START + KMSAN_VMALLOC_SHADOW_START, + end - VMALLOC_START + KMSAN_VMALLOC_SHADOW_START); + __arch_sync_kernel_mappings( + start - VMALLOC_START + KMSAN_VMALLOC_ORIGIN_START, + end - VMALLOC_START + KMSAN_VMALLOC_ORIGIN_START); + } +#endif +} + static bool low_pfn(unsigned long pfn) { return pfn < max_low_pfn;