arm/arm64: vgic-new: Implement API for vGICv3 live migration
Subsystems (3)
v3 cover arm/arm64: vgic-new: Implement API for vGICv3 live migration
From: Vijaya Kumar K <[email protected]>
This patchset adds API for saving and restoring
of VGICv3 registers to support live migration with new vgic feature. This API definition is as per version of VGICv3 specification
http://lists.infradead.org/pipermail/linux-arm-kernel/2016-July/445611.html
To test live migration with QEMU, use below patch series
https://lists.gnu.org/archive/html/qemu-devel/2016-08/msg01444.html
The patch 3 & 4 are picked from the Pavel's previous implementation.
http://www.spinics.net/lists/kvm/msg122040.html
v2 => v3:
- Implemented separate API for ISPENDR and ICPENDR to
read soft_pending instead of pending for level triggerred interrupts
- Implemented ioctl KVM_DEV_ARM_VGIC_GRP_LEVEL_INFO to access line level
- Rebased on top of Christoffer's patch set
http://www.spinics.net/lists/kvm/msg136840.html
NOTE: GICD_STATUSR and GICR_STATUSR are implemented as RAZ/WI.
v1 => v2:
- The init sequence change patch is no more required.
Fixed in patch 2 by using static vgic_io_dev regions structure instead of using dynamic allocation pointer.
- Updated commit message of patch 4.
- Dropped usage of union to manage 32-bit and 64-bit access in patch 1. Used local variable for 32-bit access.
- Updated macro __ARM64_SYS_REG and ARM64_SYS_REG in arch/arm64/include/uapi/asm/kvm.h as per qemu requirements.
Vijaya Kumar K (5):
arm/arm64: vgic-new: Implement support for userspace access arm/arm64: vgic-new: Add distributor and redistributor access arm/arm64: vgic-new: Introduce find_reg_by_id() arm/arm64: vgic-new: Implement VGICv3 CPU interface access arm/arm64: vgic-new: Implement KVM_DEV_ARM_VGIC_GRP_LEVEL_INFO ioctl
arch/arm64/include/uapi/asm/kvm.h | 24 +++- arch/arm64/kvm/Makefile | 1 + arch/arm64/kvm/sys_regs.c | 22 ++-- arch/arm64/kvm/sys_regs.h | 4 + include/linux/irqchip/arm-gic-v3.h | 4 + virt/kvm/arm/vgic/vgic-kvm-device.c | 198 ++++++++++++++++++++++++++++++++- virt/kvm/arm/vgic/vgic-mmio-v2.c | 9 +- virt/kvm/arm/vgic/vgic-mmio-v3.c | 178 ++++++++++++++++++++++++++++-- virt/kvm/arm/vgic/vgic-mmio.c | 123 +++++++++++++++++++-- virt/kvm/arm/vgic/vgic-mmio.h | 31 ++++++ virt/kvm/arm/vgic/vgic-sys-reg-v3.c | 211 ++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic.h | 17 +++ 12 files changed, 789 insertions(+), 33 deletions(-) create mode 100644 virt/kvm/arm/vgic/vgic-sys-reg-v3.c
Signature · 1 line
1.9.1
RFC PATCH v3 1/5 arm/arm64: vgic-new: Implement support for userspace access
From: Vijaya Kumar K <[email protected]>
Read and write of some registers like ISPENDR and ICPENDR from userspace requires special handling when compared to guest access for these registers.
Refer to Documentation/virtual/kvm/devices/arm-vgic-its.txt for handling of ISPENDR, ICPENDR registers handling.
Add infrastructure to support guest and userspace read and write for the required registers
--- virt/kvm/arm/vgic/vgic-mmio-v2.c | 5 ++- virt/kvm/arm/vgic/vgic-mmio-v3.c | 40 ++++++++++++++---- virt/kvm/arm/vgic/vgic-mmio.c | 87 ++++++++++++++++++++++++++++++++++++---- virt/kvm/arm/vgic/vgic-mmio.h | 25 ++++++++++++ 4 files changed, 139 insertions(+), 18 deletions(-)
virt/kvm/arm/vgic/vgic-mmio-v2.c +3 -2
@@ -421,9 +421,10 @@ static int vgic_uaccess(struct kvm_vcpu *vcpu, struct vgic_io_device *dev,if (is_write) {vgic_data_host_to_mmio_bus (buf, len, *val); - ret = kvm_io_gic_ops.write (vcpu, &dev->dev, offset, len, buf); + ret =vgic_mmio_uaccess_write (vcpu, &dev->dev, offset, + len, buf); }else { - ret = kvm_io_gic_ops.read (vcpu, &dev->dev, offset, len, buf); + ret =vgic_mmio_uaccess_read (vcpu, &dev->dev, offset, len, buf);if (!ret) *val =vgic_data_mmio_bus_to_host (buf, len); }
virt/kvm/arm/vgic/vgic-mmio-v3.c +32 -8
@@ -367,6 +367,26 @@ static void vgic_mmio_write_pendbase(struct kvm_vcpu *vcpu, .write = wr, \ } +#define REGISTER_DESC_WITH_BITS_PER_IRQ_SHARED_UACCESS (off, rd, wr, ur, \ + uw, bpi, acc) \ + { \ + .reg_offset = off, \ + .bits_per_irq = bpi, \ + .len = (bpi * VGIC_NR_PRIVATE_IRQS) / 8, \ + .access_flags = acc, \ + .read = vgic_mmio_read_raz, \ + .write = vgic_mmio_write_wi, \ + }, { \ + .reg_offset = off + (bpi * VGIC_NR_PRIVATE_IRQS) / 8, \ + .bits_per_irq = bpi, \ + .len = (bpi * (1024 - VGIC_NR_PRIVATE_IRQS)) / 8, \ + .access_flags = acc, \ + .read = rd, \ + .write = wr, \ + .uaccess_read = ur, \ + .uaccess_write = uw, \ + } +static const struct vgic_register_region vgic_v3_dist_registers[] = { REGISTER_DESC_WITH_LENGTH(GICD_CTLR, vgic_mmio_read_v3_misc, vgic_mmio_write_v3_misc, 16,
@@ -380,11 +400,13 @@ static const struct vgic_register_region vgic_v3_dist_registers[] = {REGISTER_DESC_WITH_BITS_PER_IRQ_SHARED (GICD_ICENABLER , vgic_mmio_read_enable, vgic_mmio_write_cenable,1 , VGIC_ACCESS_32bit), -REGISTER_DESC_WITH_BITS_PER_IRQ_SHARED (GICD_ISPENDR , - vgic_mmio_read_pending, vgic_mmio_write_spending,1 , +REGISTER_DESC_WITH_BITS_PER_IRQ_SHARED_UACCESS (GICD_ISPENDR , + vgic_mmio_read_pending, vgic_mmio_write_spending, + vgic_mmio_read_soft_pending, vgic_mmio_write_spending,1 , VGIC_ACCESS_32bit), -REGISTER_DESC_WITH_BITS_PER_IRQ_SHARED (GICD_ICPENDR , - vgic_mmio_read_pending, vgic_mmio_write_cpending,1 , +REGISTER_DESC_WITH_BITS_PER_IRQ_SHARED_UACCESS (GICD_ICPENDR , + vgic_mmio_read_pending, vgic_mmio_write_cpending, + vgic_mmio_read_soft_pending, vgic_mmio_write_cpending,1 , VGIC_ACCESS_32bit), REGISTER_DESC_WITH_BITS_PER_IRQ_SHARED(GICD_ISACTIVER, vgic_mmio_read_active, vgic_mmio_write_sactive, 1,
@@ -443,11 +465,13 @@ static const struct vgic_register_region vgic_v3_sgibase_registers[] = {REGISTER_DESC_WITH_LENGTH (GICR_ICENABLER0 , vgic_mmio_read_enable, vgic_mmio_write_cenable,4 , VGIC_ACCESS_32bit), -REGISTER_DESC_WITH_LENGTH (GICR_ISPENDR0 , - vgic_mmio_read_pending, vgic_mmio_write_spending,4 , +REGISTER_DESC_WITH_LENGTH_UACCESS (GICR_ISPENDR0 , + vgic_mmio_read_pending, vgic_mmio_write_spending, + vgic_mmio_read_soft_pending, vgic_mmio_write_spending,4 , VGIC_ACCESS_32bit), -REGISTER_DESC_WITH_LENGTH (GICR_ICPENDR0 , - vgic_mmio_read_pending, vgic_mmio_write_cpending,4 , +REGISTER_DESC_WITH_LENGTH_UACCESS (GICR_ICPENDR0 , + vgic_mmio_read_pending, vgic_mmio_write_cpending, + vgic_mmio_read_soft_pending, vgic_mmio_write_cpending,4 , VGIC_ACCESS_32bit), REGISTER_DESC_WITH_LENGTH(GICR_ISACTIVER0, vgic_mmio_read_active, vgic_mmio_write_sactive, 4,
virt/kvm/arm/vgic/vgic-mmio.c +79 -8
114 lines not on this page · raw message
virt/kvm/arm/vgic/vgic-mmio.h +25 -0
@@ -34,6 +34,10 @@ struct vgic_register_region { gpa_t addr, unsigned int len, unsigned long val); }; +unsigned long (*uaccess_read)(struct kvm_vcpu *vcpu,gpa_t addr, +unsigned int len); +void (*uaccess_write)(struct kvm_vcpu *vcpu,gpa_t addr, +unsigned int len,unsigned long val); };extern struct kvm_io_device_ops kvm_io_gic_ops;
@@ -86,6 +90,18 @@ extern struct kvm_io_device_ops kvm_io_gic_ops; .write = wr, \ } +#define REGISTER_DESC_WITH_LENGTH_UACCESS (off, rd, wr, urd, uwr, length, acc) \ + { \ + .reg_offset = off, \ + .bits_per_irq = 0, \ + .len = length, \ + .access_flags = acc, \ + .read = rd, \ + .write = wr, \ + .uaccess_read = urd, \ + .uaccess_write = uwr, \ + } + int kvm_vgic_register_mmio_region(struct kvm *kvm, struct kvm_vcpu *vcpu, struct vgic_register_region *reg_desc, struct vgic_io_device *region,
@@ -122,6 +138,9 @@ void vgic_mmio_write_cenable(struct kvm_vcpu *vcpu, gpa_t addr, unsigned int len, unsigned long val); +unsigned long vgic_mmio_read_soft_pending (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len); +unsigned long vgic_mmio_read_pending (struct kvm_vcpu *vcpu,gpa_t addr,unsigned int len);
@@ -158,6 +177,12 @@ void vgic_mmio_write_config(struct kvm_vcpu *vcpu, gpa_t addr, unsigned int len, unsigned long val); +int vgic_mmio_uaccess_read (struct kvm_vcpu *vcpu,struct kvm_io_device *dev, +gpa_t addr,int len,void *val); + +int vgic_mmio_uaccess_write (struct kvm_vcpu *vcpu,struct kvm_io_device *dev, +gpa_t addr,int len,const void *val); +unsigned int vgic_v2_init_dist_iodev (struct vgic_io_device *dev);unsigned int vgic_v3_init_dist_iodev (struct vgic_io_device *dev);
Signature · 1 line
1.9.1
Re: [RFC PATCH v3 1/5] arm/arm64: vgic-new: Implement support for userspace access
Quoted 7 lines · On Wed, Aug 24, 2016 at 04:50:05PM +0530, [email protected] wrote:
From: Vijaya Kumar K <[email protected]>
Read and write of some registers like ISPENDR and ICPENDR from userspace requires special handling when compared to guest access for these registers.
Refer to
Documentation/virtual/kvm/devices/arm-vgic-its.txt
you mean arm-vgic-v3.txt right?
Quoted 48 lines
for handling of ISPENDR, ICPENDR registers handling.
Add infrastructure to support guest and userspace read and write for the required registers
Signed-off-by Vijaya Kumar K <[email protected]>--- virt/kvm/arm/vgic/vgic-mmio-v2.c | 5 ++- virt/kvm/arm/vgic/vgic-mmio-v3.c | 40 ++++++++++++++---- virt/kvm/arm/vgic/vgic-mmio.c | 87 ++++++++++++++++++++++++++++++++++++---- virt/kvm/arm/vgic/vgic-mmio.h | 25 ++++++++++++ 4 files changed, 139 insertions(+), 18 deletions(-)virt/kvm/arm/vgic/vgic-mmio-v2.c +3
-2@@ -421,9 +421,10 @@ static int vgic_uaccess(struct kvm_vcpu *vcpu, struct vgic_io_device *dev,if (is_write) {vgic_data_host_to_mmio_bus (buf, len, *val); - ret = kvm_io_gic_ops.write (vcpu, &dev->dev, offset, len, buf); + ret =vgic_mmio_uaccess_write (vcpu, &dev->dev, offset, + len, buf); }else { - ret = kvm_io_gic_ops.read (vcpu, &dev->dev, offset, len, buf); + ret =vgic_mmio_uaccess_read (vcpu, &dev->dev, offset, len, buf);if (!ret) *val =vgic_data_mmio_bus_to_host (buf, len); }virt/kvm/arm/vgic/vgic-mmio-v3.c +10
-0@@ -367,6 +367,26 @@ static void vgic_mmio_write_pendbase(struct kvm_vcpu *vcpu, .write = wr, \ } +#define REGISTER_DESC_WITH_BITS_PER_IRQ_SHARED_UACCESS (off, rd, wr, ur, \ + uw, bpi, acc) \ + { \ + .reg_offset = off, \ + .bits_per_irq = bpi, \ + .len = (bpi * VGIC_NR_PRIVATE_IRQS) / 8, \ + .access_flags = acc, \ + .read = vgic_mmio_read_raz, \ + .write = vgic_mmio_write_wi, \ + }, { \
virt/kvm/arm/vgic/vgic-mmio-v3.c static void vgic_mmio_write_pendbase(struct kvm_vcpu *vcpu, · line 389
Quoted 10 lines
virt/kvm/arm/vgic/vgic-mmio-v3.c +10
-0+ .reg_offset = off + (bpi * VGIC_NR_PRIVATE_IRQS) / 8, \ + .bits_per_irq = bpi, \ + .len = (bpi * (1024 - VGIC_NR_PRIVATE_IRQS)) / 8, \ + .access_flags = acc, \ + .read = rd, \ + .write = wr, \ + .uaccess_read = ur, \ + .uaccess_write = uw, \ + } +
that macro name is getting really long and complicated.
Could we consider simply modifying the existing macro to take two additional parameters, and change the list of users of the macro to pass NULL where these functions are not used?
virt/kvm/arm/vgic/vgic-mmio-v3.c static const struct vgic_register_region vgic_v3_dist_registers[] = { · line 405
Quoted 12 lines
virt/kvm/arm/vgic/vgic-mmio-v3.c +3
-2static const struct vgic_register_region vgic_v3_dist_registers[] = { REGISTER_DESC_WITH_LENGTH(GICD_CTLR, vgic_mmio_read_v3_misc, vgic_mmio_write_v3_misc, 16,@@ -380,11 +400,13 @@ static const struct vgic_register_region vgic_v3_dist_registers[] = {REGISTER_DESC_WITH_BITS_PER_IRQ_SHARED (GICD_ICENABLER , vgic_mmio_read_enable, vgic_mmio_write_cenable,1 , VGIC_ACCESS_32bit), - REGISTER_DESC_WITH_BITS_PER_IRQ_SHARED(GICD_ISPENDR, - vgic_mmio_read_pending, vgic_mmio_write_spending, 1, + REGISTER_DESC_WITH_BITS_PER_IRQ_SHARED_UACCESS(GICD_ISPENDR, + vgic_mmio_read_pending, vgic_mmio_write_spending, + vgic_mmio_read_soft_pending, vgic_mmio_write_spending, 1,
You need a uaccess for the write part as well to provide raw access to the latch state, without imposing any ordering requirements for the restore part of userspace. For example, you cannot rely on userspace having restored the configuration state of the IRQs before the pending state, unless we modify the API to require this.
I think you need a function that looks very similar tot he write_spending function, but which always sets the soft_pending state, regardless of the configuration of the IRQ.
We need to tweak the vgic_mmio_write_config function to queue interrupts that become pending when changed to LEVEL to go along with this. I can send a patch with this separately.
Quoted 32 lines
virt/kvm/arm/vgic/vgic-mmio-v3.c +9
-6VGIC_ACCESS_32bit), -REGISTER_DESC_WITH_BITS_PER_IRQ_SHARED (GICD_ICPENDR , - vgic_mmio_read_pending, vgic_mmio_write_cpending,1 , +REGISTER_DESC_WITH_BITS_PER_IRQ_SHARED_UACCESS (GICD_ICPENDR , + vgic_mmio_read_pending, vgic_mmio_write_cpending, + vgic_mmio_read_soft_pending, vgic_mmio_write_cpending,1 , VGIC_ACCESS_32bit), REGISTER_DESC_WITH_BITS_PER_IRQ_SHARED(GICD_ISACTIVER, vgic_mmio_read_active, vgic_mmio_write_sactive, 1,@@ -443,11 +465,13 @@ static const struct vgic_register_region vgic_v3_sgibase_registers[] = {REGISTER_DESC_WITH_LENGTH (GICR_ICENABLER0 , vgic_mmio_read_enable, vgic_mmio_write_cenable,4 , VGIC_ACCESS_32bit), -REGISTER_DESC_WITH_LENGTH (GICR_ISPENDR0 , - vgic_mmio_read_pending, vgic_mmio_write_spending,4 , +REGISTER_DESC_WITH_LENGTH_UACCESS (GICR_ISPENDR0 , + vgic_mmio_read_pending, vgic_mmio_write_spending, + vgic_mmio_read_soft_pending, vgic_mmio_write_spending,4 , VGIC_ACCESS_32bit), -REGISTER_DESC_WITH_LENGTH (GICR_ICPENDR0 , - vgic_mmio_read_pending, vgic_mmio_write_cpending,4 , +REGISTER_DESC_WITH_LENGTH_UACCESS (GICR_ICPENDR0 , + vgic_mmio_read_pending, vgic_mmio_write_cpending, + vgic_mmio_read_soft_pending, vgic_mmio_write_cpending,4 , VGIC_ACCESS_32bit), REGISTER_DESC_WITH_LENGTH(GICR_ISACTIVER0, vgic_mmio_read_active, vgic_mmio_write_sactive, 4,virt/kvm/arm/vgic/vgic-mmio.c +0
-0
virt/kvm/arm/vgic/vgic-mmio.c void vgic_mmio_write_cenable(struct kvm_vcpu *vcpu, · line 104
Quoted 5 lines
virt/kvm/arm/vgic/vgic-mmio.c +2
-0@@ -100,6 +100,26 @@ void vgic_mmio_write_cenable(struct kvm_vcpu *vcpu, } } +unsigned long vgic_mmio_read_soft_pending (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len)
since this is only reading the soft_pending state for level triggered interrupts, I don't appreciate this name.
How about vgic_uaccess_read_pending ?
virt/kvm/arm/vgic/vgic-mmio.c void vgic_mmio_write_cenable(struct kvm_vcpu *vcpu, · line 113
Quoted 9 lines
virt/kvm/arm/vgic/vgic-mmio.c +9
-0+{ +u32 intid =VGIC_ADDR_TO_INTID (addr,1 ); +u32 value =0 ; +int i; + +/* Loop over all IRQs affected by this read */ +for (i =0 ; i < len *8 ; i++) { +struct vgic_irq *irq =vgic_get_irq (vcpu->kvm, vcpu, intid + i); +
Add a comment with a reference to the logic defined in the arm-vgic-v3.txt for this implementation here.
virt/kvm/arm/vgic/vgic-mmio.c void vgic_mmio_write_cenable(struct kvm_vcpu *vcpu, · line 116
Quoted 3 lines
virt/kvm/arm/vgic/vgic-mmio.c +3
-0+if (irq->config ==VGIC_CONFIG_LEVEL && irq->soft_pending) + value |= (1U << i); +if (irq->config !=VGIC_CONFIG_LEVEL && irq->pending)
please change the latter to irq->config == VGIC_CONFIG_EDGE.
Quoted 18 lines
virt/kvm/arm/vgic/vgic-mmio.c +11
-0+ value |= (1U << i); + } + +return value; +} +unsigned long vgic_mmio_read_pending (struct kvm_vcpu *vcpu,gpa_t addr,unsigned int len) {@@ -468,6 +488,62 @@ static bool check_region(const struct vgic_register_region *region,return false; } +static const struct vgic_register_region * +vgic_get_mmio_region (struct vgic_io_device *iodev,gpa_t addr,int len) +{ +const struct vgic_register_region *region; +
virt/kvm/arm/vgic/vgic-mmio.c static bool check_region(const struct vgic_register_region *region, · line 505
Quoted 10 lines
virt/kvm/arm/vgic/vgic-mmio.c +10
-0+ region =vgic_find_mmio_region (iodev->regions, iodev->nr_regions, + addr - iodev->base_addr); +if (!region || !check_region (region, addr, len)) +return NULL ; + +return region; +} + +int vgic_mmio_uaccess_read (struct kvm_vcpu *vcpu,struct kvm_io_device *dev, +gpa_t addr,int len,void *val)
I would probably rename these two functions to be vgic_uaccess_read/write, that is get rid of the 'mmio' part.
Quoted 132 lines
virt/kvm/arm/vgic/vgic-mmio.c +44
-8+{ +struct vgic_io_device *iodev =kvm_to_vgic_iodev (dev); +const struct vgic_register_region *region; +struct kvm_vcpu *r_vcpu; +unsigned long data; + + region =vgic_get_mmio_region (iodev, addr, len); +if (!region) { +memset (val,0 , len); +return 0 ; + } + + r_vcpu = iodev->redist_vcpu ? iodev->redist_vcpu : vcpu; +if (region->uaccess_read !=NULL ) + data = region->uaccess_read (r_vcpu, addr, len); +else + data = region->read (r_vcpu, addr, len); +vgic_data_host_to_mmio_bus (val, len, data); +return 0 ; +} + +int vgic_mmio_uaccess_write (struct kvm_vcpu *vcpu,struct kvm_io_device *dev, +gpa_t addr,int len,const void *val) +{ +struct vgic_io_device *iodev =kvm_to_vgic_iodev (dev); +const struct vgic_register_region *region; +struct kvm_vcpu *r_vcpu; +unsigned long data =vgic_data_mmio_bus_to_host (val, len); + + region =vgic_get_mmio_region (iodev, addr, len); +if (!region) +return 0 ; + + r_vcpu = iodev->redist_vcpu ? iodev->redist_vcpu : vcpu; +if (region->uaccess_write !=NULL ) + region->uaccess_write (r_vcpu, addr, len, data); +else + region->write (r_vcpu, addr, len, data); +return 0 ; +} +static int dispatch_mmio_read (struct kvm_vcpu *vcpu,struct kvm_io_device *dev,gpa_t addr,int len,void *val) {@@ -475,9 +551,8 @@ static int dispatch_mmio_read(struct kvm_vcpu *vcpu, struct kvm_io_device *dev,const struct vgic_register_region *region;unsigned long data =0 ; - region =vgic_find_mmio_region (iodev->regions, iodev->nr_regions, - addr - iodev->base_addr); -if (!region || !check_region (region, addr, len)) { + region =vgic_get_mmio_region (iodev, addr, len); +if (!region) {memset (val,0 , len);return 0 ; }@@ -508,14 +583,10 @@ static int dispatch_mmio_write(struct kvm_vcpu *vcpu, struct kvm_io_device *dev,const struct vgic_register_region *region;unsigned long data =vgic_data_mmio_bus_to_host (val, len); - region =vgic_find_mmio_region (iodev->regions, iodev->nr_regions, - addr - iodev->base_addr); + region =vgic_get_mmio_region (iodev, addr, len);if (!region)return 0 ; -if (!check_region (region, addr, len)) -return 0 ; -switch (iodev->iodev_type) {case IODEV_CPUIF : region->write (vcpu, addr, len, data);virt/kvm/arm/vgic/vgic-mmio.h +25
-0@@ -34,6 +34,10 @@ struct vgic_register_region { gpa_t addr, unsigned int len, unsigned long val); }; +unsigned long (*uaccess_read)(struct kvm_vcpu *vcpu,gpa_t addr, +unsigned int len); +void (*uaccess_write)(struct kvm_vcpu *vcpu,gpa_t addr, +unsigned int len,unsigned long val); };extern struct kvm_io_device_ops kvm_io_gic_ops;@@ -86,6 +90,18 @@ extern struct kvm_io_device_ops kvm_io_gic_ops; .write = wr, \ } +#define REGISTER_DESC_WITH_LENGTH_UACCESS (off, rd, wr, urd, uwr, length, acc) \ + { \ + .reg_offset = off, \ + .bits_per_irq = 0, \ + .len = length, \ + .access_flags = acc, \ + .read = rd, \ + .write = wr, \ + .uaccess_read = urd, \ + .uaccess_write = uwr, \ + } + int kvm_vgic_register_mmio_region(struct kvm *kvm, struct kvm_vcpu *vcpu, struct vgic_register_region *reg_desc, struct vgic_io_device *region,@@ -122,6 +138,9 @@ void vgic_mmio_write_cenable(struct kvm_vcpu *vcpu, gpa_t addr, unsigned int len, unsigned long val); +unsigned long vgic_mmio_read_soft_pending (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len); +unsigned long vgic_mmio_read_pending (struct kvm_vcpu *vcpu,gpa_t addr,unsigned int len);@@ -158,6 +177,12 @@ void vgic_mmio_write_config(struct kvm_vcpu *vcpu, gpa_t addr, unsigned int len, unsigned long val); +int vgic_mmio_uaccess_read (struct kvm_vcpu *vcpu,struct kvm_io_device *dev, +gpa_t addr,int len,void *val); + +int vgic_mmio_uaccess_write (struct kvm_vcpu *vcpu,struct kvm_io_device *dev, +gpa_t addr,int len,const void *val); +unsigned int vgic_v2_init_dist_iodev (struct vgic_io_device *dev);unsigned int vgic_v3_init_dist_iodev (struct vgic_io_device *dev);Signature · 1 line
1.9.1
Re: [RFC PATCH v3 1/5] arm/arm64: vgic-new: Implement support for userspace access
[replying to myself...]
Quoted 2 lines · Christoffer Dall
Quoted 1 line · On Wed, Aug 24, 2016 at 04:50:05PM +0530, [email protected] wrote:
From: Vijaya Kumar K <[email protected]>
[...]
Quoted 20 lines
virt/kvm/arm/vgic/vgic-mmio-v3.c static const struct vgic_register_region vgic_v3_dist_registers[] = { · line 405
Quoted 13 lines
static const struct
vgic_register_regionvgic_v3_dist_registers[] = {virt/kvm/arm/vgic/vgic-mmio-v3.c +3
-2REGISTER_DESC_WITH_LENGTH(GICD_CTLR, vgic_mmio_read_v3_misc, vgic_mmio_write_v3_misc, 16,@@ -380,11 +400,13 @@ static const struct vgic_register_region vgic_v3_dist_registers[] = {REGISTER_DESC_WITH_BITS_PER_IRQ_SHARED (GICD_ICENABLER , vgic_mmio_read_enable, vgic_mmio_write_cenable,1 , VGIC_ACCESS_32bit), - REGISTER_DESC_WITH_BITS_PER_IRQ_SHARED(GICD_ISPENDR, - vgic_mmio_read_pending, vgic_mmio_write_spending, 1, + REGISTER_DESC_WITH_BITS_PER_IRQ_SHARED_UACCESS(GICD_ISPENDR, + vgic_mmio_read_pending, vgic_mmio_write_spending, + vgic_mmio_read_soft_pending, vgic_mmio_write_spending, 1,You need a uaccess for the write part as well to provide raw access to the latch state, without imposing any ordering requirements for the restore part of userspace. For example, you cannot rely on userspace having restored the configuration state of the IRQs before the pending state, unless we modify the API to require this.
Quoted 9 lines
I think you need a function that looks very similar tot he
write_spendingfunction, but which always sets thesoft_pendingstate, regardless of the configuration of the IRQ.We need to tweak the
vgic_mmio_write_configfunction to queue interrupts that become pending when changed to LEVEL to go along with this. I can send a patch with this separately.
Thinking about this some more, this last part of my comment, about vgic_mmio_write_config, is not necessary.
If we implement the uaccess_write_pending such that we call vgic_queue_irq_unlock when setting the pending state, then we obviously don't need to do it again later, just because we're changing the configuration.
Another thing I forgot to say was that the API also specifies that writes to the CPENDR registers are ignored and writes to the SPENDR register directly set the latch state, so I you need to make sure the uaccess writes to CPENDR are ignored and that the writes to SPENDR can both set/clear the values.
I think the uaccess_write_pending function needs to look something like this (completely untested):
void vgic_uaccess_write_pending(struct kvm_vcpu *vcpu,
gpa_t addr, unsigned int len, unsigned long val)
{
u32 intid = VGIC_ADDR_TO_INTID(addr, 1);
int i;
for (i = 0; i < len * 8; i++) {
struct vgic_irq *irq = vgic_get_irq(vcpu->kvm, vcpu, intid + i);
spin_lock(&irq->irq_lock);
if (test_bit(i, &val)) {
irq->pending = true;
irq->soft_pending = true;
vgic_queue_irq_unlock(vcpu->kvm, irq);
} else {
irq->soft_pending = false;
if (irq->config == VGIC_CONFIG_EDGE ||
(irq->config == VGIC_CONFIG_LEVEL && !irq->line_level))
irq->pending = false;
spin_unlock(&irq->irq_lock);
}
vgic_put_irq(vcpu->kvm, irq);
}
}Thanks,
-Christoffer
Re: [RFC PATCH v3 1/5] arm/arm64: vgic-new: Implement support for userspace access
In reply to [email protected]Quoted 179 lines · On Wed, Aug 24, 2016 at 04:50:05PM +0530, [email protected] wrote:
From: Vijaya Kumar K <[email protected]>
Read and write of some registers like ISPENDR and ICPENDR from userspace requires special handling when compared to guest access for these registers.
Refer to
Documentation/virtual/kvm/devices/arm-vgic-its.txtfor handling of ISPENDR, ICPENDR registers handling.Add infrastructure to support guest and userspace read and write for the required registers
Signed-off-by Vijaya Kumar K <[email protected]>--- virt/kvm/arm/vgic/vgic-mmio-v2.c | 5 ++- virt/kvm/arm/vgic/vgic-mmio-v3.c | 40 ++++++++++++++---- virt/kvm/arm/vgic/vgic-mmio.c | 87 ++++++++++++++++++++++++++++++++++++---- virt/kvm/arm/vgic/vgic-mmio.h | 25 ++++++++++++ 4 files changed, 139 insertions(+), 18 deletions(-)virt/kvm/arm/vgic/vgic-mmio-v2.c +3
-2@@ -421,9 +421,10 @@ static int vgic_uaccess(struct kvm_vcpu *vcpu, struct vgic_io_device *dev,if (is_write) {vgic_data_host_to_mmio_bus (buf, len, *val); - ret = kvm_io_gic_ops.write (vcpu, &dev->dev, offset, len, buf); + ret =vgic_mmio_uaccess_write (vcpu, &dev->dev, offset, + len, buf); }else { - ret = kvm_io_gic_ops.read (vcpu, &dev->dev, offset, len, buf); + ret =vgic_mmio_uaccess_read (vcpu, &dev->dev, offset, len, buf);if (!ret) *val =vgic_data_mmio_bus_to_host (buf, len); }virt/kvm/arm/vgic/vgic-mmio-v3.c +32
-8@@ -367,6 +367,26 @@ static void vgic_mmio_write_pendbase(struct kvm_vcpu *vcpu, .write = wr, \ } +#define REGISTER_DESC_WITH_BITS_PER_IRQ_SHARED_UACCESS (off, rd, wr, ur, \ + uw, bpi, acc) \ + { \ + .reg_offset = off, \ + .bits_per_irq = bpi, \ + .len = (bpi * VGIC_NR_PRIVATE_IRQS) / 8, \ + .access_flags = acc, \ + .read = vgic_mmio_read_raz, \ + .write = vgic_mmio_write_wi, \ + }, { \ + .reg_offset = off + (bpi * VGIC_NR_PRIVATE_IRQS) / 8, \ + .bits_per_irq = bpi, \ + .len = (bpi * (1024 - VGIC_NR_PRIVATE_IRQS)) / 8, \ + .access_flags = acc, \ + .read = rd, \ + .write = wr, \ + .uaccess_read = ur, \ + .uaccess_write = uw, \ + } +static const struct vgic_register_region vgic_v3_dist_registers[] = { REGISTER_DESC_WITH_LENGTH(GICD_CTLR, vgic_mmio_read_v3_misc, vgic_mmio_write_v3_misc, 16,@@ -380,11 +400,13 @@ static const struct vgic_register_region vgic_v3_dist_registers[] = {REGISTER_DESC_WITH_BITS_PER_IRQ_SHARED (GICD_ICENABLER , vgic_mmio_read_enable, vgic_mmio_write_cenable,1 , VGIC_ACCESS_32bit), -REGISTER_DESC_WITH_BITS_PER_IRQ_SHARED (GICD_ISPENDR , - vgic_mmio_read_pending, vgic_mmio_write_spending,1 , +REGISTER_DESC_WITH_BITS_PER_IRQ_SHARED_UACCESS (GICD_ISPENDR , + vgic_mmio_read_pending, vgic_mmio_write_spending, + vgic_mmio_read_soft_pending, vgic_mmio_write_spending,1 , VGIC_ACCESS_32bit), -REGISTER_DESC_WITH_BITS_PER_IRQ_SHARED (GICD_ICPENDR , - vgic_mmio_read_pending, vgic_mmio_write_cpending,1 , +REGISTER_DESC_WITH_BITS_PER_IRQ_SHARED_UACCESS (GICD_ICPENDR , + vgic_mmio_read_pending, vgic_mmio_write_cpending, + vgic_mmio_read_soft_pending, vgic_mmio_write_cpending,1 , VGIC_ACCESS_32bit), REGISTER_DESC_WITH_BITS_PER_IRQ_SHARED(GICD_ISACTIVER, vgic_mmio_read_active, vgic_mmio_write_sactive, 1,@@ -443,11 +465,13 @@ static const struct vgic_register_region vgic_v3_sgibase_registers[] = {REGISTER_DESC_WITH_LENGTH (GICR_ICENABLER0 , vgic_mmio_read_enable, vgic_mmio_write_cenable,4 , VGIC_ACCESS_32bit), -REGISTER_DESC_WITH_LENGTH (GICR_ISPENDR0 , - vgic_mmio_read_pending, vgic_mmio_write_spending,4 , +REGISTER_DESC_WITH_LENGTH_UACCESS (GICR_ISPENDR0 , + vgic_mmio_read_pending, vgic_mmio_write_spending, + vgic_mmio_read_soft_pending, vgic_mmio_write_spending,4 , VGIC_ACCESS_32bit), -REGISTER_DESC_WITH_LENGTH (GICR_ICPENDR0 , - vgic_mmio_read_pending, vgic_mmio_write_cpending,4 , +REGISTER_DESC_WITH_LENGTH_UACCESS (GICR_ICPENDR0 , + vgic_mmio_read_pending, vgic_mmio_write_cpending, + vgic_mmio_read_soft_pending, vgic_mmio_write_cpending,4 , VGIC_ACCESS_32bit), REGISTER_DESC_WITH_LENGTH(GICR_ISACTIVER0, vgic_mmio_read_active, vgic_mmio_write_sactive, 4,virt/kvm/arm/vgic/vgic-mmio.c +60
-0@@ -100,6 +100,26 @@ void vgic_mmio_write_cenable(struct kvm_vcpu *vcpu, } } +unsigned long vgic_mmio_read_soft_pending (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len) +{ +u32 intid =VGIC_ADDR_TO_INTID (addr,1 ); +u32 value =0 ; +int i; + +/* Loop over all IRQs affected by this read */ +for (i =0 ; i < len *8 ; i++) { +struct vgic_irq *irq =vgic_get_irq (vcpu->kvm, vcpu, intid + i); + +if (irq->config ==VGIC_CONFIG_LEVEL && irq->soft_pending) + value |= (1U << i); +if (irq->config !=VGIC_CONFIG_LEVEL && irq->pending) + value |= (1U << i); + } + +return value; +} +unsigned long vgic_mmio_read_pending (struct kvm_vcpu *vcpu,gpa_t addr,unsigned int len) {@@ -468,6 +488,62 @@ static bool check_region(const struct vgic_register_region *region,return false; } +static const struct vgic_register_region * +vgic_get_mmio_region (struct vgic_io_device *iodev,gpa_t addr,int len) +{ +const struct vgic_register_region *region; + + region =vgic_find_mmio_region (iodev->regions, iodev->nr_regions, + addr - iodev->base_addr); +if (!region || !check_region (region, addr, len)) +return NULL ; + +return region; +} + +int vgic_mmio_uaccess_read (struct kvm_vcpu *vcpu,struct kvm_io_device *dev, +gpa_t addr,int len,void *val) +{ +struct vgic_io_device *iodev =kvm_to_vgic_iodev (dev); +const struct vgic_register_region *region; +struct kvm_vcpu *r_vcpu; +unsigned long data; + + region =vgic_get_mmio_region (iodev, addr, len); +if (!region) { +memset (val,0 , len); +return 0 ; + } + + r_vcpu = iodev->redist_vcpu ? iodev->redist_vcpu : vcpu; +if (region->uaccess_read !=NULL ) + data = region->uaccess_read (r_vcpu, addr, len); +else + data = region->read (r_vcpu, addr, len); +vgic_data_host_to_mmio_bus (val, len, data); +return 0 ; +} + +int vgic_mmio_uaccess_write (struct kvm_vcpu *vcpu,struct kvm_io_device *dev, +gpa_t addr,int len,const void *val) +{ +struct vgic_io_device *iodev =kvm_to_vgic_iodev (dev);
virt/kvm/arm/vgic/vgic-mmio.c static bool check_region(const struct vgic_register_region *region, · line 540
Quoted 10 lines
virt/kvm/arm/vgic/vgic-mmio.c +10
-0+const struct vgic_register_region *region; +struct kvm_vcpu *r_vcpu; +unsigned long data =vgic_data_mmio_bus_to_host (val, len); + + region =vgic_get_mmio_region (iodev, addr, len); +if (!region) +return 0 ; + + r_vcpu = iodev->redist_vcpu ? iodev->redist_vcpu : vcpu; +if (region->uaccess_write !=NULL )
nit: we use the form if (!region->uaccess_write) most other places, please use this instead.
Thanks,
-Christoffer
RFC PATCH v3 2/5 arm/arm64: vgic-new: Add distributor and redistributor access
In reply to [email protected]From: Vijaya Kumar K <[email protected]>
VGICv3 Distributor and Redistributor registers are accessed using KVM_DEV_ARM_VGIC_GRP_DIST_REGS and KVM_DEV_ARM_VGIC_GRP_DIST_REGS with KVM_SET_DEVICE_ATTR and KVM_GET_DEVICE_ATTR ioctls. These registers are accessed as 32-bit and cpu mpidr value passed along with register offset is used to identify the cpu for redistributor registers access.
The version of VGIC v3 specification is define here
http://lists.infradead.org/pipermail/linux-arm-kernel/2016-July/445611.html
--- arch/arm64/include/uapi/asm/kvm.h | 3 + virt/kvm/arm/vgic/vgic-kvm-device.c | 127 +++++++++++++++++++++++++++++++++++- virt/kvm/arm/vgic/vgic-mmio-v3.c | 113 ++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic-mmio.c | 2 +- virt/kvm/arm/vgic/vgic.h | 8 +++ 5 files changed, 250 insertions(+), 3 deletions(-)
arch/arm64/include/uapi/asm/kvm.h +3 -0
@@ -201,10 +201,13 @@ struct kvm_arch_memory_slot {#define KVM_DEV_ARM_VGIC_GRP_CPU_REGS 2#define KVM_DEV_ARM_VGIC_CPUID_SHIFT 32#define KVM_DEV_ARM_VGIC_CPUID_MASK (0xffULL << KVM_DEV_ARM_VGIC_CPUID_SHIFT) +#define KVM_DEV_ARM_VGIC_V3_CPUID_MASK \ + (0xffffffffULL << KVM_DEV_ARM_VGIC_CPUID_SHIFT)#define KVM_DEV_ARM_VGIC_OFFSET_SHIFT 0#define KVM_DEV_ARM_VGIC_OFFSET_MASK (0xffffffffULL << KVM_DEV_ARM_VGIC_OFFSET_SHIFT)#define KVM_DEV_ARM_VGIC_GRP_NR_IRQS 3#define KVM_DEV_ARM_VGIC_GRP_CTRL 4 +#define KVM_DEV_ARM_VGIC_GRP_REDIST_REGS 5#define KVM_DEV_ARM_VGIC_CTRL_INIT 0/* Device Control API on vcpu fd */
virt/kvm/arm/vgic/vgic-kvm-device.c +125 -2
147 lines not on this page · raw message
virt/kvm/arm/vgic/vgic-mmio-v3.c +113 -0
146 lines not on this page · raw message
virt/kvm/arm/vgic/vgic-mmio.c +1 -1
@@ -406,7 +406,7 @@ static int match_region(const void *key, const void *elt) }/* Find the proper register handler entry given a certain address offset. */ -static const struct vgic_register_region * +const struct vgic_register_region *vgic_find_mmio_region (const struct vgic_register_region *region,int nr_regions,unsigned int offset) {
virt/kvm/arm/vgic/vgic.h +8 -0
@@ -72,6 +72,9 @@ static inline void vgic_get_irq_kref(struct vgic_irq *irq)kref_get (&irq->refcount); } +const struct vgic_register_region * +vgic_find_mmio_region (const struct vgic_register_region *region, +int nr_regions,unsigned int offset);#ifdef CONFIG_KVM_ARM_VGIC_V3 void vgic_v3_process_maintenance (struct kvm_vcpu *vcpu);void vgic_v3_fold_lr_state (struct kvm_vcpu *vcpu);
@@ -88,6 +91,11 @@ bool vgic_has_its(struct kvm *kvm);int kvm_vgic_register_its_device (void );void vgic_enable_lpis (struct kvm_vcpu *vcpu);int vgic_its_inject_msi (struct kvm *kvm,struct kvm_msi *msi); +int vgic_v3_has_attr_regs (struct kvm_device *dev,struct kvm_device_attr *attr); +int vgic_v3_dist_uaccess (struct kvm_vcpu *vcpu,bool is_write, +int offset,u32 *val); +int vgic_v3_redist_uaccess (struct kvm_vcpu *vcpu,bool is_write, +int offset,u32 *val);#else static inline void vgic_v3_process_maintenance (struct kvm_vcpu *vcpu) {
Signature · 1 line
1.9.1
Re: [RFC PATCH v3 2/5] arm/arm64: vgic-new: Add distributor and redistributor access
Quoted 26 lines · On Wed, Aug 24, 2016 at 04:50:06PM +0530, [email protected] wrote:
From: Vijaya Kumar K <[email protected]>
VGICv3 Distributor and Redistributor registers are accessed using
KVM_DEV_ARM_VGIC_GRP_DIST_REGSandKVM_DEV_ARM_VGIC_GRP_DIST_REGSwithKVM_SET_DEVICE_ATTRandKVM_GET_DEVICE_ATTRioctls. These registers are accessed as 32-bit and cpu mpidr value passed along with register offset is used to identify the cpu for redistributor registers access.The version of VGIC v3 specification is define here
http://lists.infradead.org/pipermail/linux-arm-kernel/2016-July/445611.htmlSigned-off-by Vijaya Kumar K <[email protected]>--- arch/arm64/include/uapi/asm/kvm.h | 3 + virt/kvm/arm/vgic/vgic-kvm-device.c | 127 +++++++++++++++++++++++++++++++++++- virt/kvm/arm/vgic/vgic-mmio-v3.c | 113 ++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic-mmio.c | 2 +- virt/kvm/arm/vgic/vgic.h | 8 +++ 5 files changed, 250 insertions(+), 3 deletions(-)arch/arm64/include/uapi/asm/kvm.h +0
-0
arch/arm64/include/uapi/asm/kvm.h struct kvm_arch_memory_slot { · line 205
Quoted 5 lines
arch/arm64/include/uapi/asm/kvm.h +2
-0@@ -201,10 +201,13 @@ struct kvm_arch_memory_slot {#define KVM_DEV_ARM_VGIC_GRP_CPU_REGS 2#define KVM_DEV_ARM_VGIC_CPUID_SHIFT 32#define KVM_DEV_ARM_VGIC_CPUID_MASK (0xffULL << KVM_DEV_ARM_VGIC_CPUID_SHIFT) +#define KVM_DEV_ARM_VGIC_V3_CPUID_MASK \ + (0xffffffffULL << KVM_DEV_ARM_VGIC_CPUID_SHIFT)
I think this should be KVM_DEV_ARM_VGIC_V3_MPIDR_MASK, and I would probably define a V3 of the shift as well, since we're really talking about two distinct APIs here.
Quoted 17 lines
arch/arm64/include/uapi/asm/kvm.h +1
-0#define KVM_DEV_ARM_VGIC_OFFSET_SHIFT 0#define KVM_DEV_ARM_VGIC_OFFSET_MASK (0xffffffffULL << KVM_DEV_ARM_VGIC_OFFSET_SHIFT)#define KVM_DEV_ARM_VGIC_GRP_NR_IRQS 3#define KVM_DEV_ARM_VGIC_GRP_CTRL 4 +#define KVM_DEV_ARM_VGIC_GRP_REDIST_REGS 5#define KVM_DEV_ARM_VGIC_CTRL_INIT 0/* Device Control API on vcpu fd */ virt/kvm/arm/vgic/vgic-kvm-device.c +1
-0@@ -433,16 +433,136 @@ struct kvm_device_ops kvm_arm_vgic_v2_ops = {#ifdef CONFIG_KVM_ARM_VGIC_V3 +static int parse_vgic_v3_attr(struct kvm_device *dev,
virt/kvm/arm/vgic/vgic-kvm-device.c struct kvm_device_ops kvm_arm_vgic_v2_ops = { · line 446
Quoted 10 lines
virt/kvm/arm/vgic/vgic-kvm-device.c +10
-0+struct kvm_device_attr *attr, + struct vgic_reg_attr *reg_attr) +{ + int cpuid; + + cpuid = (attr->attr &KVM_DEV_ARM_VGIC_V3_CPUID_MASK ) >> +KVM_DEV_ARM_VGIC_CPUID_SHIFT ; + +if (cpuid >=atomic_read (&dev->kvm->online_vcpus)) +return -EINVAL ;
huh? it's an MPIDR, not a cpu id.
just resolve it with kvm_mpidr_to_vcpu and check its return value.
virt/kvm/arm/vgic/vgic-kvm-device.c struct kvm_device_ops kvm_arm_vgic_v2_ops = { · line 448
Quoted 2 lines
virt/kvm/arm/vgic/vgic-kvm-device.c +2
-0+ + reg_attr->vcpu =kvm_mpidr_to_vcpu (dev->kvm, cpuid);
please check the return value of this function in any case...
Quoted 25 lines
virt/kvm/arm/vgic/vgic-kvm-device.c +25
-0+ reg_attr->addr = attr->attr &KVM_DEV_ARM_VGIC_OFFSET_MASK ; + +return 0 ; +} + +/** +* vgic_attr_regs_access_v3 - allows user space to access VGIC v3 state +* +* @dev: kvm device handle +* @attr: kvm device attribute +* @reg: address the value is read or written +* @is_write: true if userspace is writing a register +*/ +static int vgic_attr_regs_access_v3 (struct kvm_device *dev, +struct kvm_device_attr *attr, +u64 *reg,bool is_write) +{ +struct vgic_reg_attr reg_attr; +gpa_t addr; +struct kvm_vcpu *vcpu; +int ret; +u32 tmp32; + + ret =parse_vgic_v3_attr (dev, attr, ®_attr); +if (ret)
virt/kvm/arm/vgic/vgic-kvm-device.c struct kvm_device_ops kvm_arm_vgic_v2_ops = { · line 483
Quoted 10 lines
virt/kvm/arm/vgic/vgic-kvm-device.c +10
-0+return ret; + + vcpu = reg_attr.vcpu; + addr = reg_attr.addr; + +mutex_lock (&dev->kvm->lock); + + ret =vgic_init (dev->kvm); +if (ret) + goto out;
no, no, please no more auto-init at userspace access time. This code should instead check vgic_initialized() and return an error to userspace if not initialized.
virt/kvm/arm/vgic/vgic-kvm-device.c struct kvm_device_ops kvm_arm_vgic_v2_ops = { · line 492
Quoted 9 lines
virt/kvm/arm/vgic/vgic-kvm-device.c +9
-0+ +if (!lock_all_vcpus (dev->kvm)) { + ret = -EBUSY ; + goto out; + } + +switch (attr->group) { +case KVM_DEV_ARM_VGIC_GRP_DIST_REGS : + tmp32 = *reg;
why is this assignment not predicated on if (is_write) ?
also, all this type conversion nonsense is probably unnecessary, see my comment below.
Quoted 33 lines
virt/kvm/arm/vgic/vgic-kvm-device.c +29
-1+ ret =vgic_v3_dist_uaccess (vcpu, is_write, addr, &tmp32); +if (!is_write) + *reg = tmp32; +break ; +case KVM_DEV_ARM_VGIC_GRP_REDIST_REGS : + tmp32 = *reg; + ret =vgic_v3_redist_uaccess (vcpu, is_write, addr, &tmp32); +if (!is_write) + *reg = tmp32; +break ; +default : + ret = -EINVAL ; +break ; + } + +unlock_all_vcpus (dev->kvm); +out: +mutex_unlock (&dev->kvm->lock); +return ret; +} +static int vgic_v3_set_attr (struct kvm_device *dev,struct kvm_device_attr *attr) { -return vgic_set_common_attr (dev, attr); +int ret; + + ret =vgic_set_common_attr (dev, attr); +if (ret != -ENXIO ) +return ret; + +switch (attr->group) { +case KVM_DEV_ARM_VGIC_GRP_DIST_REGS :
virt/kvm/arm/vgic/vgic-kvm-device.c struct kvm_device_ops kvm_arm_vgic_v2_ops = { · line 534
Quoted 10 lines
virt/kvm/arm/vgic/vgic-kvm-device.c +10
-0+case KVM_DEV_ARM_VGIC_GRP_REDIST_REGS : { +u32 __user *uaddr = (u32 __user *)(long )attr->addr; +u32 tmp32; +u64 reg; + +if (get_user (tmp32, uaddr)) +return -EFAULT ; + + reg = tmp32; +return vgic_attr_regs_access_v3 (dev, attr, ®, true);
oh, but wait, you already had a 32-bit value, which you convert into a 64-bit value, just to convert it back again, to do some extra data copies?
I'm really confused as to why this has to be so complicated.
Why not simply use u32 all the way?
Quoted 17 lines
virt/kvm/arm/vgic/vgic-kvm-device.c +11
-1+ } + } +return -ENXIO ; }static int vgic_v3_get_attr (struct kvm_device *dev,struct kvm_device_attr *attr) { -return vgic_get_common_attr (dev, attr); +int ret; + + ret =vgic_get_common_attr (dev, attr); +if (ret != -ENXIO ) +return ret; + +switch (attr->group) { +case KVM_DEV_ARM_VGIC_GRP_DIST_REGS :
virt/kvm/arm/vgic/vgic-kvm-device.c struct kvm_device_ops kvm_arm_vgic_v2_ops = { · line 560
Quoted 10 lines
virt/kvm/arm/vgic/vgic-kvm-device.c +10
-0+case KVM_DEV_ARM_VGIC_GRP_REDIST_REGS : { +u32 __user *uaddr = (u32 __user *)(long )attr->addr; +u64 reg; +u32 tmp32; + + ret =vgic_attr_regs_access_v3 (dev, attr, ®, false); +if (ret) +return ret; + tmp32 = reg; + ret =put_user (tmp32, uaddr);
same, type stuff.
Quoted 66 lines
virt/kvm/arm/vgic/vgic-kvm-device.c +8
-0+return ret; + } + } + +return -ENXIO ; } static int vgic_v3_has_attr(struct kvm_device *dev,@@ -456,6 +576,9 @@ static int vgic_v3_has_attr(struct kvm_device *dev,return 0 ; }break ; +case KVM_DEV_ARM_VGIC_GRP_DIST_REGS : +case KVM_DEV_ARM_VGIC_GRP_REDIST_REGS : +return vgic_v3_has_attr_regs (dev, attr);case KVM_DEV_ARM_VGIC_GRP_NR_IRQS :return 0 ;case KVM_DEV_ARM_VGIC_GRP_CTRL :virt/kvm/arm/vgic/vgic-mmio-v3.c +13
-0@@ -18,6 +18,8 @@#include <kvm/arm_vgic.h> #include <asm/kvm_emulate.h> +#include <asm/kvm_arm.h> +#include <asm/kvm_mmu.h> #include "vgic.h" #include "vgic-mmio.h" @@ -391,6 +393,9 @@ static const struct vgic_register_region vgic_v3_dist_registers[] = {REGISTER_DESC_WITH_LENGTH (GICD_CTLR , vgic_mmio_read_v3_misc, vgic_mmio_write_v3_misc,16 , VGIC_ACCESS_32bit), +REGISTER_DESC_WITH_LENGTH (GICD_STATUSR , + vgic_mmio_read_rao, vgic_mmio_write_wi,4 , + VGIC_ACCESS_32bit),REGISTER_DESC_WITH_BITS_PER_IRQ_SHARED (GICD_IGROUPR , vgic_mmio_read_rao, vgic_mmio_write_wi,1 , VGIC_ACCESS_32bit),@@ -438,12 +443,18 @@ static const struct vgic_register_region vgic_v3_rdbase_registers[] = {REGISTER_DESC_WITH_LENGTH (GICR_CTLR , vgic_mmio_read_v3r_ctlr, vgic_mmio_write_v3r_ctlr,4 , VGIC_ACCESS_32bit), +REGISTER_DESC_WITH_LENGTH (GICR_STATUSR , + vgic_mmio_read_raz, vgic_mmio_write_wi,4 , + VGIC_ACCESS_32bit),REGISTER_DESC_WITH_LENGTH (GICR_IIDR , vgic_mmio_read_v3r_iidr, vgic_mmio_write_wi,4 , VGIC_ACCESS_32bit),REGISTER_DESC_WITH_LENGTH (GICR_TYPER , vgic_mmio_read_v3r_typer, vgic_mmio_write_wi,8 , VGIC_ACCESS_64bit | VGIC_ACCESS_32bit), +REGISTER_DESC_WITH_LENGTH (GICR_WAKER , + vgic_mmio_read_raz, vgic_mmio_write_wi,8 , + VGIC_ACCESS_32bit),REGISTER_DESC_WITH_LENGTH (GICR_PROPBASER , vgic_mmio_read_propbase, vgic_mmio_write_propbase,8 , VGIC_ACCESS_64bit | VGIC_ACCESS_32bit),@@ -564,6 +575,46 @@ int vgic_register_redist_iodevs(struct kvm *kvm, gpa_t redist_base_address)return ret; } +int vgic_v3_has_attr_regs (struct kvm_device *dev,struct kvm_device_attr *attr) +{
virt/kvm/arm/vgic/vgic-mmio-v3.c int vgic_register_redist_iodevs(struct kvm *kvm, gpa_t redist_base_address) · line 589
Quoted 10 lines
virt/kvm/arm/vgic/vgic-mmio-v3.c +10
-0+struct kvm_vcpu *vcpu; +int nr_irqs = dev->kvm->arch.vgic.nr_spis +VGIC_NR_PRIVATE_IRQS ; +const struct vgic_register_region *regions; +gpa_t addr; +int nr_regions, i, len, cpuid; + + addr = attr->attr &KVM_DEV_ARM_VGIC_OFFSET_MASK ; + cpuid = (attr->attr &KVM_DEV_ARM_VGIC_V3_CPUID_MASK ) >> +KVM_DEV_ARM_VGIC_CPUID_SHIFT ; + vcpu =kvm_mpidr_to_vcpu (dev->kvm, cpuid);
why do you need the vcpu variable?
(also, you don't check the return value)
Quoted 4 lines
virt/kvm/arm/vgic/vgic-mmio-v3.c +4
-0+ +switch (attr->group) { +case KVM_DEV_ARM_VGIC_GRP_DIST_REGS : + regions = vgic_v3_dist_registers;
virt/kvm/arm/vgic/vgic-mmio-v3.c int vgic_register_redist_iodevs(struct kvm *kvm, gpa_t redist_base_address) · line 603
Quoted 10 lines
virt/kvm/arm/vgic/vgic-mmio-v3.c +10
-0+ nr_regions =ARRAY_SIZE (vgic_v3_dist_registers); +break ; +case KVM_DEV_ARM_VGIC_GRP_REDIST_REGS :{ + regions = vgic_v3_rdbase_registers; + nr_regions =ARRAY_SIZE (vgic_v3_rdbase_registers); +break ; + } +default : +return -ENXIO ; + }
why don't you need an address alignment check here?
virt/kvm/arm/vgic/vgic-mmio-v3.c int vgic_register_redist_iodevs(struct kvm *kvm, gpa_t redist_base_address) · line 614
Quoted 11 lines
virt/kvm/arm/vgic/vgic-mmio-v3.c +11
-0+ +for (i =0 ; i < nr_regions; i++) { +if (regions[i].bits_per_irq) + len = (regions[i].bits_per_irq * nr_irqs) /8 ; +else + len = regions[i].len; + +if (regions[i].reg_offset <= addr && + regions[i].reg_offset + len > addr) +return 0 ; + }
this is directly lifted from v2, definitely this loop or the whole function can be shared between v2/v3 somehow.
Quoted 26 lines
virt/kvm/arm/vgic/vgic-mmio-v3.c +19
-0+ +return -ENXIO ; +}/* * Compare a given affinity (level 1-3 and a level 0 mask, from the SGI * generation register ICC_SGI1R_EL1) with a given VCPU. @@ -670,3 +721,65 @@ void vgic_v3_dispatch_sgi(struct kvm_vcpu *vcpu, u64 reg)vgic_put_irq (vcpu->kvm, irq); } } + +/* +* When userland tries to access the VGIC register handlers, we need to +* create a usable struct vgic_io_device to be passed to the handlers and we +* have to set up a buffer similar to what would have happened if a guest MMIO +* access occurred, including doing endian conversions on BE systems. +*/ +static int vgic_v3_uaccess (struct kvm_vcpu *vcpu,struct vgic_io_device *dev, +bool is_write,int offset,u32 *val) +{ +unsigned int len =4 ; +u8 buf[4 ]; +int ret; + +if (is_write) { +vgic_data_host_to_mmio_bus (buf, len, *val);
virt/kvm/arm/vgic/vgic-mmio-v3.c void vgic_v3_dispatch_sgi(struct kvm_vcpu *vcpu, u64 reg) · line 749
Quoted 10 lines
virt/kvm/arm/vgic/vgic-mmio-v3.c +10
-0+ ret =vgic_mmio_uaccess_write (vcpu, &dev->dev, offset, + len, buf); + }else { + ret =vgic_mmio_uaccess_read (vcpu, &dev->dev, offset, len, buf); +if (!ret) + *val =vgic_data_mmio_bus_to_host (buf, len); + } + +return ret; +}
this as well seems to be completely identical to the v2 version, or am I missing something?
Quoted 18 lines
virt/kvm/arm/vgic/vgic-mmio-v3.c +18
-0+ +int vgic_v3_dist_uaccess (struct kvm_vcpu *vcpu,bool is_write, +int offset,u32 *val) +{ +struct vgic_io_device dev = { + .regions = vgic_v3_dist_registers, + .nr_regions =ARRAY_SIZE (vgic_v3_dist_registers), + }; + +return vgic_v3_uaccess (vcpu, &dev, is_write, offset, val); +} + +int vgic_v3_redist_uaccess (struct kvm_vcpu *vcpu,bool is_write, +int offset,u32 *val) +{ +struct vgic_io_device *dev; +const struct vgic_register_region *region; +
virt/kvm/arm/vgic/vgic-mmio-v3.c void vgic_v3_dispatch_sgi(struct kvm_vcpu *vcpu, u64 reg) · line 777
Quoted 10 lines
virt/kvm/arm/vgic/vgic-mmio-v3.c +10
-0+struct vgic_io_device rd_dev = { + .regions = vgic_v3_rdbase_registers, + .nr_regions =ARRAY_SIZE (vgic_v3_rdbase_registers), + }; + +struct vgic_io_device sgi_dev = { + .regions = vgic_v3_sgibase_registers, + .nr_regions =ARRAY_SIZE (vgic_v3_sgibase_registers), + }; +
The whole bit following here deserves a comment.
I'm guessing the idea is to check if the offset falls into the sgi_dev or rd_dev region?
Why not simply do:
/* SGI_base is the next 64K frame after RD_base */ if (offset >= SZ_64K) return vgic_v3_uaccess(vcpu, &sgi_dev, is_write, offset - SZ_64K, val); else return vgic_v3_uaccess(vcpu, &rd_dev, is_write, offset, val);
virt/kvm/arm/vgic/vgic-mmio-v3.c void vgic_v3_dispatch_sgi(struct kvm_vcpu *vcpu, u64 reg) · line 780
Quoted 3 lines
virt/kvm/arm/vgic/vgic-mmio-v3.c +3
-0+ dev = &sgi_dev; + region =vgic_find_mmio_region (dev->regions, dev->nr_regions, + offset - dev->base_addr);
In any case, this doesn't look right: dev->base_addr is not set?
virt/kvm/arm/vgic/vgic-mmio-v3.c void vgic_v3_dispatch_sgi(struct kvm_vcpu *vcpu, u64 reg) · line 781
Quoted 1 line
virt/kvm/arm/vgic/vgic-mmio-v3.c +1
-0+if (region ==NULL )
If you must, then do: if (!region)
Quoted 46 lines
virt/kvm/arm/vgic/vgic-mmio-v3.c +4
-0+ dev = &rd_dev; + +return vgic_v3_uaccess (vcpu, dev, is_write, offset, val); +}virt/kvm/arm/vgic/vgic-mmio.c +1
-1@@ -406,7 +406,7 @@ static int match_region(const void *key, const void *elt) }/* Find the proper register handler entry given a certain address offset. */ -static const struct vgic_register_region * +const struct vgic_register_region *vgic_find_mmio_region (const struct vgic_register_region *region,int nr_regions,unsigned int offset) {virt/kvm/arm/vgic/vgic.h +8
-0@@ -72,6 +72,9 @@ static inline void vgic_get_irq_kref(struct vgic_irq *irq)kref_get (&irq->refcount); } +const struct vgic_register_region * +vgic_find_mmio_region (const struct vgic_register_region *region, +int nr_regions,unsigned int offset);#ifdef CONFIG_KVM_ARM_VGIC_V3 void vgic_v3_process_maintenance (struct kvm_vcpu *vcpu);void vgic_v3_fold_lr_state (struct kvm_vcpu *vcpu);@@ -88,6 +91,11 @@ bool vgic_has_its(struct kvm *kvm);int kvm_vgic_register_its_device (void );void vgic_enable_lpis (struct kvm_vcpu *vcpu);int vgic_its_inject_msi (struct kvm *kvm,struct kvm_msi *msi); +int vgic_v3_has_attr_regs (struct kvm_device *dev,struct kvm_device_attr *attr); +int vgic_v3_dist_uaccess (struct kvm_vcpu *vcpu,bool is_write, +int offset,u32 *val); +int vgic_v3_redist_uaccess (struct kvm_vcpu *vcpu,bool is_write, +int offset,u32 *val);#else static inline void vgic_v3_process_maintenance (struct kvm_vcpu *vcpu) {Signature · 1 line
1.9.1
Re: [RFC PATCH v3 2/5] arm/arm64: vgic-new: Add distributor and redistributor access
Quoted 190 lines · Christoffer Dall
Quoted 11 lines · On Wed, Aug 24, 2016 at 04:50:06PM +0530, [email protected] wrote:
From: Vijaya Kumar K <[email protected]>
VGICv3 Distributor and Redistributor registers are accessed using
KVM_DEV_ARM_VGIC_GRP_DIST_REGSandKVM_DEV_ARM_VGIC_GRP_DIST_REGSwithKVM_SET_DEVICE_ATTRandKVM_GET_DEVICE_ATTRioctls. These registers are accessed as 32-bit and cpu mpidr value passed along with register offset is used to identify the cpu for redistributor registers access.The version of VGIC v3 specification is define here
http://lists.infradead.org/pipermail/linux-arm-kernel/2016-July/445611.html
Quoted 5 lines
Signed-off-by Vijaya Kumar K <[email protected]>--- arch/arm64/include/uapi/asm/kvm.h | 3 + virt/kvm/arm/vgic/vgic-kvm-device.c | 127+++++++++++++++++++++++++++++++++++-
Quoted 1 line
virt/kvm/arm/vgic/vgic-mmio-v3.c | 113++++++++++++++++++++++++++++++++
Review
Quoted 5 lines
virt/kvm/arm/vgic/vgic-mmio.c | 2 +- virt/kvm/arm/vgic/vgic.h | 8 +++ 5 files changed, 250 insertions(+), 3 deletions(-)(quoted diff) +0
-0
b/arch/arm64/include/uapi/asm/kvm.harch/arm64/include/uapi/asm/kvm.h struct kvm_arch_memory_slot { · line 203
Quoted 7 lines
index 3051f86..94ea676 100644
arch/arm64/include/uapi/asm/kvm.h +0
-0@@ -201,10 +201,13 @@ struct kvm_arch_memory_slot {#define KVM_DEV_ARM_VGIC_GRP_CPU_REGS 2#define KVM_DEV_ARM_VGIC_CPUID_SHIFT 32#define KVM_DEV_ARM_VGIC_CPUID_MASK (0xffULL <<
KVM_DEV_ARM_VGIC_CPUID_SHIFT)arch/arm64/include/uapi/asm/kvm.h struct kvm_arch_memory_slot { · line 205
Quoted 2 lines
arch/arm64/include/uapi/asm/kvm.h +2
-0+#define KVM_DEV_ARM_VGIC_V3_CPUID_MASK \ + (0xffffffffULL <<
KVM_DEV_ARM_VGIC_CPUID_SHIFT)I think this should be
KVM_DEV_ARM_VGIC_V3_MPIDR_MASK, and I would probably define a V3 of the shift as well, since we're really talking about two distinct APIs here.arch/arm64/include/uapi/asm/kvm.h struct kvm_arch_memory_slot { · line 207
Quoted 2 lines
arch/arm64/include/uapi/asm/kvm.h +0
-0#define KVM_DEV_ARM_VGIC_OFFSET_SHIFT 0#define KVM_DEV_ARM_VGIC_OFFSET_MASK (0xffffffffULL <<
KVM_DEV_ARM_VGIC_OFFSET_SHIFT)Review
Quoted 7 lines
arch/arm64/include/uapi/asm/kvm.h +1
-0#define KVM_DEV_ARM_VGIC_GRP_NR_IRQS 3#define KVM_DEV_ARM_VGIC_GRP_CTRL 4 +#define KVM_DEV_ARM_VGIC_GRP_REDIST_REGS 5#define KVM_DEV_ARM_VGIC_CTRL_INIT 0/* Device Control API on vcpu fd */ (quoted diff) +0
-0
b/virt/kvm/arm/vgic/vgic-kvm-device.cQuoted 8 lines
index 163b057..06f0158 100644
virt/kvm/arm/vgic/vgic-kvm-device.c +1
-0@@ -433,16 +433,136 @@ struct kvm_device_ops kvm_arm_vgic_v2_ops = {#ifdef CONFIG_KVM_ARM_VGIC_V3 +static int parse_vgic_v3_attr(struct kvm_device *dev,virt/kvm/arm/vgic/vgic-kvm-device.c struct kvm_device_ops kvm_arm_vgic_v2_ops = { · line 446
Quoted 10 lines
virt/kvm/arm/vgic/vgic-kvm-device.c +10
-0+struct kvm_device_attr *attr, + struct vgic_reg_attr *reg_attr) +{ + int cpuid; + + cpuid = (attr->attr &KVM_DEV_ARM_VGIC_V3_CPUID_MASK ) >> +KVM_DEV_ARM_VGIC_CPUID_SHIFT ; + +if (cpuid >=atomic_read (&dev->kvm->online_vcpus)) +return -EINVAL ;huh? it's an MPIDR, not a cpu id.
just resolve it with
kvm_mpidr_to_vcpuand check its return value.virt/kvm/arm/vgic/vgic-kvm-device.c struct kvm_device_ops kvm_arm_vgic_v2_ops = { · line 448
Quoted 2 lines
virt/kvm/arm/vgic/vgic-kvm-device.c +2
-0+ + reg_attr->vcpu =kvm_mpidr_to_vcpu (dev->kvm, cpuid);please check the return value of this function in any case...
Quoted 25 lines
virt/kvm/arm/vgic/vgic-kvm-device.c +25
-0+ reg_attr->addr = attr->attr &KVM_DEV_ARM_VGIC_OFFSET_MASK ; + +return 0 ; +} + +/** +* vgic_attr_regs_access_v3 - allows user space to access VGIC v3 state +* +* @dev: kvm device handle +* @attr: kvm device attribute +* @reg: address the value is read or written +* @is_write: true if userspace is writing a register +*/ +static int vgic_attr_regs_access_v3 (struct kvm_device *dev, +struct kvm_device_attr *attr, +u64 *reg,bool is_write) +{ +struct vgic_reg_attr reg_attr; +gpa_t addr; +struct kvm_vcpu *vcpu; +int ret; +u32 tmp32; + + ret =parse_vgic_v3_attr (dev, attr, ®_attr); +if (ret)virt/kvm/arm/vgic/vgic-kvm-device.c struct kvm_device_ops kvm_arm_vgic_v2_ops = { · line 483
Quoted 10 lines
virt/kvm/arm/vgic/vgic-kvm-device.c +10
-0+return ret; + + vcpu = reg_attr.vcpu; + addr = reg_attr.addr; + +mutex_lock (&dev->kvm->lock); + + ret =vgic_init (dev->kvm); +if (ret) + goto out;no, no, please no more auto-init at userspace access time. This code should instead check
vgic_initialized()and return an error to userspace if not initialized.Ok. I wil fix it. It is coming from v2 code.
virt/kvm/arm/vgic/vgic-kvm-device.c struct kvm_device_ops kvm_arm_vgic_v2_ops = { · line 492
Quoted 9 lines
virt/kvm/arm/vgic/vgic-kvm-device.c +9
-0+ +if (!lock_all_vcpus (dev->kvm)) { + ret = -EBUSY ; + goto out; + } + +switch (attr->group) { +case KVM_DEV_ARM_VGIC_GRP_DIST_REGS : + tmp32 = *reg;why is this assignment not predicated on if (
is_write) ?also, all this type conversion nonsense is probably unnecessary, see my comment below.
Quoted 33 lines
virt/kvm/arm/vgic/vgic-kvm-device.c +29
-1+ ret =vgic_v3_dist_uaccess (vcpu, is_write, addr, &tmp32); +if (!is_write) + *reg = tmp32; +break ; +case KVM_DEV_ARM_VGIC_GRP_REDIST_REGS : + tmp32 = *reg; + ret =vgic_v3_redist_uaccess (vcpu, is_write, addr, &tmp32); +if (!is_write) + *reg = tmp32; +break ; +default : + ret = -EINVAL ; +break ; + } + +unlock_all_vcpus (dev->kvm); +out: +mutex_unlock (&dev->kvm->lock); +return ret; +} +static int vgic_v3_set_attr (struct kvm_device *dev,struct kvm_device_attr *attr) { -return vgic_set_common_attr (dev, attr); +int ret; + + ret =vgic_set_common_attr (dev, attr); +if (ret != -ENXIO ) +return ret; + +switch (attr->group) { +case KVM_DEV_ARM_VGIC_GRP_DIST_REGS :virt/kvm/arm/vgic/vgic-kvm-device.c struct kvm_device_ops kvm_arm_vgic_v2_ops = { · line 534
Quoted 10 lines
virt/kvm/arm/vgic/vgic-kvm-device.c +10
-0+case KVM_DEV_ARM_VGIC_GRP_REDIST_REGS : { +u32 __user *uaddr = (u32 __user *)(long )attr->addr; +u32 tmp32; +u64 reg; + +if (get_user (tmp32, uaddr)) +return -EFAULT ; + + reg = tmp32; +return vgic_attr_regs_access_v3 (dev, attr, ®, true);oh, but wait, you already had a 32-bit value, which you convert into a 64-bit value, just to convert it back again, to do some extra data copies?
Quoted 4 lines
I'm really confused as to why this has to be so complicated.
Why not simply use u32 all the way?
vgic_attr_regs_access_v3() is used for handling both GICD/GICR and
SYSREGS. For this reason we convert u32 to 64 and vice versa.
To avoid these conversions, I can create separate vgic_attr_regs_access_v3() functions for GICD and SYSREGS.
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Re: [RFC PATCH v3 2/5] arm/arm64: vgic-new: Add distributor and redistributor access
Resending in plain text mode
Quoted 207 lines · Vijay Kilari
Quoted 192 lines · Christoffer Dall
Quoted 30 lines · On Wed, Aug 24, 2016 at 04:50:06PM +0530, [email protected] wrote:
From: Vijaya Kumar K <[email protected]>
VGICv3 Distributor and Redistributor registers are accessed using
KVM_DEV_ARM_VGIC_GRP_DIST_REGSandKVM_DEV_ARM_VGIC_GRP_DIST_REGSwithKVM_SET_DEVICE_ATTRandKVM_GET_DEVICE_ATTRioctls. These registers are accessed as 32-bit and cpu mpidr value passed along with register offset is used to identify the cpu for redistributor registers access.The version of VGIC v3 specification is define here
http://lists.infradead.org/pipermail/linux-arm-kernel/2016-July/445611.html
Signed-off-by Vijaya Kumar K <[email protected]>--- arch/arm64/include/uapi/asm/kvm.h | 3 + virt/kvm/arm/vgic/vgic-kvm-device.c | 127 +++++++++++++++++++++++++++++++++++- virt/kvm/arm/vgic/vgic-mmio-v3.c | 113 ++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic-mmio.c | 2 +- virt/kvm/arm/vgic/vgic.h | 8 +++ 5 files changed, 250 insertions(+), 3 deletions(-)arch/arm64/include/uapi/asm/kvm.h +0
-0arch/arm64/include/uapi/asm/kvm.h struct kvm_arch_memory_slot { · line 207
Quoted 7 lines
arch/arm64/include/uapi/asm/kvm.h +2
-0@@ -201,10 +201,13 @@ struct kvm_arch_memory_slot {#define KVM_DEV_ARM_VGIC_GRP_CPU_REGS 2#define KVM_DEV_ARM_VGIC_CPUID_SHIFT 32#define KVM_DEV_ARM_VGIC_CPUID_MASK (0xffULL << KVM_DEV_ARM_VGIC_CPUID_SHIFT) +#define KVM_DEV_ARM_VGIC_V3_CPUID_MASK \ + (0xffffffffULL << KVM_DEV_ARM_VGIC_CPUID_SHIFT)I think this should be
KVM_DEV_ARM_VGIC_V3_MPIDR_MASK, and I would probably define a V3 of the shift as well, since we're really talking about two distinct APIs here.Quoted 19 lines
arch/arm64/include/uapi/asm/kvm.h +1
-0#define KVM_DEV_ARM_VGIC_OFFSET_SHIFT 0#define KVM_DEV_ARM_VGIC_OFFSET_MASK (0xffffffffULL << KVM_DEV_ARM_VGIC_OFFSET_SHIFT)#define KVM_DEV_ARM_VGIC_GRP_NR_IRQS 3#define KVM_DEV_ARM_VGIC_GRP_CTRL 4 +#define KVM_DEV_ARM_VGIC_GRP_REDIST_REGS 5#define
KVM_DEV_ARM_VGIC_CTRL_INIT0/* Device Control API on vcpu fd */
virt/kvm/arm/vgic/vgic-kvm-device.c +1
-0@@ -433,16 +433,136 @@ struct kvm_device_ops kvm_arm_vgic_v2_ops = {#ifdef CONFIG_KVM_ARM_VGIC_V3 +static int parse_vgic_v3_attr(struct kvm_device *dev,virt/kvm/arm/vgic/vgic-kvm-device.c struct kvm_device_ops kvm_arm_vgic_v2_ops = { · line 446
Quoted 10 lines
virt/kvm/arm/vgic/vgic-kvm-device.c +10
-0+struct kvm_device_attr *attr, + struct vgic_reg_attr *reg_attr) +{ + int cpuid; + + cpuid = (attr->attr &KVM_DEV_ARM_VGIC_V3_CPUID_MASK ) >> +KVM_DEV_ARM_VGIC_CPUID_SHIFT ; + +if (cpuid >=atomic_read (&dev->kvm->online_vcpus)) +return -EINVAL ;huh? it's an MPIDR, not a cpu id.
just resolve it with
kvm_mpidr_to_vcpuand check its return value.virt/kvm/arm/vgic/vgic-kvm-device.c struct kvm_device_ops kvm_arm_vgic_v2_ops = { · line 448
Quoted 2 lines
virt/kvm/arm/vgic/vgic-kvm-device.c +2
-0+ + reg_attr->vcpu =kvm_mpidr_to_vcpu (dev->kvm, cpuid);please check the return value of this function in any case...
Quoted 25 lines
virt/kvm/arm/vgic/vgic-kvm-device.c +25
-0+ reg_attr->addr = attr->attr &KVM_DEV_ARM_VGIC_OFFSET_MASK ; + +return 0 ; +} + +/** +* vgic_attr_regs_access_v3 - allows user space to access VGIC v3 state +* +* @dev: kvm device handle +* @attr: kvm device attribute +* @reg: address the value is read or written +* @is_write: true if userspace is writing a register +*/ +static int vgic_attr_regs_access_v3 (struct kvm_device *dev, +struct kvm_device_attr *attr, +u64 *reg,bool is_write) +{ +struct vgic_reg_attr reg_attr; +gpa_t addr; +struct kvm_vcpu *vcpu; +int ret; +u32 tmp32; + + ret =parse_vgic_v3_attr (dev, attr, ®_attr); +if (ret)virt/kvm/arm/vgic/vgic-kvm-device.c struct kvm_device_ops kvm_arm_vgic_v2_ops = { · line 483
Quoted 10 lines
virt/kvm/arm/vgic/vgic-kvm-device.c +10
-0+return ret; + + vcpu = reg_attr.vcpu; + addr = reg_attr.addr; + +mutex_lock (&dev->kvm->lock); + + ret =vgic_init (dev->kvm); +if (ret) + goto out;no, no, please no more auto-init at userspace access time. This code should instead check
vgic_initialized()and return an error to userspace if not initialized.Ok. I wil fix it. It is coming from v2 code.
virt/kvm/arm/vgic/vgic-kvm-device.c struct kvm_device_ops kvm_arm_vgic_v2_ops = { · line 492
Quoted 9 lines
virt/kvm/arm/vgic/vgic-kvm-device.c +9
-0+ +if (!lock_all_vcpus (dev->kvm)) { + ret = -EBUSY ; + goto out; + } + +switch (attr->group) { +case KVM_DEV_ARM_VGIC_GRP_DIST_REGS : + tmp32 = *reg;why is this assignment not predicated on if (
is_write) ?also, all this type conversion nonsense is probably unnecessary, see my comment below.
Quoted 34 lines
virt/kvm/arm/vgic/vgic-kvm-device.c +29
-1+ ret =vgic_v3_dist_uaccess (vcpu, is_write, addr, &tmp32); +if (!is_write) + *reg = tmp32; +break ; +case KVM_DEV_ARM_VGIC_GRP_REDIST_REGS : + tmp32 = *reg; + ret =vgic_v3_redist_uaccess (vcpu, is_write, addr, &tmp32); +if (!is_write) + *reg = tmp32; +break ; +default : + ret = -EINVAL ; +break ; + } + +unlock_all_vcpus (dev->kvm); +out: +mutex_unlock (&dev->kvm->lock); +return ret; +} +static int vgic_v3_set_attr (struct kvm_device *dev,struct kvm_device_attr *attr) { -return vgic_set_common_attr (dev, attr); +int ret; + + ret =vgic_set_common_attr (dev, attr); +if (ret != -ENXIO ) +return ret; + +switch (attr->group) { +case KVM_DEV_ARM_VGIC_GRP_DIST_REGS :virt/kvm/arm/vgic/vgic-kvm-device.c struct kvm_device_ops kvm_arm_vgic_v2_ops = { · line 534
Quoted 10 lines
virt/kvm/arm/vgic/vgic-kvm-device.c +10
-0+case KVM_DEV_ARM_VGIC_GRP_REDIST_REGS : { +u32 __user *uaddr = (u32 __user *)(long )attr->addr; +u32 tmp32; +u64 reg; + +if (get_user (tmp32, uaddr)) +return -EFAULT ; + + reg = tmp32; +return vgic_attr_regs_access_v3 (dev, attr, ®, true);oh, but wait, you already had a 32-bit value, which you convert into a 64-bit value, just to convert it back again, to do some extra data copies?
Quoted 3 lines
I'm really confused as to why this has to be so complicated.
Why not simply use u32 all the way?
vgic_attr_regs_access_v3()is used for handling both GICD/GICR and
SYSREGS. For this reason we convert u32 to 64 and vice versa.
To avoid these conversions, I can create separatevgic_attr_regs_access_v3()functions for GICD and SYSREGS.
Re: [RFC PATCH v3 2/5] arm/arm64: vgic-new: Add distributor and redistributor access
Quoted 132 lines · Vijay Kilari
Resending in plain text mode
Quoted 129 lines · Vijay Kilari
Quoted 125 lines · Christoffer Dall
Quoted 30 lines · On Wed, Aug 24, 2016 at 04:50:06PM +0530, [email protected] wrote:
From: Vijaya Kumar K <[email protected]>
VGICv3 Distributor and Redistributor registers are accessed using
KVM_DEV_ARM_VGIC_GRP_DIST_REGSandKVM_DEV_ARM_VGIC_GRP_DIST_REGSwithKVM_SET_DEVICE_ATTRandKVM_GET_DEVICE_ATTRioctls. These registers are accessed as 32-bit and cpu mpidr value passed along with register offset is used to identify the cpu for redistributor registers access.The version of VGIC v3 specification is define here
http://lists.infradead.org/pipermail/linux-arm-kernel/2016-July/445611.html
Signed-off-by Vijaya Kumar K <[email protected]>--- arch/arm64/include/uapi/asm/kvm.h | 3 + virt/kvm/arm/vgic/vgic-kvm-device.c | 127 +++++++++++++++++++++++++++++++++++- virt/kvm/arm/vgic/vgic-mmio-v3.c | 113 ++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic-mmio.c | 2 +- virt/kvm/arm/vgic/vgic.h | 8 +++ 5 files changed, 250 insertions(+), 3 deletions(-)arch/arm64/include/uapi/asm/kvm.h +0
-0arch/arm64/include/uapi/asm/kvm.h struct kvm_arch_memory_slot { · line 207
Quoted 7 lines
arch/arm64/include/uapi/asm/kvm.h +2
-0@@ -201,10 +201,13 @@ struct kvm_arch_memory_slot {#define KVM_DEV_ARM_VGIC_GRP_CPU_REGS 2#define KVM_DEV_ARM_VGIC_CPUID_SHIFT 32#define KVM_DEV_ARM_VGIC_CPUID_MASK (0xffULL << KVM_DEV_ARM_VGIC_CPUID_SHIFT) +#define KVM_DEV_ARM_VGIC_V3_CPUID_MASK \ + (0xffffffffULL << KVM_DEV_ARM_VGIC_CPUID_SHIFT)I think this should be
KVM_DEV_ARM_VGIC_V3_MPIDR_MASK, and I would probably define a V3 of the shift as well, since we're really talking about two distinct APIs here.Quoted 19 lines
arch/arm64/include/uapi/asm/kvm.h +1
-0#define KVM_DEV_ARM_VGIC_OFFSET_SHIFT 0#define KVM_DEV_ARM_VGIC_OFFSET_MASK (0xffffffffULL << KVM_DEV_ARM_VGIC_OFFSET_SHIFT)#define KVM_DEV_ARM_VGIC_GRP_NR_IRQS 3#define KVM_DEV_ARM_VGIC_GRP_CTRL 4 +#define KVM_DEV_ARM_VGIC_GRP_REDIST_REGS 5#define
KVM_DEV_ARM_VGIC_CTRL_INIT0/* Device Control API on vcpu fd */
virt/kvm/arm/vgic/vgic-kvm-device.c +1
-0@@ -433,16 +433,136 @@ struct kvm_device_ops kvm_arm_vgic_v2_ops = {#ifdef CONFIG_KVM_ARM_VGIC_V3 +static int parse_vgic_v3_attr(struct kvm_device *dev,virt/kvm/arm/vgic/vgic-kvm-device.c struct kvm_device_ops kvm_arm_vgic_v2_ops = { · line 446
Quoted 10 lines
virt/kvm/arm/vgic/vgic-kvm-device.c +10
-0+struct kvm_device_attr *attr, + struct vgic_reg_attr *reg_attr) +{ + int cpuid; + + cpuid = (attr->attr &KVM_DEV_ARM_VGIC_V3_CPUID_MASK ) >> +KVM_DEV_ARM_VGIC_CPUID_SHIFT ; + +if (cpuid >=atomic_read (&dev->kvm->online_vcpus)) +return -EINVAL ;huh? it's an MPIDR, not a cpu id.
just resolve it with
kvm_mpidr_to_vcpuand check its return value.virt/kvm/arm/vgic/vgic-kvm-device.c struct kvm_device_ops kvm_arm_vgic_v2_ops = { · line 448
Quoted 2 lines
virt/kvm/arm/vgic/vgic-kvm-device.c +2
-0+ + reg_attr->vcpu =kvm_mpidr_to_vcpu (dev->kvm, cpuid);please check the return value of this function in any case...
Quoted 25 lines
virt/kvm/arm/vgic/vgic-kvm-device.c +25
-0+ reg_attr->addr = attr->attr &KVM_DEV_ARM_VGIC_OFFSET_MASK ; + +return 0 ; +} + +/** +* vgic_attr_regs_access_v3 - allows user space to access VGIC v3 state +* +* @dev: kvm device handle +* @attr: kvm device attribute +* @reg: address the value is read or written +* @is_write: true if userspace is writing a register +*/ +static int vgic_attr_regs_access_v3 (struct kvm_device *dev, +struct kvm_device_attr *attr, +u64 *reg,bool is_write) +{ +struct vgic_reg_attr reg_attr; +gpa_t addr; +struct kvm_vcpu *vcpu; +int ret; +u32 tmp32; + + ret =parse_vgic_v3_attr (dev, attr, ®_attr); +if (ret)virt/kvm/arm/vgic/vgic-kvm-device.c struct kvm_device_ops kvm_arm_vgic_v2_ops = { · line 483
Quoted 10 lines
virt/kvm/arm/vgic/vgic-kvm-device.c +10
-0+return ret; + + vcpu = reg_attr.vcpu; + addr = reg_attr.addr; + +mutex_lock (&dev->kvm->lock); + + ret =vgic_init (dev->kvm); +if (ret) + goto out;no, no, please no more auto-init at userspace access time. This code should instead check
vgic_initialized()and return an error to userspace if not initialized.Ok. I wil fix it. It is coming from v2 code.
Next time, please fix your reply/indentation settings for replying to patches.
Quoted 72 lines
Quoted 72 lines
Quoted 70 lines
virt/kvm/arm/vgic/vgic-kvm-device.c struct kvm_device_ops kvm_arm_vgic_v2_ops = { · line 492
Quoted 12 lines
virt/kvm/arm/vgic/vgic-kvm-device.c +9
-0+ +if (!lock_all_vcpus (dev->kvm)) { + ret = -EBUSY ; + goto out; + } + +switch (attr->group) { +case KVM_DEV_ARM_VGIC_GRP_DIST_REGS : + tmp32 = *reg;why is this assignment not predicated on if (
is_write) ?also, all this type conversion nonsense is probably unnecessary, see my comment below.
Quoted 34 lines
virt/kvm/arm/vgic/vgic-kvm-device.c +29
-1+ ret =vgic_v3_dist_uaccess (vcpu, is_write, addr, &tmp32); +if (!is_write) + *reg = tmp32; +break ; +case KVM_DEV_ARM_VGIC_GRP_REDIST_REGS : + tmp32 = *reg; + ret =vgic_v3_redist_uaccess (vcpu, is_write, addr, &tmp32); +if (!is_write) + *reg = tmp32; +break ; +default : + ret = -EINVAL ; +break ; + } + +unlock_all_vcpus (dev->kvm); +out: +mutex_unlock (&dev->kvm->lock); +return ret; +} +static int vgic_v3_set_attr (struct kvm_device *dev,struct kvm_device_attr *attr) { -return vgic_set_common_attr (dev, attr); +int ret; + + ret =vgic_set_common_attr (dev, attr); +if (ret != -ENXIO ) +return ret; + +switch (attr->group) { +case KVM_DEV_ARM_VGIC_GRP_DIST_REGS :virt/kvm/arm/vgic/vgic-kvm-device.c struct kvm_device_ops kvm_arm_vgic_v2_ops = { · line 534
Quoted 10 lines
virt/kvm/arm/vgic/vgic-kvm-device.c +10
-0+case KVM_DEV_ARM_VGIC_GRP_REDIST_REGS : { +u32 __user *uaddr = (u32 __user *)(long )attr->addr; +u32 tmp32; +u64 reg; + +if (get_user (tmp32, uaddr)) +return -EFAULT ; + + reg = tmp32; +return vgic_attr_regs_access_v3 (dev, attr, ®, true);oh, but wait, you already had a 32-bit value, which you convert into a 64-bit value, just to convert it back again, to do some extra data copies?
I'm really confused as to why this has to be so complicated.
Why not simply use u32 all the way?
Quoted 6 lines
Quoted 6 lines
vgic_attr_regs_access_v3()is used for handling both GICD/GICR and
SYSREGS. For this reason we convert u32 to 64 and vice versa.
To avoid these conversions, I can create separatevgic_attr_regs_access_v3()functions for GICD and SYSREGS.
Ah, I see, thanks for pointing that out.
If there's a cleaner way, perhaps by creating a wrapper, that would be better, but we shouldn't duplicate the complicated function just to avoid the cast.
Thanks,
-Christoffer
RFC PATCH v3 3/5 arm/arm64: vgic-new: Introduce find_reg_by_id()
In reply to [email protected]From: Vijaya Kumar K <[email protected]>
In order to implement vGICv3 CPU interface access, we will need to perform table lookup of system registers. We would need both index_to_params() and find_reg() exported for that purpose, but instead we export a single function which combines them both.
--- arch/arm64/kvm/sys_regs.c | 22 +++++++++++++++------- arch/arm64/kvm/sys_regs.h | 4 ++++ 2 files changed, 19 insertions(+), 7 deletions(-)
arch/arm64/kvm/sys_regs.c +15 -7
@@ -1802,6 +1802,17 @@ static bool index_to_params(u64 id, struct sys_reg_params *params) } } +const struct sys_reg_desc *find_reg_by_id (u64 id, +struct sys_reg_params *params, +const struct sys_reg_desc table[], +unsigned int num) +{ +if (!index_to_params (id, params)) +return NULL ; + +return find_reg (params, table, num); +} +/* Decode an index value, and find the sys_reg_desc entry. */ static const struct sys_reg_desc *index_to_sys_reg_desc (struct kvm_vcpu *vcpu,u64 id)
@@ -1929,10 +1940,8 @@ static int get_invariant_sys_reg(u64 id, void __user *uaddr)struct sys_reg_params params;const struct sys_reg_desc *r; -if (!index_to_params (id, ¶ms)) -return -ENOENT ; - - r =find_reg (¶ms, invariant_sys_regs,ARRAY_SIZE (invariant_sys_regs)); + r =find_reg_by_id (id, ¶ms, invariant_sys_regs, +ARRAY_SIZE (invariant_sys_regs));if (!r)return -ENOENT ;
@@ -1946,9 +1955,8 @@ static int set_invariant_sys_reg(u64 id, void __user *uaddr)int err;u64 val =0 ;/* Make sure high bits are 0 for 32-bit regs */ -if (!index_to_params (id, ¶ms)) -return -ENOENT ; - r =find_reg (¶ms, invariant_sys_regs,ARRAY_SIZE (invariant_sys_regs)); + r =find_reg_by_id (id, ¶ms, invariant_sys_regs, +ARRAY_SIZE (invariant_sys_regs));if (!r)return -ENOENT ;
arch/arm64/kvm/sys_regs.h +4 -0
@@ -136,6 +136,10 @@ static inline int cmp_sys_reg(const struct sys_reg_desc *i1,return i1->Op2 - i2->Op2; } +const struct sys_reg_desc *find_reg_by_id (u64 id, +struct sys_reg_params *params, +const struct sys_reg_desc table[], +unsigned int num);#define Op0 (_x) .Op0 = _x#define Op1 (_x) .Op1 = _x
Signature · 1 line
1.9.1
Re: [RFC PATCH v3 3/5] arm/arm64: vgic-new: Introduce find_reg_by_id()
Quoted 10 lines · On Wed, Aug 24, 2016 at 04:50:07PM +0530, [email protected] wrote:
From: Vijaya Kumar K <[email protected]>
In order to implement vGICv3 CPU interface access, we will need to perform table lookup of system registers. We would need both
index_to_params()andfind_reg()exported for that purpose, but instead we export a single function which combines them both.Signed-off-by Pavel Fedin <[email protected]>Reviewed-by Andre Przywara <[email protected]>Signed-off-by Vijaya Kumar K <[email protected]>
RFC PATCH v3 4/5 arm/arm64: vgic-new: Implement VGICv3 CPU interface access
In reply to [email protected]From: Vijaya Kumar K <[email protected]>
VGICv3 CPU interface registers are accessed using KVM_DEV_ARM_VGIC_CPU_SYSREGS ioctl. These registers are accessed as 64-bit. The cpu MPIDR value is passed along with register id. is used to identify the cpu for registers access.
The version of VGIC v3 specification is define here
http://lists.infradead.org/pipermail/linux-arm-kernel/2016-July/445611.html
--- arch/arm64/include/uapi/asm/kvm.h | 15 ++- arch/arm64/kvm/Makefile | 1 + include/linux/irqchip/arm-gic-v3.h | 4 + virt/kvm/arm/vgic/vgic-kvm-device.c | 29 +++++ virt/kvm/arm/vgic/vgic-mmio-v2.c | 4 +- virt/kvm/arm/vgic/vgic-mmio-v3.c | 6 + virt/kvm/arm/vgic/vgic-sys-reg-v3.c | 211 ++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic.h | 6 + 8 files changed, 271 insertions(+), 5 deletions(-)
arch/arm64/include/uapi/asm/kvm.h +12 -3
@@ -182,14 +182,14 @@ struct kvm_arch_memory_slot { KVM_REG_ARM64_SYSREG_ ## n ## _MASK)#define __ARM64_SYS_REG (op0,op1,crn,crm,op2) \ - (KVM_REG_ARM64 | KVM_REG_ARM64_SYSREG | \ - ARM64_SYS_REG_SHIFT_MASK(op0, OP0) | \ + (ARM64_SYS_REG_SHIFT_MASK(op0, OP0) | \ ARM64_SYS_REG_SHIFT_MASK(op1, OP1) | \ ARM64_SYS_REG_SHIFT_MASK(crn, CRN) | \ ARM64_SYS_REG_SHIFT_MASK(crm, CRM) | \ ARM64_SYS_REG_SHIFT_MASK(op2, OP2)) -#define ARM64_SYS_REG (...) (__ARM64_SYS_REG(__VA_ARGS__) | KVM_REG_SIZE_U64) +#define ARM64_SYS_REG (...) (__ARM64_SYS_REG(__VA_ARGS__) | KVM_REG_SIZE_U64 | \ + KVM_REG_ARM64 | KVM_REG_ARM64_SYSREG)#define KVM_REG_ARM_TIMER_CTL ARM64_SYS_REG(3, 3, 14, 3, 1)#define KVM_REG_ARM_TIMER_CNT ARM64_SYS_REG(3, 3, 14, 3, 2)
@@ -208,7 +208,16 @@ struct kvm_arch_memory_slot {#define KVM_DEV_ARM_VGIC_GRP_NR_IRQS 3#define KVM_DEV_ARM_VGIC_GRP_CTRL 4#define KVM_DEV_ARM_VGIC_GRP_REDIST_REGS 5 +#define KVM_DEV_ARM_VGIC_CPU_SYSREGS 6 +#define KVM_DEV_ARM_VGIC_CTRL_INIT 0 +#define KVM_DEV_ARM_VGIC_SYSREG_MASK (KVM_REG_ARM64_SYSREG_OP0_MASK | \ + KVM_REG_ARM64_SYSREG_OP1_MASK | \ + KVM_REG_ARM64_SYSREG_CRN_MASK | \ + KVM_REG_ARM64_SYSREG_CRM_MASK | \ + KVM_REG_ARM64_SYSREG_OP2_MASK) +#define KVM_DEV_ARM_VGIC_SYSREG (op0, op1, crn, crm, op2) \ + __ARM64_SYS_REG(op0, op1, crn, crm, op2)/* Device Control API on vcpu fd */ #define KVM_ARM_VCPU_PMU_V3_CTRL 0
arch/arm64/kvm/Makefile +1 -0
@@ -31,5 +31,6 @@ kvm-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/vgic/vgic-mmio-v3.o kvm-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/vgic/vgic-kvm-device.o kvm-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/vgic/vgic-its.o kvm-$(CONFIG_KVM_ARM_HOST) += $(KVM)/irqchip.o +kvm-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/vgic/vgic-sys-reg-v3.o kvm-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/arch_timer.o kvm-$(CONFIG_KVM_ARM_PMU) += $(KVM)/arm/pmu.o
include/linux/irqchip/arm-gic-v3.h +4 -0
@@ -383,6 +383,10 @@#define ICH_VMCR_CTLR_SHIFT 0#define ICH_VMCR_CTLR_MASK (0x21f << ICH_VMCR_CTLR_SHIFT) +#define ICH_VMCR_ENG0_SHIFT 0 +#define ICH_VMCR_ENG0 (1 << ICH_VMCR_ENG0_SHIFT) +#define ICH_VMCR_ENG1_SHIFT 1 +#define ICH_VMCR_ENG1 (1 << ICH_VMCR_ENG1_SHIFT)#define ICH_VMCR_BPR1_SHIFT 18#define ICH_VMCR_BPR1_MASK (7 << ICH_VMCR_BPR1_SHIFT)#define ICH_VMCR_BPR0_SHIFT 21
virt/kvm/arm/vgic/vgic-kvm-device.c +29 -0
@@ -500,6 +500,15 @@ static int vgic_attr_regs_access_v3(struct kvm_device *dev,if (!is_write) *reg = tmp32;break ; +case KVM_DEV_ARM_VGIC_CPU_SYSREGS : { +u64 regid; + + regid = (attr->attr &KVM_DEV_ARM_VGIC_SYSREG_MASK ) | +KVM_REG_SIZE_U64 ; + ret =vgic_v3_cpu_sysregs_uaccess (vcpu, is_write, + regid, reg); +break ; + }default : ret = -EINVAL ;break ;
@@ -533,6 +542,15 @@ static int vgic_v3_set_attr(struct kvm_device *dev, reg = tmp32;return vgic_attr_regs_access_v3 (dev, attr, ®, true); } +case KVM_DEV_ARM_VGIC_CPU_SYSREGS : { +u64 __user *uaddr = (u64 __user *)(long )attr->addr; +u64 reg; + +if (get_user (reg, uaddr)) +return -EFAULT ; + +return vgic_attr_regs_access_v3 (dev, attr, ®, true); + } }return -ENXIO ; }
@@ -560,6 +578,16 @@ static int vgic_v3_get_attr(struct kvm_device *dev, ret =put_user (tmp32, uaddr);return ret; } +case KVM_DEV_ARM_VGIC_CPU_SYSREGS : { +u64 __user *uaddr = (u64 __user *)(long )attr->addr; +u64 reg; + + ret =vgic_attr_regs_access_v3 (dev, attr, ®, false); +if (ret) +return ret; + ret =put_user (reg, uaddr); +return ret; + } }return -ENXIO ;
@@ -578,6 +606,7 @@ static int vgic_v3_has_attr(struct kvm_device *dev,break ;case KVM_DEV_ARM_VGIC_GRP_DIST_REGS :case KVM_DEV_ARM_VGIC_GRP_REDIST_REGS : +case KVM_DEV_ARM_VGIC_CPU_SYSREGS :return vgic_v3_has_attr_regs (dev, attr);case KVM_DEV_ARM_VGIC_GRP_NR_IRQS :return 0 ;
virt/kvm/arm/vgic/vgic-mmio-v2.c +2 -2
@@ -212,7 +212,7 @@ static void vgic_mmio_write_sgipends(struct kvm_vcpu *vcpu, } } -static void vgic_set_vmcr (struct kvm_vcpu *vcpu,struct vgic_vmcr *vmcr) +void vgic_set_vmcr (struct kvm_vcpu *vcpu,struct vgic_vmcr *vmcr) {if (kvm_vgic_global_state.type ==VGIC_V2 )vgic_v2_set_vmcr (vcpu, vmcr);
@@ -220,7 +220,7 @@ static void vgic_set_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcr)vgic_v3_set_vmcr (vcpu, vmcr); } -static void vgic_get_vmcr (struct kvm_vcpu *vcpu,struct vgic_vmcr *vmcr) +void vgic_get_vmcr (struct kvm_vcpu *vcpu,struct vgic_vmcr *vmcr) {if (kvm_vgic_global_state.type ==VGIC_V2 )vgic_v2_get_vmcr (vcpu, vmcr);
virt/kvm/arm/vgic/vgic-mmio-v3.c +6 -0
@@ -23,6 +23,7 @@#include "vgic.h" #include "vgic-mmio.h" +#include "sys_regs.h" /* extract @num bytes at @offset bytes offset in data */ unsigned long extract_bytes(unsigned long data, unsigned int offset,
@@ -598,6 +599,11 @@ int vgic_v3_has_attr_regs(struct kvm_device *dev, struct kvm_device_attr *attr) nr_regions =ARRAY_SIZE (vgic_v3_rdbase_registers);break ; } +case KVM_DEV_ARM_VGIC_CPU_SYSREGS : { +u64 reg; + +return vgic_v3_has_cpu_sysregs_attr (vcpu,0 , cpuid, ®); + }default :return -ENXIO ; }
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +211 -0
211 lines not on this page · raw message
virt/kvm/arm/vgic/vgic.h +6 -0
@@ -96,6 +96,10 @@ int vgic_v3_dist_uaccess(struct kvm_vcpu *vcpu, bool is_write, int offset, u32 *val);int vgic_v3_redist_uaccess (struct kvm_vcpu *vcpu,bool is_write,int offset,u32 *val); +int vgic_v3_cpu_sysregs_uaccess (struct kvm_vcpu *vcpu,bool is_write, +u64 id,u64 *val); +int vgic_v3_has_cpu_sysregs_attr (struct kvm_vcpu *vcpu,bool is_write,u64 id, +u64 *reg);#else static inline void vgic_v3_process_maintenance (struct kvm_vcpu *vcpu) {
@@ -169,6 +173,8 @@ static inline int vgic_its_inject_msi(struct kvm *kvm, struct kvm_msi *msi)#endif int kvm_register_vgic_device (unsigned long type); +void vgic_set_vmcr (struct kvm_vcpu *vcpu,struct vgic_vmcr *vmcr); +void vgic_get_vmcr (struct kvm_vcpu *vcpu,struct vgic_vmcr *vmcr);int vgic_lazy_init (struct kvm *kvm);int vgic_init (struct kvm *kvm);
Signature · 1 line
1.9.1
Re: [RFC PATCH v3 4/5] arm/arm64: vgic-new: Implement VGICv3 CPU interface access
Quoted 28 lines · On Wed, Aug 24, 2016 at 04:50:08PM +0530, [email protected] wrote:
From: Vijaya Kumar K <[email protected]>
VGICv3 CPU interface registers are accessed using
KVM_DEV_ARM_VGIC_CPU_SYSREGSioctl. These registers are accessed as 64-bit. The cpu MPIDR value is passed along with register id. is used to identify the cpu for registers access.The version of VGIC v3 specification is define here
http://lists.infradead.org/pipermail/linux-arm-kernel/2016-July/445611.htmlSigned-off-by Pavel Fedin <[email protected]>Signed-off-by Vijaya Kumar K <[email protected]>--- arch/arm64/include/uapi/asm/kvm.h | 15 ++- arch/arm64/kvm/Makefile | 1 + include/linux/irqchip/arm-gic-v3.h | 4 + virt/kvm/arm/vgic/vgic-kvm-device.c | 29 +++++ virt/kvm/arm/vgic/vgic-mmio-v2.c | 4 +- virt/kvm/arm/vgic/vgic-mmio-v3.c | 6 + virt/kvm/arm/vgic/vgic-sys-reg-v3.c | 211 ++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic.h | 6 + 8 files changed, 271 insertions(+), 5 deletions(-)arch/arm64/include/uapi/asm/kvm.h +0
-0
arch/arm64/include/uapi/asm/kvm.h struct kvm_arch_memory_slot { · line 189
Quoted 10 lines
arch/arm64/include/uapi/asm/kvm.h +1
-2@@ -182,14 +182,14 @@ struct kvm_arch_memory_slot { KVM_REG_ARM64_SYSREG_ ## n ## _MASK)#define __ARM64_SYS_REG (op0,op1,crn,crm,op2) \ - (KVM_REG_ARM64 | KVM_REG_ARM64_SYSREG | \ - ARM64_SYS_REG_SHIFT_MASK(op0, OP0) | \ + (ARM64_SYS_REG_SHIFT_MASK(op0, OP0) | \ ARM64_SYS_REG_SHIFT_MASK(op1, OP1) | \ ARM64_SYS_REG_SHIFT_MASK(crn, CRN) | \ ARM64_SYS_REG_SHIFT_MASK(crm, CRM) | \ ARM64_SYS_REG_SHIFT_MASK(op2, OP2))
eh, no, please don't modify an exported userspace API header file in this way.
If you want to reuse this, then add a new define for the sysreg field generators and call that from __ARM64_SYS_REG() and from KVM_DEV_ARM_VGIC_SYSREG.
Quoted 9 lines
arch/arm64/include/uapi/asm/kvm.h +2
-1-#define ARM64_SYS_REG (...) (__ARM64_SYS_REG(__VA_ARGS__) | KVM_REG_SIZE_U64) +#define ARM64_SYS_REG (...) (__ARM64_SYS_REG(__VA_ARGS__) | KVM_REG_SIZE_U64 | \ + KVM_REG_ARM64 | KVM_REG_ARM64_SYSREG)#define KVM_REG_ARM_TIMER_CTL ARM64_SYS_REG(3, 3, 14, 3, 1)#define KVM_REG_ARM_TIMER_CNT ARM64_SYS_REG(3, 3, 14, 3, 2)@@ -208,7 +208,16 @@ struct kvm_arch_memory_slot {#define KVM_DEV_ARM_VGIC_GRP_NR_IRQS 3
arch/arm64/include/uapi/asm/kvm.h struct kvm_arch_memory_slot { · line 218
Quoted 10 lines
arch/arm64/include/uapi/asm/kvm.h +7
-0#define KVM_DEV_ARM_VGIC_GRP_CTRL 4#define KVM_DEV_ARM_VGIC_GRP_REDIST_REGS 5 +#define KVM_DEV_ARM_VGIC_CPU_SYSREGS 6 +#define KVM_DEV_ARM_VGIC_CTRL_INIT 0 +#define KVM_DEV_ARM_VGIC_SYSREG_MASK (KVM_REG_ARM64_SYSREG_OP0_MASK | \ + KVM_REG_ARM64_SYSREG_OP1_MASK | \ + KVM_REG_ARM64_SYSREG_CRN_MASK | \ + KVM_REG_ARM64_SYSREG_CRM_MASK | \ + KVM_REG_ARM64_SYSREG_OP2_MASK)
we didn't need this for the existing userspace to kernel sysreg interface, why do we need this now, and even need to export it to userspace?
Quoted 36 lines
arch/arm64/include/uapi/asm/kvm.h +2
-0+#define KVM_DEV_ARM_VGIC_SYSREG (op0, op1, crn, crm, op2) \ + __ARM64_SYS_REG(op0, op1, crn, crm, op2)/* Device Control API on vcpu fd */ #define KVM_ARM_VCPU_PMU_V3_CTRL 0arch/arm64/kvm/Makefile +1
-0@@ -31,5 +31,6 @@ kvm-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/vgic/vgic-mmio-v3.o kvm-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/vgic/vgic-kvm-device.o kvm-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/vgic/vgic-its.o kvm-$(CONFIG_KVM_ARM_HOST) += $(KVM)/irqchip.o +kvm-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/vgic/vgic-sys-reg-v3.o kvm-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/arch_timer.o kvm-$(CONFIG_KVM_ARM_PMU) += $(KVM)/arm/pmu.oinclude/linux/irqchip/arm-gic-v3.h +4
-0@@ -383,6 +383,10 @@#define ICH_VMCR_CTLR_SHIFT 0#define ICH_VMCR_CTLR_MASK (0x21f << ICH_VMCR_CTLR_SHIFT) +#define ICH_VMCR_ENG0_SHIFT 0 +#define ICH_VMCR_ENG0 (1 << ICH_VMCR_ENG0_SHIFT) +#define ICH_VMCR_ENG1_SHIFT 1 +#define ICH_VMCR_ENG1 (1 << ICH_VMCR_ENG1_SHIFT)#define ICH_VMCR_BPR1_SHIFT 18#define ICH_VMCR_BPR1_MASK (7 << ICH_VMCR_BPR1_SHIFT)#define ICH_VMCR_BPR0_SHIFT 21virt/kvm/arm/vgic/vgic-kvm-device.c +0
-0
virt/kvm/arm/vgic/vgic-kvm-device.c static int vgic_attr_regs_access_v3(struct kvm_device *dev, · line 507
Quoted 8 lines
virt/kvm/arm/vgic/vgic-kvm-device.c +5
-0@@ -500,6 +500,15 @@ static int vgic_attr_regs_access_v3(struct kvm_device *dev,if (!is_write) *reg = tmp32;break ; +case KVM_DEV_ARM_VGIC_CPU_SYSREGS : { +u64 regid; + + regid = (attr->attr &KVM_DEV_ARM_VGIC_SYSREG_MASK ) | +KVM_REG_SIZE_U64 ;
I think the simpler way, which is analogous to what the other sysreg access functions do, it so simply define a mask fort the 'instr' field (0xffff) and let the lookup function worry about the individual fields.
Quoted 26 lines
virt/kvm/arm/vgic/vgic-kvm-device.c +13
-0+ ret =vgic_v3_cpu_sysregs_uaccess (vcpu, is_write, + regid, reg); +break ; + }default : ret = -EINVAL ;break ;@@ -533,6 +542,15 @@ static int vgic_v3_set_attr(struct kvm_device *dev, reg = tmp32;return vgic_attr_regs_access_v3 (dev, attr, ®, true); } +case KVM_DEV_ARM_VGIC_CPU_SYSREGS : { +u64 __user *uaddr = (u64 __user *)(long )attr->addr; +u64 reg; + +if (get_user (reg, uaddr)) +return -EFAULT ; + +return vgic_attr_regs_access_v3 (dev, attr, ®, true); + } }return -ENXIO ; }@@ -560,6 +578,16 @@ static int vgic_v3_get_attr(struct kvm_device *dev, ret =put_user (tmp32, uaddr);return ret;
virt/kvm/arm/vgic/vgic-kvm-device.c static int vgic_v3_get_attr(struct kvm_device *dev, · line 589
Quoted 10 lines
virt/kvm/arm/vgic/vgic-kvm-device.c +9
-0} +case KVM_DEV_ARM_VGIC_CPU_SYSREGS : { +u64 __user *uaddr = (u64 __user *)(long )attr->addr; +u64 reg; + + ret =vgic_attr_regs_access_v3 (dev, attr, ®, false); +if (ret) +return ret; + ret =put_user (reg, uaddr); +return ret;
nit: you can just do 'return put_user(reg, uaddr);'
Quoted 80 lines
virt/kvm/arm/vgic/vgic-kvm-device.c +2
-0+ } }return -ENXIO ;@@ -578,6 +606,7 @@ static int vgic_v3_has_attr(struct kvm_device *dev,break ;case KVM_DEV_ARM_VGIC_GRP_DIST_REGS :case KVM_DEV_ARM_VGIC_GRP_REDIST_REGS : +case KVM_DEV_ARM_VGIC_CPU_SYSREGS :return vgic_v3_has_attr_regs (dev, attr);case KVM_DEV_ARM_VGIC_GRP_NR_IRQS :return 0 ;virt/kvm/arm/vgic/vgic-mmio-v2.c +2
-2@@ -212,7 +212,7 @@ static void vgic_mmio_write_sgipends(struct kvm_vcpu *vcpu, } } -static void vgic_set_vmcr (struct kvm_vcpu *vcpu,struct vgic_vmcr *vmcr) +void vgic_set_vmcr (struct kvm_vcpu *vcpu,struct vgic_vmcr *vmcr) {if (kvm_vgic_global_state.type ==VGIC_V2 )vgic_v2_set_vmcr (vcpu, vmcr);@@ -220,7 +220,7 @@ static void vgic_set_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcr)vgic_v3_set_vmcr (vcpu, vmcr); } -static void vgic_get_vmcr (struct kvm_vcpu *vcpu,struct vgic_vmcr *vmcr) +void vgic_get_vmcr (struct kvm_vcpu *vcpu,struct vgic_vmcr *vmcr) {if (kvm_vgic_global_state.type ==VGIC_V2 )vgic_v2_get_vmcr (vcpu, vmcr);virt/kvm/arm/vgic/vgic-mmio-v3.c +6
-0@@ -23,6 +23,7 @@#include "vgic.h" #include "vgic-mmio.h" +#include "sys_regs.h" /* extract @num bytes at @offset bytes offset in data */ unsigned long extract_bytes(unsigned long data, unsigned int offset,@@ -598,6 +599,11 @@ int vgic_v3_has_attr_regs(struct kvm_device *dev, struct kvm_device_attr *attr) nr_regions =ARRAY_SIZE (vgic_v3_rdbase_registers);break ; } +case KVM_DEV_ARM_VGIC_CPU_SYSREGS : { +u64 reg; + +return vgic_v3_has_cpu_sysregs_attr (vcpu,0 , cpuid, ®); + }default :return -ENXIO ; }virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +16
-0@@ -0,0 +1,211 @@ +#include <linux/irqchip/arm-gic-v3.h> +#include <linux/kvm.h> +#include <linux/kvm_host.h> +#include <kvm/iodev.h> +#include <kvm/arm_vgic.h> +#include <asm/kvm_emulate.h> +#include <asm/kvm_arm.h> +#include <asm/kvm_mmu.h> + +#include "vgic.h" +#include "vgic-mmio.h" +#include "sys_regs.h" + +static bool access_gic_ctlr (struct kvm_vcpu *vcpu,struct sys_reg_params *p, +const struct sys_reg_desc *r) +{
virt/kvm/arm/vgic/vgic-sys-reg-v3.c line 26
Quoted 10 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +10
-0+struct vgic_vmcr vmcr; + +vgic_get_vmcr (vcpu, &vmcr); +if (p->is_write) { + vmcr.ctlr = (u32 )p->regval; +vgic_set_vmcr (vcpu, &vmcr); + }else { + p->regval = vmcr.ctlr; + } +
really? Have you looked at the spec and implementation of this or did you just copy the v2 code?
The ICH_VMCR_EL2 register field mappings are not identical to the ctlr mappings. I think this causes some rework for much of this patch, so I'll have a look at the next revision.
Quoted 54 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +54
-0+return true; +} + +static bool access_gic_pmr (struct kvm_vcpu *vcpu,struct sys_reg_params *p, +const struct sys_reg_desc *r) +{ +struct vgic_vmcr vmcr; + +vgic_get_vmcr (vcpu, &vmcr); +if (p->is_write) { + vmcr.pmr = (u32 )p->regval; +vgic_set_vmcr (vcpu, &vmcr); + }else { + p->regval = vmcr.pmr; + } + +return true; +} + +static bool access_gic_bpr0 (struct kvm_vcpu *vcpu,struct sys_reg_params *p, +const struct sys_reg_desc *r) +{ +struct vgic_vmcr vmcr; + +vgic_get_vmcr (vcpu, &vmcr); +if (p->is_write) { + vmcr.bpr = (u32 )p->regval; +vgic_set_vmcr (vcpu, &vmcr); + }else { + p->regval = vmcr.bpr; + } + +return true; +} + +static bool access_gic_bpr1 (struct kvm_vcpu *vcpu,struct sys_reg_params *p, +const struct sys_reg_desc *r) +{ +struct vgic_vmcr vmcr; + +vgic_get_vmcr (vcpu, &vmcr); +if (p->is_write) { + vmcr.abpr = (u32 )p->regval; +vgic_set_vmcr (vcpu, &vmcr); + }else { + p->regval = vmcr.abpr; + } + +return true; +} + +static bool access_gic_grpen0 (struct kvm_vcpu *vcpu,struct sys_reg_params *p, +const struct sys_reg_desc *r) +{
virt/kvm/arm/vgic/vgic-sys-reg-v3.c line 90
Quoted 10 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +10
-0+struct vgic_v3_cpu_if *vgicv3 = &vcpu->arch.vgic_cpu.vgic_v3; + +if (p->is_write) { + vgicv3->vgic_vmcr &= ~ICH_VMCR_ENG0 ; + vgicv3->vgic_vmcr |= (p->regval <<ICH_VMCR_ENG0_SHIFT ) & +ICH_VMCR_ENG0 ; + }else { + p->regval = (vgicv3->vgic_vmcr &ICH_VMCR_ENG0 ) >> +ICH_VMCR_ENG0_SHIFT ; + }
so for example, why shouldn't these go through the vgic_set/get_vmcr wrappers?
Quoted 68 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +68
-0+ +return true; +} + +static bool access_gic_grpen1 (struct kvm_vcpu *vcpu,struct sys_reg_params *p, +const struct sys_reg_desc *r) +{ +struct vgic_v3_cpu_if *vgicv3 = &vcpu->arch.vgic_cpu.vgic_v3; + +if (p->is_write) { + vgicv3->vgic_vmcr &= ~ICH_VMCR_ENG1 ; + vgicv3->vgic_vmcr |= (p->regval <<ICH_VMCR_ENG1_SHIFT ) & +ICH_VMCR_ENG1 ; + }else { + p->regval = (vgicv3->vgic_vmcr &ICH_VMCR_ENG1 ) >> +ICH_VMCR_ENG1_SHIFT ; + } + +return true; +} + +static bool access_gic_ap0r (struct kvm_vcpu *vcpu,struct sys_reg_params *p, +const struct sys_reg_desc *r) +{ +struct vgic_v3_cpu_if *vgicv3 = &vcpu->arch.vgic_cpu.vgic_v3; +u8 idx = r->Op2 &3 ; + +if (p->is_write) + vgicv3->vgic_ap0r[idx] = p->regval; +else + p->regval = vgicv3->vgic_ap0r[idx]; + +return true; +} + +static bool access_gic_ap1r (struct kvm_vcpu *vcpu,struct sys_reg_params *p, +const struct sys_reg_desc *r) +{ +struct vgic_v3_cpu_if *vgicv3 = &vcpu->arch.vgic_cpu.vgic_v3; +u8 idx = r->Op2 &3 ; + +if (p->is_write) + vgicv3->vgic_ap1r[idx] = p->regval; +else + p->regval = vgicv3->vgic_ap1r[idx]; + +return true; +} + +static const struct sys_reg_desc gic_v3_icc_reg_descs[] = { +/* ICC_PMR_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (4 ),CRm (6 ),Op2 (0 ), access_gic_pmr }, +/* ICC_BPR0_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (8 ),Op2 (3 ), access_gic_bpr0 }, +/* ICC_AP0R0_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (8 ),Op2 (4 ), access_gic_ap0r }, +/* ICC_AP0R1_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (8 ),Op2 (5 ), access_gic_ap0r }, +/* ICC_AP0R2_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (8 ),Op2 (6 ), access_gic_ap0r }, +/* ICC_AP0R3_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (8 ),Op2 (7 ), access_gic_ap0r }, +/* ICC_AP1R0_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (9 ),Op2 (0 ), access_gic_ap1r }, +/* ICC_AP1R1_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (9 ),Op2 (1 ), access_gic_ap1r }, +/* ICC_AP1R2_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (9 ),Op2 (2 ), access_gic_ap1r },
virt/kvm/arm/vgic/vgic-sys-reg-v3.c line 168
Quoted 10 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +10
-0+/* ICC_AP1R3_EL1 */ + { Op0(3), Op1(0), CRn(12), CRm(9), Op2(3), access_gic_ap1r }, +/* ICC_BPR1_EL1 */ + { Op0(3), Op1(0), CRn(12), CRm(12), Op2(3), access_gic_bpr1 }, +/* ICC_CTLR_EL1 */ + { Op0(3), Op1(0), CRn(12), CRm(12), Op2(4), access_gic_ctlr }, +/* ICC_IGRPEN0_EL1 */ + { Op0(3), Op1(0), CRn(12), CRm(12), Op2(6), access_gic_grpen0 }, +/* ICC_GRPEN1_EL1 */ + { Op0(3), Op1(0), CRn(12), CRm(12), Op2(7), access_gic_grpen1 },
Do we need to allow userspace to at least read ICC_SRE_EL1?
Should we verify that the DIB and FDB fields of that register are written as the system understands them (clear, WI)?
Quoted 5 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +5
-0+}; + +int vgic_v3_has_cpu_sysregs_attr (struct kvm_vcpu *vcpu,bool is_write,u64 id, +u64 *reg) +{
virt/kvm/arm/vgic/vgic-sys-reg-v3.c line 183
Quoted 10 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +10
-0+struct sys_reg_params params; + + params.regval =le64_to_cpu (*reg); + params.is_write = is_write; + params.is_aarch32 = false; + params.is_32bit = false; + +return find_reg_by_id (id, ¶ms, gic_v3_icc_reg_descs, +ARRAY_SIZE (gic_v3_icc_reg_descs)) ? +0 : -ENXIO ;
this looks terrible, please rewrite without the ternary operator.
virt/kvm/arm/vgic/vgic-sys-reg-v3.c line 193
Quoted 10 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +10
-0+} + +int vgic_v3_cpu_sysregs_uaccess (struct kvm_vcpu *vcpu,bool is_write,u64 id, +u64 *reg) +{ +struct sys_reg_params params; +const struct sys_reg_desc *r; + +if (is_write) + params.regval =le64_to_cpu (*reg);
why do we need this conversion here?
Quoted 4 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +4
-0+ params.is_write = is_write; + params.is_aarch32 = false; + params.is_32bit = false; +
virt/kvm/arm/vgic/vgic-sys-reg-v3.c line 207
Quoted 10 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +10
-0+ r =find_reg_by_id (id, ¶ms, gic_v3_icc_reg_descs, +ARRAY_SIZE (gic_v3_icc_reg_descs)); +if (!r) +return -ENXIO ; + +if (!r->access (vcpu, ¶ms, r)) +return -EINVAL ; + +if (!is_write) + *reg =cpu_to_le64 (params.regval);
same question as above
Quoted 31 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +4
-0+ +return 0 ; +} +virt/kvm/arm/vgic/vgic.h +6
-0@@ -96,6 +96,10 @@ int vgic_v3_dist_uaccess(struct kvm_vcpu *vcpu, bool is_write, int offset, u32 *val);int vgic_v3_redist_uaccess (struct kvm_vcpu *vcpu,bool is_write,int offset,u32 *val); +int vgic_v3_cpu_sysregs_uaccess (struct kvm_vcpu *vcpu,bool is_write, +u64 id,u64 *val); +int vgic_v3_has_cpu_sysregs_attr (struct kvm_vcpu *vcpu,bool is_write,u64 id, +u64 *reg);#else static inline void vgic_v3_process_maintenance (struct kvm_vcpu *vcpu) {@@ -169,6 +173,8 @@ static inline int vgic_its_inject_msi(struct kvm *kvm, struct kvm_msi *msi)#endif int kvm_register_vgic_device (unsigned long type); +void vgic_set_vmcr (struct kvm_vcpu *vcpu,struct vgic_vmcr *vmcr); +void vgic_get_vmcr (struct kvm_vcpu *vcpu,struct vgic_vmcr *vmcr);int vgic_lazy_init (struct kvm *kvm);int vgic_init (struct kvm *kvm);Signature · 1 line
1.9.1
Re: [RFC PATCH v3 4/5] arm/arm64: vgic-new: Implement VGICv3 CPU interface access
Quoted 43 lines · Christoffer Dall
Review
Quoted 5 lines · On Wed, Aug 24, 2016 at 04:50:08PM +0530, [email protected] wrote:
From: Vijaya Kumar K <[email protected]>
(quoted diff) +0
-0
b/virt/kvm/arm/vgic/vgic-sys-reg-v3.cQuoted 9 lines
new file mode 100644
index 0000000..581d053virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +4
-0@@ -0,0 +1,211 @@ +#include <linux/irqchip/arm-gic-v3.h> +#include <linux/kvm.h> +#include <linux/kvm_host.h> +#include <kvm/iodev.h> virt/kvm/arm/vgic/vgic-sys-reg-v3.c line 14
Quoted 10 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +10
-0+#include <kvm/arm_vgic.h> +#include <asm/kvm_emulate.h> +#include <asm/kvm_arm.h> +#include <asm/kvm_mmu.h> + +#include "vgic.h" +#include "vgic-mmio.h" +#include "sys_regs.h" + +static bool access_gic_ctlr(struct kvm_vcpu *vcpu, struct
sys_reg_params*p,virt/kvm/arm/vgic/vgic-sys-reg-v3.c line 26
Quoted 12 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +12
-0+ const struct sys_reg_desc *r) +{ +struct vgic_vmcr vmcr; + +vgic_get_vmcr (vcpu, &vmcr); +if (p->is_write) { + vmcr.ctlr = (u32 )p->regval; +vgic_set_vmcr (vcpu, &vmcr); + }else { + p->regval = vmcr.ctlr; + } +really? Have you looked at the spec and implementation of this or did you just copy the v2 code?
Quoted 4 lines
The
ICH_VMCR_EL2register field mappings are not identical to the ctlr mappings. I think this causes some rework for much of this patch, so I'll have a look at the next revision.
ICH_VMCR_EL2.VEOIM & ICH_VMCR_EL2.CBPR holds
ICC_CTLR_EL1.EOImode & ICC_CTLR_EL1.CBPR respectively. Remaining fields are Readonly except PHME. AFAIK, vgic is not holding ICC_CTLR_EL1 except the fields in ICH_VMCR_EL2.
Quoted 57 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c
Quoted 5 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +4
-0+return true; +} + +static bool access_gic_pmr(struct kvm_vcpu *vcpu, struct sys_reg_params*p,
Quoted 6 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +6
-0+ const struct sys_reg_desc *r) +{ +struct vgic_vmcr vmcr; + +vgic_get_vmcr (vcpu, &vmcr); +if (p->is_write) {virt/kvm/arm/vgic/vgic-sys-reg-v3.c
Quoted 10 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +10
-0+ vmcr.pmr = (u32 )p->regval; +vgic_set_vmcr (vcpu, &vmcr); + }else { + p->regval = vmcr.pmr; + } + +return true; +} + +static bool access_gic_bpr0(struct kvm_vcpu *vcpu, struct
sys_reg_params*p,Quoted 6 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +6
-0+ const struct sys_reg_desc *r) +{ +struct vgic_vmcr vmcr; + +vgic_get_vmcr (vcpu, &vmcr); +if (p->is_write) {virt/kvm/arm/vgic/vgic-sys-reg-v3.c
Quoted 10 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +10
-0+ vmcr.bpr = (u32 )p->regval; +vgic_set_vmcr (vcpu, &vmcr); + }else { + p->regval = vmcr.bpr; + } + +return true; +} + +static bool access_gic_bpr1(struct kvm_vcpu *vcpu, struct
sys_reg_params*p,Quoted 6 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +6
-0+ const struct sys_reg_desc *r) +{ +struct vgic_vmcr vmcr; + +vgic_get_vmcr (vcpu, &vmcr); +if (p->is_write) {virt/kvm/arm/vgic/vgic-sys-reg-v3.c
Quoted 10 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +10
-0+ vmcr.abpr = (u32 )p->regval; +vgic_set_vmcr (vcpu, &vmcr); + }else { + p->regval = vmcr.abpr; + } + +return true; +} + +static bool access_gic_grpen0(struct kvm_vcpu *vcpu, struct
sys_reg_params*p,
Quoted 16 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c line 90
Quoted 12 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +12
-0+ const struct sys_reg_desc *r) +{ +struct vgic_v3_cpu_if *vgicv3 = &vcpu->arch.vgic_cpu.vgic_v3; + +if (p->is_write) { + vgicv3->vgic_vmcr &= ~ICH_VMCR_ENG0 ; + vgicv3->vgic_vmcr |= (p->regval <<ICH_VMCR_ENG0_SHIFT ) & +ICH_VMCR_ENG0 ; + }else { + p->regval = (vgicv3->vgic_vmcr &ICH_VMCR_ENG0 ) >> +ICH_VMCR_ENG0_SHIFT ; + }so for example, why shouldn't these go through the vgic_set/get_vmcr wrappers?
The vgic_vmcr struct as below is not managing ENG0 and ENG1 fields. So could not use vgic_set/get wrappers.
struct vgic_vmcr {
u32 ctlr;
u32 abpr;
u32 bpr;
u32 pmr;
};Quoted 76 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c
Quoted 6 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +5
-0+ +return true; +} + +static bool access_gic_grpen1(struct kvm_vcpu *vcpu, struct
sys_reg_params*p,Quoted 7 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +7
-0+ const struct sys_reg_desc *r) +{ +struct vgic_v3_cpu_if *vgicv3 = &vcpu->arch.vgic_cpu.vgic_v3; + +if (p->is_write) { + vgicv3->vgic_vmcr &= ~ICH_VMCR_ENG1 ; + vgicv3->vgic_vmcr |= (p->regval << ICH_VMCR_ENG1_SHIFT) &virt/kvm/arm/vgic/vgic-sys-reg-v3.c
Quoted 10 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +10
-0+ICH_VMCR_ENG1 ; + }else { + p->regval = (vgicv3->vgic_vmcr &ICH_VMCR_ENG1 ) >> +ICH_VMCR_ENG1_SHIFT ; + } + +return true; +} + +static bool access_gic_ap0r(struct kvm_vcpu *vcpu, struct
sys_reg_params*p,Quoted 4 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +4
-0+ const struct sys_reg_desc *r) +{ +struct vgic_v3_cpu_if *vgicv3 = &vcpu->arch.vgic_cpu.vgic_v3; +u8 idx = r->Op2 &3 ;virt/kvm/arm/vgic/vgic-sys-reg-v3.c
Quoted 10 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +10
-0+ +if (p->is_write) + vgicv3->vgic_ap0r[idx] = p->regval; +else + p->regval = vgicv3->vgic_ap0r[idx]; + +return true; +} + +static bool access_gic_ap1r(struct kvm_vcpu *vcpu, struct
sys_reg_params*p,Quoted 36 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +36
-0+ const struct sys_reg_desc *r) +{ +struct vgic_v3_cpu_if *vgicv3 = &vcpu->arch.vgic_cpu.vgic_v3; +u8 idx = r->Op2 &3 ; + +if (p->is_write) + vgicv3->vgic_ap1r[idx] = p->regval; +else + p->regval = vgicv3->vgic_ap1r[idx]; + +return true; +} + +static const struct sys_reg_desc gic_v3_icc_reg_descs[] = { +/* ICC_PMR_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (4 ),CRm (6 ),Op2 (0 ), access_gic_pmr }, +/* ICC_BPR0_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (8 ),Op2 (3 ), access_gic_bpr0 }, +/* ICC_AP0R0_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (8 ),Op2 (4 ), access_gic_ap0r }, +/* ICC_AP0R1_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (8 ),Op2 (5 ), access_gic_ap0r }, +/* ICC_AP0R2_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (8 ),Op2 (6 ), access_gic_ap0r }, +/* ICC_AP0R3_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (8 ),Op2 (7 ), access_gic_ap0r }, +/* ICC_AP1R0_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (9 ),Op2 (0 ), access_gic_ap1r }, +/* ICC_AP1R1_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (9 ),Op2 (1 ), access_gic_ap1r }, +/* ICC_AP1R2_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (9 ),Op2 (2 ), access_gic_ap1r }, +/* ICC_AP1R3_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (9 ),Op2 (3 ), access_gic_ap1r }, +/* ICC_BPR1_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (12 ),Op2 (3 ), access_gic_bpr1 },
Quoted 8 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c line 168
Quoted 6 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +6
-0+/* ICC_CTLR_EL1 */ + { Op0(3), Op1(0), CRn(12), CRm(12), Op2(4), access_gic_ctlr }, +/* ICC_IGRPEN0_EL1 */ + { Op0(3), Op1(0), CRn(12), CRm(12), Op2(6), access_gic_grpen0 }, +/* ICC_GRPEN1_EL1 */ + { Op0(3), Op1(0), CRn(12), CRm(12), Op2(7), access_gic_grpen1 },Do we need to allow userspace to at least read
ICC_SRE_EL1?
ICC_SRE_EL1.SRE is enabled at vgic initialization and DIB and FDB are not configured.
So save and restore does not make any effect.
Quoted 3 lines
Should we verify that the DIB and FDB fields of that register are written as the system understands them (clear, WI)?
What kind of verification we can do on DIB and FDB by userspace?.
Quoted 14 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c line 170
Quoted 3 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +2
-0+ +int vgic_v3_cpu_sysregs_uaccess(struct kvm_vcpu *vcpu, bool is_write,u64 id,
virt/kvm/arm/vgic/vgic-sys-reg-v3.c line 193
Quoted 7 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +7
-0+ u64 *reg) +{ +struct sys_reg_params params; +const struct sys_reg_desc *r; + +if (is_write) + params.regval =le64_to_cpu (*reg);why do we need this conversion here?
Quoted 1 line
The registers are managed in LE mode. So here the value to be
writtern is coverted to LE mode and similarly on reading back it is converted
from LE.
Quoted 18 lines
+ params.is_write =
is_write;virt/kvm/arm/vgic/vgic-sys-reg-v3.c line 207
Quoted 13 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +13
-0+ params.is_aarch32 = false; + params.is_32bit = false; + + r =find_reg_by_id (id, ¶ms, gic_v3_icc_reg_descs, +ARRAY_SIZE (gic_v3_icc_reg_descs)); +if (!r) +return -ENXIO ; + +if (!r->access (vcpu, ¶ms, r)) +return -EINVAL ; + +if (!is_write) + *reg =cpu_to_le64 (params.regval);same question as above
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Re: [RFC PATCH v3 4/5] arm/arm64: vgic-new: Implement VGICv3 CPU interface access
Resending in plain text mode
Quoted 279 lines · Vijay Kilari
Quoted 45 lines · Christoffer Dall
Quoted 29 lines · On Wed, Aug 24, 2016 at 04:50:08PM +0530, [email protected] wrote:
From: Vijaya Kumar K <[email protected]>
virt/kvm/arm/vgic/vgic-sys-reg-v3.c +0
-0new file mode 100644
index 0000000..581d053virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +14
-0@@ -0,0 +1,211 @@ +#include <linux/irqchip/arm-gic-v3.h> +#include <linux/kvm.h> +#include <linux/kvm_host.h> +#include <kvm/iodev.h> +#include <kvm/arm_vgic.h> +#include <asm/kvm_emulate.h> +#include <asm/kvm_arm.h> +#include <asm/kvm_mmu.h> + +#include "vgic.h" +#include "vgic-mmio.h" +#include "sys_regs.h" + +static bool access_gic_ctlr(struct kvm_vcpu *vcpu, struct
sys_reg_params*p,virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +2
-0+ const struct sys_reg_desc *r) +{virt/kvm/arm/vgic/vgic-sys-reg-v3.c line 26
Quoted 10 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +10
-0+struct vgic_vmcr vmcr; + +vgic_get_vmcr (vcpu, &vmcr); +if (p->is_write) { + vmcr.ctlr = (u32 )p->regval; +vgic_set_vmcr (vcpu, &vmcr); + }else { + p->regval = vmcr.ctlr; + } +really? Have you looked at the spec and implementation of this or did you just copy the v2 code?
Quoted 3 lines
The
ICH_VMCR_EL2register field mappings are not identical to the ctlr mappings. I think this causes some rework for much of this patch, so I'll have a look at the next revision.ICH_VMCR_EL2.VEOIM & ICH_VMCR_EL2.CBPR holds
ICC_CTLR_EL1.EOImode & ICC_CTLR_EL1.CBPR respectively. Remaining fields are Readonly except PHME. AFAIK, vgic is not holdingICC_CTLR_EL1except the fields inICH_VMCR_EL2.Quoted 65 lines
Quoted 65 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +4
-0+return true; +} + +static bool access_gic_pmr(struct kvm_vcpu *vcpu, struct sys_reg_params*p,
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +16
-0+ const struct sys_reg_desc *r) +{ +struct vgic_vmcr vmcr; + +vgic_get_vmcr (vcpu, &vmcr); +if (p->is_write) { + vmcr.pmr = (u32 )p->regval; +vgic_set_vmcr (vcpu, &vmcr); + }else { + p->regval = vmcr.pmr; + } + +return true; +} + +static bool access_gic_bpr0(struct kvm_vcpu *vcpu, struct
sys_reg_params*p,virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +16
-0+ const struct sys_reg_desc *r) +{ +struct vgic_vmcr vmcr; + +vgic_get_vmcr (vcpu, &vmcr); +if (p->is_write) { + vmcr.bpr = (u32 )p->regval; +vgic_set_vmcr (vcpu, &vmcr); + }else { + p->regval = vmcr.bpr; + } + +return true; +} + +static bool access_gic_bpr1(struct kvm_vcpu *vcpu, struct
sys_reg_params*p,virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +16
-0+ const struct sys_reg_desc *r) +{ +struct vgic_vmcr vmcr; + +vgic_get_vmcr (vcpu, &vmcr); +if (p->is_write) { + vmcr.abpr = (u32 )p->regval; +vgic_set_vmcr (vcpu, &vmcr); + }else { + p->regval = vmcr.abpr; + } + +return true; +} + +static bool access_gic_grpen0(struct kvm_vcpu *vcpu, struct
sys_reg_params*p,virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +7
-0+ const struct sys_reg_desc *r) +{ +struct vgic_v3_cpu_if *vgicv3 = &vcpu->arch.vgic_cpu.vgic_v3; + +if (p->is_write) { + vgicv3->vgic_vmcr &= ~ICH_VMCR_ENG0 ; + vgicv3->vgic_vmcr |= (p->regval << ICH_VMCR_ENG0_SHIFT) &Quoted 8 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c line 90
Quoted 5 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +5
-0+ICH_VMCR_ENG0 ; + }else { + p->regval = (vgicv3->vgic_vmcr &ICH_VMCR_ENG0 ) >> +ICH_VMCR_ENG0_SHIFT ; + }so for example, why shouldn't these go through the vgic_set/get_vmcr wrappers?
The
vgic_vmcrstruct as below is not managing ENG0 and ENG1 fields. So could not use vgic_set/get wrappers.struct vgic_vmcr { u32 ctlr; u32 abpr; u32 bpr; u32 pmr; };Quoted 77 lines
Quoted 77 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +5
-0+ +return true; +} + +static bool access_gic_grpen1(struct kvm_vcpu *vcpu, struct
sys_reg_params*p,virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +17
-0+ const struct sys_reg_desc *r) +{ +struct vgic_v3_cpu_if *vgicv3 = &vcpu->arch.vgic_cpu.vgic_v3; + +if (p->is_write) { + vgicv3->vgic_vmcr &= ~ICH_VMCR_ENG1 ; + vgicv3->vgic_vmcr |= (p->regval <<ICH_VMCR_ENG1_SHIFT ) & +ICH_VMCR_ENG1 ; + }else { + p->regval = (vgicv3->vgic_vmcr &ICH_VMCR_ENG1 ) >> +ICH_VMCR_ENG1_SHIFT ; + } + +return true; +} + +static bool access_gic_ap0r(struct kvm_vcpu *vcpu, struct
sys_reg_params*p,virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +14
-0+ const struct sys_reg_desc *r) +{ +struct vgic_v3_cpu_if *vgicv3 = &vcpu->arch.vgic_cpu.vgic_v3; +u8 idx = r->Op2 &3 ; + +if (p->is_write) + vgicv3->vgic_ap0r[idx] = p->regval; +else + p->regval = vgicv3->vgic_ap0r[idx]; + +return true; +} + +static bool access_gic_ap1r(struct kvm_vcpu *vcpu, struct
sys_reg_params*p,virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +36
-0+ const struct sys_reg_desc *r) +{ +struct vgic_v3_cpu_if *vgicv3 = &vcpu->arch.vgic_cpu.vgic_v3; +u8 idx = r->Op2 &3 ; + +if (p->is_write) + vgicv3->vgic_ap1r[idx] = p->regval; +else + p->regval = vgicv3->vgic_ap1r[idx]; + +return true; +} + +static const struct sys_reg_desc gic_v3_icc_reg_descs[] = { +/* ICC_PMR_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (4 ),CRm (6 ),Op2 (0 ), access_gic_pmr }, +/* ICC_BPR0_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (8 ),Op2 (3 ), access_gic_bpr0 }, +/* ICC_AP0R0_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (8 ),Op2 (4 ), access_gic_ap0r }, +/* ICC_AP0R1_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (8 ),Op2 (5 ), access_gic_ap0r }, +/* ICC_AP0R2_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (8 ),Op2 (6 ), access_gic_ap0r }, +/* ICC_AP0R3_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (8 ),Op2 (7 ), access_gic_ap0r }, +/* ICC_AP1R0_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (9 ),Op2 (0 ), access_gic_ap1r }, +/* ICC_AP1R1_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (9 ),Op2 (1 ), access_gic_ap1r }, +/* ICC_AP1R2_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (9 ),Op2 (2 ), access_gic_ap1r }, +/* ICC_AP1R3_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (9 ),Op2 (3 ), access_gic_ap1r }, +/* ICC_BPR1_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (12 ),Op2 (3 ), access_gic_bpr1 },Quoted 8 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c line 168
Quoted 6 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +6
-0+/* ICC_CTLR_EL1 */ + { Op0(3), Op1(0), CRn(12), CRm(12), Op2(4), access_gic_ctlr }, +/* ICC_IGRPEN0_EL1 */ + { Op0(3), Op1(0), CRn(12), CRm(12), Op2(6), access_gic_grpen0 }, +/* ICC_GRPEN1_EL1 */ + { Op0(3), Op1(0), CRn(12), CRm(12), Op2(7), access_gic_grpen1 },Do we need to allow userspace to at least read
ICC_SRE_EL1?ICC_SRE_EL1.SRE is enabled at vgic initialization and DIB and FDB are not configured.
So save and restore does not make any effect.Quoted 3 lines
Should we verify that the DIB and FDB fields of that register are written as the system understands them (clear, WI)?
What kind of verification we can do on DIB and FDB by userspace?.
Quoted 15 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c line 193
Quoted 12 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +2
-0+ +int vgic_v3_cpu_sysregs_uaccess(struct kvm_vcpu *vcpu, bool is_write,u64 id,
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +7
-0+ u64 *reg) +{ +struct sys_reg_params params; +const struct sys_reg_desc *r; + +if (is_write) + params.regval =le64_to_cpu (*reg);why do we need this conversion here?
The registers are managed in LE mode. So here the value to be
writtern is coverted to LE mode and similarly on reading back it is converted
from LE.Quoted 17 lines
Quoted 4 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +4
-0+ params.is_write = is_write; + params.is_aarch32 = false; + params.is_32bit = false; +virt/kvm/arm/vgic/vgic-sys-reg-v3.c line 207
Quoted 10 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +10
-0+ r =find_reg_by_id (id, ¶ms, gic_v3_icc_reg_descs, +ARRAY_SIZE (gic_v3_icc_reg_descs)); +if (!r) +return -ENXIO ; + +if (!r->access (vcpu, ¶ms, r)) +return -EINVAL ; + +if (!is_write) + *reg =cpu_to_le64 (params.regval);same question as above
Re: [RFC PATCH v3 4/5] arm/arm64: vgic-new: Implement VGICv3 CPU interface access
Quoted 61 lines · Vijay Kilari
Resending in plain text mode
Quoted 58 lines · Vijay Kilari
Quoted 45 lines · Christoffer Dall
Quoted 29 lines · On Wed, Aug 24, 2016 at 04:50:08PM +0530, [email protected] wrote:
From: Vijaya Kumar K <[email protected]>
virt/kvm/arm/vgic/vgic-sys-reg-v3.c +0
-0new file mode 100644
index 0000000..581d053virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +14
-0@@ -0,0 +1,211 @@ +#include <linux/irqchip/arm-gic-v3.h> +#include <linux/kvm.h> +#include <linux/kvm_host.h> +#include <kvm/iodev.h> +#include <kvm/arm_vgic.h> +#include <asm/kvm_emulate.h> +#include <asm/kvm_arm.h> +#include <asm/kvm_mmu.h> + +#include "vgic.h" +#include "vgic-mmio.h" +#include "sys_regs.h" + +static bool access_gic_ctlr(struct kvm_vcpu *vcpu, struct
sys_reg_params*p,virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +2
-0+ const struct sys_reg_desc *r) +{virt/kvm/arm/vgic/vgic-sys-reg-v3.c line 26
Quoted 10 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +10
-0+struct vgic_vmcr vmcr; + +vgic_get_vmcr (vcpu, &vmcr); +if (p->is_write) { + vmcr.ctlr = (u32 )p->regval; +vgic_set_vmcr (vcpu, &vmcr); + }else { + p->regval = vmcr.ctlr; + } +really? Have you looked at the spec and implementation of this or did you just copy the v2 code?
Quoted 3 lines
The
ICH_VMCR_EL2register field mappings are not identical to the ctlr mappings. I think this causes some rework for much of this patch, so I'll have a look at the next revision.ICH_VMCR_EL2.VEOIM & ICH_VMCR_EL2.CBPR holds
ICC_CTLR_EL1.EOImode & ICC_CTLR_EL1.CBPR respectively. Remaining fields are Readonly except PHME. AFAIK, vgic is not holdingICC_CTLR_EL1except the fields inICH_VMCR_EL2.
This function implements the accessor for ICC_CTLR_EL1 according to your own comment (and the system register encoding).
If you planned on exposing ICH_VMCR_EL2 to userspace, then why did you expose it for the encoding of ICC_CTLR_EL1?
More to the point, you're exposing the *VM's* state of the GIC, not details about the hypervisor implementation.
Quoted 73 lines
Quoted 73 lines
Quoted 71 lines
Quoted 58 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +4
-0+return true; +} + +static bool access_gic_pmr(struct kvm_vcpu *vcpu, struct sys_reg_params*p,
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +16
-0+ const struct sys_reg_desc *r) +{ +struct vgic_vmcr vmcr; + +vgic_get_vmcr (vcpu, &vmcr); +if (p->is_write) { + vmcr.pmr = (u32 )p->regval; +vgic_set_vmcr (vcpu, &vmcr); + }else { + p->regval = vmcr.pmr; + } + +return true; +} + +static bool access_gic_bpr0(struct kvm_vcpu *vcpu, struct
sys_reg_params*p,virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +16
-0+ const struct sys_reg_desc *r) +{ +struct vgic_vmcr vmcr; + +vgic_get_vmcr (vcpu, &vmcr); +if (p->is_write) { + vmcr.bpr = (u32 )p->regval; +vgic_set_vmcr (vcpu, &vmcr); + }else { + p->regval = vmcr.bpr; + } + +return true; +} + +static bool access_gic_bpr1(struct kvm_vcpu *vcpu, struct
sys_reg_params*p,virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +16
-0+ const struct sys_reg_desc *r) +{ +struct vgic_vmcr vmcr; + +vgic_get_vmcr (vcpu, &vmcr); +if (p->is_write) { + vmcr.abpr = (u32 )p->regval; +vgic_set_vmcr (vcpu, &vmcr); + }else { + p->regval = vmcr.abpr; + } + +return true; +} + +static bool access_gic_grpen0(struct kvm_vcpu *vcpu, struct
sys_reg_params*p,virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +2
-0+ const struct sys_reg_desc *r) +{virt/kvm/arm/vgic/vgic-sys-reg-v3.c line 90
Quoted 10 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +10
-0+struct vgic_v3_cpu_if *vgicv3 = &vcpu->arch.vgic_cpu.vgic_v3; + +if (p->is_write) { + vgicv3->vgic_vmcr &= ~ICH_VMCR_ENG0 ; + vgicv3->vgic_vmcr |= (p->regval <<ICH_VMCR_ENG0_SHIFT ) & +ICH_VMCR_ENG0 ; + }else { + p->regval = (vgicv3->vgic_vmcr &ICH_VMCR_ENG0 ) >> +ICH_VMCR_ENG0_SHIFT ; + }so for example, why shouldn't these go through the vgic_set/get_vmcr wrappers?
Quoted 2 lines
Quoted 2 lines
The
vgic_vmcrstruct as below is not managing ENG0 and ENG1 fields. So could not use vgic_set/get wrappers.
eh, but you could expand this structure, right?
It's strange that some things go through access functions, while others do not. If there is a good reason for that, then document that somehow.
Quoted 96 lines
Quoted 96 lines
struct vgic_vmcr { u32 ctlr; u32 abpr; u32 bpr; u32 pmr; };Quoted 85 lines
Quoted 73 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +5
-0+ +return true; +} + +static bool access_gic_grpen1(struct kvm_vcpu *vcpu, struct
sys_reg_params*p,virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +17
-0+ const struct sys_reg_desc *r) +{ +struct vgic_v3_cpu_if *vgicv3 = &vcpu->arch.vgic_cpu.vgic_v3; + +if (p->is_write) { + vgicv3->vgic_vmcr &= ~ICH_VMCR_ENG1 ; + vgicv3->vgic_vmcr |= (p->regval <<ICH_VMCR_ENG1_SHIFT ) & +ICH_VMCR_ENG1 ; + }else { + p->regval = (vgicv3->vgic_vmcr &ICH_VMCR_ENG1 ) >> +ICH_VMCR_ENG1_SHIFT ; + } + +return true; +} + +static bool access_gic_ap0r(struct kvm_vcpu *vcpu, struct
sys_reg_params*p,virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +14
-0+ const struct sys_reg_desc *r) +{ +struct vgic_v3_cpu_if *vgicv3 = &vcpu->arch.vgic_cpu.vgic_v3; +u8 idx = r->Op2 &3 ; + +if (p->is_write) + vgicv3->vgic_ap0r[idx] = p->regval; +else + p->regval = vgicv3->vgic_ap0r[idx]; + +return true; +} + +static bool access_gic_ap1r(struct kvm_vcpu *vcpu, struct
sys_reg_params*p,virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +32
-0+ const struct sys_reg_desc *r) +{ +struct vgic_v3_cpu_if *vgicv3 = &vcpu->arch.vgic_cpu.vgic_v3; +u8 idx = r->Op2 &3 ; + +if (p->is_write) + vgicv3->vgic_ap1r[idx] = p->regval; +else + p->regval = vgicv3->vgic_ap1r[idx]; + +return true; +} + +static const struct sys_reg_desc gic_v3_icc_reg_descs[] = { +/* ICC_PMR_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (4 ),CRm (6 ),Op2 (0 ), access_gic_pmr }, +/* ICC_BPR0_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (8 ),Op2 (3 ), access_gic_bpr0 }, +/* ICC_AP0R0_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (8 ),Op2 (4 ), access_gic_ap0r }, +/* ICC_AP0R1_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (8 ),Op2 (5 ), access_gic_ap0r }, +/* ICC_AP0R2_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (8 ),Op2 (6 ), access_gic_ap0r }, +/* ICC_AP0R3_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (8 ),Op2 (7 ), access_gic_ap0r }, +/* ICC_AP1R0_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (9 ),Op2 (0 ), access_gic_ap1r }, +/* ICC_AP1R1_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (9 ),Op2 (1 ), access_gic_ap1r }, +/* ICC_AP1R2_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (9 ),Op2 (2 ), access_gic_ap1r },virt/kvm/arm/vgic/vgic-sys-reg-v3.c line 168
Quoted 10 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +10
-0+/* ICC_AP1R3_EL1 */ + { Op0(3), Op1(0), CRn(12), CRm(9), Op2(3), access_gic_ap1r }, +/* ICC_BPR1_EL1 */ + { Op0(3), Op1(0), CRn(12), CRm(12), Op2(3), access_gic_bpr1 }, +/* ICC_CTLR_EL1 */ + { Op0(3), Op1(0), CRn(12), CRm(12), Op2(4), access_gic_ctlr }, +/* ICC_IGRPEN0_EL1 */ + { Op0(3), Op1(0), CRn(12), CRm(12), Op2(6), access_gic_grpen0 }, +/* ICC_GRPEN1_EL1 */ + { Op0(3), Op1(0), CRn(12), CRm(12), Op2(7), access_gic_grpen1 },Do we need to allow userspace to at least read
ICC_SRE_EL1?
Quoted 3 lines
Quoted 3 lines
ICC_SRE_EL1.SRE is enabled at vgic initialization and DIB and FDB are not configured.
So save and restore does not make any effect.
I know, but that doesn't mean that userspace shouldn't be able to tell what the result of the vgic initialization was by looking at the register.
So I am looking for slightly better arguments than 'it doesn't seem to matter in practice right now'.
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Should we verify that the DIB and FDB fields of that register are written as the system understands them (clear, WI)?
What kind of verification we can do on DIB and FDB by userspace?.
That userspace tries to write a value as it thinks they should be and the kernel code checks that this corresponds to the underlying hardware.
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c line 193
Quoted 12 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +2
-0+ +int vgic_v3_cpu_sysregs_uaccess(struct kvm_vcpu *vcpu, bool is_write,u64 id,
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +7
-0+ u64 *reg) +{ +struct sys_reg_params params; +const struct sys_reg_desc *r; + +if (is_write) + params.regval =le64_to_cpu (*reg);why do we need this conversion here?
Quoted 1 line
Quoted 1 line
The registers are managed in LE mode.
What do you mean? They are stored as typed values, right? Why is endianness a factor here.
System registers are registers, they do not have an endianness.
Quoted 5 lines
Quoted 5 lines
So here the value to be
writtern is coverted to LE mode and similarly on reading back it is converted
from LE.
I don't understand where you feel the mismatch in endianness comes from?
The reason why we use vgic_data_host_to_mmio_bus() is historic and I think we can actually get rid of that in the uaccess part. (Looking at the symmetry between vgic_uaccess and vgic_mmio_uaccess_{read,write} should tell us that this is completely unnecessary and we can just replace the prototype to take an unsigned long instead of a void * for the val parameter.)
Can you provide an example of how it goes bad if you don't have this conversion?
Thanks,
-Christoffer
Quoted 18 lines
Quoted 18 lines
Quoted 17 lines
Quoted 4 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +4
-0+ params.is_write = is_write; + params.is_aarch32 = false; + params.is_32bit = false; +virt/kvm/arm/vgic/vgic-sys-reg-v3.c line 207
Quoted 10 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +10
-0+ r =find_reg_by_id (id, ¶ms, gic_v3_icc_reg_descs, +ARRAY_SIZE (gic_v3_icc_reg_descs)); +if (!r) +return -ENXIO ; + +if (!r->access (vcpu, ¶ms, r)) +return -EINVAL ; + +if (!is_write) + *reg =cpu_to_le64 (params.regval);same question as above
Re: [RFC PATCH v3 4/5] arm/arm64: vgic-new: Implement VGICv3 CPU interface access
Quoted 63 lines · Christoffer Dall
Quoted 61 lines · Vijay Kilari
Resending in plain text mode
Quoted 58 lines · Vijay Kilari
Quoted 45 lines · Christoffer Dall
Quoted 29 lines · On Wed, Aug 24, 2016 at 04:50:08PM +0530, [email protected] wrote:
From: Vijaya Kumar K <[email protected]>
virt/kvm/arm/vgic/vgic-sys-reg-v3.c +0
-0new file mode 100644
index 0000000..581d053virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +14
-0@@ -0,0 +1,211 @@ +#include <linux/irqchip/arm-gic-v3.h> +#include <linux/kvm.h> +#include <linux/kvm_host.h> +#include <kvm/iodev.h> +#include <kvm/arm_vgic.h> +#include <asm/kvm_emulate.h> +#include <asm/kvm_arm.h> +#include <asm/kvm_mmu.h> + +#include "vgic.h" +#include "vgic-mmio.h" +#include "sys_regs.h" + +static bool access_gic_ctlr(struct kvm_vcpu *vcpu, struct
sys_reg_params*p,virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +2
-0+ const struct sys_reg_desc *r) +{virt/kvm/arm/vgic/vgic-sys-reg-v3.c line 26
Quoted 10 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +10
-0+struct vgic_vmcr vmcr; + +vgic_get_vmcr (vcpu, &vmcr); +if (p->is_write) { + vmcr.ctlr = (u32 )p->regval; +vgic_set_vmcr (vcpu, &vmcr); + }else { + p->regval = vmcr.ctlr; + } +really? Have you looked at the spec and implementation of this or did you just copy the v2 code?
Quoted 3 lines
The
ICH_VMCR_EL2register field mappings are not identical to the ctlr mappings. I think this causes some rework for much of this patch, so I'll have a look at the next revision.ICH_VMCR_EL2.VEOIM & ICH_VMCR_EL2.CBPR holds
ICC_CTLR_EL1.EOImode & ICC_CTLR_EL1.CBPR respectively. Remaining fields are Readonly except PHME. AFAIK, vgic is not holdingICC_CTLR_EL1except the fields inICH_VMCR_EL2.
Quoted 8 lines
This function implements the accessor for
ICC_CTLR_EL1according to your own comment (and the system register encoding).If you planned on exposing
ICH_VMCR_EL2to userspace, then why did you expose it for the encoding ofICC_CTLR_EL1?More to the point, you're exposing the *VM's* state of the GIC, not details about the hypervisor implementation.
ICH_VMCR_EL2 provides virtual access to ICC_CTLR_EL1, PMR_EL1, BPR0_EL1, and few more regs. So access for these registers, we rely on VMCR_EL2. and more over VMCR_EL2 is EL2 register to expose to userspace.
Quoted 74 lines
Quoted 74 lines
Quoted 74 lines
Quoted 72 lines
Quoted 59 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +4
-0+return true; +} + +static bool access_gic_pmr(struct kvm_vcpu *vcpu, struct sys_reg_params*p,
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +16
-0+ const struct sys_reg_desc *r) +{ +struct vgic_vmcr vmcr; + +vgic_get_vmcr (vcpu, &vmcr); +if (p->is_write) { + vmcr.pmr = (u32 )p->regval; +vgic_set_vmcr (vcpu, &vmcr); + }else { + p->regval = vmcr.pmr; + } + +return true; +} + +static bool access_gic_bpr0(struct kvm_vcpu *vcpu, struct
sys_reg_params*p,virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +16
-0+ const struct sys_reg_desc *r) +{ +struct vgic_vmcr vmcr; + +vgic_get_vmcr (vcpu, &vmcr); +if (p->is_write) { + vmcr.bpr = (u32 )p->regval; +vgic_set_vmcr (vcpu, &vmcr); + }else { + p->regval = vmcr.bpr; + } + +return true; +} + +static bool access_gic_bpr1(struct kvm_vcpu *vcpu, struct
sys_reg_params*p,virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +16
-0+ const struct sys_reg_desc *r) +{ +struct vgic_vmcr vmcr; + +vgic_get_vmcr (vcpu, &vmcr); +if (p->is_write) { + vmcr.abpr = (u32 )p->regval; +vgic_set_vmcr (vcpu, &vmcr); + }else { + p->regval = vmcr.abpr; + } + +return true; +} + +static bool access_gic_grpen0(struct kvm_vcpu *vcpu, struct
sys_reg_params*p,virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +2
-0+ const struct sys_reg_desc *r) +{virt/kvm/arm/vgic/vgic-sys-reg-v3.c line 90
Quoted 10 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +10
-0+struct vgic_v3_cpu_if *vgicv3 = &vcpu->arch.vgic_cpu.vgic_v3; + +if (p->is_write) { + vgicv3->vgic_vmcr &= ~ICH_VMCR_ENG0 ; + vgicv3->vgic_vmcr |= (p->regval <<ICH_VMCR_ENG0_SHIFT ) & +ICH_VMCR_ENG0 ; + }else { + p->regval = (vgicv3->vgic_vmcr &ICH_VMCR_ENG0 ) >> +ICH_VMCR_ENG0_SHIFT ; + }so for example, why shouldn't these go through the vgic_set/get_vmcr wrappers?
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
The
vgic_vmcrstruct as below is not managing ENG0 and ENG1 fields. So could not use vgic_set/get wrappers.eh, but you could expand this structure, right?
OK, I will try to expand this structure
Quoted 100 lines
It's strange that some things go through access functions, while others do not. If there is a good reason for that, then document that somehow.
Quoted 96 lines
Quoted 96 lines
struct vgic_vmcr { u32 ctlr; u32 abpr; u32 bpr; u32 pmr; };Quoted 85 lines
Quoted 73 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +5
-0+ +return true; +} + +static bool access_gic_grpen1(struct kvm_vcpu *vcpu, struct
sys_reg_params*p,virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +17
-0+ const struct sys_reg_desc *r) +{ +struct vgic_v3_cpu_if *vgicv3 = &vcpu->arch.vgic_cpu.vgic_v3; + +if (p->is_write) { + vgicv3->vgic_vmcr &= ~ICH_VMCR_ENG1 ; + vgicv3->vgic_vmcr |= (p->regval <<ICH_VMCR_ENG1_SHIFT ) & +ICH_VMCR_ENG1 ; + }else { + p->regval = (vgicv3->vgic_vmcr &ICH_VMCR_ENG1 ) >> +ICH_VMCR_ENG1_SHIFT ; + } + +return true; +} + +static bool access_gic_ap0r(struct kvm_vcpu *vcpu, struct
sys_reg_params*p,virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +14
-0+ const struct sys_reg_desc *r) +{ +struct vgic_v3_cpu_if *vgicv3 = &vcpu->arch.vgic_cpu.vgic_v3; +u8 idx = r->Op2 &3 ; + +if (p->is_write) + vgicv3->vgic_ap0r[idx] = p->regval; +else + p->regval = vgicv3->vgic_ap0r[idx]; + +return true; +} + +static bool access_gic_ap1r(struct kvm_vcpu *vcpu, struct
sys_reg_params*p,virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +32
-0+ const struct sys_reg_desc *r) +{ +struct vgic_v3_cpu_if *vgicv3 = &vcpu->arch.vgic_cpu.vgic_v3; +u8 idx = r->Op2 &3 ; + +if (p->is_write) + vgicv3->vgic_ap1r[idx] = p->regval; +else + p->regval = vgicv3->vgic_ap1r[idx]; + +return true; +} + +static const struct sys_reg_desc gic_v3_icc_reg_descs[] = { +/* ICC_PMR_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (4 ),CRm (6 ),Op2 (0 ), access_gic_pmr }, +/* ICC_BPR0_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (8 ),Op2 (3 ), access_gic_bpr0 }, +/* ICC_AP0R0_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (8 ),Op2 (4 ), access_gic_ap0r }, +/* ICC_AP0R1_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (8 ),Op2 (5 ), access_gic_ap0r }, +/* ICC_AP0R2_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (8 ),Op2 (6 ), access_gic_ap0r }, +/* ICC_AP0R3_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (8 ),Op2 (7 ), access_gic_ap0r }, +/* ICC_AP1R0_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (9 ),Op2 (0 ), access_gic_ap1r }, +/* ICC_AP1R1_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (9 ),Op2 (1 ), access_gic_ap1r }, +/* ICC_AP1R2_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (9 ),Op2 (2 ), access_gic_ap1r },virt/kvm/arm/vgic/vgic-sys-reg-v3.c line 168
Quoted 10 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +10
-0+/* ICC_AP1R3_EL1 */ + { Op0(3), Op1(0), CRn(12), CRm(9), Op2(3), access_gic_ap1r }, +/* ICC_BPR1_EL1 */ + { Op0(3), Op1(0), CRn(12), CRm(12), Op2(3), access_gic_bpr1 }, +/* ICC_CTLR_EL1 */ + { Op0(3), Op1(0), CRn(12), CRm(12), Op2(4), access_gic_ctlr }, +/* ICC_IGRPEN0_EL1 */ + { Op0(3), Op1(0), CRn(12), CRm(12), Op2(6), access_gic_grpen0 }, +/* ICC_GRPEN1_EL1 */ + { Op0(3), Op1(0), CRn(12), CRm(12), Op2(7), access_gic_grpen1 },Do we need to allow userspace to at least read
ICC_SRE_EL1?
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
ICC_SRE_EL1.SRE is enabled at vgic initialization and DIB and FDB are not configured.
So save and restore does not make any effect.I know, but that doesn't mean that userspace shouldn't be able to tell what the result of the vgic initialization was by looking at the register.
Ok, I will save and restore this registers with some verification in userspace.
Quoted 52 lines
So I am looking for slightly better arguments than 'it doesn't seem to matter in practice right now'.
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Should we verify that the DIB and FDB fields of that register are written as the system understands them (clear, WI)?
What kind of verification we can do on DIB and FDB by userspace?.
That userspace tries to write a value as it thinks they should be and the kernel code checks that this corresponds to the underlying hardware.
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c line 193
Quoted 12 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +2
-0+ +int vgic_v3_cpu_sysregs_uaccess(struct kvm_vcpu *vcpu, bool is_write,u64 id,
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +7
-0+ u64 *reg) +{ +struct sys_reg_params params; +const struct sys_reg_desc *r; + +if (is_write) + params.regval =le64_to_cpu (*reg);why do we need this conversion here?
Quoted 1 line
Quoted 1 line
The registers are managed in LE mode.
What do you mean? They are stored as typed values, right? Why is endianness a factor here.
System registers are registers, they do not have an endianness.
Quoted 5 lines
Quoted 5 lines
So here the value to be
writtern is coverted to LE mode and similarly on reading back it is converted
from LE.I don't understand where you feel the mismatch in endianness comes from?
The reason why we use
vgic_data_host_to_mmio_bus()is historic and I think we can actually get rid of that in the uaccess part. (Looking at the symmetry betweenvgic_uaccessand vgic_mmio_uaccess_{read,write} should tell us that this is completely unnecessary and we can just replace the prototype to take an unsigned long instead of a void * for the val parameter.)
Quoted 2 lines
Can you provide an example of how it goes bad if you don't have this conversion?
You have added a comment for vgic_uaccess() that conversion is required from the patch commit c3199f28e09496aa9fec9313b4f6e90e7dc913f0 "KVM: arm/arm64: vgic-new: Export register access interface"
If sysregs does not have endianess, then this conversion can be dropped for sysregs.
Quoted 22 lines
Thanks,
-ChristofferQuoted 18 lines
Quoted 18 lines
Quoted 17 lines
Quoted 4 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +4
-0+ params.is_write = is_write; + params.is_aarch32 = false; + params.is_32bit = false; +virt/kvm/arm/vgic/vgic-sys-reg-v3.c line 207
Quoted 10 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +10
-0+ r =find_reg_by_id (id, ¶ms, gic_v3_icc_reg_descs, +ARRAY_SIZE (gic_v3_icc_reg_descs)); +if (!r) +return -ENXIO ; + +if (!r->access (vcpu, ¶ms, r)) +return -EINVAL ; + +if (!is_write) + *reg =cpu_to_le64 (params.regval);same question as above
Re: [RFC PATCH v3 4/5] arm/arm64: vgic-new: Implement VGICv3 CPU interface access
Quoted 68 lines · Vijay Kilari
Quoted 66 lines · Christoffer Dall
Quoted 61 lines · Vijay Kilari
Resending in plain text mode
Quoted 58 lines · Vijay Kilari
Quoted 45 lines · Christoffer Dall
Quoted 29 lines · On Wed, Aug 24, 2016 at 04:50:08PM +0530, [email protected] wrote:
From: Vijaya Kumar K <[email protected]>
virt/kvm/arm/vgic/vgic-sys-reg-v3.c +0
-0new file mode 100644
index 0000000..581d053virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +14
-0@@ -0,0 +1,211 @@ +#include <linux/irqchip/arm-gic-v3.h> +#include <linux/kvm.h> +#include <linux/kvm_host.h> +#include <kvm/iodev.h> +#include <kvm/arm_vgic.h> +#include <asm/kvm_emulate.h> +#include <asm/kvm_arm.h> +#include <asm/kvm_mmu.h> + +#include "vgic.h" +#include "vgic-mmio.h" +#include "sys_regs.h" + +static bool access_gic_ctlr(struct kvm_vcpu *vcpu, struct
sys_reg_params*p,virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +2
-0+ const struct sys_reg_desc *r) +{virt/kvm/arm/vgic/vgic-sys-reg-v3.c line 26
Quoted 10 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +10
-0+struct vgic_vmcr vmcr; + +vgic_get_vmcr (vcpu, &vmcr); +if (p->is_write) { + vmcr.ctlr = (u32 )p->regval; +vgic_set_vmcr (vcpu, &vmcr); + }else { + p->regval = vmcr.ctlr; + } +really? Have you looked at the spec and implementation of this or did you just copy the v2 code?
Quoted 3 lines
The
ICH_VMCR_EL2register field mappings are not identical to the ctlr mappings. I think this causes some rework for much of this patch, so I'll have a look at the next revision.ICH_VMCR_EL2.VEOIM & ICH_VMCR_EL2.CBPR holds
ICC_CTLR_EL1.EOImode & ICC_CTLR_EL1.CBPR respectively. Remaining fields are Readonly except PHME. AFAIK, vgic is not holdingICC_CTLR_EL1except the fields inICH_VMCR_EL2.This function implements the accessor for
ICC_CTLR_EL1according to your own comment (and the system register encoding).
Quoted 8 lines
Quoted 5 lines
If you planned on exposing
ICH_VMCR_EL2to userspace, then why did you expose it for the encoding ofICC_CTLR_EL1?More to the point, you're exposing the *VM's* state of the GIC, not details about the hypervisor implementation.
ICH_VMCR_EL2provides virtual access toICC_CTLR_EL1,PMR_EL1,BPR0_EL1, and few more regs. So access for these registers, we rely onVMCR_EL2.
I know how this works, I'm not asking you to explain me how VMCR_EL2 works.
Quoted 2 lines
and more over
VMCR_EL2is EL2 register to expose to userspace.
If you wanted to go that route, you shouldn't export it using the encoding of ICC_CTRL_EL1, then you should export it using VMCR_EL2.
But this is now what we do for all the other state, so it's fairly obvious to me what you need to do. But let me spell it out for you:
Export the VM's state in shape of the EL1 registers as they are presented to the guest, similar to what we do for the distributor with the exception of the latch state for the pending state.
You have failed to explain the design of what you are implementing, and what you have here is wildly inconsistent. Please try to understand what I'm saying instead of just insisting on your original understanding of how to solve this problem.
Quoted 183 lines
Quoted 74 lines
Quoted 74 lines
Quoted 74 lines
Quoted 72 lines
Quoted 59 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +4
-0+return true; +} + +static bool access_gic_pmr(struct kvm_vcpu *vcpu, struct sys_reg_params*p,
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +16
-0+ const struct sys_reg_desc *r) +{ +struct vgic_vmcr vmcr; + +vgic_get_vmcr (vcpu, &vmcr); +if (p->is_write) { + vmcr.pmr = (u32 )p->regval; +vgic_set_vmcr (vcpu, &vmcr); + }else { + p->regval = vmcr.pmr; + } + +return true; +} + +static bool access_gic_bpr0(struct kvm_vcpu *vcpu, struct
sys_reg_params*p,virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +16
-0+ const struct sys_reg_desc *r) +{ +struct vgic_vmcr vmcr; + +vgic_get_vmcr (vcpu, &vmcr); +if (p->is_write) { + vmcr.bpr = (u32 )p->regval; +vgic_set_vmcr (vcpu, &vmcr); + }else { + p->regval = vmcr.bpr; + } + +return true; +} + +static bool access_gic_bpr1(struct kvm_vcpu *vcpu, struct
sys_reg_params*p,virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +16
-0+ const struct sys_reg_desc *r) +{ +struct vgic_vmcr vmcr; + +vgic_get_vmcr (vcpu, &vmcr); +if (p->is_write) { + vmcr.abpr = (u32 )p->regval; +vgic_set_vmcr (vcpu, &vmcr); + }else { + p->regval = vmcr.abpr; + } + +return true; +} + +static bool access_gic_grpen0(struct kvm_vcpu *vcpu, struct
sys_reg_params*p,virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +2
-0+ const struct sys_reg_desc *r) +{virt/kvm/arm/vgic/vgic-sys-reg-v3.c line 90
Quoted 10 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +10
-0+struct vgic_v3_cpu_if *vgicv3 = &vcpu->arch.vgic_cpu.vgic_v3; + +if (p->is_write) { + vgicv3->vgic_vmcr &= ~ICH_VMCR_ENG0 ; + vgicv3->vgic_vmcr |= (p->regval <<ICH_VMCR_ENG0_SHIFT ) & +ICH_VMCR_ENG0 ; + }else { + p->regval = (vgicv3->vgic_vmcr &ICH_VMCR_ENG0 ) >> +ICH_VMCR_ENG0_SHIFT ; + }so for example, why shouldn't these go through the vgic_set/get_vmcr wrappers?
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
The
vgic_vmcrstruct as below is not managing ENG0 and ENG1 fields. So could not use vgic_set/get wrappers.eh, but you could expand this structure, right?
OK, I will try to expand this structure
Quoted 104 lines
It's strange that some things go through access functions, while others do not. If there is a good reason for that, then document that somehow.
Quoted 99 lines
Quoted 99 lines
struct vgic_vmcr { u32 ctlr; u32 abpr; u32 bpr; u32 pmr; };Quoted 77 lines
Quoted 77 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +5
-0+ +return true; +} + +static bool access_gic_grpen1(struct kvm_vcpu *vcpu, struct
sys_reg_params*p,virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +17
-0+ const struct sys_reg_desc *r) +{ +struct vgic_v3_cpu_if *vgicv3 = &vcpu->arch.vgic_cpu.vgic_v3; + +if (p->is_write) { + vgicv3->vgic_vmcr &= ~ICH_VMCR_ENG1 ; + vgicv3->vgic_vmcr |= (p->regval <<ICH_VMCR_ENG1_SHIFT ) & +ICH_VMCR_ENG1 ; + }else { + p->regval = (vgicv3->vgic_vmcr &ICH_VMCR_ENG1 ) >> +ICH_VMCR_ENG1_SHIFT ; + } + +return true; +} + +static bool access_gic_ap0r(struct kvm_vcpu *vcpu, struct
sys_reg_params*p,virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +14
-0+ const struct sys_reg_desc *r) +{ +struct vgic_v3_cpu_if *vgicv3 = &vcpu->arch.vgic_cpu.vgic_v3; +u8 idx = r->Op2 &3 ; + +if (p->is_write) + vgicv3->vgic_ap0r[idx] = p->regval; +else + p->regval = vgicv3->vgic_ap0r[idx]; + +return true; +} + +static bool access_gic_ap1r(struct kvm_vcpu *vcpu, struct
sys_reg_params*p,virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +36
-0+ const struct sys_reg_desc *r) +{ +struct vgic_v3_cpu_if *vgicv3 = &vcpu->arch.vgic_cpu.vgic_v3; +u8 idx = r->Op2 &3 ; + +if (p->is_write) + vgicv3->vgic_ap1r[idx] = p->regval; +else + p->regval = vgicv3->vgic_ap1r[idx]; + +return true; +} + +static const struct sys_reg_desc gic_v3_icc_reg_descs[] = { +/* ICC_PMR_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (4 ),CRm (6 ),Op2 (0 ), access_gic_pmr }, +/* ICC_BPR0_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (8 ),Op2 (3 ), access_gic_bpr0 }, +/* ICC_AP0R0_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (8 ),Op2 (4 ), access_gic_ap0r }, +/* ICC_AP0R1_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (8 ),Op2 (5 ), access_gic_ap0r }, +/* ICC_AP0R2_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (8 ),Op2 (6 ), access_gic_ap0r }, +/* ICC_AP0R3_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (8 ),Op2 (7 ), access_gic_ap0r }, +/* ICC_AP1R0_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (9 ),Op2 (0 ), access_gic_ap1r }, +/* ICC_AP1R1_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (9 ),Op2 (1 ), access_gic_ap1r }, +/* ICC_AP1R2_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (9 ),Op2 (2 ), access_gic_ap1r }, +/* ICC_AP1R3_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (9 ),Op2 (3 ), access_gic_ap1r }, +/* ICC_BPR1_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (12 ),Op2 (3 ), access_gic_bpr1 },Quoted 8 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c line 168
Quoted 6 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +6
-0+/* ICC_CTLR_EL1 */ + { Op0(3), Op1(0), CRn(12), CRm(12), Op2(4), access_gic_ctlr }, +/* ICC_IGRPEN0_EL1 */ + { Op0(3), Op1(0), CRn(12), CRm(12), Op2(6), access_gic_grpen0 }, +/* ICC_GRPEN1_EL1 */ + { Op0(3), Op1(0), CRn(12), CRm(12), Op2(7), access_gic_grpen1 },Do we need to allow userspace to at least read
ICC_SRE_EL1?ICC_SRE_EL1.SRE is enabled at vgic initialization and DIB and FDB are not configured.
So save and restore does not make any effect.
Quoted 7 lines
Quoted 4 lines
I know, but that doesn't mean that userspace shouldn't be able to tell what the result of the vgic initialization was by looking at the register.
Ok, I will save and restore this registers with some verification in userspace.
My point was that the kernel could verify that the systems are consistent, similar to what we do for invariant sysregs.
Quoted 52 lines
Quoted 52 lines
So I am looking for slightly better arguments than 'it doesn't seem to matter in practice right now'.
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Should we verify that the DIB and FDB fields of that register are written as the system understands them (clear, WI)?
What kind of verification we can do on DIB and FDB by userspace?.
That userspace tries to write a value as it thinks they should be and the kernel code checks that this corresponds to the underlying hardware.
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c line 193
Quoted 12 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +2
-0+ +int vgic_v3_cpu_sysregs_uaccess(struct kvm_vcpu *vcpu, bool is_write,u64 id,
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +7
-0+ u64 *reg) +{ +struct sys_reg_params params; +const struct sys_reg_desc *r; + +if (is_write) + params.regval =le64_to_cpu (*reg);why do we need this conversion here?
Quoted 1 line
Quoted 1 line
The registers are managed in LE mode.
What do you mean? They are stored as typed values, right? Why is endianness a factor here.
System registers are registers, they do not have an endianness.
Quoted 5 lines
Quoted 5 lines
So here the value to be
writtern is coverted to LE mode and similarly on reading back it is converted
from LE.I don't understand where you feel the mismatch in endianness comes from?
The reason why we use
vgic_data_host_to_mmio_bus()is historic and I think we can actually get rid of that in the uaccess part. (Looking at the symmetry betweenvgic_uaccessand vgic_mmio_uaccess_{read,write} should tell us that this is completely unnecessary and we can just replace the prototype to take an unsigned long instead of a void * for the val parameter.)
Quoted 6 lines
Quoted 2 lines
Can you provide an example of how it goes bad if you don't have this conversion?
You have added a comment for
vgic_uaccess()that conversion is required from the patch commitc3199f28e09496aa9fec9313b4f6e90e7dc913f0"KVM: arm/arm64: vgic-new: Export register access interface"
Again, I didn't ask you to quote a commit, but to actually understand what you are implementing.
I've already stated that I do not see a need for the endianness conversion here, yet you persist that it is needed. To substantiate your claim, I asked to provide an example of a situation where we would write the wrong value to the kernel without the le64_to_cpu operation, not to quote a commit on a different function, which uses an existing function to conveniently place date into a byte array.
As I told you, this was needed *before your patches* because we reused dispatch_mmio_write, but now you do the region lookup in vgic_mmio_uaccess_write() and do not reuse the mmio path that expected a void * to a byte array.
Quoted 4 lines
If sysregs does not have endianess, then this conversion can be dropped for sysregs.
As I've said, I don't see where there would be an endianness mismatch here.
-Christoffer
Re: [RFC PATCH v3 4/5] arm/arm64: vgic-new: Implement VGICv3 CPU interface access
In reply to [email protected]Quoted 402 lines · On Wed, Aug 24, 2016 at 04:50:08PM +0530, [email protected] wrote:
From: Vijaya Kumar K <[email protected]>
VGICv3 CPU interface registers are accessed using
KVM_DEV_ARM_VGIC_CPU_SYSREGSioctl. These registers are accessed as 64-bit. The cpu MPIDR value is passed along with register id. is used to identify the cpu for registers access.The version of VGIC v3 specification is define here
http://lists.infradead.org/pipermail/linux-arm-kernel/2016-July/445611.htmlSigned-off-by Pavel Fedin <[email protected]>Signed-off-by Vijaya Kumar K <[email protected]>--- arch/arm64/include/uapi/asm/kvm.h | 15 ++- arch/arm64/kvm/Makefile | 1 + include/linux/irqchip/arm-gic-v3.h | 4 + virt/kvm/arm/vgic/vgic-kvm-device.c | 29 +++++ virt/kvm/arm/vgic/vgic-mmio-v2.c | 4 +- virt/kvm/arm/vgic/vgic-mmio-v3.c | 6 + virt/kvm/arm/vgic/vgic-sys-reg-v3.c | 211 ++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic.h | 6 + 8 files changed, 271 insertions(+), 5 deletions(-)arch/arm64/include/uapi/asm/kvm.h +12
-3@@ -182,14 +182,14 @@ struct kvm_arch_memory_slot { KVM_REG_ARM64_SYSREG_ ## n ## _MASK)#define __ARM64_SYS_REG (op0,op1,crn,crm,op2) \ - (KVM_REG_ARM64 | KVM_REG_ARM64_SYSREG | \ - ARM64_SYS_REG_SHIFT_MASK(op0, OP0) | \ + (ARM64_SYS_REG_SHIFT_MASK(op0, OP0) | \ ARM64_SYS_REG_SHIFT_MASK(op1, OP1) | \ ARM64_SYS_REG_SHIFT_MASK(crn, CRN) | \ ARM64_SYS_REG_SHIFT_MASK(crm, CRM) | \ ARM64_SYS_REG_SHIFT_MASK(op2, OP2)) -#define ARM64_SYS_REG (...) (__ARM64_SYS_REG(__VA_ARGS__) | KVM_REG_SIZE_U64) +#define ARM64_SYS_REG (...) (__ARM64_SYS_REG(__VA_ARGS__) | KVM_REG_SIZE_U64 | \ + KVM_REG_ARM64 | KVM_REG_ARM64_SYSREG)#define KVM_REG_ARM_TIMER_CTL ARM64_SYS_REG(3, 3, 14, 3, 1)#define KVM_REG_ARM_TIMER_CNT ARM64_SYS_REG(3, 3, 14, 3, 2)@@ -208,7 +208,16 @@ struct kvm_arch_memory_slot {#define KVM_DEV_ARM_VGIC_GRP_NR_IRQS 3#define KVM_DEV_ARM_VGIC_GRP_CTRL 4#define KVM_DEV_ARM_VGIC_GRP_REDIST_REGS 5 +#define KVM_DEV_ARM_VGIC_CPU_SYSREGS 6 +#define KVM_DEV_ARM_VGIC_CTRL_INIT 0 +#define KVM_DEV_ARM_VGIC_SYSREG_MASK (KVM_REG_ARM64_SYSREG_OP0_MASK | \ + KVM_REG_ARM64_SYSREG_OP1_MASK | \ + KVM_REG_ARM64_SYSREG_CRN_MASK | \ + KVM_REG_ARM64_SYSREG_CRM_MASK | \ + KVM_REG_ARM64_SYSREG_OP2_MASK) +#define KVM_DEV_ARM_VGIC_SYSREG (op0, op1, crn, crm, op2) \ + __ARM64_SYS_REG(op0, op1, crn, crm, op2)/* Device Control API on vcpu fd */ #define KVM_ARM_VCPU_PMU_V3_CTRL 0arch/arm64/kvm/Makefile +1
-0@@ -31,5 +31,6 @@ kvm-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/vgic/vgic-mmio-v3.o kvm-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/vgic/vgic-kvm-device.o kvm-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/vgic/vgic-its.o kvm-$(CONFIG_KVM_ARM_HOST) += $(KVM)/irqchip.o +kvm-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/vgic/vgic-sys-reg-v3.o kvm-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/arch_timer.o kvm-$(CONFIG_KVM_ARM_PMU) += $(KVM)/arm/pmu.oinclude/linux/irqchip/arm-gic-v3.h +4
-0@@ -383,6 +383,10 @@#define ICH_VMCR_CTLR_SHIFT 0#define ICH_VMCR_CTLR_MASK (0x21f << ICH_VMCR_CTLR_SHIFT) +#define ICH_VMCR_ENG0_SHIFT 0 +#define ICH_VMCR_ENG0 (1 << ICH_VMCR_ENG0_SHIFT) +#define ICH_VMCR_ENG1_SHIFT 1 +#define ICH_VMCR_ENG1 (1 << ICH_VMCR_ENG1_SHIFT)#define ICH_VMCR_BPR1_SHIFT 18#define ICH_VMCR_BPR1_MASK (7 << ICH_VMCR_BPR1_SHIFT)#define ICH_VMCR_BPR0_SHIFT 21virt/kvm/arm/vgic/vgic-kvm-device.c +29
-0@@ -500,6 +500,15 @@ static int vgic_attr_regs_access_v3(struct kvm_device *dev,if (!is_write) *reg = tmp32;break ; +case KVM_DEV_ARM_VGIC_CPU_SYSREGS : { +u64 regid; + + regid = (attr->attr &KVM_DEV_ARM_VGIC_SYSREG_MASK ) | +KVM_REG_SIZE_U64 ; + ret =vgic_v3_cpu_sysregs_uaccess (vcpu, is_write, + regid, reg); +break ; + }default : ret = -EINVAL ;break ;@@ -533,6 +542,15 @@ static int vgic_v3_set_attr(struct kvm_device *dev, reg = tmp32;return vgic_attr_regs_access_v3 (dev, attr, ®, true); } +case KVM_DEV_ARM_VGIC_CPU_SYSREGS : { +u64 __user *uaddr = (u64 __user *)(long )attr->addr; +u64 reg; + +if (get_user (reg, uaddr)) +return -EFAULT ; + +return vgic_attr_regs_access_v3 (dev, attr, ®, true); + } }return -ENXIO ; }@@ -560,6 +578,16 @@ static int vgic_v3_get_attr(struct kvm_device *dev, ret =put_user (tmp32, uaddr);return ret; } +case KVM_DEV_ARM_VGIC_CPU_SYSREGS : { +u64 __user *uaddr = (u64 __user *)(long )attr->addr; +u64 reg; + + ret =vgic_attr_regs_access_v3 (dev, attr, ®, false); +if (ret) +return ret; + ret =put_user (reg, uaddr); +return ret; + } }return -ENXIO ;@@ -578,6 +606,7 @@ static int vgic_v3_has_attr(struct kvm_device *dev,break ;case KVM_DEV_ARM_VGIC_GRP_DIST_REGS :case KVM_DEV_ARM_VGIC_GRP_REDIST_REGS : +case KVM_DEV_ARM_VGIC_CPU_SYSREGS :return vgic_v3_has_attr_regs (dev, attr);case KVM_DEV_ARM_VGIC_GRP_NR_IRQS :return 0 ;virt/kvm/arm/vgic/vgic-mmio-v2.c +2
-2@@ -212,7 +212,7 @@ static void vgic_mmio_write_sgipends(struct kvm_vcpu *vcpu, } } -static void vgic_set_vmcr (struct kvm_vcpu *vcpu,struct vgic_vmcr *vmcr) +void vgic_set_vmcr (struct kvm_vcpu *vcpu,struct vgic_vmcr *vmcr) {if (kvm_vgic_global_state.type ==VGIC_V2 )vgic_v2_set_vmcr (vcpu, vmcr);@@ -220,7 +220,7 @@ static void vgic_set_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcr)vgic_v3_set_vmcr (vcpu, vmcr); } -static void vgic_get_vmcr (struct kvm_vcpu *vcpu,struct vgic_vmcr *vmcr) +void vgic_get_vmcr (struct kvm_vcpu *vcpu,struct vgic_vmcr *vmcr) {if (kvm_vgic_global_state.type ==VGIC_V2 )vgic_v2_get_vmcr (vcpu, vmcr);virt/kvm/arm/vgic/vgic-mmio-v3.c +6
-0@@ -23,6 +23,7 @@#include "vgic.h" #include "vgic-mmio.h" +#include "sys_regs.h" /* extract @num bytes at @offset bytes offset in data */ unsigned long extract_bytes(unsigned long data, unsigned int offset,@@ -598,6 +599,11 @@ int vgic_v3_has_attr_regs(struct kvm_device *dev, struct kvm_device_attr *attr) nr_regions =ARRAY_SIZE (vgic_v3_rdbase_registers);break ; } +case KVM_DEV_ARM_VGIC_CPU_SYSREGS : { +u64 reg; + +return vgic_v3_has_cpu_sysregs_attr (vcpu,0 , cpuid, ®); + }default :return -ENXIO ; }virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +201
-0@@ -0,0 +1,211 @@ +#include <linux/irqchip/arm-gic-v3.h> +#include <linux/kvm.h> +#include <linux/kvm_host.h> +#include <kvm/iodev.h> +#include <kvm/arm_vgic.h> +#include <asm/kvm_emulate.h> +#include <asm/kvm_arm.h> +#include <asm/kvm_mmu.h> + +#include "vgic.h" +#include "vgic-mmio.h" +#include "sys_regs.h" + +static bool access_gic_ctlr (struct kvm_vcpu *vcpu,struct sys_reg_params *p, +const struct sys_reg_desc *r) +{ +struct vgic_vmcr vmcr; + +vgic_get_vmcr (vcpu, &vmcr); +if (p->is_write) { + vmcr.ctlr = (u32 )p->regval; +vgic_set_vmcr (vcpu, &vmcr); + }else { + p->regval = vmcr.ctlr; + } + +return true; +} + +static bool access_gic_pmr (struct kvm_vcpu *vcpu,struct sys_reg_params *p, +const struct sys_reg_desc *r) +{ +struct vgic_vmcr vmcr; + +vgic_get_vmcr (vcpu, &vmcr); +if (p->is_write) { + vmcr.pmr = (u32 )p->regval; +vgic_set_vmcr (vcpu, &vmcr); + }else { + p->regval = vmcr.pmr; + } + +return true; +} + +static bool access_gic_bpr0 (struct kvm_vcpu *vcpu,struct sys_reg_params *p, +const struct sys_reg_desc *r) +{ +struct vgic_vmcr vmcr; + +vgic_get_vmcr (vcpu, &vmcr); +if (p->is_write) { + vmcr.bpr = (u32 )p->regval; +vgic_set_vmcr (vcpu, &vmcr); + }else { + p->regval = vmcr.bpr; + } + +return true; +} + +static bool access_gic_bpr1 (struct kvm_vcpu *vcpu,struct sys_reg_params *p, +const struct sys_reg_desc *r) +{ +struct vgic_vmcr vmcr; + +vgic_get_vmcr (vcpu, &vmcr); +if (p->is_write) { + vmcr.abpr = (u32 )p->regval; +vgic_set_vmcr (vcpu, &vmcr); + }else { + p->regval = vmcr.abpr; + } + +return true; +} + +static bool access_gic_grpen0 (struct kvm_vcpu *vcpu,struct sys_reg_params *p, +const struct sys_reg_desc *r) +{ +struct vgic_v3_cpu_if *vgicv3 = &vcpu->arch.vgic_cpu.vgic_v3; + +if (p->is_write) { + vgicv3->vgic_vmcr &= ~ICH_VMCR_ENG0 ; + vgicv3->vgic_vmcr |= (p->regval <<ICH_VMCR_ENG0_SHIFT ) & +ICH_VMCR_ENG0 ; + }else { + p->regval = (vgicv3->vgic_vmcr &ICH_VMCR_ENG0 ) >> +ICH_VMCR_ENG0_SHIFT ; + } + +return true; +} + +static bool access_gic_grpen1 (struct kvm_vcpu *vcpu,struct sys_reg_params *p, +const struct sys_reg_desc *r) +{ +struct vgic_v3_cpu_if *vgicv3 = &vcpu->arch.vgic_cpu.vgic_v3; + +if (p->is_write) { + vgicv3->vgic_vmcr &= ~ICH_VMCR_ENG1 ; + vgicv3->vgic_vmcr |= (p->regval <<ICH_VMCR_ENG1_SHIFT ) & +ICH_VMCR_ENG1 ; + }else { + p->regval = (vgicv3->vgic_vmcr &ICH_VMCR_ENG1 ) >> +ICH_VMCR_ENG1_SHIFT ; + } + +return true; +} + +static bool access_gic_ap0r (struct kvm_vcpu *vcpu,struct sys_reg_params *p, +const struct sys_reg_desc *r) +{ +struct vgic_v3_cpu_if *vgicv3 = &vcpu->arch.vgic_cpu.vgic_v3; +u8 idx = r->Op2 &3 ; + +if (p->is_write) + vgicv3->vgic_ap0r[idx] = p->regval; +else + p->regval = vgicv3->vgic_ap0r[idx]; + +return true; +} + +static bool access_gic_ap1r (struct kvm_vcpu *vcpu,struct sys_reg_params *p, +const struct sys_reg_desc *r) +{ +struct vgic_v3_cpu_if *vgicv3 = &vcpu->arch.vgic_cpu.vgic_v3; +u8 idx = r->Op2 &3 ; + +if (p->is_write) + vgicv3->vgic_ap1r[idx] = p->regval; +else + p->regval = vgicv3->vgic_ap1r[idx]; + +return true; +} + +static const struct sys_reg_desc gic_v3_icc_reg_descs[] = { +/* ICC_PMR_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (4 ),CRm (6 ),Op2 (0 ), access_gic_pmr }, +/* ICC_BPR0_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (8 ),Op2 (3 ), access_gic_bpr0 }, +/* ICC_AP0R0_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (8 ),Op2 (4 ), access_gic_ap0r }, +/* ICC_AP0R1_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (8 ),Op2 (5 ), access_gic_ap0r }, +/* ICC_AP0R2_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (8 ),Op2 (6 ), access_gic_ap0r }, +/* ICC_AP0R3_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (8 ),Op2 (7 ), access_gic_ap0r }, +/* ICC_AP1R0_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (9 ),Op2 (0 ), access_gic_ap1r }, +/* ICC_AP1R1_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (9 ),Op2 (1 ), access_gic_ap1r }, +/* ICC_AP1R2_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (9 ),Op2 (2 ), access_gic_ap1r }, +/* ICC_AP1R3_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (9 ),Op2 (3 ), access_gic_ap1r }, +/* ICC_BPR1_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (12 ),Op2 (3 ), access_gic_bpr1 }, +/* ICC_CTLR_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (12 ),Op2 (4 ), access_gic_ctlr }, +/* ICC_IGRPEN0_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (12 ),Op2 (6 ), access_gic_grpen0 }, +/* ICC_GRPEN1_EL1 */ + {Op0 (3 ),Op1 (0 ),CRn (12 ),CRm (12 ),Op2 (7 ), access_gic_grpen1 }, +}; + +int vgic_v3_has_cpu_sysregs_attr (struct kvm_vcpu *vcpu,bool is_write,u64 id, +u64 *reg) +{ +struct sys_reg_params params; + + params.regval =le64_to_cpu (*reg); + params.is_write = is_write; + params.is_aarch32 = false; + params.is_32bit = false; + +return find_reg_by_id (id, ¶ms, gic_v3_icc_reg_descs, +ARRAY_SIZE (gic_v3_icc_reg_descs)) ? +0 : -ENXIO ; +} + +int vgic_v3_cpu_sysregs_uaccess (struct kvm_vcpu *vcpu,bool is_write,u64 id, +u64 *reg) +{ +struct sys_reg_params params; +const struct sys_reg_desc *r; + +if (is_write) + params.regval =le64_to_cpu (*reg); + params.is_write = is_write; + params.is_aarch32 = false; + params.is_32bit = false; + + r =find_reg_by_id (id, ¶ms, gic_v3_icc_reg_descs, +ARRAY_SIZE (gic_v3_icc_reg_descs)); +if (!r) +return -ENXIO ;
virt/kvm/arm/vgic/vgic-sys-reg-v3.c line 211
Quoted 10 lines
virt/kvm/arm/vgic/vgic-sys-reg-v3.c new file +10
-0+ +if (!r->access (vcpu, ¶ms, r)) +return -EINVAL ; + +if (!is_write) + *reg =cpu_to_le64 (params.regval); + +return 0 ; +} +
Btw. I get a warning about this stray white space line at the end of the file here when applying these patches.
Thanks,
-Christoffer
Quoted 27 lines
virt/kvm/arm/vgic/vgic.h +6
-0@@ -96,6 +96,10 @@ int vgic_v3_dist_uaccess(struct kvm_vcpu *vcpu, bool is_write, int offset, u32 *val);int vgic_v3_redist_uaccess (struct kvm_vcpu *vcpu,bool is_write,int offset,u32 *val); +int vgic_v3_cpu_sysregs_uaccess (struct kvm_vcpu *vcpu,bool is_write, +u64 id,u64 *val); +int vgic_v3_has_cpu_sysregs_attr (struct kvm_vcpu *vcpu,bool is_write,u64 id, +u64 *reg);#else static inline void vgic_v3_process_maintenance (struct kvm_vcpu *vcpu) {@@ -169,6 +173,8 @@ static inline int vgic_its_inject_msi(struct kvm *kvm, struct kvm_msi *msi)#endif int kvm_register_vgic_device (unsigned long type); +void vgic_set_vmcr (struct kvm_vcpu *vcpu,struct vgic_vmcr *vmcr); +void vgic_get_vmcr (struct kvm_vcpu *vcpu,struct vgic_vmcr *vmcr);int vgic_lazy_init (struct kvm *kvm);int vgic_init (struct kvm *kvm);Signature · 1 line
1.9.1
RFC PATCH v3 5/5 arm/arm64: vgic-new: Implement KVM_DEV_ARM_VGIC_GRP_LEVEL_INFO ioctl
In reply to [email protected]From: Vijaya Kumar K <[email protected]>
Userspace requires to store and restore of line_level for level triggered interrupts. For this ioctl KVM_DEV_ARM_VGIC_GRP_LEVEL_INFO is defined.
--- arch/arm64/include/uapi/asm/kvm.h | 6 +++++ virt/kvm/arm/vgic/vgic-kvm-device.c | 44 ++++++++++++++++++++++++++++++++++++- virt/kvm/arm/vgic/vgic-mmio-v3.c | 19 ++++++++++++++++ virt/kvm/arm/vgic/vgic-mmio.c | 34 ++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic-mmio.h | 6 +++++ virt/kvm/arm/vgic/vgic.h | 3 +++ 6 files changed, 111 insertions(+), 1 deletion(-)
arch/arm64/include/uapi/asm/kvm.h +6 -0
@@ -209,6 +209,12 @@ struct kvm_arch_memory_slot {#define KVM_DEV_ARM_VGIC_GRP_CTRL 4#define KVM_DEV_ARM_VGIC_GRP_REDIST_REGS 5#define KVM_DEV_ARM_VGIC_CPU_SYSREGS 6 +#define KVM_DEV_ARM_VGIC_GRP_LEVEL_INFO 7 +#define KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_SHIFT 9 +#define KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_MASK \ + (0x7fffffULL << KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_SHIFT) +#define KVM_DEV_ARM_VGIC_LINE_LEVEL_INTID_MASK 0x1ff +#define KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_VAL 1#define KVM_DEV_ARM_VGIC_CTRL_INIT 0#define KVM_DEV_ARM_VGIC_SYSREG_MASK (KVM_REG_ARM64_SYSREG_OP0_MASK | \
virt/kvm/arm/vgic/vgic-kvm-device.c +43 -1
74 lines not on this page · raw message
virt/kvm/arm/vgic/vgic-mmio-v3.c +19 -0
@@ -789,3 +789,22 @@ int vgic_v3_redist_uaccess(struct kvm_vcpu *vcpu, bool is_write,return vgic_v3_uaccess (vcpu, dev, is_write, offset, val); } + +int vgic_v3_line_level_info_uaccess (struct kvm_vcpu *vcpu,bool is_write, +u32 intid,u32 *val) +{ +unsigned int len =4 ; +u8 buf[4 ]; +int ret; + +if (is_write) { +vgic_data_host_to_mmio_bus (buf, len, *val); + ret =vgic_write_irq_line_level_info (vcpu, intid, len, buf); + }else { + ret =vgic_read_irq_line_level_info (vcpu, intid, len, buf); +if (!ret) + *val =vgic_data_mmio_bus_to_host (buf, len); + } + +return ret; +}
virt/kvm/arm/vgic/vgic-mmio.c +34 -0
@@ -391,6 +391,40 @@ void vgic_mmio_write_config(struct kvm_vcpu *vcpu, } } +int vgic_read_irq_line_level_info (struct kvm_vcpu *vcpu,u32 intid, +unsigned int len,void *val) +{ +unsigned long data =0 ; +int i; + +for (i =0 ; i < len *8 ; i++) { +struct vgic_irq *irq =vgic_get_irq (vcpu->kvm, vcpu, intid + i); + +if (irq->line_level) + data |= (1U << i); + } +vgic_data_host_to_mmio_bus (val, len, data); + +return 0 ; +} + +int vgic_write_irq_line_level_info (struct kvm_vcpu *vcpu,u32 intid, +unsigned int len,const void *val) +{ +int i; +unsigned long data =vgic_data_mmio_bus_to_host (val, len); + +for_each_set_bit (i, &data, len *8 ) { +struct vgic_irq *irq =vgic_get_irq (vcpu->kvm, vcpu, intid + i); + +spin_lock (&irq->irq_lock); + irq->line_level = true; +spin_unlock (&irq->irq_lock); + } + +return 0 ; +} +static int match_region (const void *key,const void *elt) {const unsigned int offset = (unsigned long )key;
virt/kvm/arm/vgic/vgic-mmio.h +6 -0
@@ -183,6 +183,12 @@ int vgic_mmio_uaccess_read(struct kvm_vcpu *vcpu, struct kvm_io_device *dev,int vgic_mmio_uaccess_write (struct kvm_vcpu *vcpu,struct kvm_io_device *dev,gpa_t addr,int len,const void *val); +int vgic_read_irq_line_level_info (struct kvm_vcpu *vcpu,u32 intid, +unsigned int len,void *val); + +int vgic_write_irq_line_level_info (struct kvm_vcpu *vcpu,u32 intid, +unsigned int len,const void *val); +unsigned int vgic_v2_init_dist_iodev (struct vgic_io_device *dev);unsigned int vgic_v3_init_dist_iodev (struct vgic_io_device *dev);
virt/kvm/arm/vgic/vgic.h +3 -0
@@ -100,6 +100,9 @@ int vgic_v3_cpu_sysregs_uaccess(struct kvm_vcpu *vcpu, bool is_write, u64 id, u64 *val);int vgic_v3_has_cpu_sysregs_attr (struct kvm_vcpu *vcpu,bool is_write,u64 id,u64 *reg); +int vgic_v3_line_level_info_uaccess (struct kvm_vcpu *vcpu,bool is_write, +u32 intid,u32 *val); +#else static inline void vgic_v3_process_maintenance (struct kvm_vcpu *vcpu) {
Signature · 1 line
1.9.1
Re: [RFC PATCH v3 5/5] arm/arm64: vgic-new: Implement KVM_DEV_ARM_VGIC_GRP_LEVEL_INFO ioctl
Quoted 21 lines · On Wed, Aug 24, 2016 at 04:50:09PM +0530, [email protected] wrote:
From: Vijaya Kumar K <[email protected]>
Userspace requires to store and restore of
line_levelfor level triggered interrupts. For this ioctlKVM_DEV_ARM_VGIC_GRP_LEVEL_INFOis defined.Signed-off-by Vijaya Kumar K <[email protected]>--- arch/arm64/include/uapi/asm/kvm.h | 6 +++++ virt/kvm/arm/vgic/vgic-kvm-device.c | 44 ++++++++++++++++++++++++++++++++++++- virt/kvm/arm/vgic/vgic-mmio-v3.c | 19 ++++++++++++++++ virt/kvm/arm/vgic/vgic-mmio.c | 34 ++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic-mmio.h | 6 +++++ virt/kvm/arm/vgic/vgic.h | 3 +++ 6 files changed, 111 insertions(+), 1 deletion(-)arch/arm64/include/uapi/asm/kvm.h +0
-0
arch/arm64/include/uapi/asm/kvm.h struct kvm_arch_memory_slot { · line 213
Quoted 5 lines
arch/arm64/include/uapi/asm/kvm.h +2
-0@@ -209,6 +209,12 @@ struct kvm_arch_memory_slot {#define KVM_DEV_ARM_VGIC_GRP_CTRL 4#define KVM_DEV_ARM_VGIC_GRP_REDIST_REGS 5#define KVM_DEV_ARM_VGIC_CPU_SYSREGS 6 +#define KVM_DEV_ARM_VGIC_GRP_LEVEL_INFO 7 +#define KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_SHIFT 9
This should be 10, bits 0 through 9 gives you 10 to work with.
arch/arm64/include/uapi/asm/kvm.h struct kvm_arch_memory_slot { · line 215
Quoted 2 lines
arch/arm64/include/uapi/asm/kvm.h +2
-0+#define KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_MASK \ + (0x7fffffULL << KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_SHIFT)
this mask is also wrong, 32 - 10 == 22, not 23.
arch/arm64/include/uapi/asm/kvm.h struct kvm_arch_memory_slot { · line 216
Quoted 1 line
arch/arm64/include/uapi/asm/kvm.h +1
-0+#define KVM_DEV_ARM_VGIC_LINE_LEVEL_INTID_MASK 0x1ff
this is also wrong, you have 10 bits, not 9 bits.
Hint: the max SPI number is around 1024.
arch/arm64/include/uapi/asm/kvm.h struct kvm_arch_memory_slot { · line 217
Quoted 1 line
arch/arm64/include/uapi/asm/kvm.h +1
-0+#define KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_VAL 1
This should really be KVM_DEV_ARM_VGIC_GRP_LEVEL_INFO_LEVEL. Why is 0 not a valid value?
Quoted 32 lines
arch/arm64/include/uapi/asm/kvm.h +0
-0#define KVM_DEV_ARM_VGIC_CTRL_INIT 0#define KVM_DEV_ARM_VGIC_SYSREG_MASK (KVM_REG_ARM64_SYSREG_OP0_MASK | \virt/kvm/arm/vgic/vgic-kvm-device.c +17
-0@@ -509,6 +509,23 @@ static int vgic_attr_regs_access_v3(struct kvm_device *dev, regid, reg);break ; } +case KVM_DEV_ARM_VGIC_GRP_LEVEL_INFO : { +unsigned int info, intid; + + info = (attr->attr &KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_MASK ) >> +KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_SHIFT ; +if (info ==KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_VAL ) { + intid = attr->attr & +KVM_DEV_ARM_VGIC_LINE_LEVEL_INTID_MASK ; + ret =vgic_v3_line_level_info_uaccess (vcpu, is_write, + intid, &tmp32); +if (!is_write) + *reg = tmp32; + }else { + ret = -EINVAL ; + } +break ; + }default : ret = -EINVAL ;break ;
virt/kvm/arm/vgic/vgic-kvm-device.c static int vgic_v3_set_attr(struct kvm_device *dev, · line 574
Quoted 7 lines
virt/kvm/arm/vgic/vgic-kvm-device.c +4
-0@@ -551,6 +568,17 @@ static int vgic_v3_set_attr(struct kvm_device *dev,return vgic_attr_regs_access_v3 (dev, attr, ®, true); } +case KVM_DEV_ARM_VGIC_GRP_LEVEL_INFO : { +u32 __user *uaddr = (u32 __user *)(long )attr->addr; +u64 reg; +u32 tmp32;
here we have more type fun, which I assume you fix based on my comments on a previous patch.
Quoted 32 lines
virt/kvm/arm/vgic/vgic-kvm-device.c +19
-1+ +if (get_user (tmp32, uaddr)) +return -EFAULT ; + + reg = tmp32; +return vgic_attr_regs_access_v3 (dev, attr, ®, true); + } }return -ENXIO ; }@@ -588,8 +616,19 @@ static int vgic_v3_get_attr(struct kvm_device *dev, ret =put_user (reg, uaddr);return ret; } - } +case KVM_DEV_ARM_VGIC_GRP_LEVEL_INFO : { +u32 __user *uaddr = (u32 __user *)(long )attr->addr; +u64 reg; +u32 tmp32; + ret =vgic_attr_regs_access_v3 (dev, attr, ®, false); +if (ret) +return ret; + tmp32 = reg; + ret =put_user (tmp32, uaddr); +return ret; + } + }return -ENXIO ; }
virt/kvm/arm/vgic/vgic-kvm-device.c static int vgic_v3_has_attr(struct kvm_device *dev, · line 653
Quoted 5 lines
virt/kvm/arm/vgic/vgic-kvm-device.c +2
-0@@ -610,11 +649,14 @@ static int vgic_v3_has_attr(struct kvm_device *dev,return vgic_v3_has_attr_regs (dev, attr);case KVM_DEV_ARM_VGIC_GRP_NR_IRQS :return 0 ; +case KVM_DEV_ARM_VGIC_GRP_LEVEL_INFO : +return 0 ;
probably you should check the info field here as well
Quoted 17 lines
virt/kvm/arm/vgic/vgic-kvm-device.c +1
-0case KVM_DEV_ARM_VGIC_GRP_CTRL :switch (attr->attr) {case KVM_DEV_ARM_VGIC_CTRL_INIT :return 0 ; } +break ; }return -ENXIO ; }virt/kvm/arm/vgic/vgic-mmio-v3.c +0
-0@@ -789,3 +789,22 @@ int vgic_v3_redist_uaccess(struct kvm_vcpu *vcpu, bool is_write,return vgic_v3_uaccess (vcpu, dev, is_write, offset, val); }
virt/kvm/arm/vgic/vgic-mmio-v3.c int vgic_v3_redist_uaccess(struct kvm_vcpu *vcpu, bool is_write, · line 801
Quoted 10 lines
virt/kvm/arm/vgic/vgic-mmio-v3.c +10
-0+ +int vgic_v3_line_level_info_uaccess (struct kvm_vcpu *vcpu,bool is_write, +u32 intid,u32 *val) +{ +unsigned int len =4 ; +u8 buf[4 ]; +int ret; + +if (is_write) { +vgic_data_host_to_mmio_bus (buf, len, *val);
why do you involve the mmio bus in this?
Quoted 20 lines
virt/kvm/arm/vgic/vgic-mmio-v3.c +9
-0+ ret =vgic_write_irq_line_level_info (vcpu, intid, len, buf); + }else { + ret =vgic_read_irq_line_level_info (vcpu, intid, len, buf); +if (!ret) + *val =vgic_data_mmio_bus_to_host (buf, len); + } + +return ret; +}virt/kvm/arm/vgic/vgic-mmio.c +3
-0@@ -391,6 +391,40 @@ void vgic_mmio_write_config(struct kvm_vcpu *vcpu, } } +int vgic_read_irq_line_level_info (struct kvm_vcpu *vcpu,u32 intid, +unsigned int len,void *val) +{
virt/kvm/arm/vgic/vgic-mmio.c void vgic_mmio_write_config(struct kvm_vcpu *vcpu, · line 406
Quoted 10 lines
virt/kvm/arm/vgic/vgic-mmio.c +10
-0+unsigned long data =0 ; +int i; + +for (i =0 ; i < len *8 ; i++) { +struct vgic_irq *irq =vgic_get_irq (vcpu->kvm, vcpu, intid + i); + +if (irq->line_level) + data |= (1U << i); + } +vgic_data_host_to_mmio_bus (val, len, data);
why???
virt/kvm/arm/vgic/vgic-mmio.c void vgic_mmio_write_config(struct kvm_vcpu *vcpu, · line 415
Quoted 9 lines
virt/kvm/arm/vgic/vgic-mmio.c +9
-0+ +return 0 ; +} + +int vgic_write_irq_line_level_info (struct kvm_vcpu *vcpu,u32 intid, +unsigned int len,const void *val) +{ +int i; +unsigned long data =vgic_data_mmio_bus_to_host (val, len);
why???
Quoted 49 lines
virt/kvm/arm/vgic/vgic-mmio.c +12
-0+ +for_each_set_bit (i, &data, len *8 ) { +struct vgic_irq *irq =vgic_get_irq (vcpu->kvm, vcpu, intid + i); + +spin_lock (&irq->irq_lock); + irq->line_level = true; +spin_unlock (&irq->irq_lock); + } + +return 0 ; +} +static int match_region (const void *key,const void *elt) {const unsigned int offset = (unsigned long )key;virt/kvm/arm/vgic/vgic-mmio.h +6
-0@@ -183,6 +183,12 @@ int vgic_mmio_uaccess_read(struct kvm_vcpu *vcpu, struct kvm_io_device *dev,int vgic_mmio_uaccess_write (struct kvm_vcpu *vcpu,struct kvm_io_device *dev,gpa_t addr,int len,const void *val); +int vgic_read_irq_line_level_info (struct kvm_vcpu *vcpu,u32 intid, +unsigned int len,void *val); + +int vgic_write_irq_line_level_info (struct kvm_vcpu *vcpu,u32 intid, +unsigned int len,const void *val); +unsigned int vgic_v2_init_dist_iodev (struct vgic_io_device *dev);unsigned int vgic_v3_init_dist_iodev (struct vgic_io_device *dev);virt/kvm/arm/vgic/vgic.h +3
-0@@ -100,6 +100,9 @@ int vgic_v3_cpu_sysregs_uaccess(struct kvm_vcpu *vcpu, bool is_write, u64 id, u64 *val);int vgic_v3_has_cpu_sysregs_attr (struct kvm_vcpu *vcpu,bool is_write,u64 id,u64 *reg); +int vgic_v3_line_level_info_uaccess (struct kvm_vcpu *vcpu,bool is_write, +u32 intid,u32 *val); +#else static inline void vgic_v3_process_maintenance (struct kvm_vcpu *vcpu) {Signature · 1 line
1.9.1
Re: [RFC PATCH v3 5/5] arm/arm64: vgic-new: Implement KVM_DEV_ARM_VGIC_GRP_LEVEL_INFO ioctl
Quoted 37 lines · Christoffer Dall
Quoted 21 lines · On Wed, Aug 24, 2016 at 04:50:09PM +0530, [email protected] wrote:
From: Vijaya Kumar K <[email protected]>
Userspace requires to store and restore of
line_levelfor level triggered interrupts. For this ioctlKVM_DEV_ARM_VGIC_GRP_LEVEL_INFOis defined.Signed-off-by Vijaya Kumar K <[email protected]>--- arch/arm64/include/uapi/asm/kvm.h | 6 +++++ virt/kvm/arm/vgic/vgic-kvm-device.c | 44 ++++++++++++++++++++++++++++++++++++- virt/kvm/arm/vgic/vgic-mmio-v3.c | 19 ++++++++++++++++ virt/kvm/arm/vgic/vgic-mmio.c | 34 ++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic-mmio.h | 6 +++++ virt/kvm/arm/vgic/vgic.h | 3 +++ 6 files changed, 111 insertions(+), 1 deletion(-)arch/arm64/include/uapi/asm/kvm.h +0
-0arch/arm64/include/uapi/asm/kvm.h struct kvm_arch_memory_slot { · line 213
Quoted 5 lines
arch/arm64/include/uapi/asm/kvm.h +2
-0@@ -209,6 +209,12 @@ struct kvm_arch_memory_slot {#define KVM_DEV_ARM_VGIC_GRP_CTRL 4#define KVM_DEV_ARM_VGIC_GRP_REDIST_REGS 5#define KVM_DEV_ARM_VGIC_CPU_SYSREGS 6 +#define KVM_DEV_ARM_VGIC_GRP_LEVEL_INFO 7 +#define KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_SHIFT 9This should be 10, bits 0 through 9 gives you 10 to work with.
arch/arm64/include/uapi/asm/kvm.h struct kvm_arch_memory_slot { · line 215
Quoted 2 lines
arch/arm64/include/uapi/asm/kvm.h +2
-0+#define KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_MASK \ + (0x7fffffULL << KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_SHIFT)this mask is also wrong, 32 - 10 == 22, not 23.
arch/arm64/include/uapi/asm/kvm.h struct kvm_arch_memory_slot { · line 216
Quoted 1 line
arch/arm64/include/uapi/asm/kvm.h +1
-0+#define KVM_DEV_ARM_VGIC_LINE_LEVEL_INTID_MASK 0x1ff
Quoted 9 lines
this is also wrong, you have 10 bits, not 9 bits.
Hint: the max SPI number is around 1024.
arch/arm64/include/uapi/asm/kvm.h struct kvm_arch_memory_slot { · line 217
Quoted 1 line
arch/arm64/include/uapi/asm/kvm.h +1
-0+#define KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_VAL 1This should really be
KVM_DEV_ARM_VGIC_GRP_LEVEL_INFO_LEVEL. Why is 0 not a valid value?
actually, the API documentation specifies that this should simply be defined as VGIC_LEVEL_INFO_LINE_LEVEL.
-Christoffer
Re: [RFC PATCH v3 5/5] arm/arm64: vgic-new: Implement KVM_DEV_ARM_VGIC_GRP_LEVEL_INFO ioctl
In reply to Christoffer DallQuoted 10 lines · Christoffer Dall
Quoted 8 lines · On Wed, Aug 24, 2016 at 04:50:09PM +0530, [email protected] wrote:
From: Vijaya Kumar K <[email protected]>
}virt/kvm/arm/vgic/vgic-mmio-v3.c +0
-0@@ -789,3 +789,22 @@ int vgic_v3_redist_uaccess(struct kvm_vcpu *vcpu, bool is_write,
Quoted 14 lines
virt/kvm/arm/vgic/vgic-mmio-v3.c int vgic_v3_redist_uaccess(struct kvm_vcpu *vcpu, bool is_write, · line 801
Quoted 12 lines
virt/kvm/arm/vgic/vgic-mmio-v3.c +10
-0return vgic_v3_uaccess (vcpu, dev, is_write, offset, val); } + +int vgic_v3_line_level_info_uaccess (struct kvm_vcpu *vcpu,bool is_write, +u32 intid,u32 *val) +{ +unsigned int len =4 ; +u8 buf[4 ]; +int ret; + +if (is_write) { +vgic_data_host_to_mmio_bus (buf, len, *val);why do you involve the mmio bus in this?
This is doing LE conversion. This is being done by vgic_uaccess function. IRC, This sys register access in not following vgic_uaccess path. Hence added it here.
Quoted 19 lines
Quoted 19 lines
virt/kvm/arm/vgic/vgic-mmio-v3.c +9
-0+ ret =vgic_write_irq_line_level_info (vcpu, intid, len, buf); + }else { + ret =vgic_read_irq_line_level_info (vcpu, intid, len, buf); +if (!ret) + *val =vgic_data_mmio_bus_to_host (buf, len); + } + +return ret; +}virt/kvm/arm/vgic/vgic-mmio.c +0
-0@@ -391,6 +391,40 @@ void vgic_mmio_write_config(struct kvm_vcpu *vcpu, } }
Quoted 15 lines
virt/kvm/arm/vgic/vgic-mmio.c void vgic_mmio_write_config(struct kvm_vcpu *vcpu, · line 406
Quoted 13 lines
virt/kvm/arm/vgic/vgic-mmio.c +13
-0+int vgic_read_irq_line_level_info (struct kvm_vcpu *vcpu,u32 intid, +unsigned int len,void *val) +{ +unsigned long data =0 ; +int i; + +for (i =0 ; i < len *8 ; i++) { +struct vgic_irq *irq =vgic_get_irq (vcpu->kvm, vcpu, intid + i); + +if (irq->line_level) + data |= (1U << i); + } +vgic_data_host_to_mmio_bus (val, len, data);why???
Same as above reason
Quoted 13 lines
virt/kvm/arm/vgic/vgic-mmio.c void vgic_mmio_write_config(struct kvm_vcpu *vcpu, · line 415
Quoted 11 lines
virt/kvm/arm/vgic/vgic-mmio.c +9
-0+ +return 0 ; +} + +int vgic_write_irq_line_level_info (struct kvm_vcpu *vcpu,u32 intid, +unsigned int len,const void *val) +{ +int i; +unsigned long data =vgic_data_mmio_bus_to_host (val, len);why???
Same as above reason
Re: [RFC PATCH v3 5/5] arm/arm64: vgic-new: Implement KVM_DEV_ARM_VGIC_GRP_LEVEL_INFO ioctl
Quoted 27 lines · Vijay Kilari
Quoted 10 lines · Christoffer Dall
Quoted 8 lines · On Wed, Aug 24, 2016 at 04:50:09PM +0530, [email protected] wrote:
From: Vijaya Kumar K <[email protected]>
}virt/kvm/arm/vgic/vgic-mmio-v3.c +0
-0@@ -789,3 +789,22 @@ int vgic_v3_redist_uaccess(struct kvm_vcpu *vcpu, bool is_write,Quoted 14 lines
virt/kvm/arm/vgic/vgic-mmio-v3.c int vgic_v3_redist_uaccess(struct kvm_vcpu *vcpu, bool is_write, · line 801
Quoted 12 lines
virt/kvm/arm/vgic/vgic-mmio-v3.c +10
-0return vgic_v3_uaccess (vcpu, dev, is_write, offset, val); } + +int vgic_v3_line_level_info_uaccess (struct kvm_vcpu *vcpu,bool is_write, +u32 intid,u32 *val) +{ +unsigned int len =4 ; +u8 buf[4 ]; +int ret; + +if (is_write) { +vgic_data_host_to_mmio_bus (buf, len, *val);why do you involve the mmio bus in this?
Quoted 3 lines
This is doing LE conversion. This is being done by
vgic_uaccessfunction. IRC, This sys register access in not followingvgic_uaccesspath. Hence added it here.
See my e-mail on the other patch. I think this is all just legacy from the time where we didn't distinguish between uaccess and mmio dispatches.
Quoted 50 lines
Quoted 19 lines
Quoted 19 lines
virt/kvm/arm/vgic/vgic-mmio-v3.c +9
-0+ ret =vgic_write_irq_line_level_info (vcpu, intid, len, buf); + }else { + ret =vgic_read_irq_line_level_info (vcpu, intid, len, buf); +if (!ret) + *val =vgic_data_mmio_bus_to_host (buf, len); + } + +return ret; +}virt/kvm/arm/vgic/vgic-mmio.c +0
-0@@ -391,6 +391,40 @@ void vgic_mmio_write_config(struct kvm_vcpu *vcpu, } }Quoted 15 lines
virt/kvm/arm/vgic/vgic-mmio.c void vgic_mmio_write_config(struct kvm_vcpu *vcpu, · line 406
Quoted 13 lines
virt/kvm/arm/vgic/vgic-mmio.c +13
-0+int vgic_read_irq_line_level_info (struct kvm_vcpu *vcpu,u32 intid, +unsigned int len,void *val) +{ +unsigned long data =0 ; +int i; + +for (i =0 ; i < len *8 ; i++) { +struct vgic_irq *irq =vgic_get_irq (vcpu->kvm, vcpu, intid + i); + +if (irq->line_level) + data |= (1U << i); + } +vgic_data_host_to_mmio_bus (val, len, data);why???
Same as above reason
Quoted 13 lines
virt/kvm/arm/vgic/vgic-mmio.c void vgic_mmio_write_config(struct kvm_vcpu *vcpu, · line 415
Quoted 11 lines
virt/kvm/arm/vgic/vgic-mmio.c +9
-0+ +return 0 ; +} + +int vgic_write_irq_line_level_info (struct kvm_vcpu *vcpu,u32 intid, +unsigned int len,const void *val) +{ +int i; +unsigned long data =vgic_data_mmio_bus_to_host (val, len);why???
Quoted 1 line
Same as above reason
Thanks,
-Christoffer