From patchwork Sun Mar 2 14:55:54 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 13997842 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 70831C282C6 for ; Sun, 2 Mar 2025 14:56:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F0BAE6B0089; Sun, 2 Mar 2025 09:56:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EBB616B008A; Sun, 2 Mar 2025 09:56:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D81456B008C; Sun, 2 Mar 2025 09:56:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id BA49B6B0089 for ; Sun, 2 Mar 2025 09:56:21 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 75D6E1A0199 for ; Sun, 2 Mar 2025 14:56:21 +0000 (UTC) X-FDA: 83176911762.18.53D7AD6 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf12.hostedemail.com (Postfix) with ESMTP id CA3AB40006 for ; Sun, 2 Mar 2025 14:56:19 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=none; spf=pass (imf12.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1740927380; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3m2pAygD+EMdTPBq71HILz1nyiOak8HVJYf6iQSblHs=; b=ajORdI6KnaKkdXOrdCt4YIiS9qotOX1lR/+xOihepmhGV6jSCm11SANVCEkOHLy4uy5dym kF9dODTjcAWcjdOiO9UtRCgBZFCUDzeJpYnmSbii7H0CV53hKEkR0Y2Fn3xmNJg+4Xm7Lh BdTMIPU+nk5S3FsZbKOfHM7DyONky/s= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=none; spf=pass (imf12.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1740927380; a=rsa-sha256; cv=none; b=VHR4wpb5H4qX7sAZoAecdybM6XjizRH8fHQN+4j9clQrQatum2ApYd/HBLPMDlF8YlbxH+ 0cDxOfm8QYiiJgifI4kGoJAe9QGa8J9CVLZzEXs0BfNB7TeZ2Nr7EoL0vKujjgSYazDDju CWtZosxtl1U5QyeM39RpxiHePPbrgbw= Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9B79A16F8; Sun, 2 Mar 2025 06:56:33 -0800 (PST) Received: from e125769.cambridge.arm.com (e125769.cambridge.arm.com [10.1.196.27]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id CB8B43F5A1; Sun, 2 Mar 2025 06:56:16 -0800 (PST) From: Ryan Roberts To: Andrew Morton , "David S. Miller" , Andreas Larsson , Juergen Gross , Boris Ostrovsky , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , "Matthew Wilcox (Oracle)" , Catalin Marinas Cc: Ryan Roberts , linux-mm@kvack.org, sparclinux@vger.kernel.org, xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 4/4] Revert "x86/xen: allow nesting of same lazy mode" Date: Sun, 2 Mar 2025 14:55:54 +0000 Message-ID: <20250302145555.3236789-5-ryan.roberts@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250302145555.3236789-1-ryan.roberts@arm.com> References: <20250302145555.3236789-1-ryan.roberts@arm.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: CA3AB40006 X-Rspamd-Server: rspam09 X-Stat-Signature: oufztyakj1q47ntxj49gks6sy569jsw8 X-HE-Tag: 1740927379-31448 X-HE-Meta: U2FsdGVkX1/06ASCepttRsedI7tVoP/paJ+dhRZeDF8aZFgY3CPsmjjt32VLfRt2SCp+2zxSXvHMggjcsyXT2w7NzV36N9+24gHmy7Pw60aKYyU5rIbQv/kysyzN2jV8Wg+Xi7SqbHaT0wOZIFD8ymU/ArP9PFOb/ijymmI777ke1B0Xj8N4dOb+jjFZ3mStWHtCdHNTz9hBLqMmdhnybULEtau3EN6p2D8uKiyGF87Hy3L5WwZK0AxI3td3nLhEMBAxZCCY69aSi/8DPII7Jbby8Vk3p28qRjbz6avf33miH8W0P7kCWa8ssXqvhdIftsN710LnPWpzwih917RgwKlx636V8rzwAZZOVHVMMgtf/dkoa8axokt/g59re5iEmhOB3PHB8N3tC3ekt7r7atbfbS2yOC5NrrruSC1GsWvafEagf173gml9Kig4IG8s4MhB7e5UeKLtMXD0aZ9ISm5KqfI53JyvEjczrLI+dgdQlI6UIRLVcF/5DiwCTZvXzq7qUZG/dQfT9JFiJarcnt01OHUxN8QlKjlCUCbnzY6eM9zQmIc/4mF7i95vIFgY3WThMyNgAjdAI+Zh6gR7/sS7fn3cBvkonLdTv9h3ygaBiSIvVzVPfpVRPqi/X22uNg8pilJe9KbpJKl/LWqhtoEh4H+RCt1uvwy8+JnUERMvfxu0+1V73RGirtyO5m2rS8Naoqalxz1es7Yk/klwU2Qtw85go7xyEEVYtd2bvJ6laADfRVne/0/TZwUQk3RnE3KZkpLHwRsmLnUFbdgFatBA1AAAODQT1nXdlkjimBPJ1oHC3Rk88aWgN9wa6h+AcUkywe7Y9X1rKdDAJrTBIXBbDopFeNbEpzmb4Wkz0E0B2/eL1kMdS3ztL0hc4cB9nJoGyCHyXkwZ4Zfy7El1DSVilCQlve1NP4ms4VyQgrkLjuK8zUzSK2+sK6M8B9X2bavIqzVC+32Ok1wPv9T ocCZTAML GTGiBdDhEJI/wd+XiprJYbu6h6ZJSFyDcslgl/fUuMHbaK74rxbWIaufdCPT36Zw6NDFkALZim6W5kx3TYwtAwwv7OEocbq1A3kIfM9GaebdrNDz805d8SYZ28V7Rm66QVCewA1zaOS6xF7YlK/eNagUyvw== 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: Commit 49147beb0ccb ("x86/xen: allow nesting of same lazy mode") was added as a solution for a core-mm code change where arch_[enter|leave]_lazy_mmu_mode() started to be called in a nested manner; see commit bcc6cc832573 ("mm: add default definition of set_ptes()"). However, now that we have fixed the API to avoid nesting, we no longer need this capability in the x86 implementation. Additionally, from code review, I don't believe the fix was ever robust in the case of preemption occurring while in the nested lazy mode. The implementation usually deals with preemption by calling arch_leave_lazy_mmu_mode() from xen_start_context_switch() for the outgoing task if we are in the lazy mmu mode. Then in xen_end_context_switch(), it restarts the lazy mode by calling arch_enter_lazy_mmu_mode() for an incoming task that was in the lazy mode when it was switched out. But arch_leave_lazy_mmu_mode() will only unwind a single level of nesting. If we are in the double nest, then it's not fully unwound and per-cpu variables are left in a bad state. So the correct solution is to remove the possibility of nesting from the higher level (which has now been done) and remove this x86-specific solution. Fixes: 49147beb0ccb ("x86/xen: allow nesting of same lazy mode") Signed-off-by: Ryan Roberts Acked-by: David Hildenbrand --- arch/x86/include/asm/xen/hypervisor.h | 15 ++------------- arch/x86/xen/enlighten_pv.c | 1 - 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/arch/x86/include/asm/xen/hypervisor.h b/arch/x86/include/asm/xen/hypervisor.h index a9088250770f..bd0fc69a10a7 100644 --- a/arch/x86/include/asm/xen/hypervisor.h +++ b/arch/x86/include/asm/xen/hypervisor.h @@ -72,18 +72,10 @@ enum xen_lazy_mode { }; DECLARE_PER_CPU(enum xen_lazy_mode, xen_lazy_mode); -DECLARE_PER_CPU(unsigned int, xen_lazy_nesting); static inline void enter_lazy(enum xen_lazy_mode mode) { - enum xen_lazy_mode old_mode = this_cpu_read(xen_lazy_mode); - - if (mode == old_mode) { - this_cpu_inc(xen_lazy_nesting); - return; - } - - BUG_ON(old_mode != XEN_LAZY_NONE); + BUG_ON(this_cpu_read(xen_lazy_mode) != XEN_LAZY_NONE); this_cpu_write(xen_lazy_mode, mode); } @@ -92,10 +84,7 @@ static inline void leave_lazy(enum xen_lazy_mode mode) { BUG_ON(this_cpu_read(xen_lazy_mode) != mode); - if (this_cpu_read(xen_lazy_nesting) == 0) - this_cpu_write(xen_lazy_mode, XEN_LAZY_NONE); - else - this_cpu_dec(xen_lazy_nesting); + this_cpu_write(xen_lazy_mode, XEN_LAZY_NONE); } enum xen_lazy_mode xen_get_lazy_mode(void); diff --git a/arch/x86/xen/enlighten_pv.c b/arch/x86/xen/enlighten_pv.c index 5e57835e999d..919e4df9380b 100644 --- a/arch/x86/xen/enlighten_pv.c +++ b/arch/x86/xen/enlighten_pv.c @@ -99,7 +99,6 @@ struct tls_descs { }; DEFINE_PER_CPU(enum xen_lazy_mode, xen_lazy_mode) = XEN_LAZY_NONE; -DEFINE_PER_CPU(unsigned int, xen_lazy_nesting); enum xen_lazy_mode xen_get_lazy_mode(void) {