All of lore.kernel.org
 help / color / mirror / Atom feed
From: Huaitong Han <huaitong.han@intel.com>
To: pbonzini@redhat.com, gleb@kernel.org
Cc: kvm@vger.kernel.org, Huaitong Han <huaitong.han@intel.com>
Subject: [PATCH V2 2/7] KVM, pkeys: disable pkeys for guests in non-paging mode
Date: Mon, 16 Nov 2015 15:51:46 +0800	[thread overview]
Message-ID: <1447660311-12003-3-git-send-email-huaitong.han@intel.com> (raw)
In-Reply-To: <1447660311-12003-1-git-send-email-huaitong.han@intel.com>

Pkeys is disabled if CPU is in non-paging mode in hardware. However KVM
always uses paging mode to emulate guest non-paging, mode with TDP. To
emulate this behavior, pkeys needs to be manually disabled when guest
switches to non-paging mode.

Signed-off-by: Huaitong Han <huaitong.han@intel.com>

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index d019868..9b12c80 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -3645,14 +3645,14 @@ static int vmx_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)
 			hw_cr4 &= ~X86_CR4_PAE;
 			hw_cr4 |= X86_CR4_PSE;
 			/*
-			 * SMEP/SMAP is disabled if CPU is in non-paging mode
-			 * in hardware. However KVM always uses paging mode to
-			 * emulate guest non-paging mode with TDP.
-			 * To emulate this behavior, SMEP/SMAP needs to be
+			 * SMEP/SMAP/PKU is disabled if CPU is in non-paging
+			 * mode in hardware. However KVM always uses paging
+			 * mode to emulate guest non-paging mode with TDP.
+			 * To emulate this behavior, SMEP/SMAP/PKU needs to be
 			 * manually disabled when guest switches to non-paging
 			 * mode.
 			 */
-			hw_cr4 &= ~(X86_CR4_SMEP | X86_CR4_SMAP);
+			hw_cr4 &= ~(X86_CR4_SMEP | X86_CR4_SMAP | X86_CR4_PKE);
 		} else if (!(cr4 & X86_CR4_PAE)) {
 			hw_cr4 &= ~X86_CR4_PAE;
 		}
-- 
2.4.3


  parent reply	other threads:[~2015-11-16  7:52 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-16  7:51 [PATCH V2 0/7] KVM, pkeys: add memory protection-key support Huaitong Han
2015-11-16  7:51 ` [PATCH V2 1/7] KVM, pkeys: expose CPUID/CR4 to guest Huaitong Han
2015-11-16  7:51 ` Huaitong Han [this message]
2015-11-16  7:51 ` [PATCH V2 3/7] KVM, pkeys: update memeory permission bitmask for pkeys Huaitong Han
2015-11-16  7:51 ` [PATCH V2 4/7] KVM, pkeys: add pkeys support for permission_fault logic Huaitong Han
2015-11-16  7:51 ` [PATCH V2 5/7] KVM, pkeys: Add pkeys support for gva_to_gpa funcions Huaitong Han
2015-11-16  7:51 ` [PATCH V2 6/7] KVM, pkeys: add pkeys support for xsave state Huaitong Han
2015-11-16  7:51 ` [PATCH V2 7/7] KVM, pkeys: disable PKU feature without ept Huaitong Han
2015-11-16  9:20   ` Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1447660311-12003-3-git-send-email-huaitong.han@intel.com \
    --to=huaitong.han@intel.com \
    --cc=gleb@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.