vITS save/restore
Subsystems (6)
v4 cover vITS save/restore
This series specifies and implements an API aimed at saving and restoring the state of the in-kernel emulated ITS device.
The ITS is programmed through registers and tables. Those latter are allocated by the guest. Their base address is programmed in registers or table entries before the ITS is enabled.
The ITS is free to use some of them to flush its internal caches. This is likely to be used when entering low power state.
Therefore, for save/restore use case, it looks natural to use this guest RAM allocated space to save the table related data. However, currently, The ITS in-kernel emulated device does not use all of those tables and for those it uses, it does not always sync them with its cached data. Additional sync must happen for:
- the collection table
- the device table
- the per-device translation tables
- the LPI pending tables.
The LPI configation table and the command queues do not need extra syncs.
An alternative to flushing the tables into guest RAM could have been to flush them into a separate user-space buffer. However the drawback of this alternative is that the virtualizer would allocate dedicated buffers to store the data that should normally be laid out in guest RAM. It would also be obliged to re-compute their size from register/table content.
So saving the tables in guest RAM better fit the ITS programming model and optimizes the memory usage. The drawback of this solution is it brings additional challenges at user-space level to make sure the guest RAM is frozen after table sync.
Best Regards
Eric
Git: complete series available at
https://github.com/eauger/linux/tree/v4.11-rc3-its-mig-v4
* Testing:
- on Cavium ThunderX using a virtio-net-pci guest, virsh save/restore commands and virt-manager live migration. Tested with 1 and 2 stage device table.
History:
v3 -> v4:
- update the DTE format (ITT_addr 52 bit support, validity bit addition)
- Document ABI revision and implement check
- iidr save/restore (including a new patch for iidr user write access)
- changed locking: kvm lock + vcpu lock
- fix nb_eventid_bits mixup
- 2 new patches aiming at exposing next_segment() and lock_all_vcpus()
- rework errror handling of lookup_table functions
- I took into account all Andre's comments/suggestions except:
- trigger the save/restore of pending tables from GICV3 KVM device instead of ITS KVM device
- implement ITS flush/restore in KVM_DEV_ARM_VGIC_GRP_CTRL ITS group
See the ML replies for current justifications. In case other people strongly disagree of course I will change the code.
v2 -> v3:
- fix restore ITS ITT_addr bit masking
v1 -> v2:
- rebased on Vijaya's v11
- all entries now are 8 byte large
- devid/eventid indexing for device table and ITT
- support 2 stage device table
- common infra to read indexed tables
- add cpu <-> le64 conversions
- itte renamed into ite
- do not care anymore about pending table 1st KB
(not needed at the moment for coarse mapping)
RFC v1
- creation
Eric Auger (22):
KVM: arm/arm64: Add vITS save/restore API documentation
KVM: arm/arm64: rename itte into ite
arm/arm64: vgic: turn vgic_find_mmio_region into public
KVM: arm64: ITS: KVM_DEV_ARM_VGIC_GRP_ITS_REGS group
KVM: arm/arm64: vgic: expose (un)lock_all_vcpus
KVM: arm64: ITS: Implement vgic_its_has_attr_regs and attr_regs_access
KVM: arm64: ITS: Implement vgic_mmio_uaccess_write_its_creadr
KVM: arm64: ITS: Implement vgic_mmio_uaccess_write_its_iidr
KVM: arm64: ITS: Report the ITE size in GITS_TYPER
KVM: arm64: ITS: Interpret MAPD Size field and check related errors
KVM: arm64: ITS: Interpret MAPD ITT_addr field
KVM: arm64: ITS: Check the device id matches TYPER DEVBITS range
KVM: arm64: ITS: KVM_DEV_ARM_VGIC_GRP_ITS_TABLES group
KVM: arm64: ITS: vgic_its_alloc_ite/device
KVM: arm64: ITS: Sort the device and ITE lists
KVM: expose next_segment()
KVM: arm64: ITS: Add infrastructure for table lookup
KVM: arm64: ITS: Collection table save/restore
KVM: arm64: ITS: vgic_its_check_id returns the entry's GPA
KVM: arm64: ITS: ITT flush and restore
KVM: arm64: ITS: Device table save/restore
KVM: arm64: ITS: Pending table save/restore
Documentation/virtual/kvm/devices/arm-vgic-its.txt | 118 +++ arch/arm/include/uapi/asm/kvm.h | 2 + arch/arm64/include/uapi/asm/kvm.h | 2 + include/kvm/arm_vgic.h | 2 + include/linux/irqchip/arm-gic-v3.h | 3 + include/linux/kvm_host.h | 8 + virt/kvm/arm/vgic/vgic-its.c | 1106 ++++++++++++++++++-- virt/kvm/arm/vgic/vgic-kvm-device.c | 4 +- virt/kvm/arm/vgic/vgic-mmio.c | 11 +- virt/kvm/arm/vgic/vgic-mmio.h | 14 +- virt/kvm/arm/vgic/vgic.h | 3 + virt/kvm/kvm_main.c | 8 - 12 files changed, 1161 insertions(+), 120 deletions(-)
Signature · 1 line
2.5.5
PATCH v4 1/22 KVM: arm/arm64: Add vITS save/restore API documentation
Add description for how to access vITS registers and how to flush/restore vITS tables into/from memory
---
v3 -> v4:
- take into account Peter's comments:
- typos
- KVM_DEV_ARM_VGIC_GRP_ITS_TABLES kvm_device_attr = 0
- add a validity bit in DTE
- document all fields in CTE and ITE
- document ABI revision
- take into account Andre's comments:
- document restrictions about GITS_CREADR writing and GITS_IIDR
- document -EBUSY error if one or more VCPUS are runnning
- document 64b registers only can be accessed with 64b access
- itt_addr field matches bits [51:8] of the itt_addr
v1 -> v2:
- DTE and ITE now are 8 bytes
- DTE and ITE now indexed by deviceid/eventid
- use ITE name instead of ITTE
- mentions ITT_addr matches bits [51:8] of the actual address
- mentions LE layout
--- Documentation/virtual/kvm/devices/arm-vgic-its.txt | 118 +++++++++++++++++++++ 1 file changed, 118 insertions(+)
Documentation/virtual/kvm/devices/arm-vgic-its.txt +118 -0
@@ -36,3 +36,121 @@ Groups: -ENXIO: ITS not properly configured as required prior to setting this attribute -ENOMEM: Memory shortage when allocating ITS internal data + + KVM_DEV_ARM_VGIC_GRP_ITS_REGS + Attributes: + The attr field of kvm_device_attr encodes the offset of the + ITS register, relative to the ITS control frame base address + (ITS_base). + + kvm_device_attr.addr points to a __u64 value whatever the width + of the addressed register (32/64 bits). 64 bit registers can only + be accessed with full length. + + Writes to read-only registers are ignored by the kernel except for: + - GITS_READR. It needs to be restored otherwise commands in the queue + will be re-executed after CWRITER setting. Writing this register is + allowed if the ITS is not enabled (GITS_CTLR.enable = 0). Also it + needs to be restored after GITS_CBASER since a write to GITS_CBASER + resets GITS_CREADR. + - GITS_IIDR. Its Revision field encodes the table layout ABI revision. + + For other registers, getting or setting a register has the same + effect as reading/writing the register on real hardware. + Errors: + -ENXIO: Offset does not correspond to any supported register + -EFAULT: Invalid user pointer for attr->addr + -EINVAL: Offset is not 64-bit aligned + -EBUSY: one or more VCPUS are running + + KVM_DEV_ARM_VGIC_GRP_ITS_TABLES + Attributes + The attr field of kvm_device_attr must be zero. + + request the flush-save/restore of the ITS tables, namely + the device table, the collection table, all the ITT tables, + the LPI pending tables. On save, the tables are flushed + into guest memory at the location provisioned by the guest + in GITS_BASER (device and collection tables), in the MAPD + command (ITT_addr), GICR_PENDBASERs (pending tables). + + This means the GIC should be restored before the ITS and all + ITS registers but the GITS_CTLR must be restored before + restoring the ITS tables. + + The GITS_READR and GITS_IIDR read-only registers must also + be restored before the table restore. The IIDR revision field + encodes the ABI revision of the table layout. If not set by + user space, the restoration of the tables will fail. + + Note the LPI configuration table is read-only for the + in-kernel ITS and its save/restore goes through the standard + RAM save/restore. + + The layout of the tables in guest memory defines an ABI. + The entries are laid in little endian format as follows; + + Errors: + -EINVAL: kvm_device_attr not equal to 0, invalid table data + -EFAULT: invalid guest ram access + -EBUSY: one or more VCPUS are running + + ITS Table ABI REV1: + ------------------- + + The device table and ITE are respectively indexed by device id and + eventid. The collection table however is not indexed by collection id: + CTE are written at the beginning of the buffer. + + Device Table Entry (DTE) layout: entry size = 8 bytes + + bits: | 63| 62 ... 49 | 48 ... 5 | 4 ... 0 | + values: | V | next | ITT_addr | Size | + + where; + - V indicates whether the entry is valid, + - ITT_addr matches bits [51:8] of the ITT address (256B aligned), + - next field is meaningful only if the entry is valid. + It equals to 0 if this entry is the last one; otherwise it corresponds + to the minimum between the offset to the next device id and 2^14 -1. + + Collection Table Entry (CTE) layout: entry size = 8 bytes + + bits: | 63| 62 .. 52 | 51 ... 16 | 15 ... 0 | + values: | V | RES0 | RDBase | ICID | + + where: + - V indicates whether the entry is valid, + - RDBase matches the PE number (GICR_TYPER.Processor_Number), + - ICID matches the collection ID + + Interrupt Translation Entry (ITE) layout: entry size = 8 bytes + + bits: | 63 ... 48 | 47 ... 16 | 15 ... 0 | + values: | next | pINTID | ICID | + + where: + - pINTID is the physical LPI ID, + - ICID is the collection ID, + - next field is meaningful only if the entry is valid (pINTID != 0). + It equals to 0 if this entry is the last one; otherwise it corresponds + to the minimum between the eventid offset to the next ITE and 2^16 -1. + + LPI Pending Table layout: + + As specified in the ARM Generic Interrupt Controller Architecture + Specification GIC Architecture version 3.0 and version 4. The first + 1kB is not modified and therefore should contain zeroes. + + Future evolutions of the ITS table layout: + + At the moment the table layout is defined and optimized for physical + LPI support. + + In the future we might implement direct injection of virtual LPIS. + This will require an upgrade of the table layout and an evolution of + the ABI. The ABI revision is encoded in the GITS_IIDR revision field. + That register must be restored before the table restoration, otherwise + the operation will fail. + + ABI V1: GITS_IIDR.Revision = 1
Signature · 1 line
2.5.5
Re: [PATCH v4 01/22] KVM: arm/arm64: Add vITS save/restore API documentation
Quoted 64 lines · Eric Auger
Add description for how to access vITS registers and how to flush/restore vITS tables into/from memory
Signed-off-by Eric Auger <[email protected]>---
v3 -> v4:
- take into account Peter's comments:
- typos
-KVM_DEV_ARM_VGIC_GRP_ITS_TABLESkvm_device_attr= 0
- add a validity bit in DTE
- document all fields in CTE and ITE
- document ABI revision
- take into account Andre's comments:
- document restrictions aboutGITS_CREADRwriting andGITS_IIDR
- document-EBUSYerror if one or more VCPUS are runnning
- document 64b registers only can be accessed with 64b access
-itt_addrfield matches bits [51:8] of theitt_addrv1 -> v2:
- DTE and ITE now are 8 bytes
- DTE and ITE now indexed by deviceid/eventid
- use ITE name instead of ITTE
- mentionsITT_addrmatches bits [51:8] of the actual address
- mentions LE layout--- Documentation/virtual/kvm/devices/arm-vgic-its.txt | 118 +++++++++++++++++++++ 1 file changed, 118 insertions(+)Documentation/virtual/kvm/devices/arm-vgic-its.txt +27
-0@@ -36,3 +36,121 @@ Groups: -ENXIO: ITS not properly configured as required prior to setting this attribute -ENOMEM: Memory shortage when allocating ITS internal data + + KVM_DEV_ARM_VGIC_GRP_ITS_REGS + Attributes: + The attr field of kvm_device_attr encodes the offset of the + ITS register, relative to the ITS control frame base address + (ITS_base). + + kvm_device_attr.addr points to a __u64 value whatever the width + of the addressed register (32/64 bits). 64 bit registers can only + be accessed with full length. + + Writes to read-only registers are ignored by the kernel except for: + - GITS_READR. It needs to be restored otherwise commands in the queue + will be re-executed after CWRITER setting. Writing this register is + allowed if the ITS is not enabled (GITS_CTLR.enable = 0). Also it + needs to be restored after GITS_CBASER since a write to GITS_CBASER + resets GITS_CREADR. + - GITS_IIDR. Its Revision field encodes the table layout ABI revision. + + For other registers, getting or setting a register has the same + effect as reading/writing the register on real hardware. + Errors: + -ENXIO: Offset does not correspond to any supported register + -EFAULT: Invalid user pointer for attr->addr + -EINVAL: Offset is not 64-bit aligned + -EBUSY: one or more VCPUS are running +
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 75
Quoted 10 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +10
-0+ KVM_DEV_ARM_VGIC_GRP_ITS_TABLES + Attributes + The attr field of kvm_device_attr must be zero. + + request the flush-save/restore of the ITS tables, namely + the device table, the collection table, all the ITT tables, + the LPI pending tables. On save, the tables are flushed + into guest memory at the location provisioned by the guest + in GITS_BASER (device and collection tables), in the MAPD + command (ITT_addr), GICR_PENDBASERs (pending tables).
May I echo Andre's concern here? Seeing the GICR_PENDBASER registers here feels wrong. The pending table is a redistributor concept, and is local to it. Even more, it is perfectly possible to use the redistributors (and its pending tables) without an ITS by using the GICR_SETLPIR registers.
Granted, we do not support this (and I'm *not* looking forward to supporting it), but I would rather implement a redistributor flush than using the ITS to indirectly force it. That's not how the HW works, and I don't think we should deviate from it.
I appreciate this brings additional complexity to userspace (having to iterate over the vcpus or the redistributors is likely more costly than hitting the ITS which is likely to be unique), but sticking to the letter of the architecture is probably our best bet. Each time we tried to deviate from it, we've had to backtrack (and I'm using the royal "we" here).
Any chance you could revisit this aspect?
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny.
Re: [PATCH v4 01/22] KVM: arm/arm64: Add vITS save/restore API documentation
Quoted 87 lines · Marc Zyngier
Quoted 64 lines · Eric Auger
Add description for how to access vITS registers and how to flush/restore vITS tables into/from memory
Signed-off-by Eric Auger <[email protected]>---
v3 -> v4:
- take into account Peter's comments:
- typos
-KVM_DEV_ARM_VGIC_GRP_ITS_TABLESkvm_device_attr= 0
- add a validity bit in DTE
- document all fields in CTE and ITE
- document ABI revision
- take into account Andre's comments:
- document restrictions aboutGITS_CREADRwriting andGITS_IIDR
- document-EBUSYerror if one or more VCPUS are runnning
- document 64b registers only can be accessed with 64b access
-itt_addrfield matches bits [51:8] of theitt_addrv1 -> v2:
- DTE and ITE now are 8 bytes
- DTE and ITE now indexed by deviceid/eventid
- use ITE name instead of ITTE
- mentionsITT_addrmatches bits [51:8] of the actual address
- mentions LE layout--- Documentation/virtual/kvm/devices/arm-vgic-its.txt | 118 +++++++++++++++++++++ 1 file changed, 118 insertions(+)Documentation/virtual/kvm/devices/arm-vgic-its.txt +27
-0@@ -36,3 +36,121 @@ Groups: -ENXIO: ITS not properly configured as required prior to setting this attribute -ENOMEM: Memory shortage when allocating ITS internal data + + KVM_DEV_ARM_VGIC_GRP_ITS_REGS + Attributes: + The attr field of kvm_device_attr encodes the offset of the + ITS register, relative to the ITS control frame base address + (ITS_base). + + kvm_device_attr.addr points to a __u64 value whatever the width + of the addressed register (32/64 bits). 64 bit registers can only + be accessed with full length. + + Writes to read-only registers are ignored by the kernel except for: + - GITS_READR. It needs to be restored otherwise commands in the queue + will be re-executed after CWRITER setting. Writing this register is + allowed if the ITS is not enabled (GITS_CTLR.enable = 0). Also it + needs to be restored after GITS_CBASER since a write to GITS_CBASER + resets GITS_CREADR. + - GITS_IIDR. Its Revision field encodes the table layout ABI revision. + + For other registers, getting or setting a register has the same + effect as reading/writing the register on real hardware. + Errors: + -ENXIO: Offset does not correspond to any supported register + -EFAULT: Invalid user pointer for attr->addr + -EINVAL: Offset is not 64-bit aligned + -EBUSY: one or more VCPUS are running +Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 75
Quoted 10 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +10
-0+ KVM_DEV_ARM_VGIC_GRP_ITS_TABLES + Attributes + The attr field of kvm_device_attr must be zero. + + request the flush-save/restore of the ITS tables, namely + the device table, the collection table, all the ITT tables, + the LPI pending tables. On save, the tables are flushed + into guest memory at the location provisioned by the guest + in GITS_BASER (device and collection tables), in the MAPD + command (ITT_addr), GICR_PENDBASERs (pending tables).May I echo Andre's concern here? Seeing the
GICR_PENDBASERregisters here feels wrong. The pending table is a redistributor concept, and is local to it. Even more, it is perfectly possible to use the redistributors (and its pending tables) without an ITS by using theGICR_SETLPIRregisters.Granted, we do not support this (and I'm *not* looking forward to supporting it), but I would rather implement a redistributor flush than using the ITS to indirectly force it. That's not how the HW works, and I don't think we should deviate from it.
Quoted 5 lines
I appreciate this brings additional complexity to userspace (having to iterate over the vcpus or the redistributors is likely more costly than hitting the ITS which is likely to be unique), but sticking to the letter of the architecture is probably our best bet. Each time we tried to deviate from it, we've had to backtrack.
I agree. I think the possibility of using LPIs without an ITS is the winning argument.
However, I could see it being reasonable to have a single call that userspace can make on the vgic device to ask it to flush all the redistributors at the same time. We defined the cpu sysreg interface via the vgic device as well, so I don't think we're breaking anything, and in fact, it may be good to have a single sync-point where the kernel can atomically say "all redistributors are flushed correctly" or "something bad happened". Do we have any arguments for wanting to be able flush redistributors independently?
Thanks,
-Christoffer
Re: [PATCH v4 01/22] KVM: arm/arm64: Add vITS save/restore API documentation
Quoted 97 lines · Christoffer Dall
Quoted 87 lines · Marc Zyngier
Quoted 64 lines · Eric Auger
Add description for how to access vITS registers and how to flush/restore vITS tables into/from memory
Signed-off-by Eric Auger <[email protected]>---
v3 -> v4:
- take into account Peter's comments:
- typos
-KVM_DEV_ARM_VGIC_GRP_ITS_TABLESkvm_device_attr= 0
- add a validity bit in DTE
- document all fields in CTE and ITE
- document ABI revision
- take into account Andre's comments:
- document restrictions aboutGITS_CREADRwriting andGITS_IIDR
- document-EBUSYerror if one or more VCPUS are runnning
- document 64b registers only can be accessed with 64b access
-itt_addrfield matches bits [51:8] of theitt_addrv1 -> v2:
- DTE and ITE now are 8 bytes
- DTE and ITE now indexed by deviceid/eventid
- use ITE name instead of ITTE
- mentionsITT_addrmatches bits [51:8] of the actual address
- mentions LE layout--- Documentation/virtual/kvm/devices/arm-vgic-its.txt | 118 +++++++++++++++++++++ 1 file changed, 118 insertions(+)Documentation/virtual/kvm/devices/arm-vgic-its.txt +27
-0@@ -36,3 +36,121 @@ Groups: -ENXIO: ITS not properly configured as required prior to setting this attribute -ENOMEM: Memory shortage when allocating ITS internal data + + KVM_DEV_ARM_VGIC_GRP_ITS_REGS + Attributes: + The attr field of kvm_device_attr encodes the offset of the + ITS register, relative to the ITS control frame base address + (ITS_base). + + kvm_device_attr.addr points to a __u64 value whatever the width + of the addressed register (32/64 bits). 64 bit registers can only + be accessed with full length. + + Writes to read-only registers are ignored by the kernel except for: + - GITS_READR. It needs to be restored otherwise commands in the queue + will be re-executed after CWRITER setting. Writing this register is + allowed if the ITS is not enabled (GITS_CTLR.enable = 0). Also it + needs to be restored after GITS_CBASER since a write to GITS_CBASER + resets GITS_CREADR. + - GITS_IIDR. Its Revision field encodes the table layout ABI revision. + + For other registers, getting or setting a register has the same + effect as reading/writing the register on real hardware. + Errors: + -ENXIO: Offset does not correspond to any supported register + -EFAULT: Invalid user pointer for attr->addr + -EINVAL: Offset is not 64-bit aligned + -EBUSY: one or more VCPUS are running +Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 75
Quoted 10 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +10
-0+ KVM_DEV_ARM_VGIC_GRP_ITS_TABLES + Attributes + The attr field of kvm_device_attr must be zero. + + request the flush-save/restore of the ITS tables, namely + the device table, the collection table, all the ITT tables, + the LPI pending tables. On save, the tables are flushed + into guest memory at the location provisioned by the guest + in GITS_BASER (device and collection tables), in the MAPD + command (ITT_addr), GICR_PENDBASERs (pending tables).May I echo Andre's concern here? Seeing the
GICR_PENDBASERregisters here feels wrong. The pending table is a redistributor concept, and is local to it. Even more, it is perfectly possible to use the redistributors (and its pending tables) without an ITS by using theGICR_SETLPIRregisters.Granted, we do not support this (and I'm *not* looking forward to supporting it), but I would rather implement a redistributor flush than using the ITS to indirectly force it. That's not how the HW works, and I don't think we should deviate from it.
Quoted 5 lines
I appreciate this brings additional complexity to userspace (having to iterate over the vcpus or the redistributors is likely more costly than hitting the ITS which is likely to be unique), but sticking to the letter of the architecture is probably our best bet. Each time we tried to deviate from it, we've had to backtrack.
I agree. I think the possibility of using LPIs without an ITS is the winning argument.
Quoted 8 lines
However, I could see it being reasonable to have a single call that userspace can make on the vgic device to ask it to flush all the redistributors at the same time. We defined the cpu sysreg interface via the vgic device as well, so I don't think we're breaking anything, and in fact, it may be good to have a single sync-point where the kernel can atomically say "all redistributors are flushed correctly" or "something bad happened". Do we have any arguments for wanting to be able flush redistributors independently?
Not as such. The redistributors may support implementation-specific ways of ensuring synchronization with the PT (for power management purposes, for example), but there is no architected way of ensuring it.
So I agree that having a single synchronization hook for all redistributors in the system is probably the right thing to do. This is simple enough for userspace, and we already have the required code in this series -- we just need to tie it to an additional property on the GICv3 group.
Eric: can you explore this and let us know if there is any issue we haven't foreseen yet?
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny.
Re: [PATCH v4 01/22] KVM: arm/arm64: Add vITS save/restore API documentation
Hi Marc, Christoffer,
Quoted 111 lines · Marc Zyngier
Quoted 97 lines · Christoffer Dall
Quoted 87 lines · Marc Zyngier
Quoted 64 lines · Eric Auger
Add description for how to access vITS registers and how to flush/restore vITS tables into/from memory
Signed-off-by Eric Auger <[email protected]>---
v3 -> v4:
- take into account Peter's comments:
- typos
-KVM_DEV_ARM_VGIC_GRP_ITS_TABLESkvm_device_attr= 0
- add a validity bit in DTE
- document all fields in CTE and ITE
- document ABI revision
- take into account Andre's comments:
- document restrictions aboutGITS_CREADRwriting andGITS_IIDR
- document-EBUSYerror if one or more VCPUS are runnning
- document 64b registers only can be accessed with 64b access
-itt_addrfield matches bits [51:8] of theitt_addrv1 -> v2:
- DTE and ITE now are 8 bytes
- DTE and ITE now indexed by deviceid/eventid
- use ITE name instead of ITTE
- mentionsITT_addrmatches bits [51:8] of the actual address
- mentions LE layout--- Documentation/virtual/kvm/devices/arm-vgic-its.txt | 118 +++++++++++++++++++++ 1 file changed, 118 insertions(+)Documentation/virtual/kvm/devices/arm-vgic-its.txt +27
-0@@ -36,3 +36,121 @@ Groups: -ENXIO: ITS not properly configured as required prior to setting this attribute -ENOMEM: Memory shortage when allocating ITS internal data + + KVM_DEV_ARM_VGIC_GRP_ITS_REGS + Attributes: + The attr field of kvm_device_attr encodes the offset of the + ITS register, relative to the ITS control frame base address + (ITS_base). + + kvm_device_attr.addr points to a __u64 value whatever the width + of the addressed register (32/64 bits). 64 bit registers can only + be accessed with full length. + + Writes to read-only registers are ignored by the kernel except for: + - GITS_READR. It needs to be restored otherwise commands in the queue + will be re-executed after CWRITER setting. Writing this register is + allowed if the ITS is not enabled (GITS_CTLR.enable = 0). Also it + needs to be restored after GITS_CBASER since a write to GITS_CBASER + resets GITS_CREADR. + - GITS_IIDR. Its Revision field encodes the table layout ABI revision. + + For other registers, getting or setting a register has the same + effect as reading/writing the register on real hardware. + Errors: + -ENXIO: Offset does not correspond to any supported register + -EFAULT: Invalid user pointer for attr->addr + -EINVAL: Offset is not 64-bit aligned + -EBUSY: one or more VCPUS are running +Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 75
Quoted 10 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +10
-0+ KVM_DEV_ARM_VGIC_GRP_ITS_TABLES + Attributes + The attr field of kvm_device_attr must be zero. + + request the flush-save/restore of the ITS tables, namely + the device table, the collection table, all the ITT tables, + the LPI pending tables. On save, the tables are flushed + into guest memory at the location provisioned by the guest + in GITS_BASER (device and collection tables), in the MAPD + command (ITT_addr), GICR_PENDBASERs (pending tables).May I echo Andre's concern here? Seeing the
GICR_PENDBASERregisters here feels wrong. The pending table is a redistributor concept, and is local to it. Even more, it is perfectly possible to use the redistributors (and its pending tables) without an ITS by using theGICR_SETLPIRregisters.Granted, we do not support this (and I'm *not* looking forward to supporting it), but I would rather implement a redistributor flush than using the ITS to indirectly force it. That's not how the HW works, and I don't think we should deviate from it.
Quoted 5 lines
I appreciate this brings additional complexity to userspace (having to iterate over the vcpus or the redistributors is likely more costly than hitting the ITS which is likely to be unique), but sticking to the letter of the architecture is probably our best bet. Each time we tried to deviate from it, we've had to backtrack.
I agree. I think the possibility of using LPIs without an ITS is the winning argument.
Quoted 8 lines
However, I could see it being reasonable to have a single call that userspace can make on the vgic device to ask it to flush all the redistributors at the same time. We defined the cpu sysreg interface via the vgic device as well, so I don't think we're breaking anything, and in fact, it may be good to have a single sync-point where the kernel can atomically say "all redistributors are flushed correctly" or "something bad happened". Do we have any arguments for wanting to be able flush redistributors independently?
Not as such. The redistributors may support implementation-specific ways of ensuring synchronization with the PT (for power management purposes, for example), but there is no architected way of ensuring it.
Quoted 8 lines
So I agree that having a single synchronization hook for all redistributors in the system is probably the right thing to do. This is simple enough for userspace, and we already have the required code in this series -- we just need to tie it to an additional property on the GICv3 group.
Eric: can you explore this and let us know if there is any issue we haven't foreseen yet?
Yes I am going to investigate this. The extra complexity I foresee is that I need to implement coarse mapping in the first kB of the pending table to guess what LPI is pending and thus become independent on the restoration of the ITS - which is the goal -.
Thanks
Eric
Quoted 5 lines
Thanks,
M.
Re: [PATCH v4 01/22] KVM: arm/arm64: Add vITS save/restore API documentation
Quoted 120 lines · Auger Eric
Hi Marc, Christoffer,
Quoted 117 lines · Marc Zyngier
Quoted 97 lines · Christoffer Dall
Quoted 87 lines · Marc Zyngier
Quoted 64 lines · Eric Auger
Add description for how to access vITS registers and how to flush/restore vITS tables into/from memory
Signed-off-by Eric Auger <[email protected]>---
v3 -> v4:
- take into account Peter's comments:
- typos
-KVM_DEV_ARM_VGIC_GRP_ITS_TABLESkvm_device_attr= 0
- add a validity bit in DTE
- document all fields in CTE and ITE
- document ABI revision
- take into account Andre's comments:
- document restrictions aboutGITS_CREADRwriting andGITS_IIDR
- document-EBUSYerror if one or more VCPUS are runnning
- document 64b registers only can be accessed with 64b access
-itt_addrfield matches bits [51:8] of theitt_addrv1 -> v2:
- DTE and ITE now are 8 bytes
- DTE and ITE now indexed by deviceid/eventid
- use ITE name instead of ITTE
- mentionsITT_addrmatches bits [51:8] of the actual address
- mentions LE layout--- Documentation/virtual/kvm/devices/arm-vgic-its.txt | 118 +++++++++++++++++++++ 1 file changed, 118 insertions(+)Documentation/virtual/kvm/devices/arm-vgic-its.txt +27
-0@@ -36,3 +36,121 @@ Groups: -ENXIO: ITS not properly configured as required prior to setting this attribute -ENOMEM: Memory shortage when allocating ITS internal data + + KVM_DEV_ARM_VGIC_GRP_ITS_REGS + Attributes: + The attr field of kvm_device_attr encodes the offset of the + ITS register, relative to the ITS control frame base address + (ITS_base). + + kvm_device_attr.addr points to a __u64 value whatever the width + of the addressed register (32/64 bits). 64 bit registers can only + be accessed with full length. + + Writes to read-only registers are ignored by the kernel except for: + - GITS_READR. It needs to be restored otherwise commands in the queue + will be re-executed after CWRITER setting. Writing this register is + allowed if the ITS is not enabled (GITS_CTLR.enable = 0). Also it + needs to be restored after GITS_CBASER since a write to GITS_CBASER + resets GITS_CREADR. + - GITS_IIDR. Its Revision field encodes the table layout ABI revision. + + For other registers, getting or setting a register has the same + effect as reading/writing the register on real hardware. + Errors: + -ENXIO: Offset does not correspond to any supported register + -EFAULT: Invalid user pointer for attr->addr + -EINVAL: Offset is not 64-bit aligned + -EBUSY: one or more VCPUS are running +Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 75
Quoted 10 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +10
-0+ KVM_DEV_ARM_VGIC_GRP_ITS_TABLES + Attributes + The attr field of kvm_device_attr must be zero. + + request the flush-save/restore of the ITS tables, namely + the device table, the collection table, all the ITT tables, + the LPI pending tables. On save, the tables are flushed + into guest memory at the location provisioned by the guest + in GITS_BASER (device and collection tables), in the MAPD + command (ITT_addr), GICR_PENDBASERs (pending tables).May I echo Andre's concern here? Seeing the
GICR_PENDBASERregisters here feels wrong. The pending table is a redistributor concept, and is local to it. Even more, it is perfectly possible to use the redistributors (and its pending tables) without an ITS by using theGICR_SETLPIRregisters.Granted, we do not support this (and I'm *not* looking forward to supporting it), but I would rather implement a redistributor flush than using the ITS to indirectly force it. That's not how the HW works, and I don't think we should deviate from it.
Quoted 5 lines
I appreciate this brings additional complexity to userspace (having to iterate over the vcpus or the redistributors is likely more costly than hitting the ITS which is likely to be unique), but sticking to the letter of the architecture is probably our best bet. Each time we tried to deviate from it, we've had to backtrack.
I agree. I think the possibility of using LPIs without an ITS is the winning argument.
Quoted 8 lines
However, I could see it being reasonable to have a single call that userspace can make on the vgic device to ask it to flush all the redistributors at the same time. We defined the cpu sysreg interface via the vgic device as well, so I don't think we're breaking anything, and in fact, it may be good to have a single sync-point where the kernel can atomically say "all redistributors are flushed correctly" or "something bad happened". Do we have any arguments for wanting to be able flush redistributors independently?
Not as such. The redistributors may support implementation-specific ways of ensuring synchronization with the PT (for power management purposes, for example), but there is no architected way of ensuring it.
So I agree that having a single synchronization hook for all redistributors in the system is probably the right thing to do. This is simple enough for userspace, and we already have the required code in this series -- we just need to tie it to an additional property on the GICv3 group.
Quoted 6 lines
Quoted 2 lines
Eric: can you explore this and let us know if there is any issue we haven't foreseen yet?
Yes I am going to investigate this. The extra complexity I foresee is that I need to implement coarse mapping in the first kB of the pending table to guess what LPI is pending and thus become independent on the restoration of the ITS - which is the goal -.
I don't think you necessarily need a coarse map. When restoring the ITS tables, you can always read the pending bit when creating the LPI structure (it has been written to RAM at save time). Note that we already do something like this in vgic_enable_lpis().
If that proves to be too slow (because you have so many mapped interrupts that doing bit access is a huge waste of time), then you can implement a coarse map and reload the pending state independently of the LPI mapping creation.
In short, don't optimize prematurely! ;-)
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Re: [PATCH v4 01/22] KVM: arm/arm64: Add vITS save/restore API documentation
In reply to Eric AugerHi Eric,
Most of my comments below are just me being picky about text when defining a user space ABI, so I think this mainly looks good, but just needs a bit of clarify, except the versioning aspect and exporting the pending table vie the redistributor instead, as Marc and Andre have pointed out.
Quoted 41 lines · Eric Auger
Add description for how to access vITS registers and how to flush/restore vITS tables into/from memory
Signed-off-by Eric Auger <[email protected]>---
v3 -> v4:
- take into account Peter's comments:
- typos
-KVM_DEV_ARM_VGIC_GRP_ITS_TABLESkvm_device_attr= 0
- add a validity bit in DTE
- document all fields in CTE and ITE
- document ABI revision
- take into account Andre's comments:
- document restrictions aboutGITS_CREADRwriting andGITS_IIDR
- document-EBUSYerror if one or more VCPUS are runnning
- document 64b registers only can be accessed with 64b access
-itt_addrfield matches bits [51:8] of theitt_addrv1 -> v2:
- DTE and ITE now are 8 bytes
- DTE and ITE now indexed by deviceid/eventid
- use ITE name instead of ITTE
- mentionsITT_addrmatches bits [51:8] of the actual address
- mentions LE layout--- Documentation/virtual/kvm/devices/arm-vgic-its.txt | 118 +++++++++++++++++++++ 1 file changed, 118 insertions(+)Documentation/virtual/kvm/devices/arm-vgic-its.txt +4
-0@@ -36,3 +36,121 @@ Groups: -ENXIO: ITS not properly configured as required prior to setting this attribute -ENOMEM: Memory shortage when allocating ITS internal data + + KVM_DEV_ARM_VGIC_GRP_ITS_REGS + Attributes: + The attr field of kvm_device_attr encodes the offset of the
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 52
Quoted 10 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +10
-0+ ITS register, relative to the ITS control frame base address + (ITS_base). + + kvm_device_attr.addr points to a __u64 value whatever the width + of the addressed register (32/64 bits). 64 bit registers can only + be accessed with full length. + + Writes to read-only registers are ignored by the kernel except for: + - GITS_READR. It needs to be restored otherwise commands in the queue + will be re-executed after CWRITER setting. Writing this register is
^^^^^^^^^^^^^^^
"after restoring CWRITER." ?
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 53
Quoted 1 line
Documentation/virtual/kvm/devices/arm-vgic-its.txt +1
-0+ allowed if the ITS is not enabled (GITS_CTLR.enable = 0). Also it
Does that mean that you can only save/restore a disabled ITS or does it mean that initially after creating the ITS it is disabled and userspace should restore the CWRITER before restoring GITS_CTLR (which may enable the ITS) ?
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 56
Quoted 3 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +3
-0+ needs to be restored after GITS_CBASER since a write to GITS_CBASER + resets GITS_CREADR. + - GITS_IIDR. Its Revision field encodes the table layout ABI revision.
How is this really going to work? Your ABI here must be backwards compatible for future revisions, so what is userspace supposed to do, when it reads a newer revision than it was programmed for?
I think we need a more clear description of how the revision is going to be used, such that each operation on the ITS here is described as requiring a minimum revision X, and making sure that userspace can safely ignore things that are of a higher revision number, while at the same time userspace can decide not to use newer features with older kernels.
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 66
Quoted 10 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +10
-0+ + For other registers, getting or setting a register has the same + effect as reading/writing the register on real hardware. + Errors: + -ENXIO: Offset does not correspond to any supported register + -EFAULT: Invalid user pointer for attr->addr + -EINVAL: Offset is not 64-bit aligned + -EBUSY: one or more VCPUS are running + + KVM_DEV_ARM_VGIC_GRP_ITS_TABLES
Shouldn't this be called KVM_DEV_ARM_VGIC_GRP_FLUSH_ITS_TABLES ?
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 70
Quoted 4 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +4
-0+ Attributes + The attr field of kvm_device_attr must be zero. + + request the flush-save/restore of the ITS tables, namely
Nit: Request (upper case R)
what does flush-save/restore mean as opposed to just flush?
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 72
Quoted 2 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +2
-0+ the device table, the collection table, all the ITT tables, + the LPI pending tables. On save, the tables are flushed
, and the LPI pending table.
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 77
Quoted 5 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +5
-0+ into guest memory at the location provisioned by the guest + in GITS_BASER (device and collection tables), in the MAPD + command (ITT_addr), GICR_PENDBASERs (pending tables). + + This means the GIC should be restored before the ITS and all
should or must? Is this enforced?
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 84
Quoted 7 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +7
-0+ ITS registers but the GITS_CTLR must be restored before + restoring the ITS tables. + + The GITS_READR and GITS_IIDR read-only registers must also + be restored before the table restore. The IIDR revision field + encodes the ABI revision of the table layout. If not set by + user space, the restoration of the tables will fail.
consider rewording: ", restoring the ITS tables will fail."
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 86
Quoted 2 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +2
-0+ + Note the LPI configuration table is read-only for the
Note that
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 87
Quoted 1 line
Documentation/virtual/kvm/devices/arm-vgic-its.txt +1
-0+ in-kernel ITS and its save/restore goes through the standard
and saving/restoring it is done via the normal process to save/restore guest RAM.
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 91
Quoted 4 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +4
-0+ RAM save/restore. + + The layout of the tables in guest memory defines an ABI. + The entries are laid in little endian format as follows;
s/;/:/
It's a bit weird to say "as follows:" and then proceed with the error descriptions. I would simply say "as described in the following paragraph."
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 101
Quoted 10 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +10
-0+ + Errors: + -EINVAL: kvm_device_attr not equal to 0, invalid table data + -EFAULT: invalid guest ram access + -EBUSY: one or more VCPUS are running + + ITS Table ABI REV1: + ------------------- + + The device table and ITE are respectively indexed by device id and
s/ITE/ITT/
are indexed by the device id and eventid, respectively.
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 102
Quoted 1 line
Documentation/virtual/kvm/devices/arm-vgic-its.txt +1
-0+ eventid. The collection table however is not indexed by collection id:
...by collection id, instead all the CTEs are written...
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 103
Quoted 1 line
Documentation/virtual/kvm/devices/arm-vgic-its.txt +1
-0+ CTE are written at the beginning of the buffer.
in any particular order, or?
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 113
Quoted 10 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +10
-0+ + Device Table Entry (DTE) layout: entry size = 8 bytes + + bits: | 63| 62 ... 49 | 48 ... 5 | 4 ... 0 | + values: | V | next | ITT_addr | Size | + + where; + - V indicates whether the entry is valid, + - ITT_addr matches bits [51:8] of the ITT address (256B aligned), + - next field is meaningful only if the entry is valid.
is the ITT_addr meaningful if the entry is not valid?
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 115
Quoted 2 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +2
-0+ It equals to 0 if this entry is the last one; otherwise it corresponds + to the minimum between the offset to the next device id and 2^14 -1.
I don't easily understand this last paragraph and the indentation is weird and makes it look like it's not explaining the next field.
You're missing a description of the size field. Size in what unit? Size of what?
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 123
Quoted 8 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +8
-0+ + Collection Table Entry (CTE) layout: entry size = 8 bytes + + bits: | 63| 62 .. 52 | 51 ... 16 | 15 ... 0 | + values: | V | RES0 | RDBase | ICID | + + where: + - V indicates whether the entry is valid,
Do we explain anywhere what RES0 means?
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 124
Quoted 1 line
Documentation/virtual/kvm/devices/arm-vgic-its.txt +1
-0+ - RDBase matches the PE number (GICR_TYPER.Processor_Number),
is 'matches' the right verb to use here?
What exactly is the format of GICR_TYPER.Processor_Number ?
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 125
Quoted 1 line
Documentation/virtual/kvm/devices/arm-vgic-its.txt +1
-0+ - ICID matches the collection ID
again, is 'matches' the right verb to use here?
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 134
Quoted 9 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +9
-0+ + Interrupt Translation Entry (ITE) layout: entry size = 8 bytes + + bits: | 63 ... 48 | 47 ... 16 | 15 ... 0 | + values: | next | pINTID | ICID | + + where: + - pINTID is the physical LPI ID, + - ICID is the collection ID,
here you use 'is' intead of 'matches'. At leat be consistent.
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 137
Quoted 3 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +3
-0+ - next field is meaningful only if the entry is valid (pINTID != 0). + It equals to 0 if this entry is the last one; otherwise it corresponds + to the minimum between the eventid offset to the next ITE and 2^16 -1.
same comments, as above.
also, can you list the field in the order they appear?
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 142
Quoted 5 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +5
-0+ + LPI Pending Table layout: + + As specified in the ARM Generic Interrupt Controller Architecture + Specification GIC Architecture version 3.0 and version 4. The first
"...version 4, the first". ("As specified in X." is not a sentence).
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 143
Quoted 1 line
Documentation/virtual/kvm/devices/arm-vgic-its.txt +1
-0+ 1kB is not modified and therefore should contain zeroes.
should or must? or always contains zeros? Will you return an error if userspace puts something non-zero in there?
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 148
Quoted 5 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +5
-0+ + Future evolutions of the ITS table layout: + + At the moment the table layout is defined and optimized for physical + LPI support.
This comment is a bit confusing, because this is all about virtual interrupts really, so 'physical from the point of view of the VM', but I think you should just drop this sentence.
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 150
Quoted 2 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +2
-0+ + In the future we might implement direct injection of virtual LPIS.
For nesting, yes? (on the host this should not be visible here, should it?)
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 154
Quoted 4 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +4
-0+ This will require an upgrade of the table layout and an evolution of + the ABI. The ABI revision is encoded in the GITS_IIDR revision field. + That register must be restored before the table restoration, otherwise + the operation will fail.
Hmm, I thought we dealt with that before, feels a bit out of place.
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 156
Quoted 2 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +2
-0+ + ABI V1: GITS_IIDR.Revision = 1
I feel like this should go in the ITS register description of the IIDR. Most likely, I think this particular line can be dropped, but all other definitions in this file can be annoted with a minimum revision number ensuring that future revisions implement this, plus potentially more stuff.
Thanks,
-Christoffer
Re: [PATCH v4 01/22] KVM: arm/arm64: Add vITS save/restore API documentation
Hi Christoffer,
Quoted 62 lines · Christoffer Dall
Hi Eric,
Most of my comments below are just me being picky about text when defining a user space ABI, so I think this mainly looks good, but just needs a bit of clarify, except the versioning aspect and exporting the pending table vie the redistributor instead, as Marc and Andre have pointed out.
Quoted 41 lines · Eric Auger
Add description for how to access vITS registers and how to flush/restore vITS tables into/from memory
Signed-off-by Eric Auger <[email protected]>---
v3 -> v4:
- take into account Peter's comments:
- typos
-KVM_DEV_ARM_VGIC_GRP_ITS_TABLESkvm_device_attr= 0
- add a validity bit in DTE
- document all fields in CTE and ITE
- document ABI revision
- take into account Andre's comments:
- document restrictions aboutGITS_CREADRwriting andGITS_IIDR
- document-EBUSYerror if one or more VCPUS are runnning
- document 64b registers only can be accessed with 64b access
-itt_addrfield matches bits [51:8] of theitt_addrv1 -> v2:
- DTE and ITE now are 8 bytes
- DTE and ITE now indexed by deviceid/eventid
- use ITE name instead of ITTE
- mentionsITT_addrmatches bits [51:8] of the actual address
- mentions LE layout--- Documentation/virtual/kvm/devices/arm-vgic-its.txt | 118 +++++++++++++++++++++ 1 file changed, 118 insertions(+)Documentation/virtual/kvm/devices/arm-vgic-its.txt +4
-0@@ -36,3 +36,121 @@ Groups: -ENXIO: ITS not properly configured as required prior to setting this attribute -ENOMEM: Memory shortage when allocating ITS internal data + + KVM_DEV_ARM_VGIC_GRP_ITS_REGS + Attributes: + The attr field of kvm_device_attr encodes the offset of theDocumentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 52
Quoted 10 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +10
-0+ ITS register, relative to the ITS control frame base address + (ITS_base). + + kvm_device_attr.addr points to a __u64 value whatever the width + of the addressed register (32/64 bits). 64 bit registers can only + be accessed with full length. + + Writes to read-only registers are ignored by the kernel except for: + - GITS_READR. It needs to be restored otherwise commands in the queue + will be re-executed after CWRITER setting. Writing this register is^^^^^^^^^^^^^^^
Quoted 1 line
"after restoring CWRITER." ?
OK
Quoted 7 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 53
Quoted 2 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +1
-0+ allowed if the ITS is not enabled (GITS_CTLR.enable = 0). Also itDoes that mean that you can only save/restore a disabled ITS or does it mean that initially after creating the ITS it is disabled and userspace should restore the CWRITER before restoring
GITS_CTLR(which may enable the ITS) ?
No I meant the second. As normally the ITS is responsible for updating the GITS_READR, if the userspace plays with it while the ITS is enabled this can mess everything. So the userspace is supposed to restore the GITS_READR *before* restoring the GITS_CTLR which is likely to enable the ITS.
Quoted 8 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 56
Quoted 4 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +3
-0+ needs to be restored after GITS_CBASER since a write to GITS_CBASER + resets GITS_CREADR. + - GITS_IIDR. Its Revision field encodes the table layout ABI revision.How is this really going to work? Your ABI here must be backwards compatible for future revisions, so what is userspace supposed to do, when it reads a newer revision than it was programmed for?
destination ABI revision must be >= source ABI revision
By restoring the IIDR value on the destination side, the userspace informs destination KVM about the layout of the table. If the destination KVM does not support this ABI revision, the restoration of the ITS table fails. Is that wrong?
Quoted 7 lines
I think we need a more clear description of how the revision is going to be used, such that each operation on the ITS here is described as requiring a minimum revision X, and making sure that userspace can safely ignore things that are of a higher revision number, while at the same time userspace can decide not to use newer features with older kernels.
At the moment I did not plan to implement any way for the userspace to force the ITS state save in a specified ABI revision. Today it uses the higher revision. Let's say that ABI V2 supports GICv4, save of source ITS with be done in v2 layout. A destination only supporting GICv3 (ABI v1) won't be able to read that format. Does it make sense?
Quoted 13 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 66
Quoted 11 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +10
-0+ + For other registers, getting or setting a register has the same + effect as reading/writing the register on real hardware. + Errors: + -ENXIO: Offset does not correspond to any supported register + -EFAULT: Invalid user pointer for attr->addr + -EINVAL: Offset is not 64-bit aligned + -EBUSY: one or more VCPUS are running + + KVM_DEV_ARM_VGIC_GRP_ITS_TABLESShouldn't this be called
KVM_DEV_ARM_VGIC_GRP_FLUSH_ITS_TABLES?
At the moment this group is used for flush and restore. But as you have the same remark as Andre I guess it is worth having separate commands in KVM_DEV_ARM_VGIC_GRP_CTRL then.
Quoted 7 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 70
Quoted 5 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +4
-0+ Attributes + The attr field of kvm_device_attr must be zero. + + request the flush-save/restore of the ITS tables, namelyNit: Request (upper case R)
OK
Quoted 2 lines
what does flush-save/restore mean as opposed to just flush?
meant flush/restore
Quoted 5 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 72
Quoted 3 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +2
-0+ the device table, the collection table, all the ITT tables, + the LPI pending tables. On save, the tables are flushed, and the LPI pending table.
OK
Quoted 8 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 77
Quoted 6 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +5
-0+ into guest memory at the location provisioned by the guest + in GITS_BASER (device and collection tables), in the MAPD + command (ITT_addr), GICR_PENDBASERs (pending tables). + + This means the GIC should be restored before the ITS and allshould or must? Is this enforced?
must. yes it is.
Quoted 10 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 84
Quoted 8 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +7
-0+ ITS registers but the GITS_CTLR must be restored before + restoring the ITS tables. + + The GITS_READR and GITS_IIDR read-only registers must also + be restored before the table restore. The IIDR revision field + encodes the ABI revision of the table layout. If not set by + user space, the restoration of the tables will fail.consider rewording: ", restoring the ITS tables will fail."
OK
Quoted 5 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 86
Quoted 3 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +2
-0+ + Note the LPI configuration table is read-only for theNote that
OK
Quoted 5 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 87
Quoted 2 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +1
-0+ in-kernel ITS and its save/restore goes through the standardand saving/restoring it is done via the normal process to save/restore guest RAM.
OK
Quoted 7 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 91
Quoted 5 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +4
-0+ RAM save/restore. + + The layout of the tables in guest memory defines an ABI. + The entries are laid in little endian format as follows;s/;/:/
OK
Quoted 4 lines
It's a bit weird to say "as follows:" and then proceed with the error descriptions. I would simply say "as described in the following paragraph."
OK
Quoted 13 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 101
Quoted 11 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +10
-0+ + Errors: + -EINVAL: kvm_device_attr not equal to 0, invalid table data + -EFAULT: invalid guest ram access + -EBUSY: one or more VCPUS are running + + ITS Table ABI REV1: + ------------------- + + The device table and ITE are respectively indexed by device id ands/ITE/ITT/
right
Quoted 10 lines
are indexed by the device id and eventid, respectively.
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 102
Quoted 1 line
Documentation/virtual/kvm/devices/arm-vgic-its.txt +1
-0+ eventid. The collection table however is not indexed by collection id:...by collection id, instead all the CTEs are written...
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 103
Quoted 1 line
Documentation/virtual/kvm/devices/arm-vgic-its.txt +1
-0+ CTE are written at the beginning of the buffer.in any particular order, or?
no order or creation
Quoted 13 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 113
Quoted 11 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +10
-0+ + Device Table Entry (DTE) layout: entry size = 8 bytes + + bits: | 63| 62 ... 49 | 48 ... 5 | 4 ... 0 | + values: | V | next | ITT_addr | Size | + + where; + - V indicates whether the entry is valid, + - ITT_addr matches bits [51:8] of the ITT address (256B aligned), + - next field is meaningful only if the entry is valid.is the
ITT_addrmeaningful if the entry is not valid?
no, I will add this detail.
Quoted 6 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 115
Quoted 3 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +2
-0+ It equals to 0 if this entry is the last one; otherwise it corresponds + to the minimum between the offset to the next device id and 2^14 -1.I don't easily understand this last paragraph and the indentation is weird and makes it look like it's not explaining the next field.
reworded:
It equals to 0 if this entry is the last one; otherwise it corresponds to the the deviceid offset to the next DTE, capped by 2^14 -1.
Quoted 3 lines
You're missing a description of the size field. Size in what unit? Size of what?
right, added "size matches the MAPD Size semantic."
Quoted 12 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 123
Quoted 10 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +8
-0+ + Collection Table Entry (CTE) layout: entry size = 8 bytes + + bits: | 63| 62 .. 52 | 51 ... 16 | 15 ... 0 | + values: | V | RES0 | RDBase | ICID | + + where: + - V indicates whether the entry is valid,Do we explain anywhere what RES0 means?
Added RES0: reserved field with Should-Be-Zero-or-Preserved behavior.
Quoted 4 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 124
Quoted 2 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +1
-0+ - RDBase matches the PE number (GICR_TYPER.Processor_Number),is 'matches' the right verb to use here?
is
Quoted 6 lines
What exactly is the format of GICR_TYPER.Processor_Number ?
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 125
Quoted 1 line
Documentation/virtual/kvm/devices/arm-vgic-its.txt +1
-0+ - ICID matches the collection IDagain, is 'matches' the right verb to use here?
is
Quoted 12 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 134
Quoted 10 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +9
-0+ + Interrupt Translation Entry (ITE) layout: entry size = 8 bytes + + bits: | 63 ... 48 | 47 ... 16 | 15 ... 0 | + values: | next | pINTID | ICID | + + where: + - pINTID is the physical LPI ID, + - ICID is the collection ID,here you use 'is' intead of 'matches'. At leat be consistent.
is
Quoted 6 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 137
Quoted 4 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +3
-0+ - next field is meaningful only if the entry is valid (pINTID != 0). + It equals to 0 if this entry is the last one; otherwise it corresponds + to the minimum between the eventid offset to the next ITE and 2^16 -1.same comments, as above.
ok
Quoted 2 lines
also, can you list the field in the order they appear?
ok
Quoted 9 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 142
Quoted 6 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +5
-0+ + LPI Pending Table layout: + + As specified in the ARM Generic Interrupt Controller Architecture + Specification GIC Architecture version 3.0 and version 4. The first"...version 4, the first". ("As specified in X." is not a sentence).
Quoted 4 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 143
Quoted 1 line
Documentation/virtual/kvm/devices/arm-vgic-its.txt +1
-0+ 1kB is not modified and therefore should contain zeroes.should or must? or always contains zeros? Will you return an error if userspace puts something non-zero in there?
no I don't. Spec says it should initialized to zero. $
Quoted 10 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 148
Quoted 6 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +5
-0+ + Future evolutions of the ITS table layout: + + At the moment the table layout is defined and optimized for physical + LPI support.This comment is a bit confusing, because this is all about virtual interrupts really, so 'physical from the point of view of the VM', but I think you should just drop this sentence.
OK
Quoted 6 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 150
Quoted 3 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +2
-0+ + In the future we might implement direct injection of virtual LPIS.For nesting, yes? (on the host this should not be visible here, should it?)
yes for nesting.
Quoted 7 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 154
Quoted 5 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +4
-0+ This will require an upgrade of the table layout and an evolution of + the ABI. The ABI revision is encoded in the GITS_IIDR revision field. + That register must be restored before the table restoration, otherwise + the operation will fail.Hmm, I thought we dealt with that before, feels a bit out of place.
OK moved to the register description.
Quoted 9 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 156
Quoted 3 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +2
-0+ + ABI V1: GITS_IIDR.Revision = 1I feel like this should go in the ITS register description of the IIDR. Most likely, I think this particular line can be dropped, but all other definitions in this file can be annoted with a minimum revision number ensuring that future revisions implement this, plus potentially more stuff.
I already put the following title, "ITS Table ABI REV1" for the table layout description. My intent was to create a new chapter per revision. Is it OK?
Thanks
Eric
Quoted 9 lines
Thanks,
-Christoffer_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v4 01/22] KVM: arm/arm64: Add vITS save/restore API documentation
Quoted 84 lines · Auger Eric
Hi Christoffer,
Quoted 62 lines · Christoffer Dall
Hi Eric,
Most of my comments below are just me being picky about text when defining a user space ABI, so I think this mainly looks good, but just needs a bit of clarify, except the versioning aspect and exporting the pending table vie the redistributor instead, as Marc and Andre have pointed out.
Quoted 41 lines · Eric Auger
Add description for how to access vITS registers and how to flush/restore vITS tables into/from memory
Signed-off-by Eric Auger <[email protected]>---
v3 -> v4:
- take into account Peter's comments:
- typos
-KVM_DEV_ARM_VGIC_GRP_ITS_TABLESkvm_device_attr= 0
- add a validity bit in DTE
- document all fields in CTE and ITE
- document ABI revision
- take into account Andre's comments:
- document restrictions aboutGITS_CREADRwriting andGITS_IIDR
- document-EBUSYerror if one or more VCPUS are runnning
- document 64b registers only can be accessed with 64b access
-itt_addrfield matches bits [51:8] of theitt_addrv1 -> v2:
- DTE and ITE now are 8 bytes
- DTE and ITE now indexed by deviceid/eventid
- use ITE name instead of ITTE
- mentionsITT_addrmatches bits [51:8] of the actual address
- mentions LE layout--- Documentation/virtual/kvm/devices/arm-vgic-its.txt | 118 +++++++++++++++++++++ 1 file changed, 118 insertions(+)Documentation/virtual/kvm/devices/arm-vgic-its.txt +4
-0@@ -36,3 +36,121 @@ Groups: -ENXIO: ITS not properly configured as required prior to setting this attribute -ENOMEM: Memory shortage when allocating ITS internal data + + KVM_DEV_ARM_VGIC_GRP_ITS_REGS + Attributes: + The attr field of kvm_device_attr encodes the offset of theDocumentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 52
Quoted 10 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +10
-0+ ITS register, relative to the ITS control frame base address + (ITS_base). + + kvm_device_attr.addr points to a __u64 value whatever the width + of the addressed register (32/64 bits). 64 bit registers can only + be accessed with full length. + + Writes to read-only registers are ignored by the kernel except for: + - GITS_READR. It needs to be restored otherwise commands in the queue + will be re-executed after CWRITER setting. Writing this register is^^^^^^^^^^^^^^^Quoted 1 line
"after restoring CWRITER." ?
OK
Quoted 7 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 53
Quoted 2 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +1
-0+ allowed if the ITS is not enabled (GITS_CTLR.enable = 0). Also itDoes that mean that you can only save/restore a disabled ITS or does it mean that initially after creating the ITS it is disabled and userspace should restore the CWRITER before restoring
GITS_CTLR(which may enable the ITS) ?No I meant the second. As normally the ITS is responsible for updating the
GITS_READR, if the userspace plays with it while the ITS is enabled this can mess everything. So the userspace is supposed to restore theGITS_READR*before* restoring theGITS_CTLRwhich is likely to enable the ITS.Quoted 5 lines
Quoted 4 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +3
-0+ needs to be restored after GITS_CBASER since a write to GITS_CBASER + resets GITS_CREADR. + - GITS_IIDR. Its Revision field encodes the table layout ABI revision.
Quoted 9 lines
Quoted 3 lines
How is this really going to work? Your ABI here must be backwards compatible for future revisions, so what is userspace supposed to do, when it reads a newer revision than it was programmed for?
destination ABI revision must be >= source ABI revision
By restoring the IIDR value on the destination side, the userspace informs destination KVM about the layout of the table. If the destination KVM does not support this ABI revision, the restoration of the ITS table fails. Is that wrong?
No, that's fine. I think my confusion was that I didn't appreciate that the revision thing is for the table layouts only, and not the other calls here.
Quoted 8 lines
Quoted 7 lines
I think we need a more clear description of how the revision is going to be used, such that each operation on the ITS here is described as requiring a minimum revision X, and making sure that userspace can safely ignore things that are of a higher revision number, while at the same time userspace can decide not to use newer features with older kernels.
Quoted 6 lines
At the moment I did not plan to implement any way for the userspace to force the ITS state save in a specified ABI revision. Today it uses the higher revision. Let's say that ABI V2 supports GICv4, save of source ITS with be done in v2 layout. A destination only supporting GICv3 (ABI v1) won't be able to read that format. Does it make sense?
That makes sense, yes.
Quoted 95 lines
Quoted 13 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 66
Quoted 11 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +10
-0+ + For other registers, getting or setting a register has the same + effect as reading/writing the register on real hardware. + Errors: + -ENXIO: Offset does not correspond to any supported register + -EFAULT: Invalid user pointer for attr->addr + -EINVAL: Offset is not 64-bit aligned + -EBUSY: one or more VCPUS are running + + KVM_DEV_ARM_VGIC_GRP_ITS_TABLESShouldn't this be called
KVM_DEV_ARM_VGIC_GRP_FLUSH_ITS_TABLES?At the moment this group is used for flush and restore. But as you have the same remark as Andre I guess it is worth having separate commands in
KVM_DEV_ARM_VGIC_GRP_CTRLthen.Quoted 7 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 70
Quoted 5 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +4
-0+ Attributes + The attr field of kvm_device_attr must be zero. + + request the flush-save/restore of the ITS tables, namelyNit: Request (upper case R)
OK
Quoted 2 lines
what does flush-save/restore mean as opposed to just flush?
meant flush/restore
Quoted 5 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 72
Quoted 3 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +2
-0+ the device table, the collection table, all the ITT tables, + the LPI pending tables. On save, the tables are flushed, and the LPI pending table.
OK
Quoted 8 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 77
Quoted 6 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +5
-0+ into guest memory at the location provisioned by the guest + in GITS_BASER (device and collection tables), in the MAPD + command (ITT_addr), GICR_PENDBASERs (pending tables). + + This means the GIC should be restored before the ITS and allshould or must? Is this enforced?
must. yes it is.
Quoted 10 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 84
Quoted 8 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +7
-0+ ITS registers but the GITS_CTLR must be restored before + restoring the ITS tables. + + The GITS_READR and GITS_IIDR read-only registers must also + be restored before the table restore. The IIDR revision field + encodes the ABI revision of the table layout. If not set by + user space, the restoration of the tables will fail.consider rewording: ", restoring the ITS tables will fail."
OK
Quoted 5 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 86
Quoted 3 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +2
-0+ + Note the LPI configuration table is read-only for theNote that
OK
Quoted 5 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 87
Quoted 2 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +1
-0+ in-kernel ITS and its save/restore goes through the standardand saving/restoring it is done via the normal process to save/restore guest RAM.
OK
Quoted 7 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 91
Quoted 5 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +4
-0+ RAM save/restore. + + The layout of the tables in guest memory defines an ABI. + The entries are laid in little endian format as follows;s/;/:/
OK
Quoted 4 lines
It's a bit weird to say "as follows:" and then proceed with the error descriptions. I would simply say "as described in the following paragraph."
OK
Quoted 13 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 101
Quoted 11 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +10
-0+ + Errors: + -EINVAL: kvm_device_attr not equal to 0, invalid table data + -EFAULT: invalid guest ram access + -EBUSY: one or more VCPUS are running + + ITS Table ABI REV1: + ------------------- + + The device table and ITE are respectively indexed by device id ands/ITE/ITT/
right
Quoted 3 lines
are indexed by the device id and eventid, respectively.
Quoted 8 lines
Quoted 7 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 102
Quoted 1 line
Documentation/virtual/kvm/devices/arm-vgic-its.txt +1
-0+ eventid. The collection table however is not indexed by collection id:...by collection id, instead all the CTEs are written...
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 103
Quoted 1 line
Documentation/virtual/kvm/devices/arm-vgic-its.txt +1
-0+ CTE are written at the beginning of the buffer.in any particular order, or?
no order or creation
Probably good to point that out.
Quoted 121 lines
Quoted 13 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 113
Quoted 11 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +10
-0+ + Device Table Entry (DTE) layout: entry size = 8 bytes + + bits: | 63| 62 ... 49 | 48 ... 5 | 4 ... 0 | + values: | V | next | ITT_addr | Size | + + where; + - V indicates whether the entry is valid, + - ITT_addr matches bits [51:8] of the ITT address (256B aligned), + - next field is meaningful only if the entry is valid.is the
ITT_addrmeaningful if the entry is not valid?no, I will add this detail.
Quoted 6 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 115
Quoted 3 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +2
-0+ It equals to 0 if this entry is the last one; otherwise it corresponds + to the minimum between the offset to the next device id and 2^14 -1.I don't easily understand this last paragraph and the indentation is weird and makes it look like it's not explaining the next field.
reworded:
It equals to 0 if this entry is the last one; otherwise it corresponds to the the deviceid offset to the next DTE, capped by 2^14 -1.Quoted 3 lines
You're missing a description of the size field. Size in what unit? Size of what?
right, added "size matches the MAPD Size semantic."
Quoted 12 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 123
Quoted 10 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +8
-0+ + Collection Table Entry (CTE) layout: entry size = 8 bytes + + bits: | 63| 62 .. 52 | 51 ... 16 | 15 ... 0 | + values: | V | RES0 | RDBase | ICID | + + where: + - V indicates whether the entry is valid,Do we explain anywhere what RES0 means?
Added RES0: reserved field with Should-Be-Zero-or-Preserved behavior.
Quoted 4 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 124
Quoted 2 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +1
-0+ - RDBase matches the PE number (GICR_TYPER.Processor_Number),is 'matches' the right verb to use here?
is
Quoted 6 lines
What exactly is the format of GICR_TYPER.Processor_Number ?
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 125
Quoted 1 line
Documentation/virtual/kvm/devices/arm-vgic-its.txt +1
-0+ - ICID matches the collection IDagain, is 'matches' the right verb to use here?
is
Quoted 12 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 134
Quoted 10 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +9
-0+ + Interrupt Translation Entry (ITE) layout: entry size = 8 bytes + + bits: | 63 ... 48 | 47 ... 16 | 15 ... 0 | + values: | next | pINTID | ICID | + + where: + - pINTID is the physical LPI ID, + - ICID is the collection ID,here you use 'is' intead of 'matches'. At leat be consistent.
is
Quoted 6 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 137
Quoted 4 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +3
-0+ - next field is meaningful only if the entry is valid (pINTID != 0). + It equals to 0 if this entry is the last one; otherwise it corresponds + to the minimum between the eventid offset to the next ITE and 2^16 -1.same comments, as above.
ok
Quoted 2 lines
also, can you list the field in the order they appear?
ok
Quoted 9 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 142
Quoted 6 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +5
-0+ + LPI Pending Table layout: + + As specified in the ARM Generic Interrupt Controller Architecture + Specification GIC Architecture version 3.0 and version 4. The first"...version 4, the first". ("As specified in X." is not a sentence).
Quoted 4 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 143
Quoted 1 line
Documentation/virtual/kvm/devices/arm-vgic-its.txt +1
-0+ 1kB is not modified and therefore should contain zeroes.should or must? or always contains zeros? Will you return an error if userspace puts something non-zero in there?
no I don't. Spec says it should initialized to zero. $
Quoted 10 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 148
Quoted 6 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +5
-0+ + Future evolutions of the ITS table layout: + + At the moment the table layout is defined and optimized for physical + LPI support.This comment is a bit confusing, because this is all about virtual interrupts really, so 'physical from the point of view of the VM', but I think you should just drop this sentence.
OK
Quoted 6 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 150
Quoted 3 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +2
-0+ + In the future we might implement direct injection of virtual LPIS.For nesting, yes? (on the host this should not be visible here, should it?)
yes for nesting.
Quoted 7 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt Groups: · line 154
Quoted 5 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +4
-0+ This will require an upgrade of the table layout and an evolution of + the ABI. The ABI revision is encoded in the GITS_IIDR revision field. + That register must be restored before the table restoration, otherwise + the operation will fail.Hmm, I thought we dealt with that before, feels a bit out of place.
OK moved to the register description.
Quoted 4 lines
Quoted 3 lines
Documentation/virtual/kvm/devices/arm-vgic-its.txt +2
-0+ + ABI V1: GITS_IIDR.Revision = 1
Quoted 9 lines
Quoted 5 lines
I feel like this should go in the ITS register description of the IIDR. Most likely, I think this particular line can be dropped, but all other definitions in this file can be annoted with a minimum revision number ensuring that future revisions implement this, plus potentially more stuff.
I already put the following title, "ITS Table ABI REV1" for the table layout description. My intent was to create a new chapter per revision. Is it OK?
I'll have a look at the next revision.
Thanks for responding to all my comments.
-Christoffer
PATCH v4 2/22 KVM: arm/arm64: rename itte into ite
In reply to Eric AugerThe actual abbreviation for the interrupt translation table entry is ITE. Let's rename all itte instances by ite.
--- virt/kvm/arm/vgic/vgic-its.c | 148 +++++++++++++++++++++---------------------- 1 file changed, 74 insertions(+), 74 deletions(-)
virt/kvm/arm/vgic/vgic-its.c +74 -74
@@ -114,8 +114,8 @@ struct its_collection {#define its_is_collection_mapped (coll) ((coll) && \ ((coll)->target_addr != COLLECTION_NOT_MAPPED)) -struct its_itte { -struct list_head itte_list; +struct its_ite { +struct list_head ite_list;struct vgic_irq *irq;struct its_collection *collection;
@@ -143,27 +143,27 @@ static struct its_device *find_its_device(struct vgic_its *its, u32 device_id)* Device ID/Event ID pair on an ITS. * Must be called with the its_lock mutex held. */ -static struct its_itte *find_itte (struct vgic_its *its,u32 device_id, +static struct its_ite *find_ite (struct vgic_its *its,u32 device_id,u32 event_id) {struct its_device *device; -struct its_itte *itte; +struct its_ite *ite; device =find_its_device (its, device_id);if (device ==NULL )return NULL ; -list_for_each_entry (itte, &device->itt_head, itte_list) -if (itte->event_id == event_id) -return itte; +list_for_each_entry (ite, &device->itt_head, ite_list) +if (ite->event_id == event_id) +return ite;return NULL ; }/* To be used as an iterator this macro misses the enclosing parentheses */ -#define for_each_lpi_its (dev, itte, its) \ +#define for_each_lpi_its (dev, ite, its) \ list_for_each_entry(dev, &(its)->device_list, dev_list) \ - list_for_each_entry(itte, &(dev)->itt_head, itte_list) + list_for_each_entry(ite, &(dev)->itt_head, ite_list)/* * We only implement 48 bits of PA at the moment, although the ITS
@@ -270,18 +270,18 @@ static int vgic_copy_lpi_list(struct kvm *kvm, u32 **intid_ptr)* Needs to be called whenever either the collection for a LPIs has * changed or the collection itself got retargeted. */ -static void update_affinity_itte (struct kvm *kvm,struct its_itte *itte) +static void update_affinity_ite (struct kvm *kvm,struct its_ite *ite) {struct kvm_vcpu *vcpu; -if (!its_is_collection_mapped (itte->collection)) +if (!its_is_collection_mapped (ite->collection))return ; - vcpu =kvm_get_vcpu (kvm, itte->collection->target_addr); + vcpu =kvm_get_vcpu (kvm, ite->collection->target_addr); -spin_lock (&itte->irq->irq_lock); - itte->irq->target_vcpu = vcpu; -spin_unlock (&itte->irq->irq_lock); +spin_lock (&ite->irq->irq_lock); + ite->irq->target_vcpu = vcpu; +spin_unlock (&ite->irq->irq_lock); }/*
@@ -292,13 +292,13 @@ static void update_affinity_collection(struct kvm *kvm, struct vgic_its *its, struct its_collection *coll) {struct its_device *device; -struct its_itte *itte; +struct its_ite *ite; -for_each_lpi_its (device, itte, its) { -if (!itte->collection || coll != itte->collection) +for_each_lpi_its (device, ite, its) { +if (!ite->collection || coll != ite->collection)continue ; -update_affinity_itte (kvm, itte); +update_affinity_ite (kvm, ite); } }
@@ -425,25 +425,25 @@ static int vgic_its_trigger_msi(struct kvm *kvm, struct vgic_its *its, u32 devid, u32 eventid) {struct kvm_vcpu *vcpu; -struct its_itte *itte; +struct its_ite *ite;if (!its->enabled)return -EBUSY ; - itte =find_itte (its, devid, eventid); -if (!itte || !its_is_collection_mapped (itte->collection)) + ite =find_ite (its, devid, eventid); +if (!ite || !its_is_collection_mapped (ite->collection))return E_ITS_INT_UNMAPPED_INTERRUPT ; - vcpu =kvm_get_vcpu (kvm, itte->collection->target_addr); + vcpu =kvm_get_vcpu (kvm, ite->collection->target_addr);if (!vcpu)return E_ITS_INT_UNMAPPED_INTERRUPT ;if (!vcpu->arch.vgic_cpu.lpis_enabled)return -EBUSY ; -spin_lock (&itte->irq->irq_lock); - itte->irq->pending_latch = true; -vgic_queue_irq_unlock (kvm, itte->irq); +spin_lock (&ite->irq->irq_lock); + ite->irq->pending_latch = true; +vgic_queue_irq_unlock (kvm, ite->irq);return 0 ; }
@@ -511,15 +511,15 @@ int vgic_its_inject_msi(struct kvm *kvm, struct kvm_msi *msi) }/* Requires the its_lock to be held. */ -static void its_free_itte (struct kvm *kvm,struct its_itte *itte) +static void its_free_ite (struct kvm *kvm,struct its_ite *ite) { -list_del (&itte->itte_list); +list_del (&ite->ite_list);/* This put matches the get in vgic_add_lpi. */ -if (itte->irq) -vgic_put_irq (kvm, itte->irq); +if (ite->irq) +vgic_put_irq (kvm, ite->irq); -kfree (itte); +kfree (ite); }static u64 its_cmd_mask_field (u64 *its_cmd,int word,int shift,int size)
@@ -544,17 +544,17 @@ static int vgic_its_cmd_handle_discard(struct kvm *kvm, struct vgic_its *its, {u32 device_id =its_cmd_get_deviceid (its_cmd);u32 event_id =its_cmd_get_id (its_cmd); -struct its_itte *itte; +struct its_ite *ite; - itte =find_itte (its, device_id, event_id); -if (itte && itte->collection) { + ite =find_ite (its, device_id, event_id); +if (ite && ite->collection) {/* * Though the spec talks about removing the pending state, we * don't bother here since we clear the ITTE anyway and the * pending state is a property of the ITTE struct. */ -its_free_itte (kvm, itte); +its_free_ite (kvm, ite);return 0 ; }
@@ -572,26 +572,26 @@ static int vgic_its_cmd_handle_movi(struct kvm *kvm, struct vgic_its *its,u32 event_id =its_cmd_get_id (its_cmd);u32 coll_id =its_cmd_get_collection (its_cmd);struct kvm_vcpu *vcpu; -struct its_itte *itte; +struct its_ite *ite;struct its_collection *collection; - itte =find_itte (its, device_id, event_id); -if (!itte) + ite =find_ite (its, device_id, event_id); +if (!ite)return E_ITS_MOVI_UNMAPPED_INTERRUPT ; -if (!its_is_collection_mapped (itte->collection)) +if (!its_is_collection_mapped (ite->collection))return E_ITS_MOVI_UNMAPPED_COLLECTION ; collection =find_collection (its, coll_id);if (!its_is_collection_mapped (collection))return E_ITS_MOVI_UNMAPPED_COLLECTION ; - itte->collection = collection; + ite->collection = collection; vcpu =kvm_get_vcpu (kvm, collection->target_addr); -spin_lock (&itte->irq->irq_lock); - itte->irq->target_vcpu = vcpu; -spin_unlock (&itte->irq->irq_lock); +spin_lock (&ite->irq->irq_lock); + ite->irq->target_vcpu = vcpu; +spin_unlock (&ite->irq->irq_lock);return 0 ; }
@@ -679,7 +679,7 @@ static void vgic_its_free_collection(struct vgic_its *its, u32 coll_id) {struct its_collection *collection;struct its_device *device; -struct its_itte *itte; +struct its_ite *ite;/* * Clearing the mapping for that collection ID removes the
@@ -690,10 +690,10 @@ static void vgic_its_free_collection(struct vgic_its *its, u32 coll_id)if (!collection)return ; -for_each_lpi_its (device, itte, its) -if (itte->collection && - itte->collection->collection_id == coll_id) - itte->collection =NULL ; +for_each_lpi_its (device, ite, its) +if (ite->collection && + ite->collection->collection_id == coll_id) + ite->collection =NULL ;list_del (&collection->coll_list);kfree (collection);
@@ -709,7 +709,7 @@ static int vgic_its_cmd_handle_mapi(struct kvm *kvm, struct vgic_its *its,u32 device_id =its_cmd_get_deviceid (its_cmd);u32 event_id =its_cmd_get_id (its_cmd);u32 coll_id =its_cmd_get_collection (its_cmd); -struct its_itte *itte; +struct its_ite *ite;struct its_device *device;struct its_collection *collection, *new_coll =NULL ;int lpi_nr;
@@ -728,7 +728,7 @@ static int vgic_its_cmd_handle_mapi(struct kvm *kvm, struct vgic_its *its,return E_ITS_MAPTI_PHYSICALID_OOR ;/* If there is an existing mapping, behavior is UNPREDICTABLE. */ -if (find_itte (its, device_id, event_id)) +if (find_ite (its, device_id, event_id))return 0 ; collection =find_collection (its, coll_id);
@@ -739,36 +739,36 @@ static int vgic_its_cmd_handle_mapi(struct kvm *kvm, struct vgic_its *its, new_coll = collection; } - itte =kzalloc (sizeof (struct its_itte ),GFP_KERNEL ); -if (!itte) { + ite =kzalloc (sizeof (struct its_ite ),GFP_KERNEL ); +if (!ite) {if (new_coll)vgic_its_free_collection (its, coll_id);return -ENOMEM ; } - itte->event_id = event_id; -list_add_tail (&itte->itte_list, &device->itt_head); + ite->event_id = event_id; +list_add_tail (&ite->ite_list, &device->itt_head); - itte->collection = collection; - itte->lpi = lpi_nr; + ite->collection = collection; + ite->lpi = lpi_nr; irq =vgic_add_lpi (kvm, lpi_nr);if (IS_ERR (irq)) {if (new_coll)vgic_its_free_collection (its, coll_id); -its_free_itte (kvm, itte); +its_free_ite (kvm, ite);return PTR_ERR (irq); } - itte->irq = irq; + ite->irq = irq; -update_affinity_itte (kvm, itte); +update_affinity_ite (kvm, ite);/* * We "cache" the configuration table entries in out struct vgic_irq's. * However we only have those structs for mapped IRQs, so we read in * the respective config data from memory here upon mapping the LPI. */ -update_lpi_config (kvm, itte->irq,NULL ); +update_lpi_config (kvm, ite->irq,NULL );return 0 ; }
@@ -776,15 +776,15 @@ static int vgic_its_cmd_handle_mapi(struct kvm *kvm, struct vgic_its *its,/* Requires the its_lock to be held. */ static void vgic_its_unmap_device (struct kvm *kvm,struct its_device *device) { -struct its_itte *itte, *temp; +struct its_ite *ite, *temp;/* * The spec says that unmapping a device with still valid * ITTEs associated is UNPREDICTABLE. We remove all ITTEs, * since we cannot leave the memory unreferenced. */ -list_for_each_entry_safe (itte, temp, &device->itt_head, itte_list) -its_free_itte (kvm, itte); +list_for_each_entry_safe (ite, temp, &device->itt_head, ite_list) +its_free_ite (kvm, ite);list_del (&device->dev_list);kfree (device);
@@ -883,14 +883,14 @@ static int vgic_its_cmd_handle_clear(struct kvm *kvm, struct vgic_its *its, {u32 device_id =its_cmd_get_deviceid (its_cmd);u32 event_id =its_cmd_get_id (its_cmd); -struct its_itte *itte; +struct its_ite *ite; - itte =find_itte (its, device_id, event_id); -if (!itte) + ite =find_ite (its, device_id, event_id); +if (!ite)return E_ITS_CLEAR_UNMAPPED_INTERRUPT ; - itte->irq->pending_latch = false; + ite->irq->pending_latch = false;return 0 ; }
@@ -904,14 +904,14 @@ static int vgic_its_cmd_handle_inv(struct kvm *kvm, struct vgic_its *its, {u32 device_id =its_cmd_get_deviceid (its_cmd);u32 event_id =its_cmd_get_id (its_cmd); -struct its_itte *itte; +struct its_ite *ite; - itte =find_itte (its, device_id, event_id); -if (!itte) + ite =find_ite (its, device_id, event_id); +if (!ite)return E_ITS_INV_UNMAPPED_INTERRUPT ; -return update_lpi_config (kvm, itte->irq,NULL ); +return update_lpi_config (kvm, ite->irq,NULL ); }/*
@@ -1435,7 +1435,7 @@ static void vgic_its_destroy(struct kvm_device *kvm_dev)struct kvm *kvm = kvm_dev->kvm;struct vgic_its *its = kvm_dev->private;struct its_device *dev; -struct its_itte *itte; +struct its_ite *ite;struct list_head *dev_cur, *dev_temp;struct list_head *cur, *temp;
@@ -1450,8 +1450,8 @@ static void vgic_its_destroy(struct kvm_device *kvm_dev)list_for_each_safe (dev_cur, dev_temp, &its->device_list) { dev = container_of(dev_cur, struct its_device, dev_list);list_for_each_safe (cur, temp, &dev->itt_head) { - itte = (container_of(cur, struct its_itte, itte_list)); -its_free_itte (kvm, itte); + ite = (container_of(cur, struct its_ite, ite_list)); +its_free_ite (kvm, ite); }list_del (dev_cur);kfree (dev);
Signature · 1 line
2.5.5
Re: [PATCH v4 02/22] KVM: arm/arm64: rename itte into ite
Quoted 4 lines · Eric Auger
The actual abbreviation for the interrupt translation table entry is ITE. Let's rename all itte instances by ite.
Signed-off-by Eric Auger <[email protected]>
M.
Signature · 1 line
Jazz is not dead. It just smells funny.
PATCH v4 3/22 arm/arm64: vgic: turn vgic_find_mmio_region into public
In reply to Eric AugerWe plan to use vgic_find_mmio_region in vgic-its.c so let's turn it into a public function.
Also let's take the opportunity to rename the region parameter into regions to emphasize this latter is an array of regions.
---
v3 -> v4:
- rename region parameter into regions
- add Andre's R-b
--- virt/kvm/arm/vgic/vgic-mmio.c | 11 +++++------ virt/kvm/arm/vgic/vgic-mmio.h | 5 +++++ 2 files changed, 10 insertions(+), 6 deletions(-)
virt/kvm/arm/vgic/vgic-mmio.c +5 -6
@@ -446,13 +446,12 @@ static int match_region(const void *key, const void *elt)return 0 ; } -/* Find the proper register handler entry given a certain address offset. */ -static const struct vgic_register_region * -vgic_find_mmio_region (const struct vgic_register_region *region,int nr_regions, -unsigned int offset) +const struct vgic_register_region * +vgic_find_mmio_region (const struct vgic_register_region *regions, +int nr_regions,unsigned int offset) { -return bsearch ((void *)(uintptr_t )offset, region, nr_regions, -sizeof (region[0 ]), match_region); +return bsearch ((void *)(uintptr_t )offset, regions, nr_regions, +sizeof (regions[0 ]), match_region); }void vgic_set_vmcr (struct kvm_vcpu *vcpu,struct vgic_vmcr *vmcr)
virt/kvm/arm/vgic/vgic-mmio.h +5 -0
@@ -192,4 +192,9 @@ u64 vgic_sanitise_shareability(u64 reg);u64 vgic_sanitise_field (u64 reg,u64 field_mask,int field_shift,u64 (*sanitise_fn)(u64 )); +/* Find the proper register handler entry given a certain address offset */ +const struct vgic_register_region * +vgic_find_mmio_region (const struct vgic_register_region *regions, +int nr_regions,unsigned int offset); +#endif
Signature · 1 line
2.5.5
Re: [PATCH v4 03/22] arm/arm64: vgic: turn vgic_find_mmio_region into public
Quoted 8 lines · Eric Auger
We plan to use
vgic_find_mmio_regioninvgic-its.cso let's turn it into a public function.Also let's take the opportunity to rename the region parameter into regions to emphasize this latter is an array of regions.
Signed-off-by Eric Auger <[email protected]>Reviewed-by Andre Przywara <[email protected]>
M.
Signature · 1 line
Jazz is not dead. It just smells funny.
PATCH v4 4/22 KVM: arm64: ITS: KVM_DEV_ARM_VGIC_GRP_ITS_REGS group
In reply to Eric AugerThe ITS KVM device exposes a new KVM_DEV_ARM_VGIC_GRP_ITS_REGS group which allows the userspace to save/restore ITS registers.
At this stage the get/set/has operations are not yet implemented.
---
v3 -> v4:
- added Andre's R-b
--- arch/arm/include/uapi/asm/kvm.h | 1 + arch/arm64/include/uapi/asm/kvm.h | 1 + virt/kvm/arm/vgic/vgic-its.c | 36 +++++++++++++++++++++++++++++++++++- 3 files changed, 37 insertions(+), 1 deletion(-)
arch/arm/include/uapi/asm/kvm.h +1 -0
@@ -192,6 +192,7 @@ struct kvm_arch_memory_slot {#define KVM_DEV_ARM_VGIC_GRP_REDIST_REGS 5#define KVM_DEV_ARM_VGIC_GRP_CPU_SYSREGS 6#define KVM_DEV_ARM_VGIC_GRP_LEVEL_INFO 7 +#define KVM_DEV_ARM_VGIC_GRP_ITS_REGS 8#define KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_SHIFT 10#define KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_MASK \ (0x3fffffULL << KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_SHIFT)
arch/arm64/include/uapi/asm/kvm.h +1 -0
@@ -212,6 +212,7 @@ struct kvm_arch_memory_slot {#define KVM_DEV_ARM_VGIC_GRP_REDIST_REGS 5#define KVM_DEV_ARM_VGIC_GRP_CPU_SYSREGS 6#define KVM_DEV_ARM_VGIC_GRP_LEVEL_INFO 7 +#define KVM_DEV_ARM_VGIC_GRP_ITS_REGS 8#define KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_SHIFT 10#define KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_MASK \ (0x3fffffULL << KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_SHIFT)
virt/kvm/arm/vgic/vgic-its.c +35 -1
@@ -1466,6 +1466,19 @@ static void vgic_its_destroy(struct kvm_device *kvm_dev)kfree (its); } +int vgic_its_has_attr_regs (struct kvm_device *dev, +struct kvm_device_attr *attr) +{ +return -ENXIO ; +} + +int vgic_its_attr_regs_access (struct kvm_device *dev, +struct kvm_device_attr *attr, +u64 *reg,bool is_write) +{ +return -ENXIO ; +} +static int vgic_its_has_attr (struct kvm_device *dev,struct kvm_device_attr *attr) {
@@ -1482,6 +1495,8 @@ static int vgic_its_has_attr(struct kvm_device *dev,return 0 ; }break ; +case KVM_DEV_ARM_VGIC_GRP_ITS_REGS : +return vgic_its_has_attr_regs (dev, attr); }return -ENXIO ; }
@@ -1521,6 +1536,15 @@ static int vgic_its_set_attr(struct kvm_device *dev,return 0 ; }break ; +case KVM_DEV_ARM_VGIC_GRP_ITS_REGS : { +u64 __user *uaddr = (u64 __user *)(long )attr->addr; +u64 reg; + +if (get_user (reg, uaddr)) +return -EFAULT ; + +return vgic_its_attr_regs_access (dev, attr, ®, true); + } }return -ENXIO ; }
@@ -1541,10 +1565,20 @@ static int vgic_its_get_attr(struct kvm_device *dev,if (copy_to_user (uaddr, &addr,sizeof (addr)))return -EFAULT ;break ; + } +case KVM_DEV_ARM_VGIC_GRP_ITS_REGS : { +u64 __user *uaddr = (u64 __user *)(long )attr->addr; +u64 reg; +int ret; + + ret =vgic_its_attr_regs_access (dev, attr, ®, false); +if (ret) +return ret; +return put_user (reg, uaddr); + }default :return -ENXIO ; } - }return 0 ; }
Signature · 1 line
2.5.5
Re: [PATCH v4 04/22] KVM: arm64: ITS: KVM_DEV_ARM_VGIC_GRP_ITS_REGS group
Quoted 7 lines · Eric Auger
The ITS KVM device exposes a new
KVM_DEV_ARM_VGIC_GRP_ITS_REGSgroup which allows the userspace to save/restore ITS registers.At this stage the get/set/has operations are not yet implemented.
Signed-off-by Eric Auger <[email protected]>Reviewed-by Andre Przywara <[email protected]>
M.
Signature · 1 line
Jazz is not dead. It just smells funny.
PATCH v4 5/22 KVM: arm/arm64: vgic: expose (un)lock_all_vcpus
In reply to Eric AugerWe need to use those helpers in vgic-its.c so let's expose them in the private vgic header.
--- virt/kvm/arm/vgic/vgic-kvm-device.c | 4 ++-- virt/kvm/arm/vgic/vgic.h | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-)
virt/kvm/arm/vgic/vgic-kvm-device.c +2 -2
@@ -259,13 +259,13 @@ static void unlock_vcpus(struct kvm *kvm, int vcpu_lock_idx) } } -static void unlock_all_vcpus (struct kvm *kvm) +void unlock_all_vcpus (struct kvm *kvm) {unlock_vcpus (kvm,atomic_read (&kvm->online_vcpus) -1 ); }/* Returns true if all vcpus were locked, false otherwise */ -static bool lock_all_vcpus (struct kvm *kvm) +bool lock_all_vcpus (struct kvm *kvm) {struct kvm_vcpu *tmp_vcpu;int c;
virt/kvm/arm/vgic/vgic.h +3 -0
@@ -175,4 +175,7 @@ int vgic_init(struct kvm *kvm);int vgic_debug_init (struct kvm *kvm);int vgic_debug_destroy (struct kvm *kvm); +bool lock_all_vcpus (struct kvm *kvm); +void unlock_all_vcpus (struct kvm *kvm); +#endif
Signature · 1 line
2.5.5
Re: [PATCH v4 05/22] KVM: arm/arm64: vgic: expose (un)lock_all_vcpus
Quoted 4 lines · Eric Auger
We need to use those helpers in
vgic-its.cso let's expose them in the private vgic header.Signed-off-by Eric Auger <[email protected]>
M.
Signature · 1 line
Jazz is not dead. It just smells funny.
PATCH v4 6/22 KVM: arm64: ITS: Implement vgic_its_has_attr_regs and attr_regs_access
In reply to Eric AugerThis patch implements vgic_its_has_attr_regs and vgic_its_attr_regs_access upon the MMIO framework. VGIC ITS KVM device KVM_DEV_ARM_VGIC_GRP_ITS_REGS group becomes functional.
At least GITS_CREADR requires to differentiate a guest write action from a user access. As such let's introduce a new uaccess_its_write vgic_register_region callback.
---
v3 -> v4:
- remove changes to the REGISTER_ITS_DESC macro. This will be handled in subsequent patch with the introduction of a new REGISTER_ITS_DESC_UACCESS macro
- fix IIDR access and add a comment wrt full length access
- handle endianness
- add kvm lock and vcpus lock
--- virt/kvm/arm/vgic/vgic-its.c | 78 +++++++++++++++++++++++++++++++++++++++++-- virt/kvm/arm/vgic/vgic-mmio.h | 9 +++-- 2 files changed, 83 insertions(+), 4 deletions(-)
virt/kvm/arm/vgic/vgic-its.c +76 -2
@@ -1469,14 +1469,88 @@ static void vgic_its_destroy(struct kvm_device *kvm_dev)int vgic_its_has_attr_regs (struct kvm_device *dev,struct kvm_device_attr *attr) { -return -ENXIO ; +const struct vgic_register_region *region; +struct vgic_io_device iodev = { + .regions = its_registers, + .nr_regions =ARRAY_SIZE (its_registers), + }; +gpa_t offset = attr->attr; + + region =vgic_find_mmio_region (iodev.regions, + iodev.nr_regions, + offset); +if (!region) +return -ENXIO ; + +return 0 ; }int vgic_its_attr_regs_access (struct kvm_device *dev,struct kvm_device_attr *attr,u64 *reg,bool is_write) { -return -ENXIO ; +const struct vgic_register_region *region; +struct vgic_io_device iodev = { + .regions = its_registers, + .nr_regions =ARRAY_SIZE (its_registers), + }; +struct vgic_its *its = dev->private; +gpa_t addr, offset = attr->attr; +unsigned int len; +unsigned long data =0 ; +int ret =0 ; + +/* +* Among supported registers, only GITS_CTLR (0x0) and GITS_IIDR (0x4) +* are 32 bits. Others are 64 bits. +*/ +if ((offset <0x8 && offset &0x3 ) || (offset >=0x8 && offset &0x7 )) +return -EINVAL ; + +mutex_lock (&dev->kvm->lock); + +if (IS_VGIC_ADDR_UNDEF (its->vgic_its_base)) { + ret = -ENXIO ; + goto out; + } + + region =vgic_find_mmio_region (iodev.regions, + iodev.nr_regions, + offset); +if (!region) { + ret = -ENXIO ; + goto out; + } + +if (!lock_all_vcpus (dev->kvm)) { + ret = -EBUSY ; + goto out; + } + + addr = its->vgic_its_base + offset; + +/* +* Only full length register accesses are supported although +* the architecture spec theoretically allows upper/lower 32 +* bits to be accessed independently +*/ + len = region->access_flags & VGIC_ACCESS_64bit ?8 :4 ; + +if (is_write) { + data =vgic_data_mmio_bus_to_host (reg, len); +if (region->uaccess_its_write) + region->uaccess_its_write (dev->kvm, its, addr, + len, data); +else + region->its_write (dev->kvm, its, addr, len, data); + }else { + data = region->its_read (dev->kvm, its, addr, len); +vgic_data_host_to_mmio_bus (reg, len, data); + } +unlock_all_vcpus (dev->kvm); +out: +mutex_unlock (&dev->kvm->lock); +return ret; } static int vgic_its_has_attr(struct kvm_device *dev,
virt/kvm/arm/vgic/vgic-mmio.h +7 -2
@@ -36,8 +36,13 @@ struct vgic_register_region { };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); +union { +void (*uaccess_write)(struct kvm_vcpu *vcpu,gpa_t addr, +unsigned int len,unsigned long val); +void (*uaccess_its_write)(struct kvm *kvm,struct vgic_its *its, +gpa_t addr,unsigned int len, +unsigned long val); + }; };extern struct kvm_io_device_ops kvm_io_gic_ops;
Signature · 1 line
2.5.5
Re: [PATCH v4 06/22] KVM: arm64: ITS: Implement vgic_its_has_attr_regs and attr_regs_access
Quoted 61 lines · Eric Auger
This patch implements
vgic_its_has_attr_regsandvgic_its_attr_regs_accessupon the MMIO framework. VGIC ITS KVM deviceKVM_DEV_ARM_VGIC_GRP_ITS_REGSgroup becomes functional.At least
GITS_CREADRrequires to differentiate a guest write action from a user access. As such let's introduce a newuaccess_its_writevgic_register_regioncallback.Signed-off-by Eric Auger <[email protected]>---
v3 -> v4:
- remove changes to theREGISTER_ITS_DESCmacro. This will be handled in subsequent patch with the introduction of a newREGISTER_ITS_DESC_UACCESSmacro
- fix IIDR access and add a comment wrt full length access
- handle endianness
- add kvm lock and vcpus lock--- virt/kvm/arm/vgic/vgic-its.c | 78 +++++++++++++++++++++++++++++++++++++++++-- virt/kvm/arm/vgic/vgic-mmio.h | 9 +++-- 2 files changed, 83 insertions(+), 4 deletions(-)virt/kvm/arm/vgic/vgic-its.c +21
-2@@ -1469,14 +1469,88 @@ static void vgic_its_destroy(struct kvm_device *kvm_dev)int vgic_its_has_attr_regs (struct kvm_device *dev,struct kvm_device_attr *attr) { -return -ENXIO ; +const struct vgic_register_region *region; +struct vgic_io_device iodev = { + .regions = its_registers, + .nr_regions =ARRAY_SIZE (its_registers), + }; +gpa_t offset = attr->attr; + + region =vgic_find_mmio_region (iodev.regions, + iodev.nr_regions, + offset); +if (!region) +return -ENXIO ; + +return 0 ; }int vgic_its_attr_regs_access (struct kvm_device *dev,struct kvm_device_attr *attr,u64 *reg,bool is_write) { -return -ENXIO ; +const struct vgic_register_region *region; +struct vgic_io_device iodev = { + .regions = its_registers, + .nr_regions =ARRAY_SIZE (its_registers), + }; +struct vgic_its *its = dev->private; +gpa_t addr, offset = attr->attr;
virt/kvm/arm/vgic/vgic-its.c static void vgic_its_destroy(struct kvm_device *kvm_dev) · line 1508
Quoted 10 lines
virt/kvm/arm/vgic/vgic-its.c +10
-0+unsigned int len; +unsigned long data =0 ; +int ret =0 ; + +/* +* Among supported registers, only GITS_CTLR (0x0) and GITS_IIDR (0x4) +* are 32 bits. Others are 64 bits. +*/ +if ((offset <0x8 && offset &0x3 ) || (offset >=0x8 && offset &0x7 )) +return -EINVAL ;
Can you use the actual register names instead of raw offsets? It's certainly be more readable.
Quoted 58 lines
virt/kvm/arm/vgic/vgic-its.c +45
-0+ +mutex_lock (&dev->kvm->lock); + +if (IS_VGIC_ADDR_UNDEF (its->vgic_its_base)) { + ret = -ENXIO ; + goto out; + } + + region =vgic_find_mmio_region (iodev.regions, + iodev.nr_regions, + offset); +if (!region) { + ret = -ENXIO ; + goto out; + } + +if (!lock_all_vcpus (dev->kvm)) { + ret = -EBUSY ; + goto out; + } + + addr = its->vgic_its_base + offset; + +/* +* Only full length register accesses are supported although +* the architecture spec theoretically allows upper/lower 32 +* bits to be accessed independently +*/ + len = region->access_flags & VGIC_ACCESS_64bit ?8 :4 ; + +if (is_write) { + data =vgic_data_mmio_bus_to_host (reg, len); +if (region->uaccess_its_write) + region->uaccess_its_write (dev->kvm, its, addr, + len, data); +else + region->its_write (dev->kvm, its, addr, len, data); + }else { + data = region->its_read (dev->kvm, its, addr, len); +vgic_data_host_to_mmio_bus (reg, len, data); + } +unlock_all_vcpus (dev->kvm); +out: +mutex_unlock (&dev->kvm->lock); +return ret; } static int vgic_its_has_attr(struct kvm_device *dev,virt/kvm/arm/vgic/vgic-mmio.h +0
-2@@ -36,8 +36,13 @@ struct vgic_register_region { };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);
virt/kvm/arm/vgic/vgic-mmio.h struct vgic_register_region { · line 48
Quoted 10 lines
virt/kvm/arm/vgic/vgic-mmio.h +7
-0+union { +void (*uaccess_write)(struct kvm_vcpu *vcpu,gpa_t addr, +unsigned int len,unsigned long val); +void (*uaccess_its_write)(struct kvm *kvm,struct vgic_its *its, +gpa_t addr,unsigned int len, +unsigned long val); + }; };extern struct kvm_io_device_ops kvm_io_gic_ops;
Other that that, looks good to me
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny.
PATCH v4 7/22 KVM: arm64: ITS: Implement vgic_mmio_uaccess_write_its_creadr
In reply to Eric AugerGITS_CREADR needs to be restored so let's implement the associated uaccess_write_its callback. The write only is allowed if the its is disabled.
---
v3 -> v4:
- REGISTER_ITS_DESC_UACCESS now introduced in this patch
- we now check the its is disabled
--- virt/kvm/arm/vgic/vgic-its.c | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-)
virt/kvm/arm/vgic/vgic-its.c +35 -2
@@ -1213,6 +1213,28 @@ static unsigned long vgic_mmio_read_its_creadr(struct kvm *kvm,return extract_bytes (its->creadr, addr &0x7 , len); } +static void vgic_mmio_uaccess_write_its_creadr (struct kvm *kvm, +struct vgic_its *its, +gpa_t addr,unsigned int len, +unsigned long val) +{ +u32 reg; + +mutex_lock (&its->cmd_lock); + +if (its->enabled) + goto out; + + reg =update_64bit_reg (its->creadr, addr &7 , len, val); + reg =ITS_CMD_OFFSET (reg); +if (reg >=ITS_CMD_BUFFER_SIZE (its->cbaser)) + goto out; + + its->creadr = reg; +out: +mutex_unlock (&its->cmd_lock); +} +#define BASER_INDEX (addr) (((addr) / sizeof(u64)) & 0x7) static unsigned long vgic_mmio_read_its_baser(struct kvm *kvm, struct vgic_its *its,
@@ -1317,6 +1339,16 @@ static void vgic_mmio_write_its_ctlr(struct kvm *kvm, struct vgic_its *its, .its_write = wr, \ } +#define REGISTER_ITS_DESC_UACCESS (off, rd, wr, uwr, length, acc)\ +{ \ + .reg_offset = off, \ + .len = length, \ + .access_flags = acc, \ + .its_read = rd, \ + .its_write = wr, \ + .uaccess_its_write = uwr, \ +} +static void its_mmio_write_wi (struct kvm *kvm,struct vgic_its *its,gpa_t addr,unsigned int len,unsigned long val) {
@@ -1339,8 +1371,9 @@ static struct vgic_register_region its_registers[] = {REGISTER_ITS_DESC (GITS_CWRITER , vgic_mmio_read_its_cwriter, vgic_mmio_write_its_cwriter,8 , VGIC_ACCESS_64bit | VGIC_ACCESS_32bit), -REGISTER_ITS_DESC (GITS_CREADR , - vgic_mmio_read_its_creadr, its_mmio_write_wi,8 , +REGISTER_ITS_DESC_UACCESS (GITS_CREADR , + vgic_mmio_read_its_creadr, its_mmio_write_wi, + vgic_mmio_uaccess_write_its_creadr,8 , VGIC_ACCESS_64bit | VGIC_ACCESS_32bit), REGISTER_ITS_DESC(GITS_BASER, vgic_mmio_read_its_baser, vgic_mmio_write_its_baser, 0x40,
Signature · 1 line
2.5.5
Re: [PATCH v4 07/22] KVM: arm64: ITS: Implement vgic_mmio_uaccess_write_its_creadr
Quoted 31 lines · Eric Auger
GITS_CREADRneeds to be restored so let's implement the associateduaccess_write_itscallback. The write only is allowed if the its is disabled.Signed-off-by Eric Auger <[email protected]>---
v3 -> v4:
-REGISTER_ITS_DESC_UACCESSnow introduced in this patch
- we now check the its is disabled--- virt/kvm/arm/vgic/vgic-its.c | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-)virt/kvm/arm/vgic/vgic-its.c +8
-0@@ -1213,6 +1213,28 @@ static unsigned long vgic_mmio_read_its_creadr(struct kvm *kvm,return extract_bytes (its->creadr, addr &0x7 , len); } +static void vgic_mmio_uaccess_write_its_creadr (struct kvm *kvm, +struct vgic_its *its, +gpa_t addr,unsigned int len, +unsigned long val) +{ +u32 reg; + +mutex_lock (&its->cmd_lock);
virt/kvm/arm/vgic/vgic-its.c static unsigned long vgic_mmio_read_its_creadr(struct kvm *kvm, · line 1233
Quoted 10 lines
virt/kvm/arm/vgic/vgic-its.c +10
-0+ +if (its->enabled) + goto out; + + reg =update_64bit_reg (its->creadr, addr &7 , len, val); + reg =ITS_CMD_OFFSET (reg); +if (reg >=ITS_CMD_BUFFER_SIZE (its->cbaser)) + goto out; + + its->creadr = reg;
Careful. Here, you're loosing the "Stalled" bit. We do not implement support for it yet, but I wonder if we should preserve it. If not, we should at least document that we're purposely stripping that bit.
Quoted 26 lines
virt/kvm/arm/vgic/vgic-its.c +14
-0+out: +mutex_unlock (&its->cmd_lock); +} +#define BASER_INDEX (addr) (((addr) / sizeof(u64)) & 0x7) static unsigned long vgic_mmio_read_its_baser(struct kvm *kvm, struct vgic_its *its,@@ -1317,6 +1339,16 @@ static void vgic_mmio_write_its_ctlr(struct kvm *kvm, struct vgic_its *its, .its_write = wr, \ } +#define REGISTER_ITS_DESC_UACCESS (off, rd, wr, uwr, length, acc)\ +{ \ + .reg_offset = off, \ + .len = length, \ + .access_flags = acc, \ + .its_read = rd, \ + .its_write = wr, \ + .uaccess_its_write = uwr, \ +} +static void its_mmio_write_wi (struct kvm *kvm,struct vgic_its *its,gpa_t addr,unsigned int len,unsigned long val) {@@ -1339,8 +1371,9 @@ static struct vgic_register_region its_registers[] = { REGISTER_ITS_DESC(GITS_CWRITER,
virt/kvm/arm/vgic/vgic-its.c static struct vgic_register_region its_registers[] = { · line 1379
Quoted 10 lines
virt/kvm/arm/vgic/vgic-its.c +3
-2vgic_mmio_read_its_cwriter, vgic_mmio_write_its_cwriter, 8, VGIC_ACCESS_64bit | VGIC_ACCESS_32bit), -REGISTER_ITS_DESC (GITS_CREADR , - vgic_mmio_read_its_creadr, its_mmio_write_wi,8 , +REGISTER_ITS_DESC_UACCESS (GITS_CREADR , + vgic_mmio_read_its_creadr, its_mmio_write_wi, + vgic_mmio_uaccess_write_its_creadr,8 , VGIC_ACCESS_64bit | VGIC_ACCESS_32bit), REGISTER_ITS_DESC(GITS_BASER, vgic_mmio_read_its_baser, vgic_mmio_write_its_baser, 0x40,
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny.
PATCH v4 8/22 KVM: arm64: ITS: Implement vgic_mmio_uaccess_write_its_iidr
In reply to Eric AugerThe GITS_IIDR revision field is used to encode the version of the table layout (ABI). So we need to restore it to check the table layout to be restored is compatible with the destination vITS.
The user selected revision is stored in the user_revision field. It will be compared against the REV num at table restoration time.
---
v4: creation
--- include/kvm/arm_vgic.h | 2 ++ virt/kvm/arm/vgic/vgic-its.c | 24 +++++++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-)
include/kvm/arm_vgic.h +2 -0
@@ -162,6 +162,8 @@ struct vgic_its {u32 creadr;u32 cwriter; +u32 user_revision; +/* Protects the device and collection lists */ struct mutex its_lock;struct list_head device_list;
virt/kvm/arm/vgic/vgic-its.c +21 -3
@@ -33,6 +33,9 @@#include "vgic.h" #include "vgic-mmio.h" +/* ITS Table Layout ABI Revision */ +#define REV 0x1 +/* * Creates a new (reference to a) struct vgic_irq for a given LPI. * If this LPI is already mapped on another ITS, we increase its refcount
@@ -384,7 +387,19 @@ static unsigned long vgic_mmio_read_its_iidr(struct kvm *kvm,struct vgic_its *its, gpa_t addr, unsigned int len) { - return (PRODUCT_ID_KVM << 24) | (IMPLEMENTER_ARM << 0); + return (PRODUCT_ID_KVM << 24) | (REV << 12) | IMPLEMENTER_ARM; +} + +static void vgic_mmio_uaccess_write_its_iidr (struct kvm *kvm, +struct vgic_its *its, +gpa_t addr,unsigned int len, +unsigned long val) +{ +u64 tmp =0 ; + + tmp =update_64bit_reg (tmp, addr &3 , len, val); + tmp = (tmp &GENMASK (15 ,12 )) >>12 ; + its->user_revision = tmp; } static unsigned long vgic_mmio_read_its_idregs(struct kvm *kvm,
@@ -1359,8 +1374,9 @@ static struct vgic_register_region its_registers[] = {REGISTER_ITS_DESC (GITS_CTLR , vgic_mmio_read_its_ctlr, vgic_mmio_write_its_ctlr,4 , VGIC_ACCESS_32bit), -REGISTER_ITS_DESC (GITS_IIDR , - vgic_mmio_read_its_iidr, its_mmio_write_wi,4 , +REGISTER_ITS_DESC_UACCESS (GITS_IIDR , + vgic_mmio_read_its_iidr, its_mmio_write_wi, + vgic_mmio_uaccess_write_its_iidr,4 , VGIC_ACCESS_32bit), REGISTER_ITS_DESC(GITS_TYPER, vgic_mmio_read_its_typer, its_mmio_write_wi, 8,
@@ -1458,6 +1474,8 @@ static int vgic_its_create(struct kvm_device *dev, u32 type) ((u64 )GITS_BASER_TYPE_COLLECTION <<GITS_BASER_TYPE_SHIFT ); dev->kvm->arch.vgic.propbaser =INITIAL_PROPBASER_VALUE ; + its->user_revision =0 ; + dev->private = its;return 0 ;
Signature · 1 line
2.5.5
Re: [PATCH v4 08/22] KVM: arm64: ITS: Implement vgic_mmio_uaccess_write_its_iidr
Quoted 6 lines · Eric Auger
The
GITS_IIDRrevision field is used to encode the version of the table layout (ABI). So we need to restore it to check the table layout to be restored is compatible with the destination vITS.The user selected revision is stored in the
user_revisionfield. It will be compared against the REV num at table restoration time.
Why isn't it sufficient to keep it GITS_IIDR RO and let userspace find out about the ABI revision that the kernel understands?
Or are we planning on supporting multiple ABIs in the kernel? If so, do we have a deprecation policy/plan? I don't mind either way, but it would be good to document it...
Maybe it is documented already and I missed it (which is perfectly possible!).
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny.
Re: [PATCH v4 08/22] KVM: arm64: ITS: Implement vgic_mmio_uaccess_write_its_iidr
Hi Marc,
Quoted 5 lines · Marc Zyngier
Quoted 4 lines · Eric Auger
The
GITS_IIDRrevision field is used to encode the version of the table layout (ABI). So we need to restore it to check the table layout to be restored is compatible with the destination vITS.
Quoted 7 lines
Quoted 2 lines
The user selected revision is stored in the
user_revisionfield. It will be compared against the REV num at table restoration time.Why isn't it sufficient to keep it
GITS_IIDRRO and let userspace find out about the ABI revision that the kernel understands?Or are we planning on supporting multiple ABIs in the kernel?
Yes as discussed with Peter, the plan is to allow several ABIs. So the userspace informs the destination about the ABI revision of the stored tables (contained by the GITS_IIDR). If the destination KVM does not support this ABI revision, table restore will fail.
If so, do
Quoted 5 lines
we have a deprecation policy/plan? I don't mind either way, but it would be good to document it...
Maybe it is documented already and I missed it (which is perfectly possible!).
Well this is partly documented in Documentation/virtual/kvm/devices/arm-vgic-its.txt. No plan to deprecate. migration from KVM supporting v1 to KVM supporting V2 would be possible but not the contrary.
Does it make sense?
Thanks
Eric
Quoted 5 lines
Thanks,
M.
Re: [PATCH v4 08/22] KVM: arm64: ITS: Implement vgic_mmio_uaccess_write_its_iidr
Quoted 23 lines · Auger Eric
Hi Marc,
Quoted 5 lines · Marc Zyngier
Quoted 4 lines · Eric Auger
The
GITS_IIDRrevision field is used to encode the version of the table layout (ABI). So we need to restore it to check the table layout to be restored is compatible with the destination vITS.Quoted 7 lines
Quoted 2 lines
The user selected revision is stored in the
user_revisionfield. It will be compared against the REV num at table restoration time.Why isn't it sufficient to keep it
GITS_IIDRRO and let userspace find out about the ABI revision that the kernel understands?Or are we planning on supporting multiple ABIs in the kernel?
Yes as discussed with Peter, the plan is to allow several ABIs. So the userspace informs the destination about the ABI revision of the stored tables (contained by the
GITS_IIDR). If the destination KVM does not support this ABI revision, table restore will fail.
If so, doQuoted 3 lines
we have a deprecation policy/plan? I don't mind either way, but it would be good to document it...
Quoted 8 lines
Quoted 2 lines
Maybe it is documented already and I missed it (which is perfectly possible!).
Well this is partly documented in
Documentation/virtual/kvm/devices/arm-vgic-its.txt. No plan to deprecate. migration from KVM supporting v1 to KVM supporting V2 would be possible but not the contrary.Does it make sense?
Sort of. Say you have three systems: A and C, which only supports v1; B, which supports v1 and v2. Let's say you migrate from A to B, and from B to C. Is B mandated to be able to export the tables as v1 and v2? Or can it restrict what it can export?
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Re: [PATCH v4 08/22] KVM: arm64: ITS: Implement vgic_mmio_uaccess_write_its_iidr
Quoted 6 lines · Marc Zyngier
Quoted 5 lines · Auger Eric
Well this is partly documented in
Documentation/virtual/kvm/devices/arm-vgic-its.txt. No plan to deprecate. migration from KVM supporting v1 to KVM supporting V2 would be possible but not the contrary.
Quoted 6 lines
Quoted 1 line
Does it make sense?
Sort of. Say you have three systems: A and C, which only supports v1; B, which supports v1 and v2. Let's say you migrate from A to B, and from B to C. Is B mandated to be able to export the tables as v1 and v2? Or can it restrict what it can export?
Generally for QEMU we only require forwards-compatibility (so in this case old-kernel to new-kernel has to work but new-kernel to old-kernel need not). Export-as-old-format if the in-kernel data can be represented in the old format would be a nice to have property only (and depending what the unanticipated future need is, might not be possible at all).
The idea here is not that we expect to need this, but to give ourselves an escape hatch for future use if we do find we need to add something which won't fit in the currently defined format.
thanks
-- PMM
Re: [PATCH v4 08/22] KVM: arm64: ITS: Implement vgic_mmio_uaccess_write_its_iidr
In reply to Marc ZyngierHi Marc,
Quoted 31 lines · Marc Zyngier
Quoted 30 lines · Auger Eric
Hi Marc,
Quoted 5 lines · Marc Zyngier
Quoted 4 lines · Eric Auger
The
GITS_IIDRrevision field is used to encode the version of the table layout (ABI). So we need to restore it to check the table layout to be restored is compatible with the destination vITS.Quoted 7 lines
Quoted 2 lines
The user selected revision is stored in the
user_revisionfield. It will be compared against the REV num at table restoration time.Why isn't it sufficient to keep it
GITS_IIDRRO and let userspace find out about the ABI revision that the kernel understands?Or are we planning on supporting multiple ABIs in the kernel?
Yes as discussed with Peter, the plan is to allow several ABIs. So the userspace informs the destination about the ABI revision of the stored tables (contained by the
GITS_IIDR). If the destination KVM does not support this ABI revision, table restore will fail.
If so, doQuoted 5 lines
we have a deprecation policy/plan? I don't mind either way, but it would be good to document it...
Maybe it is documented already and I missed it (which is perfectly possible!).
Well this is partly documented in
Documentation/virtual/kvm/devices/arm-vgic-its.txt. No plan to deprecate. migration from KVM supporting v1 to KVM supporting V2 would be possible but not the contrary.
Quoted 6 lines
Quoted 1 line
Does it make sense?
Sort of. Say you have three systems: A and C, which only supports v1; B, which supports v1 and v2. Let's say you migrate from A to B, and from B to C. Is B mandated to be able to export the tables as v1 and v2? Or can it restrict what it can export?
At the moment migration from B to C will fail because source ABI rev = v2 > destination support ABI = v1.
A (v1) -> B (v1 & v2): migration OK
B (v1 & v2) -> C (v1): migration NOK
What could be done if we want something clever is source KVM detects which ABI is sufficient and choose the lowest revision for the save. for instance if no vLPI choose rev1, otherwise rev2. rev2 typically is needed for vLPI support for nested as we need to save/restore vPE table and vLPIs in ITE (2x8 byte entries).
The problem is that once you have migrated to B and you start playing with vLPIs and C do not know the table layout for vPE/vLPIs, you can't migrate anymore.
Thanks
Eric
Quoted 5 lines
Thanks,
M.
Re: [PATCH v4 08/22] KVM: arm64: ITS: Implement vgic_mmio_uaccess_write_its_iidr
Quoted 40 lines · Auger Eric
Hi Marc,
Quoted 31 lines · Marc Zyngier
Quoted 30 lines · Auger Eric
Hi Marc,
Quoted 5 lines · Marc Zyngier
Quoted 4 lines · Eric Auger
The
GITS_IIDRrevision field is used to encode the version of the table layout (ABI). So we need to restore it to check the table layout to be restored is compatible with the destination vITS.Quoted 7 lines
Quoted 2 lines
The user selected revision is stored in the
user_revisionfield. It will be compared against the REV num at table restoration time.Why isn't it sufficient to keep it
GITS_IIDRRO and let userspace find out about the ABI revision that the kernel understands?Or are we planning on supporting multiple ABIs in the kernel?
Yes as discussed with Peter, the plan is to allow several ABIs. So the userspace informs the destination about the ABI revision of the stored tables (contained by the
GITS_IIDR). If the destination KVM does not support this ABI revision, table restore will fail.
If so, doQuoted 5 lines
we have a deprecation policy/plan? I don't mind either way, but it would be good to document it...
Maybe it is documented already and I missed it (which is perfectly possible!).
Well this is partly documented in
Documentation/virtual/kvm/devices/arm-vgic-its.txt. No plan to deprecate. migration from KVM supporting v1 to KVM supporting V2 would be possible but not the contrary.Quoted 6 lines
Quoted 1 line
Does it make sense?
Sort of. Say you have three systems: A and C, which only supports v1; B, which supports v1 and v2. Let's say you migrate from A to B, and from B to C. Is B mandated to be able to export the tables as v1 and v2? Or can it restrict what it can export?
Quoted 5 lines
At the moment migration from B to C will fail because source ABI rev = v2 > destination support ABI = v1.
A (v1) -> B (v1 & v2): migration OK
B (v1 & v2) -> C (v1): migration NOK
So what does IIDR report on B once the A->B migration has taken place? Does it report v2?
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Re: [PATCH v4 08/22] KVM: arm64: ITS: Implement vgic_mmio_uaccess_write_its_iidr
Marc,
Quoted 41 lines · Marc Zyngier
Quoted 40 lines · Auger Eric
Hi Marc,
Quoted 37 lines · Marc Zyngier
Quoted 23 lines · Auger Eric
Hi Marc,
Quoted 5 lines · Marc Zyngier
Quoted 4 lines · Eric Auger
The
GITS_IIDRrevision field is used to encode the version of the table layout (ABI). So we need to restore it to check the table layout to be restored is compatible with the destination vITS.Quoted 7 lines
Quoted 2 lines
The user selected revision is stored in the
user_revisionfield. It will be compared against the REV num at table restoration time.Why isn't it sufficient to keep it
GITS_IIDRRO and let userspace find out about the ABI revision that the kernel understands?Or are we planning on supporting multiple ABIs in the kernel?
Yes as discussed with Peter, the plan is to allow several ABIs. So the userspace informs the destination about the ABI revision of the stored tables (contained by the
GITS_IIDR). If the destination KVM does not support this ABI revision, table restore will fail.
If so, doQuoted 3 lines
we have a deprecation policy/plan? I don't mind either way, but it would be good to document it...
Quoted 8 lines
Quoted 2 lines
Maybe it is documented already and I missed it (which is perfectly possible!).
Well this is partly documented in
Documentation/virtual/kvm/devices/arm-vgic-its.txt. No plan to deprecate. migration from KVM supporting v1 to KVM supporting V2 would be possible but not the contrary.Does it make sense?
Sort of. Say you have three systems: A and C, which only supports v1; B, which supports v1 and v2. Let's say you migrate from A to B, and from B to C. Is B mandated to be able to export the tables as v1 and v2? Or can it restrict what it can export?
Quoted 8 lines
Quoted 5 lines
At the moment migration from B to C will fail because source ABI rev = v2 > destination support ABI = v1.
A (v1) -> B (v1 & v2): migration OK
B (v1 & v2) -> C (v1): migration NOKSo what does IIDR report on B once the
A->Bmigration has taken place? Does it report v2?
yes that was the plan
Thanks
Eric
Quoted 5 lines
Thanks,
M.
Re: [PATCH v4 08/22] KVM: arm64: ITS: Implement vgic_mmio_uaccess_write_its_iidr
Quoted 9 lines · Auger Eric
Quoted 6 lines · Marc Zyngier
Quoted 2 lines · Auger Eric
A (v1) -> B (v1 & v2): migration OK
B (v1 & v2) -> C (v1): migration NOKSo what does IIDR report on B once the
A->Bmigration has taken place? Does it report v2?yes that was the plan
Hmm, the IIDR value shouldn't change across a migration I think. It's guest visible so the guest should see it still the same value even after migration.
thanks
-- PMM
Re: [PATCH v4 08/22] KVM: arm64: ITS: Implement vgic_mmio_uaccess_write_its_iidr
Quoted 6 lines · Peter Maydell
Quoted 5 lines · Auger Eric
Quoted 4 lines · Marc Zyngier
Quoted 2 lines · Auger Eric
A (v1) -> B (v1 & v2): migration OK
B (v1 & v2) -> C (v1): migration NOK
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
So what does IIDR report on B once the
A->Bmigration has taken place? Does it report v2?yes that was the plan
Hmm, the IIDR value shouldn't change across a migration I think. It's guest visible so the guest should see it still the same value even after migration.
That's my worry. But we then have a problem when this VM migrates again. How does userspace find out which ABI to use then?
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Re: [PATCH v4 08/22] KVM: arm64: ITS: Implement vgic_mmio_uaccess_write_its_iidr
Quoted 10 lines · Marc Zyngier
Quoted 9 lines · Peter Maydell
Quoted 8 lines · Auger Eric
Quoted 6 lines · Marc Zyngier
Quoted 2 lines · Auger Eric
A (v1) -> B (v1 & v2): migration OK
B (v1 & v2) -> C (v1): migration NOKSo what does IIDR report on B once the
A->Bmigration has taken place? Does it report v2?
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
yes that was the plan
Hmm, the IIDR value shouldn't change across a migration I think. It's guest visible so the guest should see it still the same value even after migration.
That's my worry. But we then have a problem when this VM migrates again. How does userspace find out which ABI to use then?
Userspace shouldn't need to care; the idea of this scheme is that if the kernel has to change its ABI then the kernel is what has to deal with the change.
I think that means that if you can read the v1 format on input you have to output it too, though.
thanks
-- PMM
Re: [PATCH v4 08/22] KVM: arm64: ITS: Implement vgic_mmio_uaccess_write_its_iidr
In reply to Marc ZyngierHi,
Quoted 10 lines · Marc Zyngier
Quoted 9 lines · Peter Maydell
Quoted 8 lines · Auger Eric
Quoted 6 lines · Marc Zyngier
Quoted 2 lines · Auger Eric
A (v1) -> B (v1 & v2): migration OK
B (v1 & v2) -> C (v1): migration NOKSo what does IIDR report on B once the
A->Bmigration has taken place? Does it report v2?
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
yes that was the plan
Hmm, the IIDR value shouldn't change across a migration I think. It's guest visible so the guest should see it still the same value even after migration.
That's my worry. But we then have a problem when this VM migrates again. How does userspace find out which ABI to use then?
Today the userspace just conveys the information from source kernel to destination kernel through the IIDR value. This allows the destination kernel to know what was the table layout used during the migration.
If we report the source ABI revision value on the destination, what is the strategy we should adopt:
- limit the features to those that will be migratable through this ABI
- allow the functionalities (GICv4 for instance) but reject save?
Thanks
Eric
Quoted 5 lines
Thanks,
M.
PATCH v4 9/22 KVM: arm64: ITS: Report the ITE size in GITS_TYPER
In reply to Eric AugerAn ITE size of 8 Bytes is reported to the guest. Combining this information with the number of event IDs the guest wants to support, this latter will be able to allocate each device's ITT with the right size.
---
v2 -> v3:
- changed (u64)(VITS_ESZ - 1) to (VITS_ESZ - 1ULL) in vgic_register_its_iodev
- added Andre's R-b
v1 -> v2:
- correct ITT_ENTRY_SIZE field
- remove ITE_SIZE since all entries become 8 bytes
--- include/linux/irqchip/arm-gic-v3.h | 1 + virt/kvm/arm/vgic/vgic-its.c | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-)
include/linux/irqchip/arm-gic-v3.h +1 -0
@@ -232,6 +232,7 @@#define GITS_CTLR_QUIESCENT (1U << 31)#define GITS_TYPER_PLPIS (1UL << 0) +#define GITS_TYPER_ITT_ENTRY_SIZE_SHIFT 4#define GITS_TYPER_IDBITS_SHIFT 8#define GITS_TYPER_DEVBITS_SHIFT 13#define GITS_TYPER_DEVBITS (r) ((((r) >> GITS_TYPER_DEVBITS_SHIFT) & 0x1f) + 1)
virt/kvm/arm/vgic/vgic-its.c +4 -1
@@ -179,6 +179,8 @@ static struct its_ite *find_ite(struct vgic_its *its, u32 device_id,#define GIC_LPI_OFFSET 8192 +#define VITS_ESZ 8 +/* * Finds and returns a collection in the ITS collection table. * Must be called with the its_lock mutex held.
@@ -379,6 +381,7 @@ static unsigned long vgic_mmio_read_its_typer(struct kvm *kvm,*/ reg |=0x0f <<GITS_TYPER_DEVBITS_SHIFT ; reg |=0x0f <<GITS_TYPER_IDBITS_SHIFT ; + reg |= (VITS_ESZ -1 ) <<GITS_TYPER_ITT_ENTRY_SIZE_SHIFT ;return extract_bytes (reg, addr &7 , len); }
@@ -1436,7 +1439,7 @@ static int vgic_register_its_iodev(struct kvm *kvm, struct vgic_its *its) (GIC_BASER_CACHEABILITY (GITS_BASER ,INNER , RaWb) | \GIC_BASER_CACHEABILITY (GITS_BASER ,OUTER , SameAsInner) | \GIC_BASER_SHAREABILITY (GITS_BASER , InnerShareable) | \ - ((8ULL -1 ) <<GITS_BASER_ENTRY_SIZE_SHIFT ) | \ + ((VITS_ESZ -1ULL ) <<GITS_BASER_ENTRY_SIZE_SHIFT ) | \ GITS_BASER_PAGE_SIZE_64K)#define INITIAL_PROPBASER_VALUE \
Signature · 1 line
2.5.5
Re: [PATCH v4 09/22] KVM: arm64: ITS: Report the ITE size in GITS_TYPER
Quoted 57 lines · Eric Auger
An ITE size of 8 Bytes is reported to the guest. Combining this information with the number of event IDs the guest wants to support, this latter will be able to allocate each device's ITT with the right size.
Signed-off-by Eric Auger <[email protected]>Reviewed-by Andre Przywara <[email protected]>---
v2 -> v3:
- changed (u64)(VITS_ESZ - 1) to (VITS_ESZ- 1ULL) invgic_register_its_iodev
- added Andre's R-bv1 -> v2:
- correctITT_ENTRY_SIZEfield
- removeITE_SIZEsince all entries become 8 bytes--- include/linux/irqchip/arm-gic-v3.h | 1 + virt/kvm/arm/vgic/vgic-its.c | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-)include/linux/irqchip/arm-gic-v3.h +1
-0@@ -232,6 +232,7 @@#define GITS_CTLR_QUIESCENT (1U << 31)#define GITS_TYPER_PLPIS (1UL << 0) +#define GITS_TYPER_ITT_ENTRY_SIZE_SHIFT 4#define GITS_TYPER_IDBITS_SHIFT 8#define GITS_TYPER_DEVBITS_SHIFT 13#define GITS_TYPER_DEVBITS (r) ((((r) >> GITS_TYPER_DEVBITS_SHIFT) & 0x1f) + 1)virt/kvm/arm/vgic/vgic-its.c +3
-0@@ -179,6 +179,8 @@ static struct its_ite *find_ite(struct vgic_its *its, u32 device_id,#define GIC_LPI_OFFSET 8192 +#define VITS_ESZ 8 +/* * Finds and returns a collection in the ITS collection table. * Must be called with the its_lock mutex held. @@ -379,6 +381,7 @@ static unsigned long vgic_mmio_read_its_typer(struct kvm *kvm,*/ reg |=0x0f <<GITS_TYPER_DEVBITS_SHIFT ; reg |=0x0f <<GITS_TYPER_IDBITS_SHIFT ; + reg |= (VITS_ESZ -1 ) <<GITS_TYPER_ITT_ENTRY_SIZE_SHIFT ;return extract_bytes (reg, addr &7 , len); }
virt/kvm/arm/vgic/vgic-its.c static int vgic_register_its_iodev(struct kvm *kvm, struct vgic_its *its) · line 1445
Quoted 8 lines
virt/kvm/arm/vgic/vgic-its.c +1
-1@@ -1436,7 +1439,7 @@ static int vgic_register_its_iodev(struct kvm *kvm, struct vgic_its *its) (GIC_BASER_CACHEABILITY (GITS_BASER ,INNER , RaWb) | \GIC_BASER_CACHEABILITY (GITS_BASER ,OUTER , SameAsInner) | \GIC_BASER_SHAREABILITY (GITS_BASER , InnerShareable) | \ - ((8ULL -1 ) <<GITS_BASER_ENTRY_SIZE_SHIFT ) | \ + ((VITS_ESZ -1ULL ) <<GITS_BASER_ENTRY_SIZE_SHIFT ) | \ GITS_BASER_PAGE_SIZE_64K)#define INITIAL_PROPBASER_VALUE \
nit: since we're going to now encode a number of sizes in various registers, I have the feeling that it would make sense to have a macro that performs that encoding in a relatively generic way.
Something along the lines of
#define GIC_ENCODE_SZ(n,w) (((unsigned long)(n) - 1) & GENMASK_ULL(((w) - 1), 0))
where n is the value, and w is the number of bits required. Somehow, I'd find it slightly more readable. Or do you think that it is completely overkill?
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny.
PATCH v4 10/22 KVM: arm64: ITS: Interpret MAPD Size field and check related errors
In reply to Eric AugerUp to now the MAPD's ITT size field has been ignored. It encodes the number of eventid bit minus 1. It should be used to check the eventid when a MAPTI command is issued on a device. Let's store the number of eventid bits in the its_device and do the check on MAPTI. Also make sure the ITT size field does not exceed the GITS_TYPER IDBITS field.
---
v3 -> v4:
- VITS_TYPER_IDBITS set to 16 to be homogeneous with VITS_ESZ definition and correct users
- nb_eventid_bits correspond to the actual number of eventid bits
--- include/linux/irqchip/arm-gic-v3.h | 2 ++ virt/kvm/arm/vgic/vgic-its.c | 14 +++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-)
include/linux/irqchip/arm-gic-v3.h +2 -0
@@ -338,9 +338,11 @@#define E_ITS_INT_UNMAPPED_INTERRUPT 0x010307#define E_ITS_CLEAR_UNMAPPED_INTERRUPT 0x010507#define E_ITS_MAPD_DEVICE_OOR 0x010801 +#define E_ITS_MAPD_ITTSIZE_OOR 0x010802#define E_ITS_MAPC_PROCNUM_OOR 0x010902#define E_ITS_MAPC_COLLECTION_OOR 0x010903#define E_ITS_MAPTI_UNMAPPED_DEVICE 0x010a04 +#define E_ITS_MAPTI_ID_OOR 0x010a05#define E_ITS_MAPTI_PHYSICALID_OOR 0x010a06#define E_ITS_INV_UNMAPPED_INTERRUPT 0x010c07#define E_ITS_INVALL_UNMAPPED_COLLECTION 0x010d09
virt/kvm/arm/vgic/vgic-its.c +13 -1
@@ -102,6 +102,7 @@ struct its_device {/* the head for the list of ITTEs */ struct list_head itt_head; +u32 nb_eventid_bits;u32 device_id; };
@@ -180,6 +181,7 @@ static struct its_ite *find_ite(struct vgic_its *its, u32 device_id,#define GIC_LPI_OFFSET 8192#define VITS_ESZ 8 +#define VITS_TYPER_IDBITS 16/* * Finds and returns a collection in the ITS collection table.
@@ -380,7 +382,7 @@ static unsigned long vgic_mmio_read_its_typer(struct kvm *kvm,* DevBits low - as least for the time being. */ reg |=0x0f <<GITS_TYPER_DEVBITS_SHIFT ; - reg |=0x0f <<GITS_TYPER_IDBITS_SHIFT ; + reg |= (VITS_TYPER_IDBITS -1 ) <<GITS_TYPER_IDBITS_SHIFT ; reg |= (VITS_ESZ -1 ) <<GITS_TYPER_ITT_ENTRY_SIZE_SHIFT ;return extract_bytes (reg, addr &7 , len);
@@ -547,6 +549,7 @@ static u64 its_cmd_mask_field(u64 *its_cmd, int word, int shift, int size)#define its_cmd_get_command (cmd) its_cmd_mask_field(cmd, 0, 0, 8)#define its_cmd_get_deviceid (cmd) its_cmd_mask_field(cmd, 0, 32, 32) +#define its_cmd_get_size (cmd) its_cmd_mask_field(cmd, 1, 0, 5)#define its_cmd_get_id (cmd) its_cmd_mask_field(cmd, 1, 0, 32)#define its_cmd_get_physical_id (cmd) its_cmd_mask_field(cmd, 1, 32, 32)#define its_cmd_get_collection (cmd) its_cmd_mask_field(cmd, 2, 0, 16)
@@ -737,6 +740,9 @@ static int vgic_its_cmd_handle_mapi(struct kvm *kvm, struct vgic_its *its,if (!device)return E_ITS_MAPTI_UNMAPPED_DEVICE ; +if (event_id >=BIT_ULL (device->nb_eventid_bits)) +return E_ITS_MAPTI_ID_OOR ; +if (its_cmd_get_command (its_cmd) ==GITS_CMD_MAPTI ) lpi_nr =its_cmd_get_physical_id (its_cmd);else
@@ -817,11 +823,15 @@ static int vgic_its_cmd_handle_mapd(struct kvm *kvm, struct vgic_its *its, {u32 device_id =its_cmd_get_deviceid (its_cmd);bool valid =its_cmd_get_validbit (its_cmd); +u8 nb_eventid_bits =its_cmd_get_size (its_cmd) +1 ;struct its_device *device;if (!vgic_its_check_id (its, its->baser_device_table, device_id))return E_ITS_MAPD_DEVICE_OOR ; +if (valid && nb_eventid_bits >VITS_TYPER_IDBITS ) +return E_ITS_MAPD_ITTSIZE_OOR ; + device =find_its_device (its, device_id);/*
@@ -844,6 +854,8 @@ static int vgic_its_cmd_handle_mapd(struct kvm *kvm, struct vgic_its *its,return -ENOMEM ; device->device_id = device_id; + device->nb_eventid_bits = nb_eventid_bits; +INIT_LIST_HEAD (&device->itt_head);list_add_tail (&device->dev_list, &its->device_list);
Signature · 1 line
2.5.5
Re: [PATCH v4 10/22] KVM: arm64: ITS: Interpret MAPD Size field and check related errors
Quoted 84 lines · Eric Auger
Up to now the MAPD's ITT size field has been ignored. It encodes the number of eventid bit minus 1. It should be used to check the eventid when a MAPTI command is issued on a device. Let's store the number of eventid bits in the
its_deviceand do the check on MAPTI. Also make sure the ITT size field does not exceed theGITS_TYPERIDBITS field.Signed-off-by Eric Auger <[email protected]>---
v3 -> v4:
-VITS_TYPER_IDBITSset to 16 to be homogeneous withVITS_ESZdefinition and correct users
-nb_eventid_bitscorrespond to the actual number of eventid bits--- include/linux/irqchip/arm-gic-v3.h | 2 ++ virt/kvm/arm/vgic/vgic-its.c | 14 +++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-)include/linux/irqchip/arm-gic-v3.h +2
-0@@ -338,9 +338,11 @@#define E_ITS_INT_UNMAPPED_INTERRUPT 0x010307#define E_ITS_CLEAR_UNMAPPED_INTERRUPT 0x010507#define E_ITS_MAPD_DEVICE_OOR 0x010801 +#define E_ITS_MAPD_ITTSIZE_OOR 0x010802#define E_ITS_MAPC_PROCNUM_OOR 0x010902#define E_ITS_MAPC_COLLECTION_OOR 0x010903#define E_ITS_MAPTI_UNMAPPED_DEVICE 0x010a04 +#define E_ITS_MAPTI_ID_OOR 0x010a05#define E_ITS_MAPTI_PHYSICALID_OOR 0x010a06#define E_ITS_INV_UNMAPPED_INTERRUPT 0x010c07#define E_ITS_INVALL_UNMAPPED_COLLECTION 0x010d09virt/kvm/arm/vgic/vgic-its.c +7
-1@@ -102,6 +102,7 @@ struct its_device {/* the head for the list of ITTEs */ struct list_head itt_head; +u32 nb_eventid_bits;u32 device_id; };@@ -180,6 +181,7 @@ static struct its_ite *find_ite(struct vgic_its *its, u32 device_id,#define GIC_LPI_OFFSET 8192#define VITS_ESZ 8 +#define VITS_TYPER_IDBITS 16/* * Finds and returns a collection in the ITS collection table. @@ -380,7 +382,7 @@ static unsigned long vgic_mmio_read_its_typer(struct kvm *kvm,* DevBits low - as least for the time being. */ reg |=0x0f <<GITS_TYPER_DEVBITS_SHIFT ; - reg |=0x0f <<GITS_TYPER_IDBITS_SHIFT ; + reg |= (VITS_TYPER_IDBITS -1 ) <<GITS_TYPER_IDBITS_SHIFT ; reg |= (VITS_ESZ -1 ) <<GITS_TYPER_ITT_ENTRY_SIZE_SHIFT ;return extract_bytes (reg, addr &7 , len);@@ -547,6 +549,7 @@ static u64 its_cmd_mask_field(u64 *its_cmd, int word, int shift, int size)#define its_cmd_get_command (cmd) its_cmd_mask_field(cmd, 0, 0, 8)#define its_cmd_get_deviceid (cmd) its_cmd_mask_field(cmd, 0, 32, 32) +#define its_cmd_get_size (cmd) its_cmd_mask_field(cmd, 1, 0, 5)#define its_cmd_get_id (cmd) its_cmd_mask_field(cmd, 1, 0, 32)#define its_cmd_get_physical_id (cmd) its_cmd_mask_field(cmd, 1, 32, 32)#define its_cmd_get_collection (cmd) its_cmd_mask_field(cmd, 2, 0, 16)@@ -737,6 +740,9 @@ static int vgic_its_cmd_handle_mapi(struct kvm *kvm, struct vgic_its *its,if (!device)return E_ITS_MAPTI_UNMAPPED_DEVICE ; +if (event_id >=BIT_ULL (device->nb_eventid_bits)) +return E_ITS_MAPTI_ID_OOR ; +if (its_cmd_get_command (its_cmd) ==GITS_CMD_MAPTI ) lpi_nr =its_cmd_get_physical_id (its_cmd);else
virt/kvm/arm/vgic/vgic-its.c static int vgic_its_cmd_handle_mapd(struct kvm *kvm, struct vgic_its *its, · line 826
Quoted 4 lines
virt/kvm/arm/vgic/vgic-its.c +1
-0@@ -817,11 +823,15 @@ static int vgic_its_cmd_handle_mapd(struct kvm *kvm, struct vgic_its *its, {u32 device_id =its_cmd_get_deviceid (its_cmd);bool valid =its_cmd_get_validbit (its_cmd); +u8 nb_eventid_bits =its_cmd_get_size (its_cmd) +1 ;
I feel it would be clearer if we had its_cmd_get_size() return the actual size, and not just the encoding of the size (i.e. put the +1 in the macro instead of the caller).
Quoted 12 lines
virt/kvm/arm/vgic/vgic-its.c +3
-0struct its_device *device;if (!vgic_its_check_id (its, its->baser_device_table, device_id))return E_ITS_MAPD_DEVICE_OOR ; +if (valid && nb_eventid_bits >VITS_TYPER_IDBITS ) +return E_ITS_MAPD_ITTSIZE_OOR ; + device =find_its_device (its, device_id);/*
virt/kvm/arm/vgic/vgic-its.c static int vgic_its_cmd_handle_mapd(struct kvm *kvm, struct vgic_its *its, · line 861
Quoted 8 lines
virt/kvm/arm/vgic/vgic-its.c +2
-0@@ -844,6 +854,8 @@ static int vgic_its_cmd_handle_mapd(struct kvm *kvm, struct vgic_its *its,return -ENOMEM ; device->device_id = device_id; + device->nb_eventid_bits = nb_eventid_bits; +INIT_LIST_HEAD (&device->itt_head);list_add_tail (&device->dev_list, &its->device_list);
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny.
PATCH v4 11/22 KVM: arm64: ITS: Interpret MAPD ITT_addr field
In reply to Eric AugerUp to now the MAPD ITT_addr had been ignored. We will need it for save/restore. Let's record it in the its_device struct.
---
v3 -> v4:
- in vgic_its_cmd_handle_mapd, itt_addr directly is shifted
- correct ittaddr bitmask to support 48bit GPA
--- virt/kvm/arm/vgic/vgic-its.c | 4 ++++ 1 file changed, 4 insertions(+)
virt/kvm/arm/vgic/vgic-its.c +4 -0
@@ -103,6 +103,7 @@ struct its_device {/* the head for the list of ITTEs */ struct list_head itt_head;u32 nb_eventid_bits; +gpa_t itt_addr;u32 device_id; };
@@ -553,6 +554,7 @@ static u64 its_cmd_mask_field(u64 *its_cmd, int word, int shift, int size)#define its_cmd_get_id (cmd) its_cmd_mask_field(cmd, 1, 0, 32)#define its_cmd_get_physical_id (cmd) its_cmd_mask_field(cmd, 1, 32, 32)#define its_cmd_get_collection (cmd) its_cmd_mask_field(cmd, 2, 0, 16) +#define its_cmd_get_ittaddr (cmd) its_cmd_mask_field(cmd, 2, 8, 47)#define its_cmd_get_target_addr (cmd) its_cmd_mask_field(cmd, 2, 16, 32)#define its_cmd_get_validbit (cmd) its_cmd_mask_field(cmd, 2, 63, 1)
@@ -824,6 +826,7 @@ static int vgic_its_cmd_handle_mapd(struct kvm *kvm, struct vgic_its *its,u32 device_id =its_cmd_get_deviceid (its_cmd);bool valid =its_cmd_get_validbit (its_cmd);u8 nb_eventid_bits =its_cmd_get_size (its_cmd) +1 ; +gpa_t itt_addr =its_cmd_get_ittaddr (its_cmd) <<8 ;struct its_device *device;if (!vgic_its_check_id (its, its->baser_device_table, device_id))
@@ -855,6 +858,7 @@ static int vgic_its_cmd_handle_mapd(struct kvm *kvm, struct vgic_its *its, device->device_id = device_id; device->nb_eventid_bits = nb_eventid_bits; + device->itt_addr = itt_addr;INIT_LIST_HEAD (&device->itt_head);
Signature · 1 line
2.5.5
Re: [PATCH v4 11/22] KVM: arm64: ITS: Interpret MAPD ITT_addr field
Quoted 35 lines · Eric Auger
Up to now the MAPD
ITT_addrhad been ignored. We will need it for save/restore. Let's record it in theits_devicestruct.Signed-off-by Eric Auger <[email protected]>---
v3 -> v4:
- invgic_its_cmd_handle_mapd,itt_addrdirectly is shifted
- correct ittaddr bitmask to support 48bit GPA--- virt/kvm/arm/vgic/vgic-its.c | 4 ++++ 1 file changed, 4 insertions(+)virt/kvm/arm/vgic/vgic-its.c +2
-0@@ -103,6 +103,7 @@ struct its_device {/* the head for the list of ITTEs */ struct list_head itt_head;u32 nb_eventid_bits; +gpa_t itt_addr;u32 device_id; };@@ -553,6 +554,7 @@ static u64 its_cmd_mask_field(u64 *its_cmd, int word, int shift, int size)#define its_cmd_get_id (cmd) its_cmd_mask_field(cmd, 1, 0, 32)#define its_cmd_get_physical_id (cmd) its_cmd_mask_field(cmd, 1, 32, 32)#define its_cmd_get_collection (cmd) its_cmd_mask_field(cmd, 2, 0, 16) +#define its_cmd_get_ittaddr (cmd) its_cmd_mask_field(cmd, 2, 8, 47)#define its_cmd_get_target_addr (cmd) its_cmd_mask_field(cmd, 2, 16, 32)#define its_cmd_get_validbit (cmd) its_cmd_mask_field(cmd, 2, 63, 1)
virt/kvm/arm/vgic/vgic-its.c static int vgic_its_cmd_handle_mapd(struct kvm *kvm, struct vgic_its *its, · line 829
Quoted 4 lines
virt/kvm/arm/vgic/vgic-its.c +1
-0@@ -824,6 +826,7 @@ static int vgic_its_cmd_handle_mapd(struct kvm *kvm, struct vgic_its *its,u32 device_id =its_cmd_get_deviceid (its_cmd);bool valid =its_cmd_get_validbit (its_cmd);u8 nb_eventid_bits =its_cmd_get_size (its_cmd) +1 ; +gpa_t itt_addr =its_cmd_get_ittaddr (its_cmd) <<8 ;
Same remark as previously. I'd rather have the macro returning something that is directly useful rather than having to shift afterwards.
virt/kvm/arm/vgic/vgic-its.c static int vgic_its_cmd_handle_mapd(struct kvm *kvm, struct vgic_its *its, · line 863
Quoted 10 lines
virt/kvm/arm/vgic/vgic-its.c +1
-0struct its_device *device;if (!vgic_its_check_id (its, its->baser_device_table, device_id))@@ -855,6 +858,7 @@ static int vgic_its_cmd_handle_mapd(struct kvm *kvm, struct vgic_its *its, device->device_id = device_id; device->nb_eventid_bits = nb_eventid_bits; + device->itt_addr = itt_addr;INIT_LIST_HEAD (&device->itt_head);
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny.
PATCH v4 12/22 KVM: arm64: ITS: Check the device id matches TYPER DEVBITS range
In reply to Eric AugerOn MAPD we currently check the device id can be stored in the device table. Let's first check it can be encoded within the range defined by TYPER DEVBITS.
---
v3 -> v4:
- VITS_TYPER_DEVBITS set to 16 for homogeneity
- use BIT_ULL
--- virt/kvm/arm/vgic/vgic-its.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
virt/kvm/arm/vgic/vgic-its.c +7 -3
@@ -183,6 +183,7 @@ static struct its_ite *find_ite(struct vgic_its *its, u32 device_id,#define VITS_ESZ 8#define VITS_TYPER_IDBITS 16 +#define VITS_TYPER_DEVBITS 16/* * Finds and returns a collection in the ITS collection table.
@@ -382,8 +383,8 @@ static unsigned long vgic_mmio_read_its_typer(struct kvm *kvm,* To avoid memory waste in the guest, we keep the number of IDBits and * DevBits low - as least for the time being. */ - reg |=0x0f <<GITS_TYPER_DEVBITS_SHIFT ; reg |= (VITS_TYPER_IDBITS -1 ) <<GITS_TYPER_IDBITS_SHIFT ; + reg |= (VITS_TYPER_DEVBITS -1 ) <<GITS_TYPER_DEVBITS_SHIFT ; reg |= (VITS_ESZ -1 ) <<GITS_TYPER_ITT_ENTRY_SIZE_SHIFT ;return extract_bytes (reg, addr &7 , len);
@@ -623,10 +624,10 @@ static int vgic_its_cmd_handle_movi(struct kvm *kvm, struct vgic_its *its,* Check whether an ID can be stored into the corresponding guest table. * For a direct table this is pretty easy, but gets a bit nasty for * indirect tables. We check whether the resulting guest physical address -* is actually valid (covered by a memslot and guest accessbible). +* is actually valid (covered by a memslot and guest accessible). * For this we have to read the respective first level entry. */ -static bool vgic_its_check_id (struct vgic_its *its,u64 baser,int id) +static bool vgic_its_check_id (struct vgic_its *its,u64 baser,u32 id) {int l1_tbl_size =GITS_BASER_NR_PAGES (baser) *SZ_64K ;int index;
@@ -634,6 +635,9 @@ static bool vgic_its_check_id(struct vgic_its *its, u64 baser, int id)gfn_t gfn;int esz =GITS_BASER_ENTRY_SIZE (baser); +if (id >=BIT_ULL (VITS_TYPER_DEVBITS )) +return false; +if (!(baser &GITS_BASER_INDIRECT )) {phys_addr_t addr;
Signature · 1 line
2.5.5
PATCH v4 13/22 KVM: arm64: ITS: KVM_DEV_ARM_VGIC_GRP_ITS_TABLES group
In reply to Eric AugerIntroduce a new group aiming at saving/restoring the ITS tables to/from the guest memory.
We hold the vcpus lock during the save and restore to make sure no vcpu is running.
At this stage the functionality is not yet implemented. Only the skeleton is put in place.
The ABI revision supposed to have been set through IIDR user write is checked before the table restoration. This guarantees this vITS knows how to restore the saved tables.
---
v3 -> v4:
- pass kvm struct handle to vgic_its_flush/restore_pending_tables
- take the kvm lock and vcpu locks
- ABI revision check
- check attr->attr is null
v1 -> v2:
- remove useless kvm parameter
--- arch/arm/include/uapi/asm/kvm.h | 1 + arch/arm64/include/uapi/asm/kvm.h | 1 + virt/kvm/arm/vgic/vgic-its.c | 142 +++++++++++++++++++++++++++++++++++++- 3 files changed, 143 insertions(+), 1 deletion(-)
arch/arm/include/uapi/asm/kvm.h +1 -0
@@ -193,6 +193,7 @@ struct kvm_arch_memory_slot {#define KVM_DEV_ARM_VGIC_GRP_CPU_SYSREGS 6#define KVM_DEV_ARM_VGIC_GRP_LEVEL_INFO 7#define KVM_DEV_ARM_VGIC_GRP_ITS_REGS 8 +#define KVM_DEV_ARM_VGIC_GRP_ITS_TABLES 9#define KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_SHIFT 10#define KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_MASK \ (0x3fffffULL << KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_SHIFT)
arch/arm64/include/uapi/asm/kvm.h +1 -0
@@ -213,6 +213,7 @@ struct kvm_arch_memory_slot {#define KVM_DEV_ARM_VGIC_GRP_CPU_SYSREGS 6#define KVM_DEV_ARM_VGIC_GRP_LEVEL_INFO 7#define KVM_DEV_ARM_VGIC_GRP_ITS_REGS 8 +#define KVM_DEV_ARM_VGIC_GRP_ITS_TABLES 9#define KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_SHIFT 10#define KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_MASK \ (0x3fffffULL << KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_SHIFT)
virt/kvm/arm/vgic/vgic-its.c +141 -1
174 lines not on this page · raw message
Signature · 1 line
2.5.5
kbuild test robot
build botRe: [PATCH v4 13/22] KVM: arm64: ITS: KVM_DEV_ARM_VGIC_GRP_ITS_TABLES group
reproduce: wget https://raw.githubusercontent.com/01org/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # save the attached .config to linux build tree make.cross…
Hi Eric,
[auto build test ERROR on kvmarm/next]
[also build test ERROR on v4.11-rc4 next-20170327]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Eric-Auger/vITS-save-restore/20170327-195443 base: https://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm.git next config: arm64-defconfig (attached as .config) compiler: aarch64-linux-gnu-gcc (Debian 6.1.1-9) 6.1.1 20160705
reproduce:
wget https://raw.githubusercontent.com/01org/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=arm64
All errors (new ones prefixed by >>):
arch/arm64/kvm/../../../virt/kvm/arm/vgic/vgic-its.c: In function 'vgic_its_has_attr':
>> arch/arm64/kvm/../../../virt/kvm/arm/vgic/vgic-its.c:1766:33: error: 'its' undeclared (first use in this function)
return vgic_its_table_restore(its);
^~~ arch/arm64/kvm/../../../virt/kvm/arm/vgic/vgic-its.c:1766:33: note: each undeclared identifier is reported only once for each function it appears in
vim +/its +1766 arch/arm64/kvm/../../../virt/kvm/arm/vgic/vgic-its.c
1750 case KVM_DEV_ARM_VGIC_CTRL_INIT:
1751 return 0;
1752 }
1753 break;
1754 case KVM_DEV_ARM_VGIC_GRP_ITS_REGS: {
1755 u64 __user *uaddr = (u64 __user *)(long)attr->addr;
1756 u64 reg;
1757
1758 if (get_user(reg, uaddr))
1759 return -EFAULT;
1760
1761 return vgic_its_attr_regs_access(dev, attr, ®, true);
1762 }
1763 case KVM_DEV_ARM_VGIC_GRP_ITS_TABLES:
1764 if (attr->attr)
1765 return -EINVAL;
> 1766 return vgic_its_table_restore(its);
1767 }
1768 return -ENXIO;
1769 }
1770
1771 static int vgic_its_set_attr(struct kvm_device *dev,
1772 struct kvm_device_attr *attr)
1773 {
1774 struct vgic_its *its = dev->private;
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Re: [PATCH v4 13/22] KVM: arm64: ITS: KVM_DEV_ARM_VGIC_GRP_ITS_TABLES group
Hi,
Quoted 16 lines · kbuild test robot
Hi Eric,
[auto build test ERROR on kvmarm/next]
[also build test ERROR on v4.11-rc4 next-20170327]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]url: https://github.com/0day-ci/linux/commits/Eric-Auger/vITS-save-restore/20170327-195443 base: https://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm.git next config: arm64-defconfig (attached as .config) compiler: aarch64-linux-gnu-gcc (Debian 6.1.1-9) 6.1.1 20160705reproduce:
wget https://raw.githubusercontent.com/01org/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=arm64
Quoted 5 lines
All errors (new ones prefixed by >>):
arch/arm64/kvm/../../../virt/kvm/arm/vgic/vgic-its.c: In function 'vgic_its_has_attr':Quoted 1 line
Quoted 1 line
arch/arm64/kvm/../../../virt/kvm/arm/vgic/vgic-its.c:1766:33: error: 'its' undeclared (first use in this function)return vgic_its_table_restore(its);
I think this is due to the fact the series is applied on KVM: arm/arm64:
Emulate the EL1 phys timer registers (kvmarm-for-4.11).
Please apply it to (kvmarm/queue, kvmarm/next, kvm_next) KVM: arm/arm64:
vgic: Improve sync_hwstate performance (255905e)
I also checked it compiles on 4.11-rc4.
Please let me know if I got something wrong.
Thanks
Eric
Quoted 42 lines
^~~
arch/arm64/kvm/../../../virt/kvm/arm/vgic/vgic-its.c:1766:33: note: each undeclared identifier is reported only once for each function it appears invim +/its +1766
arch/arm64/kvm/../../../virt/kvm/arm/vgic/vgic-its.c1750 case
KVM_DEV_ARM_VGIC_CTRL_INIT:
1751 return 0;
1752 }
1753 break;
1754 caseKVM_DEV_ARM_VGIC_GRP_ITS_REGS: {
1755 u64__user*uaddr = (u64__user*)(long)attr->addr;
1756 u64 reg;
1757
1758 if (get_user(reg, uaddr))
1759 return-EFAULT;
1760
1761 returnvgic_its_attr_regs_access(dev, attr, ®, true);
1762 }
1763 caseKVM_DEV_ARM_VGIC_GRP_ITS_TABLES:
1764 if (attr->attr)
1765 return-EINVAL;Quoted 1 line
1766 return
vgic_its_table_restore(its);1767 }
1768 return-ENXIO;
1769 }
1770
1771 static int vgic_its_set_attr(structkvm_device*dev,
1772 structkvm_device_attr*attr)
1773 {
1774 structvgic_its*its =dev->private;---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [kbuild-all] [PATCH v4 13/22] KVM: arm64: ITS: KVM_DEV_ARM_VGIC_GRP_ITS_TABLES group
Hi, Eric
Quoted 23 lines · Auger Eric
Hi,
Quoted 20 lines · kbuild test robot
Hi Eric,
[auto build test ERROR on kvmarm/next]
[also build test ERROR on v4.11-rc4 next-20170327]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]url: https://github.com/0day-ci/linux/commits/Eric-Auger/vITS-save-restore/20170327-195443 base: https://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm.git next config: arm64-defconfig (attached as .config) compiler: aarch64-linux-gnu-gcc (Debian 6.1.1-9) 6.1.1 20160705reproduce:
wget https://raw.githubusercontent.com/01org/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=arm64All errors (new ones prefixed by >>):
arch/arm64/kvm/../../../virt/kvm/arm/vgic/vgic-its.c: In function 'vgic_its_has_attr':Quoted 1 line
Quoted 1 line
arch/arm64/kvm/../../../virt/kvm/arm/vgic/vgic-its.c:1766:33: error: 'its' undeclared (first use in this function)
Quoted 8 lines
Quoted 1 line
return vgic_its_table_restore(its);I think this is due to the fact the series is applied on KVM: arm/arm64:
Emulate the EL1 phys timer registers (kvmarm-for-4.11).Please apply it to (kvmarm/queue, kvmarm/next,
kvm_next) KVM: arm/arm64:
vgic: Improvesync_hwstateperformance (255905e)
I also checked it compiles on 4.11-rc4.
Hmm, we did apply your series on top of kvarm/next, judging from the function code below, I can't see the 'its' declaration.
static int vgic_its_has_attr(struct kvm_device *dev,
struct kvm_device_attr *attr)
{
switch (attr->group) {
case KVM_DEV_ARM_VGIC_GRP_ADDR:
switch (attr->attr) {
case KVM_VGIC_ITS_ADDR_TYPE:
return 0;
}
break;
case KVM_DEV_ARM_VGIC_GRP_CTRL:
switch (attr->attr) {
case KVM_DEV_ARM_VGIC_CTRL_INIT:
return 0;
}
break;
case KVM_DEV_ARM_VGIC_GRP_ITS_REGS: {
u64 __user *uaddr = (u64 __user *)(long)attr->addr;
u64 reg;
if (get_user(reg, uaddr))
return -EFAULT;
return vgic_its_attr_regs_access(dev, attr, ®, true);
}
case KVM_DEV_ARM_VGIC_GRP_ITS_TABLES:
if (attr->attr)
return -EINVAL;
return vgic_its_table_restore(its);
}
return -ENXIO;
}Thanks,
Xiaolong
Quoted 52 lines
Please let me know if I got something wrong.
Thanks
Eric
Quoted 37 lines
^~~
arch/arm64/kvm/../../../virt/kvm/arm/vgic/vgic-its.c:1766:33: note: each undeclared identifier is reported only once for each function it appears invim +/its +1766
arch/arm64/kvm/../../../virt/kvm/arm/vgic/vgic-its.c1750 case
KVM_DEV_ARM_VGIC_CTRL_INIT:
1751 return 0;
1752 }
1753 break;
1754 caseKVM_DEV_ARM_VGIC_GRP_ITS_REGS: {
1755 u64__user*uaddr = (u64__user*)(long)attr->addr;
1756 u64 reg;
1757
1758 if (get_user(reg, uaddr))
1759 return-EFAULT;
1760
1761 returnvgic_its_attr_regs_access(dev, attr, ®, true);
1762 }
1763 caseKVM_DEV_ARM_VGIC_GRP_ITS_TABLES:
1764 if (attr->attr)
1765 return-EINVAL;Quoted 1 line
1766 return
vgic_its_table_restore(its);1767 }
1768 return-ENXIO;
1769 }
1770
1771 static int vgic_its_set_attr(structkvm_device*dev,
1772 structkvm_device_attr*attr)
1773 {
1774 structvgic_its*its =dev->private;---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel CorporationQuoted 5 lines
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel_______________________________________________
kbuild-all mailing list
[email protected]
https://lists.01.org/mailman/listinfo/kbuild-all
Re: [kbuild-all] [PATCH v4 13/22] KVM: arm64: ITS: KVM_DEV_ARM_VGIC_GRP_ITS_TABLES group
Hi Xiaolong
Quoted 59 lines · Ye Xiaolong
Hi, Eric
Quoted 23 lines · Auger Eric
Hi,
Quoted 20 lines · kbuild test robot
Hi Eric,
[auto build test ERROR on kvmarm/next]
[also build test ERROR on v4.11-rc4 next-20170327]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]url: https://github.com/0day-ci/linux/commits/Eric-Auger/vITS-save-restore/20170327-195443 base: https://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm.git next config: arm64-defconfig (attached as .config) compiler: aarch64-linux-gnu-gcc (Debian 6.1.1-9) 6.1.1 20160705reproduce:
wget https://raw.githubusercontent.com/01org/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=arm64All errors (new ones prefixed by >>):
arch/arm64/kvm/../../../virt/kvm/arm/vgic/vgic-its.c: In function 'vgic_its_has_attr':Quoted 1 line
Quoted 1 line
arch/arm64/kvm/../../../virt/kvm/arm/vgic/vgic-its.c:1766:33: error: 'its' undeclared (first use in this function)Quoted 8 lines
Quoted 1 line
return vgic_its_table_restore(its);I think this is due to the fact the series is applied on KVM: arm/arm64:
Emulate the EL1 phys timer registers (kvmarm-for-4.11).Please apply it to (kvmarm/queue, kvmarm/next,
kvm_next) KVM: arm/arm64:
vgic: Improvesync_hwstateperformance (255905e)
I also checked it compiles on 4.11-rc4.Hmm, we did apply your series on top of kvarm/next, judging from the function code below, I can't see the 'its' declaration.
static int vgic_its_has_attr(struct
kvm_device*dev,
structkvm_device_attr*attr){ switch (attr->group) { case KVM_DEV_ARM_VGIC_GRP_ADDR: switch (attr->attr) { case KVM_VGIC_ITS_ADDR_TYPE: return 0; } break; case KVM_DEV_ARM_VGIC_GRP_CTRL: switch (attr->attr) { case KVM_DEV_ARM_VGIC_CTRL_INIT: return 0; } break; case KVM_DEV_ARM_VGIC_GRP_ITS_REGS: { u64 __user *uaddr = (u64 __user *)(long)attr->addr; u64 reg; if (get_user(reg, uaddr))
Quoted 8 lines
return -EFAULT;
return vgic_its_attr_regs_access(dev, attr, ®, true);
}
case KVM_DEV_ARM_VGIC_GRP_ITS_TABLES:
if (attr->attr)
return -EINVAL;
return vgic_its_table_restore(its);The above code shows that my series is not correctly applied since that call to vgic_its_table_restore() should normally be in vgic_its_set_attr() and not in vgic_its_has_attr() function (virt/kvm/arm/vgic-its.c).
I pushed this series applied on top of up to date kvmarm/next at
https://github.com/eauger/linux/tree/v4.11-rc3-its-mig-v4.
As noticed earlier, the series is applied on top of 255905e (KVM:
arm/arm64: vgic: Improve sync_hwstate performance)
Thanks
Eric
Quoted 65 lines
} return -ENXIO; }Thanks,
XiaolongQuoted 48 lines
Please let me know if I got something wrong.
Thanks
Eric
Quoted 37 lines
^~~
arch/arm64/kvm/../../../virt/kvm/arm/vgic/vgic-its.c:1766:33: note: each undeclared identifier is reported only once for each function it appears invim +/its +1766
arch/arm64/kvm/../../../virt/kvm/arm/vgic/vgic-its.c1750 case
KVM_DEV_ARM_VGIC_CTRL_INIT:
1751 return 0;
1752 }
1753 break;
1754 caseKVM_DEV_ARM_VGIC_GRP_ITS_REGS: {
1755 u64__user*uaddr = (u64__user*)(long)attr->addr;
1756 u64 reg;
1757
1758 if (get_user(reg, uaddr))
1759 return-EFAULT;
1760
1761 returnvgic_its_attr_regs_access(dev, attr, ®, true);
1762 }
1763 caseKVM_DEV_ARM_VGIC_GRP_ITS_TABLES:
1764 if (attr->attr)
1765 return-EINVAL;Quoted 1 line
1766 return
vgic_its_table_restore(its);1767 }
1768 return-ENXIO;
1769 }
1770
1771 static int vgic_its_set_attr(structkvm_device*dev,
1772 structkvm_device_attr*attr)
1773 {
1774 structvgic_its*its =dev->private;---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel CorporationQuoted 5 lines
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernelQuoted 4 lines
_______________________________________________
kbuild-all mailing list
[email protected]
https://lists.01.org/mailman/listinfo/kbuild-all_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [kbuild-all] [PATCH v4 13/22] KVM: arm64: ITS: KVM_DEV_ARM_VGIC_GRP_ITS_TABLES group
Quoted 70 lines · Auger Eric
Hi Xiaolong
Quoted 59 lines · Ye Xiaolong
Hi, Eric
Quoted 23 lines · Auger Eric
Hi,
Quoted 20 lines · kbuild test robot
Hi Eric,
[auto build test ERROR on kvmarm/next]
[also build test ERROR on v4.11-rc4 next-20170327]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]url: https://github.com/0day-ci/linux/commits/Eric-Auger/vITS-save-restore/20170327-195443 base: https://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm.git next config: arm64-defconfig (attached as .config) compiler: aarch64-linux-gnu-gcc (Debian 6.1.1-9) 6.1.1 20160705reproduce:
wget https://raw.githubusercontent.com/01org/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=arm64All errors (new ones prefixed by >>):
arch/arm64/kvm/../../../virt/kvm/arm/vgic/vgic-its.c: In function 'vgic_its_has_attr':Quoted 1 line
Quoted 1 line
arch/arm64/kvm/../../../virt/kvm/arm/vgic/vgic-its.c:1766:33: error: 'its' undeclared (first use in this function)Quoted 8 lines
Quoted 1 line
return vgic_its_table_restore(its);I think this is due to the fact the series is applied on KVM: arm/arm64:
Emulate the EL1 phys timer registers (kvmarm-for-4.11).Please apply it to (kvmarm/queue, kvmarm/next,
kvm_next) KVM: arm/arm64:
vgic: Improvesync_hwstateperformance (255905e)
I also checked it compiles on 4.11-rc4.Hmm, we did apply your series on top of kvarm/next, judging from the function code below, I can't see the 'its' declaration.
static int vgic_its_has_attr(struct
kvm_device*dev,
structkvm_device_attr*attr){ switch (attr->group) { case KVM_DEV_ARM_VGIC_GRP_ADDR: switch (attr->attr) { case KVM_VGIC_ITS_ADDR_TYPE: return 0; } break; case KVM_DEV_ARM_VGIC_GRP_CTRL: switch (attr->attr) { case KVM_DEV_ARM_VGIC_CTRL_INIT: return 0; } break; case KVM_DEV_ARM_VGIC_GRP_ITS_REGS: { u64 __user *uaddr = (u64 __user *)(long)attr->addr; u64 reg; if (get_user(reg, uaddr))Quoted 8 lines
return -EFAULT; return vgic_its_attr_regs_access(dev, attr, ®, true); } case KVM_DEV_ARM_VGIC_GRP_ITS_TABLES: if (attr->attr) return -EINVAL; return vgic_its_table_restore(its);
Quoted 5 lines
The above code shows that my series is not correctly applied since that call to
vgic_its_table_restore()should normally be invgic_its_set_attr()and not invgic_its_has_attr()function (virt/kvm/arm/vgic-its.c).
Er, you are right, the real problem here seems we had a rather old kvmarm/next mirror at the time 0day applied your series.
Thanks for the clarification and sorry for the noise.
Thanks,
Xiaolong
Quoted 76 lines
I pushed this series applied on top of up to date kvmarm/next at
https://github.com/eauger/linux/tree/v4.11-rc3-its-mig-v4.As noticed earlier, the series is applied on top of 255905e (KVM:
arm/arm64: vgic: Improvesync_hwstateperformance)Thanks
Eric
Quoted 65 lines
} return -ENXIO; }Thanks,
XiaolongQuoted 48 lines
Please let me know if I got something wrong.
Thanks
Eric
Quoted 37 lines
^~~
arch/arm64/kvm/../../../virt/kvm/arm/vgic/vgic-its.c:1766:33: note: each undeclared identifier is reported only once for each function it appears invim +/its +1766
arch/arm64/kvm/../../../virt/kvm/arm/vgic/vgic-its.c1750 case
KVM_DEV_ARM_VGIC_CTRL_INIT:
1751 return 0;
1752 }
1753 break;
1754 caseKVM_DEV_ARM_VGIC_GRP_ITS_REGS: {
1755 u64__user*uaddr = (u64__user*)(long)attr->addr;
1756 u64 reg;
1757
1758 if (get_user(reg, uaddr))
1759 return-EFAULT;
1760
1761 returnvgic_its_attr_regs_access(dev, attr, ®, true);
1762 }
1763 caseKVM_DEV_ARM_VGIC_GRP_ITS_TABLES:
1764 if (attr->attr)
1765 return-EINVAL;Quoted 1 line
1766 return
vgic_its_table_restore(its);1767 }
1768 return-ENXIO;
1769 }
1770
1771 static int vgic_its_set_attr(structkvm_device*dev,
1772 structkvm_device_attr*attr)
1773 {
1774 structvgic_its*its =dev->private;---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel CorporationQuoted 5 lines
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernelQuoted 4 lines
_______________________________________________
kbuild-all mailing list
[email protected]
https://lists.01.org/mailman/listinfo/kbuild-all_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [kbuild-all] [PATCH v4 13/22] KVM: arm64: ITS: KVM_DEV_ARM_VGIC_GRP_ITS_TABLES group
Hi Xiaolong,
Quoted 77 lines · Ye Xiaolong
Quoted 70 lines · Auger Eric
Hi Xiaolong
Quoted 59 lines · Ye Xiaolong
Hi, Eric
Quoted 23 lines · Auger Eric
Hi,
Quoted 20 lines · kbuild test robot
Hi Eric,
[auto build test ERROR on kvmarm/next]
[also build test ERROR on v4.11-rc4 next-20170327]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]url: https://github.com/0day-ci/linux/commits/Eric-Auger/vITS-save-restore/20170327-195443 base: https://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm.git next config: arm64-defconfig (attached as .config) compiler: aarch64-linux-gnu-gcc (Debian 6.1.1-9) 6.1.1 20160705reproduce:
wget https://raw.githubusercontent.com/01org/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=arm64All errors (new ones prefixed by >>):
arch/arm64/kvm/../../../virt/kvm/arm/vgic/vgic-its.c: In function 'vgic_its_has_attr':Quoted 1 line
Quoted 1 line
arch/arm64/kvm/../../../virt/kvm/arm/vgic/vgic-its.c:1766:33: error: 'its' undeclared (first use in this function)Quoted 8 lines
Quoted 1 line
return vgic_its_table_restore(its);I think this is due to the fact the series is applied on KVM: arm/arm64:
Emulate the EL1 phys timer registers (kvmarm-for-4.11).Please apply it to (kvmarm/queue, kvmarm/next,
kvm_next) KVM: arm/arm64:
vgic: Improvesync_hwstateperformance (255905e)
I also checked it compiles on 4.11-rc4.Hmm, we did apply your series on top of kvarm/next, judging from the function code below, I can't see the 'its' declaration.
static int vgic_its_has_attr(struct
kvm_device*dev,
structkvm_device_attr*attr){ switch (attr->group) { case KVM_DEV_ARM_VGIC_GRP_ADDR: switch (attr->attr) { case KVM_VGIC_ITS_ADDR_TYPE: return 0; } break; case KVM_DEV_ARM_VGIC_GRP_CTRL: switch (attr->attr) { case KVM_DEV_ARM_VGIC_CTRL_INIT: return 0; } break; case KVM_DEV_ARM_VGIC_GRP_ITS_REGS: { u64 __user *uaddr = (u64 __user *)(long)attr->addr; u64 reg; if (get_user(reg, uaddr))Quoted 8 lines
return -EFAULT; return vgic_its_attr_regs_access(dev, attr, ®, true); } case KVM_DEV_ARM_VGIC_GRP_ITS_TABLES: if (attr->attr) return -EINVAL; return vgic_its_table_restore(its);Quoted 5 lines
The above code shows that my series is not correctly applied since that call to
vgic_its_table_restore()should normally be invgic_its_set_attr()and not invgic_its_has_attr()function (virt/kvm/arm/vgic-its.c).
Quoted 4 lines
Er, you are right, the real problem here seems we had a rather old kvmarm/next mirror at the time 0day applied your series.
Thanks for the clarification and sorry for the noise.
no worries
Thanks
Eric
Quoted 79 lines
Thanks,
XiaolongQuoted 76 lines
I pushed this series applied on top of up to date kvmarm/next at
https://github.com/eauger/linux/tree/v4.11-rc3-its-mig-v4.As noticed earlier, the series is applied on top of 255905e (KVM:
arm/arm64: vgic: Improvesync_hwstateperformance)Thanks
Eric
Quoted 65 lines
} return -ENXIO; }Thanks,
XiaolongQuoted 48 lines
Please let me know if I got something wrong.
Thanks
Eric
Quoted 37 lines
^~~
arch/arm64/kvm/../../../virt/kvm/arm/vgic/vgic-its.c:1766:33: note: each undeclared identifier is reported only once for each function it appears invim +/its +1766
arch/arm64/kvm/../../../virt/kvm/arm/vgic/vgic-its.c1750 case
KVM_DEV_ARM_VGIC_CTRL_INIT:
1751 return 0;
1752 }
1753 break;
1754 caseKVM_DEV_ARM_VGIC_GRP_ITS_REGS: {
1755 u64__user*uaddr = (u64__user*)(long)attr->addr;
1756 u64 reg;
1757
1758 if (get_user(reg, uaddr))
1759 return-EFAULT;
1760
1761 returnvgic_its_attr_regs_access(dev, attr, ®, true);
1762 }
1763 caseKVM_DEV_ARM_VGIC_GRP_ITS_TABLES:
1764 if (attr->attr)
1765 return-EINVAL;Quoted 1 line
1766 return
vgic_its_table_restore(its);1767 }
1768 return-ENXIO;
1769 }
1770
1771 static int vgic_its_set_attr(structkvm_device*dev,
1772 structkvm_device_attr*attr)
1773 {
1774 structvgic_its*its =dev->private;---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel CorporationQuoted 5 lines
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernelQuoted 4 lines
_______________________________________________
kbuild-all mailing list
[email protected]
https://lists.01.org/mailman/listinfo/kbuild-all_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v4 13/22] KVM: arm64: ITS: KVM_DEV_ARM_VGIC_GRP_ITS_TABLES group
In reply to Eric AugerQuoted 6 lines · Eric Auger
Introduce a new group aiming at saving/restoring the ITS tables to/from the guest memory.
We hold the vcpus lock during the save and restore to make sure no vcpu is running.
Quoted 6 lines
At this stage the functionality is not yet implemented. Only the skeleton is put in place.
The ABI revision supposed to have been set through IIDR user write is checked before the table restoration. This guarantees this vITS knows how to restore the saved tables.
This last point hints at the kernel side being able to deal with multiple versions of the ABI. As I mentioned before, this requires some clarification on what we plan to support, and whether or not we are able to deprecate ABIs in the long run
One thing that is not clear to me is that although you want to be able to restore the vITS using a given ABI, should you be able to save it using that same ABI? Or does a restore/save cycle act as an ABI upgrade for this VM?
I'd also like to see some infrastructure in the code to support this, in the form of a per-ABI array of support functions (even if we only have one ABI for the time being). Although that's not required ATM, it would certainly halp me understanding what is ABI-specific and what's not.
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny.
PATCH v4 14/22 KVM: arm64: ITS: vgic_its_alloc_ite/device
In reply to Eric AugerAdd two new helpers to allocate an its ite and an its device. This will avoid duplication on restore path.
---
v3 -> v4:
- fix allocation
- add comment about its_lock mutex hold
v1 -> v2:
- report itt_size fix and remove ITE_SIZE
- s/itte/ite/g
--- virt/kvm/arm/vgic/vgic-its.c | 73 ++++++++++++++++++++++++++++++-------------- 1 file changed, 50 insertions(+), 23 deletions(-)
virt/kvm/arm/vgic/vgic-its.c +50 -23
@@ -726,6 +726,27 @@ static void vgic_its_free_collection(struct vgic_its *its, u32 coll_id)kfree (collection); } +/* Must be called with its_lock mutex held */ +static int vgic_its_alloc_ite (struct its_device *device, +struct its_ite **itep, +struct its_collection *collection, +u32 lpi_id,u32 event_id) +{ +struct its_ite *ite; + + ite =kzalloc (sizeof (*ite),GFP_KERNEL ); +if (!ite) +return -ENOMEM ; + + ite->event_id = event_id; + ite->collection = collection; + ite->lpi = lpi_id; + +list_add_tail (&ite->ite_list, &device->itt_head); + *itep = ite; +return 0 ; +} +/* * The MAPTI and MAPI commands map LPIs to ITTEs. * Must be called with its_lock mutex held.
@@ -739,7 +760,7 @@ static int vgic_its_cmd_handle_mapi(struct kvm *kvm, struct vgic_its *its,struct its_ite *ite;struct its_device *device;struct its_collection *collection, *new_coll =NULL ; -int lpi_nr; +int lpi_nr, ret;struct vgic_irq *irq; device =find_its_device (its, device_id);
@@ -769,19 +790,13 @@ static int vgic_its_cmd_handle_mapi(struct kvm *kvm, struct vgic_its *its, new_coll = collection; } - ite =kzalloc (sizeof (struct its_ite ),GFP_KERNEL ); -if (!ite) { + ret =vgic_its_alloc_ite (device, &ite, collection, lpi_nr, event_id); +if (ret) {if (new_coll)vgic_its_free_collection (its, coll_id); -return -ENOMEM ; +return ret; } - ite->event_id = event_id; -list_add_tail (&ite->ite_list, &device->itt_head); - - ite->collection = collection; - ite->lpi = lpi_nr; - irq =vgic_add_lpi (kvm, lpi_nr);if (IS_ERR (irq)) {if (new_coll)
@@ -820,6 +835,29 @@ static void vgic_its_unmap_device(struct kvm *kvm, struct its_device *device)kfree (device); } +/* Must be called with its_lock mutex held */ +static int vgic_its_alloc_device (struct vgic_its *its, +struct its_device **devp, +u32 device_id,gpa_t itt_addr, +u8 nb_eventid_bits) +{ +struct its_device *device; + + device =kzalloc (sizeof (*device),GFP_KERNEL ); +if (!device) +return -ENOMEM ; + + device->device_id = device_id; + device->itt_addr = itt_addr; + device->nb_eventid_bits = nb_eventid_bits; +INIT_LIST_HEAD (&device->itt_head); + +list_add_tail (&device->dev_list, &its->device_list); + *devp = device; + +return 0 ; +} +/* * MAPD maps or unmaps a device ID to Interrupt Translation Tables (ITTs). * Must be called with the its_lock mutex held.
@@ -856,19 +894,8 @@ static int vgic_its_cmd_handle_mapd(struct kvm *kvm, struct vgic_its *its,if (!valid)return 0 ; - device =kzalloc (sizeof (struct its_device ),GFP_KERNEL ); -if (!device) -return -ENOMEM ; - - device->device_id = device_id; - device->nb_eventid_bits = nb_eventid_bits; - device->itt_addr = itt_addr; - -INIT_LIST_HEAD (&device->itt_head); - -list_add_tail (&device->dev_list, &its->device_list); - -return 0 ; +return vgic_its_alloc_device (its, &device, device_id, + itt_addr, nb_eventid_bits); }/*
Signature · 1 line
2.5.5
Re: [PATCH v4 14/22] KVM: arm64: ITS: vgic_its_alloc_ite/device
Quoted 4 lines · Eric Auger
Add two new helpers to allocate an its ite and an its device. This will avoid duplication on restore path.
Signed-off-by Eric Auger <[email protected]>
M.
Signature · 1 line
Jazz is not dead. It just smells funny.
PATCH v4 15/22 KVM: arm64: ITS: Sort the device and ITE lists
In reply to Eric AugerNatively sort the device and ITE lists in ascending deviceId/eventid order. This paves the way to optimized DTE and ITE scan in guest RAM table where entries are chained together using a next ID offset.
---
v3 -> v4:
- added Andre's R-b
--- virt/kvm/arm/vgic/vgic-its.c | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-)
virt/kvm/arm/vgic/vgic-its.c +34 -2
@@ -726,6 +726,21 @@ static void vgic_its_free_collection(struct vgic_its *its, u32 coll_id)kfree (collection); } +static void ite_list_insert_sorted (struct list_head *h,struct its_ite *ite) +{ +struct list_head *pos = h->next; +u32 id = ite->event_id; + +while (pos != h) { +struct its_ite *iter = + list_entry(pos, struct its_ite, ite_list); +if (id < iter->event_id) +break ; + pos = pos->next; + } +list_add_tail (&ite->ite_list, pos); +} +/* Must be called with its_lock mutex held */ static int vgic_its_alloc_ite(struct its_device *device, struct its_ite **itep,
@@ -742,7 +757,7 @@ static int vgic_its_alloc_ite(struct its_device *device, ite->collection = collection; ite->lpi = lpi_id; -list_add_tail (&ite->ite_list, &device->itt_head); +ite_list_insert_sorted (&device->itt_head, ite); *itep = ite;return 0 ; }
@@ -835,6 +850,22 @@ static void vgic_its_unmap_device(struct kvm *kvm, struct its_device *device)kfree (device); } +static void device_list_insert_sorted (struct list_head *h, +struct its_device *dev) +{ +struct list_head *pos = h->next; +u32 id = dev->device_id; + +while (pos != h) { +struct its_device *iter = + list_entry(pos, struct its_device, dev_list); +if (id < iter->device_id) +break ; + pos = pos->next; + } +list_add_tail (&dev->dev_list, pos); +} +/* Must be called with its_lock mutex held */ static int vgic_its_alloc_device(struct vgic_its *its, struct its_device **devp,
@@ -852,7 +883,8 @@ static int vgic_its_alloc_device(struct vgic_its *its, device->nb_eventid_bits = nb_eventid_bits;INIT_LIST_HEAD (&device->itt_head); -list_add_tail (&device->dev_list, &its->device_list); +device_list_insert_sorted (&its->device_list, device); + *devp = device;return 0 ;
Signature · 1 line
2.5.5
Re: [PATCH v4 15/22] KVM: arm64: ITS: Sort the device and ITE lists
Quoted 75 lines · Eric Auger
Natively sort the device and ITE lists in ascending deviceId/eventid order. This paves the way to optimized DTE and ITE scan in guest RAM table where entries are chained together using a next ID offset.
Signed-off-by Eric Auger <[email protected]>Reviewed-by Andre Przywara <[email protected]>---
v3 -> v4:
- added Andre's R-b--- virt/kvm/arm/vgic/vgic-its.c | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-)virt/kvm/arm/vgic/vgic-its.c +32
-1@@ -726,6 +726,21 @@ static void vgic_its_free_collection(struct vgic_its *its, u32 coll_id)kfree (collection); } +static void ite_list_insert_sorted (struct list_head *h,struct its_ite *ite) +{ +struct list_head *pos = h->next; +u32 id = ite->event_id; + +while (pos != h) { +struct its_ite *iter = + list_entry(pos, struct its_ite, ite_list); +if (id < iter->event_id) +break ; + pos = pos->next; + } +list_add_tail (&ite->ite_list, pos); +} +/* Must be called with its_lock mutex held */ static int vgic_its_alloc_ite(struct its_device *device, struct its_ite **itep,@@ -742,7 +757,7 @@ static int vgic_its_alloc_ite(struct its_device *device, ite->collection = collection; ite->lpi = lpi_id; -list_add_tail (&ite->ite_list, &device->itt_head); +ite_list_insert_sorted (&device->itt_head, ite); *itep = ite;return 0 ; }@@ -835,6 +850,22 @@ static void vgic_its_unmap_device(struct kvm *kvm, struct its_device *device)kfree (device); } +static void device_list_insert_sorted (struct list_head *h, +struct its_device *dev) +{ +struct list_head *pos = h->next; +u32 id = dev->device_id; + +while (pos != h) { +struct its_device *iter = + list_entry(pos, struct its_device, dev_list); +if (id < iter->device_id) +break ; + pos = pos->next; + } +list_add_tail (&dev->dev_list, pos); +} +/* Must be called with its_lock mutex held */ static int vgic_its_alloc_device(struct vgic_its *its, struct its_device **devp,
virt/kvm/arm/vgic/vgic-its.c static int vgic_its_alloc_device(struct vgic_its *its, · line 890
Quoted 9 lines
virt/kvm/arm/vgic/vgic-its.c +2
-1@@ -852,7 +883,8 @@ static int vgic_its_alloc_device(struct vgic_its *its, device->nb_eventid_bits = nb_eventid_bits;INIT_LIST_HEAD (&device->itt_head); -list_add_tail (&device->dev_list, &its->device_list); +device_list_insert_sorted (&its->device_list, device); + *devp = device;return 0 ;
What is the actual gain for sorting the list at runtime, vs sorting it at save time? A save/restore operation is a very rare event compared to the normal use of the ITS, so I'd rather put the overhead on the rarest event if possible.
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny.
PATCH v4 16/22 KVM: expose next_segment()
In reply to Eric AugerExpose next_segment() as we would like to reuse this routine in ARM vgic-its code.
--- include/linux/kvm_host.h | 8 ++++++++ virt/kvm/kvm_main.c | 8 -------- 2 files changed, 8 insertions(+), 8 deletions(-)
include/linux/kvm_host.h +8 -0
@@ -92,6 +92,14 @@ static inline bool is_noslot_pfn(kvm_pfn_t pfn)return pfn ==KVM_PFN_NOSLOT ; } +static inline int next_segment (unsigned long len,int offset) +{ +if (len >PAGE_SIZE - offset) +return PAGE_SIZE - offset; +else +return len; +} +/* * architectures with KVM_HVA_ERR_BAD other than PAGE_OFFSET (e.g. s390) * provide own defines and kvm_is_error_hva
virt/kvm/kvm_main.c +0 -8
@@ -1738,14 +1738,6 @@ void kvm_get_pfn(kvm_pfn_t pfn) }EXPORT_SYMBOL_GPL (kvm_get_pfn); -static int next_segment (unsigned long len,int offset) -{ -if (len >PAGE_SIZE - offset) -return PAGE_SIZE - offset; -else -return len; -} -static int __kvm_read_guest_page (struct kvm_memory_slot *slot,gfn_t gfn,void *data,int offset,int len) {
Signature · 1 line
2.5.5
PATCH v4 17/22 KVM: arm64: ITS: Add infrastructure for table lookup
In reply to Eric AugerAdd a generic lookup_table() helper whose role consists in scanning a contiguous table located in guest RAM and applying a callback on each entry. Entries can be handled as linked lists since the callback may return an offset to the next entry and also tell that an entry is the last one.
Helper functions also are added to compute the device/event ID offset to the next DTE/ITE.
compute_next_devid_offset, compute_next_eventid_offset and lookup_table will become static in subsequent patches
---
v3 -> v4:
- remove static to avoid compilation warning
- correct size computation in looup_table()
- defines now encode the number of bits used for devid and eventid offsets
- use BIT() - 1 to encode the max offets
--- virt/kvm/arm/vgic/vgic-its.c | 107 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+)
virt/kvm/arm/vgic/vgic-its.c +107 -0
@@ -184,6 +184,8 @@ static struct its_ite *find_ite(struct vgic_its *its, u32 device_id,#define VITS_ESZ 8#define VITS_TYPER_IDBITS 16#define VITS_TYPER_DEVBITS 16 +#define VITS_DTE_MAX_DEVID_OFFSET (BIT(14) - 1) +#define VITS_ITE_MAX_EVENTID_OFFSET (BIT(16) - 1)/* * Finds and returns a collection in the ITS collection table.
@@ -1686,6 +1688,111 @@ int vgic_its_attr_regs_access(struct kvm_device *dev,return ret; } +u32 compute_next_devid_offset (struct list_head *h,struct its_device *dev) +{ +struct list_head *e = &dev->dev_list; +struct its_device *next; +u32 next_offset; + +if (e->next == h) +return 0 ; + next = list_entry(e->next, struct its_device, dev_list); + next_offset = next->device_id - dev->device_id; + +return min_t (u32, next_offset,VITS_DTE_MAX_DEVID_OFFSET ); +} + +u32 compute_next_eventid_offset (struct list_head *h,struct its_ite *ite) +{ +struct list_head *e = &ite->ite_list; +struct its_ite *next; +u32 next_offset; + +if (e->next == h) +return 0 ; + next = list_entry(e->next, struct its_ite, ite_list); + next_offset = next->event_id - ite->event_id; + +return min_t (u32, next_offset,VITS_ITE_MAX_EVENTID_OFFSET ); +} + +/** +* entry_fn_t - Callback called on a table entry restore path +* @its: its handle +* @id: id of the entry +* @addr: kernel VA of the entry +* @opaque: pointer to an opaque data +* @next_offset: minimal ID offset to the next entry. 0 if this +* entry is the last one, 1 if the entry is invalid, >= 1 if an +* entry's next_offset field was truly decoded +* +* Return: < 0 on error, 0 otherwise +*/ +typedef int (*entry_fn_t )(struct vgic_its *its,u32 id,void *addr, +void *opaque,u32 *next_offset); + +/** +* lookup_table - scans a contiguous table in guest RAM and applies a function +* to each entry +* +* @its: its handle +* @base: base gpa of the table +* @size: size of the table in bytes +* @esz: entry size in bytes +* @start_id: first entry's ID +* @fn: function to apply on each entry +* +* Return: < 0 on error, 1 if last element identified, 0 otherwise +*/ +int lookup_table (struct vgic_its *its,gpa_t base,int size,int esz, +int start_id,entry_fn_t fn,void *opaque) +{ +gpa_t gpa = base, top = base + size -1 ; +unsigned long len = size; +int ret, seg, offset =offset_in_page (gpa); +gfn_t gfn = gpa >>PAGE_SHIFT ; +u32 id = start_id + (gpa - base)/esz; +struct kvm *kvm = its->dev->kvm; +kvm_pfn_t pfn; + +while ((seg =next_segment (len, offset)) !=0 ) { +u32 next_offset; +bool writeable; +void *addr; + + pfn =gfn_to_pfn_prot (kvm, gfn, true, &writeable); +if (is_error_noslot_pfn (pfn)) +return -EINVAL ; + addr =phys_to_virt ((u64 )pfn <<PAGE_SHIFT ); + addr += offset; + +while (seg >0 ) { +size_t byte_offset; + + ret =fn (its, id, addr, opaque, &next_offset); +if (ret <0 || (!ret && !next_offset)) + goto out; + + byte_offset = next_offset * esz; + + id += next_offset; + gpa += byte_offset; + addr += byte_offset; + seg -= byte_offset; + } +kvm_release_pfn_clean (pfn); + + len = top - gpa +1 ; + offset =offset_in_page (gpa); + gfn = gpa >>PAGE_SHIFT ; + id = start_id + (gpa - base)/esz; + } +return 0 ; +out: +kvm_release_pfn_clean (pfn); +return (ret <0 ? ret :1 ); +} +/** * vgic_its_flush_pending_tables - Flush the pending tables into guest RAM */
Signature · 1 line
2.5.5
Re: [PATCH v4 17/22] KVM: arm64: ITS: Add infrastructure for table lookup
Quoted 109 lines · Eric Auger
Add a generic
lookup_table()helper whose role consists in scanning a contiguous table located in guest RAM and applying a callback on each entry. Entries can be handled as linked lists since the callback may return an offset to the next entry and also tell that an entry is the last one.Helper functions also are added to compute the device/event ID offset to the next DTE/ITE.
compute_next_devid_offset,compute_next_eventid_offsetandlookup_tablewill become static in subsequent patchesSigned-off-by Eric Auger <[email protected]>---
v3 -> v4:
- remove static to avoid compilation warning
- correct size computation inlooup_table()
- defines now encode the number of bits used for devid and eventid offsets
- useBIT()- 1 to encode the max offets--- virt/kvm/arm/vgic/vgic-its.c | 107 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+)virt/kvm/arm/vgic/vgic-its.c +69
-0@@ -184,6 +184,8 @@ static struct its_ite *find_ite(struct vgic_its *its, u32 device_id,#define VITS_ESZ 8#define VITS_TYPER_IDBITS 16#define VITS_TYPER_DEVBITS 16 +#define VITS_DTE_MAX_DEVID_OFFSET (BIT(14) - 1) +#define VITS_ITE_MAX_EVENTID_OFFSET (BIT(16) - 1)/* * Finds and returns a collection in the ITS collection table. @@ -1686,6 +1688,111 @@ int vgic_its_attr_regs_access(struct kvm_device *dev,return ret; } +u32 compute_next_devid_offset (struct list_head *h,struct its_device *dev) +{ +struct list_head *e = &dev->dev_list; +struct its_device *next; +u32 next_offset; + +if (e->next == h) +return 0 ; + next = list_entry(e->next, struct its_device, dev_list); + next_offset = next->device_id - dev->device_id; + +return min_t (u32, next_offset,VITS_DTE_MAX_DEVID_OFFSET ); +} + +u32 compute_next_eventid_offset (struct list_head *h,struct its_ite *ite) +{ +struct list_head *e = &ite->ite_list; +struct its_ite *next; +u32 next_offset; + +if (e->next == h) +return 0 ; + next = list_entry(e->next, struct its_ite, ite_list); + next_offset = next->event_id - ite->event_id; + +return min_t (u32, next_offset,VITS_ITE_MAX_EVENTID_OFFSET ); +} + +/** +* entry_fn_t - Callback called on a table entry restore path +* @its: its handle +* @id: id of the entry +* @addr: kernel VA of the entry +* @opaque: pointer to an opaque data +* @next_offset: minimal ID offset to the next entry. 0 if this +* entry is the last one, 1 if the entry is invalid, >= 1 if an +* entry's next_offset field was truly decoded +* +* Return: < 0 on error, 0 otherwise +*/ +typedef int (*entry_fn_t )(struct vgic_its *its,u32 id,void *addr, +void *opaque,u32 *next_offset); + +/** +* lookup_table - scans a contiguous table in guest RAM and applies a function +* to each entry +* +* @its: its handle +* @base: base gpa of the table +* @size: size of the table in bytes +* @esz: entry size in bytes +* @start_id: first entry's ID +* @fn: function to apply on each entry +* +* Return: < 0 on error, 1 if last element identified, 0 otherwise +*/ +int lookup_table (struct vgic_its *its,gpa_t base,int size,int esz, +int start_id,entry_fn_t fn,void *opaque) +{ +gpa_t gpa = base, top = base + size -1 ; +unsigned long len = size; +int ret, seg, offset =offset_in_page (gpa); +gfn_t gfn = gpa >>PAGE_SHIFT ; +u32 id = start_id + (gpa - base)/esz; +struct kvm *kvm = its->dev->kvm; +kvm_pfn_t pfn; +
virt/kvm/arm/vgic/vgic-its.c int vgic_its_attr_regs_access(struct kvm_device *dev, · line 1767
Quoted 10 lines
virt/kvm/arm/vgic/vgic-its.c +10
-0+while ((seg =next_segment (len, offset)) !=0 ) { +u32 next_offset; +bool writeable; +void *addr; + + pfn =gfn_to_pfn_prot (kvm, gfn, true, &writeable); +if (is_error_noslot_pfn (pfn)) +return -EINVAL ; + addr =phys_to_virt ((u64 )pfn <<PAGE_SHIFT ); + addr += offset;
Why do we use the kernel mapping here? I'd have expected the use of kvm_read_guest and co rather than directly accessing the memory. What locks do we hold to ensure that the page cannot be evicted behind our back?
Quoted 21 lines
virt/kvm/arm/vgic/vgic-its.c +21
-0+ +while (seg >0 ) { +size_t byte_offset; + + ret =fn (its, id, addr, opaque, &next_offset); +if (ret <0 || (!ret && !next_offset)) + goto out; + + byte_offset = next_offset * esz; + + id += next_offset; + gpa += byte_offset; + addr += byte_offset; + seg -= byte_offset; + } +kvm_release_pfn_clean (pfn); + + len = top - gpa +1 ; + offset =offset_in_page (gpa); + gfn = gpa >>PAGE_SHIFT ; + id = start_id + (gpa - base)/esz;
virt/kvm/arm/vgic/vgic-its.c int vgic_its_attr_regs_access(struct kvm_device *dev, · line 1798
Quoted 10 lines
virt/kvm/arm/vgic/vgic-its.c +7
-0+ } +return 0 ; +out: +kvm_release_pfn_clean (pfn); +return (ret <0 ? ret :1 ); +} +/** * vgic_its_flush_pending_tables - Flush the pending tables into guest RAM */
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny.
PATCH v4 18/22 KVM: arm64: ITS: Collection table save/restore
In reply to Eric AugerThe flush path copies the collection entries into guest RAM at the GPA specified in the BASER register. This obviously requires the BASER to be set. The last written element is a dummy collection table entry.
We do not index by collection ID as the collection entry can fit into 8 bytes while containing the collection ID.
On restore path we re-allocate the collection objects.
---
v3 -> v4:
- replaced u64 *ptr by gpa_t gpa
- check the collection does not exist before allocating it
v1 -> v2:
- reword commit message and directly use 8 as entry size
- no kvm parameter anymore
- add helper for flush/restore cte
- table size computed here
- add le64/cpu conversions
--- virt/kvm/arm/vgic/vgic-its.c | 99 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 97 insertions(+), 2 deletions(-)
virt/kvm/arm/vgic/vgic-its.c +97 -2
@@ -1828,13 +1828,89 @@ static int vgic_its_restore_device_tables(struct vgic_its *its)return -ENXIO ; } +static int vgic_its_flush_cte (struct vgic_its *its, +struct its_collection *collection,gpa_t gpa) +{ +u64 val; +int ret; + + val = ((u64 )1 <<63 | ((u64 )collection->target_addr <<16 ) | + collection->collection_id); + val =cpu_to_le64 (val); + ret =kvm_write_guest (its->dev->kvm, gpa, &val,8 ); +return ret; +} + +static int vgic_its_restore_cte (struct vgic_its *its,gpa_t gpa,bool *valid) +{ +struct its_collection *collection; +u32 target_addr; +u32 coll_id; +u64 val; +int ret; + + *valid = false; + + ret =kvm_read_guest (its->dev->kvm, gpa, &val,8 ); +if (ret) +return ret; + val =le64_to_cpu (val); + *valid = val &BIT_ULL (63 ); + +if (!*valid) +return 0 ; + + target_addr = (u32)(val >>16 ); + coll_id = val &0xFFFF ; + + collection =find_collection (its, coll_id); +if (collection) +return -EEXIST ; + ret =vgic_its_alloc_collection (its, &collection, coll_id); +if (ret) +return ret; + collection->target_addr = target_addr; +return 0 ; +} +/** * vgic_its_flush_collection_table - flush the collection table into * guest RAM */ static int vgic_its_flush_collection_table (struct vgic_its *its) { -return -ENXIO ; +struct its_collection *collection; +u64 val; +gpa_t gpa; +size_t max_size, filled =0 ; +int ret; + + gpa =BASER_ADDRESS (its->baser_coll_table); +if (!gpa) +return 0 ; + + max_size =GITS_BASER_NR_PAGES (its->baser_coll_table) *SZ_64K ; + +list_for_each_entry (collection, &its->collection_list, coll_list) { +if (filled == max_size) +return -ENOSPC ; + ret =vgic_its_flush_cte (its, collection, gpa); +if (ret) +return ret; + gpa +=8 ; + filled +=8 ; + } + +if (filled == max_size) +return 0 ; + +/* +* table is not fully filled, add a last dummy element +* with valid bit unset +*/ + val =0 ; + ret =kvm_write_guest (its->dev->kvm, gpa, &val,8 ); +return ret; }/**
@@ -1844,7 +1920,26 @@ static int vgic_its_flush_collection_table(struct vgic_its *its)*/ static int vgic_its_restore_collection_table (struct vgic_its *its) { -return -ENXIO ; +size_t max_size, read =0 ; +gpa_t gpa; +int ret; + + gpa =BASER_ADDRESS (its->baser_coll_table); +if (!gpa) +return 0 ; + + max_size =GITS_BASER_NR_PAGES (its->baser_coll_table) *SZ_64K ; + +while (read < max_size) { +bool valid; + + ret =vgic_its_restore_cte (its, gpa, &valid); +if (!valid || ret) +break ; + gpa +=8 ; + read +=8 ; + } +return ret; }/**
Signature · 1 line
2.5.5
Re: [PATCH v4 18/22] KVM: arm64: ITS: Collection table save/restore
Quoted 33 lines · Eric Auger
The flush path copies the collection entries into guest RAM at the GPA specified in the BASER register. This obviously requires the BASER to be set. The last written element is a dummy collection table entry.
We do not index by collection ID as the collection entry can fit into 8 bytes while containing the collection ID.
On restore path we re-allocate the collection objects.
Signed-off-by Eric Auger <[email protected]>---
v3 -> v4:
- replaced u64 *ptr bygpa_tgpa
- check the collection does not exist before allocating itv1 -> v2:
- reword commit message and directly use 8 as entry size
- no kvm parameter anymore
- add helper for flush/restore cte
- table size computed here
- add le64/cpu conversions--- virt/kvm/arm/vgic/vgic-its.c | 99 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 97 insertions(+), 2 deletions(-)virt/kvm/arm/vgic/vgic-its.c +0
-0
virt/kvm/arm/vgic/vgic-its.c static int vgic_its_restore_device_tables(struct vgic_its *its) · line 1832
Quoted 5 lines
virt/kvm/arm/vgic/vgic-its.c +2
-0@@ -1828,13 +1828,89 @@ static int vgic_its_restore_device_tables(struct vgic_its *its)return -ENXIO ; } +static int vgic_its_flush_cte (struct vgic_its *its, +struct its_collection *collection,gpa_t gpa)
Given that the pendent of this function is name ..._restore_..., should this be called ..._save_... ?
virt/kvm/arm/vgic/vgic-its.c static int vgic_its_restore_device_tables(struct vgic_its *its) · line 1838
Quoted 6 lines
virt/kvm/arm/vgic/vgic-its.c +6
-0+{ +u64 val; +int ret; + + val = ((u64 )1 <<63 | ((u64 )collection->target_addr <<16 ) | + collection->collection_id);
Please provide some #defines that describe the encoding. This will be specially useful if we need to export this to userspace (KVM/TCG interoperability?).
Quoted 15 lines
virt/kvm/arm/vgic/vgic-its.c +15
-0+ val =cpu_to_le64 (val); + ret =kvm_write_guest (its->dev->kvm, gpa, &val,8 ); +return ret; +} + +static int vgic_its_restore_cte (struct vgic_its *its,gpa_t gpa,bool *valid) +{ +struct its_collection *collection; +u32 target_addr; +u32 coll_id; +u64 val; +int ret; + + *valid = false; +
virt/kvm/arm/vgic/vgic-its.c static int vgic_its_restore_device_tables(struct vgic_its *its) · line 1863
Quoted 10 lines
virt/kvm/arm/vgic/vgic-its.c +10
-0+ ret =kvm_read_guest (its->dev->kvm, gpa, &val,8 ); +if (ret) +return ret; + val =le64_to_cpu (val); + *valid = val &BIT_ULL (63 ); + +if (!*valid) +return 0 ; + + target_addr = (u32)(val >>16 );
u32?
virt/kvm/arm/vgic/vgic-its.c static int vgic_its_restore_device_tables(struct vgic_its *its) · line 1864
Quoted 1 line
virt/kvm/arm/vgic/vgic-its.c +1
-0+ coll_id = val &0xFFFF ;
Same comment about the various shifts/masks.
Quoted 28 lines
virt/kvm/arm/vgic/vgic-its.c +21
-1+ + collection =find_collection (its, coll_id); +if (collection) +return -EEXIST ; + ret =vgic_its_alloc_collection (its, &collection, coll_id); +if (ret) +return ret; + collection->target_addr = target_addr; +return 0 ; +} +/** * vgic_its_flush_collection_table - flush the collection table into * guest RAM */ static int vgic_its_flush_collection_table (struct vgic_its *its) { -return -ENXIO ; +struct its_collection *collection; +u64 val; +gpa_t gpa; +size_t max_size, filled =0 ; +int ret; + + gpa =BASER_ADDRESS (its->baser_coll_table); +if (!gpa) +return 0 ; +
virt/kvm/arm/vgic/vgic-its.c static int vgic_its_restore_device_tables(struct vgic_its *its) · line 1901
Quoted 10 lines
virt/kvm/arm/vgic/vgic-its.c +10
-0+ max_size =GITS_BASER_NR_PAGES (its->baser_coll_table) *SZ_64K ; + +list_for_each_entry (collection, &its->collection_list, coll_list) { +if (filled == max_size) +return -ENOSPC ; + ret =vgic_its_flush_cte (its, collection, gpa); +if (ret) +return ret; + gpa +=8 ; + filled +=8 ;
This "8" should be extracted from the BASER register itself (Entry_Size).
Quoted 34 lines
virt/kvm/arm/vgic/vgic-its.c +25
-1+ } + +if (filled == max_size) +return 0 ; + +/* +* table is not fully filled, add a last dummy element +* with valid bit unset +*/ + val =0 ; + ret =kvm_write_guest (its->dev->kvm, gpa, &val,8 ); +return ret; }/** @@ -1844,7 +1920,26 @@ static int vgic_its_flush_collection_table(struct vgic_its *its)*/ static int vgic_its_restore_collection_table (struct vgic_its *its) { -return -ENXIO ; +size_t max_size, read =0 ; +gpa_t gpa; +int ret; + + gpa =BASER_ADDRESS (its->baser_coll_table); +if (!gpa) +return 0 ; + + max_size =GITS_BASER_NR_PAGES (its->baser_coll_table) *SZ_64K ; + +while (read < max_size) { +bool valid; +
virt/kvm/arm/vgic/vgic-its.c static int vgic_its_flush_collection_table(struct vgic_its *its) · line 1945
Quoted 10 lines
virt/kvm/arm/vgic/vgic-its.c +7
-0+ ret =vgic_its_restore_cte (its, gpa, &valid); +if (!valid || ret) +break ; + gpa +=8 ; + read +=8 ; + } +return ret; }/**
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Re: [PATCH v4 18/22] KVM: arm64: ITS: Collection table save/restore
Hi Marc,
Quoted 73 lines · Marc Zyngier
Quoted 33 lines · Eric Auger
The flush path copies the collection entries into guest RAM at the GPA specified in the BASER register. This obviously requires the BASER to be set. The last written element is a dummy collection table entry.
We do not index by collection ID as the collection entry can fit into 8 bytes while containing the collection ID.
On restore path we re-allocate the collection objects.
Signed-off-by Eric Auger <[email protected]>---
v3 -> v4:
- replaced u64 *ptr bygpa_tgpa
- check the collection does not exist before allocating itv1 -> v2:
- reword commit message and directly use 8 as entry size
- no kvm parameter anymore
- add helper for flush/restore cte
- table size computed here
- add le64/cpu conversions--- virt/kvm/arm/vgic/vgic-its.c | 99 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 97 insertions(+), 2 deletions(-)virt/kvm/arm/vgic/vgic-its.c +0
-0virt/kvm/arm/vgic/vgic-its.c static int vgic_its_restore_device_tables(struct vgic_its *its) · line 1832
Quoted 5 lines
virt/kvm/arm/vgic/vgic-its.c +2
-0@@ -1828,13 +1828,89 @@ static int vgic_its_restore_device_tables(struct vgic_its *its)return -ENXIO ; } +static int vgic_its_flush_cte (struct vgic_its *its, +struct its_collection *collection,gpa_t gpa)Given that the pendent of this function is name ..._restore_..., should this be called ..._save_... ?
virt/kvm/arm/vgic/vgic-its.c static int vgic_its_restore_device_tables(struct vgic_its *its) · line 1838
Quoted 6 lines
virt/kvm/arm/vgic/vgic-its.c +6
-0+{ +u64 val; +int ret; + + val = ((u64 )1 <<63 | ((u64 )collection->target_addr <<16 ) | + collection->collection_id);Please provide some #defines that describe the encoding. This will be specially useful if we need to export this to userspace (KVM/TCG interoperability?).
Quoted 19 lines
virt/kvm/arm/vgic/vgic-its.c +19
-0+ val =cpu_to_le64 (val); + ret =kvm_write_guest (its->dev->kvm, gpa, &val,8 ); +return ret; +} + +static int vgic_its_restore_cte (struct vgic_its *its,gpa_t gpa,bool *valid) +{ +struct its_collection *collection; +u32 target_addr; +u32 coll_id; +u64 val; +int ret; + + *valid = false; + + ret =kvm_read_guest (its->dev->kvm, gpa, &val,8 ); +if (ret) +return ret; + val =le64_to_cpu (val);
Quoted 8 lines
virt/kvm/arm/vgic/vgic-its.c static int vgic_its_restore_device_tables(struct vgic_its *its) · line 1863
Quoted 6 lines
virt/kvm/arm/vgic/vgic-its.c +6
-0+ *valid = val &BIT_ULL (63 ); + +if (!*valid) +return 0 ; + + target_addr = (u32)(val >>16 );u32?
At the moment its_collection.target_addr is u32 and corresponds to the PE number. Only GITS_TYPER.PTA = 0 is supported.
Or do I miss something?
Thanks
Eric
Quoted 95 lines
virt/kvm/arm/vgic/vgic-its.c static int vgic_its_restore_device_tables(struct vgic_its *its) · line 1864
Quoted 2 lines
virt/kvm/arm/vgic/vgic-its.c +1
-0+ coll_id = val &0xFFFF ;Same comment about the various shifts/masks.
Quoted 28 lines
virt/kvm/arm/vgic/vgic-its.c +21
-1+ + collection =find_collection (its, coll_id); +if (collection) +return -EEXIST ; + ret =vgic_its_alloc_collection (its, &collection, coll_id); +if (ret) +return ret; + collection->target_addr = target_addr; +return 0 ; +} +/** * vgic_its_flush_collection_table - flush the collection table into * guest RAM */ static int vgic_its_flush_collection_table (struct vgic_its *its) { -return -ENXIO ; +struct its_collection *collection; +u64 val; +gpa_t gpa; +size_t max_size, filled =0 ; +int ret; + + gpa =BASER_ADDRESS (its->baser_coll_table); +if (!gpa) +return 0 ; +virt/kvm/arm/vgic/vgic-its.c static int vgic_its_restore_device_tables(struct vgic_its *its) · line 1901
Quoted 10 lines
virt/kvm/arm/vgic/vgic-its.c +10
-0+ max_size =GITS_BASER_NR_PAGES (its->baser_coll_table) *SZ_64K ; + +list_for_each_entry (collection, &its->collection_list, coll_list) { +if (filled == max_size) +return -ENOSPC ; + ret =vgic_its_flush_cte (its, collection, gpa); +if (ret) +return ret; + gpa +=8 ; + filled +=8 ;This "8" should be extracted from the BASER register itself (
Entry_Size).Quoted 34 lines
virt/kvm/arm/vgic/vgic-its.c +25
-1+ } + +if (filled == max_size) +return 0 ; + +/* +* table is not fully filled, add a last dummy element +* with valid bit unset +*/ + val =0 ; + ret =kvm_write_guest (its->dev->kvm, gpa, &val,8 ); +return ret; }/** @@ -1844,7 +1920,26 @@ static int vgic_its_flush_collection_table(struct vgic_its *its)*/ static int vgic_its_restore_collection_table (struct vgic_its *its) { -return -ENXIO ; +size_t max_size, read =0 ; +gpa_t gpa; +int ret; + + gpa =BASER_ADDRESS (its->baser_coll_table); +if (!gpa) +return 0 ; + + max_size =GITS_BASER_NR_PAGES (its->baser_coll_table) *SZ_64K ; + +while (read < max_size) { +bool valid; +virt/kvm/arm/vgic/vgic-its.c static int vgic_its_flush_collection_table(struct vgic_its *its) · line 1945
Quoted 10 lines
virt/kvm/arm/vgic/vgic-its.c +7
-0+ ret =vgic_its_restore_cte (its, gpa, &valid); +if (!valid || ret) +break ; + gpa +=8 ; + read +=8 ; + } +return ret; }/** Thanks,
M.
Re: [PATCH v4 18/22] KVM: arm64: ITS: Collection table save/restore
Quoted 84 lines · Auger Eric
Hi Marc,
Quoted 73 lines · Marc Zyngier
Quoted 33 lines · Eric Auger
The flush path copies the collection entries into guest RAM at the GPA specified in the BASER register. This obviously requires the BASER to be set. The last written element is a dummy collection table entry.
We do not index by collection ID as the collection entry can fit into 8 bytes while containing the collection ID.
On restore path we re-allocate the collection objects.
Signed-off-by Eric Auger <[email protected]>---
v3 -> v4:
- replaced u64 *ptr bygpa_tgpa
- check the collection does not exist before allocating itv1 -> v2:
- reword commit message and directly use 8 as entry size
- no kvm parameter anymore
- add helper for flush/restore cte
- table size computed here
- add le64/cpu conversions--- virt/kvm/arm/vgic/vgic-its.c | 99 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 97 insertions(+), 2 deletions(-)virt/kvm/arm/vgic/vgic-its.c +0
-0virt/kvm/arm/vgic/vgic-its.c static int vgic_its_restore_device_tables(struct vgic_its *its) · line 1832
Quoted 5 lines
virt/kvm/arm/vgic/vgic-its.c +2
-0@@ -1828,13 +1828,89 @@ static int vgic_its_restore_device_tables(struct vgic_its *its)return -ENXIO ; } +static int vgic_its_flush_cte (struct vgic_its *its, +struct its_collection *collection,gpa_t gpa)Given that the pendent of this function is name ..._restore_..., should this be called ..._save_... ?
virt/kvm/arm/vgic/vgic-its.c static int vgic_its_restore_device_tables(struct vgic_its *its) · line 1838
Quoted 6 lines
virt/kvm/arm/vgic/vgic-its.c +6
-0+{ +u64 val; +int ret; + + val = ((u64 )1 <<63 | ((u64 )collection->target_addr <<16 ) | + collection->collection_id);Please provide some #defines that describe the encoding. This will be specially useful if we need to export this to userspace (KVM/TCG interoperability?).
Quoted 19 lines
virt/kvm/arm/vgic/vgic-its.c +19
-0+ val =cpu_to_le64 (val); + ret =kvm_write_guest (its->dev->kvm, gpa, &val,8 ); +return ret; +} + +static int vgic_its_restore_cte (struct vgic_its *its,gpa_t gpa,bool *valid) +{ +struct its_collection *collection; +u32 target_addr; +u32 coll_id; +u64 val; +int ret; + + *valid = false; + + ret =kvm_read_guest (its->dev->kvm, gpa, &val,8 ); +if (ret) +return ret; + val =le64_to_cpu (val);Quoted 8 lines
virt/kvm/arm/vgic/vgic-its.c static int vgic_its_restore_device_tables(struct vgic_its *its) · line 1863
Quoted 6 lines
virt/kvm/arm/vgic/vgic-its.c +6
-0+ *valid = val &BIT_ULL (63 ); + +if (!*valid) +return 0 ; + + target_addr = (u32)(val >>16 );u32?
Quoted 4 lines
At the moment its_collection.target_addr is u32 and corresponds to the PE number. Only GITS_TYPER.PTA = 0 is supported.
Or do I miss something?
No, you're right. I'm getting confused between the model I'm working with and the ITS emulation... Ignore me.
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
PATCH v4 19/22 KVM: arm64: ITS: vgic_its_check_id returns the entry's GPA
In reply to Eric AugerAs vgic_its_check_id() computes the device/collection entry's GPA, let's return it so that new callers can retrieve it easily.
---
v3 -> v4:
- check eaddr is not NULL to allow passing NULL eaddr parameter to vgic_its_check_id
v2: new
--- virt/kvm/arm/vgic/vgic-its.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
virt/kvm/arm/vgic/vgic-its.c +8 -3
@@ -629,7 +629,8 @@ static int vgic_its_cmd_handle_movi(struct kvm *kvm, struct vgic_its *its,* is actually valid (covered by a memslot and guest accessible). * For this we have to read the respective first level entry. */ -static bool vgic_its_check_id (struct vgic_its *its,u64 baser,u32 id) +static bool vgic_its_check_id (struct vgic_its *its,u64 baser,u32 id, +gpa_t *eaddr) {int l1_tbl_size =GITS_BASER_NR_PAGES (baser) *SZ_64K ;int index;
@@ -649,6 +650,8 @@ static bool vgic_its_check_id(struct vgic_its *its, u64 baser, u32 id) addr =BASER_ADDRESS (baser) + id * esz; gfn = addr >>PAGE_SHIFT ; +if (eaddr) + *eaddr = addr;return kvm_is_visible_gfn (its->dev->kvm, gfn); }
@@ -681,6 +684,8 @@ static bool vgic_its_check_id(struct vgic_its *its, u64 baser, u32 id) indirect_ptr += index * esz; gfn = indirect_ptr >>PAGE_SHIFT ; +if (eaddr) + *eaddr = indirect_ptr;return kvm_is_visible_gfn (its->dev->kvm, gfn); }
@@ -690,7 +695,7 @@ static int vgic_its_alloc_collection(struct vgic_its *its, {struct its_collection *collection; -if (!vgic_its_check_id (its, its->baser_coll_table, coll_id)) +if (!vgic_its_check_id (its, its->baser_coll_table, coll_id,NULL ))return E_ITS_MAPC_COLLECTION_OOR ; collection =kzalloc (sizeof (*collection),GFP_KERNEL );
@@ -905,7 +910,7 @@ static int vgic_its_cmd_handle_mapd(struct kvm *kvm, struct vgic_its *its,gpa_t itt_addr =its_cmd_get_ittaddr (its_cmd) <<8 ;struct its_device *device; -if (!vgic_its_check_id (its, its->baser_device_table, device_id)) +if (!vgic_its_check_id (its, its->baser_device_table, device_id,NULL ))return E_ITS_MAPD_DEVICE_OOR ;if (valid && nb_eventid_bits >VITS_TYPER_IDBITS )
Signature · 1 line
2.5.5
PATCH v4 20/22 KVM: arm64: ITS: ITT flush and restore
In reply to Eric AugerIntroduce routines to flush and restore device ITT and their interrupt table entries (ITE).
The routines will be called on device table flush and restore. They will become static in subsequent patches.
---
v3 -> v4:
- lookup_table and compute_next_eventid_offset become static in this patch
- remove static along with vgic_its_flush/restore_itt to avoid compilation warnings
- next field only computed with a shift (mask removed)
- handle the case where the last element has not been found
v2 -> v3:
- add return 0 in vgic_its_restore_ite (was in subsequent patch)
v2: creation
--- virt/kvm/arm/vgic/vgic-its.c | 107 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 104 insertions(+), 3 deletions(-)
virt/kvm/arm/vgic/vgic-its.c +104 -3
@@ -1707,7 +1707,7 @@ u32 compute_next_devid_offset(struct list_head *h, struct its_device *dev)return min_t (u32, next_offset,VITS_DTE_MAX_DEVID_OFFSET ); } -u32 compute_next_eventid_offset (struct list_head *h,struct its_ite *ite) +static u32 compute_next_eventid_offset (struct list_head *h,struct its_ite *ite) {struct list_head *e = &ite->ite_list;struct its_ite *next;
@@ -1749,8 +1749,8 @@ typedef int (*entry_fn_t)(struct vgic_its *its, u32 id, void *addr,* * Return: < 0 on error, 1 if last element identified, 0 otherwise */ -int lookup_table (struct vgic_its *its,gpa_t base,int size,int esz, -int start_id,entry_fn_t fn,void *opaque) +static int lookup_table (struct vgic_its *its,gpa_t base,int size,int esz, +int start_id,entry_fn_t fn,void *opaque) {gpa_t gpa = base, top = base + size -1 ;unsigned long len = size;
@@ -1815,6 +1815,107 @@ static int vgic_its_restore_pending_tables(struct kvm *kvm)return -ENXIO ; } +static int vgic_its_flush_ite (struct vgic_its *its,struct its_device *dev, +struct its_ite *ite,gpa_t gpa) +{ +struct kvm *kvm = its->dev->kvm; +u32 next_offset; +u64 val; + + next_offset =compute_next_eventid_offset (&dev->itt_head, ite); + val = ((u64 )next_offset <<48 ) | ((u64 )ite->lpi <<16 ) | + ite->collection->collection_id; + val =cpu_to_le64 (val); +return kvm_write_guest (kvm, gpa, &val,VITS_ESZ ); +} + +/** +* vgic_its_restore_ite - restore an interrupt translation entry +* @event_id: id used for indexing +* @ptr: kernel VA where the 8 byte ITE is located +* @opaque: pointer to the its_device +* @next: id offset to the next entry +*/ +static int vgic_its_restore_ite (struct vgic_its *its,u32 event_id, +void *ptr,void *opaque,u32 *next) +{ +struct its_device *dev = (struct its_device *)opaque; +struct its_collection *collection; +struct kvm *kvm = its->dev->kvm; +u64 val, *p = (u64 *)ptr; +struct vgic_irq *irq; +u32 coll_id, lpi_id; +struct its_ite *ite; +int ret; + + val = *p; + *next =1 ; + + val =le64_to_cpu (val); + + coll_id = val &GENMASK_ULL (15 ,0 ); + lpi_id = (val &GENMASK_ULL (47 ,16 )) >>16 ; + +if (!lpi_id) +return 0 ; + + *next = val >>48 ; + + collection =find_collection (its, coll_id); +if (!collection) +return -EINVAL ; + + ret =vgic_its_alloc_ite (dev, &ite, collection, + lpi_id, event_id); +if (ret) +return ret; + + irq =vgic_add_lpi (kvm, lpi_id); +if (IS_ERR (irq)) +return PTR_ERR (irq); + ite->irq = irq; + +/* restore the configuration of the LPI */ + ret =update_lpi_config (kvm, irq,NULL ); +if (ret) +return ret; + +update_affinity_ite (kvm, ite); +return 0 ; +} + +int vgic_its_flush_itt (struct vgic_its *its,struct its_device *device) +{ +gpa_t base = device->itt_addr; +struct its_ite *ite; +int ret; + +list_for_each_entry (ite, &device->itt_head, ite_list) { +gpa_t gpa = base + ite->event_id *VITS_ESZ ; + + ret =vgic_its_flush_ite (its, device, ite, gpa); +if (ret) +return ret; + } +return 0 ; +} + +int vgic_its_restore_itt (struct vgic_its *its,struct its_device *dev) +{ +size_t max_size =BIT_ULL (dev->nb_eventid_bits) *VITS_ESZ ; +gpa_t base = dev->itt_addr; +int ret; + + ret =lookup_table (its, base, max_size,VITS_ESZ ,0 , + vgic_its_restore_ite, dev); + +if (ret <0 ) +return ret; + +/* if the last element has not been found we are in trouble */ +return ret ?0 : -EINVAL ; +} +/** * vgic_its_flush_device_tables - flush the device table and all ITT * into guest RAM
Signature · 1 line
2.5.5
Re: [PATCH v4 20/22] KVM: arm64: ITS: ITT flush and restore
Quoted 54 lines · Eric Auger
Introduce routines to flush and restore device ITT and their interrupt table entries (ITE).
The routines will be called on device table flush and restore. They will become static in subsequent patches.
Signed-off-by Eric Auger <[email protected]>---
v3 -> v4:
-lookup_tableandcompute_next_eventid_offsetbecome static in this patch
- remove static along with vgic_its_flush/restore_itt to avoid compilation warnings
- next field only computed with a shift (mask removed)
- handle the case where the last element has not been foundv2 -> v3:
- add return 0 invgic_its_restore_ite(was in subsequent patch)v2: creation
--- virt/kvm/arm/vgic/vgic-its.c | 107 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 104 insertions(+), 3 deletions(-)virt/kvm/arm/vgic/vgic-its.c +3
-3@@ -1707,7 +1707,7 @@ u32 compute_next_devid_offset(struct list_head *h, struct its_device *dev)return min_t (u32, next_offset,VITS_DTE_MAX_DEVID_OFFSET ); } -u32 compute_next_eventid_offset (struct list_head *h,struct its_ite *ite) +static u32 compute_next_eventid_offset (struct list_head *h,struct its_ite *ite) {struct list_head *e = &ite->ite_list;struct its_ite *next;@@ -1749,8 +1749,8 @@ typedef int (*entry_fn_t)(struct vgic_its *its, u32 id, void *addr,* * Return: < 0 on error, 1 if last element identified, 0 otherwise */ -int lookup_table (struct vgic_its *its,gpa_t base,int size,int esz, -int start_id,entry_fn_t fn,void *opaque) +static int lookup_table (struct vgic_its *its,gpa_t base,int size,int esz, +int start_id,entry_fn_t fn,void *opaque) {gpa_t gpa = base, top = base + size -1 ;unsigned long len = size;@@ -1815,6 +1815,107 @@ static int vgic_its_restore_pending_tables(struct kvm *kvm)return -ENXIO ; }
virt/kvm/arm/vgic/vgic-its.c static int vgic_its_restore_pending_tables(struct kvm *kvm) · line 1827
Quoted 10 lines
virt/kvm/arm/vgic/vgic-its.c +10
-0+static int vgic_its_flush_ite (struct vgic_its *its,struct its_device *dev, +struct its_ite *ite,gpa_t gpa) +{ +struct kvm *kvm = its->dev->kvm; +u32 next_offset; +u64 val; + + next_offset =compute_next_eventid_offset (&dev->itt_head, ite); + val = ((u64 )next_offset <<48 ) | ((u64 )ite->lpi <<16 ) | + ite->collection->collection_id;
Same remark as before concerning the #define-ing of the encoding and the name of the function.
Quoted 79 lines
virt/kvm/arm/vgic/vgic-its.c +79
-0+ val =cpu_to_le64 (val); +return kvm_write_guest (kvm, gpa, &val,VITS_ESZ ); +} + +/** +* vgic_its_restore_ite - restore an interrupt translation entry +* @event_id: id used for indexing +* @ptr: kernel VA where the 8 byte ITE is located +* @opaque: pointer to the its_device +* @next: id offset to the next entry +*/ +static int vgic_its_restore_ite (struct vgic_its *its,u32 event_id, +void *ptr,void *opaque,u32 *next) +{ +struct its_device *dev = (struct its_device *)opaque; +struct its_collection *collection; +struct kvm *kvm = its->dev->kvm; +u64 val, *p = (u64 *)ptr; +struct vgic_irq *irq; +u32 coll_id, lpi_id; +struct its_ite *ite; +int ret; + + val = *p; + *next =1 ; + + val =le64_to_cpu (val); + + coll_id = val &GENMASK_ULL (15 ,0 ); + lpi_id = (val &GENMASK_ULL (47 ,16 )) >>16 ; + +if (!lpi_id) +return 0 ; + + *next = val >>48 ; + + collection =find_collection (its, coll_id); +if (!collection) +return -EINVAL ; + + ret =vgic_its_alloc_ite (dev, &ite, collection, + lpi_id, event_id); +if (ret) +return ret; + + irq =vgic_add_lpi (kvm, lpi_id); +if (IS_ERR (irq)) +return PTR_ERR (irq); + ite->irq = irq; + +/* restore the configuration of the LPI */ + ret =update_lpi_config (kvm, irq,NULL ); +if (ret) +return ret; + +update_affinity_ite (kvm, ite); +return 0 ; +} + +int vgic_its_flush_itt (struct vgic_its *its,struct its_device *device) +{ +gpa_t base = device->itt_addr; +struct its_ite *ite; +int ret; + +list_for_each_entry (ite, &device->itt_head, ite_list) { +gpa_t gpa = base + ite->event_id *VITS_ESZ ; + + ret =vgic_its_flush_ite (its, device, ite, gpa); +if (ret) +return ret; + } +return 0 ; +} + +int vgic_its_restore_itt (struct vgic_its *its,struct its_device *dev) +{ +size_t max_size =BIT_ULL (dev->nb_eventid_bits) *VITS_ESZ ; +gpa_t base = dev->itt_addr;
virt/kvm/arm/vgic/vgic-its.c static int vgic_its_restore_pending_tables(struct kvm *kvm) · line 1916
Quoted 10 lines
virt/kvm/arm/vgic/vgic-its.c +10
-0+int ret; + + ret =lookup_table (its, base, max_size,VITS_ESZ ,0 , + vgic_its_restore_ite, dev); + +if (ret <0 ) +return ret; + +/* if the last element has not been found we are in trouble */ +return ret ?0 : -EINVAL ;
This makes me wonder. Can't lookup_table perform that check on its own and always return an error when something went wrong?
virt/kvm/arm/vgic/vgic-its.c static int vgic_its_restore_pending_tables(struct kvm *kvm) · line 1921
Quoted 6 lines
virt/kvm/arm/vgic/vgic-its.c +2
-0+} +/** * vgic_its_flush_device_tables - flush the device table and all ITT * into guest RAM
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Re: [PATCH v4 20/22] KVM: arm64: ITS: ITT flush and restore
Hi Marc,
Quoted 153 lines · Marc Zyngier
Quoted 54 lines · Eric Auger
Introduce routines to flush and restore device ITT and their interrupt table entries (ITE).
The routines will be called on device table flush and restore. They will become static in subsequent patches.
Signed-off-by Eric Auger <[email protected]>---
v3 -> v4:
-lookup_tableandcompute_next_eventid_offsetbecome static in this patch
- remove static along with vgic_its_flush/restore_itt to avoid compilation warnings
- next field only computed with a shift (mask removed)
- handle the case where the last element has not been foundv2 -> v3:
- add return 0 invgic_its_restore_ite(was in subsequent patch)v2: creation
--- virt/kvm/arm/vgic/vgic-its.c | 107 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 104 insertions(+), 3 deletions(-)virt/kvm/arm/vgic/vgic-its.c +3
-3@@ -1707,7 +1707,7 @@ u32 compute_next_devid_offset(struct list_head *h, struct its_device *dev)return min_t (u32, next_offset,VITS_DTE_MAX_DEVID_OFFSET ); } -u32 compute_next_eventid_offset (struct list_head *h,struct its_ite *ite) +static u32 compute_next_eventid_offset (struct list_head *h,struct its_ite *ite) {struct list_head *e = &ite->ite_list;struct its_ite *next;@@ -1749,8 +1749,8 @@ typedef int (*entry_fn_t)(struct vgic_its *its, u32 id, void *addr,* * Return: < 0 on error, 1 if last element identified, 0 otherwise */ -int lookup_table (struct vgic_its *its,gpa_t base,int size,int esz, -int start_id,entry_fn_t fn,void *opaque) +static int lookup_table (struct vgic_its *its,gpa_t base,int size,int esz, +int start_id,entry_fn_t fn,void *opaque) {gpa_t gpa = base, top = base + size -1 ;unsigned long len = size;@@ -1815,6 +1815,107 @@ static int vgic_its_restore_pending_tables(struct kvm *kvm)return -ENXIO ; }virt/kvm/arm/vgic/vgic-its.c static int vgic_its_restore_pending_tables(struct kvm *kvm) · line 1827
Quoted 10 lines
virt/kvm/arm/vgic/vgic-its.c +10
-0+static int vgic_its_flush_ite (struct vgic_its *its,struct its_device *dev, +struct its_ite *ite,gpa_t gpa) +{ +struct kvm *kvm = its->dev->kvm; +u32 next_offset; +u64 val; + + next_offset =compute_next_eventid_offset (&dev->itt_head, ite); + val = ((u64 )next_offset <<48 ) | ((u64 )ite->lpi <<16 ) | + ite->collection->collection_id;Same remark as before concerning the #define-ing of the encoding and the name of the function.
Quoted 84 lines
virt/kvm/arm/vgic/vgic-its.c +84
-0+ val =cpu_to_le64 (val); +return kvm_write_guest (kvm, gpa, &val,VITS_ESZ ); +} + +/** +* vgic_its_restore_ite - restore an interrupt translation entry +* @event_id: id used for indexing +* @ptr: kernel VA where the 8 byte ITE is located +* @opaque: pointer to the its_device +* @next: id offset to the next entry +*/ +static int vgic_its_restore_ite (struct vgic_its *its,u32 event_id, +void *ptr,void *opaque,u32 *next) +{ +struct its_device *dev = (struct its_device *)opaque; +struct its_collection *collection; +struct kvm *kvm = its->dev->kvm; +u64 val, *p = (u64 *)ptr; +struct vgic_irq *irq; +u32 coll_id, lpi_id; +struct its_ite *ite; +int ret; + + val = *p; + *next =1 ; + + val =le64_to_cpu (val); + + coll_id = val &GENMASK_ULL (15 ,0 ); + lpi_id = (val &GENMASK_ULL (47 ,16 )) >>16 ; + +if (!lpi_id) +return 0 ; + + *next = val >>48 ; + + collection =find_collection (its, coll_id); +if (!collection) +return -EINVAL ; + + ret =vgic_its_alloc_ite (dev, &ite, collection, + lpi_id, event_id); +if (ret) +return ret; + + irq =vgic_add_lpi (kvm, lpi_id); +if (IS_ERR (irq)) +return PTR_ERR (irq); + ite->irq = irq; + +/* restore the configuration of the LPI */ + ret =update_lpi_config (kvm, irq,NULL ); +if (ret) +return ret; + +update_affinity_ite (kvm, ite); +return 0 ; +} + +int vgic_its_flush_itt (struct vgic_its *its,struct its_device *device) +{ +gpa_t base = device->itt_addr; +struct its_ite *ite; +int ret; + +list_for_each_entry (ite, &device->itt_head, ite_list) { +gpa_t gpa = base + ite->event_id *VITS_ESZ ; + + ret =vgic_its_flush_ite (its, device, ite, gpa); +if (ret) +return ret; + } +return 0 ; +} + +int vgic_its_restore_itt (struct vgic_its *its,struct its_device *dev) +{ +size_t max_size =BIT_ULL (dev->nb_eventid_bits) *VITS_ESZ ; +gpa_t base = dev->itt_addr; +int ret; + + ret =lookup_table (its, base, max_size,VITS_ESZ ,0 , + vgic_its_restore_ite, dev); +
Quoted 8 lines
virt/kvm/arm/vgic/vgic-its.c static int vgic_its_restore_pending_tables(struct kvm *kvm) · line 1916
Quoted 5 lines
virt/kvm/arm/vgic/vgic-its.c +5
-0+if (ret <0 ) +return ret; + +/* if the last element has not been found we are in trouble */ +return ret ?0 : -EINVAL ;This makes me wonder. Can't
lookup_tableperform that check on its own and always return an error when something went wrong?
No I don't think this is possible due to the fact we have 2 levels of tables for the device tables. If a second level table lookup does not find the last entry, this is not an issue.
Thanks
Eric
Quoted 12 lines
virt/kvm/arm/vgic/vgic-its.c static int vgic_its_restore_pending_tables(struct kvm *kvm) · line 1921
Quoted 7 lines
virt/kvm/arm/vgic/vgic-its.c +2
-0+} +/** * vgic_its_flush_device_tables - flush the device table and all ITT * into guest RAM Thanks,
M.
PATCH v4 21/22 KVM: arm64: ITS: Device table save/restore
In reply to Eric AugerThis patch flushes the device table entries into guest RAM. Both flat table and 2 stage tables are supported. DeviceId indexing is used.
For each device listed in the device table, we also flush the translation table using the vgic_its_flush/restore_itt routines.
On restore, devices are re-allocated and their itte are re-built.
---
v3 -> v4:
- use the new proto for its_alloc_device
- compute_next_devid_offset, vgic_its_flush/restore_itt become static in this patch
- change in the DTE entry format with the introduction of the valid bit and next field width decrease; ittaddr encoded on its full range
- fix handle_l1_entry entry handling
- correct vgic_its_table_restore error handling
v2 -> v3:
- fix itt_addr bitmask in vgic_its_restore_dte
- addition of return 0 in vgic_its_restore_ite moved to the ITE related patch
v1 -> v2:
- use 8 byte format for DTE and ITE
- support 2 stage format
- remove kvm parameter
- ITT flush/restore moved in a separate patch
- use deviceid indexing
--- virt/kvm/arm/vgic/vgic-its.c | 161 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 156 insertions(+), 5 deletions(-)
virt/kvm/arm/vgic/vgic-its.c +156 -5
@@ -1693,7 +1693,8 @@ int vgic_its_attr_regs_access(struct kvm_device *dev,return ret; } -u32 compute_next_devid_offset (struct list_head *h,struct its_device *dev) +static u32 compute_next_devid_offset (struct list_head *h, +struct its_device *dev) {struct list_head *e = &dev->dev_list;struct its_device *next;
@@ -1884,7 +1885,7 @@ static int vgic_its_restore_ite(struct vgic_its *its, u32 event_id,return 0 ; } -int vgic_its_flush_itt (struct vgic_its *its,struct its_device *device) +static int vgic_its_flush_itt (struct vgic_its *its,struct its_device *device) {gpa_t base = device->itt_addr;struct its_ite *ite;
@@ -1900,7 +1901,7 @@ int vgic_its_flush_itt(struct vgic_its *its, struct its_device *device)return 0 ; } -int vgic_its_restore_itt (struct vgic_its *its,struct its_device *dev) +static int vgic_its_restore_itt (struct vgic_its *its,struct its_device *dev) {size_t max_size =BIT_ULL (dev->nb_eventid_bits) *VITS_ESZ ;gpa_t base = dev->itt_addr;
@@ -1917,12 +1918,141 @@ int vgic_its_restore_itt(struct vgic_its *its, struct its_device *dev) }/** +* vgic_its_flush_dte - Flush a device table entry at a given GPA +* +* @its: ITS handle +* @dev: ITS device +* @ptr: GPA +*/ +static int vgic_its_flush_dte (struct vgic_its *its, +struct its_device *dev,gpa_t ptr) +{ +struct kvm *kvm = its->dev->kvm; +u64 val, itt_addr_field; +int ret; +u32 next_offset; + + itt_addr_field = dev->itt_addr >>8 ; + next_offset =compute_next_devid_offset (&its->device_list, dev); + val = (1ULL <<63 | ((u64 )next_offset <<49 ) | (itt_addr_field <<5 ) | + (dev->nb_eventid_bits -1 )); + val =cpu_to_le64 (val); + ret =kvm_write_guest (kvm, ptr, &val,8 ); +return ret; +} + +/** +* vgic_its_restore_dte - restore a device table entry +* +* @its: its handle +* @id: device id the DTE corresponds to +* @ptr: kernel VA where the 8 byte DTE is located +* @opaque: unused +* @next: offset to the next valid device id +* +* Return: < 0 on error, 0 otherwise +*/ +static int vgic_its_restore_dte (struct vgic_its *its,u32 id, +void *ptr,void *opaque,u32 *next) +{ +struct its_device *dev; +gpa_t itt_addr; +u8 nb_eventid_bits; +u64 entry = *(u64 *)ptr; +bool valid; +int ret; + + entry =le64_to_cpu (entry); + + valid = entry >>63 ; + nb_eventid_bits = (entry &GENMASK_ULL (4 ,0 )) +1 ; + itt_addr = ((entry &GENMASK_ULL (48 ,5 )) >>5 ) <<8 ; + *next =1 ; + +if (!valid) +return 0 ; + +/* dte entry is valid */ + *next = (entry &GENMASK_ULL (62 ,49 )) >>49 ; + + ret =vgic_its_alloc_device (its, &dev, id, + itt_addr, nb_eventid_bits); +if (ret) +return ret; + ret =vgic_its_restore_itt (its, dev); + +return ret; +} + +/** * vgic_its_flush_device_tables - flush the device table and all ITT * into guest RAM +* +* L1/L2 handling is hidden by vgic_its_check_id() helper which directly +* returns the GPA of the device entry */ static int vgic_its_flush_device_tables (struct vgic_its *its) { -return -ENXIO ; +struct its_device *dev; +u64 baser; + + baser = its->baser_device_table; + +list_for_each_entry (dev, &its->device_list, dev_list) { +int ret; +gpa_t eaddr; + +if (!vgic_its_check_id (its, baser, + dev->device_id, &eaddr)) +return -EINVAL ; + + ret =vgic_its_flush_itt (its, dev); +if (ret) +return ret; + + ret =vgic_its_flush_dte (its, dev, eaddr); +if (ret) +return ret; + } +return 0 ; +} + +/** +* handle_l1_entry - callback used for L1 entries (2 stage case) +* +* @its: its handle +* @id: id +* @addr: kernel VA +* @opaque: unused +* @next_offset: offset to the next L1 entry: 0 if the last element +* was found, 1 otherwise +*/ +static int handle_l1_entry (struct vgic_its *its,u32 id,void *addr, +void *opaque,u32 *next_offset) +{ +int l2_start_id = id * (SZ_64K /GITS_LVL1_ENTRY_SIZE ); +u64 entry = *(u64 *)addr; +gpa_t gpa; +int ret; + + entry =le64_to_cpu (entry); + *next_offset =1 ; + +if (!(entry &BIT_ULL (63 ))) +return 0 ; + + gpa = entry &GENMASK_ULL (51 ,16 ); + + ret =lookup_table (its, gpa,SZ_64K ,8 , + l2_start_id, vgic_its_restore_dte,NULL ); + +if (ret ==1 ) { +/* last entry was found in this L2 table */ + *next_offset =0 ; + ret =0 ; + } + +return ret; }/**
@@ -1931,7 +2061,28 @@ static int vgic_its_flush_device_tables(struct vgic_its *its)*/ static int vgic_its_restore_device_tables (struct vgic_its *its) { -return -ENXIO ; +u64 baser = its->baser_device_table; +int l1_tbl_size =GITS_BASER_NR_PAGES (baser) *SZ_64K ; +int l1_esz =GITS_BASER_ENTRY_SIZE (baser); +gpa_t l1_gpa; +int ret; + + l1_gpa =BASER_ADDRESS (baser); +if (!l1_gpa) +return 0 ; + +if (baser &GITS_BASER_INDIRECT ) + ret =lookup_table (its, l1_gpa, l1_tbl_size,8 ,0 , + handle_l1_entry,NULL ); +else + ret =lookup_table (its, l1_gpa, l1_tbl_size, l1_esz, +0 , vgic_its_restore_dte,NULL ); + +if (ret <0 ) +return ret; + +/* if last element was not found we have an issue here */ +return ret ?0 : -EINVAL ; } static int vgic_its_flush_cte(struct vgic_its *its,
Signature · 1 line
2.5.5
Re: [PATCH v4 21/22] KVM: arm64: ITS: Device table save/restore
Quoted 199 lines · Eric Auger
This patch flushes the device table entries into guest RAM. Both flat table and 2 stage tables are supported. DeviceId indexing is used.
For each device listed in the device table, we also flush the translation table using the vgic_its_flush/restore_itt routines.
On restore, devices are re-allocated and their itte are re-built.
Signed-off-by Eric Auger <[email protected]>---
v3 -> v4:
- use the new proto forits_alloc_device
-compute_next_devid_offset, vgic_its_flush/restore_itt become static in this patch
- change in the DTE entry format with the introduction of the valid bit and next field width decrease; ittaddr encoded on its full range
- fixhandle_l1_entryentry handling
- correctvgic_its_table_restoreerror handlingv2 -> v3:
- fixitt_addrbitmask invgic_its_restore_dte
- addition of return 0 invgic_its_restore_itemoved to the ITE related patchv1 -> v2:
- use 8 byte format for DTE and ITE
- support 2 stage format
- remove kvm parameter
- ITT flush/restore moved in a separate patch
- use deviceid indexing--- virt/kvm/arm/vgic/vgic-its.c | 161 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 156 insertions(+), 5 deletions(-)virt/kvm/arm/vgic/vgic-its.c +122
-4@@ -1693,7 +1693,8 @@ int vgic_its_attr_regs_access(struct kvm_device *dev,return ret; } -u32 compute_next_devid_offset (struct list_head *h,struct its_device *dev) +static u32 compute_next_devid_offset (struct list_head *h, +struct its_device *dev) {struct list_head *e = &dev->dev_list;struct its_device *next;@@ -1884,7 +1885,7 @@ static int vgic_its_restore_ite(struct vgic_its *its, u32 event_id,return 0 ; } -int vgic_its_flush_itt (struct vgic_its *its,struct its_device *device) +static int vgic_its_flush_itt (struct vgic_its *its,struct its_device *device) {gpa_t base = device->itt_addr;struct its_ite *ite;@@ -1900,7 +1901,7 @@ int vgic_its_flush_itt(struct vgic_its *its, struct its_device *device)return 0 ; } -int vgic_its_restore_itt (struct vgic_its *its,struct its_device *dev) +static int vgic_its_restore_itt (struct vgic_its *its,struct its_device *dev) {size_t max_size =BIT_ULL (dev->nb_eventid_bits) *VITS_ESZ ;gpa_t base = dev->itt_addr;@@ -1917,12 +1918,141 @@ int vgic_its_restore_itt(struct vgic_its *its, struct its_device *dev) }/** +* vgic_its_flush_dte - Flush a device table entry at a given GPA +* +* @its: ITS handle +* @dev: ITS device +* @ptr: GPA +*/ +static int vgic_its_flush_dte (struct vgic_its *its, +struct its_device *dev,gpa_t ptr) +{ +struct kvm *kvm = its->dev->kvm; +u64 val, itt_addr_field; +int ret; +u32 next_offset; + + itt_addr_field = dev->itt_addr >>8 ; + next_offset =compute_next_devid_offset (&its->device_list, dev); + val = (1ULL <<63 | ((u64 )next_offset <<49 ) | (itt_addr_field <<5 ) | + (dev->nb_eventid_bits -1 )); + val =cpu_to_le64 (val); + ret =kvm_write_guest (kvm, ptr, &val,8 ); +return ret; +} + +/** +* vgic_its_restore_dte - restore a device table entry +* +* @its: its handle +* @id: device id the DTE corresponds to +* @ptr: kernel VA where the 8 byte DTE is located +* @opaque: unused +* @next: offset to the next valid device id +* +* Return: < 0 on error, 0 otherwise +*/ +static int vgic_its_restore_dte (struct vgic_its *its,u32 id, +void *ptr,void *opaque,u32 *next) +{ +struct its_device *dev; +gpa_t itt_addr; +u8 nb_eventid_bits; +u64 entry = *(u64 *)ptr; +bool valid; +int ret; + + entry =le64_to_cpu (entry); + + valid = entry >>63 ; + nb_eventid_bits = (entry &GENMASK_ULL (4 ,0 )) +1 ; + itt_addr = ((entry &GENMASK_ULL (48 ,5 )) >>5 ) <<8 ; + *next =1 ; + +if (!valid) +return 0 ; + +/* dte entry is valid */ + *next = (entry &GENMASK_ULL (62 ,49 )) >>49 ; + + ret =vgic_its_alloc_device (its, &dev, id, + itt_addr, nb_eventid_bits); +if (ret) +return ret; + ret =vgic_its_restore_itt (its, dev); + +return ret; +} + +/** * vgic_its_flush_device_tables - flush the device table and all ITT * into guest RAM +* +* L1/L2 handling is hidden by vgic_its_check_id() helper which directly +* returns the GPA of the device entry */ static int vgic_its_flush_device_tables (struct vgic_its *its) { -return -ENXIO ; +struct its_device *dev; +u64 baser; + + baser = its->baser_device_table; + +list_for_each_entry (dev, &its->device_list, dev_list) { +int ret; +gpa_t eaddr; + +if (!vgic_its_check_id (its, baser, + dev->device_id, &eaddr)) +return -EINVAL ; + + ret =vgic_its_flush_itt (its, dev); +if (ret) +return ret; + + ret =vgic_its_flush_dte (its, dev, eaddr); +if (ret) +return ret; + } +return 0 ; +} + +/** +* handle_l1_entry - callback used for L1 entries (2 stage case) +* +* @its: its handle +* @id: id +* @addr: kernel VA +* @opaque: unused +* @next_offset: offset to the next L1 entry: 0 if the last element +* was found, 1 otherwise +*/ +static int handle_l1_entry (struct vgic_its *its,u32 id,void *addr, +void *opaque,u32 *next_offset) +{ +int l2_start_id = id * (SZ_64K /GITS_LVL1_ENTRY_SIZE ); +u64 entry = *(u64 *)addr; +gpa_t gpa; +int ret; + + entry =le64_to_cpu (entry); + *next_offset =1 ; + +if (!(entry &BIT_ULL (63 ))) +return 0 ; +
virt/kvm/arm/vgic/vgic-its.c int vgic_its_restore_itt(struct vgic_its *its, struct its_device *dev) · line 2053
Quoted 10 lines
virt/kvm/arm/vgic/vgic-its.c +10
-0+ gpa = entry &GENMASK_ULL (51 ,16 ); + + ret =lookup_table (its, gpa,SZ_64K ,8 , + l2_start_id, vgic_its_restore_dte,NULL ); + +if (ret ==1 ) { +/* last entry was found in this L2 table */ + *next_offset =0 ; + ret =0 ; + }
Ah, that's why you have this complicated return convention.
Quoted 13 lines
virt/kvm/arm/vgic/vgic-its.c +5
-1+ +return ret; }/** @@ -1931,7 +2061,28 @@ static int vgic_its_flush_device_tables(struct vgic_its *its)*/ static int vgic_its_restore_device_tables (struct vgic_its *its) { -return -ENXIO ; +u64 baser = its->baser_device_table; +int l1_tbl_size =GITS_BASER_NR_PAGES (baser) *SZ_64K ; +int l1_esz =GITS_BASER_ENTRY_SIZE (baser);
virt/kvm/arm/vgic/vgic-its.c static int vgic_its_flush_device_tables(struct vgic_its *its) · line 2076
Quoted 10 lines
virt/kvm/arm/vgic/vgic-its.c +10
-0+gpa_t l1_gpa; +int ret; + + l1_gpa =BASER_ADDRESS (baser); +if (!l1_gpa) +return 0 ; + +if (baser &GITS_BASER_INDIRECT ) + ret =lookup_table (its, l1_gpa, l1_tbl_size,8 ,0 , + handle_l1_entry,NULL );
I wonder if you shouldn't make this a different function (maybe using the same core helper) to parse L1 tables.
virt/kvm/arm/vgic/vgic-its.c static int vgic_its_flush_device_tables(struct vgic_its *its) · line 2088
Quoted 13 lines
virt/kvm/arm/vgic/vgic-its.c +9
-0+else + ret =lookup_table (its, l1_gpa, l1_tbl_size, l1_esz, +0 , vgic_its_restore_dte,NULL ); + +if (ret <0 ) +return ret; + +/* if last element was not found we have an issue here */ +return ret ?0 : -EINVAL ; } static int vgic_its_flush_cte(struct vgic_its *its,
The previous comments about the the encoding still apply... ;-)
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
PATCH v4 22/22 KVM: arm64: ITS: Pending table save/restore
In reply to Eric AugerSave and restore the pending tables.
Pending table restore obviously requires the pendbaser to be already set.
---
v3 -> v4:
- remove the wrong comment about locking
- pass kvm struct instead of its handle
- add comment about restore method
- remove GITR_PENDABASER.PTZ check
- continue if target_vcpu == NULL
- new locking strategy
v1 -> v2:
- do not care about the 1st KB which should be zeroed according to the spec.
--- virt/kvm/arm/vgic/vgic-its.c | 66 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 2 deletions(-)
virt/kvm/arm/vgic/vgic-its.c +64 -2
@@ -1804,16 +1804,78 @@ static int lookup_table(struct vgic_its *its, gpa_t base, int size, int esz,*/ static int vgic_its_flush_pending_tables (struct kvm *kvm) { -return -ENXIO ; +struct vgic_dist *dist = &kvm->arch.vgic; +struct vgic_irq *irq; +int ret; + +list_for_each_entry (irq, &dist->lpi_list_head, lpi_list) { +struct kvm_vcpu *vcpu; +gpa_t pendbase, ptr; +bool stored; +u8 val; + + vcpu = irq->target_vcpu; +if (!vcpu) +continue ; + + pendbase =PENDBASER_ADDRESS (vcpu->arch.vgic_cpu.pendbaser); + + ptr = pendbase + (irq->intid /BITS_PER_BYTE ); + + ret =kvm_read_guest (kvm, (gpa_t )ptr, &val,1 ); +if (ret) +return ret; + + stored = val & (irq->intid %BITS_PER_BYTE ); +if (stored == irq->pending_latch) +continue ; + +if (irq->pending_latch) + val |=1 << (irq->intid %BITS_PER_BYTE ); +else + val &= ~(1 << (irq->intid %BITS_PER_BYTE )); + + ret =kvm_write_guest (kvm, (gpa_t )ptr, &val,1 ); +if (ret) +return ret; + } + +return 0 ; }/** * vgic_its_restore_pending_tables - Restore the pending tables from guest * RAM to internal data structs +* +* Does not scan the whole pending tables but just loop on all registered +* LPIS and scan their associated pending bit. This obviously requires +* the ITEs to be restored before. */ static int vgic_its_restore_pending_tables (struct kvm *kvm) { -return -ENXIO ; +struct vgic_dist *dist = &kvm->arch.vgic; +struct vgic_irq *irq; +int ret; + +list_for_each_entry (irq, &dist->lpi_list_head, lpi_list) { +struct kvm_vcpu *vcpu; +gpa_t pendbase, ptr; +u8 val; + + vcpu = irq->target_vcpu; +if (!vcpu) +continue ; + + pendbase =PENDBASER_ADDRESS (vcpu->arch.vgic_cpu.pendbaser); + + ptr = pendbase + (irq->intid /BITS_PER_BYTE ); + + ret =kvm_read_guest (kvm, (gpa_t )ptr, &val,1 ); +if (ret) +return ret; + irq->pending_latch = val & (1 << (irq->intid %BITS_PER_BYTE )); + } +return 0 ; } static int vgic_its_flush_ite(struct vgic_its *its, struct its_device *dev,
Signature · 1 line
2.5.5
Re: [PATCH v4 22/22] KVM: arm64: ITS: Pending table save/restore
Quoted 42 lines · Eric Auger
Save and restore the pending tables.
Pending table restore obviously requires the pendbaser to be already set.
Signed-off-by Eric Auger <[email protected]>---
v3 -> v4:
- remove the wrong comment about locking
- pass kvm struct instead of its handle
- add comment about restore method
- remove GITR_PENDABASER.PTZ check
- continue iftarget_vcpu== NULL
- new locking strategyv1 -> v2:
- do not care about the 1st KB which should be zeroed according to the spec.--- virt/kvm/arm/vgic/vgic-its.c | 66 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 2 deletions(-)virt/kvm/arm/vgic/vgic-its.c +9
-1@@ -1804,16 +1804,78 @@ static int lookup_table(struct vgic_its *its, gpa_t base, int size, int esz,*/ static int vgic_its_flush_pending_tables (struct kvm *kvm) { -return -ENXIO ; +struct vgic_dist *dist = &kvm->arch.vgic; +struct vgic_irq *irq; +int ret; + +list_for_each_entry (irq, &dist->lpi_list_head, lpi_list) { +struct kvm_vcpu *vcpu; +gpa_t pendbase, ptr; +bool stored; +u8 val;
virt/kvm/arm/vgic/vgic-its.c static int lookup_table(struct vgic_its *its, gpa_t base, int size, int esz, · line 1825
Quoted 10 lines
virt/kvm/arm/vgic/vgic-its.c +10
-0+ + vcpu = irq->target_vcpu; +if (!vcpu) +continue ; + + pendbase =PENDBASER_ADDRESS (vcpu->arch.vgic_cpu.pendbaser); + + ptr = pendbase + (irq->intid /BITS_PER_BYTE ); + + ret =kvm_read_guest (kvm, (gpa_t )ptr, &val,1 );
ptr is already a gpa_t...
Quoted 5 lines
virt/kvm/arm/vgic/vgic-its.c +5
-0+if (ret) +return ret; + + stored = val & (irq->intid %BITS_PER_BYTE ); +if (stored == irq->pending_latch)
virt/kvm/arm/vgic/vgic-its.c static int lookup_table(struct vgic_its *its, gpa_t base, int size, int esz, · line 1840
Quoted 10 lines
virt/kvm/arm/vgic/vgic-its.c +10
-0+continue ; + +if (irq->pending_latch) + val |=1 << (irq->intid %BITS_PER_BYTE ); +else + val &= ~(1 << (irq->intid %BITS_PER_BYTE )); + + ret =kvm_write_guest (kvm, (gpa_t )ptr, &val,1 ); +if (ret) +return ret;
Consider the optimization used in its_sync_lpi_pending_table(), where consecutive LPIs stored in the same byte are set in a single access.
Quoted 29 lines
virt/kvm/arm/vgic/vgic-its.c +20
-1+ } + +return 0 ; }/** * vgic_its_restore_pending_tables - Restore the pending tables from guest * RAM to internal data structs +* +* Does not scan the whole pending tables but just loop on all registered +* LPIS and scan their associated pending bit. This obviously requires +* the ITEs to be restored before. */ static int vgic_its_restore_pending_tables (struct kvm *kvm) { -return -ENXIO ; +struct vgic_dist *dist = &kvm->arch.vgic; +struct vgic_irq *irq; +int ret; + +list_for_each_entry (irq, &dist->lpi_list_head, lpi_list) { +struct kvm_vcpu *vcpu; +gpa_t pendbase, ptr; +u8 val; + + vcpu = irq->target_vcpu; +if (!vcpu) +continue ; +
virt/kvm/arm/vgic/vgic-its.c static int lookup_table(struct vgic_its *its, gpa_t base, int size, int esz, · line 1878
Quoted 10 lines
virt/kvm/arm/vgic/vgic-its.c +10
-0+ pendbase =PENDBASER_ADDRESS (vcpu->arch.vgic_cpu.pendbaser); + + ptr = pendbase + (irq->intid /BITS_PER_BYTE ); + + ret =kvm_read_guest (kvm, (gpa_t )ptr, &val,1 ); +if (ret) +return ret; + irq->pending_latch = val & (1 << (irq->intid %BITS_PER_BYTE )); + } +return 0 ;
Again, this feels very similar to what its_sync_lpi_pending_table is doing. We should be able to have some common code here.
virt/kvm/arm/vgic/vgic-its.c static int lookup_table(struct vgic_its *its, gpa_t base, int size, int esz, · line 1881
Quoted 4 lines
virt/kvm/arm/vgic/vgic-its.c +0
-0} static int vgic_its_flush_ite(struct vgic_its *its, struct its_device *dev,
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Hi Eric,
Quoted 30 lines · Eric Auger
This series specifies and implements an API aimed at saving and restoring the state of the in-kernel emulated ITS device.
The ITS is programmed through registers and tables. Those latter are allocated by the guest. Their base address is programmed in registers or table entries before the ITS is enabled.
The ITS is free to use some of them to flush its internal caches. This is likely to be used when entering low power state.
Therefore, for save/restore use case, it looks natural to use this guest RAM allocated space to save the table related data. However, currently, The ITS in-kernel emulated device does not use all of those tables and for those it uses, it does not always sync them with its cached data. Additional sync must happen for:
- the collection table
- the device table
- the per-device translation tables
- the LPI pending tables.The LPI configation table and the command queues do not need extra syncs.
An alternative to flushing the tables into guest RAM could have been to flush them into a separate user-space buffer. However the drawback of this alternative is that the virtualizer would allocate dedicated buffers to store the data that should normally be laid out in guest RAM. It would also be obliged to re-compute their size from register/table content.
Quoted 4 lines
So saving the tables in guest RAM better fit the ITS programming model and optimizes the memory usage. The drawback of this solution is it brings additional challenges at user-space level to make sure the guest RAM is frozen after table sync.
I think this series is on the right track. What it needs is some clarification in the spec (as outlined by Christoffer), some tidying up around the encoding, and various nits that need addressing all over the map.
The only architectural issue is really the ITS/GICR split, but I don't think this is a big deal.
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...