From patchwork Wed Mar 25 16:12:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 11458255 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 924F714B4 for ; Wed, 25 Mar 2020 16:13:44 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4547220409 for ; Wed, 25 Mar 2020 16:13:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Nke1rrgA" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4547220409 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 582876B0072; Wed, 25 Mar 2020 12:13:36 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 50BD36B0073; Wed, 25 Mar 2020 12:13:36 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 383F06B0074; Wed, 25 Mar 2020 12:13:36 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0223.hostedemail.com [216.40.44.223]) by kanga.kvack.org (Postfix) with ESMTP id 210566B0072 for ; Wed, 25 Mar 2020 12:13:36 -0400 (EDT) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 0E32F83E8A for ; Wed, 25 Mar 2020 16:13:36 +0000 (UTC) X-FDA: 76634380032.15.magic67_76b66b787e85e X-Spam-Summary: 2,0,0,9f9125dcd3be754a,d41d8cd98f00b204,3lon7xgykcb09eb67k9hh9e7.5hfebgnq-ffdo35d.hk9@flex--glider.bounces.google.com,,RULES_HIT:41:152:355:379:541:800:960:973:988:989:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1535:1542:1593:1594:1711:1730:1747:1777:1792:2393:2559:2562:3138:3139:3140:3141:3142:3152:3353:3867:3868:3870:3874:4321:5007:6117:6261:6653:6742:6743:7901:7903:9969:10004:10400:11026:11232:11473:11658:11914:12043:12048:12291:12296:12297:12438:12555:12895:12986:13846:14096:14097:14181:14394:14659:14721:21080:21365:21444:21451:21627:21990:30003:30054:30064,0,RBL:209.85.221.201:@flex--glider.bounces.google.com:.lbl8.mailshell.net-66.100.201.100 62.18.0.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: magic67_76b66b787e85e X-Filterd-Recvd-Size: 5607 Received: from mail-vk1-f201.google.com (mail-vk1-f201.google.com [209.85.221.201]) by imf08.hostedemail.com (Postfix) with ESMTP for ; Wed, 25 Mar 2020 16:13:35 +0000 (UTC) Received: by mail-vk1-f201.google.com with SMTP id t138so957850vkt.17 for ; Wed, 25 Mar 2020 09:13:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=Dty9U5lEq/JO4Z1gO2OONUzqNNcvuqvvEN3in6yhbGM=; b=Nke1rrgAXYVPzJszS0k2Yq/3K2/LuEKPUSBsmc1kBzGvsV/rH2AsZesOaEGHrQwBhP U9KFjn65kCxXKLHqx9OxjskDKNZKawmSfu/c6lguW1N5IUgDRBe1qpQoDLK6CYi8cZz/ F0gmk0QnY0YPPSC/fileT4Z/ObF0dD19N8c1YW0RvaiEMxZYW4TPBDW3H1v6bHkuTwkA XkKqJnxbQeSbw//rmc1EjdvXaFAaLq9HsdDUg7pBfbeaRz129FSmAYUgKhfXPxSowAFh hLDhHcGwvzabrqKvGm9pIT1Uthz9p7uRRxLcWdZ7p64VNxGi0Y6K+PyD/WyI8Li8iFL7 qxfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=Dty9U5lEq/JO4Z1gO2OONUzqNNcvuqvvEN3in6yhbGM=; b=e+PbDhwqj7MlkSDvTsMT2ON55kEt9fxoaDEzIxuDdGkha5SAY+Y/HFYm06BrAAR//V 6I3AmhQFw79xH3lYroAUzcriFGutDILdIkQZNiUjDqAGBzujU4xDmdOfGbPLm3mdp0X0 fKEmXYpcOx76Hp8G4gWL6rzW9T9w3rwsWSOkQP4yfXZDso6MBSVdpZMev+bptJz5CF9h OGNAzQ9b0PO0oSLI7CHky348UX5zdGKtLXTSqvV4ZXYDWKO8ZQvwn3a4S732ZkjaurF4 uLh5muZFCzzTp4gGasc42NuGwk4tvC6wZm3njIgglVRH5HC0XQ8AaCf6YVxawZJnQxS2 qZgQ== X-Gm-Message-State: ANhLgQ3LY89WEJxeOEWhWZjEAWs92z6poZEyklABPdKPypvFy6xTvnQ5 Mvhj1BNKQMgFmgi9A+O1UKP5aMqE2RU= X-Google-Smtp-Source: ADFU+vs/Cz560/OUQZI4xKP+/UNFKeoTP5Lkh7T10q1Rfq/qtD0hWzzM8zVLOJAMhUrXHbucQ3Y5sHeWNb8= X-Received: by 2002:ab0:770d:: with SMTP id z13mr3005021uaq.58.1585152814296; Wed, 25 Mar 2020 09:13:34 -0700 (PDT) Date: Wed, 25 Mar 2020 17:12:23 +0100 In-Reply-To: <20200325161249.55095-1-glider@google.com> Message-Id: <20200325161249.55095-13-glider@google.com> Mime-Version: 1.0 References: <20200325161249.55095-1-glider@google.com> X-Mailer: git-send-email 2.25.1.696.g5e7596f4ac-goog Subject: [PATCH v5 12/38] kmsan: x86: sync metadata pages on page fault From: glider@google.com To: Ingo Molnar , Vegard Nossum , Dmitry Vyukov , Marco Elver , Andrey Konovalov , linux-mm@kvack.org Cc: glider@google.com, viro@zeniv.linux.org.uk, adilger.kernel@dilger.ca, akpm@linux-foundation.org, aryabinin@virtuozzo.com, luto@kernel.org, ard.biesheuvel@linaro.org, arnd@arndb.de, hch@infradead.org, hch@lst.de, darrick.wong@oracle.com, davem@davemloft.net, dmitry.torokhov@gmail.com, ebiggers@google.com, edumazet@google.com, ericvh@gmail.com, gregkh@linuxfoundation.org, harry.wentland@amd.com, herbert@gondor.apana.org.au, iii@linux.ibm.com, jasowang@redhat.com, axboe@kernel.dk, m.szyprowski@samsung.com, mark.rutland@arm.com, martin.petersen@oracle.com, schwidefsky@de.ibm.com, willy@infradead.org, mst@redhat.com, mhocko@suse.com, monstr@monstr.eu, pmladek@suse.com, cai@lca.pw, rdunlap@infradead.org, robin.murphy@arm.com, sergey.senozhatsky@gmail.com, rostedt@goodmis.org, tiwai@suse.com, tytso@mit.edu, tglx@linutronix.de, gor@linux.ibm.com, wsa@the-dreams.de 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 in vmalloc region those metadata pages reside in [VMALLOC_END, VMALLOC_META_END), therefore we must sync a bigger memory region. Signed-off-by: Alexander Potapenko To: Alexander Potapenko Cc: Ingo Molnar Cc: Vegard Nossum Cc: Dmitry Vyukov Cc: Marco Elver Cc: Andrey Konovalov Cc: linux-mm@kvack.org Reviewed-by: Andrey Konovalov --- Change-Id: I0d54855489870ef1180b37fe2120b601da464bf7 --- arch/x86/mm/fault.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c index a51df516b87bf..d22e373fa2124 100644 --- a/arch/x86/mm/fault.c +++ b/arch/x86/mm/fault.c @@ -331,11 +331,21 @@ static void dump_pagetable(unsigned long address) void vmalloc_sync_mappings(void) { +#ifndef CONFIG_KMSAN /* * 64-bit mappings might allocate new p4d/pud pages * that need to be propagated to all tasks' PGDs. */ sync_global_pgds(VMALLOC_START & PGDIR_MASK, VMALLOC_END); +#else + /* + * For KMSAN, make sure metadata pages for vmalloc area and modules are + * also synced. + */ + sync_global_pgds(VMALLOC_START & PGDIR_MASK, VMALLOC_META_END); + sync_global_pgds(MODULES_SHADOW_START & PGDIR_MASK, + MODULES_ORIGIN_END); +#endif } void vmalloc_sync_unmappings(void) @@ -360,7 +370,17 @@ static noinline int vmalloc_fault(unsigned long address) pte_t *pte; /* Make sure we are in vmalloc area: */ +#ifdef CONFIG_KMSAN + /* + * For KMSAN, make sure metadata pages for vmalloc area and modules are + * also synced. + */ + if (!(address >= VMALLOC_START && address < VMALLOC_META_END) && + !(address >= MODULES_SHADOW_START && + address < MODULES_ORIGIN_END)) +#else if (!(address >= VMALLOC_START && address < VMALLOC_END)) +#endif return -1; /*