Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1486166 > unrolled thread
| Started by | Colin King <colin.king@canonical.com> |
|---|---|
| First post | 2016-09-19 08:20 +0200 |
| Last post | 2016-09-19 13:30 +0200 |
| Articles | 3 — 3 participants |
Back to article view | Back to linux.kernel
[PATCH] kvm: svm: fix unsigned compare less than zero comparison Colin King <colin.king@canonical.com> - 2016-09-19 08:20 +0200
Re: [PATCH] kvm: svm: fix unsigned compare less than zero comparison Joerg Roedel <joro@8bytes.org> - 2016-09-19 12:10 +0200
Re: [PATCH] kvm: svm: fix unsigned compare less than zero comparison Paolo Bonzini <pbonzini@redhat.com> - 2016-09-19 13:30 +0200
| From | Colin King <colin.king@canonical.com> |
|---|---|
| Date | 2016-09-19 08:20 +0200 |
| Subject | [PATCH] kvm: svm: fix unsigned compare less than zero comparison |
| Message-ID | <sj05Q-1Oq-9@gated-at.bofh.it> |
From: Colin Ian King <colin.king@canonical.com>
vm_data->avic_vm_id is a u32, so the check for a error
return (less than zero) such as -EAGAIN from
avic_get_next_vm_id currently has no effect whatsoever.
Fix this by using a temporary int for the comparison
and assign vm_data->avic_vm_id to this. I used an explicit
u32 cast in the assignment to show why vm_data->avic_vm_id
cannot be used in the assign/compare steps.
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
arch/x86/kvm/svm.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index 1b66c5a..2ca66aa 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -1419,7 +1419,7 @@ static void avic_vm_destroy(struct kvm *kvm)
static int avic_vm_init(struct kvm *kvm)
{
unsigned long flags;
- int err = -ENOMEM;
+ int vm_id, err = -ENOMEM;
struct kvm_arch *vm_data = &kvm->arch;
struct page *p_page;
struct page *l_page;
@@ -1427,9 +1427,10 @@ static int avic_vm_init(struct kvm *kvm)
if (!avic)
return 0;
- vm_data->avic_vm_id = avic_get_next_vm_id();
- if (vm_data->avic_vm_id < 0)
- return vm_data->avic_vm_id;
+ vm_id = avic_get_next_vm_id();
+ if (vm_id < 0)
+ return vm_id;
+ vm_data->avic_vm_id = (u32)vm_id;
/* Allocating physical APIC ID table (4KB) */
p_page = alloc_page(GFP_KERNEL);
--
2.9.3
[toc] | [next] | [standalone]
| From | Joerg Roedel <joro@8bytes.org> |
|---|---|
| Date | 2016-09-19 12:10 +0200 |
| Message-ID | <sj3Gq-43G-17@gated-at.bofh.it> |
| In reply to | #1486166 |
On Mon, Sep 19, 2016 at 07:11:59AM +0100, Colin King wrote: > From: Colin Ian King <colin.king@canonical.com> > > vm_data->avic_vm_id is a u32, so the check for a error > return (less than zero) such as -EAGAIN from > avic_get_next_vm_id currently has no effect whatsoever. > Fix this by using a temporary int for the comparison > and assign vm_data->avic_vm_id to this. I used an explicit > u32 cast in the assignment to show why vm_data->avic_vm_id > cannot be used in the assign/compare steps. > > Signed-off-by: Colin Ian King <colin.king@canonical.com> Acked-by: Joerg Roedel <jroedel@suse.de>
[toc] | [prev] | [next] | [standalone]
| From | Paolo Bonzini <pbonzini@redhat.com> |
|---|---|
| Date | 2016-09-19 13:30 +0200 |
| Message-ID | <sj4VP-4O0-9@gated-at.bofh.it> |
| In reply to | #1486166 |
On 19/09/2016 08:11, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> vm_data->avic_vm_id is a u32, so the check for a error
> return (less than zero) such as -EAGAIN from
> avic_get_next_vm_id currently has no effect whatsoever.
> Fix this by using a temporary int for the comparison
> and assign vm_data->avic_vm_id to this. I used an explicit
> u32 cast in the assignment to show why vm_data->avic_vm_id
> cannot be used in the assign/compare steps.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
> arch/x86/kvm/svm.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
> index 1b66c5a..2ca66aa 100644
> --- a/arch/x86/kvm/svm.c
> +++ b/arch/x86/kvm/svm.c
> @@ -1419,7 +1419,7 @@ static void avic_vm_destroy(struct kvm *kvm)
> static int avic_vm_init(struct kvm *kvm)
> {
> unsigned long flags;
> - int err = -ENOMEM;
> + int vm_id, err = -ENOMEM;
> struct kvm_arch *vm_data = &kvm->arch;
> struct page *p_page;
> struct page *l_page;
> @@ -1427,9 +1427,10 @@ static int avic_vm_init(struct kvm *kvm)
> if (!avic)
> return 0;
>
> - vm_data->avic_vm_id = avic_get_next_vm_id();
> - if (vm_data->avic_vm_id < 0)
> - return vm_data->avic_vm_id;
> + vm_id = avic_get_next_vm_id();
> + if (vm_id < 0)
> + return vm_id;
> + vm_data->avic_vm_id = (u32)vm_id;
>
> /* Allocating physical APIC ID table (4KB) */
> p_page = alloc_page(GFP_KERNEL);
>
Applying the patch, thanks.
Paolo
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web