Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp1587605pxb; Fri, 20 Aug 2021 09:00:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyBgUpp7/rV6TzE5Y3vqlEUlWRk5nJ6lBwKB3DyD2+t9Go6ieW79+REL0L7eKE6vb9tiX9V X-Received: by 2002:a1c:7c0b:: with SMTP id x11mr4625905wmc.79.1629475249164; Fri, 20 Aug 2021 09:00:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1629475249; cv=pass; d=google.com; s=arc-20160816; b=BDUOAIXUnPGNXv60AnVBK7EbnpvR5bd9pk4FWsHpccf20MopmRN9dwlILeUdzfVOvZ ro9QNDnYFN39pTd8PII8pnd5WL6QPce5gifW3yeuySq/MFRjuAnkuMgVX2Qjv5dFldF8 /0aBd44CuC4nz6dub+BBmwxa1saU//4KQaLaUH/2BLXqr6NKEig4qmQUizNNQIECBL/0 WXKAAYt8py+ZF481T+XYin/Q0dvu9FDMX3pRdeNrDI6tfC7vhjLTDAO1Ir/M7gZntHFs q9Ldg6eTJsbJyJ1TQnD55rFj9uBpDuu/Tt6WZIGZSTcYka0zPZOexo0FBri8xk5Wsybl 4aRg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=qPb0Krkmp5g+egnTw4zbXxw+YrNaWXAd4naJ69WHSYU=; b=U3NGGBPmCuKN0WturCKGVSZT+LAtUwN60gCa+7DB5MjOcGkihEucYrJSuV8Yky9h7u 3jlIcCY0cnTQtE49ZVXh+Bpa6rhoRR28rGIT6cHYK6pw88FQ+8fmUXwWsHOw1H3j1FuK ScMiwuofJjQkU3NmlNJoc4mH+ZewatlYzkfWqrRPIIGpvkH51iHcoQs527TRww5DiseX i9Jti2R4POtwB5KMBiQ6mu1XFQvnA9NlI4vkykON8UHEWboxWLh5yHrkEz7GJTAe1XZB fIe919nHQzbaEEnmzz71X2Op+EAu3q0mKaO1IMxSwLxRu0AuhJysOqrmQqE2E7tuKipF nA0w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=iO3DBuWp; arc=pass (i=1 spf=pass spfdomain=amd.com dkim=pass dkdomain=amd.com dmarc=pass fromdomain=amd.com); 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p21si6766000edq.94.2021.08.20.09.00.25; Fri, 20 Aug 2021 09:00:49 -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=@amd.com header.s=selector1 header.b=iO3DBuWp; arc=pass (i=1 spf=pass spfdomain=amd.com dkim=pass dkdomain=amd.com dmarc=pass fromdomain=amd.com); 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241367AbhHTQAl (ORCPT + 99 others); Fri, 20 Aug 2021 12:00:41 -0400 Received: from mail-bn8nam08on2075.outbound.protection.outlook.com ([40.107.100.75]:31200 "EHLO NAM04-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S241328AbhHTQAi (ORCPT ); Fri, 20 Aug 2021 12:00:38 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fF6Iv7P2QvyGyqWmhXOr5P9v4T+rEvw2UNLG50A9fxEqFrfQS7PN+I+ubMu0ngLs6dnlH+pc74PkEZ1aPOKHxyW0Vp7AFYyZyJlL7uYk3RtevQZSv+M+abBd3V6PU1rMddQXUUW2BOlAb0K1BYi5N51KQKX8DBooEmOs8g6/AD63vPqkWCufSoTD7F6GPd20MLI3UNbABKVbQDl9j0sLJBfehwQ1RsPvRyRP0TEJGOFa/sgKgRtFDNUcMN3I3NMCLM83+mOfxgzuGu8bmmrT4nwZQ90bPvBpUtq4v3vqmDBT2bUydlftgdLsqzPpgyBJcO2VJZt3jtYyzZgL9jYZBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=qPb0Krkmp5g+egnTw4zbXxw+YrNaWXAd4naJ69WHSYU=; b=JjSaIkz4EJ04paViG2/fZDMxPPNd+9zWIdHfekcH/yZvkk8BIztej8RFag328gkH3u8Y7e54ejy0IqoNiKlmZhnDGfjojuW5q9beE2FyvtMm431TL/gohM6zF5gFLDkfmpCWT0Rtzqg+dKP9f7Ldgx+t+4vz9BxjbB1sfnQtds4lEji4saKt6mgCdM0qzauaX5nDnTdZUuoPcwLDJlCPHrjDGZq/YaV5vDHVCh6SdDgVnC9ja7sIt/HK6dMAuPV/4htGWX/R4I1ClGNvQ2z4EKBhTaVZ0MZjU8drnzDHy44yWw+MjQzAJ8ecL4zsYHkR8hunu/hfHs2bBk8FeRM5Zw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=qPb0Krkmp5g+egnTw4zbXxw+YrNaWXAd4naJ69WHSYU=; b=iO3DBuWpxDra4HGOe7RdQZ1CO+jvc+tx3TqRjrsiIWqjBPFh9f8JULjnSuMMlHf+A0rTbwUiBbCF7/QS9rF9UejdWkG4ITTDi9JprzW+5hNMdEDDkT7nT593IRCmodXdoQKb0t1LxkLQQiKOsSF64i9hcayIL6dnLh6C24B2Fjc= Authentication-Results: kernel.org; dkim=none (message not signed) header.d=none;kernel.org; dmarc=none action=none header.from=amd.com; Received: from SN6PR12MB2718.namprd12.prod.outlook.com (2603:10b6:805:6f::22) by SA0PR12MB4384.namprd12.prod.outlook.com (2603:10b6:806:9f::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.19; Fri, 20 Aug 2021 15:59:56 +0000 Received: from SN6PR12MB2718.namprd12.prod.outlook.com ([fe80::78b7:7336:d363:9be3]) by SN6PR12MB2718.namprd12.prod.outlook.com ([fe80::78b7:7336:d363:9be3%6]) with mapi id 15.20.4436.019; Fri, 20 Aug 2021 15:59:56 +0000 From: Brijesh Singh To: 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 Cc: 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 , Borislav Petkov , Michael Roth , Vlastimil Babka , "Kirill A . Shutemov" , Andi Kleen , tony.luck@intel.com, marcorr@google.com, sathyanarayanan.kuppuswamy@linux.intel.com, Brijesh Singh Subject: [PATCH Part2 v5 02/45] iommu/amd: Introduce function to check SEV-SNP support Date: Fri, 20 Aug 2021 10:58:35 -0500 Message-Id: <20210820155918.7518-3-brijesh.singh@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210820155918.7518-1-brijesh.singh@amd.com> References: <20210820155918.7518-1-brijesh.singh@amd.com> Content-Type: text/plain X-ClientProxiedBy: SN7P222CA0013.NAMP222.PROD.OUTLOOK.COM (2603:10b6:806:124::11) To SN6PR12MB2718.namprd12.prod.outlook.com (2603:10b6:805:6f::22) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sbrijesh-desktop.amd.com (165.204.77.1) by SN7P222CA0013.NAMP222.PROD.OUTLOOK.COM (2603:10b6:806:124::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.18 via Frontend Transport; Fri, 20 Aug 2021 15:59:55 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 640aa177-0f1d-46be-f1bf-08d963f38de8 X-MS-TrafficTypeDiagnostic: SA0PR12MB4384: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: EyRCeDlMOPKzGSuUzwJD/ZXT7XDQknk5mfqKak/IK718ErPQraVIKhNtRbVfkbM4xmJ021O9lYI16QnI3rOUqDZuzEfPdoI+bSl2jk5hdC8fVAKyHo0VriLezDNi24CmZaJMcNyDXkIIZVN7c0hW8wJkBIvPLva4QqHpdqCRZL2qtcV1NG3AAAzXmjROdn+rxIdznPvUn5x/FxzEI8go14TAre6fvJhAjYg9r9sX7Kba0XCaqQQ9uhhnyTsR0o5xlSnTDyI6MEbLUSL91/ex9tPLTjjCAAAu1wtYBjG3Ynq1ai399k3cgboT0hBwYNSanL8LxR8wRZHuYtlMZ/IsVa+s+q5ohlgAlFX3u7R5yD7Ckc9L9igZEBip01yTN6YjqZpKpntzpR1URUFd/1dsRxN+pEXcJc+39Mf/K0tfIDLtuijdo0kgvoXLybtUAvEnE7Kyb4DUrk4ngad1XLl5XLgQaQljoPLtkMQRyF4GYKECwu2JP0SFbPBegVT3s4V8O89UitNj6ZjxwjiuM2Q4O2Vtl+jCoN1H3IqlXAJwpNRWZCErKE4y9iOcUIGUEeaSWng9AjZZBPnJ7G+9AeiNvu6T6PUI8k/AxSpG9IhsIJGxx5N5WMbX+kiKPSAaiHp2rttB20biOxBZwWsXUGXKLmJrCIOl4rdZZKjDfPaqif7tT5Cdi5Lj4eXxULIuwp34/mf08d7b1VzihvH/zLl15w== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR12MB2718.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(39860400002)(396003)(366004)(346002)(136003)(5660300002)(6666004)(52116002)(66946007)(44832011)(36756003)(7416002)(66476007)(7406005)(6486002)(956004)(8936002)(316002)(2906002)(186003)(4326008)(478600001)(86362001)(26005)(54906003)(38100700002)(38350700002)(7696005)(1076003)(8676002)(83380400001)(2616005)(66556008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?i6T83T4twIh4+dUtC8zzxOkltYfaaUDxxNFzwtwng/AVa6YThvTwYW+GvvLP?= =?us-ascii?Q?j5/Aol0TBhGHxcGB5auyjFAw2q7EH3KbZDPI3f0qIBvzg8bA/VVWEHacb/Z3?= =?us-ascii?Q?Uc3RCD51p2XIc896gEf70nRH36PrHj9AxLPX3MBEqzxsw9a4+rGruhsSZydr?= =?us-ascii?Q?Uoaam4UFnuGdW1ZS0XaAWWayE6c/Ys+71p2KVAZqY88SZAEAAclZBjfv96J2?= =?us-ascii?Q?M6vx/ha/V0MMltRrLyH76aywj9z2stXaoSacldFIpt/IOYj0Jn2PRjHisWQB?= =?us-ascii?Q?B6tv5qalpyeX6ZqRoox0sJP9n+PgSy7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5BaoLMuWc61en8XXPPvfWct883tuiaOPcGlPc9OkcPj4c5?= =?us-ascii?Q?P7PbMX4xbGQqpaTncC8TEY7yhT6Y1qD3ZvVqqKzgqkWtOGntB8Pca0rbfPfl?= =?us-ascii?Q?+Bx7CuWp3mN30hCkKxKpjiAt?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 640aa177-0f1d-46be-f1bf-08d963f38de8 X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2718.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Aug 2021 15:59:56.0571 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: qBpA0sNwA4uZNg1MdEcSCylMWiE6cgUkRQ7T3uNrH3nqtSnIRglYwdc6XBj3Yi1AfFvDFvhWp5iG3W8fqHWF6A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4384 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org The SEV-SNP support requires that IOMMU must to enabled, see the IOMMU 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 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); 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; } + #endif /* CONFIG_IOMMU_API */ /** -- 2.17.1