[PATCH v2 05/39] xen/riscv: request a G-stage flush on vmenter when VMIDs are disabled
Oleksii Kurochko <[email protected]>
| Newsgroups | gmane.comp.emulators.xen.devel |
|---|---|
| Message-ID | <4274740481062ef92a76debd9c3f1e8371858735.1787838835.git.oleksii.kurochko@gmail.com> |
vmid_handle_vmenter() reports that no flush is needed when VMIDs are
unavailable (vmid=off, or hardware with no more than one VMID bit). Every
domain then runs under VMID 0 with nothing flushed in between, so as soon
as a hart runs more than one domain, a domain entered there can use the
G-stage translations left behind by the domain which ran before it.
Adjust the comment in p2m_handle_vmenter() accordingly: skipping the
VS-stage flush no longer relies on an old VMID not being reused, which
doesn't hold when there are no VMIDs to begin with.
While at it, spell the other early return as a bool literal.
Fixes: bff3b9ea4696 ("xen/riscv: introduce VMID allocation and manegement")
Signed-off-by: Oleksii Kurochko <[email protected]>
---
Changes in v2:
- New patch.
---
---
xen/arch/riscv/p2m.c | 4 +++-
xen/arch/riscv/vmid.c | 4 ++--
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/xen/arch/riscv/p2m.c b/xen/arch/riscv/p2m.c
index 1cea86512c8c..de25607247a6 100644
--- a/xen/arch/riscv/p2m.c
+++ b/xen/arch/riscv/p2m.c
@@ -1584,7 +1584,9 @@ void p2m_handle_vmenter(void)
/*
* There is also no need to flush the VS-stage TLB: even if speculation
* occurs (VSATP + old HGATP were used), it will use the old VMID, which
- * won't be reused until need_flush is set to true.
+ * won't be reused until need_flush is set to true. When VMIDs aren't
+ * available there is no old VMID to rely on, but then need_flush is set
+ * on every entry, so the flush above covers that case.
*/
}
diff --git a/xen/arch/riscv/vmid.c b/xen/arch/riscv/vmid.c
index 11c7e9d6d6c8..93714b359534 100644
--- a/xen/arch/riscv/vmid.c
+++ b/xen/arch/riscv/vmid.c
@@ -141,7 +141,7 @@ bool vmid_handle_vmenter(struct vcpu_vmid *vmid)
/* Test if VCPU has valid VMID. */
if ( read_atomic(&vmid->generation) == data->generation )
- return 0;
+ return false;
/* If there are no free VMIDs, need to go to a new generation. */
if ( unlikely(data->next_vmid > data->max_vmid) )
@@ -164,7 +164,7 @@ bool vmid_handle_vmenter(struct vcpu_vmid *vmid)
disabled:
vmid->vmid = 0;
- return 0;
+ return true;
}
/*
--
2.55.0