From patchwork Fri May 10 06:52:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Byungchul Park X-Patchwork-Id: 13660940 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 68EC8C25B10 for ; Fri, 10 May 2024 06:52:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C76AC6B009E; Fri, 10 May 2024 02:52:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BFF036B009F; Fri, 10 May 2024 02:52:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9DBFB6B00A0; Fri, 10 May 2024 02:52:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 80F076B009E for ; Fri, 10 May 2024 02:52:28 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 41C40C04CE for ; Fri, 10 May 2024 06:52:28 +0000 (UTC) X-FDA: 82101567576.09.6F2791C Received: from invmail4.hynix.com (exvmail4.hynix.com [166.125.252.92]) by imf02.hostedemail.com (Postfix) with ESMTP id 6596280007 for ; Fri, 10 May 2024 06:52:26 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=none; spf=pass (imf02.hostedemail.com: domain of byungchul@sk.com designates 166.125.252.92 as permitted sender) smtp.mailfrom=byungchul@sk.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1715323946; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=x9wh2Uy2LBAY2jLtNMSHkvHujd6XB9pxIP0VooR2LTw=; b=tI7GuWHqDNqnYQFozdjK7v3ktTSXIp7mA3Rvhwcld8UvKcywUxiQPzhoA140/sd+P8kQEz 31eWILZrVYzR0BoFnv75QjfExNiWjDlSD5PRS1nqL6vBVya7EVpgURxvlfD1A0idwrsdun OcfryJO2Ndqva7iiejFv2zTh/Hd8s8g= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715323946; a=rsa-sha256; cv=none; b=vyEnpcwfc4N2iTrM79Nth+Fdf/hBWwZ9jgFkBkd8MEIyj7wA3LFa/mYozlHheYJpeBXVjy 3Pot50xEUswprTcxs4P7f1Lez2Era/+8wYYRwSZ6X2Wbtm1zmMAFG3Fy1onGPNwffwrRKs ZABPu1fFKrw4G+uP0a7JsFv7ruL2yA8= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=none; spf=pass (imf02.hostedemail.com: domain of byungchul@sk.com designates 166.125.252.92 as permitted sender) smtp.mailfrom=byungchul@sk.com; dmarc=none X-AuditID: a67dfc5b-d6dff70000001748-e7-663dc421aa7f From: Byungchul Park To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: kernel_team@skhynix.com, akpm@linux-foundation.org, ying.huang@intel.com, vernhao@tencent.com, mgorman@techsingularity.net, hughd@google.com, willy@infradead.org, david@redhat.com, peterz@infradead.org, luto@kernel.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, rjgolo@gmail.com Subject: [PATCH v10 08/12] mm/rmap: recognize read-only tlb entries during batched tlb flush Date: Fri, 10 May 2024 15:52:02 +0900 Message-Id: <20240510065206.76078-9-byungchul@sk.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240510065206.76078-1-byungchul@sk.com> References: <20240510065206.76078-1-byungchul@sk.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrKLMWRmVeS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D1OzPjN4jHvZKDH+31X2TwWv/jA5LH1l51H49RrbB6fN8kF8Edx2aSk 5mSWpRbp2yVwZTS8e8RecEe24uLuGWwNjEckuhg5OSQETCSuv9nADGKzCahL3LjxE8wWETCT ONj6hx3EZha4yyRxoJ+ti5GDQ1ggRqJhkQ1ImEVAVeLq6ZNsIDavgKnEhusHmCBGykus3nAA bAwn0JgPy2aAxYWAajoeTGScwMi1gJFhFaNIZl5ZbmJmjqlecXZGZV5mhV5yfu4mRmAYL6v9 M3EH45fL7ocYBTgYlXh4d2y2SRNiTSwrrsw9xCjBwawkwltVY50mxJuSWFmVWpQfX1Sak1p8 iFGag0VJnNcrPDVBSCA9sSQ1OzW1ILUIJsvEwSnVwOjyVOdO4urdb9Y9eTd7wWrpJXo2rY0a GUlbY+YZsrA07VppI2Qtk//9542Sg04fKvsKeyK8S28vnXqxN/nXhD2Kgl9DWG7d0JENNjzc l65yz+fbCbt3YYHLyquu98y13cCxfmpJWq+uaL/tZb5//W/7TzAcWv3g+XEGSwkbEzsPlruX Qqd/l1FiKc5INNRiLipOBADOpyuuXwIAAA== X-CFilter-Loop: Reflected X-Rspam-User: X-Stat-Signature: kwpe8rhx66p9zrjtwezpe6a97ram8737 X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 6596280007 X-HE-Tag: 1715323946-210060 X-HE-Meta: U2FsdGVkX1+/bCE8YiRkSH/OwflZEalfDOVn4dkwePf09Kyv2LqnlgnhBtTPZdf5L4sT4+FQca5CQesftO7jzB6plPhXdXqyiQaIRAHMSZLTiry3h5IxJYCGg8temVx5LEb4tUFn6ks5thSrCNZQsxdXwYFEW+R4EmpMh2Uz3LifhvKpBqj4XRvge6sQtpS7iHNdwzzC+Ihmnyzx/KeOS7f2HElfN6nKsLUXZFx8b6W4H+nmMLXx2M6w+ggpoYuVvmj1aqng77dgWUftnh6DDmUmpZ4WEGSpn89TKMgtqJI1CxzJUCX6fbjCzwvunwgjryVEEyWDV1uIoSg4jpexLg78aHYOrsUyXakE6iB/kw6srODzAUwGmgSw72LOPS5d9qyZjF0PCzJdyGWRi60KhRQrbKGenXIXhFB1tLxCOdXjVoVpQr0STziMvoFT8gtLGMAAyO4ZoyYuxGMIG6xSOaXMo/wILlzQDP8f0HWN8F8UPhp6pR4HgzP9Qc6s3sW49L9wHJvGk2RqUu0LLvGS2yjkCU0dpf/q0GfD6rXRaJSX9XcYDKtFP/Y1UJet8TpqNd4dn9qD59cVKaTHwcwnQyBKZ6HR4Dh6FWBLOaj9iSp6kS3Z51FSajsFXgthloj6sSz+tl8JZ0jAZ/eIRLhlekt97xuIVGOdqxzL5bOjjfKgC6d8Jj/xzjgLz4u0iKr/eeSNHEYXnx1faz0Y1Ago7ILDkOJjLc04PdQj5ixadif2WcVTLRckgETC1LeJBoHfz+Q1ImU4FmsVvKrF7dxsUgXBEXs8RIGNbqel1Omc2euiDRdbRdVoRu1JWBch/1PLPUp8UmuJ/TWerIflZcW7XG/oEhyEjF9lyP1n4Tm7RmyG1skV3INg6ZZ6naegZlcDhCJeOkxS9YGwlqUEA4SGqLcJBuj6a6a13ZODKCRX5sSuvawuWKlqWlBLZVTunbTbGL9i+rSwDB/eAnv7AiB AgQ== 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: Functionally, no change. This is a preparation for luf mechanism that requires to recognize read-only tlb entries and handle them in a different way. The newly introduced API in this patch, fold_ubc(), will be used by luf mechanism. Signed-off-by: Byungchul Park --- include/linux/sched.h | 1 + mm/internal.h | 4 ++++ mm/rmap.c | 34 ++++++++++++++++++++++++++++++++-- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/include/linux/sched.h b/include/linux/sched.h index 2aa48adad226..0915390b1b5e 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1339,6 +1339,7 @@ struct task_struct { #endif struct tlbflush_unmap_batch tlb_ubc; + struct tlbflush_unmap_batch tlb_ubc_ro; unsigned short int ugen; /* Cache last used pipe for splice(): */ diff --git a/mm/internal.h b/mm/internal.h index 0d4c74e76de6..805f0e6ecab4 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -1100,6 +1100,7 @@ extern struct workqueue_struct *mm_percpu_wq; void try_to_unmap_flush(void); void try_to_unmap_flush_dirty(void); void flush_tlb_batched_pending(struct mm_struct *mm); +void fold_ubc(struct tlbflush_unmap_batch *dst, struct tlbflush_unmap_batch *src); #else static inline void try_to_unmap_flush(void) { @@ -1110,6 +1111,9 @@ static inline void try_to_unmap_flush_dirty(void) static inline void flush_tlb_batched_pending(struct mm_struct *mm) { } +static inline void fold_ubc(struct tlbflush_unmap_batch *dst, struct tlbflush_unmap_batch *src) +{ +} #endif /* CONFIG_ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH */ extern const struct trace_print_flags pageflag_names[]; diff --git a/mm/rmap.c b/mm/rmap.c index cf8a99a49aef..328b5e2217e6 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -635,6 +635,28 @@ struct anon_vma *folio_lock_anon_vma_read(struct folio *folio, } #ifdef CONFIG_ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH + +void fold_ubc(struct tlbflush_unmap_batch *dst, + struct tlbflush_unmap_batch *src) +{ + if (!src->flush_required) + return; + + /* + * Fold src to dst. + */ + arch_tlbbatch_fold(&dst->arch, &src->arch); + dst->writable = dst->writable || src->writable; + dst->flush_required = true; + + /* + * Reset src. + */ + arch_tlbbatch_clear(&src->arch); + src->flush_required = false; + src->writable = false; +} + /* * Flush TLB entries for recently unmapped pages from remote CPUs. It is * important if a PTE was dirty when it was unmapped that it's flushed @@ -644,7 +666,9 @@ struct anon_vma *folio_lock_anon_vma_read(struct folio *folio, void try_to_unmap_flush(void) { struct tlbflush_unmap_batch *tlb_ubc = ¤t->tlb_ubc; + struct tlbflush_unmap_batch *tlb_ubc_ro = ¤t->tlb_ubc_ro; + fold_ubc(tlb_ubc, tlb_ubc_ro); if (!tlb_ubc->flush_required) return; @@ -658,8 +682,9 @@ void try_to_unmap_flush(void) void try_to_unmap_flush_dirty(void) { struct tlbflush_unmap_batch *tlb_ubc = ¤t->tlb_ubc; + struct tlbflush_unmap_batch *tlb_ubc_ro = ¤t->tlb_ubc_ro; - if (tlb_ubc->writable) + if (tlb_ubc->writable || tlb_ubc_ro->writable) try_to_unmap_flush(); } @@ -676,13 +701,18 @@ void try_to_unmap_flush_dirty(void) static void set_tlb_ubc_flush_pending(struct mm_struct *mm, pte_t pteval, unsigned long uaddr) { - struct tlbflush_unmap_batch *tlb_ubc = ¤t->tlb_ubc; + struct tlbflush_unmap_batch *tlb_ubc; int batch; bool writable = pte_dirty(pteval); if (!pte_accessible(mm, pteval)) return; + if (pte_write(pteval)) + tlb_ubc = ¤t->tlb_ubc; + else + tlb_ubc = ¤t->tlb_ubc_ro; + arch_tlbbatch_add_pending(&tlb_ubc->arch, mm, uaddr); tlb_ubc->flush_required = true;