Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 71072C636D4 for ; Mon, 13 Feb 2023 10:34:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230423AbjBMKe4 (ORCPT ); Mon, 13 Feb 2023 05:34:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230356AbjBMKem (ORCPT ); Mon, 13 Feb 2023 05:34:42 -0500 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 17166144A1; Mon, 13 Feb 2023 02:34:39 -0800 (PST) Received: from vm02.corp.microsoft.com (unknown [167.220.196.155]) by linux.microsoft.com (Postfix) with ESMTPSA id 3A2B320C8B73; Mon, 13 Feb 2023 02:34:36 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 3A2B320C8B73 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1676284478; bh=seVPAjNfSiYKxnX2j0YblQLtaiY/QQf1dxqHVHTN/Zc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YQaKS8/tWGPsg/vr+lv3W7e7ETHFnqAEdaZn7cwscr/pRpUtFeY5yo4n4AFouND64 QvKhy7BXBALbt13SRO9CASzhjkwKrgJgvBepCJ9MK6xl3KloUl2x6WuXb0cb6qIY2k 2F98P3q2k92KEl2+UF5tE+nrqNorqi8OJIFvgbo0= From: Jeremi Piotrowski To: linux-kernel@vger.kernel.org Cc: Jeremi Piotrowski , Wei Liu , Dexuan Cui , Tianyu Lan , Michael Kelley , linux-hyperv@vger.kernel.org, Brijesh Singh , Michael Roth , Ashish Kalra , Tom Lendacky , Joerg Roedel , Suravee Suthikulpanit , iommu@lists.linux.dev Subject: [RFC PATCH v2 5/7] iommu/amd: Don't fail snp_enable when running virtualized Date: Mon, 13 Feb 2023 10:34:00 +0000 Message-Id: <20230213103402.1189285-6-jpiotrowski@linux.microsoft.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230213103402.1189285-1-jpiotrowski@linux.microsoft.com> References: <20230213103402.1189285-1-jpiotrowski@linux.microsoft.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hyper-V VMs do not have access to an IOMMU but can support hosting SNP VMs. amd_iommu_snp_enable() is on the SNP init path and should not fail in that case. Signed-off-by: Jeremi Piotrowski --- drivers/iommu/amd/init.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c index d1270e3c5baf..8049dbe78a27 100644 --- a/drivers/iommu/amd/init.c +++ b/drivers/iommu/amd/init.c @@ -3619,6 +3619,12 @@ int amd_iommu_pc_set_reg(struct amd_iommu *iommu, u8 bank, u8 cntr, u8 fxn, u64 #ifdef CONFIG_AMD_MEM_ENCRYPT int amd_iommu_snp_enable(void) { + /* + * If we're running virtualized there doesn't have to be an IOMMU for SNP to work. + */ + if (init_state == IOMMU_NOT_FOUND && boot_cpu_has(X86_FEATURE_HYPERVISOR)) + return 0; + /* * The SNP support requires that IOMMU must be enabled, and is * not configured in the passthrough mode. -- 2.25.1