Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1588677pxb; Thu, 16 Sep 2021 10:31:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxv/uXCuDB5t5rvPjIfW1yxMD6eg1VPM7a+I4f8m20daiTC2C/IX1wo/sBbMLTqgjemzm8q X-Received: by 2002:aa7:cad0:: with SMTP id l16mr7659263edt.16.1631813477379; Thu, 16 Sep 2021 10:31:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631813477; cv=none; d=google.com; s=arc-20160816; b=bpz82G2vGJm+HlG6ooVONPfvCrOOnSf+2nWN2SlW1i0V9GY6hopq90VzypksNj8pui WHjshP843JHo816Aj+tnanTDYugPmxShN7WqQ5ei/GM+y3AoRQxoZKy/2ZMPkBo8NA3Q wjUQjdwvNLy2nWsbky+R8gdRgEWyhwYUV8NQ9jRvI5MkpvHgQBB7x5p1axw329OQpy0+ qA4pnwhzk8I4kALi9R7qCOShzZ67pbqB4b4hIGmsy8HpdhMxnjjuqMLk2THSdlbYTGkY OT/B/bfCAZA8hyAKkhm87DfBx5YwZbaIRzF8JpnWn549cAmNTIYtQWXuqX93j6AwvTAd PU1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=oOtmNTM2jr/g9JVg0OexwbFg2/pG+8cff5fWd4oubyk=; b=vJRjhTuDy7hN58F3C59dkyCA+Az9Oxm3e7CyFLUsQEMD/750QDpvtPpBsUXjvzXAsr VsfZ/KtoLgGyVLWCZml+ApMCv6ZtDboB+1VCshcxcAvsEQol38BHnodBuAuTYkt95c+6 ODz0cUfDTggh/Y+ZwrtsAXHI78s0J9aXlD+Hj+ouH69FHx4kAgN01CBHaexw/ovg2RoX 2XJbFHp+2Mu9sBFC88b0ctMx2upBul68yHiy6vDpmTJaq8LlH3f4J9P+fuD3UxLFU06/ IA4c2tELMAYDTRIPoHJHWcESskuYDtNejXmjin1ZaJlhrQC4460TbuuHLyvSLc2OxQAW yp8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=HA43ImuG; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y14si4456762edo.391.2021.09.16.10.30.47; Thu, 16 Sep 2021 10:31:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=HA43ImuG; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243658AbhIPRa7 (ORCPT + 99 others); Thu, 16 Sep 2021 13:30:59 -0400 Received: from mail.skyhub.de ([5.9.137.197]:42316 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352754AbhIPR1j (ORCPT ); Thu, 16 Sep 2021 13:27:39 -0400 Received: from zn.tnic (p200300ec2f11c6001e49ea6afe1054f5.dip0.t-ipconnect.de [IPv6:2003:ec:2f11:c600:1e49:ea6a:fe10:54f5]) (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 5ED201EC01DF; Thu, 16 Sep 2021 19:26:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1631813168; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=oOtmNTM2jr/g9JVg0OexwbFg2/pG+8cff5fWd4oubyk=; b=HA43ImuGZC1WGrvAhfNdFt6SUtTLcSGWTR/UJVK0nwQVPxc+EN+ytuygjgJvsDLf/v619f /mdq87L35kG6yS8syIKPfSYSI0oP8iaQEgeOJlWiTRfBbdN6rLm+JNU+WDuyQBUs5a0bmU GfQ50AjWPdgVTca2lYAIWjSFmICdB2A= Date: Thu, 16 Sep 2021 19:26:07 +0200 From: Borislav Petkov To: Brijesh Singh Cc: x86@kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-coco@lists.linux.dev, linux-mm@kvack.org, linux-crypto@vger.kernel.org, Thomas Gleixner , Ingo Molnar , Joerg Roedel , Tom Lendacky , "H. Peter Anvin" , Ard Biesheuvel , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Andy Lutomirski , Dave Hansen , Sergio Lopez , Peter Gonda , Peter Zijlstra , Srinivas Pandruvada , David Rientjes , Dov Murik , Tobin Feldman-Fitzthum , Michael Roth , Vlastimil Babka , "Kirill A . Shutemov" , Andi Kleen , tony.luck@intel.com, marcorr@google.com, sathyanarayanan.kuppuswamy@linux.intel.com Subject: Re: [PATCH Part2 v5 02/45] iommu/amd: Introduce function to check SEV-SNP support Message-ID: References: <20210820155918.7518-1-brijesh.singh@amd.com> <20210820155918.7518-3-brijesh.singh@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20210820155918.7518-3-brijesh.singh@amd.com> Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Fri, Aug 20, 2021 at 10:58:35AM -0500, Brijesh Singh wrote: > The SEV-SNP support requires that IOMMU must to enabled, see the IOMMU s/must to/is/ > spec section 2.12 for further details. If IOMMU is not enabled or the > SNPSup extended feature register is not set then the SNP_INIT command > (used for initializing firmware) will fail. > > The iommu_sev_snp_supported() can be used to check if IOMMU supports the "can be used"? Just say what is going to use it. > SEV-SNP feature. > > Signed-off-by: Brijesh Singh > --- > drivers/iommu/amd/init.c | 30 ++++++++++++++++++++++++++++++ > include/linux/iommu.h | 9 +++++++++ > 2 files changed, 39 insertions(+) > > diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c > index 46280e6e1535..bd420fb71126 100644 > --- a/drivers/iommu/amd/init.c > +++ b/drivers/iommu/amd/init.c > @@ -3320,3 +3320,33 @@ int amd_iommu_pc_set_reg(struct amd_iommu *iommu, u8 bank, u8 cntr, u8 fxn, u64 > > return iommu_pc_get_set_reg(iommu, bank, cntr, fxn, value, true); > } > + > +bool iommu_sev_snp_supported(void) > +{ > + struct amd_iommu *iommu; > + > + /* > + * The SEV-SNP support requires that IOMMU must be enabled, and is > + * not configured in the passthrough mode. > + */ > + if (no_iommu || iommu_default_passthrough()) { > + pr_err("SEV-SNP: IOMMU is either disabled or configured in passthrough mode.\n"); > + return false; > + } > + > + /* > + * Iterate through all the IOMMUs and verify the SNPSup feature is > + * enabled. > + */ > + for_each_iommu(iommu) { > + if (!iommu_feature(iommu, FEATURE_SNP)) { > + pr_err("SNPSup is disabled (devid: %02x:%02x.%x)\n", > + PCI_BUS_NUM(iommu->devid), PCI_SLOT(iommu->devid), > + PCI_FUNC(iommu->devid)); > + return false; > + } > + } > + > + return true; > +} > +EXPORT_SYMBOL_GPL(iommu_sev_snp_supported); That export is not needed. > diff --git a/include/linux/iommu.h b/include/linux/iommu.h > index 32d448050bf7..269abc17b2c3 100644 > --- a/include/linux/iommu.h > +++ b/include/linux/iommu.h > @@ -604,6 +604,12 @@ struct iommu_sva *iommu_sva_bind_device(struct device *dev, > void iommu_sva_unbind_device(struct iommu_sva *handle); > u32 iommu_sva_get_pasid(struct iommu_sva *handle); > > +#ifdef CONFIG_AMD_MEM_ENCRYPT > +bool iommu_sev_snp_supported(void); > +#else > +static inline bool iommu_sev_snp_supported(void) { return false; } > +#endif > + > #else /* CONFIG_IOMMU_API */ > > struct iommu_ops {}; > @@ -999,6 +1005,9 @@ static inline struct iommu_fwspec *dev_iommu_fwspec_get(struct device *dev) > { > return NULL; > } > + > +static inline bool iommu_sev_snp_supported(void) { return false; } > + Most of those stubs and ifdeffery is not needed if you put the function itself in #ifdef CONFIG_AMD_MEM_ENCRYPT ... #endif as it is called by sev.c only, AFAICT, and latter is enabled by CONFIG_AMD_MEM_ENCRYPT anyway. Thx. -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette