From patchwork Tue Jan 10 14:31:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suravee Suthikulpanit X-Patchwork-Id: 41497 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2779949wrt; Tue, 10 Jan 2023 06:33:57 -0800 (PST) X-Google-Smtp-Source: AMrXdXv5QtlYSY7oPKdu3TqosJMJwopjLqsfuNL3FOXCdwfr1zvg35h/0SjRtq7fdIiPQQ+mIAXL X-Received: by 2002:a05:6402:a55:b0:475:9918:37ce with SMTP id bt21-20020a0564020a5500b00475991837cemr58684198edb.13.1673361237443; Tue, 10 Jan 2023 06:33:57 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1673361237; cv=pass; d=google.com; s=arc-20160816; b=IWhykA3wjeapuflf04op8ImsMKcYWFPgmN5OGKPZEBD5VTSI6GkW7SQ8qLBf7Gqf/0 Zt2BFCmzeIXr8896ZqvElGtxCAsZv7Ksdz8Um+bRJT223Q7INPdr6LhhqxGntXCQRv89 PXdvazXhEfG5rB/gwNsZkHEh1Bf2lL9Vq7IvNAR5wYffQtOUIwPkf1CVN+/saRMHa6p0 ZjkC3tNcW7FgW1s9EDCZZroFeryOnTGpcsWKv1J2/nOek3wiR704UIbScpxpJBgBXiQm SD9K1t7jfHJTdilW6+qAQBt6g8GkGtLTdWOrztxYUKs8TyPZOZYntC3nTSzpCxPB57oh zRZA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=rM/7rBbvFmTloP90cbfDESDHZVvtwEhdd3UXHRXpRbE=; b=WQ+TyRX4/4IQPh5Pd7X3FXsQ8EwPQUn5FWAW2pX+l1eN/th8UXUjbNCV7tGYow2MoG OYnEs/bpPZTG1rGpNkNHlyNvsK2IR1m1ihqWn3Ob3lD4KGncf2rmGyrrRTNFLqt7etTs Lm3lK26FP4XTKTcThavWZIx7AmlzJU0QKSmoFNXGiB9FmKmEGamWpslWgrBGskoG/M8U eb6kh/w8XEIRQDSpv/SMs8vHE/bsRhTz4EcR0lrEnqYzkducceBSCcJN09OTJQOGrGcP US37b0T7JvSFc7bNQsqUkgTgw1Dzh0CjQh/6+crsyYhuretAW0/2jLXfNAJYLLmce7cJ NVNg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=YkaCjFPQ; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k11-20020a50ce4b000000b0048017a9576bsi10569581edj.543.2023.01.10.06.33.33; Tue, 10 Jan 2023 06:33:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-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=@amd.com header.s=selector1 header.b=YkaCjFPQ; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-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 S238504AbjAJOcW (ORCPT + 99 others); Tue, 10 Jan 2023 09:32:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238611AbjAJOcH (ORCPT ); Tue, 10 Jan 2023 09:32:07 -0500 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2069.outbound.protection.outlook.com [40.107.96.69]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C59C37277 for ; Tue, 10 Jan 2023 06:31:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Q/JmObhkl9+jyLJKujnwUdf3A3DrtJxXhgRyq1FwgDGFiLf95IqYUwbxpuC/YJs3o6umki19gr6nzTg0GpPYVF3E94QXZoEHbP+gI2ormeEpIyRlAApTm1dbMcCss9EqCq0YuQoXBz6B3mtVA0k+9K7s98BtiD1rY5cgH32PHvCdvBZErnYSzP0L9LI/lkPenFG7Tn/NWpDULI6lgPQ/cRZwMzo+kHPVCMPau+YztjbcVjRIKzqRfrIAzrupS0MHKj4NqKN7D8HVM5NtqfClP3TvmU4diJhktIwedcl9002Ygw9jNE1S2QkZXKp5niVjfgCHPAuBhlfEWiC7nzzNTg== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=rM/7rBbvFmTloP90cbfDESDHZVvtwEhdd3UXHRXpRbE=; b=jI5e35NZ/fbexZlrinfXUBFP5B28Kd81ND16CWii1ZrG18L/G2oJM2tdNXwapU3Qhw5TykgIiW95AjJmznHrukhXZ5MyLJm/o51v48vLY435p7n0/T12IxmemgZXk0kt2ulT2tSPRyM7YHbTe2Me2tcPJztgVRyivuBA6wxZHWujfgyqw1Ouni9FgTT25oV+6MqfCOSFEfm/uaDNeHGwR8u712v/G8/al4keF/gigJxFGQ3kOHVIHEVeV99jom9VBPDv13ActRH01Asjo65MP7VOIYCueehzvpQ3FjNNSKJCX6iPDgaT3/L1Euy9JmhIZUwoAnBo66CX03fpjNIkiQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); 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=rM/7rBbvFmTloP90cbfDESDHZVvtwEhdd3UXHRXpRbE=; b=YkaCjFPQJ9az6l+X5e2x+4Qk/WbImO2bR9CW26Vn454eRC04LOvx3cYnqm0gpiK1qb16SX1YQEi3nwZTlCiokfGkP5b9IP8WUmVS3JJy43aRrbT2XRw7ofzSECXFqJlkuExycRn9Y2YXzF6IszvAur8ngNNivz9ZPm6itVVAn90= Received: from BL1PR13CA0262.namprd13.prod.outlook.com (2603:10b6:208:2ba::27) by PH7PR12MB7892.namprd12.prod.outlook.com (2603:10b6:510:27e::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.18; Tue, 10 Jan 2023 14:31:56 +0000 Received: from BL02EPF0000C402.namprd05.prod.outlook.com (2603:10b6:208:2ba:cafe::e7) by BL1PR13CA0262.outlook.office365.com (2603:10b6:208:2ba::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.6 via Frontend Transport; Tue, 10 Jan 2023 14:31:56 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BL02EPF0000C402.mail.protection.outlook.com (10.167.241.4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6002.11 via Frontend Transport; Tue, 10 Jan 2023 14:31:56 +0000 Received: from sp5-759chost.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 10 Jan 2023 08:31:55 -0600 From: Suravee Suthikulpanit To: , CC: , , , , , , Suravee Suthikulpanit Subject: [PATCH 1/4] iommu/amd: Introduce Protection-domain flag VFIO Date: Tue, 10 Jan 2023 08:31:34 -0600 Message-ID: <20230110143137.54517-2-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20230110143137.54517-1-suravee.suthikulpanit@amd.com> References: <20230110143137.54517-1-suravee.suthikulpanit@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF0000C402:EE_|PH7PR12MB7892:EE_ X-MS-Office365-Filtering-Correlation-Id: 6dabf742-5c42-48e0-db5f-08daf3176cf5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: co8R8f9Oktuh1gclZtNKRE7ZNXRbHfPr1Z37K1wys51wAdVc+8NxhEsO6r9/hBaB7sD9nkD6+fKEXImu4ZPE+yc7O5olhEOpBdd0gELjcvjHJDCOm1K8J4AgYkwxlY4rFODY4Bl8SZe5u4Pg01BovutQWdmb/bpx4shM0piolyD6rcw6fJHSbkacnk+HZnrKh+/2KcPMQFFTCYe8RNeECB82qI/SqVrSHLgRHK5jkihf2EFN76YMl5MSA15UVScZ4/iGhmNgvAI4xD7+FkmbTI4LAsNnOQZSWUiTIR0omvmwR+cFGFWLzP6LLyEnmVSpj7oBOOGk8WnGmCFg4ilH4w282E48sjD1Inevjwovw1whJyxN/c1AbCFkmtRQX0v1cfRiZK+K811vFe+Ej1J3FbV1reMlZaEvqYLz19mWONXzaElHUGvPkFsjQaK+dmgSPzw0Qx92J9yPDcv/arTOw9WIyTqSvOhwLKqovtgq3cpjq3gU63p5vm1Pth/neUFZ0YG/poyoT21jxqq6xvB5El81lXCQerWjzq/XGlcwj7Ndf4OkmgWLDriO4pDgxc25UESy3/zPpqn2UEflLbtNQi4B7/zUbU6sbzTSKRtDLQKafHmfbjvWFkOy2EbBa6ZTri55qF5sVx9U1pj6e4ZeYSNC3JTric/C9aOaH+8Wug5NPvOEIdFSbm71C043bpZCX7A1LF9fV756OtHZ3t0VLgVsbAgVNp+pJ4znfxHEERE= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230022)(4636009)(346002)(136003)(396003)(376002)(39860400002)(451199015)(36840700001)(46966006)(40470700004)(36756003)(316002)(54906003)(40460700003)(186003)(2906002)(110136005)(82740400003)(478600001)(356005)(81166007)(86362001)(36860700001)(44832011)(40480700001)(16526019)(2616005)(26005)(6666004)(83380400001)(70586007)(5660300002)(7696005)(41300700001)(336012)(1076003)(8676002)(426003)(8936002)(47076005)(4326008)(70206006)(82310400005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jan 2023 14:31:56.3726 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6dabf742-5c42-48e0-db5f-08daf3176cf5 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BL02EPF0000C402.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB7892 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=ham 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-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754646432587472909?= X-GMAIL-MSGID: =?utf-8?q?1754646432587472909?= Currently, to detect if a domain is enabled with VFIO support, the driver checks if the domain has devices attached and check if the domain type is IOMMU_DOMAIN_UNMANAGED. To be more explicit, introduce protection-domain flag PD_VFIO_MASK to signify an VFIO-enabled domain is enabled with VFIO support. Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/amd_iommu_types.h | 1 + drivers/iommu/amd/iommu.c | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/amd/amd_iommu_types.h b/drivers/iommu/amd/amd_iommu_types.h index 1d0a70c85333..ad124959a26a 100644 --- a/drivers/iommu/amd/amd_iommu_types.h +++ b/drivers/iommu/amd/amd_iommu_types.h @@ -439,6 +439,7 @@ translation */ #define PD_IOMMUV2_MASK (1UL << 3) /* domain has gcr3 table */ #define PD_GIOV_MASK (1UL << 4) /* domain enable GIOV support */ +#define PD_VFIO_MASK (1UL << 5) /* domain enable VFIO support */ extern bool amd_iommu_dump; #define DUMP_printk(format, arg...) \ diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index 3847f3bdc568..681ab1fdb7d5 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -2056,6 +2056,8 @@ static struct protection_domain *protection_domain_alloc(unsigned int type) mode = PAGE_MODE_NONE; } else if (type == IOMMU_DOMAIN_UNMANAGED) { pgtable = AMD_IOMMU_V1; + /* Mark unmanaged domain for VFIO */ + domain->flags |= PD_VFIO_MASK; } switch (pgtable) { @@ -2130,6 +2132,7 @@ static void amd_iommu_detach_device(struct iommu_domain *dom, struct device *dev) { struct iommu_dev_data *dev_data = dev_iommu_priv_get(dev); + struct protection_domain *domain = to_pdomain(dom); struct amd_iommu *iommu; if (!check_device(dev)) @@ -2144,7 +2147,7 @@ static void amd_iommu_detach_device(struct iommu_domain *dom, #ifdef CONFIG_IRQ_REMAP if (AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir) && - (dom->type == IOMMU_DOMAIN_UNMANAGED)) + (domain->flags & PD_VFIO_MASK)) dev_data->use_vapic = 0; #endif @@ -2176,7 +2179,7 @@ static int amd_iommu_attach_device(struct iommu_domain *dom, #ifdef CONFIG_IRQ_REMAP if (AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir)) { - if (dom->type == IOMMU_DOMAIN_UNMANAGED) + if (domain->flags & PD_VFIO_MASK) dev_data->use_vapic = 1; else dev_data->use_vapic = 0; From patchwork Tue Jan 10 14:31:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suravee Suthikulpanit X-Patchwork-Id: 41498 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2779959wrt; Tue, 10 Jan 2023 06:33:58 -0800 (PST) X-Google-Smtp-Source: AMrXdXvvpjer8xFIxVI1kChbV/OKyCudqyOtCzL+Vv/pqkCmpFgwUGlz4b/B4KWA0w8diTikgGMP X-Received: by 2002:a17:907:7416:b0:85c:c4be:5704 with SMTP id gj22-20020a170907741600b0085cc4be5704mr26225ejc.22.1673361238317; Tue, 10 Jan 2023 06:33:58 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1673361238; cv=pass; d=google.com; s=arc-20160816; b=ujE7q16I+4wKtb+hXB+U5lXb/wtCPbnTZiHcJoqMDouAId+pBqc9UDWxvU5sJQpOjm Ipz3TrMnTBOy7c+j4mFs5ezi+vGVYXcLp0VGWJmcQphSKSkNWGOEUyRRHVKarbmryQqk r447bJeSJYO8TOUvN9BgIr2EuHpY1ykmaOT/4rha/YmforijJn3dtUWpuenuFbZr5V97 P1/Kn6CUbjX0H4KE5KGYPt3AM3OkNJHnWf4Pjh2uoDtOW6ELKm4ieBxRVBO49SOgifQY 2ISgAbTLFX/JncB51XbIvZxkAS6sm88EMEX/aY+WgoqRRyOBF7ax8nT48bpau1uE7BVH s75g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=fjUmZ8NdtlWmtG6YX+A6YHtPFOZFATTgkzAlw3oUF1k=; b=yrXD2HtIazedxCdrVUYZdOtnSBaj5RevcxYa9LkdK/nBR3UG1hhcYdZ/EaEpV112Pv rOj5xQ5aprw3kHCgJsGJefBzoARmuzdT2pp7tOEvGQzouzQh6ZuDjq6Yc4AxPQ2CvgL2 1pt+poUVCC+2oTnAZV7m18HGSiSRr16zNkzNk4jgjpijAqKi/W0RFmGD70wxq5Bzttu+ K/q4ScN8YCIvPrKKLCUX0qddi2mb/6n1jk9mMmhYIMD5sIQ3sLPel2XTdr0LVbmLbqH9 /bClMm0S78pB5WStGpN0z0UlUgh10mxWnCzen+Gr5qbPG+jCHpSXTe0hhh8oKcyaMwhg J7ig== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=Slzmlgdu; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id xa5-20020a170906fd8500b0084d3fbc7accsi5509410ejb.492.2023.01.10.06.33.33; Tue, 10 Jan 2023 06:33:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-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=@amd.com header.s=selector1 header.b=Slzmlgdu; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-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 S238497AbjAJOce (ORCPT + 99 others); Tue, 10 Jan 2023 09:32:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238686AbjAJOcS (ORCPT ); Tue, 10 Jan 2023 09:32:18 -0500 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2059.outbound.protection.outlook.com [40.107.220.59]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 000C6DFF7 for ; Tue, 10 Jan 2023 06:32:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bjFOBr/CrC/3iXjeKExbK4XJg5iC/fGJqcwq2OtholnDYIlQGgs5DlFR5pL6xYesMGLcvANpHbalqa+UN168YES0nfqFo5Do711QRJbIe93nvlsfXWrG+udurZPu89reuSOxqLOMfLHRf5XVb6InnrO/qoOJbX0RmjBgBuaujoRcIW/IRgTUnS2GEmOnWMgOfcqrwg/UujhbhomZ17VLSLy7DWtOarY1Ce6e1YHeSUvzzM3kjtufPcxa7FX+TJzk2Yn6wmRCIotEbpl14Qaop3n0Xc4+Us4ddyjRpASy9bzkwtYxSXHWYWoVsFld+rC2uaeuc8CpnB4m9l9nNyu2LA== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=fjUmZ8NdtlWmtG6YX+A6YHtPFOZFATTgkzAlw3oUF1k=; b=BSXq0Ub18jctUcaomiZOPEJuaTOG6yVrEf2p1uwSin9YznzF1i1bZmLblO/paub++HyBtYYdty89enU1g3td92DhlOc3NkYu/BH+GZhYx9VRdz9EtoDTEwz3BwhkpFRcB8nmviQnqpfX2qhqOmsjWpWwNx6Ns/4K4u3wNrWPQp3mvZByX2gvZn3SzPCSJ/8kDSOt5GRW0IkgNN3qQc1WqkYAihbntxNHVM/X/10HuC2gTWHPYqppOtGm5yvTuGGNDoafHEPSxmWynICifdbkADcvcg/B2vylwJe2PHoJf4HYsfrYgRTBRW5Fhg/xIT1L0lu7FOIPfVwQNgVLd6RzUQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); 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=fjUmZ8NdtlWmtG6YX+A6YHtPFOZFATTgkzAlw3oUF1k=; b=SlzmlgduzTZlxki7/KkCAVOTZlzAtVzSgrYsGFDorPxILs23qpt7OWeBAhkUDtLo8NZRkpE42SFMiEywMWfYycTAyI/8DB37oqHh53w9F67cenVaeW+G8UW2GAwwCTMEoW0irioCsBELmoeCGk00hC/2b+mgtYnaO4VDw3NwZfs= Received: from BN9PR03CA0552.namprd03.prod.outlook.com (2603:10b6:408:138::17) by IA1PR12MB6601.namprd12.prod.outlook.com (2603:10b6:208:3a3::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.18; Tue, 10 Jan 2023 14:32:16 +0000 Received: from BL02EPF0000C408.namprd05.prod.outlook.com (2603:10b6:408:138:cafe::a3) by BN9PR03CA0552.outlook.office365.com (2603:10b6:408:138::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.15 via Frontend Transport; Tue, 10 Jan 2023 14:32:15 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BL02EPF0000C408.mail.protection.outlook.com (10.167.241.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6002.11 via Frontend Transport; Tue, 10 Jan 2023 14:32:15 +0000 Received: from sp5-759chost.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 10 Jan 2023 08:31:55 -0600 From: Suravee Suthikulpanit To: , CC: , , , , , , Suravee Suthikulpanit Subject: [PATCH 2/4] iommu/amd: Introduce structure amd_iommu_svm_ops.is_snp_guest() Date: Tue, 10 Jan 2023 08:31:35 -0600 Message-ID: <20230110143137.54517-3-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20230110143137.54517-1-suravee.suthikulpanit@amd.com> References: <20230110143137.54517-1-suravee.suthikulpanit@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF0000C408:EE_|IA1PR12MB6601:EE_ X-MS-Office365-Filtering-Correlation-Id: 28d072e2-52e0-4af3-adf7-08daf317787e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: mkWHGL76rdfUP0fA6okYx/6FuaKVHEkFSH3YB5BHi0kt8+nXWITQ4hAV4c5oXnn4vJQ9kCSEp2j5KH1H03ajg3qEFt+GfxRVXgN4OLnA4ZB7KVjs2TnI+IzTfmtRmwsdTyTC0bOnNoxzfuXtnK8uJfL8GM8D5aDM+PDi/ciYUdmuoSoFOWJ9sEXtouVX/MXms0GOIxPPqG5OEQwUiM362yOkxGwPPOEoPmRcW28e9ir3cmSt38FUYqvIfVyynlpKyFzCS6cZM9QQSU6icBBxI/1mbh4SMOAEiC2S5Oq5z0r+msbJkYmxwTbsvXUXMrrD68XOo3lbpCidDGo2LLWwi2BQo6ptewkg1wa5EDNN8PRmX8stdXKwLWKAvPdRBqvOKdLl+HQMcs66jSm0ZQ1C8biYpO2m7HRD+SVSR5bFS0SfwlJOajXNuoEIV9en3D5aV52yt/B6obT14rzQ/jg2ELIYLwaKJdjCWIJeEgQ0TuUsdKiBpdcYgYyoOrY2N9ciNlOfN0BN544rE9tOVoDtAnbNU1XI1y4NCd9KwWMVmnDcOWtb2LvDKLlyndQazJNbejqFbnaWcLQXVl6lm+3Tzyc+DAXt5pcSyse14wqAEOyvuTdPpteuWA8Ydnngou1/EVEp/IjTS5j4tL7MBzUnJVBYT50N8jpl5ZBeX9MKbWZhQXySQZefs1bnGuIilOzJBfi4DgoQFXoE+FoRHU+qNIJ0FWjStpNdNoxT+v24CpA= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230022)(4636009)(396003)(376002)(39860400002)(346002)(136003)(451199015)(46966006)(40470700004)(36840700001)(82740400003)(356005)(81166007)(8676002)(54906003)(86362001)(70206006)(4326008)(83380400001)(70586007)(40460700003)(110136005)(41300700001)(426003)(5660300002)(2906002)(44832011)(316002)(8936002)(2616005)(1076003)(82310400005)(40480700001)(336012)(16526019)(186003)(26005)(47076005)(6666004)(7696005)(36860700001)(478600001)(36756003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jan 2023 14:32:15.7243 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 28d072e2-52e0-4af3-adf7-08daf317787e X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BL02EPF0000C408.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6601 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=ham 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-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754646433895264159?= X-GMAIL-MSGID: =?utf-8?q?1754646433895264159?= The structure can be used to provide call-back functions, which are called by the AMD IOMMU driver when it needs to handle certain operations. SVM driver can define handler for each operation in the struct amd_iommu_svm_ops and register the structure using the amd_iommu_register_svm_ops() function. Initially, it contains a function pointer is_snp_guest(), which is used to check whether SNP is active for a KVM guest. Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/iommu.c | 10 ++++++++++ include/linux/amd-iommu.h | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index 681ab1fdb7d5..a03723930f70 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -754,6 +754,16 @@ static void iommu_poll_ppr_log(struct amd_iommu *iommu) } } +static const struct amd_iommu_svm_ops *amd_iommu_svm_ops; + +int amd_iommu_register_svm_ops(const struct amd_iommu_svm_ops *ops) +{ + amd_iommu_svm_ops = ops; + + return 0; +} +EXPORT_SYMBOL(amd_iommu_register_svm_ops); + #ifdef CONFIG_IRQ_REMAP static int (*iommu_ga_log_notifier)(u32); diff --git a/include/linux/amd-iommu.h b/include/linux/amd-iommu.h index 953e6f12fa1c..d4837af75550 100644 --- a/include/linux/amd-iommu.h +++ b/include/linux/amd-iommu.h @@ -11,6 +11,7 @@ #include struct amd_iommu; +struct kvm; /* * This is mainly used to communicate information back-and-forth @@ -26,6 +27,10 @@ struct amd_iommu_pi_data { void *ir_data; }; +struct amd_iommu_svm_ops { + bool (*is_snp_guest)(struct kvm *kvm); +}; + #ifdef CONFIG_AMD_IOMMU struct task_struct; @@ -205,6 +210,7 @@ int amd_iommu_pc_set_reg(struct amd_iommu *iommu, u8 bank, u8 cntr, u8 fxn, int amd_iommu_pc_get_reg(struct amd_iommu *iommu, u8 bank, u8 cntr, u8 fxn, u64 *value); struct amd_iommu *get_amd_iommu(unsigned int idx); +int amd_iommu_register_svm_ops(const struct amd_iommu_svm_ops *ops); #ifdef CONFIG_AMD_MEM_ENCRYPT int amd_iommu_snp_enable(void); From patchwork Tue Jan 10 14:31:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suravee Suthikulpanit X-Patchwork-Id: 41496 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2779946wrt; Tue, 10 Jan 2023 06:33:57 -0800 (PST) X-Google-Smtp-Source: AMrXdXucKIE2YWdYUaThFTCb8RatlbQvrO/9BsLb9C2ABFT5fh4t33ePve4bokeGwA7ri2C5jNZM X-Received: by 2002:a17:907:c689:b0:84d:122d:4af3 with SMTP id ue9-20020a170907c68900b0084d122d4af3mr17512746ejc.27.1673361237139; Tue, 10 Jan 2023 06:33:57 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1673361237; cv=pass; d=google.com; s=arc-20160816; b=RwqTUUJhjKEU3HoOTZwJg06p6GgxtMN/mrpkWvzwL5etSLfbjw8Fwgvo5VZbqWgNXO Tl+i+2+EXoq4K7wtQ5+n7ACIjiGvR1PBWJmXs8LLRVJhrgr1klf0FNDLcxT5TA/2sYDK dGE0DCfQ5kDKpbxYbW/DDfGAbE0tcbkHkW5/cHjDhhP2IeHJx+FcgY6EeYxvE58GZwNv Wc92m2QAVv7wg0A+PvRtm7bp1EZdg8iDxaowsEIw+XDOH8DW+gm3qkkFQACN04F+KpFY 5m8DaQMxLPQjsy84Qj3XLBiia4isV4UlheOKPP3lPJ4+GPoL/q174bX/HL8nq8epn83Q 2/9Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ObSra1/iNsAygRiv1o7a006n18bIyMdju24xnrqtOsQ=; b=fPG8ZAVqWVxj41K28BTjdUvGD81YCDfU7Fufx0vos6TcFbufV51PGQ8P364QTw4XdC 3XYQV5ZKeTXrRHWLXUsohX0DWHb9cleotp2FKJ00eZaXNqpUfp9sEcdoqTEgazKJW+E/ w2NJ7g84FPcZxpkzIpm3uvoDGFCoLlqQDMGtiZgh5yLQ/xk4q2ONx1EQ0tgkhg/6C5+4 sWi+T0YS6rJhoBFJf3Okn4+wpLbujkIHQh8k7UiB6EHvtiqMuJw5r6Yt8faFjn1zMzXv a7HmVPiRBhNRkm7IqnQiFvJ0gKOWl8G+xv8cIZTE0z0pJhUCET2NTcYp5om8U70HkTyv xi4Q== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=qkjD0Mss; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gt33-20020a1709072da100b007f20a95eae0si13463875ejc.262.2023.01.10.06.33.33; Tue, 10 Jan 2023 06:33:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-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=@amd.com header.s=selector1 header.b=qkjD0Mss; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-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 S238481AbjAJOcx (ORCPT + 99 others); Tue, 10 Jan 2023 09:32:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49052 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238529AbjAJOcX (ORCPT ); Tue, 10 Jan 2023 09:32:23 -0500 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2055.outbound.protection.outlook.com [40.107.223.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B537435920 for ; Tue, 10 Jan 2023 06:32:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eWi6imvJdllrdjJConVgEzKBdURG6IimciYyLUY7uBnHTV+MjwuhefSorgjEA+jC2aKfVP4o+0loEqmL+jEs7jhU0d5ZaXPmPHkgBYakaFgeu8VeaCH/tdpakSw3NMcSHwUw0/r5iyiL5m/eWCOfvOvnS20QtHejRt9z8EBWyQDsX508MinqJNCM9K0vvLNsW/gsBfHNWiyuOiaOVhNhQw2VHlvkVHo7IOYwknduFMPivfO0GAPv0+TNNQGVTzXN/z2YoTws8yJNTFZwBJuu1YwJZjm6EEUbM804qMJk0WrGz5AS3GmqbnTOQWhnFD/VYOJR0YQjjORjHALksqDqPQ== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ObSra1/iNsAygRiv1o7a006n18bIyMdju24xnrqtOsQ=; b=izP8FD3BupP/F8sm++VbTGWEq9NrvUouYy9Rh4dZsgkx9JsuiODImwl4+ZmLsd0cMZu82ZBYI5/348ijBWhqO3Hr2JDZDTvz8ZYPjs7XjHPn07b4uFovGAYBo1p+2lIluevBVL9I6j1GusXa9aj3R7AYjp+vbIhF2/mXNB1h3AKfZ96LmLQov0FIO68gQ0Z8TTeDd1wNfQ7PnKGCJznbO89/44Je04NqH/08yzDpQ9DOo2vefVdFH/WbQBenWAplclI1MwXvmirui8U1VUtmk8phShfHacWtsolhpCsw9JhAe4TQ7ZdtCzi4FpzfX3AryKGVm+zg9Is7SlORuOnnAg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); 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=ObSra1/iNsAygRiv1o7a006n18bIyMdju24xnrqtOsQ=; b=qkjD0MssUalUPgwmfPczvbeKOGF+dw5WjDhtEmNxdEJ79jpIucKJzVBoSc7gtKEMnMbk5bNWAF/hEpYJUqWOmU3C8kYmaiXNDPCAVIyAargBypvF9wH734xrRv5KlSziMNo/ZdaFsbMqHixDJC7hdvJMxwq9zolmifOKUNnwyTk= Received: from MN2PR15CA0010.namprd15.prod.outlook.com (2603:10b6:208:1b4::23) by DM6PR12MB4960.namprd12.prod.outlook.com (2603:10b6:5:1bc::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.18; Tue, 10 Jan 2023 14:32:20 +0000 Received: from BL02EPF0000C404.namprd05.prod.outlook.com (2603:10b6:208:1b4:cafe::cb) by MN2PR15CA0010.outlook.office365.com (2603:10b6:208:1b4::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.18 via Frontend Transport; Tue, 10 Jan 2023 14:32:20 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BL02EPF0000C404.mail.protection.outlook.com (10.167.241.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6002.11 via Frontend Transport; Tue, 10 Jan 2023 14:32:20 +0000 Received: from sp5-759chost.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 10 Jan 2023 08:31:56 -0600 From: Suravee Suthikulpanit To: , CC: , , , , , , Suravee Suthikulpanit Subject: [PATCH 3/4] iommu: Introduce IOMMU call-back for processing struct KVM assigned to VFIO Date: Tue, 10 Jan 2023 08:31:36 -0600 Message-ID: <20230110143137.54517-4-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20230110143137.54517-1-suravee.suthikulpanit@amd.com> References: <20230110143137.54517-1-suravee.suthikulpanit@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF0000C404:EE_|DM6PR12MB4960:EE_ X-MS-Office365-Filtering-Correlation-Id: 7be5586d-05a8-4307-d13e-08daf3177b6b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sGxayu5ztePtiY4bjXpfNqFmhifipGaWnnyoF8DrcxhiBLscdInjdwDUiCb5xNuhJzir9gTG/v/J+fLSSt1g661aSrmGTHIF5wBm8ZizWAMmnQ/LYfwkVusVRSC8L81xpFcHHPb1494D2KXoa7a38K9B4IdayD8roL9DinhQIsnSNvLgSeDf8NmCtiM/GfQY0p+EeWVx/ujCkcH2GfmOsfcxj9+Q0of8CBZXxwoKJlhb65xY/d3yEQSSpH2fG6nC/7F/vUJGmhhmVkpfGcKf+knWpTckV/KozyDZ2CQ00Plm3N9gWVK94teMLxmCWPBEjDVCz+oiibjW8iGQutgmbrdUjqWMLi4LN/6uEOMUWMRrsECFwujjEXaJ5BHkzz2OgsiblykhcGYSvPosG9oRNzWwpeF+vaPsl3eIclRcEpYaC1y+m5UjCiG/xz8dgBQUChuXKkeMfSCZNN9Nz1QH4w+trQNffk3SwAFYuBozx3Mv1rSg+QvAWKaCb2a9eo4ezjqYZ43yNJlGmJvDGNn+LrmLWof5FtrJPPZIYGnkPNWFjW5vztMsAh7DDv3T2QMWkRKNbHhDrgzRS6qSdq9uzexPVDNA3b8/XnN1Fqs4PgIc3FwZ/4RgowNO1ol2YuBv7TaMaDaZ72OwXzO1YZgrbFDDfBNUpmSZlLz6GDhXO5iOzUYMcdTj5adZgEOHuwLF08xhnJwfU6BQXQjkpz8hYUYcUDyksxojL4mFoNWblBc= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230022)(4636009)(346002)(39860400002)(396003)(376002)(136003)(451199015)(46966006)(40470700004)(36840700001)(36860700001)(82740400003)(2906002)(6666004)(81166007)(356005)(2616005)(1076003)(26005)(44832011)(7696005)(186003)(16526019)(40480700001)(478600001)(316002)(5660300002)(82310400005)(8936002)(83380400001)(36756003)(86362001)(47076005)(426003)(40460700003)(41300700001)(70586007)(8676002)(70206006)(4326008)(54906003)(336012)(110136005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jan 2023 14:32:20.6338 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7be5586d-05a8-4307-d13e-08daf3177b6b X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BL02EPF0000C404.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4960 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=ham 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-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754646432624926401?= X-GMAIL-MSGID: =?utf-8?q?1754646432624926401?= Currently, VFIO provide an kvm_vfio_file_set_kvm() interface for assigning a KVM structure to a VFIO group. The information in struct KVM is also useful for IOMMU drivers when setting up VFIO domain. Introduce struct iommu_domain_ops.set_kvm call-back function to allow IOMMU drivers to provide call-back to process the struct KVM assigned. Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/iommu.c | 10 ++++++++++ drivers/vfio/vfio_main.c | 1 + include/linux/iommu.h | 4 ++++ 3 files changed, 15 insertions(+) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 65a3b3d886dc..5116d5fe35f2 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -3231,3 +3231,13 @@ bool iommu_group_dma_owner_claimed(struct iommu_group *group) return user; } EXPORT_SYMBOL_GPL(iommu_group_dma_owner_claimed); + +void iommu_set_kvm(struct iommu_group *group, struct kvm *kvm) +{ + if (!group || !group->domain || !group->domain->ops) + return; + + if (group->domain->ops->set_kvm) + group->domain->ops->set_kvm(group->domain, kvm); +} +EXPORT_SYMBOL_GPL(iommu_set_kvm); diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c index 2d168793d4e1..7641e3a0c986 100644 --- a/drivers/vfio/vfio_main.c +++ b/drivers/vfio/vfio_main.c @@ -1652,6 +1652,7 @@ void vfio_file_set_kvm(struct file *file, struct kvm *kvm) mutex_lock(&group->group_lock); group->kvm = kvm; + iommu_set_kvm(group->iommu_group, kvm); mutex_unlock(&group->group_lock); } EXPORT_SYMBOL_GPL(vfio_file_set_kvm); diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 3c9da1f8979e..43000231d3d7 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -42,6 +42,7 @@ struct notifier_block; struct iommu_sva; struct iommu_fault_event; struct iommu_dma_cookie; +struct kvm; /* iommu fault flags */ #define IOMMU_FAULT_READ 0x0 @@ -314,6 +315,8 @@ struct iommu_domain_ops { unsigned long quirks); void (*free)(struct iommu_domain *domain); + + void (*set_kvm)(struct iommu_domain *domain, struct kvm *kvm); }; /** @@ -391,6 +394,7 @@ void iommu_device_sysfs_remove(struct iommu_device *iommu); int iommu_device_link(struct iommu_device *iommu, struct device *link); void iommu_device_unlink(struct iommu_device *iommu, struct device *link); int iommu_deferred_attach(struct device *dev, struct iommu_domain *domain); +void iommu_set_kvm(struct iommu_group *group, struct kvm *kvm); static inline struct iommu_device *dev_to_iommu_device(struct device *dev) { From patchwork Tue Jan 10 14:31:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suravee Suthikulpanit X-Patchwork-Id: 41499 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2780518wrt; Tue, 10 Jan 2023 06:34:58 -0800 (PST) X-Google-Smtp-Source: AMrXdXurzbEuH7N5SI/HxiLu9s8poMCpiLATBHKqQoARSFNEULpdhn6RRlGtCBQ7d9S5jTySr7EQ X-Received: by 2002:a17:907:7e9f:b0:7c1:7d81:d2a8 with SMTP id qb31-20020a1709077e9f00b007c17d81d2a8mr70700011ejc.3.1673361297899; Tue, 10 Jan 2023 06:34:57 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1673361297; cv=pass; d=google.com; s=arc-20160816; b=tNk56xhte2vvuZnbZZYU9f9OpHIDT8LCsAYNrHhvqbzGnYRwmUvg/NaOJnN21cfINH OT5NBt9yO5NVHccmLwcuKKZbzKHio60yWnz7JigV7JfM6Wk1rdGzSzuVHPiue5Zt1+wN hYPe99e7qhoK2f37gNSQOF9F+X8h3OF7gfiIZHOBF3K9HKul3PbF+GUl+oO4pepx5qMq tWgMleHKQXFgn8VA+FKO6MZUY5SUEOOaKk7PHwc5I1NdUtJsFYM5fVggNo9fdoKfKokk pL9jzCCs/wXf5hVOMlNSRUFOT6EoQQStLXUDYvN33bDet+EgliJT7HGT9QoW2Q+uMnbn zOLA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=4Hml2OgICGSdq5+zxCec5xRf761M3ZO15RZ+4MkXikk=; b=enWiZUpOcJYNbTh2FspHLWcVwmpn2mNaQWU651BjET2Kh6PsbMzl3oOhtj/tYntf6H MP502+wF5di9c5EivCKyy/eT3wadrPleOXgvJaXOSVm3HnQCxzFtZ8yEoc22UFzfCT3C uFzuGh7t36Qi4jJ1RyjOgUtq5dXyQhW8FbPSgjgTlwZZ0fIj+m6kp9DzK07q+6P2pgir KvpIebrjDohECBZI++6d2XU+upUr8tHXCu/CiKInbdj767DOCNmtnxdkdCTf5l+yBVUR UI7U8HzwP7R1bTlve10UF7nA5fxCvoAH3uS40ChNlJf2lw10Mdx233Yobr59Z4KRjA86 PYGw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=O5TrMh2Z; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id be13-20020a1709070a4d00b0084ca4bdbc7asi11480152ejc.780.2023.01.10.06.34.32; Tue, 10 Jan 2023 06:34:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-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=@amd.com header.s=selector1 header.b=O5TrMh2Z; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-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 S238617AbjAJOdA (ORCPT + 99 others); Tue, 10 Jan 2023 09:33:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238540AbjAJOcZ (ORCPT ); Tue, 10 Jan 2023 09:32:25 -0500 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2080.outbound.protection.outlook.com [40.107.237.80]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDA42392DB for ; Tue, 10 Jan 2023 06:32:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XRP/fqwjHyK6qLS/VpSQi10ghPsSvmD2qbo+4bm2qeVt3NYMc7n8VC50A+Ht+i1cw9pOGmruk3WcrVZubtIebzzZTyBP324QpimoPscrw9RLHjPjh43kcf4aW744jbLy09ZD58Se/HmgSghb6GwNMWBMMgWpEOqHN31JR7VY/cYBraC22YC9GDq7rn0ITHNQ+uSC6O3Vrg9dc+0ZDzsDgpP2oLT48OE2d2+VtWS2OX7zcEVXtU7OjjS/iELjz3tw2WKAAbbRQ14hWTfXiHr5hYu4MIBQddDNCJYFwDTSyAMT1A2cps8QAHyjF/MhLyCyGl3NZVZRPFShOAWY0S+kGg== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=4Hml2OgICGSdq5+zxCec5xRf761M3ZO15RZ+4MkXikk=; b=kEdxUk2fHdjQ2Gzw+eESpunJ2Dk814Glytl3mIBldTc1IiVv6vLQFk9m8HiFdgEYApux7C87D/fs4aBbEPVy1/joeHxXB5pXfjf5KWlFKkwr3BxbW/IE/5uchzecIpxujZXmtLt5H/DCZBrEWL2IbFlWNn2ltxTzQ8JAdSJ3Y5voU3Dpu+58WMwJtAMLwDtoOxylqWRxLBKpdKbXh3S9VVVpzUsiZpBEYEUJIqgbxX1pUVyhEWAPSkCf4e5vYwrFSMpAQZHTQb9ocGmdq6WGEXBrIIgPr1Tjngru8gLTSi8CnExQK3RdG4V9SPpqnyeWyPh2MhQQmGvsCJkDmiOaDA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); 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=4Hml2OgICGSdq5+zxCec5xRf761M3ZO15RZ+4MkXikk=; b=O5TrMh2ZGy2CVChOeJMxD6u4ZxiucsM4vEbq8fqj/0P7tg3PaJEA9F3u/UFk3s+QzU2QcMjponkTyaLSedXFXM6xj5ln78gCUDFXycFgGvdWm68PpmAvv9Y7xrP3LTqcUxwPRLUBGIujPGAI5oYovAnFJW4c3QOa6jM0k4Ir9Yc= Received: from MN2PR15CA0010.namprd15.prod.outlook.com (2603:10b6:208:1b4::23) by CH3PR12MB7548.namprd12.prod.outlook.com (2603:10b6:610:144::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.18; Tue, 10 Jan 2023 14:32:21 +0000 Received: from BL02EPF0000C404.namprd05.prod.outlook.com (2603:10b6:208:1b4:cafe::cb) by MN2PR15CA0010.outlook.office365.com (2603:10b6:208:1b4::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.18 via Frontend Transport; Tue, 10 Jan 2023 14:32:21 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BL02EPF0000C404.mail.protection.outlook.com (10.167.241.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6002.11 via Frontend Transport; Tue, 10 Jan 2023 14:32:21 +0000 Received: from sp5-759chost.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 10 Jan 2023 08:32:15 -0600 From: Suravee Suthikulpanit To: , CC: , , , , , , Suravee Suthikulpanit Subject: [PATCH 4/4] iommu/amd: Force SNP-enabled VFIO domain to 4K page size Date: Tue, 10 Jan 2023 08:31:37 -0600 Message-ID: <20230110143137.54517-5-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20230110143137.54517-1-suravee.suthikulpanit@amd.com> References: <20230110143137.54517-1-suravee.suthikulpanit@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF0000C404:EE_|CH3PR12MB7548:EE_ X-MS-Office365-Filtering-Correlation-Id: a3042d14-b2d6-448b-a695-08daf3177bc1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: F3wq/UUgiK6IHLmMEwGaKfEHuayOXsVMDi7GrVIx/4w479hmtJtFit/ADT2G+x2G2DEosafxZwVjuJ/1uZKmiqxP4IBEBh6N7hXAn4rl65F7OQDy9xUSf35AjZgQZwJDrPq3YfB3BIjX6CC2sG7GVaNYJ9AeCDcZ1Bgkm3eEIwFZuG2/MRvaDdpf4v29EVWozWuydr7KnREjYQisoBx5KIGEVrQYqDnRSTocGNlKXOJYFxZfmhnq6FlqBM7/IDK0horNTQu3vb8uFmtAqxZbWdR90OqWvE/j0rU2WVY0i05l8RNNQHWwMAAi2CuyEZJW1J3dgnsyTXDWtdn39j8O2/K6Edt9mp1hK/NEsq3FkNJSyCIBuCR23OOI4gSbXB6SrlRWfgMpK3aK49BAVqXxQCzVbiSCaUXvsaqiHEeqyu9G1jsFoS9GW6Q11Yq/cwNSEC+tONXJbOcy1d4NXrTgliNc2OTkeUjxXG7s3ltufhOltZpWC5bSE1Wmf4Aj5o0aDQjoPZ94u2krhkbN8ALaAf0S08U8pu7MFRy6WL/0TLtjdmsqkEk4ofYTnVngVfKCS+R9WF9OpmaUkt1FOhU+G6YVkJN+JWx2uBihgkAtPX49CI3mqHnBEas0DZRq74XYuQ1EonL4IPWxgt4xSYhPa8hU7DpeRfYCNxTcnunW7JqqMl9n+077otjiOgDDJcDZt6fgIp1+h3Hs95DqHgmBfF3j/03oza5GtNoZ1+3pGwc= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230022)(4636009)(396003)(376002)(39860400002)(136003)(346002)(451199015)(36840700001)(46966006)(40470700004)(44832011)(8936002)(2906002)(5660300002)(4326008)(70586007)(8676002)(70206006)(41300700001)(82740400003)(82310400005)(40480700001)(426003)(40460700003)(316002)(47076005)(336012)(6666004)(36756003)(36860700001)(54906003)(86362001)(26005)(2616005)(186003)(110136005)(16526019)(1076003)(7696005)(478600001)(81166007)(356005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jan 2023 14:32:21.1963 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a3042d14-b2d6-448b-a695-08daf3177bc1 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BL02EPF0000C404.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB7548 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=ham 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-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754646423163741625?= X-GMAIL-MSGID: =?utf-8?q?1754646496111996504?= SNP only supports 2M and 4K page sizes. Other page sizes requires page smashing to supported sizes. For SNP-enabled guests with pass-through devices (via VFIO), it also requires RMP and IOMMU page sizes to match. To simplify the support, for SNP-enabled guest, SNP will smash guest pages to 4K page size only, and IOMMU driver will setup the IOMMU v1 page table for the VFIO domain of the guest to match the 4K page size. Co-developed-by: Vasant Hegde Signed-off-by: Vasant Hegde Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/amd_iommu_types.h | 2 ++ drivers/iommu/amd/iommu.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/drivers/iommu/amd/amd_iommu_types.h b/drivers/iommu/amd/amd_iommu_types.h index ad124959a26a..5249ac18ce6e 100644 --- a/drivers/iommu/amd/amd_iommu_types.h +++ b/drivers/iommu/amd/amd_iommu_types.h @@ -279,6 +279,7 @@ #define AMD_IOMMU_PGSIZES ((~0xFFFUL) & ~(2ULL << 38)) /* 4K, 2MB, 1G page sizes are supported */ #define AMD_IOMMU_PGSIZES_V2 (PAGE_SIZE | (1ULL << 21) | (1ULL << 30)) +#define AMD_IOMMU_PGSIZES_4K (PAGE_SIZE) /* Bit value definition for dte irq remapping fields*/ #define DTE_IRQ_PHYS_ADDR_MASK (((1ULL << 45)-1) << 6) @@ -440,6 +441,7 @@ #define PD_IOMMUV2_MASK (1UL << 3) /* domain has gcr3 table */ #define PD_GIOV_MASK (1UL << 4) /* domain enable GIOV support */ #define PD_VFIO_MASK (1UL << 5) /* domain enable VFIO support */ +#define PD_SNP_MASK (1UL << 6) /* domain enable SNP support */ extern bool amd_iommu_dump; #define DUMP_printk(format, arg...) \ diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index a03723930f70..9a1b010a7d00 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -2422,6 +2422,33 @@ static bool amd_iommu_enforce_cache_coherency(struct iommu_domain *domain) return true; } +static void amd_iommu_set_kvm(struct iommu_domain *domain, struct kvm *kvm) +{ + struct protection_domain *pdom = to_pdomain(domain); + + if (!amd_iommu_snp_en || !amd_iommu_svm_ops || + !pdom || !(pdom->flags & PD_VFIO_MASK)) + return; + + /* + * The parameter kvm can be NULL when calling from kvm_vfio_group_del() + * and kvm_vfio_destroy(). + */ + if (!kvm || + !amd_iommu_svm_ops->is_snp_guest || + !amd_iommu_svm_ops->is_snp_guest(kvm)) + return; + + /* + * VFIO Domain for SNP guest requires IOMMU and RMP page-size to match, + * which can only support 4K and 2M. Currently, only support 4K + * IOMMU page-size. + */ + pdom->flags |= PD_SNP_MASK; + pdom->domain.pgsize_bitmap = AMD_IOMMU_PGSIZES_4K; + pr_debug("%s: Force domain %u page size to 4K.\n", __func__, pdom->id); +} + const struct iommu_ops amd_iommu_ops = { .capable = amd_iommu_capable, .domain_alloc = amd_iommu_domain_alloc, @@ -2444,6 +2471,7 @@ const struct iommu_ops amd_iommu_ops = { .iotlb_sync = amd_iommu_iotlb_sync, .free = amd_iommu_domain_free, .enforce_cache_coherency = amd_iommu_enforce_cache_coherency, + .set_kvm = amd_iommu_set_kvm, } };