From patchwork Thu Apr 18 06:15:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Byungchul Park X-Patchwork-Id: 13634194 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 99F5BC04FF8 for ; Thu, 18 Apr 2024 06:16:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 133126B0087; Thu, 18 Apr 2024 02:15:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0A0256B0088; Thu, 18 Apr 2024 02:15:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AABB56B0092; Thu, 18 Apr 2024 02:15:57 -0400 (EDT) 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 6CBBA6B0087 for ; Thu, 18 Apr 2024 02:15:57 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id F1A3D1C02A2 for ; Thu, 18 Apr 2024 06:15:56 +0000 (UTC) X-FDA: 82021641912.25.E3E9B6A Received: from invmail4.hynix.com (exvmail4.skhynix.com [166.125.252.92]) by imf08.hostedemail.com (Postfix) with ESMTP id 2B51516000D for ; Thu, 18 Apr 2024 06:15:54 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=none; spf=pass (imf08.hostedemail.com: domain of byungchul@sk.com designates 166.125.252.92 as permitted sender) smtp.mailfrom=byungchul@sk.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1713420955; a=rsa-sha256; cv=none; b=zFRIx61mzz0iC6aCbWHHuNiPKp4q7f/FR4cuj6XLJzy1WGzj2usGURkxUR7SUIbb1D/+g4 BgCpzpjiD+wjgWi/rCR4Dl3TGvuJwzlBplKpjAQxfDZCODtuQAg0g8dUBQAZsRm3qdGGoa Lkjztisu7Cn88bSgLODVFV6+E975nvM= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=none; spf=pass (imf08.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=1713420955; 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=CikM8Jg+d4XPMfLiLauAmUruEdAd319Y8J5ZbRW73Es=; b=EBOjkhWNt+I+tDL0jULNSnH9nxonW2KKS/wuHLZQoYQecMGt0m2uPgyqrv9Ipd7GtN7isp SY4ZyQ3QWso3yc8DI261jkOvV65y0R4Pp/kiB/H7kJyoCTXCrqV53bTG8F93gGtUeBIml1 Ic9fhowsbRjuOtr8kwISxmDsIJhHMHs= X-AuditID: a67dfc5b-d6dff70000001748-07-6620ba92c178 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 v9 rebase on mm-unstable 3/8] mm/rmap: recognize read-only tlb entries during batched tlb flush Date: Thu, 18 Apr 2024 15:15:31 +0900 Message-Id: <20240418061536.11645-4-byungchul@sk.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240418061536.11645-1-byungchul@sk.com> References: <20240418061536.11645-1-byungchul@sk.com> X-Brightmail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TqsXmFlsfiPS+ZPDat 6mTz2PRpErvHu3Pn2D1OzPjN4jHvZKDH+31X2TwWv/jA5LH1l51H49RrbB6fN8kF8Edx2aSk 5mSWpRbp2yVwZdzeOoW5YKZ0xbeJd9kbGHeIdTFyckgImEhMn3uNHcRmE1CXuHHjJzOILSJg JnGw9Q9YnFngLpPEgX42EFtYIF+i80E7WJxFQFXiUPt0FhCbV8BUYu6ew8wQM+UlVm84AGZz As3pf3+IsYuRg0MIqObC35AJjFwLGBlWMYpk5pXlJmbmmOoVZ2dU5mVW6CXn525iBIbxsto/ E3cwfrnsfohRgINRiYf3xAH5NCHWxLLiytxDjBIczEoivC3CsmlCvCmJlVWpRfnxRaU5qcWH GKU5WJTEeb3CUxOEBNITS1KzU1MLUotgskwcnFINjNndBcw/Xn/9m5u14OucFfrPOcL9XMX6 32jxMhpOvDz5/grFtH+bJhZOnmJbsKFJ9NuOypznyZ9WV96q0Z4ue/RY4ZS3nIeL272KV8l9 0kkMv63mw+d//7nqglllO878KlkYIRN4jfnmW7GXp7J5nfxnTcxi5dbd8UoqPPqSDa8N74fs 4qUeOUosxRmJhlrMRcWJALjcXcFfAgAA X-CFilter-Loop: Reflected X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 2B51516000D X-Stat-Signature: yirbeumtq1hsf7ghhytd8d9qe55b11ab X-Rspam-User: X-HE-Tag: 1713420954-91124 X-HE-Meta: U2FsdGVkX19xEvtyO/I36GaMLntwIQD4y4rp1sifdg7Lnv3ey1dV/8QMJjugIuyPZ2AUWPxB7nRYM2JfpUtgjScWEI7lBTTUp7/akcFzG1JL6vaN20xwi7HjQ1iPQeVuLzLsxxRSBtKaQl5j30C23GlIe/PqeHrilAyTRpu4YdSqBBhJIQI82mOiezL0Lqz5UM/gSE6T8tJvpkUqyvxwaOnLHBZlXqWW0kavuYM7Y4ywqYDECOqqmuTrq0KFFdl8wmeaxsSFDmlfn8Oaja3wr3AqOqKIV1v9hQaryO4nU7h1vR/GhgNaPBwBFdupE4GEl2pNnFYhFSQAgN0VnnB9wBW1EOfZpWnmPa3yo7wFlJIvE4fcbvGUEDK0N7038m1gcnxCAhfrYHx3Qe2/0uFN50s+Ck1j2aE/khenjdps22S1IRRUpHmqTJJ3FAYIH9YgktJzMB+4LCcMEvigFCCSzEa79rmf1gvRDtSer7N5LllIg78VOX5gWTt3zXAqNQLf0YpJPlBwQ//lFoX6f2A4jJAGy0Kx7FEP6zT9lXgjF1KY4+gPxO5t8GZu6m3nZt4OTqTBCFbzGJZmX/q23E75G2GBfh1moqRiSwMPezs57NSFtIM0CY17ZeyMQXJd1bSJcOllQrghXKt4/ZmURqiFOggV4hiQxn0AY/Fuqpyjjmd8nxOn1WPze78eNnPrS9Vq44wjjsGIqbs/OB7mvXhHbWhgsi480L86r4N9VNHMiTtY0MUIOMY0DdgwUmhLj+ifFdPPar1ycrIyUw4aBgjoXEJx+vFgQT8BPElj/AjydcZuOEo93SrtAab7hLpc/EtYRDoC3s+ktYVeizVEwzMELwF/2oasPdlN+VOA0oFiTg1brjlGuRTAZuccDltvJ+y4G6V9cWxLVlPaa/SCZ6tljglE6Sj6iYh2EnWFJ+R2UjIaccr3Qi88+XgkDpz6RlsGL5ZqOhNXz2vNj0vCLXO oww== 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 migrc mechanism that requires to recognize read-only tlb entries and handle them in a different way. The newly introduced API, fold_ubc(), will be used by migrc mechanism. Signed-off-by: Byungchul Park --- include/linux/sched.h | 1 + mm/internal.h | 4 ++++ mm/rmap.c | 31 ++++++++++++++++++++++++++++++- 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/include/linux/sched.h b/include/linux/sched.h index 4118b3f959c3..f9f8091f354f 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; /* Cache last used pipe for splice(): */ struct pipe_inode_info *splice_pipe; diff --git a/mm/internal.h b/mm/internal.h index c6483f73ec13..b34d9e627132 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 2608c40dffad..c37ff1648cf1 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; @@ -675,13 +699,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) || writable) + 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;