From: Huaitong Han Subject: [V3 PATCH 5/9] x86/hvm: pkeys, add functions to support PKRU access Date: Mon, 7 Dec 2015 17:16:16 +0800 Message-ID: <1449479780-19146-6-git-send-email-huaitong.han@intel.com> References: <1449479780-19146-1-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: <1449479780-19146-1-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: jbeulich@suse.com, andrew.cooper3@citrix.com, jun.nakajima@intel.com, eddie.dong@intel.com, kevin.tian@intel.com, george.dunlap@eu.citrix.com, ian.jackson@eu.citrix.com, stefano.stabellini@eu.citrix.com, ian.campbell@citrix.com, wei.liu2@citrix.com, keir@xen.org Cc: Huaitong Han , xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org This patch adds functions to support PKRU access. Signed-off-by: Huaitong Han --- xen/include/asm-x86/processor.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/xen/include/asm-x86/processor.h b/xen/include/asm-x86/processor.h index 3f8411f..c345787 100644 --- a/xen/include/asm-x86/processor.h +++ b/xen/include/asm-x86/processor.h @@ -342,6 +342,26 @@ 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. + */ +static inline bool_t read_pkru_ad(unsigned int pkru, unsigned int pkey) +{ + return (pkru >> (pkey * PKRU_ATTRS + PKRU_READ)) & 1; +} + +static inline bool_t read_pkru_wd(unsigned int pkru, unsigned int pkey) +{ + return (pkru >> (pkey * PKRU_ATTRS + PKRU_WRITE)) & 1; +} + /* Clear and set 'TS' bit respectively */ static inline void clts(void) { -- 2.4.3