From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F23D13DDDDA for ; Tue, 16 Jun 2026 19:03:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=96.67.55.147 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781636640; cv=none; b=qYxLPvHO9a1MwH13JUrrcaP3bifTWpmDANzMTzZoV2Zs5h+jNqBag4BQIC81vOkFMm3ZIVWwSDQF0P0iWDiFVaCHSVc04YePAITesoAkDhvsGYpzBvV0+svDIbBtBvEI35L2xKKd3h06C83PXIDPj/q4fZW99tOiz5yv2J49wdM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781636640; c=relaxed/simple; bh=76cKbQYjhHxeAM9uXo9P0GQ8hJwXD/O2U66YHE4YOJQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YgRtwjOWz+0gZFjnQrn1sp6VEg5eLHsFmzSJIr3tYAft7+3f5xD0Dsu8rH5wJL9VuezN6rY97/Fvc6lIWvLLAx4GVcx0csjHXv1Jr8bAPAZ9UHY8SQaPc1FN2z9TqfsJVFazGosB+xOxXAvVUb1vAgJqLdTlcUqOts6HwcRnGVw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=surriel.com; spf=pass smtp.mailfrom=surriel.com; dkim=pass (2048-bit key) header.d=surriel.com header.i=@surriel.com header.b=btGYs9sM; arc=none smtp.client-ip=96.67.55.147 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=surriel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=surriel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=surriel.com header.i=@surriel.com header.b="btGYs9sM" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=surriel.com ; s=mail; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=MOvX4RZR/pDRt2jv/Wl1jQyJJ9xmvr29K3ndLYIsFzU=; b=btGYs9sMX+WlAdQ7YaipGJ3rHU PivCbcP4KrBK9vhRq5kWEoL6HgKzeVU4U8C3bPvInk6bZ63bbHnRdUASiVqEKtQRgE5eIB0ljgz9a 2/weGlDRtTjMxGPCApsDIR2ZL4UMg2O7dHyOn2Bwd/NfV3rngvpTsLBCb1pIifct5XRYH0iA3qOv+ y70EPw7WwyTV151au0iu7xIXB7cb8RHjhNOOWfBbgdIgsJNkvUhJ9DuG+NRvEbfHfKlKWkahsXCJN h+SrSQoGHnai+9Snd2HyDRjFtRDMjs+D/xIC+0WEgcwn7Mql2TRvxObZuUbJzlaPuPNzGP4ELkKpi rbM8h5bA==; Received: from fangorn.home.surriel.com ([10.0.13.7]) by shelob.surriel.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.97.1) (envelope-from ) id 1wZZ4Q-000000005GL-1Tf8; Tue, 16 Jun 2026 15:03:34 -0400 From: Rik van Riel To: linux-kernel@vger.kernel.org Cc: Rik van Riel , x86@kernel.org, linux-mm@kvack.org, "Thomas Gleixner" , "Ingo Molnar" , "Dmitry Ilvokhin" , "Borislav Petkov" , "Dave Hansen" , "Andrew Morton" , "David Hildenbrand" , "Lorenzo Stoakes" , "Liam R. Howlett" , "Vlastimil Babka" , "Suren Baghdasaryan" Subject: [PATCH 1/3] x86/mm: use READ_ONCE/WRITE_ONCE for mm->context.untag_mask Date: Tue, 16 Jun 2026 15:02:58 -0400 Message-ID: <20260616190300.1509639-2-riel@surriel.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260616190300.1509639-1-riel@surriel.com> References: <20260616190300.1509639-1-riel@surriel.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 mm->context.untag_mask is written once, when LAM is enabled (mm_enable_lam(), under mmap_write_lock and while the process is still single-threaded), and is otherwise stable and never reverted. untagged_addr_remote() reads it for a remote mm, and the new untagged_addr_remote_unlocked() (used by the per-VMA-lock access_remote_vm() fast path) reads it without the mmap lock. The field is a single aligned word and cannot tear, but annotate the reads and writes with READ_ONCE()/WRITE_ONCE() to make the lockless access explicit and keep the compiler from reloading or tearing it. No functional change. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Rik van Riel --- arch/x86/include/asm/mmu_context.h | 6 +++--- arch/x86/include/asm/uaccess_64.h | 2 +- arch/x86/kernel/process_64.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h index ef5b507de34e..cee710f64658 100644 --- a/arch/x86/include/asm/mmu_context.h +++ b/arch/x86/include/asm/mmu_context.h @@ -100,18 +100,18 @@ static inline unsigned long mm_lam_cr3_mask(struct mm_struct *mm) static inline void dup_lam(struct mm_struct *oldmm, struct mm_struct *mm) { mm->context.lam_cr3_mask = oldmm->context.lam_cr3_mask; - mm->context.untag_mask = oldmm->context.untag_mask; + WRITE_ONCE(mm->context.untag_mask, READ_ONCE(oldmm->context.untag_mask)); } #define mm_untag_mask mm_untag_mask static inline unsigned long mm_untag_mask(struct mm_struct *mm) { - return mm->context.untag_mask; + return READ_ONCE(mm->context.untag_mask); } static inline void mm_reset_untag_mask(struct mm_struct *mm) { - mm->context.untag_mask = -1UL; + WRITE_ONCE(mm->context.untag_mask, -1UL); } #define arch_pgtable_dma_compat arch_pgtable_dma_compat diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h index 20de34cc9aa6..4a52497ba6a1 100644 --- a/arch/x86/include/asm/uaccess_64.h +++ b/arch/x86/include/asm/uaccess_64.h @@ -43,7 +43,7 @@ static inline unsigned long __untagged_addr_remote(struct mm_struct *mm, unsigned long addr) { mmap_assert_locked(mm); - return addr & (mm)->context.untag_mask; + return addr & READ_ONCE((mm)->context.untag_mask); } #define untagged_addr_remote(mm, addr) ({ \ diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c index d44afbe005bb..55096136de53 100644 --- a/arch/x86/kernel/process_64.c +++ b/arch/x86/kernel/process_64.c @@ -814,7 +814,7 @@ static void enable_lam_func(void *__mm) static void mm_enable_lam(struct mm_struct *mm) { mm->context.lam_cr3_mask = X86_CR3_LAM_U57; - mm->context.untag_mask = ~GENMASK(62, 57); + WRITE_ONCE(mm->context.untag_mask, ~GENMASK(62, 57)); /* * Even though the process must still be single-threaded at this -- 2.53.0-Meta