From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.215.200 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796137690; b=LM/8rRlrt5EMxY4l/wVDDlj8KCxT9Ju/WuIrViAQjusEWmEK7HWs/4dpPCiuz+0thv4o dNRZ6zMMO9gxI4sAJ3mI7hD9zWti44JuQc2ln9rDNz57gqtrFDKjqE4bV1bDP4lx/3IBj X7SwkDhE9S0mdHKtmcXLEidr05RlQfk2nn9g/5ccjIIGUraW1b42vvl+wbF8ggh4lWqUz wnRcy4dud4CMJqj7S+H9OUycp7vNbY56v8vxLX0Ke4dM9N3uOmPTscVC8Q1fu+1sAxd3Y a1zrKjCLia/PcbUrrP+R9u2NlZsVGxMvVG+El4yhUSEjjBB1+XNwHy90Aq1nCTgiUbw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796137690; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:X-Mailer:Message-ID:Subject:From:To:Cc: Content-Type; bh=zXNWiu7J9qvqDJ7bsrbk/f63K3UVTo8lNpZHpT1R0YI=; b=S4++C1vJlBBPYKNVc0mBBikc3cPFHxpaFgCJq3vO6d4hOhDMPsjftpmyHahIRz0KsgC8 q5/yF9Dq4ywGjbFGCsRw1y2dZF19VR/SaeK/AJ1AqEubKtF1uvcnKWrHqEBsD2GqVOf36 3Ky2ki7/Q6c8K3qenaZmBsIhwtHiwbED5DrDpXU3uChiZZ+rjFw08NRgR2cDca+zVqIAm a9HQEsBlXYV3pg0BxyPrOL8CooMB+E5X828dKKYY74f++OAGwWwRFkOZNKWPcbMV6jaiL 6kfoF+esz2xC6YKFmAfmepQU+msuF5WUg+SPscYGn0Z0Dqxg7UGFnBNBKFyrWts55uQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--jthoughton.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=POwdbu2u; arc=none smtp.remote-ip=209.85.215.200 Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2448F606A322 for ; Tue, 1 Dec 2026 15:08:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2448F606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jthoughton.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=POwdbu2u Received: by mail-pg1-f200.google.com with SMTP id 41be03b00d2f7-cde02b50dd6so8236011a12.1 for ; Tue, 01 Dec 2026 07:08:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796137689; x=1796742489; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=zXNWiu7J9qvqDJ7bsrbk/f63K3UVTo8lNpZHpT1R0YI=; b=POwdbu2u6B/BP2N4GaNPlV/wo6zMXp/wLNKy9TW+NqTMNUp+xOA6mb/+6UVpfZLcpn mr89ML4TE3m3ZoClfu8MmH6yBg6cLFCk5EVdr7WBnNeYdsA6ScFVKLBmX5PljkMuttnJ lrNhQj8O+o6OCY0jutSINhx2n+w3RFLoOa2fSyVERWmAsMJVIhLOthuVrjNnUlyp4On2 fVNtwNPSxhka1MZuQ0vfpqGqmboBbAnusJ0jM2Wa4iRVeNMqy8YkxxoT/EUKuYrOrY5L MtYj3vOvAL1oofSyougBTZCn0XhYk94XTj2NTb7j1hg1MALa07fuCh+2AarqygH9Mrsa 1W4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796137689; x=1796742489; h=content-type: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:content-type; bh=zXNWiu7J9qvqDJ7bsrbk/f63K3UVTo8lNpZHpT1R0YI=; b=Q2Yx+ZIzu/OXsWEiOoiUXI2MKZeZwwMT0pJeqyMfJEmzWHzB/8zUqTVgHiuLHewkUy /WbsbDG3hpKPfAUXGMo+ooOoabYUz1iY5OlrAXwuP9Mw+e63AheB9jlT5LPpXggykCBS MJBsNP2LLSbi7hCCLFUJ1cq+rFIExL/U4A7mazhujbRJbTZZEkB1oHDJYqExal4IMHb8 d9YkSM3Vc64f2XFuAh9ZfxNfpvOWYP3E+DL7BfgP6uYrvOzLG+7CTk3TMvhJefUMc/nd xAMr1yswwJk5H9W3JuyIAr+4B/UEW4w6bLIl2ucupqNNKlA12LpJy+ZanhYGHVq88FfB PD3A== X-Forwarded-Encrypted: i=1; AL+hErGCkoYAGwzebt/cY7ojvRSAigfcFR/8+fnTqGGzly0FFgF/W438uFU/jm3HlCu5m4LJ+P8uHA6S+yXXIA4=@vger.kernel.org X-Gm-Message-State: APuU4Z9An5DALwoBOamzgYJtd+mMhHeGcgWkSXCeckXwg0c/QrjPxnHO /uQLSAeJCcHNq47BoghInQLSTLNLgrzREWFtR0ADZSi4ONlOljshmtwBFtJIUrG/gmgc0aGt9KX DiL7GV36EVL4WMNmiAfzzgQ== X-Received: from plht15.prod.google.com ([2002:a17:903:2f0f:b0:2e1:2a71:d15b]) (user=jthoughton job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:d550:b0:2f0:1c03:be13 with SMTP id d9443c01a7336-2f031fc8f58mr316344925ad.29.1796137689034; Tue, 01 Dec 2026 07:08:09 -0800 (PST) Date: Tue, 1 Dec 2026 15:07:43 +0000 In-Reply-To: <20261201150801.2239894-1-jthoughton@google.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <20261201150801.2239894-1-jthoughton@google.com> X-Mailer: git-send-email 2.56.1.839.g22a8290db9-goog Message-ID: <20261201150801.2239894-2-jthoughton@google.com> Subject: [PATCH v4 01/18] arm64/pgtable: Clear AF with LDCLR on supported systems From: James Houghton To: Will Deacon , Catalin Marinas , Muchun Song , Oscar Salvador , Andrew Morton Cc: Kefeng Wang , Nikos Nikoleris , Linu Cherian , Mark Rutland , David Hildenbrand , Ryan Roberts , Nanyong Sun , Yu Zhao , Frank van der Linden , David Rientjes , James Houghton , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org Content-Type: text/plain; charset="UTF-8" Replace the cmpxchg loop with atomic64_fetch_andnot_relaxed, which, on systems with LSE atomics, should end up as LDCLR. This is somewhat overdue. In recent versions of the architecture, if a system supports FEAT_LSE, forward progress guarantees for exclusive monitors and cmpxchg loops are relaxed. Mechanically, I would love to write test_and_clear_bit_relaxed(), but no such function exists (test_and_clear_bit() has full ordering, which is also undesirable). Implementing test_and_clear_bit_relaxed() properly is a pretty large change; use atomic64 instead, as pte_t contains a u64. Signed-off-by: James Houghton --- arch/arm64/include/asm/pgtable.h | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h index ce51c1b9be22..4285b7e7a6a7 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -1252,17 +1252,11 @@ static inline void __pte_clear(struct mm_struct *mm, static inline bool __ptep_test_and_clear_young(struct vm_area_struct *vma, unsigned long address, pte_t *ptep) { - pte_t old_pte, pte; + atomic64_t *pteval = (atomic64_t *)&pte_val(*ptep); + s64 af_mask = PTE_AF; - pte = __ptep_get(ptep); - do { - old_pte = pte; - pte = pte_mkold(pte); - pte_val(pte) = cmpxchg_relaxed(&pte_val(*ptep), - pte_val(old_pte), pte_val(pte)); - } while (pte_val(pte) != pte_val(old_pte)); - - return pte_young(pte); + /* Atomically clear PTE_AF, checking that it was set before. */ + return af_mask & atomic64_fetch_andnot_relaxed(af_mask, pteval); } static inline bool __ptep_clear_flush_young(struct vm_area_struct *vma, -- 2.56.1.839.g22a8290db9-goog