Message ID | 20250110-asi-rfc-v2-v2-8-8419288bc805@google.com (mailing list archive) |
---|---|
State | New |
Headers | show
Return-Path: <owner-linux-mm@kvack.org> 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 66547E77188 for <linux-mm@archiver.kernel.org>; Fri, 10 Jan 2025 18:41:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CF97D6B00C5; Fri, 10 Jan 2025 13:41:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CA8AA6B00C6; Fri, 10 Jan 2025 13:41:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A90CE6B00C7; Fri, 10 Jan 2025 13:41:07 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 88ABB6B00C5 for <linux-mm@kvack.org>; Fri, 10 Jan 2025 13:41:07 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 3F0B6160CE5 for <linux-mm@kvack.org>; Fri, 10 Jan 2025 18:41:07 +0000 (UTC) X-FDA: 82992409374.03.1394861 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) by imf08.hostedemail.com (Postfix) with ESMTP id 5B9C216001D for <linux-mm@kvack.org>; Fri, 10 Jan 2025 18:41:05 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=LJMQ0emg; spf=pass (imf08.hostedemail.com: domain of 3v2mBZwgKCNoF68GI6J7CKKCHA.8KIHEJQT-IIGR68G.KNC@flex--jackmanb.bounces.google.com designates 209.85.128.73 as permitted sender) smtp.mailfrom=3v2mBZwgKCNoF68GI6J7CKKCHA.8KIHEJQT-IIGR68G.KNC@flex--jackmanb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736534465; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=NdZ1cQRVb5G6t/AzbRzOJmiK1PmEXn2j4H5pJNPFFDE=; b=cS9aBKFFB5r0bzpQk2ImOm+KX03rQnUkNqNZu8QKxOJ6n6B3OLFX5Rva/Pot/nbTYyhb2r MTdxyDvtwCJWMmYItLQc486QC0Hh4SN3I3RTwMURwTu/e/7qb3sveVXReWdPbUBKV5mvp2 hrvn+CWLFjmb6Z9zeC2JPXPZi4BLQoA= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=LJMQ0emg; spf=pass (imf08.hostedemail.com: domain of 3v2mBZwgKCNoF68GI6J7CKKCHA.8KIHEJQT-IIGR68G.KNC@flex--jackmanb.bounces.google.com designates 209.85.128.73 as permitted sender) smtp.mailfrom=3v2mBZwgKCNoF68GI6J7CKKCHA.8KIHEJQT-IIGR68G.KNC@flex--jackmanb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736534465; a=rsa-sha256; cv=none; b=PpK/qO/OaiaH2iAAgeKYZxGqtZnTa6oDENL9+eT84FH6ModR047u+dNULQPyZ1ix1tQOS2 dhXStHc3ZqB3aAjHKCsfvrGdknM26EMjJh3XSyikkMZHozpADJvNeO5J/9SBvyeI60P2vY Qfh2mSeoH8k6IMfQGKcLVXzgk979zw0= Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-436379713baso11446195e9.2 for <linux-mm@kvack.org>; Fri, 10 Jan 2025 10:41:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1736534464; x=1737139264; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=NdZ1cQRVb5G6t/AzbRzOJmiK1PmEXn2j4H5pJNPFFDE=; b=LJMQ0emgDdWpM4MwphRJM7K0TV0cEYm/XewpM/QdG6Tgj+MLiLfUOoosvGOtbGFAUK ve5ZiQh31iKGeNmzmWRLBCqImHDi9PrmqVGG3sGDNtJ+AjfQmzx4OF0WBSRp1Nc4Esi+ jyEssjQrFCow1Cv3aZp6V7WPM5+RUQpoYDAjLGDKVCtqtOqE1qNvuyG+URuaXHoefbxw 5k0wHz5IrghM05+nQa0Lf73LGGq4fc6pmKSoCHz6s8D+RvSHzjQSeExoqx4+FUGjjGVh vFlW21ogRhAGbbJuH7D6ACw5DohZJCwB58HEflNejAz8bFLln5SFSG6zg94cr/adWmuS Uo9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736534464; x=1737139264; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=NdZ1cQRVb5G6t/AzbRzOJmiK1PmEXn2j4H5pJNPFFDE=; b=bjM9rfQ3f9eHYTf8Svhkzyz0ZuJskhoaQI9fJAA4ziuPyRNIZxr8Riaut0SMNs1QUz 6X6Xq0TPu4EkWDv5eHXq7csR+zGhPKRUgf1A/3edhHND9m1XB+nuQi3TWimEWMraNmoE 86wq4eyXSpowIls84eDtK96m5HlKMAhXYyCmD2Pa8jej5pBCxiu9rClV7u9fwk4qzjbF WEJo4D7PWqol7YZScjctffosVxdEraefgKCnvxsrV4Mj6SWjN70Wc2UwF0lmZeSHveiD 5CCqtTe+6ihhSs1PCg1IFBt7bR5nq22dF+y6mdnBaWtCNVQ5QUhIk5uI6qqjC3SJpouV 4W9w== X-Forwarded-Encrypted: i=1; AJvYcCUY4dOX5DgBN43EsqbEIpOfdbJZ1Er5xb/2LOpchBy1tstNNto9YHqboEYGmdi63huoOLkgU1dyTQ==@kvack.org X-Gm-Message-State: AOJu0YwKSoCV7bdKmoPTgDEg+5W2Tg36JSDkZXP+beBv5Gw1RDm/MVyL 8YIMg8rFpIDcc46d/2t4WYB8k9GgT7WJYuExR0rRd6JGv9UcbFGN5XPPvEE7FIN7GxkAATuGpZB 63Y5H2VXKpA== X-Google-Smtp-Source: AGHT+IHOqPqFuZt9UmOoUeA2JDIFLsGLn/JF5TCYjoXI0XK4RQVEWWzyMiwW2MB3CIHY3dySJS8wD0E+4CgsAA== X-Received: from wmgg11.prod.google.com ([2002:a05:600d:b:b0:434:ff52:1c7]) (user=jackmanb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:4ed3:b0:434:f7e3:bfbd with SMTP id 5b1f17b1804b1-436e26dda8cmr98320145e9.23.1736534463780; Fri, 10 Jan 2025 10:41:03 -0800 (PST) Date: Fri, 10 Jan 2025 18:40:34 +0000 In-Reply-To: <20250110-asi-rfc-v2-v2-0-8419288bc805@google.com> Mime-Version: 1.0 References: <20250110-asi-rfc-v2-v2-0-8419288bc805@google.com> X-Mailer: b4 0.15-dev Message-ID: <20250110-asi-rfc-v2-v2-8-8419288bc805@google.com> Subject: [PATCH RFC v2 08/29] mm: asi: Avoid warning from NMI userspace accesses in ASI context From: Brendan Jackman <jackmanb@google.com> To: Thomas Gleixner <tglx@linutronix.de>, Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>, Dave Hansen <dave.hansen@linux.intel.com>, "H. Peter Anvin" <hpa@zytor.com>, Andy Lutomirski <luto@kernel.org>, Peter Zijlstra <peterz@infradead.org>, Richard Henderson <richard.henderson@linaro.org>, Matt Turner <mattst88@gmail.com>, Vineet Gupta <vgupta@kernel.org>, Russell King <linux@armlinux.org.uk>, Catalin Marinas <catalin.marinas@arm.com>, Will Deacon <will@kernel.org>, Guo Ren <guoren@kernel.org>, Brian Cain <bcain@quicinc.com>, Huacai Chen <chenhuacai@kernel.org>, WANG Xuerui <kernel@xen0n.name>, Geert Uytterhoeven <geert@linux-m68k.org>, Michal Simek <monstr@monstr.eu>, Thomas Bogendoerfer <tsbogend@alpha.franken.de>, Dinh Nguyen <dinguyen@kernel.org>, Jonas Bonn <jonas@southpole.se>, Stefan Kristiansson <stefan.kristiansson@saunalahti.fi>, Stafford Horne <shorne@gmail.com>, "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>, Helge Deller <deller@gmx.de>, Michael Ellerman <mpe@ellerman.id.au>, Nicholas Piggin <npiggin@gmail.com>, Christophe Leroy <christophe.leroy@csgroup.eu>, Naveen N Rao <naveen@kernel.org>, Madhavan Srinivasan <maddy@linux.ibm.com>, Paul Walmsley <paul.walmsley@sifive.com>, Palmer Dabbelt <palmer@dabbelt.com>, Albert Ou <aou@eecs.berkeley.edu>, Heiko Carstens <hca@linux.ibm.com>, Vasily Gorbik <gor@linux.ibm.com>, Alexander Gordeev <agordeev@linux.ibm.com>, Christian Borntraeger <borntraeger@linux.ibm.com>, Sven Schnelle <svens@linux.ibm.com>, Yoshinori Sato <ysato@users.sourceforge.jp>, Rich Felker <dalias@libc.org>, John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>, "David S. Miller" <davem@davemloft.net>, Andreas Larsson <andreas@gaisler.com>, Richard Weinberger <richard@nod.at>, Anton Ivanov <anton.ivanov@cambridgegreys.com>, Johannes Berg <johannes@sipsolutions.net>, Chris Zankel <chris@zankel.net>, Max Filippov <jcmvbkbc@gmail.com>, Arnd Bergmann <arnd@arndb.de>, Andrew Morton <akpm@linux-foundation.org>, Juri Lelli <juri.lelli@redhat.com>, Vincent Guittot <vincent.guittot@linaro.org>, Dietmar Eggemann <dietmar.eggemann@arm.com>, Steven Rostedt <rostedt@goodmis.org>, Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>, Valentin Schneider <vschneid@redhat.com>, Uladzislau Rezki <urezki@gmail.com>, Christoph Hellwig <hch@infradead.org>, Masami Hiramatsu <mhiramat@kernel.org>, Mathieu Desnoyers <mathieu.desnoyers@efficios.com>, Mike Rapoport <rppt@kernel.org>, Arnaldo Carvalho de Melo <acme@kernel.org>, Namhyung Kim <namhyung@kernel.org>, Mark Rutland <mark.rutland@arm.com>, Alexander Shishkin <alexander.shishkin@linux.intel.com>, Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>, Adrian Hunter <adrian.hunter@intel.com>, Dennis Zhou <dennis@kernel.org>, Tejun Heo <tj@kernel.org>, Christoph Lameter <cl@linux.com>, Sean Christopherson <seanjc@google.com>, Paolo Bonzini <pbonzini@redhat.com>, Ard Biesheuvel <ardb@kernel.org>, Josh Poimboeuf <jpoimboe@kernel.org>, Pawan Gupta <pawan.kumar.gupta@linux.intel.com> Cc: x86@kernel.org, linux-kernel@vger.kernel.org, linux-alpha@vger.kernel.org, linux-snps-arc@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-csky@vger.kernel.org, linux-hexagon@vger.kernel.org, loongarch@lists.linux.dev, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, linux-openrisc@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-um@lists.infradead.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-trace-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, kvm@vger.kernel.org, linux-efi@vger.kernel.org, Brendan Jackman <jackmanb@google.com>, Junaid Shahid <junaids@google.com>, Yosry Ahmed <yosryahmed@google.com> Content-Type: text/plain; charset="utf-8" X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 5B9C216001D X-Rspam-User: X-Stat-Signature: hsuhjmpf85za6dz96u9xeytd7ibb4mcy X-HE-Tag: 1736534465-989166 X-HE-Meta: U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xsxQA2ohm+sO9DaYADgZstWA3+y6486MscB4/VKOGkKK1veIK8Hy+SBEnK1/3n3yLpvu9VqxgW5rdUcH9UAxKrQtt48rzqv4PPC3D98OSyLJBTWmcoWebw8Lju7gFxHhGlgLRBOMBFVmVTlVb7YNvOTfEGCwa9mbFSFpi1FOwaAk+VmhPmPCHeFDTeJG3WP8/4NVWpQgx003EYVGuGFzUX01eY0zIne2Elru1yf5oH/2pSmF4CDlfu0Tynyk3ZMPvC/RflNGVzNpHsK/tGz4QcAQ8id7LO/dk1Y1kRT7DFeFbFRzNityxLwtZ7ZNOikJLzeeEs7QxRLaXm5onMNWa+NG+CSIw0Gozb7HjydzCUxA/JZJKPlLccV4Sj5QW3EPSS+6m7ZudncTbS7bfRW/W4Uuh3xdI6S+nmp5AesqPPPEW9kLXg7nEraD+1p484RH7uH873+fW793R2lqFGlic5lWy2/Ydkq7MKyojXzOuTLxEkHZldaMDxpVmK7V5m4q2cDSyA== 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: <linux-mm.kvack.org> List-Subscribe: <mailto:majordomo@kvack.org> List-Unsubscribe: <mailto:majordomo@kvack.org> |
Series |
Address Space Isolation (ASI)
|
expand
|
diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c index b2a13fdab0c6454c1d9d4e3338801f3402da4191..c41e083c5b5281684be79ad0391c1a5fc7b0c493 100644 --- a/arch/x86/mm/tlb.c +++ b/arch/x86/mm/tlb.c @@ -1340,6 +1340,22 @@ void arch_tlbbatch_flush(struct arch_tlbflush_unmap_batch *batch) put_cpu(); } +static inline bool cr3_matches_current_mm(void) +{ + struct asi *asi = asi_get_current(); + pgd_t *pgd_asi = asi_pgd(asi); + pgd_t *pgd_cr3; + + /* + * Prevent read_cr3_pa -> [NMI, asi_exit] -> asi_get_current, + * otherwise we might find CR3 pointing to the ASI PGD but not + * find a current ASI domain. + */ + barrier(); + pgd_cr3 = __va(read_cr3_pa()); + return pgd_cr3 == current->mm->pgd || pgd_cr3 == pgd_asi; +} + /* * Blindly accessing user memory from NMI context can be dangerous * if we're in the middle of switching the current user task or @@ -1355,10 +1371,10 @@ bool nmi_uaccess_okay(void) VM_WARN_ON_ONCE(!loaded_mm); /* - * The condition we want to check is - * current_mm->pgd == __va(read_cr3_pa()). This may be slow, though, - * if we're running in a VM with shadow paging, and nmi_uaccess_okay() - * is supposed to be reasonably fast. + * The condition we want to check that CR3 points to either + * current_mm->pgd or an appropriate ASI PGD. Reading CR3 may be slow, + * though, if we're running in a VM with shadow paging, and + * nmi_uaccess_okay() is supposed to be reasonably fast. * * Instead, we check the almost equivalent but somewhat conservative * condition below, and we rely on the fact that switch_mm_irqs_off() @@ -1367,7 +1383,7 @@ bool nmi_uaccess_okay(void) if (loaded_mm != current_mm) return false; - VM_WARN_ON_ONCE(current_mm->pgd != __va(read_cr3_pa())); + VM_WARN_ON_ONCE(!cr3_matches_current_mm()); return true; }