* [PATCH v2] KVM: x86: Assign correct value to array.maxnent
@ 2020-06-04 4:16 Xiaoyao Li
2020-06-04 15:12 ` Sean Christopherson
0 siblings, 1 reply; 3+ messages in thread
From: Xiaoyao Li @ 2020-06-04 4:16 UTC (permalink / raw)
To: Sean Christopherson, Paolo Bonzini; +Cc: kvm, linux-kernel, Xiaoyao Li
Delay the assignment of array.maxnent to use correct value for the case
cpuid->nent > KVM_MAX_CPUID_ENTRIES.
Fixes: e53c95e8d41e ("KVM: x86: Encapsulate CPUID entries and metadata in struct")
Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
---
v2:
- remove "const" of maxnent to fix build error.
---
arch/x86/kvm/cpuid.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index 253b8e875ccd..3d88ddf781d0 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -426,7 +426,7 @@ EXPORT_SYMBOL_GPL(kvm_set_cpu_caps);
struct kvm_cpuid_array {
struct kvm_cpuid_entry2 *entries;
- const int maxnent;
+ int maxnent;
int nent;
};
@@ -870,7 +870,6 @@ int kvm_dev_ioctl_get_cpuid(struct kvm_cpuid2 *cpuid,
struct kvm_cpuid_array array = {
.nent = 0,
- .maxnent = cpuid->nent,
};
int r, i;
@@ -887,6 +886,8 @@ int kvm_dev_ioctl_get_cpuid(struct kvm_cpuid2 *cpuid,
if (!array.entries)
return -ENOMEM;
+ array.maxnent = cpuid->nent;
+
for (i = 0; i < ARRAY_SIZE(funcs); i++) {
r = get_cpuid_func(&array, funcs[i], type);
if (r)
--
2.18.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] KVM: x86: Assign correct value to array.maxnent
2020-06-04 4:16 [PATCH v2] KVM: x86: Assign correct value to array.maxnent Xiaoyao Li
@ 2020-06-04 15:12 ` Sean Christopherson
2020-06-04 16:21 ` Paolo Bonzini
0 siblings, 1 reply; 3+ messages in thread
From: Sean Christopherson @ 2020-06-04 15:12 UTC (permalink / raw)
To: 20200604024304.14643-1-xiaoyao.li
Cc: Paolo Bonzini, kvm, linux-kernel, Xiaoyao Li
On Thu, Jun 04, 2020 at 12:16:36PM +0800, Xiaoyao Li wrote:
> Delay the assignment of array.maxnent to use correct value for the case
> cpuid->nent > KVM_MAX_CPUID_ENTRIES.
>
> Fixes: e53c95e8d41e ("KVM: x86: Encapsulate CPUID entries and metadata in struct")
> Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
> ---
> v2:
> - remove "const" of maxnent to fix build error.
> ---
> arch/x86/kvm/cpuid.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
> index 253b8e875ccd..3d88ddf781d0 100644
> --- a/arch/x86/kvm/cpuid.c
> +++ b/arch/x86/kvm/cpuid.c
> @@ -426,7 +426,7 @@ EXPORT_SYMBOL_GPL(kvm_set_cpu_caps);
>
> struct kvm_cpuid_array {
> struct kvm_cpuid_entry2 *entries;
> - const int maxnent;
> + int maxnent;
> int nent;
> };
>
> @@ -870,7 +870,6 @@ int kvm_dev_ioctl_get_cpuid(struct kvm_cpuid2 *cpuid,
>
> struct kvm_cpuid_array array = {
> .nent = 0,
> - .maxnent = cpuid->nent,
> };
> int r, i;
>
> @@ -887,6 +886,8 @@ int kvm_dev_ioctl_get_cpuid(struct kvm_cpuid2 *cpuid,
> if (!array.entries)
> return -ENOMEM;
>
> + array.maxnent = cpuid->nent;
Eh, I'd vote to just do:
diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index 253b8e875ccd..1e5b1ee75a76 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -870,7 +870,7 @@ int kvm_dev_ioctl_get_cpuid(struct kvm_cpuid2 *cpuid,
struct kvm_cpuid_array array = {
.nent = 0,
- .maxnent = cpuid->nent,
+ .maxnent = min(cpuid->nent, (u32)KVM_MAX_CPUID_ENTRIES),
};
int r, i;
> +
> for (i = 0; i < ARRAY_SIZE(funcs); i++) {
> r = get_cpuid_func(&array, funcs[i], type);
> if (r)
> --
> 2.18.2
>
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] KVM: x86: Assign correct value to array.maxnent
2020-06-04 15:12 ` Sean Christopherson
@ 2020-06-04 16:21 ` Paolo Bonzini
0 siblings, 0 replies; 3+ messages in thread
From: Paolo Bonzini @ 2020-06-04 16:21 UTC (permalink / raw)
To: Sean Christopherson; +Cc: kvm, linux-kernel, Xiaoyao Li
On 04/06/20 17:12, Sean Christopherson wrote:
> On Thu, Jun 04, 2020 at 12:16:36PM +0800, Xiaoyao Li wrote:
>> Delay the assignment of array.maxnent to use correct value for the case
>> cpuid->nent > KVM_MAX_CPUID_ENTRIES.
>>
>> Fixes: e53c95e8d41e ("KVM: x86: Encapsulate CPUID entries and metadata in struct")
>> Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
>> ---
>> v2:
>> - remove "const" of maxnent to fix build error.
>> ---
>> arch/x86/kvm/cpuid.c | 5 +++--
>> 1 file changed, 3 insertions(+), 2 deletions(-)
>>
>> diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
>> index 253b8e875ccd..3d88ddf781d0 100644
>> --- a/arch/x86/kvm/cpuid.c
>> +++ b/arch/x86/kvm/cpuid.c
>> @@ -426,7 +426,7 @@ EXPORT_SYMBOL_GPL(kvm_set_cpu_caps);
>>
>> struct kvm_cpuid_array {
>> struct kvm_cpuid_entry2 *entries;
>> - const int maxnent;
>> + int maxnent;
>> int nent;
>> };
>>
>> @@ -870,7 +870,6 @@ int kvm_dev_ioctl_get_cpuid(struct kvm_cpuid2 *cpuid,
>>
>> struct kvm_cpuid_array array = {
>> .nent = 0,
>> - .maxnent = cpuid->nent,
>> };
>> int r, i;
>>
>> @@ -887,6 +886,8 @@ int kvm_dev_ioctl_get_cpuid(struct kvm_cpuid2 *cpuid,
>> if (!array.entries)
>> return -ENOMEM;
>>
>> + array.maxnent = cpuid->nent;
>
> Eh, I'd vote to just do:
>
> diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
> index 253b8e875ccd..1e5b1ee75a76 100644
> --- a/arch/x86/kvm/cpuid.c
> +++ b/arch/x86/kvm/cpuid.c
> @@ -870,7 +870,7 @@ int kvm_dev_ioctl_get_cpuid(struct kvm_cpuid2 *cpuid,
>
> struct kvm_cpuid_array array = {
> .nent = 0,
> - .maxnent = cpuid->nent,
> + .maxnent = min(cpuid->nent, (u32)KVM_MAX_CPUID_ENTRIES),
> };
> int r, i;
>
Both are fine, I've queued Xiaoyao's patch.
Paolo
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-06-04 16:22 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-04 4:16 [PATCH v2] KVM: x86: Assign correct value to array.maxnent Xiaoyao Li
2020-06-04 15:12 ` Sean Christopherson
2020-06-04 16:21 ` Paolo Bonzini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).