From patchwork Mon Aug 16 20:24:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mingwei Zhang X-Patchwork-Id: 498215 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5CD95C4320A for ; Mon, 16 Aug 2021 20:24:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 44FCC60F55 for ; Mon, 16 Aug 2021 20:24:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232370AbhHPUZ0 (ORCPT ); Mon, 16 Aug 2021 16:25:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231760AbhHPUZZ (ORCPT ); Mon, 16 Aug 2021 16:25:25 -0400 Received: from mail-qk1-x74a.google.com (mail-qk1-x74a.google.com [IPv6:2607:f8b0:4864:20::74a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C0DEC061764 for ; Mon, 16 Aug 2021 13:24:53 -0700 (PDT) Received: by mail-qk1-x74a.google.com with SMTP id y185-20020a3764c20000b02903d2c78226ceso7979076qkb.6 for ; Mon, 16 Aug 2021 13:24:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=lAON/zCvnCQ9WkXsqWr7UdkpKpH6eowrQHHqKFOX8Ms=; b=ewJdYFg1tzZ1wizJlezLTaTYBT4aAtZdQcBb2uJlih9sqNHaFRZ8A3YzyMU+5ErrSC BcswvvEckSbQ2DChlC7FHMBSvlYETZGJi+e7GPs4mW6HvhG2+WW75B/VSvqxRfzqyMEI nwSScBipyqbyL7jwK2J+zIsprKJll7Qs1ha7ksb3Q5zZjLkp8e5+8m+btH9lgbBXbgXh b3bNhsiu8Z/gj2s0edL63ITQTAVqvoOdfD3KmZL7oo5zbX/hEyOttPr7vKgknPyAjSWX /1tE5NgbMZ4KoN/UpuUFzMc4owiAcgRCQDjk40X732mmggVhT6yh3lK51F1DEZb1vVLx hbIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=lAON/zCvnCQ9WkXsqWr7UdkpKpH6eowrQHHqKFOX8Ms=; b=pmtxNRAIzYr5WuLT/V+3Q7B1Js+d2IhKQQqriR4onfqans3oGFA3HZQRe2Sbr4/lav wBk16FyAJnNO7G0qFL5fBRDbRQ0flP9/i6SbkaIDdxhg15MOTW0fj0w7HjFW3x31qFpG g8RmdMS2T8GTa9/gek5+5zIjd0R6o7VYRIfSzyKWs85Bk1G+UwwFEhjjV5J4773X05Cc b+L2F8W81GMbBGll/39E8sytseftsGJWh7K1stm63VKaW7vd7Ii5uBh17nzu4wMbfyQ6 fM/gk/Gy94WJVJm50hG1BTLFpk2p1gWzCIe7g1yax4VPhqCVPSSP44AvVA4hLQI5yJX1 qoiA== X-Gm-Message-State: AOAM530C0/icuLHBdccXuGftl8JbpmFk0tfx2Uwn8m9R1suMCSYOPSQj +lnm07LkuyLP7ErQ1QThRILKYZNjIuWG X-Google-Smtp-Source: ABdhPJwsPia8EyVr5Q9u/4hdukkWSxdyMw6btsqaOSIt+v09BBRasZ6Wx6zQVBgvGvlkSBUrpKSgogEo8y4t X-Received: from mizhang-super.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1071]) (user=mizhang job=sendgmr) by 2002:a05:6214:1382:: with SMTP id g2mr610477qvz.14.1629145492552; Mon, 16 Aug 2021 13:24:52 -0700 (PDT) Reply-To: Mingwei Zhang Date: Mon, 16 Aug 2021 20:24:39 +0000 In-Reply-To: <20210816202441.4098523-1-mizhang@google.com> Message-Id: <20210816202441.4098523-2-mizhang@google.com> Mime-Version: 1.0 References: <20210816202441.4098523-1-mizhang@google.com> X-Mailer: git-send-email 2.33.0.rc1.237.g0d66db33f3-goog Subject: [PATCH 1/3] KVM: SVM: move sev_decommission to psp driver From: Mingwei Zhang To: Paolo Bonzini , Brijesh Singh , Tom Lendacky , John Allen Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, Alper Gun , Borislav Petkov , David Rienjes , Marc Orr , Peter Gonda , Vipin Sharma , Mingwei Zhang Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org ccp/sev-dev.c is part of the software layer in psp that allows KVM to manage SEV/ES/SNP enabled VMs. Among the APIs exposed in sev-dev, many of them requires caller (KVM) to understand psp specific data structures. This often ends up with the fact that KVM has to create its own 'wrapper' API to make it easy to use. The following is the pattern: kvm_func(unsigned int handle) { psp_data_structure data; data.handle = handle; psp_func(&data, NULL); } psp_func(psp_data_structure *data, int *error) { sev_do_cmd(data, error); } struct psp_data_structure { u32 handle; }; sev_decommission is one example following the above pattern. Since KVM is the only user for this API and 'handle' is the only data that is meaningful to KVM, simplify the interface by putting the code from kvm function sev_decommission into the psp function sev_guest_decomssion. Cc: Alper Gun Cc: Borislav Petkov Cc: Brijesh Singh Cc: David Rienjes Cc: Marc Orr Cc: John Allen Cc: Peter Gonda Cc: Sean Christopherson Cc: Tom Lendacky Cc: Vipin Sharma Suggested-by: Sean Christopherson Signed-off-by: Mingwei Zhang --- arch/x86/kvm/svm/sev.c | 15 ++------------- drivers/crypto/ccp/sev-dev.c | 8 +++++++- include/linux/psp-sev.h | 7 ++++--- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 75e0b21ad07c..6a1faf28d973 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -198,17 +198,6 @@ static void sev_asid_free(struct kvm_sev_info *sev) sev->misc_cg = NULL; } -static void sev_decommission(unsigned int handle) -{ - struct sev_data_decommission decommission; - - if (!handle) - return; - - decommission.handle = handle; - sev_guest_decommission(&decommission, NULL); -} - static void sev_unbind_asid(struct kvm *kvm, unsigned int handle) { struct sev_data_deactivate deactivate; @@ -223,7 +212,7 @@ static void sev_unbind_asid(struct kvm *kvm, unsigned int handle) sev_guest_deactivate(&deactivate, NULL); up_read(&sev_deactivate_lock); - sev_decommission(handle); + sev_guest_decommission(handle, NULL); } static int sev_guest_init(struct kvm *kvm, struct kvm_sev_cmd *argp) @@ -349,7 +338,7 @@ static int sev_launch_start(struct kvm *kvm, struct kvm_sev_cmd *argp) /* Bind ASID to this guest */ ret = sev_bind_asid(kvm, start.handle, error); if (ret) { - sev_decommission(start.handle); + sev_guest_decommission(start.handle, NULL); goto e_free_session; } diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c index 91808402e0bf..ab9c2c49d612 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -903,8 +903,14 @@ int sev_guest_activate(struct sev_data_activate *data, int *error) } EXPORT_SYMBOL_GPL(sev_guest_activate); -int sev_guest_decommission(struct sev_data_decommission *data, int *error) +int sev_guest_decommission(unsigned int handle, int *error) { + struct sev_data_decommission decommission; + + if (!handle) + return -EINVAL; + + decommission.handle = handle; return sev_do_cmd(SEV_CMD_DECOMMISSION, data, error); } EXPORT_SYMBOL_GPL(sev_guest_decommission); diff --git a/include/linux/psp-sev.h b/include/linux/psp-sev.h index d48a7192e881..6c0f2f451c89 100644 --- a/include/linux/psp-sev.h +++ b/include/linux/psp-sev.h @@ -612,17 +612,18 @@ int sev_guest_df_flush(int *error); /** * sev_guest_decommission - perform SEV DECOMMISSION command * - * @decommission: sev_data_decommission structure to be processed + * @handle: sev_data_decommission structure to be processed * @sev_ret: sev command return code * * Returns: * 0 if the sev successfully processed the command + * -%EINVAL if handle is NULL * -%ENODEV if the sev device is not available * -%ENOTSUPP if the sev does not support SEV * -%ETIMEDOUT if the sev command timed out * -%EIO if the sev returned a non-zero return code */ -int sev_guest_decommission(struct sev_data_decommission *data, int *error); +int sev_guest_decommission(unsigned int handle, int *error); void *psp_copy_user_blob(u64 uaddr, u32 len); @@ -637,7 +638,7 @@ static inline int sev_guest_deactivate(struct sev_data_deactivate *data, int *error) { return -ENODEV; } static inline int -sev_guest_decommission(struct sev_data_decommission *data, int *error) { return -ENODEV; } +sev_guest_decommission(unsigned int handle, int *error) { return -ENODEV; } static inline int sev_guest_activate(struct sev_data_activate *data, int *error) { return -ENODEV; }