Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F177019943
D61126.1793738020.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
3 KB
Referenced Files
None
Subscribers
None
D61126.1793738020.diff
View Options
diff --git a/sys/riscv/riscv/sbi_ipi.c b/sys/riscv/riscv/sbi_ipi.c
--- a/sys/riscv/riscv/sbi_ipi.c
+++ b/sys/riscv/riscv/sbi_ipi.c
@@ -74,6 +74,8 @@
mask |= (1ul << pc->pc_hart);
}
}
+ if (mask == 0)
+ return;
sbi_send_ipi(&mask);
}
diff --git a/sys/riscv/vmm/vmm_riscv.c b/sys/riscv/vmm/vmm_riscv.c
--- a/sys/riscv/vmm/vmm_riscv.c
+++ b/sys/riscv/vmm/vmm_riscv.c
@@ -548,6 +548,8 @@
if (!CPU_ISSET(i, cpus))
continue;
hypctx = hyp->ctx[i];
+ if (hypctx == NULL)
+ continue;
atomic_set_32(&hypctx->ipi_pending, 1);
vcpu_notify_event(vm_vcpu(vm, i));
}
diff --git a/sys/riscv/vmm/vmm_sbi.c b/sys/riscv/vmm/vmm_sbi.c
--- a/sys/riscv/vmm/vmm_sbi.c
+++ b/sys/riscv/vmm/vmm_sbi.c
@@ -52,7 +52,7 @@
struct hyp *hyp;
uint16_t maxcpus;
cpuset_t cpus;
- int i;
+ u_int i;
func_id = hypctx->guest_regs.hyp_a[6];
hart_mask = hypctx->guest_regs.hyp_a[0];
@@ -83,27 +83,29 @@
hyp = hypctx->hyp;
active_cpus = vm_active_cpus(hyp->vm);
maxcpus = vm_get_maxcpus(hyp->vm);
- for (i = 0; i < maxcpus; i++) {
- vcpu = vm_vcpu(hyp->vm, i);
- if (vcpu == NULL)
- continue;
- if (hart_mask_base != -1UL) {
- if (i < hart_mask_base)
- continue;
- if (!(hart_mask & (1UL << (i - hart_mask_base))))
- continue;
- }
- /*
- * If either hart_mask_base or at least one hartid from
- * hart_mask is not valid, then return error.
- */
- if (!CPU_ISSET(i, &active_cpus))
+
+ if (hart_mask_base == (uint64_t)-1) {
+ CPU_COPY(&active_cpus, &cpus);
+ } else {
+ if (hart_mask == 0)
+ return (SBI_SUCCESS);
+ if (hart_mask_base >= maxcpus)
return (SBI_ERR_INVALID_PARAM);
- CPU_SET(i, &cpus);
+
+ while (hart_mask != 0) {
+ i = ffsl(hart_mask) - 1;
+ hart_mask &= ~(1UL << i);
+
+ if (hart_mask_base + i >= maxcpus)
+ return (SBI_ERR_INVALID_PARAM);
+ if (!CPU_ISSET(hart_mask_base + i, &active_cpus))
+ return (SBI_ERR_INVALID_PARAM);
+ CPU_SET(hart_mask_base + i, &cpus);
+ }
}
if (CPU_EMPTY(&cpus))
- return (SBI_ERR_INVALID_PARAM);
+ return (SBI_SUCCESS);
vmm_fence_add(hyp->vm, &cpus, &fence);
@@ -138,9 +140,9 @@
uint64_t hart_mask;
uint64_t hart_mask_base;
uint64_t func_id;
+ uint16_t maxcpus;
cpuset_t cpus;
- int hart_id;
- int bit;
+ u_int i;
func_id = hypctx->guest_regs.hyp_a[6];
hart_mask = hypctx->guest_regs.hyp_a[0];
@@ -151,18 +153,30 @@
hyp = hypctx->hyp;
active_cpus = vm_active_cpus(hyp->vm);
+ maxcpus = vm_get_maxcpus(hyp->vm);
CPU_ZERO(&cpus);
switch (func_id) {
case SBI_IPI_SEND_IPI:
- while ((bit = ffs(hart_mask))) {
- hart_id = (bit - 1);
- hart_mask &= ~(1u << hart_id);
- if (hart_mask_base != -1)
- hart_id += hart_mask_base;
- if (!CPU_ISSET(hart_id, &active_cpus))
+ if (hart_mask_base == (uint64_t)-1) {
+ CPU_COPY(&active_cpus, &cpus);
+ } else {
+ if (hart_mask == 0)
+ return (SBI_SUCCESS);
+ if (hart_mask_base >= maxcpus)
return (SBI_ERR_INVALID_PARAM);
- CPU_SET(hart_id, &cpus);
+
+ while (hart_mask != 0) {
+ i = ffsl(hart_mask) - 1;
+ hart_mask &= ~(1UL << i);
+
+ if (hart_mask_base + i >= maxcpus)
+ return (SBI_ERR_INVALID_PARAM);
+ if (!CPU_ISSET(hart_mask_base + i,
+ &active_cpus))
+ return (SBI_ERR_INVALID_PARAM);
+ CPU_SET(hart_mask_base + i, &cpus);
+ }
}
break;
default:
@@ -171,7 +185,7 @@
}
if (CPU_EMPTY(&cpus))
- return (SBI_ERR_INVALID_PARAM);
+ return (SBI_SUCCESS);
riscv_send_ipi(hyp, &cpus);
@@ -214,6 +228,7 @@
}
hypctx->guest_regs.hyp_a[0] = error;
+ hypctx->guest_regs.hyp_a[1] = 0;
/* Request is handled in kernel mode. */
return (true);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Nov 3, 8:33 PM (5 h, 23 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41383148
Default Alt Text
D61126.1793738020.diff (3 KB)
Attached To
Mode
D61126: bhyve/riscv: correctly handle empty masks and broadcast in SBI IPI/RFNC
Attached
Detach File
Event Timeline