From nobody Mon Feb 9 12:54:54 2026 Received: from mail-qt1-f182.google.com (mail-qt1-f182.google.com [209.85.160.182]) (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 30C08B67E for ; Sun, 16 Nov 2025 06:40:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763275254; cv=none; b=XtIX5pM3vUR/AEcarM5x2u8V/MFsBALmvOz6d6Bt2l8u4WVyzT9Ql0f8oVrx/T5N2X/+tYRWnKrjZg+Pc2bfYMvs8p8jrWXEa/mfliv5eOq8bQvIvxhgKgutN/2IqOENLFkXn9M+sfDDN8P352O6FlKUjSJZStRvMgQiRFzBSFc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763275254; c=relaxed/simple; bh=muIWQccO36YRMVeS5U/f/4/TLToyy8blzhH60i2svbE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=rLFa/AvM7MUur9PtG39s03FWF1bm5I5S0qYUmXupVH8oKWReur8GavzU1vB7Jyx3C9wac9sG0JI6tNzVapICDT8tyDoE7wDCU9xzyaXRsxRtetO2zp+Vd0LCz8zj/MAYd6gDHbbl/dTtEp+Xoc/lalR16EIZQ9r/doH++vJ9/FI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=vasilevsky.ca; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.160.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=vasilevsky.ca Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-qt1-f182.google.com with SMTP id d75a77b69052e-4e4d9fc4316so29227031cf.2 for ; Sat, 15 Nov 2025 22:40:51 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763275251; x=1763880051; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=A/TBs7BuWibkRX4L1Mxki9I3H1/n/J1InK7hm63Zqwc=; b=uU/B5aC4YsTFx0eQklVd+xtEOHuZimmPZSZowjN2wKc8KCH7FQAJ4m+sEK9RR+V+2C 79f0gmCmzgs9aQ5SdXycbkEyErP2JhcjQCHWYc79CDcV2+e0irMArEB6R2NMJ+bzKV+U 8n73OQyeteFvlu2psuJD9/vAznomye/uvoUlxh8r3atCSrhrsA9Ln31j9W7PaLF3H+M/ sAmVTFlkQfgwzyd+Savl2vfYJt1obnisYtKjyQKWAWcS3pDi/n2mdfEe2dbhRYdl0V2n mnr7Wj31kO1AEsIk8+7oI+CkGe7ExuLjxGEVwiU9qYbgF7a/73rGxyZTlZclk2WlTaLC 2pXg== X-Forwarded-Encrypted: i=1; AJvYcCW1zgocrPBrNx0Q06NC5DpetfXcLGYSQjLlHk1KnWUYXr+PPH9Elvlf2eyWbnBtASS3Kb/kRkhj9Sbw47Q=@vger.kernel.org X-Gm-Message-State: AOJu0YzEvKjmK0FyEhQduOV+01+1TM3MHWyNWfJMFI0PI9cN3n2Inutv 4PbpELFHZb0qr4zAtjTuNpPe+4nrTEa+h9lWEMWPZTglDQp1Qyb5TKq5 X-Gm-Gg: ASbGncvUJxRUS3Z2vfxWBQoar3XJXqdTw6Em0owoMt8OV90i/p2nSyaKcim3A+P5tMi SHMwLAeofwSTfE6fZGWMHbbQwaA3cS6h08qmKIrUfNLpiNoeISs/sfM7NhRSs5o0+HhsgKZ9lPt 4EQOX+gKLIbuhCRbbt39+bZt2OnmdQmCW6NGDE0X15PErvFUWQRodXGzdbT6ZLrsQq+ZbkroaKY SoSaprddJqkik50PF+VfYJcPeVS8W5kfRsEI5oGZGPyZJsSDSv7nydNb6X14p6AC43geSsg7x+8 d+YmDmxbhpkiFra8WgKJgyLRgEE7aHkBZe/lwUFLEkX8mMq5SKRWBNGDDRMmwxRKQ9jCYjzk+0o H+tELzB/YxQqyKxNlLAwBknduC71OOIlgSOTJ8CNzeq+zZdlh7lo4iKaV8dZoh1s5w9ryaA83aN Ej7OZd5YeaY64jAmWoCqLprmRxhy5B+wZfrGbp+DxYnVbkg29y9Pytxerc3uYGaCxMfMgtNfTAZ A== X-Google-Smtp-Source: AGHT+IG+qzsrR+dRWKF4NmoVX7b6CUaR8vMmbs3TLbWswTg9TED3bCbWhUIV58kjiV3MwgK5w6g1yA== X-Received: by 2002:a05:622a:1107:b0:4ec:f7de:f5eb with SMTP id d75a77b69052e-4edf20a2ebbmr113268941cf.33.1763275250934; Sat, 15 Nov 2025 22:40:50 -0800 (PST) Received: from [192.168.2.45] (bras-base-mtrlpq3141w-grc-10-65-95-13-196.dsl.bell.ca. [65.95.13.196]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4ede87e6fecsm61188021cf.18.2025.11.15.22.40.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Nov 2025 22:40:50 -0800 (PST) From: Dave Vasilevsky Date: Sun, 16 Nov 2025 01:40:46 -0500 Subject: [PATCH v3] powerpc, mm: Fix mprotect on book3s 32-bit Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251116-vasi-mprotect-g3-v3-1-59a9bd33ba00@vasilevsky.ca> X-B4-Tracking: v=1; b=H4sIAO1xGWkC/33NwQ6CMAwG4FchPTuzli0MT76H8TDHBosKZCOLh PDuDi4mxtjb3/z9ukC0wdsIp2KBYJOPfuhzKA8FmE73rWW+yRmIk0ROFUs6evYcwzBZM7G2ZE4 5SZVqBAoO+WwM1vnXTl6uOXc+TkOY9w8Jt+0fLCFDVhqJquJKulqft8rDpnifj0bDBib6IHl+I JQRpdDUQrubEfSNrOv6BpGaqhz5AAAA X-Change-ID: 20251027-vasi-mprotect-g3-f8f5278d4140 To: Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Nadav Amit , "Peter Zijlstra (Intel)" , Andrew Morton , Ritesh Harjani Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, linux-mm@kvack.org, Dave Vasilevsky X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1763275249; l=3309; i=dave@vasilevsky.ca; s=20251027; h=from:subject:message-id; bh=muIWQccO36YRMVeS5U/f/4/TLToyy8blzhH60i2svbE=; b=BqibHhRBraGtc5DC4MXisv7cfh+xdLpFWAQQaxC9fzFoJvdvVanpK8QruKXcOddOsTtRvfNgH YlQotamK+KoD0aCejzMYbW1umsa7tkoXkMduqh2O3DDT0rZZS39zLZd X-Developer-Key: i=dave@vasilevsky.ca; a=ed25519; pk=Jsd1btZeqqg6x6y73Dx0YrleQb3A3pCBnUeE0qmoKq4= On 32-bit book3s with hash-MMUs, tlb_flush() was a no-op. This was unnoticed because all uses until recently were for unmaps, and thus handled by __tlb_remove_tlb_entry(). After commit 4a18419f71cd ("mm/mprotect: use mmu_gather") in kernel 5.19, tlb_gather_mmu() started being used for mprotect as well. This caused mprotect to simply not work on these machines: int *ptr =3D mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); *ptr =3D 1; // force HPTE to be created mprotect(ptr, 4096, PROT_READ); *ptr =3D 2; // should segfault, but succeeds Fixed by making tlb_flush() actually flush TLB pages. This finally agrees with the behaviour of boot3s64's tlb_flush(). Fixes: 4a18419f71cd ("mm/mprotect: use mmu_gather") Cc: stable@vger.kernel.org Reviewed-by: Christophe Leroy Reviewed-by: Ritesh Harjani (IBM) Signed-off-by: Dave Vasilevsky --- Changes in v3: - Fix formatting - Link to v2: https://lore.kernel.org/r/20251111-vasi-mprotect-g3-v2-1-881c= 94afbc42@vasilevsky.ca Changes in v2: - Flush entire TLB if full mm is requested. - Link to v1: https://lore.kernel.org/r/20251027-vasi-mprotect-g3-v1-1-3c51= 87085f9a@vasilevsky.ca --- arch/powerpc/include/asm/book3s/32/tlbflush.h | 5 ++++- arch/powerpc/mm/book3s32/tlb.c | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/include/asm/book3s/32/tlbflush.h b/arch/powerpc/i= nclude/asm/book3s/32/tlbflush.h index e43534da5207aa3b0cb3c07b78e29b833c141f3f..4be2200a3c7e1e8307f5ce1f1d5= d28047429c106 100644 --- a/arch/powerpc/include/asm/book3s/32/tlbflush.h +++ b/arch/powerpc/include/asm/book3s/32/tlbflush.h @@ -11,6 +11,7 @@ void hash__flush_tlb_mm(struct mm_struct *mm); void hash__flush_tlb_page(struct vm_area_struct *vma, unsigned long vmaddr= ); void hash__flush_range(struct mm_struct *mm, unsigned long start, unsigned= long end); +void hash__flush_gather(struct mmu_gather *tlb); =20 #ifdef CONFIG_SMP void _tlbie(unsigned long address); @@ -29,7 +30,9 @@ void _tlbia(void); static inline void tlb_flush(struct mmu_gather *tlb) { /* 603 needs to flush the whole TLB here since it doesn't use a hash tabl= e. */ - if (!mmu_has_feature(MMU_FTR_HPTE_TABLE)) + if (mmu_has_feature(MMU_FTR_HPTE_TABLE)) + hash__flush_gather(tlb); + else _tlbia(); } =20 diff --git a/arch/powerpc/mm/book3s32/tlb.c b/arch/powerpc/mm/book3s32/tlb.c index 9ad6b56bfec96e989b96f027d075ad5812500854..e54a7b0112322e5818d80facd2e= 3c7722e6dd520 100644 --- a/arch/powerpc/mm/book3s32/tlb.c +++ b/arch/powerpc/mm/book3s32/tlb.c @@ -105,3 +105,12 @@ void hash__flush_tlb_page(struct vm_area_struct *vma, = unsigned long vmaddr) flush_hash_pages(mm->context.id, vmaddr, pmd_val(*pmd), 1); } EXPORT_SYMBOL(hash__flush_tlb_page); + +void hash__flush_gather(struct mmu_gather *tlb) +{ + if (tlb->fullmm || tlb->need_flush_all) + hash__flush_tlb_mm(tlb->mm); + else + hash__flush_range(tlb->mm, tlb->start, tlb->end); +} +EXPORT_SYMBOL(hash__flush_gather); --- base-commit: 24172e0d79900908cf5ebf366600616d29c9b417 change-id: 20251027-vasi-mprotect-g3-f8f5278d4140 Best regards, --=20 Dave Vasilevsky