From patchwork Mon May 20 02:17:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Byungchul Park X-Patchwork-Id: 13668003 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 A6AA1C25B79 for ; Mon, 20 May 2024 02:18:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1DA1F6B00A0; Sun, 19 May 2024 22:17:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0C2316B009F; Sun, 19 May 2024 22:17:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CF5C86B009D; Sun, 19 May 2024 22:17:54 -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 ABF9F6B009B for ; Sun, 19 May 2024 22:17:54 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 5DD3614014A for ; Mon, 20 May 2024 02:17:54 +0000 (UTC) X-FDA: 82137163668.17.2E040DD Received: from invmail4.hynix.com (exvmail4.skhynix.com [166.125.252.92]) by imf01.hostedemail.com (Postfix) with ESMTP id 9460440008 for ; Mon, 20 May 2024 02:17:52 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=none; spf=pass (imf01.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=1716171473; 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=wOT8JZhCYcTKjC7OJKRc/UM6v7EjU4NC17iXVJbbcn2/xh/iHLvwqC6bu/0ALGnzjJTx1l OvSFoPklUR1YMjs/tgExJRjsPnJci/WiX7RQBUqhEF5xWqg+SB0X68AbztyEQUQQDJGOl7 pA5soacJu6bPm/KlMk0UREiH4QGdAPM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1716171473; a=rsa-sha256; cv=none; b=1uL/E8rUyJs2imbboEM1WIBNpNZHM7Y3pI69hZI2X0qXxWueg7D06AngXx8Hat7TWC1+0+ dNvAyrPE8LFnlp86SLIqT2bpqqRbiuHZQquMXFhviT7da6loEWuj20q97J7ExNWpbTr6Fi k7CU0Nu961/TfDEcRnvfq/hpKtvxnCs= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=none; spf=pass (imf01.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-bd-664ab2c98c0d 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: [RESEND PATCH v10 08/12] mm/rmap: recognize read-only tlb entries during batched tlb flush Date: Mon, 20 May 2024 11:17:30 +0900 Message-Id: <20240520021734.21527-9-byungchul@sk.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240520021734.21527-1-byungchul@sk.com> References: <20240520021734.21527-1-byungchul@sk.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrMLMW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nksfvGByWPrLzuPxqnX2Dw+b5IL4I/isklJ zcksSy3St0vgymh494i94I5sxcXdM9gaGI9IdDFyckgImEhMfXSdBcRmE1CXuHHjJzOILSJg JnGw9Q87iM0scJdJ4kA/G4gtLJAs8WbXZjCbRUBVomHqDUYQm1fAVKJ76TFGiJnyEqs3HACb wwk0Z8aqnWDzhYBqfhz9yjaBkWsBI8MqRpHMvLLcxMwcU73i7IzKvMwKveT83E2MwEBeVvtn 4g7GL5fdDzEKcDAq8fBuuO2ZJsSaWFZcmXuIUYKDWUmEd9MWoBBvSmJlVWpRfnxRaU5q8SFG aQ4WJXFer/DUBCGB9MSS1OzU1ILUIpgsEwenVAPjGuXpyvuCa4Wu5Zi71sTNiF1o+txDyetj bdGGb6fOL2szUmfOtvJ1uPO4b07X67ieDfWPcibJpix8tp39xuLE1jwZR4ZNZ8L+7JNhkDz8 veLy73xfa6sPltFa618dPjm1tlJ53Rq+oJvr3nw7Grs30Fxn8hOBf8+2ZLpMqrH5F1H9fnMK Z890JZbijERDLeai4kQA4J+2GmACAAA= X-CFilter-Loop: Reflected X-Rspam-User: X-Stat-Signature: ct1dkkgms4xqrq9rgp7cuypi9tscongx X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 9460440008 X-HE-Tag: 1716171472-578750 X-HE-Meta: U2FsdGVkX19JKEUH/CHsiEZrEHpjV3Kq2ZFFMKv5x3/1ETqj5EKbyJuOyo4lnsn0kAkec+gmNe4inggky+OQUQ0iZAL6kw+dqxu9CAE4tmuQqGDxfrx+BjEuc0/4Z4bxwta0lKNXh2GWciRv0dhu4MTIe1LD+XSIay5YN7DtXRaeSGue5ZVrdSpxNM24T1jeKq8Qe79YzyvBYIUYwFszlctMXOuqQxJyPJeZjdoxij21bO2vn+lawKtzdQqROdXPZl1V5W5NHhtZj11HeW8A0kTcvyi5AXAOy45Z5GoWWymNkbZqqGF2YJ8HmDGzA0FKbUpPczJEPEffkgPg4h1cq2VenPkVma8adhCGu9Lbuv8Py407TGfKxn2iCZExJB2Ln0UGJ9ygv10AlxdSMt0FCJLfsXLX4LXBcGvT4pP6JoiB7J+aVK8/MjnCHC4ln1wm3WdBbdOnu6e7QdQjWhMMtBajBS6oiUFKYq/QiyAo1JtyPmfj2cQYQ031LqTudwpRbw6lY81nU2ZFZHshBJsX8hY3VfsGM6T+4UNqsrmnW9Z0LGpOO9Mc3ydUto6pMtHkWLH5RZh75q3OvjAnbzFq6F7Xhknt3nzrzHYUtuITucPhNLSQnhKPtbg3UdTRzTnC7yt49/Ls3Fcb8V10SrtoHwCi410ckcY0B95qrJQyHXPM0fu0TMfMlpmzhu9xZOvRA/VflgYXzER+kXN7as6+VySy8XrlwXzNLFMLadKqdgcE9IQjUZLAZZdrJm9IMfatQOXIHYMpEyAPMyZYZ05n0w4Hmrtr6pbaqeIhfqqDtsQh6g8DcArK2YNrpbuZnzZYj8j8kEl0EyjgXBE46NeQ/N2m7gNlcXLX7ba8uEK5l58efnQyfQbAizzqDO0YPCEzqaTSFJkrIKievJ2V7oTPN27dPxAMj+AhThuugM+fTB6qBJFZQsnbDxpl8eeUOxSntJx/7qMlvlflF2WJeQI vGA== 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;