From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751414AbcISLW3 (ORCPT ); Mon, 19 Sep 2016 07:22:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53558 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751702AbcISLWR (ORCPT ); Mon, 19 Sep 2016 07:22:17 -0400 Subject: Re: [PATCH] kvm: svm: fix unsigned compare less than zero comparison To: Colin King , Joerg Roedel , =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , Thomas Gleixner , Ingo Molnar , "H . Peter Anvin" , x86@kernel.org, kvm@vger.kernel.org References: <20160919061159.6341-1-colin.king@canonical.com> Cc: linux-kernel@vger.kernel.org From: Paolo Bonzini Message-ID: <4f08b5ad-766f-108f-654e-3402fd2caf9c@redhat.com> Date: Mon, 19 Sep 2016 13:22:12 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: <20160919061159.6341-1-colin.king@canonical.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 19 Sep 2016 11:22:16 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 19/09/2016 08:11, Colin King wrote: > From: Colin Ian King > > 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 > --- > 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