|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH v2 13/26] xen/riscv: introduce per-vCPU IMSIC state
Each vCPU interacting with the IMSIC requires state to track the
associated guest interrupt file and its backing context.
Introduce a per-vCPU structure to hold IMSIC-related state, including
the guest interrupt file identifier and the CPU providing the backing
VS-file. Access to the guest file identifier is protected by a lock.
Initialize this structure during vCPU setup and store it in arch_vcpu.
The initial state marks the VS-file as software-backed until it becomes
associated with a physical CPU.
Add helpers to retrieve and update the guest interrupt file identifier:
- imsic_set_guest_file_id() is going to be used during vCPU creation to
initialize IMSIC interrupt controller things for this vCPU.
- vcpu_guest_file_id() is going to be used during update of APLIC's
target register with the pair of information <guest_file_id, cpu_id>
(to have MSI delivery mode work properly) when guest is trying to
access vAPLIC's target register.
It will be used in the follow up patches.
Signed-off-by: Oleksii Kurochko <oleksii.kurochko@xxxxxxxxx>
---
Changes in v2:
- Rename imsic_state to vimsic_state.
- Use 'unsigned int' for vsfile_pcpu.
- Drop initialzation of ->guest_file_id as it will be by default zero.
- Add the comment about ->guest_file_id field.
- Drop __init for vcpu_imsic_init() as it could be used during post-boot
vCPU creation.
- Update the commit message.
- Drop locks around ->guest_file_id() in vcpu_guest_file_id() and
imsic_set_guest_file_id().
---
xen/arch/riscv/imsic.c | 35 +++++++++++++++++++++++++++++
xen/arch/riscv/include/asm/domain.h | 2 ++
xen/arch/riscv/include/asm/imsic.h | 23 +++++++++++++++++++
3 files changed, 60 insertions(+)
diff --git a/xen/arch/riscv/imsic.c b/xen/arch/riscv/imsic.c
index a4460576f620..8b46419ca23b 100644
--- a/xen/arch/riscv/imsic.c
+++ b/xen/arch/riscv/imsic.c
@@ -16,6 +16,7 @@
#include <xen/errno.h>
#include <xen/init.h>
#include <xen/macros.h>
+#include <xen/sched.h>
#include <xen/smp.h>
#include <xen/spinlock.h>
#include <xen/xvmalloc.h>
@@ -56,6 +57,16 @@ do { \
csr_clear(CSR_SIREG, v); \
} while (0)
+unsigned int vcpu_guest_file_id(const struct vcpu *v)
+{
+ return ACCESS_ONCE(v->arch.vimsic_state->guest_file_id);
+}
+
+void imsic_set_guest_file_id(const struct vcpu *v, unsigned int guest_file_id)
+{
+ ACCESS_ONCE(v->arch.vimsic_state->guest_file_id) = guest_file_id;
+}
+
void __init imsic_ids_local_delivery(bool enable)
{
if ( enable )
@@ -312,6 +323,30 @@ static int imsic_parse_node(const struct dt_device_node
*node,
return 0;
}
+int vcpu_imsic_init(struct vcpu *v)
+{
+ struct vimsic_state *imsic_state;
+
+ /* Allocate IMSIC context */
+ imsic_state = xvzalloc(struct vimsic_state);
+ if ( !imsic_state )
+ return -ENOMEM;
+
+ v->arch.vimsic_state = imsic_state;
+
+ /* Setup IMSIC context */
+ rwlock_init(&imsic_state->vsfile_lock);
+
+ imsic_state->vsfile_pcpu = NR_CPUS;
+
+ return 0;
+}
+
+void vcpu_imsic_deinit(const struct vcpu *v)
+{
+ xvfree(v->arch.vimsic_state);
+}
+
/*
* Initialize the imsic_cfg structure based on the IMSIC DT node.
*
diff --git a/xen/arch/riscv/include/asm/domain.h
b/xen/arch/riscv/include/asm/domain.h
index 136d9e816a44..42c1db91bd86 100644
--- a/xen/arch/riscv/include/asm/domain.h
+++ b/xen/arch/riscv/include/asm/domain.h
@@ -54,6 +54,8 @@ struct arch_vcpu {
struct vtimer vtimer;
+ struct vimsic_state *vimsic_state;
+
register_t hcounteren;
register_t hedeleg;
register_t hideleg;
diff --git a/xen/arch/riscv/include/asm/imsic.h
b/xen/arch/riscv/include/asm/imsic.h
index c6c59215df20..2b84824cd377 100644
--- a/xen/arch/riscv/include/asm/imsic.h
+++ b/xen/arch/riscv/include/asm/imsic.h
@@ -11,6 +11,7 @@
#ifndef ASM_RISCV_IMSIC_H
#define ASM_RISCV_IMSIC_H
+#include <xen/rwlock.h>
#include <xen/spinlock.h>
#include <xen/stdbool.h>
#include <xen/types.h>
@@ -61,7 +62,24 @@ struct imsic_config {
spinlock_t lock;
};
+struct vimsic_state {
+ /* IMSIC VS-file */
+ rwlock_t vsfile_lock;
+ /*
+ * (guest_file_id == 0) -> s/w IMSIC SW-file
+ * (guest_file_id > 0) -> h/w IMSIC VS-file
+ */
+ unsigned int guest_file_id;
+ /*
+ * (vsfile_pcpu >= 0) => h/w IMSIC VS-file
+ * (vsfile_pcpu == NR_CPUS) => s/w IMSIC SW-file
+ */
+ unsigned int vsfile_pcpu;
+};
+
struct dt_device_node;
+struct vcpu;
+
int imsic_init(const struct dt_device_node *node);
const struct imsic_config *imsic_get_config(void);
@@ -71,4 +89,9 @@ void imsic_irq_disable(unsigned int hwirq);
void imsic_ids_local_delivery(bool enable);
+int vcpu_imsic_init(struct vcpu *v);
+void vcpu_imsic_deinit(const struct vcpu *v);
+unsigned int vcpu_guest_file_id(const struct vcpu *v);
+void imsic_set_guest_file_id(const struct vcpu *v, unsigned int guest_file_id);
+
#endif /* ASM_RISCV_IMSIC_H */
--
2.54.0
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |