From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Cooper Subject: Re: [V2 PATCH 6/9] x86/hvm: pkeys, add functions to support PKRU access Date: Tue, 1 Dec 2015 20:12:30 +0000 Message-ID: <565DFF2E.9010506@citrix.com> References: <1448617923-10884-1-git-send-email-huaitong.han@intel.com> <1448617923-10884-7-git-send-email-huaitong.han@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1448617923-10884-7-git-send-email-huaitong.han@intel.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Huaitong Han , jbeulich@suse.com Cc: xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org On 27/11/15 09:52, Huaitong Han wrote: > This patch adds functions to support PKRU access. > > Signed-off-by: Huaitong Han > --- > xen/include/asm-x86/processor.h | 15 +++++++++++++++ > 1 file changed, 15 insertions(+) > > diff --git a/xen/include/asm-x86/processor.h b/xen/include/asm-x86/processor.h > index 3f8411f..68d86cb 100644 > --- a/xen/include/asm-x86/processor.h > +++ b/xen/include/asm-x86/processor.h > @@ -342,6 +342,21 @@ static inline void write_cr4(unsigned long val) > asm volatile ( "mov %0,%%cr4" : : "r" (val) ); > } > > +/* Macros for PKRU domain */ > +#define PKRU_READ 0 > +#define PKRU_WRITE 1 > +#define PKRU_ATTRS 2 > + > +/* > + * PKRU defines 32 bits, there are 16 domains and 2 attribute bits per > + * domain in pkru, pkeys is index to a defined domain, so the value of > + * pte_pkeys * PKRU_ATTRS + R/W is offset of a defined domain attribute. > + */ > +#define READ_PKRU_AD(pkru, pkey) \ > + ((pkru >> (pkey * PKRU_ATTRS + PKRU_READ)) & 1) > +#define READ_PKRU_WD(pkru, pkey) \ > + ((pkru >> (pkey * PKRU_ATTRS + PKRU_WRITE)) & 1) Both macro parameters need quoting, but these would be better still as static inline functions. ~Andrew