kvm: fix KVM_MAX_VCPU_ID handling
Subsystems (9)
cover kvm: fix KVM_MAX_VCPU_ID handling
Revert commit 76b4f357d0e7d8f6f00 which was based on wrong reasoning and rename KVM_MAX_VCPU_ID to KVM_MAX_VCPU_IDS in order to avoid the same issue in future.
Juergen Gross (2):
x86/kvm: revert commit 76b4f357d0e7d8f6f00
kvm: rename KVM_MAX_VCPU_ID to KVM_MAX_VCPU_IDS
Documentation/virt/kvm/devices/xics.rst | 2 +- Documentation/virt/kvm/devices/xive.rst | 2 +- arch/mips/kvm/mips.c | 2 +- arch/powerpc/include/asm/kvm_book3s.h | 2 +- arch/powerpc/include/asm/kvm_host.h | 4 ++-- arch/powerpc/kvm/book3s_xive.c | 2 +- arch/powerpc/kvm/powerpc.c | 2 +- arch/x86/include/asm/kvm_host.h | 2 +- arch/x86/kvm/ioapic.c | 2 +- arch/x86/kvm/ioapic.h | 4 ++-- arch/x86/kvm/x86.c | 2 +- include/linux/kvm_host.h | 4 ++-- tools/testing/selftests/kvm/kvm_create_max_vcpus.c | 2 +- virt/kvm/kvm_main.c | 2 +- 14 files changed, 17 insertions(+), 17 deletions(-)
Signature · 1 line
2.26.2
PATCH 1/2 x86/kvm: revert commit 76b4f357d0e7d8f6f00
Commit 76b4f357d0e7d8f6f00 ("x86/kvm: fix vcpu-id indexed array sizes") has wrong reasoning, as KVM_MAX_VCPU_ID is not defining the maximum allowed vcpu-id as its name suggests, but the number of vcpu-ids.
So revert this patch again.
--- arch/x86/kvm/ioapic.c | 2 +- arch/x86/kvm/ioapic.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
arch/x86/kvm/ioapic.c +1 -1
@@ -96,7 +96,7 @@ static unsigned long ioapic_read_indirect(struct kvm_ioapic *ioapic,static void rtc_irq_eoi_tracking_reset (struct kvm_ioapic *ioapic) { ioapic->rtc_status.pending_eoi =0 ; -bitmap_zero (ioapic->rtc_status.dest_map.map,KVM_MAX_VCPU_ID +1 ); +bitmap_zero (ioapic->rtc_status.dest_map.map,KVM_MAX_VCPU_ID ); }static void kvm_rtc_eoi_tracking_restore_all (struct kvm_ioapic *ioapic);
arch/x86/kvm/ioapic.h +2 -2
@@ -39,13 +39,13 @@ struct kvm_vcpu;struct dest_map {/* vcpu bitmap where IRQ has been sent */ - DECLARE_BITMAP(map, KVM_MAX_VCPU_ID + 1); + DECLARE_BITMAP(map, KVM_MAX_VCPU_ID);/* * Vector sent to a given vcpu, only valid when * the vcpu's bit in map is set */ -u8 vectors[KVM_MAX_VCPU_ID +1 ]; +u8 vectors[KVM_MAX_VCPU_ID ]; };
Signature · 1 line
2.26.2
Re: [PATCH 1/2] x86/kvm: revert commit 76b4f357d0e7d8f6f00
Quoted 9 lines · Juergen Gross
Commit
76b4f357d0e7d8f6f00("x86/kvm: fix vcpu-id indexed array sizes") has wrong reasoning, asKVM_MAX_VCPU_IDis not defining the maximum allowed vcpu-id as its name suggests, but the number of vcpu-ids.So revert this patch again.
Suggested-by Eduardo Habkost <[email protected]>Signed-off-by Juergen Gross <[email protected]>
The original commit 76b4f357d0e7d8f6f00 CC'ed Stable but this revert does not. Looking at the stable branches, I see the original has been reverted but this hasn't. Should this be added to Stable as well?
Quoted 41 lines
--- arch/x86/kvm/ioapic.c | 2 +- arch/x86/kvm/ioapic.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)arch/x86/kvm/ioapic.c +1
-1@@ -96,7 +96,7 @@ static unsigned long ioapic_read_indirect(struct kvm_ioapic *ioapic,static void rtc_irq_eoi_tracking_reset (struct kvm_ioapic *ioapic) { ioapic->rtc_status.pending_eoi =0 ; -bitmap_zero (ioapic->rtc_status.dest_map.map,KVM_MAX_VCPU_ID +1 ); +bitmap_zero (ioapic->rtc_status.dest_map.map,KVM_MAX_VCPU_ID ); }static void kvm_rtc_eoi_tracking_restore_all (struct kvm_ioapic *ioapic);arch/x86/kvm/ioapic.h +2
-3@@ -39,13 +39,13 @@ struct kvm_vcpu;struct dest_map {/* vcpu bitmap where IRQ has been sent */ - DECLARE_BITMAP(map, KVM_MAX_VCPU_ID + 1); + DECLARE_BITMAP(map, KVM_MAX_VCPU_ID);/* * Vector sent to a given vcpu, only valid when * the vcpu's bit in map is set */ -u8 vectors[KVM_MAX_VCPU_ID +1 ]; +u8 vectors[KVM_MAX_VCPU_ID ]; }; --2.26.2
Re: [PATCH 1/2] x86/kvm: revert commit 76b4f357d0e7d8f6f00
Quoted 7 lines · Ben Gardon
Quoted 5 lines · Juergen Gross
Commit
76b4f357d0e7d8f6f00("x86/kvm: fix vcpu-id indexed array sizes") has wrong reasoning, asKVM_MAX_VCPU_IDis not defining the maximum allowed vcpu-id as its name suggests, but the number of vcpu-ids.
Quoted 8 lines
Quoted 4 lines
So revert this patch again.
Suggested-by Eduardo Habkost <[email protected]>Signed-off-by Juergen Gross <[email protected]>The original commit
76b4f357d0e7d8f6f00CC'ed Stable but this revert does not. Looking at the stable branches, I see the original has been reverted but this hasn't. Should this be added to Stable as well?
*the original has been incorporated into the stable branches but this hasn't.
Quoted 42 lines
Quoted 42 lines
--- arch/x86/kvm/ioapic.c | 2 +- arch/x86/kvm/ioapic.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)arch/x86/kvm/ioapic.c +1
-1@@ -96,7 +96,7 @@ static unsigned long ioapic_read_indirect(struct kvm_ioapic *ioapic,static void rtc_irq_eoi_tracking_reset (struct kvm_ioapic *ioapic) { ioapic->rtc_status.pending_eoi =0 ; -bitmap_zero (ioapic->rtc_status.dest_map.map,KVM_MAX_VCPU_ID +1 ); +bitmap_zero (ioapic->rtc_status.dest_map.map,KVM_MAX_VCPU_ID ); }static void kvm_rtc_eoi_tracking_restore_all (struct kvm_ioapic *ioapic);arch/x86/kvm/ioapic.h +2
-3@@ -39,13 +39,13 @@ struct kvm_vcpu;struct dest_map {/* vcpu bitmap where IRQ has been sent */ - DECLARE_BITMAP(map, KVM_MAX_VCPU_ID + 1); + DECLARE_BITMAP(map, KVM_MAX_VCPU_ID);/* * Vector sent to a given vcpu, only valid when * the vcpu's bit in map is set */ -u8 vectors[KVM_MAX_VCPU_ID +1 ]; +u8 vectors[KVM_MAX_VCPU_ID ]; }; --2.26.2
Re: [PATCH 1/2] x86/kvm: revert commit 76b4f357d0e7d8f6f00
Quoted 10 lines · Ben Gardon
Quoted 9 lines · Ben Gardon
Quoted 7 lines · Juergen Gross
Commit
76b4f357d0e7d8f6f00("x86/kvm: fix vcpu-id indexed array sizes") has wrong reasoning, asKVM_MAX_VCPU_IDis not defining the maximum allowed vcpu-id as its name suggests, but the number of vcpu-ids.So revert this patch again.
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
Suggested-by Eduardo Habkost <[email protected]>Signed-off-by Juergen Gross <[email protected]>The original commit
76b4f357d0e7d8f6f00CC'ed Stable but this revert does not. Looking at the stable branches, I see the original has been reverted but this hasn't. Should this be added to Stable as well?*the original has been incorporated into the stable branches but this hasn't.
Just yesterday I received mails that this patch has been added to the stable branches.
Juergen
Re: [PATCH 1/2] x86/kvm: revert commit 76b4f357d0e7d8f6f00
Quoted 19 lines · Juergen Gross
Quoted 17 lines · Ben Gardon
Quoted 15 lines · Ben Gardon
Quoted 9 lines · Juergen Gross
Commit
76b4f357d0e7d8f6f00("x86/kvm: fix vcpu-id indexed array sizes") has wrong reasoning, asKVM_MAX_VCPU_IDis not defining the maximum allowed vcpu-id as its name suggests, but the number of vcpu-ids.So revert this patch again.
Suggested-by Eduardo Habkost <[email protected]>Signed-off-by Juergen Gross <[email protected]>The original commit
76b4f357d0e7d8f6f00CC'ed Stable but this revert does not. Looking at the stable branches, I see the original has been reverted but this hasn't. Should this be added to Stable as well?
Quoted 7 lines
Quoted 1 line
*the original has been incorporated into the stable branches but this hasn't.
Just yesterday I received mails that this patch has been added to the stable branches.
Juergen
Oh wonderful, what a coincidence!
Thanks,
Ben
PATCH 2/2 kvm: rename KVM_MAX_VCPU_ID to KVM_MAX_VCPU_IDS
In reply to Juergen GrossKVM_MAX_VCPU_ID is not specifying the highest allowed vcpu-id, but the number of allowed vcpu-ids. This has already led to confusion, so rename KVM_MAX_VCPU_ID to KVM_MAX_VCPU_IDS to make its semantics more clear
--- Documentation/virt/kvm/devices/xics.rst | 2 +- Documentation/virt/kvm/devices/xive.rst | 2 +- arch/mips/kvm/mips.c | 2 +- arch/powerpc/include/asm/kvm_book3s.h | 2 +- arch/powerpc/include/asm/kvm_host.h | 4 ++-- arch/powerpc/kvm/book3s_xive.c | 2 +- arch/powerpc/kvm/powerpc.c | 2 +- arch/x86/include/asm/kvm_host.h | 2 +- arch/x86/kvm/ioapic.c | 2 +- arch/x86/kvm/ioapic.h | 4 ++-- arch/x86/kvm/x86.c | 2 +- include/linux/kvm_host.h | 4 ++-- tools/testing/selftests/kvm/kvm_create_max_vcpus.c | 2 +- virt/kvm/kvm_main.c | 2 +- 14 files changed, 17 insertions(+), 17 deletions(-)
Documentation/virt/kvm/devices/xics.rst +1 -1
@@ -22,7 +22,7 @@ Groups: Errors: ==== ===================== - -EINVAL Value greater than KVM_MAX_VCPU_ID. + -EINVAL Value greater than KVM_MAX_VCPU_IDS. -EFAULT Invalid user pointer for attr->addr. -EBUSY A vcpu is already connected to the device. ==== =====================
Documentation/virt/kvm/devices/xive.rst +1 -1
@@ -91,7 +91,7 @@ the legacy interrupt mode, referred as XICS (POWER7/8). Errors: ==== ===================== - -EINVAL Value greater than KVM_MAX_VCPU_ID. + -EINVAL Value greater than KVM_MAX_VCPU_IDS. -EFAULT Invalid user pointer for attr->addr. -EBUSY A vCPU is already connected to the device. ==== =====================
arch/mips/kvm/mips.c +1 -1
@@ -1073,7 +1073,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) r =KVM_MAX_VCPUS ;break ;case KVM_CAP_MAX_VCPU_ID : - r =KVM_MAX_VCPU_ID ; + r =KVM_MAX_VCPU_IDS ;break ;case KVM_CAP_MIPS_FPU :/* We don't handle systems with inconsistent cpu_has_fpu */
arch/powerpc/include/asm/kvm_book3s.h +1 -1
@@ -434,7 +434,7 @@ extern int kvmppc_h_logical_ci_store(struct kvm_vcpu *vcpu);#define SPLIT_HACK_OFFS 0xfb000000/* -* This packs a VCPU ID from the [0..KVM_MAX_VCPU_ID) space down to the +* This packs a VCPU ID from the [0..KVM_MAX_VCPU_IDS) space down to the * [0..KVM_MAX_VCPUS) space, using knowledge of the guest's core stride * (but not its actual threading mode, which is not available) to avoid * collisions.
arch/powerpc/include/asm/kvm_host.h +2 -2
@@ -33,11 +33,11 @@#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE #include <asm/kvm_book3s_asm.h> /* for MAX_SMT_THREADS */ -#define KVM_MAX_VCPU_ID (MAX_SMT_THREADS * KVM_MAX_VCORES) +#define KVM_MAX_VCPU_IDS (MAX_SMT_THREADS * KVM_MAX_VCORES)#define KVM_MAX_NESTED_GUESTS KVMPPC_NR_LPIDS#else -#define KVM_MAX_VCPU_ID KVM_MAX_VCPUS +#define KVM_MAX_VCPU_IDS KVM_MAX_VCPUS#endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */ #define __KVM_HAVE_ARCH_INTC_INITIALIZED
arch/powerpc/kvm/book3s_xive.c +1 -1
@@ -1928,7 +1928,7 @@ int kvmppc_xive_set_nr_servers(struct kvmppc_xive *xive, u64 addr)pr_devel ("%s nr_servers=%u\n" , __func__, nr_servers); -if (!nr_servers || nr_servers >KVM_MAX_VCPU_ID ) +if (!nr_servers || nr_servers >KVM_MAX_VCPU_IDS )return -EINVAL ;mutex_lock (&xive->lock);
arch/powerpc/kvm/powerpc.c +1 -1
@@ -649,7 +649,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) r =KVM_MAX_VCPUS ;break ;case KVM_CAP_MAX_VCPU_ID : - r =KVM_MAX_VCPU_ID ; + r =KVM_MAX_VCPU_IDS ;break ;#ifdef CONFIG_PPC_BOOK3S_64 case KVM_CAP_PPC_GET_SMMU_INFO :
arch/x86/include/asm/kvm_host.h +1 -1
@@ -50,7 +50,7 @@* so ratio of 4 should be enough. */ #define KVM_VCPU_ID_RATIO 4 -#define KVM_MAX_VCPU_ID (KVM_MAX_VCPUS * KVM_VCPU_ID_RATIO) +#define KVM_MAX_VCPU_IDS (KVM_MAX_VCPUS * KVM_VCPU_ID_RATIO)/* memory slots that are not exposed to userspace */ #define KVM_PRIVATE_MEM_SLOTS 3
arch/x86/kvm/ioapic.c +1 -1
@@ -96,7 +96,7 @@ static unsigned long ioapic_read_indirect(struct kvm_ioapic *ioapic,static void rtc_irq_eoi_tracking_reset (struct kvm_ioapic *ioapic) { ioapic->rtc_status.pending_eoi =0 ; -bitmap_zero (ioapic->rtc_status.dest_map.map,KVM_MAX_VCPU_ID ); +bitmap_zero (ioapic->rtc_status.dest_map.map,KVM_MAX_VCPU_IDS ); }static void kvm_rtc_eoi_tracking_restore_all (struct kvm_ioapic *ioapic);
arch/x86/kvm/ioapic.h +2 -2
@@ -39,13 +39,13 @@ struct kvm_vcpu;struct dest_map {/* vcpu bitmap where IRQ has been sent */ - DECLARE_BITMAP(map, KVM_MAX_VCPU_ID); + DECLARE_BITMAP(map, KVM_MAX_VCPU_IDS);/* * Vector sent to a given vcpu, only valid when * the vcpu's bit in map is set */ -u8 vectors[KVM_MAX_VCPU_ID ]; +u8 vectors[KVM_MAX_VCPU_IDS ]; };
arch/x86/kvm/x86.c +1 -1
@@ -4070,7 +4070,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) r =KVM_MAX_VCPUS ;break ;case KVM_CAP_MAX_VCPU_ID : - r =KVM_MAX_VCPU_ID ; + r =KVM_MAX_VCPU_IDS ;break ;case KVM_CAP_PV_MMU :/* obsolete */ r =0 ;
include/linux/kvm_host.h +2 -2
@@ -39,8 +39,8 @@#include <asm/kvm_host.h> #include <linux/kvm_dirty_ring.h> -#ifndef KVM_MAX_VCPU_ID -#define KVM_MAX_VCPU_ID KVM_MAX_VCPUS +#ifndef KVM_MAX_VCPU_IDS +#define KVM_MAX_VCPU_IDS KVM_MAX_VCPUS#endif /*
tools/testing/selftests/kvm/kvm_create_max_vcpus.c +1 -1
@@ -53,7 +53,7 @@ int main(int argc, char *argv[]) kvm_max_vcpu_id = kvm_max_vcpus;TEST_ASSERT (kvm_max_vcpu_id >= kvm_max_vcpus, -"KVM_MAX_VCPU_ID (%d) must be at least as large as KVM_MAX_VCPUS (%d)." , +"KVM_MAX_VCPU_IDS (%d) must be at least as large as KVM_MAX_VCPUS (%d)." , kvm_max_vcpu_id, kvm_max_vcpus);test_vcpu_creation (0 , kvm_max_vcpus);
virt/kvm/kvm_main.c +1 -1
@@ -3557,7 +3557,7 @@ static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, u32 id)struct kvm_vcpu *vcpu;struct page *page; -if (id >=KVM_MAX_VCPU_ID ) +if (id >=KVM_MAX_VCPU_IDS )return -EINVAL ;mutex_lock (&kvm->lock);
Signature · 1 line
2.26.2
Sean Christopherson
maintainerRe: [PATCH 2/2] kvm: rename KVM_MAX_VCPU_ID to KVM_MAX_VCPU_IDS
Quoted 4 lines · Juergen Gross
KVM_MAX_VCPU_IDis not specifying the highest allowed vcpu-id, but the number of allowed vcpu-ids. This has already led to confusion, so renameKVM_MAX_VCPU_IDtoKVM_MAX_VCPU_IDSto make its semantics more clear
My hesitation with this rename is that the max _number_ of IDs is not the same thing as the max allowed ID. E.g. on x86, given a capability that enumerates the max number of IDs, I would expect to be able to create vCPUs with arbitrary 32-bit x2APIC IDs so long as the total number of IDs is below the max.
Re: [PATCH 2/2] kvm: rename KVM_MAX_VCPU_ID to KVM_MAX_VCPU_IDS
Quoted 7 lines · Sean Christopherson
Quoted 4 lines · Juergen Gross
KVM_MAX_VCPU_IDis not specifying the highest allowed vcpu-id, but the number of allowed vcpu-ids. This has already led to confusion, so renameKVM_MAX_VCPU_IDtoKVM_MAX_VCPU_IDSto make its semantics more clear
Quoted 5 lines
My hesitation with this rename is that the max _number_ of IDs is not the same thing as the max allowed ID. E.g. on x86, given a capability that enumerates the max number of IDs, I would expect to be able to create vCPUs with arbitrary 32-bit x2APIC IDs so long as the total number of IDs is below the max.
What name would you suggest instead? KVM_VCPU_ID_LIMIT, maybe?
I'm assuming we are not going to redefine KVM_MAX_VCPU_ID to be an inclusive limit.
--
Eduardo
Sean Christopherson
maintainerRe: [PATCH 2/2] kvm: rename KVM_MAX_VCPU_ID to KVM_MAX_VCPU_IDS
Quoted 14 lines · Eduardo Habkost
Quoted 7 lines · Sean Christopherson
Quoted 4 lines · Juergen Gross
KVM_MAX_VCPU_IDis not specifying the highest allowed vcpu-id, but the number of allowed vcpu-ids. This has already led to confusion, so renameKVM_MAX_VCPU_IDtoKVM_MAX_VCPU_IDSto make its semantics more clearQuoted 5 lines
My hesitation with this rename is that the max _number_ of IDs is not the same thing as the max allowed ID. E.g. on x86, given a capability that enumerates the max number of IDs, I would expect to be able to create vCPUs with arbitrary 32-bit x2APIC IDs so long as the total number of IDs is below the max.
Quoted 4 lines
What name would you suggest instead?
KVM_VCPU_ID_LIMIT, maybe?I'm assuming we are not going to redefine
KVM_MAX_VCPU_IDto be an inclusive limit.
Heh, I haven't been able to come up with one, which is why I suggested the route of making it an inclusive value internally within KVM.
Quoted 8 lines · Juergen Gross
Revert commit
76b4f357d0e7d8f6f00which was based on wrong reasoning and renameKVM_MAX_VCPU_IDtoKVM_MAX_VCPU_IDSin order to avoid the same issue in future.Juergen Gross (2):
x86/kvm: revert commit76b4f357d0e7d8f6f00
kvm: renameKVM_MAX_VCPU_IDtoKVM_MAX_VCPU_IDS
Quoted 16 lines
Documentation/virt/kvm/devices/xics.rst | 2 +- Documentation/virt/kvm/devices/xive.rst | 2 +- arch/mips/kvm/mips.c | 2 +- arch/powerpc/include/asm/kvm_book3s.h | 2 +- arch/powerpc/include/asm/kvm_host.h | 4 ++-- arch/powerpc/kvm/book3s_xive.c | 2 +- arch/powerpc/kvm/powerpc.c | 2 +- arch/x86/include/asm/kvm_host.h | 2 +- arch/x86/kvm/ioapic.c | 2 +- arch/x86/kvm/ioapic.h | 4 ++-- arch/x86/kvm/x86.c | 2 +- include/linux/kvm_host.h | 4 ++-- tools/testing/selftests/kvm/kvm_create_max_vcpus.c | 2 +- virt/kvm/kvm_main.c | 2 +- 14 files changed, 17 insertions(+), 17 deletions(-)
Queued, thanks.
Paolo