From patchwork Mon Nov 6 11:31:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Borislav Petkov X-Patchwork-Id: 10043341 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 81B3E603FF for ; Mon, 6 Nov 2017 11:31:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 700F929B9D for ; Mon, 6 Nov 2017 11:31:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 64A8229B9C; Mon, 6 Nov 2017 11:31:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 157FC29B9C for ; Mon, 6 Nov 2017 11:31:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752761AbdKFLbW (ORCPT ); Mon, 6 Nov 2017 06:31:22 -0500 Received: from mail.skyhub.de ([5.9.137.197]:39694 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752658AbdKFLbU (ORCPT ); Mon, 6 Nov 2017 06:31:20 -0500 X-Virus-Scanned: Nedap ESD1 at mail.skyhub.de Received: from mail.skyhub.de ([127.0.0.1]) by localhost (blast.alien8.de [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id j_59mteFsLiK; Mon, 6 Nov 2017 12:31:19 +0100 (CET) Received: from pd.tnic (p2003008C2F2EF900D19A513C02A1D3AF.dip0.t-ipconnect.de [IPv6:2003:8c:2f2e:f900:d19a:513c:2a1:d3af]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id F22241EC01C6; Mon, 6 Nov 2017 12:31:18 +0100 (CET) Date: Mon, 6 Nov 2017 12:31:05 +0100 From: Borislav Petkov To: Brijesh Singh Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , Paolo Bonzini , Radim =?utf-8?B?S3LEjW3DocWZ?= , Joerg Roedel , Tom Lendacky , x86@kernel.org Subject: Re: [Part2 PATCH v7 33/38] KVM: SVM: Add support for SEV DEBUG_ENCRYPT command Message-ID: <20171106113105.qvw5wq7qts3ak5c2@pd.tnic> References: <20171101211723.71594-1-brijesh.singh@amd.com> <20171101211723.71594-4-brijesh.singh@amd.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20171101211723.71594-4-brijesh.singh@amd.com> User-Agent: NeoMutt/20170609 (1.8.3) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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: 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;