[PATCH v3 02/20] xen/riscv: introduce sbi_remote_hfence_gvma_vmid()

Oleksii Kurochko posted 20 patches 3 months ago
There is a newer version of this series
[PATCH v3 02/20] xen/riscv: introduce sbi_remote_hfence_gvma_vmid()
Posted by Oleksii Kurochko 3 months ago
It instructs the remote harts to execute one or more HFENCE.GVMA instructions
by making an SBI call, covering the range of guest physical addresses between
start_addr and start_addr + size only for the given VMID.

The remote fence operation applies to the entire address space if either:
  - start_addr and size are both 0, or
  - size is equal to 2^XLEN-1.

Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
---
Changes in V3:
 - Drop ASSERT() in sbi_remote_hfence_gvma_vmid() as failure will happen anyway if
   rfence isn't initialized.
 - Drop "This function call is only valid for harts implementing hypervisor
   extension." from the commit message and the comment above the declaration
   of sbi_remote_hfence_gvma_vmid().
 - Use proper FID for sbi_remote_hfence_gvma_vmid().
---
Changes in V2:
 - New patch.
---
 xen/arch/riscv/include/asm/sbi.h | 13 +++++++++++++
 xen/arch/riscv/sbi.c             |  7 +++++++
 2 files changed, 20 insertions(+)

diff --git a/xen/arch/riscv/include/asm/sbi.h b/xen/arch/riscv/include/asm/sbi.h
index 0277aab747..10930dea93 100644
--- a/xen/arch/riscv/include/asm/sbi.h
+++ b/xen/arch/riscv/include/asm/sbi.h
@@ -108,6 +108,19 @@ int sbi_remote_sfence_vma(const cpumask_t *cpu_mask, vaddr_t start,
 int sbi_remote_hfence_gvma(const cpumask_t *cpu_mask, vaddr_t start,
                            size_t size);
 
+/*
+ * Instruct the remote harts to execute one or more HFENCE.GVMA instructions,
+ * covering the range of guest physical addresses between start_addr and
+ * start_addr + size only for the given VMID.
+ *
+ * @cpu_mask a cpu mask containing all the target CPUs (in Xen space).
+ * @param start virtual address start
+ * @param size virtual address range size
+ * @param vmid virtual machine id
+ */
+int sbi_remote_hfence_gvma_vmid(const cpumask_t *cpu_mask, vaddr_t start,
+                                size_t size, unsigned long vmid);
+
 /*
  * Initialize SBI library
  *
diff --git a/xen/arch/riscv/sbi.c b/xen/arch/riscv/sbi.c
index 1809f614c5..425dce44c6 100644
--- a/xen/arch/riscv/sbi.c
+++ b/xen/arch/riscv/sbi.c
@@ -265,6 +265,13 @@ int sbi_remote_hfence_gvma(const cpumask_t *cpu_mask, vaddr_t start,
                       cpu_mask, start, size, 0, 0);
 }
 
+int sbi_remote_hfence_gvma_vmid(const cpumask_t *cpu_mask, vaddr_t start,
+                                size_t size, unsigned long vmid)
+{
+    return sbi_rfence(SBI_EXT_RFENCE_REMOTE_HFENCE_GVMA_VMID,
+                      cpu_mask, start, size, vmid, 0);
+}
+
 /* This function must always succeed. */
 #define sbi_get_spec_version()  \
     sbi_ext_base_func(SBI_EXT_BASE_GET_SPEC_VERSION)
-- 
2.50.1
Re: [PATCH v3 02/20] xen/riscv: introduce sbi_remote_hfence_gvma_vmid()
Posted by Jan Beulich 2 months, 3 weeks ago
On 31.07.2025 17:58, Oleksii Kurochko wrote:
> It instructs the remote harts to execute one or more HFENCE.GVMA instructions
> by making an SBI call, covering the range of guest physical addresses between
> start_addr and start_addr + size only for the given VMID.
> 
> The remote fence operation applies to the entire address space if either:
>   - start_addr and size are both 0, or
>   - size is equal to 2^XLEN-1.
> 
> Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>

Acked-by: Jan Beulich <jbeulich@suse.com>
with perhaps a similar on-commit edit as suggested for patch 1.

Jan
Re: [PATCH v3 02/20] xen/riscv: introduce sbi_remote_hfence_gvma_vmid()
Posted by Oleksii Kurochko 2 months, 3 weeks ago
On 8/4/25 3:55 PM, Jan Beulich wrote:
> On 31.07.2025 17:58, Oleksii Kurochko wrote:
>> It instructs the remote harts to execute one or more HFENCE.GVMA instructions
>> by making an SBI call, covering the range of guest physical addresses between
>> start_addr and start_addr + size only for the given VMID.
>>
>> The remote fence operation applies to the entire address space if either:
>>    - start_addr and size are both 0, or
>>    - size is equal to 2^XLEN-1.
>>
>> Signed-off-by: Oleksii Kurochko<oleksii.kurochko@gmail.com>
> Acked-by: Jan Beulich<jbeulich@suse.com>
> with perhaps a similar on-commit edit as suggested for patch 1.

I would happy if you could do that during merge. Thanks.

~ Oleksii