From patchwork Mon Jan 6 03:17:10 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Barry Song <21cnbao@gmail.com> X-Patchwork-Id: 13926916 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 E07A1E77198 for ; Mon, 6 Jan 2025 03:17:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 772746B0093; Sun, 5 Jan 2025 22:17:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7227B6B0095; Sun, 5 Jan 2025 22:17:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 59D746B0096; Sun, 5 Jan 2025 22:17:44 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 3D2686B0093 for ; Sun, 5 Jan 2025 22:17:44 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id EEC2B1C83D1 for ; Mon, 6 Jan 2025 03:17:43 +0000 (UTC) X-FDA: 82975567206.30.A270EA1 Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) by imf20.hostedemail.com (Postfix) with ESMTP id 0A4D11C0010 for ; Mon, 6 Jan 2025 03:17:41 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="H/Idv45U"; spf=pass (imf20.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.216.41 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736133462; 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:dkim-signature; bh=n3DoQzm517FFIjqDvouc3tzKgfaa0QgvxVLolob4ICo=; b=alJsfqHZGdIhSD+jVsQpE8cI3xylIaj0Nk/04SCIzAh6/q/WVUkDsuhWCqrqeffq5jfdn8 i8yYQTLx2tRHcrx8oEZIw6Ji/J9RewTg8VyAEoX2nvm0HjaX/9sRrjuiyDp7+4E6bApNAK RqFSkbOewP6G6/sz2S4auQlUQA3nX1U= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="H/Idv45U"; spf=pass (imf20.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.216.41 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736133462; a=rsa-sha256; cv=none; b=bdbpjx8L4svNxmsSzIh9ptIQs/yk0zROykS2wBXC7cJtl86ckuvQiLRssoLfm+SmKv8pP3 2XVfWqFR7wq1Cls4/jU/hDggJnkJEULOS23tL7SGRCijMi5tWYuqAlxQgZs8nPduc33MJh jqTfSVk0szRURfUpjGaOIiHTTmEjtis= Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-2f43d17b0e3so20346013a91.0 for ; Sun, 05 Jan 2025 19:17:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736133461; x=1736738261; darn=kvack.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; bh=n3DoQzm517FFIjqDvouc3tzKgfaa0QgvxVLolob4ICo=; b=H/Idv45UeIakpL+4VfniHif95Tc5SQ6tBn/+Ef8FT2OR8HY7YT5bzSMLU1Dc/2n2Vg R5MZzDDH4DfmWKZGhkGIp4u7OCIYFeW5fVrI4Y7WG+Z3Nt28CmM1bNrujE59I4Uj1Hym B2l80iQ66I5pjqGQkYdWiuie6we8rLkXLJF29uwRHX1U/DKtRZaw1vV0mYJmHZAMnw5T XNm9zr43v3aWchWY3OKaHd7dliR0m2tpmy/b2ZsxXfESEmwGfNKh7HLCRcB6+Gl6x53G VG5CjxQuuJEiO9hSiFNtLMuq4lGmeRfJSA5ffeb4DsbB8+jrAC56tOXl422Z9amCpF8H VyZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736133461; x=1736738261; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=n3DoQzm517FFIjqDvouc3tzKgfaa0QgvxVLolob4ICo=; b=NPqXS5z3NkauLdnU3wsEgJmu336lwuXk3mLWMTR+5C4AZMWiGHtymQEu3ioWfSfbrP 7nv+dI0lHHsENdJYvsQh8a3LUrr/rgt/+V4gHar5YSIxyQdgFF7HpeVx98WLEYhArvXI I68PlU+OPmHyJ8bvcZPNAoYWq0kv3USLAOC66nSeVr1cx/PXpanCLmkkwQcAqXDJ2ngd BqYCpOYe0DxoMMzyRoV5Ar7F3KT03Yz9LF8VTmxMM2jQs7cGGwLxdyp6paIzloseYQeU FAUHVRrFl0pK8BVvFyt1eKO6kX/0S14VtMF/A3iOYPHWiXTrcSl5gLGfhbWO0gV8dwUK eF/w== X-Forwarded-Encrypted: i=1; AJvYcCV9R14EeIp55rurQjbBuUSA59FjYb+8PCQDC5eZH/Obks/N0Axgw8Dr1LrpNUpAq5/KvmNRlh17Bg==@kvack.org X-Gm-Message-State: AOJu0Yy65cYs9j4ndClSMZXmQVkPginv/Vhy9LMiYudUtqE0nLkpY78f g8Yiv8lPcLThljDHmPdm/7aMk/TI26mu0zUXSGqmoewUOgPYZ6td X-Gm-Gg: ASbGncv5VSwnnbHu4PyNtsjGLunKmDlikIlU9DqI48POgOT0fGd316VIf39LvIfkmLO GQyybCGY/OqJ2jVMxNjydWrGS8yzSQiLAftpPLIKjtPJwwbRFyOqsenM4P6xOmmV7Nv/sh8iKkR +fAQEJDyjQI1UBTcuGAYA9dxmoXzLyrMpgmMz+ULNkbtq1InN4WCnGgP++ro1KhGutw3cTaJpVJ WJjBaOgcYBQJuS09tWOnah9ZrZ1N7wXq27LIlHhu4IkY4WqJz7QWZ2V9l2xNyUaNKLwX98/TKP2 CPDGK12D X-Google-Smtp-Source: AGHT+IFyfsnRq/TPlAXOEBq4tTLlzzCUGW+jGQSlThHUVYTr85agsMlhfIXWLMv/0CFjghXY79/T8g== X-Received: by 2002:a17:90a:e18b:b0:2ee:fdf3:390d with SMTP id 98e67ed59e1d1-2f452edc2cfmr70372123a91.31.1736133460760; Sun, 05 Jan 2025 19:17:40 -0800 (PST) Received: from Barrys-MBP.hub ([2407:7000:af65:8200:a54c:5ad3:ad27:edb7]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2f2ed62cde6sm38471399a91.13.2025.01.05.19.17.31 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 05 Jan 2025 19:17:40 -0800 (PST) From: Barry Song <21cnbao@gmail.com> To: akpm@linux-foundation.org, linux-mm@kvack.org Cc: linux-arm-kernel@lists.infradead.org, x86@kernel.org, linux-kernel@vger.kernel.org, ioworker0@gmail.com, david@redhat.com, ryan.roberts@arm.com, zhengtangquan@oppo.com, ying.huang@intel.com, kasong@tencent.com, chrisl@kernel.org, baolin.wang@linux.alibaba.com, Barry Song , Catalin Marinas , Will Deacon , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Anshuman Khandual , Shaoqin Huang , Gavin Shan , Kefeng Wang , Mark Rutland , "Kirill A. Shutemov" , Yosry Ahmed Subject: [PATCH 2/3] mm: Support tlbbatch flush for a range of PTEs Date: Mon, 6 Jan 2025 16:17:10 +1300 Message-Id: <20250106031711.82855-3-21cnbao@gmail.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) In-Reply-To: <20250106031711.82855-1-21cnbao@gmail.com> References: <20250106031711.82855-1-21cnbao@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Stat-Signature: z7kxp9bgxsiufd7jmgfdzgqdmad974qj X-Rspamd-Queue-Id: 0A4D11C0010 X-Rspam-User: X-HE-Tag: 1736133461-96255 X-HE-Meta: U2FsdGVkX194G4w95u7AFgyznl9ISuYwPBsREwe641n/sRWUyO2SSvfKMlIqIOPt4ISUaGK0F81c4r5UBakazk7UnpoiX8Ps75POg+EfMoTMf/q3Bg29HXGY/DOHqcOkEZ24jPSlBR0jP2n+sVCiG6hTIf0dpl3jDFov1FdsEka99dtS344ona/nLntHho+Gsm53MlMU++oLai7s9fSlDp+E0ycRPa+ICfHCEhQR2t2ADxbc6NX6bhTpWCDqHZgkAQlTHZ/XScy/bFT0C2ZD5v+izGfHp2EG3jlLH6+jUcVfpzVoCrsaXUkLKG9kP+yoNmKHGGUf9JnxRxGSzXsh5EHm9D06pflSoCFd4ie2v1LNmhB6NJlyLF1YXgidV1Bj6hXFM2AdjMqE7MuP2uX42sQIJUZtk8JQ5qdY5hsn1add0phPmxnosf9GE2Pq4sI5NS8SrkofRHZtCnK7AU/Oakx2tx5Cdff0rEBqoJxq7Jt0T0JmZLW9SNgmbuLEkrfWPvHesoK1t8DoKejKbDDakS+Oa6ngikDErjHB/165N30Z+vXf5xP/d+YHFeuavs4i9uYrPumfvrBOAFdJpCWyGAutgj8KbEFmoW37hA8VCkNQgcXeCAwrOn4/DqdG5TrNqkGqsmAMXtplvZP2ilBGrfsN3oPq0L3PG4uRE6bMz45+C1dVM8VcJaLVJsqSX3pGLmNtOkuotwJXNvjno3jgSuee556tE0wBrTL1bcdaLPOyw58AaNZUL3v+78/7j5azzwiV7N2F5actH2q5o8i9eDmOPN4pR39mN1i3PJTw/1+9zULEwhHilCl1r+53CN1XnnUZToQHIsZ6JEnCwBQ9hvPbRRctsOSkDT8Q1vfUBYBhga3TfWJKzIIHlTSGnScPw+o4lMC6+MG15OzPgMQFMTKxvROC2tyEFgI6ZJcWU9LcJWJEZ19DZtSKA50yJHDc01UPDcCcZOqv532cY+Y 0PzsFMxI WHJ7R3WeWP8IbF10gMv3IfdSeEHwf5vTkisKCkRk8q1fHnTItTa0SRvt4UXSoMM2DAMziKGFEx6sANxWzGB7WQSS1l1i7Xs7uI06NaOz+3HnDU3nia8FfsITW9uyZKd4K6Xfx4m+Tu8TkCggaDTWHdLI5B8xd8gMLc/uHL9eBQvkRRtgwv+AZB+2POWHugbQvXvUZm03/k3DWPVyrVjbEqOA5fpWw/YGdSPb9UubacQe2B1cP/w+gyWL7Kz4g0PJaLSDwiIX5qBp9vQuO3MR3mEUnOlWXKV60Iriyfkb7KAucDnEhkzRVLx0JQjtr+hKVLDXVTaGJelKco9KDS36HGqGAVFopWIg4HSAo+6gyvQNBxuPA+1AI4kJtUtfYT2hXRJssa3Jz1aQOgtz9qUwzRVat5VXVGcBo+/c4WmBHxe4G3AkuEvhJQh5cc47faeTTZcvl+gZ6GgSnX/0iVspOqgXLr+r8OkthBa70E1axDxJD4blJX1ExP354jH8+ONFt8UrgtLwNcq2zHQYFyW9Zr5p2JkISmUSSw0/fSwazzkxsVqmkLZEjnFn1MgaeELB0YJVejLINWQzEjDns6WtTkeP4oh2Mi/FxgJou2btzlktFgB6Ht7lbwRbYVaf3oTshqQ+1e4iK0Ta3NEI= 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: From: Barry Song This is a preparatory patch to support batch PTE unmapping in `try_to_unmap_one`. It first introduces range handling for `tlbbatch` flush. Currently, the range is always set to the size of PAGE_SIZE. Cc: Catalin Marinas Cc: Will Deacon Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: "H. Peter Anvin" Cc: Anshuman Khandual Cc: Ryan Roberts Cc: Shaoqin Huang Cc: Gavin Shan Cc: Kefeng Wang Cc: Mark Rutland Cc: David Hildenbrand Cc: Lance Yang Cc: "Kirill A. Shutemov" Cc: Yosry Ahmed Signed-off-by: Barry Song --- arch/arm64/include/asm/tlbflush.h | 26 ++++++++++++++------------ arch/arm64/mm/contpte.c | 2 +- arch/x86/include/asm/tlbflush.h | 3 ++- mm/rmap.c | 12 +++++++----- 4 files changed, 24 insertions(+), 19 deletions(-) diff --git a/arch/arm64/include/asm/tlbflush.h b/arch/arm64/include/asm/tlbflush.h index bc94e036a26b..f34e4fab5aa2 100644 --- a/arch/arm64/include/asm/tlbflush.h +++ b/arch/arm64/include/asm/tlbflush.h @@ -322,13 +322,6 @@ static inline bool arch_tlbbatch_should_defer(struct mm_struct *mm) return true; } -static inline void arch_tlbbatch_add_pending(struct arch_tlbflush_unmap_batch *batch, - struct mm_struct *mm, - unsigned long uaddr) -{ - __flush_tlb_page_nosync(mm, uaddr); -} - /* * If mprotect/munmap/etc occurs during TLB batched flushing, we need to * synchronise all the TLBI issued with a DSB to avoid the race mentioned in @@ -448,7 +441,7 @@ static inline bool __flush_tlb_range_limit_excess(unsigned long start, return false; } -static inline void __flush_tlb_range_nosync(struct vm_area_struct *vma, +static inline void __flush_tlb_range_nosync(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long stride, bool last_level, int tlb_level) @@ -460,12 +453,12 @@ static inline void __flush_tlb_range_nosync(struct vm_area_struct *vma, pages = (end - start) >> PAGE_SHIFT; if (__flush_tlb_range_limit_excess(start, end, pages, stride)) { - flush_tlb_mm(vma->vm_mm); + flush_tlb_mm(mm); return; } dsb(ishst); - asid = ASID(vma->vm_mm); + asid = ASID(mm); if (last_level) __flush_tlb_range_op(vale1is, start, pages, stride, asid, @@ -474,7 +467,7 @@ static inline void __flush_tlb_range_nosync(struct vm_area_struct *vma, __flush_tlb_range_op(vae1is, start, pages, stride, asid, tlb_level, true, lpa2_is_enabled()); - mmu_notifier_arch_invalidate_secondary_tlbs(vma->vm_mm, start, end); + mmu_notifier_arch_invalidate_secondary_tlbs(mm, start, end); } static inline void __flush_tlb_range(struct vm_area_struct *vma, @@ -482,7 +475,7 @@ static inline void __flush_tlb_range(struct vm_area_struct *vma, unsigned long stride, bool last_level, int tlb_level) { - __flush_tlb_range_nosync(vma, start, end, stride, + __flush_tlb_range_nosync(vma->vm_mm, start, end, stride, last_level, tlb_level); dsb(ish); } @@ -533,6 +526,15 @@ static inline void __flush_tlb_kernel_pgtable(unsigned long kaddr) dsb(ish); isb(); } + +static inline void arch_tlbbatch_add_pending(struct arch_tlbflush_unmap_batch *batch, + struct mm_struct *mm, + unsigned long uaddr, + unsigned long size) +{ + __flush_tlb_range_nosync(mm, uaddr, uaddr + size, + PAGE_SIZE, true, 3); +} #endif #endif diff --git a/arch/arm64/mm/contpte.c b/arch/arm64/mm/contpte.c index 55107d27d3f8..bcac4f55f9c1 100644 --- a/arch/arm64/mm/contpte.c +++ b/arch/arm64/mm/contpte.c @@ -335,7 +335,7 @@ int contpte_ptep_clear_flush_young(struct vm_area_struct *vma, * eliding the trailing DSB applies here. */ addr = ALIGN_DOWN(addr, CONT_PTE_SIZE); - __flush_tlb_range_nosync(vma, addr, addr + CONT_PTE_SIZE, + __flush_tlb_range_nosync(vma->vm_mm, addr, addr + CONT_PTE_SIZE, PAGE_SIZE, true, 3); } diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h index 69e79fff41b8..cda35f53f544 100644 --- a/arch/x86/include/asm/tlbflush.h +++ b/arch/x86/include/asm/tlbflush.h @@ -279,7 +279,8 @@ static inline u64 inc_mm_tlb_gen(struct mm_struct *mm) static inline void arch_tlbbatch_add_pending(struct arch_tlbflush_unmap_batch *batch, struct mm_struct *mm, - unsigned long uaddr) + unsigned long uaddr, + unsignd long size) { inc_mm_tlb_gen(mm); cpumask_or(&batch->cpumask, &batch->cpumask, mm_cpumask(mm)); diff --git a/mm/rmap.c b/mm/rmap.c index de6b8c34e98c..365112af5291 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -672,7 +672,8 @@ void try_to_unmap_flush_dirty(void) (TLB_FLUSH_BATCH_PENDING_MASK / 2) static void set_tlb_ubc_flush_pending(struct mm_struct *mm, pte_t pteval, - unsigned long uaddr) + unsigned long uaddr, + unsigned long size) { struct tlbflush_unmap_batch *tlb_ubc = ¤t->tlb_ubc; int batch; @@ -681,7 +682,7 @@ static void set_tlb_ubc_flush_pending(struct mm_struct *mm, pte_t pteval, if (!pte_accessible(mm, pteval)) return; - arch_tlbbatch_add_pending(&tlb_ubc->arch, mm, uaddr); + arch_tlbbatch_add_pending(&tlb_ubc->arch, mm, uaddr, size); tlb_ubc->flush_required = true; /* @@ -757,7 +758,8 @@ void flush_tlb_batched_pending(struct mm_struct *mm) } #else static void set_tlb_ubc_flush_pending(struct mm_struct *mm, pte_t pteval, - unsigned long uaddr) + unsigned long uaddr, + unsigned long size) { } @@ -1792,7 +1794,7 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma, */ pteval = ptep_get_and_clear(mm, address, pvmw.pte); - set_tlb_ubc_flush_pending(mm, pteval, address); + set_tlb_ubc_flush_pending(mm, pteval, address, PAGE_SIZE); } else { pteval = ptep_clear_flush(vma, address, pvmw.pte); } @@ -2164,7 +2166,7 @@ static bool try_to_migrate_one(struct folio *folio, struct vm_area_struct *vma, */ pteval = ptep_get_and_clear(mm, address, pvmw.pte); - set_tlb_ubc_flush_pending(mm, pteval, address); + set_tlb_ubc_flush_pending(mm, pteval, address, PAGE_SIZE); } else { pteval = ptep_clear_flush(vma, address, pvmw.pte); }