From mboxrd@z Thu Jan 1 00:00:00 1970 From: Avi Kivity Subject: Re: KVM: x86: verify MTRR/PAT validity Date: Thu, 18 Jun 2009 12:00:52 +0300 Message-ID: <4A3A0244.1040807@redhat.com> References: <20090616120529.GA529@amt.cnet> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: "Yang, Sheng" , kvm To: Marcelo Tosatti Return-path: Received: from mx2.redhat.com ([66.187.237.31]:37980 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751239AbZFRJA3 (ORCPT ); Thu, 18 Jun 2009 05:00:29 -0400 In-Reply-To: <20090616120529.GA529@amt.cnet> Sender: kvm-owner@vger.kernel.org List-ID: On 06/16/2009 03:05 PM, Marcelo Tosatti wrote: > Do not allow invalid MTRR/PAT values in set_msr_mtrr. > > Please review carefully. > > Signed-off-by: Marcelo Tosatti > > > +static unsigned mtrr_types[] = {0, 1, 4, 5, 6}; > +static unsigned pat_types[] = {0, 1, 4, 5, 6, 7}; > + > +static bool valid_mt(unsigned type, int len, unsigned array[len]) > +{ > + int i; > + > + for (i = 0; i< len; i++) > + if (type == array[i]) > + return true; > + > + return false; > +} > + > +#define valid_pat_type(a) valid_mt(a, ARRAY_SIZE(pat_types), pat_types) > +#define valid_mtrr_type(a) valid_mt(a, ARRAY_SIZE(mtrr_types), mtrr_types) > + > A little pointless since this is so performance-insensitive, but still: valid_pat_type(t) { return t < 8 && (1 << t) & 0xf3; /* 0, 1, 4, 5, 6, 7 */ } valid_mtrr_type(t) { return t < 8 && (1 << t) & 0x73; /* 0, 1, 4, 5, 6 */ } -- error compiling committee.c: too many arguments to function