From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 92A24442138 for ; Mon, 10 Aug 2026 19:40:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786390822; cv=none; b=LdhHQWBSZ98Xn+7TAkh36aqJd8SI4xEL9S7/dNEFFhgR7PaZz+gWz9CY5io3jY3/l6r1Ia5uShT6Bo1Rd59OvoTmxxZXYRbUWHrXRdAA1u+rBbDnpqxckdXYZuFZudBZc133FqOO8wooH+ZIg78F52mvsS4w2BaUCtrbyaHMesc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786390822; c=relaxed/simple; bh=OnuXGl0ethdObH0aY05B9eSD0mR9fLVNfgoP5uzlc9M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YjdG+fLp2r9oa9EZXnYd5cP4y991B0VfjKwW8QxQckp8moFOBJMVrXwD6b1JSRR4KIxqwyrF5GXBACQDtuXsiNJjX9dgYoOlW6e0H+czuNN0cuA8ZojP+vyqgCR6KNkCBJIDjL52Iio1UzUa1bv7uhvuVc9KTIx5WNNFr6QnGp8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=FOCP1sN4; arc=none smtp.client-ip=209.85.218.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FOCP1sN4" Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-c1670dad7a8so316201866b.3 for ; Mon, 10 Aug 2026 12:40:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786390814; x=1786995614; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=QZEmNt2xvk8DgVJ1haHknaJRViHX9desP4cc5qWqOEo=; b=FOCP1sN4xu/bXIIcFusluqXnO14AC+/v5B2W44ClmpxSIxxWrrAV/2nuzL+8fxNUsp RiPdh/Yowp6NBEkq+lwuAeMNRsgAT1KAyI1KP48FlC6WYtmz0WJUGJ/uAg5qbABbzSG2 QmypcEJrajHUyQICRMKFZ1ClbsMphdZM8C24iv/yqoTJxJOtGYEK9DqE8ISob06+12DM xUxwzYGq0P81phORruOvHPXGJnXAluQsZQjdqoAVJ2b4/O1C+IWJL+i1AxCO1Yrepjqg uzdVm26dNE8owr112bSfe85UEsLonbxwV9dgCefLiGAdwQami13ZLQAt4SrRzHdh/+83 RMsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786390814; x=1786995614; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=QZEmNt2xvk8DgVJ1haHknaJRViHX9desP4cc5qWqOEo=; b=nC3FuPO8OSVaBdKoSWM+3fJVKlt1zBjvR+rvePIPqrODY0Xb/iLA8D0Rm8BuPPQDxN Wfq9vi4HQaAiiugwpvULTG9W40ccKt7qiYtGwgtj9FOoFBN5dOAWR5qrYng0IK3c9qUk Yqm1nSx7VfcpmDSyAeLm4KeKEGDRXHC5lE2jZ8DNhGWdHhQdkFg2ieEJAxUHeCKmSu5Z Vf15s4oL4RrDIjMJsFLSY8qbNrnTeDQML4EY5GB3DeACWKVn6GKgmEBwe0qcyNTMngq7 UtIwb9e3Oq05exKm0Joa+cBNR3J8ARC16a9x1nsUCf9s9IzMgQQ5xZP7LDPMjMNq70sd FY6w== X-Forwarded-Encrypted: i=1; AHgh+RosXPzZrRmmWryEADxBrd9W7J2dbn3lDoUMjyE1/wmirEfzknsysK+HId13TSP30RHtTw2TJ7KzGxtSn8M=@vger.kernel.org X-Gm-Message-State: AOJu0YxP0hNgLZPaFAZpHAX/EM/lJ0LdqJqlmOMuqzuUKWYRZWHOu9k2 dn6CI8dVBPt7klNzyaN721iJqcp0ABWgCfKPXOqdVYn0oyWkfjrOyrLv X-Gm-Gg: AR+sD12Hj2RMAAn43SK2gfMUEEoZvwfOf/UCPUPSR4Qc68Njr40cClksdMX+IkcQQi5 Vb9tlqRB1Gejmi4XQCEIl0L0a4zSqo0BRK0Y0TmsHp7+MULI9MV/9ro3gTWDwwXdPah72brSb4E m8BMY8rX18GmC3DfEumjvLyufbU8X6J9JwYfVphWT2h1RYvO9nIVx1EOK1wq4eFnXC0ePRuPS7i 6PvB3EZMXGgOtIBemdgBb5dsA4Oo7AAtCFKebLKGl/GSOJCOjSiQdX8MHVurgaA1dsDOP85G0dA CP8yjERCC2HMMbWlcNHfIqovCN9sBT31kglaovW+NUOG6uoCStMZwOAacV/Su8/gQMuZInWoZqg CG/DdfkNkslBQSkfuB0v1ys8pZ8u1DqnP1n1CbAwkgFjeZ7RKaHl1u6SVZ7bS8CIqfD5dyGGUYf p18GyRGUzY10/j6bHLYKXJdDzFSDCTxT65/9lSH04YLMXB+6uHPpkpLge+CKg2cUozpyHCGvnQl 6rNc3p21wo1+457L4YD09tOjzDLyTNhusHS3LNjfw== X-Received: by 2002:a17:907:6d0b:b0:c12:83da:7eeb with SMTP id a640c23a62f3a-c207ece5c9amr1238601866b.19.1786390813898; Mon, 10 Aug 2026 12:40:13 -0700 (PDT) Received: from buildhost.darklands.se ([2001:9b1:ff:d701:51eb:176f:63d9:53f8]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c2080a29a84sm449928966b.3.2026.08.10.12.40.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Aug 2026 12:40:13 -0700 (PDT) From: Magnus Lindholm To: richard.henderson@linaro.org, mattst88@gmail.com, linux-kernel@vger.kernel.org, linux-alpha@vger.kernel.org Cc: glaubitz@physik.fu-berlin.de, mcree@orcon.net.nz, ink@unseen.parts, macro@orcam.me.uk, Magnus Lindholm , stable@vger.kernel.org Subject: [PATCH v2 1/7] alpha: run check_mmu_context() from finish_arch_post_lock_switch() Date: Mon, 10 Aug 2026 21:34:52 +0200 Message-ID: <20260810193902.3286353-2-linmag7@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260810193902.3286353-1-linmag7@gmail.com> References: <20260810193902.3286353-1-linmag7@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit check_mmu_context() clears asn_lock and acts on need_new_asn, but it runs only as the tail of switch_to(), after alpha_switch_to() returns. A newly forked task never gets there: its first context switch resumes at ret_from_fork, which goes to schedule_tail() and then to user space rather than returning to the code following alpha_switch_to(). A new kernel thread reaches schedule_tail() the same way, through ret_from_kernel_thread(). asn_lock is left set on that CPU, so the forked task runs user space with it set and interrupts enabled. A TLB shootdown IPI arriving in that window takes the deferred path, and the need_new_asn handshake meant to cover that never runs. finish_task_switch() calls finish_arch_post_lock_switch() with preemption disabled, on the CPU that ran switch_mm(), so hooking check_mmu_context() there completes the bookkeeping for both. The existing call from switch_to() then becomes redundant, since finish_task_switch() runs immediately afterwards and does the same work, so drop it. kthread_use_mm() and sched_force_init_mm() reach the same hook outside the scheduler's preemption-disabled switch tail, where the CPU may have changed since switch_mm(). check_mmu_context() acts on per-CPU state, so testing preemptible() expresses the required condition directly rather than naming particular callers. One consequence is worth stating, because the TLB patches that follow depend on it. After kthread_use_mm() the hook does nothing, so the asn_lock that ev5_switch_mm() set stays on that CPU until the next real context switch. A borrowed mm therefore has current->mm set while its context is not loaded, and the shootdown handlers rely on asn_locked() being true to take the conservative path for the whole of that window. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Cc: stable@vger.kernel.org Signed-off-by: Magnus Lindholm --- arch/alpha/include/asm/mmu_context.h | 8 ++++++++ arch/alpha/include/asm/switch_to.h | 1 - 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/arch/alpha/include/asm/mmu_context.h b/arch/alpha/include/asm/mmu_context.h index eee8fe836a59..825d3b9605c9 100644 --- a/arch/alpha/include/asm/mmu_context.h +++ b/arch/alpha/include/asm/mmu_context.h @@ -181,6 +181,14 @@ do { \ #define check_mmu_context() do { } while(0) #endif +/* Per-CPU state: only safe while still on the switching CPU. */ +#define finish_arch_post_lock_switch finish_arch_post_lock_switch +static inline void finish_arch_post_lock_switch(void) +{ + if (!preemptible()) + check_mmu_context(); +} + __EXTERN_INLINE void ev5_activate_mm(struct mm_struct *prev_mm, struct mm_struct *next_mm) { diff --git a/arch/alpha/include/asm/switch_to.h b/arch/alpha/include/asm/switch_to.h index 762b7f975310..35c4b2c9d992 100644 --- a/arch/alpha/include/asm/switch_to.h +++ b/arch/alpha/include/asm/switch_to.h @@ -9,7 +9,6 @@ extern struct task_struct *alpha_switch_to(unsigned long, struct task_struct *); #define switch_to(P,N,L) \ do { \ (L) = alpha_switch_to(virt_to_phys(&task_thread_info(N)->pcb), (P)); \ - check_mmu_context(); \ } while (0) #endif /* __ALPHA_SWITCH_TO_H */ -- 2.53.0