From: "Jan Beulich" Subject: Re: [PATCH v12 3/9] tools: provide interface for generic MSR access Date: Thu, 24 Jul 2014 07:56:00 +0100 Message-ID: <53D0CA2002000078000255BE@mail.emea.novell.com> References: <0d7bc552dae05a8756f6ff77234b9b040c6d74af.1404462280.git.dongxiao.xu@intel.com> <53B6AF2C0200007800020B1E@mail.emea.novell.com> <1404925108.26217.9.camel@hastur.hellion.org.uk> <53CF85050200007800024F57@mail.emea.novell.com> <40776A41FC278F40B59438AD47D147A911A751F9@SHSMSX104.ccr.corp.intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <40776A41FC278F40B59438AD47D147A911A751F9@SHSMSX104.ccr.corp.intel.com> Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Dongxiao Xu Cc: "keir@xen.org" , Ian Campbell , "stefano.stabellini@eu.citrix.com" , "George.Dunlap@eu.citrix.com" , "andrew.cooper3@citrix.com" , "Ian.Jackson@eu.citrix.com" , "xen-devel@lists.xen.org" , "dgdegra@tycho.nsa.gov" List-Id: xen-devel@lists.xenproject.org >>> On 24.07.14 at 08:31, wrote: > Considering many people in the list requires the white-list style to limit > the capability for resource access (e.g. MSR read/write), so I implement such > a white-list in my new version patch like following: > Does it look reasonable to you? Reasonable - perhaps. Efficiently coded - no: > static unsigned int allowed_msr_list[] = { > MSR_IA32_QOSEVTSEL, > MSR_IA32_QMC, > }; > > static unsigned int allow_access(unsigned int idx, unsigned int *list, unsigned int nr) > { > unsigned int i; > > for ( i = 0; i < nr; i++ ) > if ( list[i] == idx ) > return 1; Using a big switch allows the compiler to (hopefully) find an optimal translation - possibly via lookup table, but maybe via other means. And if you were to stay with the explicit lookup table, you'd have to fix various mechanical issues (but I take this only as a sketch, not as something you're proposing as is). That said I continue to not be fully convinced of the need of a white or black list here, not the least with the consideration in mind of extending this to port I/O. Jan