KVM Archive on lore.kernel.org
 help / color / Atom feed
* [RFC PATCH] KVM: SVM: Disallow SEV if NPT is disabled
@ 2020-07-31 20:51 Sean Christopherson
  2020-08-04 15:16 ` Brijesh Singh
  0 siblings, 1 reply; 2+ messages in thread
From: Sean Christopherson @ 2020-07-31 20:51 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
	Joerg Roedel, kvm, linux-kernel, Tom Lendacky, Brijesh Singh

Forcefully turn off SEV if NPT is disabled, e.g. via module param.  SEV
requires NPT as the C-bit only exists if NPT is active.

Fixes: e9df09428996f ("KVM: SVM: Add sev module_param")
Cc: stable@vger.kernel.org
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Cc: Brijesh Singh <brijesh.singh@amd.com>
Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
---

RFC as it's entirely possible that I am completely misunderstanding how
SEV works.  Compile tested only.

 arch/x86/kvm/svm/svm.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
index 783330d0e7b88..e30629593458b 100644
--- a/arch/x86/kvm/svm/svm.c
+++ b/arch/x86/kvm/svm/svm.c
@@ -860,8 +860,14 @@ static __init int svm_hardware_setup(void)
 		kvm_enable_efer_bits(EFER_SVME | EFER_LMSLE);
 	}
 
+	if (!boot_cpu_has(X86_FEATURE_NPT))
+		npt_enabled = false;
+
+	if (npt_enabled && !npt)
+		npt_enabled = false;
+
 	if (sev) {
-		if (boot_cpu_has(X86_FEATURE_SEV) &&
+		if (boot_cpu_has(X86_FEATURE_SEV) && npt_enabled &&
 		    IS_ENABLED(CONFIG_KVM_AMD_SEV)) {
 			r = sev_hardware_setup();
 			if (r)
@@ -879,12 +885,6 @@ static __init int svm_hardware_setup(void)
 			goto err;
 	}
 
-	if (!boot_cpu_has(X86_FEATURE_NPT))
-		npt_enabled = false;
-
-	if (npt_enabled && !npt)
-		npt_enabled = false;
-
 	kvm_configure_mmu(npt_enabled, PG_LEVEL_1G);
 	pr_info("kvm: Nested Paging %sabled\n", npt_enabled ? "en" : "dis");
 
-- 
2.28.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [RFC PATCH] KVM: SVM: Disallow SEV if NPT is disabled
  2020-07-31 20:51 [RFC PATCH] KVM: SVM: Disallow SEV if NPT is disabled Sean Christopherson
@ 2020-08-04 15:16 ` Brijesh Singh
  0 siblings, 0 replies; 2+ messages in thread
From: Brijesh Singh @ 2020-08-04 15:16 UTC (permalink / raw)
  To: Sean Christopherson, Paolo Bonzini
  Cc: brijesh.singh, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
	Joerg Roedel, kvm, linux-kernel, Tom Lendacky


On 7/31/20 3:51 PM, Sean Christopherson wrote:
> Forcefully turn off SEV if NPT is disabled, e.g. via module param.  SEV
> requires NPT as the C-bit only exists if NPT is active.
>
> Fixes: e9df09428996f ("KVM: SVM: Add sev module_param")
> Cc: stable@vger.kernel.org
> Cc: Tom Lendacky <thomas.lendacky@amd.com>
> Cc: Brijesh Singh <brijesh.singh@amd.com>
> Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
> ---
>
> RFC as it's entirely possible that I am completely misunderstanding how
> SEV works.  Compile tested only.


Reviewed-By: Brijesh Singh <brijesh.singh@amd.com>


>
>  arch/x86/kvm/svm/svm.c | 14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
> index 783330d0e7b88..e30629593458b 100644
> --- a/arch/x86/kvm/svm/svm.c
> +++ b/arch/x86/kvm/svm/svm.c
> @@ -860,8 +860,14 @@ static __init int svm_hardware_setup(void)
>  		kvm_enable_efer_bits(EFER_SVME | EFER_LMSLE);
>  	}
>  
> +	if (!boot_cpu_has(X86_FEATURE_NPT))
> +		npt_enabled = false;
> +
> +	if (npt_enabled && !npt)
> +		npt_enabled = false;
> +
>  	if (sev) {
> -		if (boot_cpu_has(X86_FEATURE_SEV) &&
> +		if (boot_cpu_has(X86_FEATURE_SEV) && npt_enabled &&
>  		    IS_ENABLED(CONFIG_KVM_AMD_SEV)) {
>  			r = sev_hardware_setup();
>  			if (r)
> @@ -879,12 +885,6 @@ static __init int svm_hardware_setup(void)
>  			goto err;
>  	}
>  
> -	if (!boot_cpu_has(X86_FEATURE_NPT))
> -		npt_enabled = false;
> -
> -	if (npt_enabled && !npt)
> -		npt_enabled = false;
> -
>  	kvm_configure_mmu(npt_enabled, PG_LEVEL_1G);
>  	pr_info("kvm: Nested Paging %sabled\n", npt_enabled ? "en" : "dis");
>  

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-31 20:51 [RFC PATCH] KVM: SVM: Disallow SEV if NPT is disabled Sean Christopherson
2020-08-04 15:16 ` Brijesh Singh

KVM Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/kvm/0 kvm/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 kvm kvm/ https://lore.kernel.org/kvm \
		kvm@vger.kernel.org
	public-inbox-index kvm

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.kvm


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git