From patchwork Wed Apr 17 07:18:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Byungchul Park X-Patchwork-Id: 13632931 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 6CBF5C4345F for ; Wed, 17 Apr 2024 07:19:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7911F6B0098; Wed, 17 Apr 2024 03:19:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 718556B009B; Wed, 17 Apr 2024 03:19:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4D01E6B009A; Wed, 17 Apr 2024 03:19:09 -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 261986B0092 for ; Wed, 17 Apr 2024 03:19:09 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id C9F9C80D6B for ; Wed, 17 Apr 2024 07:19:08 +0000 (UTC) X-FDA: 82018172376.07.6A9C28C Received: from invmail4.hynix.com (exvmail4.hynix.com [166.125.252.92]) by imf12.hostedemail.com (Postfix) with ESMTP id E602C4000D for ; Wed, 17 Apr 2024 07:19:06 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=none; spf=pass (imf12.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=1713338347; a=rsa-sha256; cv=none; b=ROEB2Y2rl0Jx3iMF/XYPOYi/MW3oCQsvr/0d5Fkg3DCjnZIjpHRMJ8ujVpW9N21g3tBQA6 33k61oMHIdC8Sm9Cv4Mz6pdJp0meAcuazfsYnctyiY8uoT1t0USlugrp157xvMtbmlCE4M eFz3R5KNYWu08LZsS7XV31FWSagAqS4= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=none; spf=pass (imf12.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=1713338347; 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=yfhK7sb49KRo43n03h4lTzgpIvnVpCj2itliDAzrNbw=; b=ZcRnkgrauhZSJpZueDnSnSB4GNI9TSA8MH4ccVXESOBN23VxckU78cinRZ3Cp08b+3wilY DvtAkPOZ2e7YNyhzfZtYy5lHma4X/JLysiwfd7JH56zdx9OoxqdVC2f+vHfhPXvxquztf1 sIKBkRxwbvRpuySV3RLR56bX8yEbVGQ= X-AuditID: a67dfc5b-d6dff70000001748-9d-661f77e24455 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 3/8] mm/rmap: recognize read-only tlb entries during batched tlb flush Date: Wed, 17 Apr 2024 16:18:42 +0900 Message-Id: <20240417071847.29584-4-byungchul@sk.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240417071847.29584-1-byungchul@sk.com> References: <20240417071847.29584-1-byungchul@sk.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+Ng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rbB6LX3xg8tj6y86jceo1No/Pm+QC+KO4bFJS czLLUov07RK4MvYuX8VUMFO64tqGPewNjDvEuhg5OSQETCSOruliA7HZBNQlbtz4yQxiiwiY SRxs/cMOYjML3GWSONAPViMsECnxdN9bsDiLgKrEvUcnwOp5BUwl1r/vYISYKS+xesMBsDgn 0JzNzWvAeoWAar6f+Mg2gZFrASPDKkaRzLyy3MTMHFO94uyMyrzMCr3k/NxNjMBAXlb7Z+IO xi+X3Q8xCnAwKvHwGkTJpQmxJpYVV+YeYpTgYFYS4W0Rlk0T4k1JrKxKLcqPLyrNSS0+xCjN waIkzusVnpogJJCeWJKanZpakFoEk2Xi4JRqYDznvqdLebNf1O7N+48ZhvUndxeJ+V2u08uL 6db9vUEt9In0w5kCliUlYdmOZrcWPj/tbnbMJOd+MPv7wzOeRancuv3oOqOW2MH/IQ8Oa2zT epL/SG3/rvj9P9MdH6y58NE683qAvIuK3/ILC0suPlog3drL8YRf/XCeteTMtcle7lN/BTYc MFZiKc5INNRiLipOBAB1cBaHYAIAAA== X-CFilter-Loop: Reflected X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: E602C4000D X-Stat-Signature: wgmegx4o9d95dq9rtuq5xjw8b439et9o X-Rspam-User: X-HE-Tag: 1713338346-545318 X-HE-Meta: U2FsdGVkX1925yQkbxSjWHUTA/hAG4ihEyFtkJNuKRslvDJdV5QMEX8Eu+TJ65BltumOpsLizHGAr9eAeFZ9gy8kfiz3t37C3ujWiN/2YmyQGt0L2c8ujis1seD4dwBQT8KKKZc0J96yIOMUJZi1/Wiw5hZNX5kzd/QfOt0DY2VZMdS66Is1BsKDPXliFyWrtAvEGcMcKACBcyIDHuv8EdpW6QBJ1Rsa6j5gDV9zQgaP/JUVj4Btc/dAYB5u1CvTbptgSfXv7wlj6QxRgaAf7u9+3DcWBpt/BXAwELU82ar5rdSnRbcgpIl5AFO8EBeoY3LkGV9b4h3xQaRA+O8ZAXNtmepyS3gnKWPkWQYI2eUJcxcuf/ro7ta56qY1S9y6DzhLA2+M5ya4nUE1it1G2gi4KZyxzoSofEopzY9WeNZ13aH6kgdqHNDIna5VuZSXFIafCaVuAoywvCpr70thFjgSCDmPj5v6o3oa7Wyq/clhlLxNeA+qVMq0vqWxl//QRXBzXYTlISa6t6KKTduwYR4Xh43o6P3KOVo2qZMwa8BXi2uE4I0f55t4H+UlBn5nP1tBkVqJzu/bPlSMDPDx8+pLBJ1m1+hC+zJZxBERh0RTeIFcHZhEohjlE6B01/N1IBiMWZb16b2eqtfl9Rm5CBzHjNV1A5XazTNqVFjq31M2SS2X1QtPrG9zC0x/fnrmPa/ceujNcUeRhQ0OBpHRJiw4MLuNpVImNgajjEMrWRA4u6BoIBYxNixbl1Kzkvc0IODQtebxwaLyvE4rp9ZIh4xYay/BiKuU6vUr+G4pqTuwNvNSaMeR4CORHx0nz8I75DbMSN+1lpmzb4AQ/aRXgMZdy8XXVSBePP5ad0OxI3bd7JbGDOrC0YaU5g2eXMPJrV47cZyYhwADbIa2k4QsWqq2siMjey53DTZGn0s9KlYWXHf4tsAHOlgZmpyu8RjmWbB68vmgJZEIjPiK3HH jbQ== 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 3c2abbc587b4..823d83b24364 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1334,6 +1334,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 7e486f2c502c..bbaf1fd97b1c 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -1019,6 +1019,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) { @@ -1029,6 +1030,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 3746a5531018..2542bfe1a947 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;