[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251030135652.63837-4-luxu.kernel@bytedance.com>
Date: Thu, 30 Oct 2025 21:56:51 +0800
From: Xu Lu <luxu.kernel@...edance.com>
To: pjw@...nel.org,
	palmer@...belt.com,
	aou@...s.berkeley.edu,
	alex@...ti.fr,
	apatel@...tanamicro.com,
	guoren@...nel.org
Cc: linux-riscv@...ts.infradead.org,
	linux-kernel@...r.kernel.org,
	Xu Lu <luxu.kernel@...edance.com>
Subject: [RFC PATCH v1 3/4] riscv: mm: Enqueue tlbflush info if task is not running on target cpu
When need to flush tlb of a remote cpu, we only send ipi to the target
cpu if the task is currently running on it. Otherwise, we only enqueue
the tlb flush info in target cpu's tlb flush queue.
Signed-off-by: Xu Lu <luxu.kernel@...edance.com>
---
 arch/riscv/mm/tlbflush.c | 30 +++++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)
diff --git a/arch/riscv/mm/tlbflush.c b/arch/riscv/mm/tlbflush.c
index aa8f1304ae5c4..f4333c3a6d251 100644
--- a/arch/riscv/mm/tlbflush.c
+++ b/arch/riscv/mm/tlbflush.c
@@ -115,6 +115,32 @@ DEFINE_PER_CPU(struct tlb_flush_queue, tlb_flush_queue) = {
 	.len = 0,
 };
 
+static bool should_ipi_flush(int cpu, void *info)
+{
+	struct tlb_flush_queue *queue = per_cpu_ptr(&tlb_flush_queue, cpu);
+	struct flush_tlb_range_data *d = info;
+	unsigned long flags;
+
+	if (per_cpu(loaded_asid, cpu) == d->asid)
+		return true;
+
+	raw_spin_lock_irqsave(&queue->lock, flags);
+	if (queue->len < TLB_FLUSH_QUEUE_SIZE) {
+		queue->tasks[queue->len] = *d;
+		queue->len++;
+	} else {
+		raw_spin_unlock_irqrestore(&queue->lock, flags);
+		return true;
+	}
+	raw_spin_unlock_irqrestore(&queue->lock, flags);
+
+	/* Recheck whether loaded_asid changed during enqueueing task */
+	if (per_cpu(loaded_asid, cpu) == d->asid)
+		return true;
+
+	return false;
+}
+
 static void __ipi_flush_tlb_range_asid(void *info)
 {
 	struct flush_tlb_range_data *d = info;
@@ -152,7 +178,9 @@ static void __flush_tlb_range(struct mm_struct *mm,
 		ftd.start = start;
 		ftd.size = size;
 		ftd.stride = stride;
-		on_each_cpu_mask(cmask, __ipi_flush_tlb_range_asid, &ftd, 1);
+		on_each_cpu_cond_mask(should_ipi_flush,
+				      __ipi_flush_tlb_range_asid,
+				      &ftd, 1, cmask);
 	}
 
 	put_cpu();
-- 
2.20.1
Powered by blists - more mailing lists
 
