From patchwork Fri Jan 10 18:40:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brendan Jackman X-Patchwork-Id: 13935248 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 53B2DE7719D for ; Fri, 10 Jan 2025 18:41:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 61CE18D000A; Fri, 10 Jan 2025 13:41:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5CC7C8D0005; Fri, 10 Jan 2025 13:41:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3F94C8D000A; Fri, 10 Jan 2025 13:41:32 -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 1F4448D0005 for ; Fri, 10 Jan 2025 13:41:32 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id D7FEBAE2BF for ; Fri, 10 Jan 2025 18:41:31 +0000 (UTC) X-FDA: 82992410382.09.4552A9E Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) by imf22.hostedemail.com (Postfix) with ESMTP id 10EEBC0004 for ; Fri, 10 Jan 2025 18:41:29 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=fjAzo60e; spf=pass (imf22.hostedemail.com: domain of 32GmBZwgKCPMeVXfhViWbjjbgZ.Xjhgdips-hhfqVXf.jmb@flex--jackmanb.bounces.google.com designates 209.85.128.73 as permitted sender) smtp.mailfrom=32GmBZwgKCPMeVXfhViWbjjbgZ.Xjhgdips-hhfqVXf.jmb@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=1736534490; 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=lgAtsH7tF25YqHAENGvYLMvhBopdecMcg5W9s6t9Qm4=; b=WS0P8RWmA2nLe7fSQVg47w3XUYlHVG1fTdCFNqd3IMC1cXMwm2cB1NSLMc0Cr9DRqAUBVk DUcsgNN/gcxHrt/oaZa2D2xj8MMaDbS9vj+s/rqDsIwGxdH152uxRWHgfjC6pB5vJgeTfs w9Zp6JrE5hoBq+rdnhHbDBZkxk1N9vg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736534490; a=rsa-sha256; cv=none; b=HLbjdVEyVrltN/K/lbL9TPegukqrNDGqA7ODO2vLb+3UyXnT9yDH/1jCJU2NKURJMOuF3u YMHDEpBlCormY4vLV3GdCO5cTF5BU499qcyBcN08LcXX2oDrTLhXMBLBJOA2Qb6WATpIeW IqEuz9cZ8b5GQvtzmq1ob+u4VL/PU1M= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=fjAzo60e; spf=pass (imf22.hostedemail.com: domain of 32GmBZwgKCPMeVXfhViWbjjbgZ.Xjhgdips-hhfqVXf.jmb@flex--jackmanb.bounces.google.com designates 209.85.128.73 as permitted sender) smtp.mailfrom=32GmBZwgKCPMeVXfhViWbjjbgZ.Xjhgdips-hhfqVXf.jmb@flex--jackmanb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-4362f893bfaso12711825e9.1 for ; Fri, 10 Jan 2025 10:41:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1736534489; x=1737139289; 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=lgAtsH7tF25YqHAENGvYLMvhBopdecMcg5W9s6t9Qm4=; b=fjAzo60eXb2GkfvMIttPy4SgfvC4ZjLMpJXbxpw0xe3EsCHdKuo6lhVSgLnZvGvQ7n lNxKeQrRRzUwM2IlGPjnc3P5YFIWhiEjIz3AXZ5gPVq4Y51LiNv6likBc6BAat7/gY59 qdZfC6e/+D0W7mvThAPqYMqqwrZq69r61MTDocfoHBrYqFUz0YhR6aIzkvpWjYWrhDD+ QY2utnc+ejhFuezyrlKn5FvCPvyfimJcaiOAYaXyYVwHKnU8S7IPBsCUfwrGXU+tkWCE +ApA8s/PdHa52Y93yPEgJzjJzG2CCHcRcwBZwfpJrxoj2TTmx2jPMf4LE6ItoAEEMeye mgog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736534489; x=1737139289; 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=lgAtsH7tF25YqHAENGvYLMvhBopdecMcg5W9s6t9Qm4=; b=oCCmhvenDZ0qzImqXbW1S+FN4WLhxnk4dsS/hdIW0o2/MUNdHfrkC/1hMjuoO4ivDb kfbK4EHJrLc9P61OWx/TuH5Zixcn8rQPbowV8PKpc1/Lz2+96oXwBJbjFoFgeRYWF7Sy ORL8C8GuffcV/J6hWVkPWF/Bjlu0LbyieWAAju8KfqbmVlsEJaTx1nkfC2phOgjcWDj4 98B+bc0pHa4scoSMyoi0ZWnvDWWHCdrI86REka8YQHBtOkTTPt0tqczhl/endlyR+4uH XKXYmKN/XkFNShY02NBc+gBRek6vEL0CH6nNILDaacyAXDV3JplU0Oka5cFbw/H12jtt 9riQ== X-Forwarded-Encrypted: i=1; AJvYcCWYGaAfhSgbTGgunh7uA1usK+hek0GJQWQuxpfpBmmG7wHSfGhnzvCd917OFnhFCeg6zMvgSANCxg==@kvack.org X-Gm-Message-State: AOJu0Yw2exnFYvTftV3eJUHMs2m9357yGkl4XrTht3fzl3SyRD6IZIOg jVq4xx/g5RqFoXpFY4MfrRGhIi+eO4J5uJzw8NiRb6wK599Ca0NuFQXnlwXTazKY34b4Me2Z/XV MdZFPwAlQ6g== X-Google-Smtp-Source: AGHT+IFeKlzdEnxlsx468YN6J+lzj2fJ2REIK9m1LE7fZOV2UV2JrR/PAzf48/PWmJ/jsXO7ZyblIN12CqtAPQ== X-Received: from wmqa17.prod.google.com ([2002:a05:600c:3491:b0:434:fa72:f1bf]) (user=jackmanb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:4586:b0:434:9e1d:7626 with SMTP id 5b1f17b1804b1-436e26f4b91mr97248925e9.25.1736534488470; Fri, 10 Jan 2025 10:41:28 -0800 (PST) Date: Fri, 10 Jan 2025 18:40:45 +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-19-8419288bc805@google.com> Subject: [PATCH RFC v2 19/29] mm: asi: Stabilize CR3 in switch_mm_irqs_off() From: Brendan Jackman To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Andy Lutomirski , Peter Zijlstra , Richard Henderson , Matt Turner , Vineet Gupta , Russell King , Catalin Marinas , Will Deacon , Guo Ren , Brian Cain , Huacai Chen , WANG Xuerui , Geert Uytterhoeven , Michal Simek , Thomas Bogendoerfer , Dinh Nguyen , Jonas Bonn , Stefan Kristiansson , Stafford Horne , "James E.J. Bottomley" , Helge Deller , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Naveen N Rao , Madhavan Srinivasan , Paul Walmsley , Palmer Dabbelt , Albert Ou , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Yoshinori Sato , Rich Felker , John Paul Adrian Glaubitz , "David S. Miller" , Andreas Larsson , Richard Weinberger , Anton Ivanov , Johannes Berg , Chris Zankel , Max Filippov , Arnd Bergmann , Andrew Morton , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , Uladzislau Rezki , Christoph Hellwig , Masami Hiramatsu , Mathieu Desnoyers , Mike Rapoport , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Dennis Zhou , Tejun Heo , Christoph Lameter , Sean Christopherson , Paolo Bonzini , Ard Biesheuvel , Josh Poimboeuf , Pawan Gupta 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 X-Rspamd-Queue-Id: 10EEBC0004 X-Rspam-User: X-Rspamd-Server: rspam07 X-Stat-Signature: zz1u3kn7kb6cwnmb3a67kb7r3bgocfu9 X-HE-Tag: 1736534489-858840 X-HE-Meta: U2FsdGVkX18ur+VNV9HZJH5HsK/p/2Z+p0y4P8NMsU7cpXIs+sgeuYwDtF3SLeEvLBPwLabE2SFX4ARZuzD0dP/4uzUlVG7CwV/rT20kDijOQdWSdHt8A+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FOucOMmqKLr6DyOYTLCRmjN+taQhYYpRuWo01W5BkkCB0G9Gu84bFkyn8rJYYdE22TK+26cBd05bpCpV+kO2A3Kr27OB/yhaX7Gp5j2FgkWeZRZ/nsVyeNpHY4DhSeFe1L6f/56rwRWixtj/hnPNTmg3lCfgC6h+jswzwbgsmsTpcD7ZcQCVYI3loxNaLJQ5prxByg3btLM7IBUKLWgB76/D9BdXITF9rzaplbCH98AP6bj8HGigleW3BwwxTgX7rAt6atKOis1BXByjOjIi+buqQjaJRP1WfDzFZofEuMFehkf9FycutgsBgbOaEwRiLMPZkEpNwsYhJPJ8XMHaexzfc7CwZmY3ufRPrY1Lw53FQV0iPj6cvfEbs+GxJYUd8yP0UZmBXjLvXapaN8XxBo= 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: List-Subscribe: List-Unsubscribe: An ASI-restricted CR3 is unstable as interrupts can cause ASI-exits. Although we already unconditionally ASI-exit during context-switch, and before returning from the VM-run path, it's still possible to reach switch_mm_irqs_off() in a restricted context, because KVM code updates static keys, which requires using a temporary mm. Signed-off-by: Brendan Jackman --- arch/x86/mm/tlb.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c index c55733e144c7538ce7f97b74ea2b1b9c22497c32..ce5598f96ea7a84dc0e8623022ab5bfbba401b48 100644 --- a/arch/x86/mm/tlb.c +++ b/arch/x86/mm/tlb.c @@ -546,6 +546,9 @@ void switch_mm_irqs_off(struct mm_struct *unused, struct mm_struct *next, bool need_flush; u16 new_asid; + /* Stabilize CR3, before reading or writing CR3 */ + asi_exit(); + /* We don't want flush_tlb_func() to run concurrently with us. */ if (IS_ENABLED(CONFIG_PROVE_LOCKING)) WARN_ON_ONCE(!irqs_disabled());