From: "GUO Ren (XuanTie)" <guoren@kernel.org>
To: Anup Patel <anup@brainfault.org>,
Atish Patra <atish.patra@linux.dev>,
Paul Walmsley <pjw@kernel.org>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>,
Alexandre Ghiti <alex@ghiti.fr>
Cc: kvm@vger.kernel.org, kvm-riscv@lists.infradead.org,
linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
"GUO Ren (XuanTie)" <guoren@kernel.org>
Subject: [PATCH] RISC-V: KVM: AIA: Initialize per-CPU HGEI free_bitmap only once
Date: Thu, 24 Sep 2026 06:03:49 +0000 [thread overview]
Message-ID: <20260924-free_bitmap_initialized-v1-1-4cfb73a0d04b@kernel.org> (raw)
kvm_riscv_aia_enable() may run more than once on the same CPU. The
per-CPU free_bitmap only needs to be initialized once, from the HGEIE
width discovered on that CPU. Perform the HGEIE probe and bitmap
setup only on the first call, and set free_bitmap_initialized after
the bitmap has been populated.
Signed-off-by: GUO Ren (XuanTie) <guoren@kernel.org>
---
arch/riscv/kvm/aia.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/arch/riscv/kvm/aia.c b/arch/riscv/kvm/aia.c
index b3b466e4db33..a65748321f7d 100644
--- a/arch/riscv/kvm/aia.c
+++ b/arch/riscv/kvm/aia.c
@@ -610,6 +610,9 @@ void kvm_riscv_aia_enable(void)
lc = (gc) ? this_cpu_ptr(gc->local) : NULL;
hgctrl = this_cpu_ptr(&aia_hgei);
+ if (hgctrl->free_bitmap_initialized)
+ goto skip_hgctrl_init;
+
/* Figure-out number of bits in HGEIE */
csr_write(CSR_HGEIE, -1UL);
hgctrl->nr_hgei = fls_long(csr_read(CSR_HGEIE));
@@ -634,12 +637,11 @@ void kvm_riscv_aia_enable(void)
} while (!atomic_try_cmpxchg(&kvm_riscv_aia_nr_hgei, &aia_nr_hgei, hgctrl->nr_hgei));
raw_spin_lock_irqsave(&hgctrl->lock, flags);
- if (!hgctrl->free_bitmap_initialized) {
- hgctrl->free_bitmap = (hgctrl->nr_hgei) ? GENMASK_ULL(hgctrl->nr_hgei, 1) : 0;
- hgctrl->free_bitmap_initialized = true;
- }
+ hgctrl->free_bitmap = (hgctrl->nr_hgei) ? GENMASK_ULL(hgctrl->nr_hgei, 1) : 0;
+ hgctrl->free_bitmap_initialized = true;
raw_spin_unlock_irqrestore(&hgctrl->lock, flags);
+skip_hgctrl_init:
csr_write(CSR_HVICTL, aia_hvictl_value(false));
csr_write(CSR_HVIPRIO1, 0x0);
csr_write(CSR_HVIPRIO2, 0x0);
---
base-commit: 93f51579e7df248780214094418f205253383cc5
change-id: 20260924-free_bitmap_initialized-abdc94a528fb
Best regards,
--
GUO Ren (XuanTie) <guoren@kernel.org>
reply other threads:[~2026-09-24 6:04 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260924-free_bitmap_initialized-v1-1-4cfb73a0d04b@kernel.org \
--to=guoren@kernel.org \
--cc=alex@ghiti.fr \
--cc=anup@brainfault.org \
--cc=aou@eecs.berkeley.edu \
--cc=atish.patra@linux.dev \
--cc=kvm-riscv@lists.infradead.org \
--cc=kvm@vger.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®