diff mbox

[Part2,v7,33/38] KVM: SVM: Add support for SEV DEBUG_ENCRYPT command

Message ID 20171106113105.qvw5wq7qts3ak5c2@pd.tnic (mailing list archive)
State New, archived
Headers show

Commit Message

Borislav Petkov Nov. 6, 2017, 11:31 a.m. UTC
On Wed, Nov 01, 2017 at 04:17:18PM -0500, Brijesh Singh wrote:
> The command copies a plaintext into guest memory and encrypts it using
> the VM encryption key. The command will be used for debug purposes
> (e.g setting breakpoints through gdbserver)

...

> @@ -6161,11 +6238,19 @@ static int sev_dbg_crypt(struct kvm *kvm, struct kvm_sev_cmd *argp, bool dec)
>  		d_off = dst_vaddr & ~PAGE_MASK;
>  		len = min_t(size_t, (PAGE_SIZE - s_off), size);
>  
> -		ret = sev_dbg_decrypt_user(kvm,
> -					   __sme_page_pa(src_p[0]) + s_off,
> -					   dst_vaddr,
> -					   __sme_page_pa(dst_p[0]) + d_off,
> -					   len, &argp->error);
> +		if (dec)
> +			ret = sev_dbg_decrypt_user(kvm,
> +						   __sme_page_pa(src_p[0]) + s_off,
> +						   dst_vaddr,
> +						   __sme_page_pa(dst_p[0]) + d_off,
> +						   len, &argp->error);
> +		else
> +			ret = __sev_dbg_encrypt_user(kvm,
> +						     __sme_page_pa(src_p[0]) + s_off,
> +						     vaddr,
> +						     __sme_page_pa(dst_p[0]) + d_off,
> +						     dst_vaddr,
> +						     len, &argp->error);

sev_dbg_decrypt_user but __sev_dbg_encrypt_user, with the "__" ??

>  
>  		sev_unpin_memory(kvm, src_p, 1);
>  		sev_unpin_memory(kvm, dst_p, 1);
> @@ -6186,6 +6271,11 @@ static int sev_dbg_decrypt(struct kvm *kvm, struct kvm_sev_cmd *argp)
>  	return sev_dbg_crypt(kvm, argp, true);
>  }
>  
> +static int sev_dbg_encrypt(struct kvm *kvm, struct kvm_sev_cmd *argp)
> +{
> +	return sev_dbg_crypt(kvm, argp, false);
> +}

Get rid of those silly wrappers:

---

Comments

Brijesh Singh Nov. 6, 2017, 4:38 p.m. UTC | #1
On 11/06/2017 05:31 AM, Borislav Petkov wrote:
...

>> -		ret = sev_dbg_decrypt_user(kvm,
>> -					   __sme_page_pa(src_p[0]) + s_off,
>> -					   dst_vaddr,
>> -					   __sme_page_pa(dst_p[0]) + d_off,
>> -					   len, &argp->error);
>> +		if (dec)
>> +			ret = sev_dbg_decrypt_user(kvm,
>> +						   __sme_page_pa(src_p[0]) + s_off,
>> +						   dst_vaddr,
>> +						   __sme_page_pa(dst_p[0]) + d_off,
>> +						   len, &argp->error);
>> +		else
>> +			ret = __sev_dbg_encrypt_user(kvm,
>> +						     __sme_page_pa(src_p[0]) + s_off,
>> +						     vaddr,
>> +						     __sme_page_pa(dst_p[0]) + d_off,
>> +						     dst_vaddr,
>> +						     len, &argp->error);
> 
> sev_dbg_decrypt_user but __sev_dbg_encrypt_user, with the "__" ??
> 

yes they both should be "__", I will overlooked it and will fix in next rev.
diff mbox

Patch

diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index a60454afb4d2..68d398e72c4c 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -6261,16 +6261,6 @@  static int sev_dbg_crypt(struct kvm *kvm, struct kvm_sev_cmd *argp, bool dec)
 	return ret;
 }
 
-static int sev_dbg_decrypt(struct kvm *kvm, struct kvm_sev_cmd *argp)
-{
-	return sev_dbg_crypt(kvm, argp, true);
-}
-
-static int sev_dbg_encrypt(struct kvm *kvm, struct kvm_sev_cmd *argp)
-{
-	return sev_dbg_crypt(kvm, argp, false);
-}
-
 static int svm_mem_enc_op(struct kvm *kvm, void __user *argp)
 {
 	struct kvm_sev_cmd sev_cmd;
@@ -6304,10 +6294,10 @@  static int svm_mem_enc_op(struct kvm *kvm, void __user *argp)
 		r = sev_guest_status(kvm, &sev_cmd);
 		break;
 	case KVM_SEV_DBG_DECRYPT:
-		r = sev_dbg_decrypt(kvm, &sev_cmd);
+		r = sev_dbg_crypt(kvm, argp, true);
 		break;
 	case KVM_SEV_DBG_ENCRYPT:
-		r = sev_dbg_encrypt(kvm, &sev_cmd);
+		r = sev_dbg_crypt(kvm, argp, false);
 		break;
 	default:
 		r = -EINVAL;