From: Xu Lu <luxu.kernel@bytedance.com>
To: pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu,
alex@ghiti.fr, apatel@ventanamicro.com, guoren@kernel.org
Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
Xu Lu <luxu.kernel@bytedance.com>
Subject: [RFC PATCH v1 1/4] riscv: mm: Introduce percpu loaded_asid
Date: Thu, 30 Oct 2025 21:56:49 +0800 [thread overview]
Message-ID: <20251030135652.63837-2-luxu.kernel@bytedance.com> (raw)
In-Reply-To: <20251030135652.63837-1-luxu.kernel@bytedance.com>
The percpu loaded_asid records the asid currently used by each CPU.
Signed-off-by: Xu Lu <luxu.kernel@bytedance.com>
---
arch/riscv/include/asm/mmu_context.h | 1 +
arch/riscv/mm/context.c | 4 ++++
2 files changed, 5 insertions(+)
diff --git a/arch/riscv/include/asm/mmu_context.h b/arch/riscv/include/asm/mmu_context.h
index 8c4bc49a3a0f5..fd532f8e8d057 100644
--- a/arch/riscv/include/asm/mmu_context.h
+++ b/arch/riscv/include/asm/mmu_context.h
@@ -39,6 +39,7 @@ static inline int init_new_context(struct task_struct *tsk,
}
DECLARE_STATIC_KEY_FALSE(use_asid_allocator);
+DECLARE_PER_CPU(unsigned long, loaded_asid);
#ifdef CONFIG_RISCV_ISA_SUPM
#define mm_untag_mask mm_untag_mask
diff --git a/arch/riscv/mm/context.c b/arch/riscv/mm/context.c
index 55c20ad1f7444..4d5792c3a8c19 100644
--- a/arch/riscv/mm/context.c
+++ b/arch/riscv/mm/context.c
@@ -32,6 +32,8 @@ static unsigned long *context_asid_map;
static DEFINE_PER_CPU(atomic_long_t, active_context);
static DEFINE_PER_CPU(unsigned long, reserved_context);
+DEFINE_PER_CPU(unsigned long, loaded_asid) = 0;
+
static bool check_update_reserved_context(unsigned long cntx,
unsigned long newcntx)
{
@@ -193,6 +195,8 @@ static void set_mm_asid(struct mm_struct *mm, unsigned int cpu)
(cntx2asid(cntx) << SATP_ASID_SHIFT) |
satp_mode);
+ this_cpu_write(loaded_asid, cntx2asid(cntx));
+
if (need_flush_tlb)
local_flush_tlb_all();
}
--
2.20.1
next prev parent reply other threads:[~2025-10-30 13:57 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-30 13:56 [RFC PATCH v1 0/4] riscv: mm: Defer tlb flush to context_switch Xu Lu
2025-10-30 13:56 ` Xu Lu [this message]
2025-10-30 13:56 ` [RFC PATCH v1 2/4] riscv: mm: Introduce percpu tlb flush queue Xu Lu
2025-10-30 13:56 ` [RFC PATCH v1 3/4] riscv: mm: Enqueue tlbflush info if task is not running on target cpu Xu Lu
2025-10-30 13:56 ` [RFC PATCH v1 4/4] riscv: mm: Perform tlb flush during context_switch Xu Lu
2025-11-03 3:44 ` Guo Ren
2025-11-03 3:44 ` [RFC PATCH v1 0/4] riscv: mm: Defer tlb flush to context_switch Guo Ren
2025-11-03 7:06 ` [External] " Xu Lu
2025-11-07 1:55 ` Guo Ren
2025-11-07 3:03 ` [External] " Xu Lu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251030135652.63837-2-luxu.kernel@bytedance.com \
--to=luxu.kernel@bytedance.com \
--cc=alex@ghiti.fr \
--cc=aou@eecs.berkeley.edu \
--cc=apatel@ventanamicro.com \
--cc=guoren@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=palmer@dabbelt.com \
--cc=pjw@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®