From mboxrd@z Thu Jan 1 00:00:00 1970 From: Paolo Bonzini Subject: Re: [PATCH 4/5] KVM: x86: fix check legal type of Variable Range MTRRs Date: Mon, 18 Aug 2014 12:28:19 +0200 Message-ID: <53F1D543.4060700@redhat.com> References: <1408355431-115633-1-git-send-email-wanpeng.li@linux.intel.com> <1408355431-115633-4-git-send-email-wanpeng.li@linux.intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit Cc: Gleb Natapov , hpa@zytor.com, x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org To: Wanpeng Li Return-path: Received: from mx1.redhat.com ([209.132.183.28]:40335 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751014AbaHRK20 (ORCPT ); Mon, 18 Aug 2014 06:28:26 -0400 In-Reply-To: <1408355431-115633-4-git-send-email-wanpeng.li@linux.intel.com> Sender: kvm-owner@vger.kernel.org List-ID: Il 18/08/2014 11:50, Wanpeng Li ha scritto: > + if (msr >= 0x200 && msr < 0x200 + 2 * KVM_NR_VAR_MTRR) { This should be a WARN_ON, and the base/mask can be separated just with an "&". WARN_ON(!(msr >= 0x200 && msr < 0x200 + 2 * KVM_NR_VAR_MTRR)); if ((msr & 1) == 0) /* MTRR base */ return valid_mtrr_type(data & 0xff); /* MTRR mask */ return true; Please provide a unit test for this patch and for patch 1. Paolo > + int idx, is_mtrr_mask; > + > + idx = (msr - 0x200) / 2; > + is_mtrr_mask = msr - 0x200 - 2 * idx; > + if (!is_mtrr_mask) > + return valid_mtrr_type(data & 0xff); > + } > + return true; > }