Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753709AbbG2THR (ORCPT ); Wed, 29 Jul 2015 15:07:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56688 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751820AbbG2THP (ORCPT ); Wed, 29 Jul 2015 15:07:15 -0400 Message-ID: <1438196833.13460.63.camel@redhat.com> Subject: Re: [PATCH 2/3] KVM: MTRR: simplify kvm_mtrr_get_guest_memory_type From: Alex Williamson To: Xiao Guangrong Cc: pbonzini@redhat.com, gleb@kernel.org, mtosatti@redhat.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, bsd@redhat.com, lersek@redhat.com, jordan.l.justen@intel.com, edk2-devel@lists.sourceforge.net, Xiao Guangrong Date: Wed, 29 Jul 2015 13:07:13 -0600 In-Reply-To: <1436988356-4565-2-git-send-email-guangrong.xiao@linux.intel.com> References: <1436988356-4565-1-git-send-email-guangrong.xiao@linux.intel.com> <1436988356-4565-2-git-send-email-guangrong.xiao@linux.intel.com> Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3386 Lines: 112 Hi Paolo, Something bad happened to this patch. This is the version I provided Tested-by for: On Thu, 2015-07-16 at 03:25 +0800, Xiao Guangrong wrote: > From: Xiao Guangrong > > kvm_mtrr_get_guest_memory_type never returns -1 which is implied > in the current code since if @type = -1 (means no MTRR contains the > range), iter.partial_map must be true > > Simplify the code to indicate this fact > > Signed-off-by: Xiao Guangrong > --- > arch/x86/kvm/mtrr.c | 19 ++++++++++--------- > 1 file changed, 10 insertions(+), 9 deletions(-) > > diff --git a/arch/x86/kvm/mtrr.c b/arch/x86/kvm/mtrr.c > index e275013..9e8bf13 100644 > --- a/arch/x86/kvm/mtrr.c > +++ b/arch/x86/kvm/mtrr.c > @@ -672,15 +672,16 @@ u8 kvm_mtrr_get_guest_memory_type(struct kvm_vcpu *vcpu, gfn_t gfn) > if (iter.mtrr_disabled) > return mtrr_disabled_type(); > > - /* It is not covered by MTRRs. */ > - if (iter.partial_map) { > - /* > - * We just check one page, partially covered by MTRRs is > - * impossible. > - */ > - WARN_ON(type != -1); > - type = mtrr_default_type(mtrr_state); > - } > + /* not contained in any MTRRs. */ > + if (type == -1) > + return mtrr_default_type(mtrr_state); > + > + /* > + * We just check one page, partially covered by MTRRs is > + * impossible. > + */ > + WARN_ON(iter.partial_map); > + > return type; > } > EXPORT_SYMBOL_GPL(kvm_mtrr_get_guest_memory_type); This is the version that was committed for v4.2-rc4: commit 3e5d2fdceda172554e681b68c853bf5d08205bbf Author: Xiao Guangrong Date: Thu Jul 16 03:25:55 2015 +0800 KVM: MTRR: simplify kvm_mtrr_get_guest_memory_type kvm_mtrr_get_guest_memory_type never returns -1 which is implied in the current code since if @type = -1 (means no MTRR contains the range), iter.partial_map must be true Simplify the code to indicate this fact Signed-off-by: Xiao Guangrong Tested-by: Alex Williamson Signed-off-by: Paolo Bonzini diff --git a/arch/x86/kvm/mtrr.c b/arch/x86/kvm/mtrr.c index e275013..dc0a84a 100644 --- a/arch/x86/kvm/mtrr.c +++ b/arch/x86/kvm/mtrr.c @@ -672,15 +672,16 @@ u8 kvm_mtrr_get_guest_memory_type(struct kvm_vcpu *vcpu, gfn_t gfn) if (iter.mtrr_disabled) return mtrr_disabled_type(); - /* It is not covered by MTRRs. */ - if (iter.partial_map) { - /* - * We just check one page, partially covered by MTRRs is - * impossible. - */ - WARN_ON(type != -1); - type = mtrr_default_type(mtrr_state); - } + /* + * We just check one page, partially covered by MTRRs is + * impossible. + */ + WARN_ON(iter.partial_map); + + /* not contained in any MTRRs. */ + if (type == -1) + return mtrr_default_type(mtrr_state); + return type; } EXPORT_SYMBOL_GPL(kvm_mtrr_get_guest_memory_type); The WARN_ON() now comes before the type == -1 test and I hit that at *very* high frequency when trying to test device assignment. Restoring the ordering to what Xiao originally proposed resolves the problem. Thanks, Alex -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/