Fix a bug in VGIC ITS tables' save/restore
cover Fix a bug in VGIC ITS tables' save/restore
This patch series addresses a critical issue in the VGIC ITS tables' save/restore mechanism, accompanied by a comprehensive selftest for bug reproduction and verification.
The identified bug manifests as a failure in VM suspend/resume operations. The root cause lies in the repeated suspend attempts often required for successful VM suspension, coupled with concurrent device interrupt registration and freeing. This concurrency leads to inconsistencies in ITS mappings before the save operation, potentially leaving orphaned Device Translation Entries (DTEs) and Interrupt Translation Entries (ITEs) in the respective tables.
During the subsequent restore operation, encountering these orphaned entries can result in two error scenarios:
* EINVAL Error: If an orphaned entry lacks a corresponding collection ID, the restore operation fails with an EINVAL error.
* Mapping Corruption: If an orphaned entry possesses a valid collection ID, the restore operation may succeed but with incorrect or lost mappings, compromising system integrity.
The provided selftest facilitates the reproduction of both error scenarios:
* EINVAL Reproduction: Execute ./vgic_its_tables without any options.
* Mapping Corruption Reproduction: Execute ./vgic_its_tables -s The -s option enforces identical collection IDs for all mappings.
* A workaround within the selftest involves clearing the tables before the save operation using the command ./vgic_its_tables -c. With this, we can run the the selftest successfully on host w/o the fix.
The core issue stems from the static linked list implementation of DTEs/ITEs, requiring a full table scan to locate the list head during restoration. This scan increases the likelihood of encountering orphaned entries. To rectify this, the patch series introduces a dummy head to the list, enabling immediate access to the list head and bypassing the scan. This optimization not only resolves the bug but also significantly enhances restore performance, particularly in edge cases where valid entries reside at the end of the table.
Result from the test demonstrates a remarkable 1000x performance improvement in such edge cases. For instance, with a single L2 device table (64KB) and 8192 mappings (one event per device at the table's end), the restore time is reduced from 6 seconds to 6 milliseconds.
Importantly, these modifications maintain compatibility with the existing ITS TABLE ABI REV0.
The table entry was a valid DTE/ITE, or an orphaned DTE/ITE, or an entry of 0. The dummy entry added in this patch series presents a fourth kind, which is an invalid entry w/ an offset field pointing to the first valid entry in the table. The dummy head entry is always the first entry in the table if it exists.
An alternative solution, proposed in patch series [1], involves clearing DTEs/ITEs during MAPD/DISCARD commands. While this approach requires fewer code changes, it lacks the performance benefits offered by the dummy head solution presented in this patch series.
---
* v1:
- Based on v6.12-rc6
[1] https://lore.kernel.org/linux-arm-kernel/[email protected]
---
Jing Zhang (4):
KVM: selftests: aarch64: Test VGIC ITS tables save/restore
KVM: arm64: vgic-its: Add a dummy DTE/ITE if necessary in ITS tables
save operation
KVM: arm64: vgic-its: Return device/event id instead of offset in ITS
tables restore
KVM: arm64: vgic-its: Utilize the dummy entry in ITS tables restoring
arch/arm64/kvm/vgic/vgic-its.c | 154 +++-- arch/arm64/kvm/vgic/vgic.h | 6 + tools/testing/selftests/kvm/Makefile | 1 + .../selftests/kvm/aarch64/vgic_its_tables.c | 562 ++++++++++++++++++ .../kvm/include/aarch64/gic_v3_its.h | 3 +- .../testing/selftests/kvm/include/kvm_util.h | 4 +- .../selftests/kvm/lib/aarch64/gic_v3_its.c | 24 +- 7 files changed, 713 insertions(+), 41 deletions(-) create mode 100644 tools/testing/selftests/kvm/aarch64/vgic_its_tables.c
base-commit: 59b723cd2adbac2a34fc8e12c74ae26ae45bf230
Signature · 1 line
2.47.0.199.ga7371fff76-goog
PATCH 1/4 KVM: selftests: aarch64: Test VGIC ITS tables save/restore
Add a selftest to verify the correctness of the VGIC ITS mappings after the save/restore operations (KVM_DEV_ARM_ITS_SAVE_TABLES / KVM_DEV_ARM_ITS_RESTORE_TABLES).
Also calculate the time spending on save/restore operations. This test uses some corner cases to capture the save/restore bugs. It will be used to verify the future incoming changes for the VGIC ITS tables save/restore.
To capture the "Invalid argument (-22)" error, run the test without any option. To capture the wrong/lost mappings, run the test with '-s' option.
Since the VGIC ITS save/restore bug is caused by orphaned DTE/ITE entries, if we run the test with '-c' option whih clears the tables before the save operation, the test will complete successfully.
--- tools/testing/selftests/kvm/Makefile | 1 + .../selftests/kvm/aarch64/vgic_its_tables.c | 562 ++++++++++++++++++ .../kvm/include/aarch64/gic_v3_its.h | 3 +- .../testing/selftests/kvm/include/kvm_util.h | 4 +- .../selftests/kvm/lib/aarch64/gic_v3_its.c | 24 +- 5 files changed, 588 insertions(+), 6 deletions(-) create mode 100644 tools/testing/selftests/kvm/aarch64/vgic_its_tables.c
tools/testing/selftests/kvm/Makefile +1 -0
@@ -163,6 +163,7 @@ TEST_GEN_PROGS_aarch64 += aarch64/smccc_filter TEST_GEN_PROGS_aarch64 += aarch64/vcpu_width_config TEST_GEN_PROGS_aarch64 += aarch64/vgic_init TEST_GEN_PROGS_aarch64 += aarch64/vgic_irq +TEST_GEN_PROGS_aarch64 += aarch64/vgic_its_tables TEST_GEN_PROGS_aarch64 += aarch64/vgic_lpi_stress TEST_GEN_PROGS_aarch64 += aarch64/vpmu_counter_access TEST_GEN_PROGS_aarch64 += aarch64/no-vgic-v3
tools/testing/selftests/kvm/aarch64/vgic_its_tables.c new file +562 -0
562 lines not on this page · raw message
tools/testing/selftests/kvm/include/aarch64/gic_v3_its.h +2 -1
@@ -7,7 +7,7 @@void its_init (vm_paddr_t coll_tbl,size_t coll_tbl_sz,vm_paddr_t device_tbl,size_t device_tbl_sz, -vm_paddr_t cmdq,size_t cmdq_size); +vm_paddr_t cmdq,size_t cmdq_size,bool indirect_device_tbl);void its_send_mapd_cmd (void *cmdq_base,u32 device_id,vm_paddr_t itt_base,size_t itt_size,bool valid);
@@ -15,5 +15,6 @@ void its_send_mapc_cmd(void *cmdq_base, u32 vcpu_id, u32 collection_id, bool valvoid its_send_mapti_cmd (void *cmdq_base,u32 device_id,u32 event_id,u32 collection_id,u32 intid);void its_send_invall_cmd (void *cmdq_base,u32 collection_id); +void its_send_discard_cmd (void *cmdq_base,u32 device_id,u32 event_id);#endif // __SELFTESTS_GIC_V3_ITS_H__
tools/testing/selftests/kvm/include/kvm_util.h +3 -1
@@ -27,7 +27,9 @@#define KVM_DEV_PATH "/dev/kvm"#define KVM_MAX_VCPUS 512 -#define NSEC_PER_SEC 1000000000L +#define NSEC_PER_USEC 1000L +#define USEC_PER_SEC 1000000L +#define NSEC_PER_SEC 1000000000Lstruct userspace_mem_region {struct kvm_userspace_memory_region2 region;
tools/testing/selftests/kvm/lib/aarch64/gic_v3_its.c +20 -4
@@ -52,7 +52,8 @@ static unsigned long its_find_baser(unsigned int type)return -1 ; } -static void its_install_table (unsigned int type,vm_paddr_t base,size_t size) +static void its_install_table (unsigned int type,vm_paddr_t base, +size_t size,bool indirect) {unsigned long offset =its_find_baser (type);u64 baser;
@@ -64,6 +65,9 @@ static void its_install_table(unsigned int type, vm_paddr_t base, size_t size) GITS_BASER_RaWaWb |GITS_BASER_VALID ; +if (indirect) + baser |=GITS_BASER_INDIRECT ; +its_write_u64 (offset, baser); }
@@ -82,12 +86,13 @@ static void its_install_cmdq(vm_paddr_t base, size_t size)void its_init (vm_paddr_t coll_tbl,size_t coll_tbl_sz,vm_paddr_t device_tbl,size_t device_tbl_sz, -vm_paddr_t cmdq,size_t cmdq_size) +vm_paddr_t cmdq,size_t cmdq_size,bool indirect_device_tbl) {u32 ctlr; -its_install_table (GITS_BASER_TYPE_COLLECTION , coll_tbl, coll_tbl_sz); -its_install_table (GITS_BASER_TYPE_DEVICE , device_tbl, device_tbl_sz); +its_install_table (GITS_BASER_TYPE_COLLECTION , coll_tbl, coll_tbl_sz, false); +its_install_table (GITS_BASER_TYPE_DEVICE , device_tbl, device_tbl_sz, + indirect_device_tbl);its_install_cmdq (cmdq, cmdq_size); ctlr =its_read_u32 (GITS_CTLR );
@@ -237,6 +242,17 @@ void its_send_mapti_cmd(void *cmdq_base, u32 device_id, u32 event_id,its_send_cmd (cmdq_base, &cmd); } +void its_send_discard_cmd (void *cmdq_base,u32 device_id,u32 event_id) +{ +struct its_cmd_block cmd = {}; + +its_encode_cmd (&cmd,GITS_CMD_DISCARD ); +its_encode_devid (&cmd, device_id); +its_encode_event_id (&cmd, event_id); + +its_send_cmd (cmdq_base, &cmd); +} +void its_send_invall_cmd (void *cmdq_base,u32 collection_id) {struct its_cmd_block cmd = {};
Signature · 1 line
2.47.0.199.ga7371fff76-goog
PATCH 2/4 KVM: arm64: vgic-its: Add a dummy DTE/ITE if necessary in ITS tables save operation
In reply to Jing ZhangIn device tables/ITTs, DTEs/ITEs are implemented as a static single linked list. But the head of the list might not be the first DTE/ITE in the table. That's why in the restore operation, the DTs/ITTs have to be scanned to find the first valid DTE/ITE (head of the list). Add a dummy DTE/ITE in the first entry of the table if the first entry doesn't have a valid DTE/ITE. This dummy DTE/ITE points to the first valid DTE/ITE if there is a valid one.
This change paves the way for future incoming changes which will utilize the fixed head the DTE/ITE list to avoid scanning uncessary table entries.
No functional change intended.
--- arch/arm64/kvm/vgic/vgic-its.c | 56 ++++++++++++++++++++++++++++++++-- arch/arm64/kvm/vgic/vgic.h | 6 ++++ 2 files changed, 59 insertions(+), 3 deletions(-)
arch/arm64/kvm/vgic/vgic-its.c +53 -3
@@ -2176,10 +2176,12 @@ static int vgic_its_ite_cmp(void *priv, const struct list_head *a,static int vgic_its_save_itt (struct vgic_its *its,struct its_device *device) {const struct vgic_its_abi *abi =vgic_its_get_abi (its); +struct its_ite *ite, *first_ite =NULL ; +struct kvm *kvm = its->dev->kvm;gpa_t base = device->itt_addr; -struct its_ite *ite; -int ret;int ite_esz = abi->ite_esz; +u64 val =0 ; +int ret;list_sort (NULL , &device->itt_head, vgic_its_ite_cmp);
@@ -2198,7 +2200,24 @@ static int vgic_its_save_itt(struct vgic_its *its, struct its_device *device) ret =vgic_its_save_ite (its, device, ite, gpa, ite_esz);if (ret)return ret; + +if (!first_ite) + first_ite = ite; } + +/* +* As for DTEs, add a dummy ITE if necessary for ITT to avoid uncessary +* sanning in the store operation. +*/ +if (first_ite && first_ite->event_id) + val = (u64 )first_ite->event_id <<KVM_ITS_ITE_NEXT_SHIFT ; + +if (!first_ite || first_ite->event_id) { + val |=KVM_ITS_ENTRY_DUMMY_MAGIC <<KVM_ITS_ENTRY_DUMMY_SHIFT ; + val =cpu_to_le64 (val); +vgic_write_guest_lock (kvm, base, &val, ite_esz); + } +return 0 ; }
@@ -2328,8 +2347,11 @@ static int vgic_its_save_device_tables(struct vgic_its *its) {const struct vgic_its_abi *abi =vgic_its_get_abi (its);u64 baser = its->baser_device_table; -struct its_device *dev; +struct its_device *dev, *first_dev =NULL ; +struct kvm *kvm = its->dev->kvm;int dte_esz = abi->dte_esz; +gpa_t dummy_eaddr; +u64 val =0 ;if (!(baser &GITS_BASER_VALID ))return 0 ;
@@ -2351,7 +2373,35 @@ static int vgic_its_save_device_tables(struct vgic_its *its) ret =vgic_its_save_dte (its, dev, eaddr, dte_esz);if (ret)return ret; + +if (!first_dev) + first_dev = dev; } + +/* +* The valid DTEs in the device table are linked with a static single +* linked list, but the list head is not always the first DTE. That's +* why the restore operation has to scan the device table from the first +* entry all the time. +* To avoid the uncessary scanning in the restore operation, if the +* first valid DTE is not the first one in the table, add a dummy DTE +* with valid bit as 0 pointing to the first valid DTE. +* This way, the first DTE in the table is always the head of the DTE +* list. It is either a valid DTE or a dummy DTE (V= 0) pointing to the +* first valid DTE if there is a valid DTE in the table. +*/ +if (first_dev && first_dev->device_id) + val = (u64 )first_dev->device_id <<KVM_ITS_DTE_DUMMY_NEXT_SHIFT ; + +if (!first_dev || first_dev->device_id) { +if (!vgic_its_check_id (its, baser,0 , &dummy_eaddr)) +return -EINVAL ; + + val |=KVM_ITS_ENTRY_DUMMY_MAGIC <<KVM_ITS_ENTRY_DUMMY_SHIFT ; + val =cpu_to_le64 (val); +vgic_write_guest_lock (kvm, dummy_eaddr, &val, dte_esz); + } +return 0 ; }
arch/arm64/kvm/vgic/vgic.h +6 -0
@@ -86,6 +86,12 @@#define KVM_ITS_L1E_VALID_MASK BIT_ULL(63)/* we only support 64 kB translation table page size */ #define KVM_ITS_L1E_ADDR_MASK GENMASK_ULL(51, 16) +/* Macros for dummy ITE/DTE */ +#define KVM_ITS_ENTRY_DUMMY_SHIFT 0 +#define KVM_ITS_ENTRY_DUMMY_MASK GENMASK_ULL(15, 0) +#define KVM_ITS_ENTRY_DUMMY_MAGIC 0xdafe +#define KVM_ITS_DTE_DUMMY_NEXT_SHIFT 16 +#define KVM_ITS_DTE_DUMMY_NEXT_MASK GENMASK(48, 16)#define KVM_VGIC_V3_RDIST_INDEX_MASK GENMASK_ULL(11, 0)#define KVM_VGIC_V3_RDIST_FLAGS_MASK GENMASK_ULL(15, 12)
Signature · 1 line
2.47.0.199.ga7371fff76-goog
PATCH 3/4 KVM: arm64: vgic-its: Return device/event id instead of offset in ITS tables restore
In reply to Jing ZhangIn ITS tables restore operation, the id offset is passing around during table scanning. But, e can derive more information from a device/event id, since device table and ITT are indexed by the id.
Pass around the next device/event id instead of id offset to ease the implementation for incoming changes.
A side benefit of this change is that the 2-level device table scanning would be more efficient. With the deivce id, we don't have to scan the L1 table entry one by one, the scanning can jump directly to the DTE in the L2 table.
--- arch/arm64/kvm/vgic/vgic-its.c | 56 ++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 23 deletions(-)
arch/arm64/kvm/vgic/vgic-its.c +33 -23
@@ -2041,15 +2041,17 @@ typedef int (*entry_fn_t)(struct vgic_its *its, u32 id, void *entry,* (non zero for 2d level tables) * @fn: function to apply on each entry * @opaque: pointer to opaque data +* @l1_tbl: true if it is a l1 table in a 2-level structure * -* Return: < 0 on error, 0 if last element was identified, 1 otherwise -* (the last element may not be found on second level tables) +* Return: < 0 on error, 0 if last element was identified, next id (device id or +* event id) of next valid entry. */ static int scan_its_table (struct vgic_its *its,gpa_t base,int size,u32 esz, -int start_id,entry_fn_t fn,void *opaque) +int start_id,entry_fn_t fn,void *opaque,bool l1_tbl) {struct kvm *kvm = its->dev->kvm;unsigned long len = size; +int next_id = start_id;int id = start_id;gpa_t gpa = base;char entry[ESZ_MAX ];
@@ -2065,8 +2067,16 @@ static int scan_its_table(struct vgic_its *its, gpa_t base, int size, u32 esz,if (ret)return ret; - next_offset =fn (its, id, entry, opaque); -if (next_offset <=0 ) + next_id =fn (its, next_id, entry, opaque); +if (next_id <=0 ) +return next_id; + +if (l1_tbl) + next_offset = next_id * esz /SZ_64K - id; +else + next_offset = next_id - id; + +if (!next_offset)return next_offset; byte_offset = next_offset * esz;
@@ -2077,7 +2087,7 @@ static int scan_its_table(struct vgic_its *its, gpa_t base, int size, u32 esz, gpa += byte_offset; len -= byte_offset; } -return 1 ; +return next_id; }/*
@@ -2128,7 +2138,7 @@ static int vgic_its_restore_ite(struct vgic_its *its, u32 event_id, lpi_id = (val &KVM_ITS_ITE_PINTID_MASK ) >>KVM_ITS_ITE_PINTID_SHIFT ;if (!lpi_id) -return 1 ;/* invalid entry, no choice but to scan next entry */ +return event_id +1 ;/* invalid entry, no choice but to scan next entry */ if (lpi_id <VGIC_MIN_LPI )return -EINVAL ;
@@ -2158,7 +2168,7 @@ static int vgic_its_restore_ite(struct vgic_its *its, u32 event_id, } ite->irq = irq; -return offset; +return event_id + offset; } static int vgic_its_ite_cmp(void *priv, const struct list_head *a,
@@ -2238,7 +2248,7 @@ static int vgic_its_restore_itt(struct vgic_its *its, struct its_device *dev)size_t max_size =BIT_ULL (dev->num_eventid_bits) * ite_esz; ret =scan_its_table (its, base, max_size, ite_esz,0 , - vgic_its_restore_ite, dev); + vgic_its_restore_ite, dev, false);/* scan_its_table returns +1 if all ITEs are invalid */ if (ret >0 )
@@ -2280,8 +2290,8 @@ static int vgic_its_save_dte(struct vgic_its *its, struct its_device *dev,* @ptr: kernel VA where the 8 byte DTE is located * @opaque: unused * -* Return: < 0 on error, 0 if the dte is the last one, id offset to the -* next dte otherwise +* Return: < 0 on error, device id of the current DTE if it +* is the last one, device id of the next DTE otherwise */ static int vgic_its_restore_dte (struct vgic_its *its,u32 id,void *ptr,void *opaque)
@@ -2303,7 +2313,7 @@ static int vgic_its_restore_dte(struct vgic_its *its, u32 id, >> KVM_ITS_DTE_ITTADDR_SHIFT) << 8;if (!valid) -return 1 ; +return id +1 ;/* dte entry is valid */ offset = (entry &KVM_ITS_DTE_NEXT_MASK ) >>KVM_ITS_DTE_NEXT_SHIFT ;
@@ -2321,7 +2331,7 @@ static int vgic_its_restore_dte(struct vgic_its *its, u32 id,return ret; } -return offset; +return id + offset; } static int vgic_its_device_cmp(void *priv, const struct list_head *a,
@@ -2409,33 +2419,33 @@ static int vgic_its_save_device_tables(struct vgic_its *its)* handle_l1_dte - callback used for L1 device table entries (2 stage case) * * @its: its handle -* @id: index of the entry in the L1 table +* @id: the start device id to scan in the L2 table * @addr: kernel VA * @opaque: unused * -* L1 table entries are scanned by steps of 1 entry * Return < 0 if error, 0 if last dte was found when scanning the L2 -* table, +1 otherwise (meaning next L1 entry must be scanned) +* table, device id of the next valid DTE otherwise */ static int handle_l1_dte (struct vgic_its *its,u32 id,void *addr,void *opaque) {const struct vgic_its_abi *abi =vgic_its_get_abi (its); -int l2_start_id = id * (SZ_64K / abi->dte_esz);u64 entry = *(u64 *)addr;int dte_esz = abi->dte_esz; +int dte_per_table =SZ_64K / dte_esz; +gpa_t gpa_offset = (id % dte_per_table) * dte_esz;gpa_t gpa;int ret; entry =le64_to_cpu (entry);if (!(entry &KVM_ITS_L1E_VALID_MASK )) -return 1 ; +return (id +1 ) * dte_per_table; - gpa = entry &KVM_ITS_L1E_ADDR_MASK ; + gpa = (entry &KVM_ITS_L1E_ADDR_MASK ) + gpa_offset; - ret =scan_its_table (its, gpa,SZ_64K , dte_esz, - l2_start_id, vgic_its_restore_dte,NULL ); + ret =scan_its_table (its, gpa,SZ_64K - gpa_offset , dte_esz, + id, vgic_its_restore_dte,NULL , false);return ret; }
@@ -2460,11 +2470,11 @@ static int vgic_its_restore_device_tables(struct vgic_its *its)if (baser &GITS_BASER_INDIRECT ) { l1_esz =GITS_LVL1_ENTRY_SIZE ; ret =scan_its_table (its, l1_gpa, l1_tbl_size, l1_esz,0 , - handle_l1_dte,NULL ); + handle_l1_dte,NULL , true); }else { l1_esz = abi->dte_esz; ret =scan_its_table (its, l1_gpa, l1_tbl_size, l1_esz,0 , - vgic_its_restore_dte,NULL ); + vgic_its_restore_dte,NULL , false); }/* scan_its_table returns +1 if all entries are invalid */
Signature · 1 line
2.47.0.199.ga7371fff76-goog
PATCH 4/4 KVM: arm64: vgic-its: Utilize the dummy entry in ITS tables restoring
In reply to Jing ZhangNow, the first entry in tables is either a valid DTE/ITE or a dummy entry pointing to the first valid DTE/ITE. Revise the DTE/ITE restore process to utilize the dummy entry to avoid unnecessary (erroneous) entry scanning.
This is not supposed to break the ITS table ABI REV0.
--- arch/arm64/kvm/vgic/vgic-its.c | 46 ++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 11 deletions(-)
arch/arm64/kvm/vgic/vgic-its.c +35 -11
@@ -2129,23 +2129,30 @@ static int vgic_its_restore_ite(struct vgic_its *its, u32 event_id,u32 coll_id, lpi_id;struct its_ite *ite;u32 offset; +u32 magic; val = *p; val =le64_to_cpu (val); - coll_id = val &KVM_ITS_ITE_ICID_MASK ; lpi_id = (val &KVM_ITS_ITE_PINTID_MASK ) >>KVM_ITS_ITE_PINTID_SHIFT ; -if (!lpi_id) -return event_id +1 ;/* invalid entry, no choice but to scan next entry */ + offset = val >>KVM_ITS_ITE_NEXT_SHIFT ; +if (event_id + offset >=BIT_ULL (dev->num_eventid_bits)) +return -EINVAL ; + +if (!lpi_id) { + magic = (val &KVM_ITS_ENTRY_DUMMY_MASK ) >>KVM_ITS_ENTRY_DUMMY_SHIFT ; +if (magic !=KVM_ITS_ENTRY_DUMMY_MAGIC ) + offset =1 ; + +return event_id + offset; + }if (lpi_id <VGIC_MIN_LPI )return -EINVAL ; - offset = val >>KVM_ITS_ITE_NEXT_SHIFT ; -if (event_id + offset >=BIT_ULL (dev->num_eventid_bits)) -return -EINVAL ; + coll_id = val &KVM_ITS_ITE_ICID_MASK ; collection =find_collection (its, coll_id);if (!collection)
@@ -2303,17 +2310,30 @@ static int vgic_its_restore_dte(struct vgic_its *its, u32 id,u64 entry = *(u64 *)ptr;bool valid;u32 offset; +u32 magic;int ret; entry =le64_to_cpu (entry); valid = entry >>KVM_ITS_DTE_VALID_SHIFT ; - num_eventid_bits = (entry &KVM_ITS_DTE_SIZE_MASK ) +1 ; - itt_addr = ((entry &KVM_ITS_DTE_ITTADDR_MASK ) - >>KVM_ITS_DTE_ITTADDR_SHIFT ) <<8 ; -if (!valid) -return id +1 ; +/* +* Since we created a dummy head entry for the DTE static linked list in +* the table if necessary, no need to scan to find the list head. +* But if the saved table was done without dummy entry support, we still +* have to scan one by one. +*/ +if (!valid) { + magic = (entry &KVM_ITS_ENTRY_DUMMY_MASK ) >> +KVM_ITS_ENTRY_DUMMY_SHIFT ; +if (magic !=KVM_ITS_ENTRY_DUMMY_MAGIC ) + offset =1 ; +else + offset = (entry &KVM_ITS_DTE_DUMMY_NEXT_MASK ) >> +KVM_ITS_DTE_DUMMY_NEXT_SHIFT ; + +return id + offset; + }/* dte entry is valid */ offset = (entry &KVM_ITS_DTE_NEXT_MASK ) >>KVM_ITS_DTE_NEXT_SHIFT ;
@@ -2321,6 +2341,10 @@ static int vgic_its_restore_dte(struct vgic_its *its, u32 id,if (!vgic_its_check_id (its, baser, id,NULL ))return -EINVAL ; + num_eventid_bits = (entry &KVM_ITS_DTE_SIZE_MASK ) +1 ; + itt_addr = ((entry &KVM_ITS_DTE_ITTADDR_MASK ) + >>KVM_ITS_DTE_ITTADDR_SHIFT ) <<8 ; + dev =vgic_its_alloc_device (its, id, itt_addr, num_eventid_bits);if (IS_ERR (dev))return PTR_ERR (dev);
Signature · 1 line
2.47.0.199.ga7371fff76-goog
Hi Jing,
Quoted 7 lines · Jing Zhang
The core issue stems from the static linked list implementation of DTEs/ITEs, requiring a full table scan to locate the list head during restoration. This scan increases the likelihood of encountering orphaned entries. To rectify this, the patch series introduces a dummy head to the list, enabling immediate access to the list head and bypassing the scan. This optimization not only resolves the bug but also significantly enhances restore performance, particularly in edge cases where valid entries reside at the end of the table.
I think we need a more targeted fix (i.e. Kunkun's patch) to stop the bleeding + backport it to stable.
Then we can have a separate discussion about improving the save/restore performance with your approach.
Signature · 2 lines
Thanks, Oliver
Quoted 12 lines · Oliver Upton
Hi Jing,
Quoted 7 lines · Jing Zhang
The core issue stems from the static linked list implementation of DTEs/ITEs, requiring a full table scan to locate the list head during restoration. This scan increases the likelihood of encountering orphaned entries. To rectify this, the patch series introduces a dummy head to the list, enabling immediate access to the list head and bypassing the scan. This optimization not only resolves the bug but also significantly enhances restore performance, particularly in edge cases where valid entries reside at the end of the table.
Quoted 5 lines
I think we need a more targeted fix (i.e. Kunkun's patch) to stop the bleeding + backport it to stable.
Then we can have a separate discussion about improving the save/restore performance with your approach.
Yes, I'll respin Kunkun's patch soon. This patch series has the selftest which we can use for verification.
Quoted 4 lines
--
Thanks,
Oliver
Thanks,
Jing
Quoted 13 lines · Jing Zhang
Quoted 12 lines · Oliver Upton
Hi Jing,
Quoted 7 lines · Jing Zhang
The core issue stems from the static linked list implementation of DTEs/ITEs, requiring a full table scan to locate the list head during restoration. This scan increases the likelihood of encountering orphaned entries. To rectify this, the patch series introduces a dummy head to the list, enabling immediate access to the list head and bypassing the scan. This optimization not only resolves the bug but also significantly enhances restore performance, particularly in edge cases where valid entries reside at the end of the table.
Quoted 8 lines
Quoted 5 lines
I think we need a more targeted fix (i.e. Kunkun's patch) to stop the bleeding + backport it to stable.
Then we can have a separate discussion about improving the save/restore performance with your approach.
Yes, I'll respin Kunkun's patch soon. This patch series has the selftest which we can use for verification.
Right -- go ahead and include your selftest as part of that respin, I'd definitely like to have some test coverage for this whole save/restore mess.
Signature · 2 lines
Thanks, Oliver