From patchwork Tue Jan 19 07:30:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Huaitong Han X-Patchwork-Id: 8058661 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 62552BEEE5 for ; Tue, 19 Jan 2016 07:34:07 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 74CD3203F3 for ; Tue, 19 Jan 2016 07:34:06 +0000 (UTC) Received: from lists.xen.org (lists.xenproject.org [50.57.142.19]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A3FD320411 for ; Tue, 19 Jan 2016 07:34:05 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aLQkz-0003DF-6z; Tue, 19 Jan 2016 07:31:13 +0000 Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aLQkx-0003Cz-8y for xen-devel@lists.xen.org; Tue, 19 Jan 2016 07:31:11 +0000 Received: from [85.158.143.35] by server-2.bemta-4.messagelabs.com id 3E/C8-08977-F36ED965; Tue, 19 Jan 2016 07:31:11 +0000 X-Env-Sender: huaitong.han@intel.com X-Msg-Ref: server-13.tower-21.messagelabs.com!1453188668!9208820!2 X-Originating-IP: [192.55.52.88] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTkyLjU1LjUyLjg4ID0+IDM3NDcyNQ==\n X-StarScan-Received: X-StarScan-Version: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 10666 invoked from network); 19 Jan 2016 07:31:10 -0000 Received: from mga01.intel.com (HELO mga01.intel.com) (192.55.52.88) by server-13.tower-21.messagelabs.com with SMTP; 19 Jan 2016 07:31:10 -0000 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP; 18 Jan 2016 23:31:09 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.22,316,1449561600"; d="scan'208";a="884417808" Received: from huaitong-desk.bj.intel.com ([10.238.135.58]) by fmsmga001.fm.intel.com with ESMTP; 18 Jan 2016 23:31:08 -0800 From: Huaitong Han To: jbeulich@suse.com, andrew.cooper3@citrix.com, george.dunlap@eu.citrix.com, wei.liu2@citrix.com, keir@xen.org Date: Tue, 19 Jan 2016 15:30:55 +0800 Message-Id: <1453188659-8908-2-git-send-email-huaitong.han@intel.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1453188659-8908-1-git-send-email-huaitong.han@intel.com> References: <1453188659-8908-1-git-send-email-huaitong.han@intel.com> Cc: Huaitong Han , xen-devel@lists.xen.org Subject: [Xen-devel] [PATCH V6 1/5] x86/hvm: pkeys, disable pkeys for guests in non-paging mode X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch disables pkeys for guest in non-paging mode, However XEN always uses paging mode to emulate guest non-paging mode, To emulate this behavior, pkeys needs to be manually disabled when guest switches to non-paging mode. Signed-off-by: Huaitong Han Reviewed-by: Andrew Cooper --- xen/arch/x86/hvm/vmx/vmx.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c index b918b8a..9a8cfb5 100644 --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -1368,12 +1368,13 @@ static void vmx_update_guest_cr(struct vcpu *v, unsigned int cr) if ( !hvm_paging_enabled(v) ) { /* - * SMEP/SMAP is disabled if CPU is in non-paging mode in hardware. - * However Xen always uses paging mode to emulate guest non-paging - * mode. To emulate this behavior, SMEP/SMAP needs to be manually - * disabled when guest VCPU is in non-paging mode. + * SMEP/SMAP/PKU is disabled if CPU is in non-paging mode in + * hardware. However Xen always uses paging mode to emulate guest + * non-paging mode. To emulate this behavior, SMEP/SMAP/PKU needs + * to be manually disabled when guest VCPU is in non-paging mode. */ - v->arch.hvm_vcpu.hw_cr[4] &= ~(X86_CR4_SMEP | X86_CR4_SMAP); + v->arch.hvm_vcpu.hw_cr[4] &= + ~(X86_CR4_SMEP | X86_CR4_SMAP | X86_CR4_PKE); } __vmwrite(GUEST_CR4, v->arch.hvm_vcpu.hw_cr[4]); break;