Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp4214874iog; Tue, 21 Jun 2022 14:44:34 -0700 (PDT) X-Google-Smtp-Source: AGRyM1v3r3eqT6G2o0FQxMnf3rIKcBwOT8cRc05i2qCWBo5WOLbQysAiwQWDqK+00qrvfWHSxVVM X-Received: by 2002:a17:90b:350b:b0:1e8:5177:fe7d with SMTP id ls11-20020a17090b350b00b001e85177fe7dmr46583937pjb.142.1655847874206; Tue, 21 Jun 2022 14:44:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655847874; cv=none; d=google.com; s=arc-20160816; b=omOwcahYrhuUV3XV7P2veEwcuv3rMBvCctgZgKSOoOJQ9Rb8Ld5wjMd/kaNToTBZWV /v386nlGyKXhUW5lJmdrTWCunDKTCoZUlt23vdXv9U3sAYw1UxoeicQfNFqKBxlDogoo mo1Bgwx6zVCuopu6Vmq0MK1/xXUvmwrX5qKiDbIvEbO/CooheVMOEnLDvxj4ERIbIdvk tv3AFxoXQl08VMynPDOShz1XfRbob7+lpS8wVo2RmB/evNO3aDFQOEBKpLQ6kuS8GtLz Ea6/AwIVbLz1jlGxPLPy0x+2IQPVOR8DDSIXM2qesVMjKiKs6SaJJ5CUBw0AwnQQoEaN TXfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=RaH322YAfZ65JMqhLFboGn96Qf6ZOePhsZrijH5KbCY=; b=v0AFJhr5pynKX7jNkSoNb1z4uiO9GE1UCvT49+zaz8/lIFp95zIHFxR2PnR3rv0IMF 6y4VYH/hQbYdGgTbWchDv5/adP3fbxMQmVUytmPWLp/Vi+7Ynkxq4wIpOkYSYpR1OcVN kYU38w7muzEMBAEq82lgF1aNmEHZkbl4KJdZ5haHRbbr3GNE6vyLKmSPM6SX7HW2pfyC mAI/YqUPcaZCVGiDZpsgJvdhv3hmeaMZUm0+UeENWnJfmRdcVnn5EvWgyYB6SkD/YVam ZqOa9/R861y9Va5WdutOZrJaK658/vqRqqoA8QrTnUG9s5gDPA3n0S80Xmw0QXvFcsmq IMBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="D3/p22Sj"; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e4-20020a635004000000b003fc57764d3csi22023024pgb.56.2022.06.21.14.44.11; Tue, 21 Jun 2022 14:44:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="D3/p22Sj"; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356279AbiFUVno (ORCPT + 99 others); Tue, 21 Jun 2022 17:43:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356498AbiFUVne (ORCPT ); Tue, 21 Jun 2022 17:43:34 -0400 Received: from mail-lj1-x236.google.com (mail-lj1-x236.google.com [IPv6:2a00:1450:4864:20::236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E4CB8175B0 for ; Tue, 21 Jun 2022 14:43:26 -0700 (PDT) Received: by mail-lj1-x236.google.com with SMTP id a11so8236429ljb.5 for ; Tue, 21 Jun 2022 14:43:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=RaH322YAfZ65JMqhLFboGn96Qf6ZOePhsZrijH5KbCY=; b=D3/p22SjNtBkp5qEhE4PypZKC+l3FMV1mhcEN+p6jsNQhcEDuTDTjJxGGLOJxbogOF 1hFTZ9BOEVKlgp02OsdyaGnv3jsasAPBa/Cnnn2ZVpnyiylHmg6eMVeg4UOWSS0+p6zX sdy+2066vX5/bbMcM3aRdbC1PfISSKXvU7NaQ/kzpQjqwI/qZveOUZN3ugQivMMRJkUd 767YoEBbRRZIM8FyEma3DgNG5SB6FMsF8zbh96yzu29kt8zP32y8BNiGjtAdoKvgo2HK SJwOxxywLUJ1z091ovPz98tTKskg+w9ZxRTuR70p3dBhFgE3sxOSL5tGHMYs7Mh864Qz uO2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=RaH322YAfZ65JMqhLFboGn96Qf6ZOePhsZrijH5KbCY=; b=6mRtcBEK3kdVSsHW2VFlBPPELQHzlqUoNqxbyVw+nGhBukcVaz3pclCPDyNL9OIozd dGXeunSjP8CJlTBt68IYLHoCGMR1shQ+s+JeB45V45BDBDQPVvD2tEMT++5jcOoze7AX CEAjRFuIF6ROSu2NX1kyPFxcwBLqsp5fi2F3jFSH09ATS7enFwa5t8GxWau7/UZshT62 yicFpk0bsNumRV/Z8MwKtBiaBacc0sqRq8E1hhDOMkl41e2PRrqYNth0dC4r7dZRKlCP sC6sVE4hluxaY5rGZDBsPZNJfsjXtnVSOasSE+g0CLIuk2NgfZnTMbf8M9L5Y0TH5JnU o+XA== X-Gm-Message-State: AJIora9/acfmc+xt7lWb+ADZKkqLQdM/0wcgnhbFkjOUH7V6fgU/vcss voiNViH7rlcyjppwkqmJOgJWvhtWhK14N6JntzpFZg== X-Received: by 2002:a2e:8805:0:b0:255:6e73:9a67 with SMTP id x5-20020a2e8805000000b002556e739a67mr91486ljh.426.1655847804879; Tue, 21 Jun 2022 14:43:24 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Peter Gonda Date: Tue, 21 Jun 2022 15:43:13 -0600 Message-ID: Subject: Re: [PATCH Part2 v6 13/49] crypto:ccp: Provide APIs to issue SEV-SNP commands To: Ashish Kalra Cc: "the arch/x86 maintainers" , LKML , kvm list , linux-coco@lists.linux.dev, linux-mm@kvack.org, Linux Crypto Mailing List , Thomas Gleixner , Ingo Molnar , Joerg Roedel , "Lendacky, Thomas" , "H. Peter Anvin" , Ard Biesheuvel , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Jim Mattson , Andy Lutomirski , Dave Hansen , Sergio Lopez , Peter Zijlstra , Srinivas Pandruvada , David Rientjes , Dov Murik , Tobin Feldman-Fitzthum , Borislav Petkov , Michael Roth , Vlastimil Babka , "Kirill A . Shutemov" , Andi Kleen , Tony Luck , Marc Orr , Sathyanarayanan Kuppuswamy , Alper Gun , "Dr. David Alan Gilbert" , jarkko@kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org ( On Mon, Jun 20, 2022 at 5:05 PM Ashish Kalra wrote: > > From: Brijesh Singh > > Provide the APIs for the hypervisor to manage an SEV-SNP guest. The > commands for SEV-SNP is defined in the SEV-SNP firmware specification. > > Signed-off-by: Brijesh Singh > --- > drivers/crypto/ccp/sev-dev.c | 24 ++++++++++++ > include/linux/psp-sev.h | 73 ++++++++++++++++++++++++++++++++++++ > 2 files changed, 97 insertions(+) > > diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c > index f1173221d0b9..35d76333e120 100644 > --- a/drivers/crypto/ccp/sev-dev.c > +++ b/drivers/crypto/ccp/sev-dev.c > @@ -1205,6 +1205,30 @@ int sev_guest_df_flush(int *error) > } > EXPORT_SYMBOL_GPL(sev_guest_df_flush); > > +int snp_guest_decommission(struct sev_data_snp_decommission *data, int *error) > +{ > + return sev_do_cmd(SEV_CMD_SNP_DECOMMISSION, data, error); > +} > +EXPORT_SYMBOL_GPL(snp_guest_decommission); > + > +int snp_guest_df_flush(int *error) > +{ > + return sev_do_cmd(SEV_CMD_SNP_DF_FLUSH, NULL, error); > +} > +EXPORT_SYMBOL_GPL(snp_guest_df_flush); Why not instead change sev_guest_df_flush() to be SNP aware? That way callers get the right behavior without having to know if SNP is enabled or not. int sev_guest_df_flush(int *error) { if (!psp_master || !psp_master->sev_data) return -EINVAL; if (psp_master->sev_data->snp_inited) return sev_do_cmd(SEV_CMD_SNP_DF_FLUSH, NULL, error); return sev_do_cmd(SEV_CMD_DF_FLUSH, NULL, error); } > +int snp_guest_page_reclaim(struct sev_data_snp_page_reclaim *data, int *error) > +{ > + return sev_do_cmd(SEV_CMD_SNP_PAGE_RECLAIM, data, error); > +} > +EXPORT_SYMBOL_GPL(snp_guest_page_reclaim); > + > +int snp_guest_dbg_decrypt(struct sev_data_snp_dbg *data, int *error) > +{ > + return sev_do_cmd(SEV_CMD_SNP_DBG_DECRYPT, data, error); > +} > +EXPORT_SYMBOL_GPL(snp_guest_dbg_decrypt); > + > static void sev_exit(struct kref *ref) > { > misc_deregister(&misc_dev->misc); > diff --git a/include/linux/psp-sev.h b/include/linux/psp-sev.h > index ef4d42e8c96e..9f921d221b75 100644 > --- a/include/linux/psp-sev.h > +++ b/include/linux/psp-sev.h > @@ -881,6 +881,64 @@ int sev_guest_df_flush(int *error); > */ > int sev_guest_decommission(struct sev_data_decommission *data, int *error); > > +/** > + * snp_guest_df_flush - perform SNP DF_FLUSH command > + * > + * @sev_ret: sev command return code > + * > + * Returns: > + * 0 if the sev successfully processed the command > + * -%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 snp_guest_df_flush(int *error); > + > +/** > + * snp_guest_decommission - perform SNP_DECOMMISSION command > + * > + * @decommission: sev_data_decommission structure to be processed > + * @sev_ret: sev command return code > + * > + * Returns: > + * 0 if the sev successfully processed the command > + * -%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 snp_guest_decommission(struct sev_data_snp_decommission *data, int *error); > + > +/** > + * snp_guest_page_reclaim - perform SNP_PAGE_RECLAIM command > + * > + * @decommission: sev_snp_page_reclaim structure to be processed > + * @sev_ret: sev command return code > + * > + * Returns: > + * 0 if the sev successfully processed the command > + * -%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 snp_guest_page_reclaim(struct sev_data_snp_page_reclaim *data, int *error); > + > +/** > + * snp_guest_dbg_decrypt - perform SEV SNP_DBG_DECRYPT command > + * > + * @sev_ret: sev command return code > + * > + * Returns: > + * 0 if the sev successfully processed the command > + * -%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 snp_guest_dbg_decrypt(struct sev_data_snp_dbg *data, int *error); > + > void *psp_copy_user_blob(u64 uaddr, u32 len); > > #else /* !CONFIG_CRYPTO_DEV_SP_PSP */ > @@ -908,6 +966,21 @@ sev_issue_cmd_external_user(struct file *filep, unsigned int id, void *data, int > > static inline void *psp_copy_user_blob(u64 __user uaddr, u32 len) { return ERR_PTR(-EINVAL); } > > +static inline int > +snp_guest_decommission(struct sev_data_snp_decommission *data, int *error) { return -ENODEV; } > + > +static inline int snp_guest_df_flush(int *error) { return -ENODEV; } > + > +static inline int snp_guest_page_reclaim(struct sev_data_snp_page_reclaim *data, int *error) > +{ > + return -ENODEV; > +} > + > +static inline int snp_guest_dbg_decrypt(struct sev_data_snp_dbg *data, int *error) > +{ > + return -ENODEV; > +} > + > #endif /* CONFIG_CRYPTO_DEV_SP_PSP */ > > #endif /* __PSP_SEV_H__ */ > -- > 2.25.1 >