From patchwork Wed Jun 21 23:54:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suravee Suthikulpanit X-Patchwork-Id: 111365 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp4732139vqr; Wed, 21 Jun 2023 17:20:09 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ42Tu5c/c3QaDkPgKkVkWwYXWrUrsuCTyqEavZy1dHHP1clSv4NT7QTLmC/GL1YLlMP2W+2 X-Received: by 2002:a17:902:ea01:b0:1ad:f407:37d1 with SMTP id s1-20020a170902ea0100b001adf40737d1mr6946384plg.52.1687393208870; Wed, 21 Jun 2023 17:20:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1687393208; cv=pass; d=google.com; s=arc-20160816; b=wfa8vhw2c2oC8XwSXX9E3QWJbUhZLplR+eo3nQnXyqYYNytBa5hkoDzmfKNsnHviyl bmPdxS26Lk3N4sFCMrlBha3dwi1Gj7CZ8T4FyRDw3xyH+ETGX76489UgOg8uspt/e43K dx4SEskGpVC3LubYH8E85OjQ3wle8GkkEATvDYl/NSczyNun32N0r82gIe+jee7CRp+a WeH8KdHP9K3IHfKYteijA5k5tomKLzjCNNi45ZNC7NLJ+TmlhjVmSz6RpCJqh/tRTi2G SCnD4SZ1rUodPLwBMwcKlYQnOx0UxDTG8x7UWDYMt3pJyfcT6wGKUCCTWC8R5WXKy0qV TiMg== 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=1gPmgzGctQgZlj/iyKvBXeaxd50UuxcrvUOqJyP51yM=; b=aXDHSc7qrguI+QInitrmQlViKJ4FS227kvvQHIGZNJZtkop+NLdixj9zkFp7buwnqS XYl2h+J+P3e6v7kAs/BuU+u93SO9ZHUwfjK2NW8Pn7bx/DcyEdyow+axRRE4PxRyy/ez z3PdNCvlrtjVAd7G65nVF9NDQHD+ldyB3bxKhsMNHZhfZv5J1YZr5mT7ES17Z+s7FgWV IFYvOFKAcJEXsByS8JQjAgaJF44BwarjIRycb3Q4SbMn7xgYvSaCJCGVjhBaibbYlEnM GYaCwSBIcYIbr4PzjgVGjlQMUFgZrWFXWznjNXZ8GC42i/EXnT1ri6/xCltpBjqNcSA2 BMIA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=2h5k1Sak; 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 o9-20020a170902d4c900b001afe7ef68afsi3652748plg.619.2023.06.21.17.19.55; Wed, 21 Jun 2023 17:20:08 -0700 (PDT) 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=2h5k1Sak; 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 S230177AbjFUX4C (ORCPT + 99 others); Wed, 21 Jun 2023 19:56:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229990AbjFUXzv (ORCPT ); Wed, 21 Jun 2023 19:55:51 -0400 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2042.outbound.protection.outlook.com [40.107.244.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B463E19AE; Wed, 21 Jun 2023 16:55:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GAQZ7c8OK0p6hI6GfNWLLxr9DoNkTosRe9L4pmIJxef9NpmRrUQ587+7t1w/pqo5UMg6z8DKlhVrgVM5keg6Kkpc3nOFEhR/RXqrOemBYJER3gmfnW+/IkFtGWzGUe71eofOILRHbtYbGr9bIlT6bxdHQmVzL5/TH9jXHQLSwTk7nlS1I3gYp37NK9B5P+S4R0mrCAtmaO3V0i7D4ovLD7d1n1ipC3rfCxLgJkX1m7JfjeRVZqzJynTRsMRnhRAZkgYM2dSknMFtn9BF8DtE8bxkNA1IQCQ9M4SpYb43QzqOFVOQr0//YdufXZY24PiPdhxWg+YUOLK9N2YwHb5cAg== 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=1gPmgzGctQgZlj/iyKvBXeaxd50UuxcrvUOqJyP51yM=; b=NLLRt73Xa6Q2j+vSrUabhpVe326bcPOLSzDS2w2q4Hfycu2rM0sfVr9hnjJF166dKQIq8xA9wwMM8/UwcaDz838MF2hEFYKaZgJnDuyyjQVjnx4XkpMWSRcpVoaouw/z3kr/jGmKe6ymtzIHUg9sarsbcxYsLZR1g9yi51rB2igGgSM6UhbH2KL21JpXKwSVnmq84JlNLTgVyQW891Z6+u/+O2liZGz4qcfmUSbAd2HHT6YQ9sZpVkIeSbDAxSBL4EFRnoYpX0ovdYPoGsdoQGZaVdcVpn5BWYkgkNYoYSSPnZom4/ApKjjshTrU5YfpytGibETOZW1rjYP8TUnZXg== 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=1gPmgzGctQgZlj/iyKvBXeaxd50UuxcrvUOqJyP51yM=; b=2h5k1Sakc2nk00xC06X2FeSNN+JzBiLJRX+nc1EZ4sRb350hm5hYpCzGxlc04BxO/VJt8IBXr+u1sAA7xmgl3pqWFYO5KZcbIyJI/BIN38adTQq9RgmWQ36OyaeXvpKMSQXTBaCBeOdPP8ckSmoXFFYq8U5X8MTO2lRxYlVH6Fs= Received: from CYZPR10CA0001.namprd10.prod.outlook.com (2603:10b6:930:8a::25) by IA1PR12MB7568.namprd12.prod.outlook.com (2603:10b6:208:42c::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.21; Wed, 21 Jun 2023 23:55:44 +0000 Received: from CY4PEPF0000E9CD.namprd03.prod.outlook.com (2603:10b6:930:8a:cafe::72) by CYZPR10CA0001.outlook.office365.com (2603:10b6:930:8a::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.23 via Frontend Transport; Wed, 21 Jun 2023 23:55:44 +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 CY4PEPF0000E9CD.mail.protection.outlook.com (10.167.241.140) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6521.24 via Frontend Transport; Wed, 21 Jun 2023 23:55:44 +0000 Received: from ruby-95f9host.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.2507.23; Wed, 21 Jun 2023 18:55:42 -0500 From: Suravee Suthikulpanit To: , , CC: , , , , , , , , , , , , , , , "Suravee Suthikulpanit" Subject: [RFC PATCH 01/21] iommu/amd: Declare helper functions as extern Date: Wed, 21 Jun 2023 18:54:48 -0500 Message-ID: <20230621235508.113949-2-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230621235508.113949-1-suravee.suthikulpanit@amd.com> References: <20230621235508.113949-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: CY4PEPF0000E9CD:EE_|IA1PR12MB7568:EE_ X-MS-Office365-Filtering-Correlation-Id: 3efdd915-31d2-4947-eabf-08db72b306ff X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2C/Szeu8l4vVwtgYHvfcz+mxpOU7e5D/hHwUpXgIFPGrxPWqEmxCyPN2pf5N3BEUuVKVzfFaiRlgd1SFfVKcF2BQiOhQPryrkNkbZ9PWHpXJr7ER8b8pi5t76zQEtN5qcGtKbIlnvkI0+DB6409uE0HbfX6F7TpsxAg4TlEY2FMspqXN87voUCHF+m6RzI0aaTVRJPa0IXYH27lNoZ403NyJ0kxOt/qnLK/Ic6eR3JkjcHO/R8nhVkIFvimKDdaRl/yyJtI+jPLEIYxuVvxACn/NqmJxoosRLSQtYAqzp4C9JOFd5IYTeVoxG1gVDfVPkG8pdQMnLrx+XEF+UJkEYQG47EzwnmyNryZZWS+7E8MnN3ZdcPSGfTDC93y1y1ab/8JaWa3ub+s/WTVP/gUK5dBYUpD42GY24bd9nSMzF9W/NPF7+eHV3wNZvnEmBI6P/NrPuc1BTKrjQJjLOTKhp5VBj/OsE3S43KlWLZlKLOrTZAJs7pVXwjKgT6vzFnZOWiamwjscFWQ7p32mYyHmPD/tW4AqLxu1aum1IiKoXLNlRPwXh0EFrGQW9RX5q/kuFjdN61msgeOcuyzUg8MPzDQuC7lfoexMvOlckhnmyDKflgCUVc53oJivuyf5Qf4RADU/P0vli2Q+Zsi9QLjDChRthvsJnpOP7bS87MtqFVnbXric9JuirOEvpre6kwf3w/VjapsTLQ2aRojqurcbgLfxmuJz8ZVZuKkgEDzpRBc1lyBiswdSBDT9OOdk2cuYf2ofcH3Enl+JH9Ka/F4cEQ== 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:(13230028)(4636009)(39860400002)(396003)(136003)(376002)(346002)(451199021)(40470700004)(46966006)(36840700001)(36860700001)(36756003)(82310400005)(40460700003)(81166007)(356005)(70206006)(5660300002)(44832011)(7416002)(41300700001)(8936002)(86362001)(4326008)(8676002)(316002)(40480700001)(82740400003)(70586007)(47076005)(426003)(26005)(1076003)(2616005)(16526019)(186003)(2906002)(7696005)(336012)(478600001)(83380400001)(110136005)(54906003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jun 2023 23:55:44.4267 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3efdd915-31d2-4947-eabf-08db72b306ff 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: CY4PEPF0000E9CD.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB7568 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=no 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?1769360021399678834?= X-GMAIL-MSGID: =?utf-8?q?1769360021399678834?= To allow reuse from other files. There is no functional change. Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/amd_iommu.h | 18 ++++++++++++++++++ drivers/iommu/amd/init.c | 6 +++--- drivers/iommu/amd/io_pgtable.c | 18 +++++++++--------- drivers/iommu/amd/iommu.c | 14 +++++++------- 4 files changed, 37 insertions(+), 19 deletions(-) diff --git a/drivers/iommu/amd/amd_iommu.h b/drivers/iommu/amd/amd_iommu.h index e98f20a9bdd8..827d065bbe8e 100644 --- a/drivers/iommu/amd/amd_iommu.h +++ b/drivers/iommu/amd/amd_iommu.h @@ -11,6 +11,24 @@ #include "amd_iommu_types.h" +extern void iommu_feature_enable(struct amd_iommu *iommu, u8 bit); +extern void iommu_feature_disable(struct amd_iommu *iommu, u8 bit); +extern u8 __iomem * __init iommu_map_mmio_space(u64 address, u64 end); +extern void set_dte_entry(struct amd_iommu *iommu, u16 devid, + struct protection_domain *domain, + bool ats, bool ppr); +extern int iommu_flush_dte(struct amd_iommu *iommu, u16 devid); +extern struct protection_domain *to_pdomain(struct iommu_domain *dom); +extern struct iommu_domain *amd_iommu_domain_alloc(unsigned int type); +extern void amd_iommu_domain_free(struct iommu_domain *dom); +extern int amd_iommu_v1_map_pages(struct io_pgtable_ops *ops, unsigned long iova, + phys_addr_t paddr, size_t pgsize, size_t pgcount, + int prot, gfp_t gfp, size_t *mapped); +extern unsigned long amd_iommu_v1_unmap_pages(struct io_pgtable_ops *ops, + unsigned long iova, + size_t pgsize, size_t pgcount, + struct iommu_iotlb_gather *gather); + extern irqreturn_t amd_iommu_int_thread(int irq, void *data); extern irqreturn_t amd_iommu_int_handler(int irq, void *data); extern void amd_iommu_apply_erratum_63(struct amd_iommu *iommu, u16 devid); diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c index 329a406cc37d..886cf55e75e2 100644 --- a/drivers/iommu/amd/init.c +++ b/drivers/iommu/amd/init.c @@ -432,7 +432,7 @@ static void iommu_set_device_table(struct amd_iommu *iommu) } /* Generic functions to enable/disable certain features of the IOMMU. */ -static void iommu_feature_enable(struct amd_iommu *iommu, u8 bit) +void iommu_feature_enable(struct amd_iommu *iommu, u8 bit) { u64 ctrl; @@ -441,7 +441,7 @@ static void iommu_feature_enable(struct amd_iommu *iommu, u8 bit) writeq(ctrl, iommu->mmio_base + MMIO_CONTROL_OFFSET); } -static void iommu_feature_disable(struct amd_iommu *iommu, u8 bit) +void iommu_feature_disable(struct amd_iommu *iommu, u8 bit) { u64 ctrl; @@ -490,7 +490,7 @@ static void iommu_disable(struct amd_iommu *iommu) * mapping and unmapping functions for the IOMMU MMIO space. Each AMD IOMMU in * the system has one. */ -static u8 __iomem * __init iommu_map_mmio_space(u64 address, u64 end) +u8 __iomem * __init iommu_map_mmio_space(u64 address, u64 end) { if (!request_mem_region(address, end, "amd_iommu")) { pr_err("Can not reserve memory region %llx-%llx for mmio\n", diff --git a/drivers/iommu/amd/io_pgtable.c b/drivers/iommu/amd/io_pgtable.c index 1b67116882be..9b398673208d 100644 --- a/drivers/iommu/amd/io_pgtable.c +++ b/drivers/iommu/amd/io_pgtable.c @@ -360,9 +360,9 @@ static void free_clear_pte(u64 *pte, u64 pteval, struct list_head *freelist) * supporting all features of AMD IOMMU page tables like level skipping * and full 64 bit address spaces. */ -static int iommu_v1_map_pages(struct io_pgtable_ops *ops, unsigned long iova, - phys_addr_t paddr, size_t pgsize, size_t pgcount, - int prot, gfp_t gfp, size_t *mapped) +int amd_iommu_v1_map_pages(struct io_pgtable_ops *ops, unsigned long iova, + phys_addr_t paddr, size_t pgsize, size_t pgcount, + int prot, gfp_t gfp, size_t *mapped) { struct protection_domain *dom = io_pgtable_ops_to_domain(ops); LIST_HEAD(freelist); @@ -435,10 +435,10 @@ static int iommu_v1_map_pages(struct io_pgtable_ops *ops, unsigned long iova, return ret; } -static unsigned long iommu_v1_unmap_pages(struct io_pgtable_ops *ops, - unsigned long iova, - size_t pgsize, size_t pgcount, - struct iommu_iotlb_gather *gather) +unsigned long amd_iommu_v1_unmap_pages(struct io_pgtable_ops *ops, + unsigned long iova, + size_t pgsize, size_t pgcount, + struct iommu_iotlb_gather *gather) { struct amd_io_pgtable *pgtable = io_pgtable_ops_to_data(ops); unsigned long long unmapped; @@ -524,8 +524,8 @@ static struct io_pgtable *v1_alloc_pgtable(struct io_pgtable_cfg *cfg, void *coo cfg->oas = IOMMU_OUT_ADDR_BIT_SIZE, cfg->tlb = &v1_flush_ops; - pgtable->iop.ops.map_pages = iommu_v1_map_pages; - pgtable->iop.ops.unmap_pages = iommu_v1_unmap_pages; + pgtable->iop.ops.map_pages = amd_iommu_v1_map_pages; + pgtable->iop.ops.unmap_pages = amd_iommu_v1_unmap_pages; pgtable->iop.ops.iova_to_phys = iommu_v1_iova_to_phys; return &pgtable->iop; diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index 4a314647d1f7..bbd10698851f 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -177,7 +177,7 @@ static struct amd_iommu *rlookup_amd_iommu(struct device *dev) return __rlookup_amd_iommu(seg, PCI_SBDF_TO_DEVID(devid)); } -static struct protection_domain *to_pdomain(struct iommu_domain *dom) +struct protection_domain *to_pdomain(struct iommu_domain *dom) { return container_of(dom, struct protection_domain, domain); } @@ -450,7 +450,7 @@ static void amd_iommu_uninit_device(struct device *dev) * ****************************************************************************/ -static void dump_dte_entry(struct amd_iommu *iommu, u16 devid) +void dump_dte_entry(struct amd_iommu *iommu, u16 devid) { int i; struct dev_table_entry *dev_table = get_dev_table(iommu); @@ -1192,7 +1192,7 @@ static int iommu_completion_wait(struct amd_iommu *iommu) return ret; } -static int iommu_flush_dte(struct amd_iommu *iommu, u16 devid) +int iommu_flush_dte(struct amd_iommu *iommu, u16 devid) { struct iommu_cmd cmd; @@ -1553,8 +1553,8 @@ static void free_gcr3_table(struct protection_domain *domain) free_page((unsigned long)domain->gcr3_tbl); } -static void set_dte_entry(struct amd_iommu *iommu, u16 devid, - struct protection_domain *domain, bool ats, bool ppr) +void set_dte_entry(struct amd_iommu *iommu, u16 devid, + struct protection_domain *domain, bool ats, bool ppr) { u64 pte_root = 0; u64 flags = 0; @@ -2118,7 +2118,7 @@ static struct protection_domain *protection_domain_alloc(unsigned int type) return NULL; } -static struct iommu_domain *amd_iommu_domain_alloc(unsigned type) +struct iommu_domain *amd_iommu_domain_alloc(unsigned int type) { struct protection_domain *domain; @@ -2140,7 +2140,7 @@ static struct iommu_domain *amd_iommu_domain_alloc(unsigned type) return &domain->domain; } -static void amd_iommu_domain_free(struct iommu_domain *dom) +void amd_iommu_domain_free(struct iommu_domain *dom) { struct protection_domain *domain; From patchwork Wed Jun 21 23:54:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suravee Suthikulpanit X-Patchwork-Id: 111348 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp4721573vqr; Wed, 21 Jun 2023 16:57:07 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ650U8BzQ/5/pbydiUkt726U8aahip0pLVk2JoxzWoe8vW5ZyMc7hllaJBrfVMqvnsuMUNY X-Received: by 2002:a05:6a00:188c:b0:668:7a6a:99ba with SMTP id x12-20020a056a00188c00b006687a6a99bamr9173339pfh.20.1687391827610; Wed, 21 Jun 2023 16:57:07 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1687391827; cv=pass; d=google.com; s=arc-20160816; b=vB3nLt9j5iepisl7m/kPk/9pDvNrAh5VWS3r69ZcLixKyyJHWlwiDiGQ/qh3Wf8Ero cPmrcC/FEzJIUgIDfwEHWsDJegYypbBg6QP+KBadZ3pGgYvRVkCUIHms/1MUPLjah8zS /bsWwkJBVB1XJisVJUF8k9ELkpETg+PGt9cCkVuYWwbSw++pDjGVi6e0R7G3ell/oLxo LHBShsgzMVqaAUfGUJNI+i1uTvfMWidwc7IR5zsMaGJZLiJlYYbaYrzN3WyxD1F+QC32 eOLa8sIaHLZQJ57wmySqZF/+tH+9g9jQkYoff/1pAGCgjwht8fDvFZJhfGfQE+rvp82L tM8w== 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=PX0vXUy9BWz7OvCUIJQvG9oLwuPAcVLSVxcDFjuzNdQ=; b=vcTaevYaIHs+A1JcSrzrb7AuEgu/9bmhGvEkWxBVfedHFz4Ft/I+S4ZTIn6UWoGlt/ gmmJeujdCz5h75ELhIF/eROi+CEMv05gdrrQzgW2bMkOIASYK8tzTvhyHYC4K804yYKi vepPlWip485DkiK7GBoqWfmOtbuDasG8+wTOQD8mfpYxgG1pKcHdqqwp97l+hk1dpMd4 r+W6cPuIKI1J1T13kqod+yb2cLLugkGNkEp8N5kdwFpQAU4nNpo8k/DbrFFcEc7LANKn UT3NfuW4ZJx4FQeyvdltu7zed9A2pBA5PZlIX7qctWgEoA2IqMKAanGb+RxdvhX2VH+9 HnwQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=Nm2TFKN3; 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 n8-20020aa79848000000b0066767d61b7esi5091681pfq.331.2023.06.21.16.56.53; Wed, 21 Jun 2023 16:57:07 -0700 (PDT) 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=Nm2TFKN3; 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 S230094AbjFUXz6 (ORCPT + 99 others); Wed, 21 Jun 2023 19:55:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229943AbjFUXzt (ORCPT ); Wed, 21 Jun 2023 19:55:49 -0400 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2082.outbound.protection.outlook.com [40.107.92.82]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 087EB171C; Wed, 21 Jun 2023 16:55:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XqPwWXvFEoacReYba+StPmkAalbnnlCdEKoZQtO9JJFNUFBpHjEbhAwc2k/yg9qNCFdBOX2sl7YlB7/wAA5ERQpvaIt6E+ZR0Jlmrs2j9pk3SHV36kW+ObnRXWXyyvWyBVeg32iqcWvoSYqAvPr7lFKtbFzfAp7rwmklsJm1sZJ1pluMyRIeeEyoXPaEAGiDC9u+GcsA8n29FxNLVKKXlC/v3ItsS9bNph9Q/7jnh4LeioEFrU5y7AAZmJnnEjsK11uT8H/zSIBT9QdXaSS+l0Gxu/wPxB3fuL5YUjCJruU8U35cKwZ96w+Tip+MXKBrUl9/Mp2zJgKiGRBTAVITCw== 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=PX0vXUy9BWz7OvCUIJQvG9oLwuPAcVLSVxcDFjuzNdQ=; b=kAniJeCNoNORf6ahbxYasWpCESWw9scuLPDEr5q4SG9knrtHh2CXCkBlpeOOrdOeSYKmPns9UhD7FGikM+u65FiC2/fEjTFXFpu7ABK8y19fmyaotE24Y9SJ2KgA10ZZbuXHyVduC+hQ8+SBMtx+difMLiocX5EXid8+ldeEUaN9Yo6gaOxqQFio46sP34ocqHM8zJ2xuzG64Jb9XJtQD0y6YSTds7hGL2HeHmJSxchvE8KOeshS0qbLD2LhJcAKO2SBBuZQgiiaHuCvlgZDlD5CSzDmX89YBrk5IKnVspf3RufZaYMQyPQyI6jUZxHpZn06ELQjn2KuA/tbXfEZRA== 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=PX0vXUy9BWz7OvCUIJQvG9oLwuPAcVLSVxcDFjuzNdQ=; b=Nm2TFKN3nWjVKrK0XP+rsa/+mHpgfW9W82nqa01tGyBCgrzZV6lBkIDCOMz45QdqXM8M88WtYDo9aR+OyoSKZEI1gH6dQ8hFIxY5Q6Hro5LhVdfrf6YaBF7ORS79Zo2XyKAohjXag/C6rXxnL5nZ+HUaQeHkFH2r9kDnzYbDjj0= Received: from CYZPR10CA0001.namprd10.prod.outlook.com (2603:10b6:930:8a::25) by MN2PR12MB4270.namprd12.prod.outlook.com (2603:10b6:208:1d9::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.23; Wed, 21 Jun 2023 23:55:45 +0000 Received: from CY4PEPF0000E9CD.namprd03.prod.outlook.com (2603:10b6:930:8a:cafe::b9) by CYZPR10CA0001.outlook.office365.com (2603:10b6:930:8a::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.23 via Frontend Transport; Wed, 21 Jun 2023 23:55:45 +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 CY4PEPF0000E9CD.mail.protection.outlook.com (10.167.241.140) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6521.24 via Frontend Transport; Wed, 21 Jun 2023 23:55:45 +0000 Received: from ruby-95f9host.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.2507.23; Wed, 21 Jun 2023 18:55:43 -0500 From: Suravee Suthikulpanit To: , , CC: , , , , , , , , , , , , , , , "Suravee Suthikulpanit" Subject: [RFC PATCH 02/21] iommu/amd: Clean up spacing in amd_iommu_ops declaration Date: Wed, 21 Jun 2023 18:54:49 -0500 Message-ID: <20230621235508.113949-3-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230621235508.113949-1-suravee.suthikulpanit@amd.com> References: <20230621235508.113949-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: CY4PEPF0000E9CD:EE_|MN2PR12MB4270:EE_ X-MS-Office365-Filtering-Correlation-Id: 4d6000db-7afa-41b2-4769-08db72b3077e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: jNQ/zNRGdn+PoZimByTW/JtGKo91VAuSTeJIT6kwrPNDsSmaFOe7eZvtgyDrebw+7B+t1LWYR8MtaPwKbIbm54ktwbxb9DyAHSQl1Y38IAcUJdPi4ugMHztEYjM6cUYJOR/PKolWz3GdSsyE+vELGZeSzXuK6pKOQJrOJPTanR1RGdzJqebE9zpzX13N5AGvT2ZAScIuiECqy/n8ERobG/gtZ/rFs/hWYIfSZ0xSN4vXBT0URbxEFKcxD0HFSrfsDFyuI9VUEMSdJ59er5pTLs24FhMw7rfTmU9Sl8fVZy3uroMh0Cv/NdChwnown1o/SvCLn9tCwKSbwxy3UOdcadIkLvyTZxmMZBWQq9fDeGeZqYL6+Bz+vjSYJL3ighISLvxKR8CCslXdB3Lm/IUO8LoHfXHVcr57uNsfBeGM7Cba3w7lydYLbJ8yUldGSKVl/Ot3frMch8ab6xDs/Cu5YdAGeUAMj4XN0qkpvF0A+FQgZB+HZIhxBq7Jr6ewNCx2yJn+G1ubLr6p8UnH8Vdszzr1Q0JiyXDrHkBdCCjEcTMfmW4z0fp4nyRpJI0b2EVWfL+yoh60Iq4vFt3aAkb8XNwstkKV2V69izTKOKBPup1tNJQFjNNXl49b/TjPH+u9vHCQiBPW5RmuKs0X8BYuVMAY+Bc3jgaq2f6CAF69zTqw8PzQUj7XP20rvHv1AnT9p3qdcVyvNCov+z1Fkl9qSeZW4VbHYyNw5L1zmnm2UqQwfqG5xhUFoHSvU/m42Z8/x/DXM7BAEnUfTa0kqhiwCg== 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:(13230028)(4636009)(346002)(376002)(136003)(39860400002)(396003)(451199021)(40470700004)(36840700001)(46966006)(478600001)(54906003)(110136005)(4326008)(47076005)(40480700001)(336012)(426003)(83380400001)(2616005)(86362001)(36756003)(36860700001)(40460700003)(2906002)(70586007)(82310400005)(16526019)(186003)(7696005)(1076003)(26005)(356005)(82740400003)(81166007)(70206006)(41300700001)(8936002)(8676002)(316002)(5660300002)(7416002)(44832011)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jun 2023 23:55:45.2392 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4d6000db-7afa-41b2-4769-08db72b3077e 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: CY4PEPF0000E9CD.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4270 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=no 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?1769358573348718834?= X-GMAIL-MSGID: =?utf-8?q?1769358573348718834?= Preparing for additional iommu_ops. There is no functional change. Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/iommu.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index bbd10698851f..356e52f478f1 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -2423,17 +2423,17 @@ static bool amd_iommu_enforce_cache_coherency(struct iommu_domain *domain) } const struct iommu_ops amd_iommu_ops = { - .capable = amd_iommu_capable, - .domain_alloc = amd_iommu_domain_alloc, - .probe_device = amd_iommu_probe_device, - .release_device = amd_iommu_release_device, - .probe_finalize = amd_iommu_probe_finalize, - .device_group = amd_iommu_device_group, - .get_resv_regions = amd_iommu_get_resv_regions, - .is_attach_deferred = amd_iommu_is_attach_deferred, - .pgsize_bitmap = AMD_IOMMU_PGSIZES, - .def_domain_type = amd_iommu_def_domain_type, - .default_domain_ops = &(const struct iommu_domain_ops) { + .capable = amd_iommu_capable, + .domain_alloc = amd_iommu_domain_alloc, + .probe_device = amd_iommu_probe_device, + .release_device = amd_iommu_release_device, + .probe_finalize = amd_iommu_probe_finalize, + .device_group = amd_iommu_device_group, + .get_resv_regions = amd_iommu_get_resv_regions, + .is_attach_deferred = amd_iommu_is_attach_deferred, + .pgsize_bitmap = AMD_IOMMU_PGSIZES, + .def_domain_type = amd_iommu_def_domain_type, + .default_domain_ops = &(const struct iommu_domain_ops) { .attach_dev = amd_iommu_attach_device, .map_pages = amd_iommu_map_pages, .unmap_pages = amd_iommu_unmap_pages, From patchwork Wed Jun 21 23:54:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suravee Suthikulpanit X-Patchwork-Id: 111354 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp4722126vqr; Wed, 21 Jun 2023 16:58:56 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5igumri22Hj53fm6N4AI1ZTto20E9oqzsK4xrGUrGHuwuWod7/O9dUPY+Zva+X6P/zraUj X-Received: by 2002:a17:902:f546:b0:1b6:9de1:eae5 with SMTP id h6-20020a170902f54600b001b69de1eae5mr2707961plf.20.1687391935664; Wed, 21 Jun 2023 16:58:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1687391935; cv=pass; d=google.com; s=arc-20160816; b=l/rVEcuzC3eF9G4W91tjyop666JUNp8i3gkOIq7oFYMBJQj91pHlWJ22Ui0VY2NIT2 71o8X7YtKrzU5WF9dhI1SpCzRtiBCseMkOEr9Ec7TCSqhGSH8ZB13iftb1wOqDK25Aq/ e2hi4Lmfqnn6Z9mazoogU3YJ8tuTeR+lrrr5NNXlbKEOiyX+Vmf3HNzzAdWr7BGOo2sc eTZkFJoUd/TZlzFPkYnjCAhDNCworaRm3KbWNQt8DFxfWLho7L1Si73zNWWNHXqdr7PW MbFBzMU2iZanFVG3ogy8yUpPv2mOWLTRbRZ1XiSES4L5aCO5Dim0ut2wKVqSpSCz5Na+ 8irg== 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=g1LmUXY7El6wGAuzWxVdc/JfOGIzhDxjgvsNezhtaD0=; b=ZfrDa5NM8TX7AQZKm/KKIRI0+7jlF6WJoGH9njBG7kUUFq2e1Lbq4NYvbaVyKL8cPr F4MxJwc+2Vt1GoXwEq0gMhpO/I1pK3n87ea3l0eota0aQrN0Zz1oFbunHifdhMqUerXf +xVcwS2Igulzxt/xPuxWqpmsU7uxp6yRW2QSCfe3leVE2fP+hmoY9tMIRNvxGc41AasP x5VJ89lzEAi77CIpd9J86Ss27qemFv8A8DNVqNXo9GE6v0s472unZTeALqJsLqb88Zia WcG/5wkXSohxT2gBtBTL23i1V7j3QgdZGQLE+EXxVWr+qlNmSDMY4+ZjJEe/K5nFM6xH HSHw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=f07mcITx; 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 i16-20020a17090332d000b001ae38227983si5813504plr.199.2023.06.21.16.58.33; Wed, 21 Jun 2023 16:58:55 -0700 (PDT) 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=f07mcITx; 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 S230039AbjFUXzz (ORCPT + 99 others); Wed, 21 Jun 2023 19:55:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229950AbjFUXzt (ORCPT ); Wed, 21 Jun 2023 19:55:49 -0400 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2068.outbound.protection.outlook.com [40.107.100.68]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5F081733; Wed, 21 Jun 2023 16:55:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gD5xo5lP4pzi8P8HgxGczL+hJqEARH8kr6ViXtBGH3cdW/l7g2XpnYssKekGXohs1zq3wTDNMUdpZzSzcFNSOp1Ssf//EWundUAmv5xAU8wxoA4s/rT88KRjsldSVq2hxR4gTiJrZ1QnRg5I3yPHiUgHsw3gN08brqdEIit1unX+tKcUMvGH0km1M3UOc3vJbvvZyIL6/02QbvUfSu53gHSzslhSG/TpyJIJAlux41ApsXufc2jno+QkXjq9wTC4uDD4R0NWK//dfU75ErNrx8MM22IUMq2Fdp27XIH75b7rZ1E0ggfVteNyrNVI8BUg79DqYGUTS16TKiY0AQLpBQ== 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=g1LmUXY7El6wGAuzWxVdc/JfOGIzhDxjgvsNezhtaD0=; b=Fgxl5K9JK2ngGKQRNTOim4zoQ6CjEtBHYPlu3Q1ckGQ8p33mkRAeKYKxanX8hin+v3uJfpl1PXVj1MGl+eQaOIdMS4oHk9I5ojmbNen+yauodJFh2BOnIiP0J56sFwRPN/g2X3hJlZSJlOsiQ1C2rf4zsqdNQGC3Gb0fJmXWYHAZkcIA9bwg5SUPPN/Epx3Q7YNYZwBUgOqycfSg9OlvmOSgYRkKUGVHjE/0dhAPMvfy2GLYf1FKI1X8Jv3YPBPPvPVGJXm+Mbb2Phlco3OvIqrpTv0i2d2DYDTqWigRvaOZ9QmtzQprbxbib/1/HfSFBTjr5MIVynOrx0+X/Toceg== 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=g1LmUXY7El6wGAuzWxVdc/JfOGIzhDxjgvsNezhtaD0=; b=f07mcITxw7C8TqkyWC01UekO5jGDFjIfzrozOlAuTay4Aj9Nswv9MqwufS7pqzuGbAmIFzb7XuHj8ddUAjxQxzg/7s+V0cbJ+CygYKvF3bV/GFWPQsIwBKDS/XVEzEt2YWVbqGIVZLOiEE852AGg6q4+FoL7pJYt4z77j9xTt6w= Received: from CYZPR10CA0017.namprd10.prod.outlook.com (2603:10b6:930:8a::17) by IA1PR12MB6068.namprd12.prod.outlook.com (2603:10b6:208:3ec::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.21; Wed, 21 Jun 2023 23:55:46 +0000 Received: from CY4PEPF0000E9CD.namprd03.prod.outlook.com (2603:10b6:930:8a:cafe::f6) by CYZPR10CA0017.outlook.office365.com (2603:10b6:930:8a::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.23 via Frontend Transport; Wed, 21 Jun 2023 23:55:46 +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 CY4PEPF0000E9CD.mail.protection.outlook.com (10.167.241.140) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6521.24 via Frontend Transport; Wed, 21 Jun 2023 23:55:46 +0000 Received: from ruby-95f9host.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.2507.23; Wed, 21 Jun 2023 18:55:44 -0500 From: Suravee Suthikulpanit To: , , CC: , , , , , , , , , , , , , , , "Suravee Suthikulpanit" Subject: [RFC PATCH 03/21] iommu/amd: Update PASID, GATS, and GLX feature related macros Date: Wed, 21 Jun 2023 18:54:50 -0500 Message-ID: <20230621235508.113949-4-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230621235508.113949-1-suravee.suthikulpanit@amd.com> References: <20230621235508.113949-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: CY4PEPF0000E9CD:EE_|IA1PR12MB6068:EE_ X-MS-Office365-Filtering-Correlation-Id: a91cc3b1-4731-47c8-1a86-08db72b307f3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: jx94nxk4DBUl/0lyI+oCtVNJyz2vmCp2bWQHqjq6UEP0NN00Lj9pLp6nTZptHzn8ceAbBAUZ226wk4+ADmkJXVHZytinZRvenPJC+EK7rRvnQ0SUYfqTCLxro/XLWya4FFNywzIqMU9DnrjliORLjwTJlOGDJkVVbYjEY//C5qkCxN4mbFnAbZTfZZ/g/Ur/Z+slbd0TVlCrbECTzVokZr7nTWHfNNqxsCNx37AaIYIABzGBZEQQdQx8/Tr349sseE0Wum3QP8H355eMksbYzFWwRTgJx6P0YA4iPI48jtSq0CZ0WwYhpYdh4nPKiN+G6vN2uIveEz5Taqsx342+mqKHF4cT/VTGVjwRQKX7N3MvG0R+3O0UywmURXVLOg2KkDZe1GKQz4A6pIMImAbVMSVYABa5Bs44t1jPDBPOEQaQICItY8OAZcWA00MRH0DJuMvxaDPyKZAaC/G2qY8N73asaR1Zjus2rJVeZbI8T9+P6FGTqqm4omE9sotUHPgnM87K942ExnPbjTTyKB4XmNzEvMw63dUwmSkmdGcI+27TNxY30aVbIXz+24qRwgs4EBuvnh75tr6Ocq12OVM51md6KBg/TzdXu1vTzVcA+6tkMXlEyFEkHG67DL97HgjPbUuPjIumzdRWSoj5lY8WLQG6RZpCEV7iUfld0UMd0nLmE0qhpkUBd75J3/GOMuY08rF9ZyBvK0IDKBbqlXuuF1r/Hu3y8ZcshdkKr27vYyedr/ZoXd1rD2Cqo4K4wRuq/8RtFRRVB0WtAGfk/L7QWg== 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:(13230028)(4636009)(396003)(376002)(346002)(136003)(39860400002)(451199021)(46966006)(36840700001)(40470700004)(40460700003)(70206006)(36860700001)(2906002)(83380400001)(7416002)(8676002)(47076005)(478600001)(54906003)(16526019)(8936002)(5660300002)(7696005)(70586007)(316002)(186003)(4326008)(44832011)(41300700001)(26005)(1076003)(6666004)(2616005)(426003)(336012)(110136005)(40480700001)(82740400003)(81166007)(82310400005)(36756003)(86362001)(356005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jun 2023 23:55:46.0048 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a91cc3b1-4731-47c8-1a86-08db72b307f3 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: CY4PEPF0000E9CD.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6068 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=no 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?1769358686373943490?= X-GMAIL-MSGID: =?utf-8?q?1769358686373943490?= Clean up and reorder them according to the bit index. There is no functional change. Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/amd_iommu_types.h | 13 +++++++------ drivers/iommu/amd/init.c | 10 +++++----- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/drivers/iommu/amd/amd_iommu_types.h b/drivers/iommu/amd/amd_iommu_types.h index 2ddbda3a4374..09df25779fe9 100644 --- a/drivers/iommu/amd/amd_iommu_types.h +++ b/drivers/iommu/amd/amd_iommu_types.h @@ -93,18 +93,19 @@ #define FEATURE_GA (1ULL<<7) #define FEATURE_HE (1ULL<<8) #define FEATURE_PC (1ULL<<9) -#define FEATURE_GATS_SHIFT (12) -#define FEATURE_GATS_MASK (3ULL) #define FEATURE_GAM_VAPIC (1ULL<<21) #define FEATURE_GIOSUP (1ULL<<48) #define FEATURE_EPHSUP (1ULL<<50) #define FEATURE_SNP (1ULL<<63) -#define FEATURE_PASID_SHIFT 32 -#define FEATURE_PASID_MASK (0x1fULL << FEATURE_PASID_SHIFT) +#define FEATURE_GATS_SHIFT 12 +#define FEATURE_GATS_MASK (0x03ULL << FEATURE_GATS_SHIFT) -#define FEATURE_GLXVAL_SHIFT 14 -#define FEATURE_GLXVAL_MASK (0x03ULL << FEATURE_GLXVAL_SHIFT) +#define FEATURE_GLX_SHIFT 14 +#define FEATURE_GLX_MASK (0x03ULL << FEATURE_GLX_SHIFT) + +#define FEATURE_PASMAX_SHIFT 32 +#define FEATURE_PASMAX_MASK (0x1FULL << FEATURE_PASMAX_SHIFT) /* Extended Feature 2 Bits */ #define FEATURE_SNPAVICSUP_SHIFT 5 diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c index 886cf55e75e2..6a045a187971 100644 --- a/drivers/iommu/amd/init.c +++ b/drivers/iommu/amd/init.c @@ -310,7 +310,7 @@ static bool check_feature_on_all_iommus(u64 mask) static inline int check_feature_gpt_level(void) { - return ((amd_iommu_efr >> FEATURE_GATS_SHIFT) & FEATURE_GATS_MASK); + return ((amd_iommu_efr && FEATURE_GATS_MASK) >> FEATURE_GATS_SHIFT); } /* @@ -2039,16 +2039,16 @@ static int __init iommu_init_pci(struct amd_iommu *iommu) u32 max_pasid; u64 pasmax; - pasmax = iommu->features & FEATURE_PASID_MASK; - pasmax >>= FEATURE_PASID_SHIFT; + pasmax = iommu->features & FEATURE_PASMAX_MASK; + pasmax >>= FEATURE_PASMAX_SHIFT; max_pasid = (1 << (pasmax + 1)) - 1; amd_iommu_max_pasid = min(amd_iommu_max_pasid, max_pasid); BUG_ON(amd_iommu_max_pasid & ~PASID_MASK); - glxval = iommu->features & FEATURE_GLXVAL_MASK; - glxval >>= FEATURE_GLXVAL_SHIFT; + glxval = iommu->features & FEATURE_GLX_MASK; + glxval >>= FEATURE_GLX_SHIFT; if (amd_iommu_max_glx_val == -1) amd_iommu_max_glx_val = glxval; From patchwork Wed Jun 21 23:54:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suravee Suthikulpanit X-Patchwork-Id: 111362 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp4731009vqr; Wed, 21 Jun 2023 17:16:59 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ64qDPC/48ZVyemTtp5+XOeALv7/byGg8DD76VsQKQaB1HY7qGwVlWzocm81veyrISzRDA7 X-Received: by 2002:a17:903:234e:b0:1b5:54cb:36a7 with SMTP id c14-20020a170903234e00b001b554cb36a7mr11916725plh.61.1687393019282; Wed, 21 Jun 2023 17:16:59 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1687393019; cv=pass; d=google.com; s=arc-20160816; b=h7EMmxnnCsZXHS66ApJ6aAfLwNygVNu9H0dhCGgYzmwGKIHGh8MhX+fP+TlKTgvQlX EOVAHoD19AXOt+37mOs2/brUg+HAumh0/1yPiN42UWz4nNfWv807KyCR0BPr9rf3gsCM du8xZ5TBvP0rcuWlq7Bc6h/StCHzrZ0g1q7pTiuNYlf0YV8U+a9AguU6mDyg6c94y5gb F666jBI5uH8cI78h3HfwP5ASflHlvTfBwMi3ZzYZ7et3L0QcMJMp5yLRui1s4+LdUHTm itw2Q0NyhISEpXNUictkY5GQsEV/XiyE5D+WUyaJjfWNozRbLAQm1628wYZOtn38pAi4 oqXQ== 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=cEqC5gNJ6QrfMU+1FtcsmxsZM8CD4QlJlb2KHBULmps=; b=UjlynvkkOkhvk2Q8N2JJ97GAMecRPaV50HU8Zi+bCcUlNGuQOfuBoZzhuiQ4feuIE1 0lsGKky5TIWARAVI3t5itqnyKLpXkqmE48i3m/zF699rf6U2CShA/rH4iNZgpJtoGMYD bvihxAXF8HH/1nScAbCn0N2JlE2tuWD5LtdzlG4ZN/dMgRKyAXt7brgtk3XGMSGHjv2h gQCvuqOhNDXPULyM1dJDKlezGDfU0OYYCvgm2dYxVO0XxhhOEXAsgHAUj6iHk40N9zLq p2474BuPq753Qe0vje/GQ29LLbXlWAgh0AmHakfJnvbVtDOpTuAh8G0gBihyHq/atLVE sU5Q== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=S5veSHUn; 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 o9-20020a170902d4c900b001afe7ef68afsi3652748plg.619.2023.06.21.17.16.46; Wed, 21 Jun 2023 17:16:59 -0700 (PDT) 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=S5veSHUn; 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 S230196AbjFUX4F (ORCPT + 99 others); Wed, 21 Jun 2023 19:56:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229974AbjFUXzu (ORCPT ); Wed, 21 Jun 2023 19:55:50 -0400 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2045.outbound.protection.outlook.com [40.107.96.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC2B01735; Wed, 21 Jun 2023 16:55:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dc0lJU6JWWq553NiNycteM3x51NupIxxtvWWTtIvlNyVk548CChZ7gm0IIEqR7JVIYKJGGbf/dw1TB68brz6K/K9qnpVS2A2tbWxvGYzQeQK9h3cqJ3G2GQjN3sTKqyXb8pcLqgLNGy21NfXgzbhYutxbovoXS/fWXu1ocGIwmIXN6Dx75PoL9ra/aC3ZCXBVI1SUmnTOKe2eKNoPg5E9eHhybIgR1HCiw48SSok7GRTa2Igl3ANBx1jhrpu4sJvZw8S7ZAkBuIpYlBHj/b6b+8Dh9KwoWBHTthWLyL/f4sWxxHYlHIT/fpHMKln3rhNWhzsMHSwDnoDSJ6+mKPffg== 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=cEqC5gNJ6QrfMU+1FtcsmxsZM8CD4QlJlb2KHBULmps=; b=ezJHeWq9jgKF+AIb9vkeK+lqstxGTuyJNbXAZYU1xi7GfzHAlu3/fbpFy9qh6jMkOgcIijU1UAvhyjSWMO0ayg9UuwPemKgfFtAV7zrKsxuXFJsM2H6nQvdqPWqURY5qU+i1KaTSe8lIz6V4HJOqEu2bRi7CWhnVBibDcYGCqzuc3RtK4HPHiErrk3vVOohhphbSUJjsniONZ0JuDsa9PDAKO2QfXRFJKhkhoTSs/a9pxzgXl+nC2VkaXKhtexf87cKcOwgk+wM6M+IWsiB7iDBiyDGkA/80DTbjCfn7L/ABFsMDK3Mqe6n83e8B8dtfzNpbC7GvMJSgdRNJz8NpUA== 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=cEqC5gNJ6QrfMU+1FtcsmxsZM8CD4QlJlb2KHBULmps=; b=S5veSHUnwIZvPBY9iK1juCauVobXlPAFGDI924JXHXX8/LD6uU8EqC2HjMtvo0riI0PZIVBPiv2ic/vSP+uV1cFvvOQCY3M67t1Ztb5KZowLDvLYTAMETamjORHgVNdL7Q1evGqCkBemkobSUcsFcnHwl9se0WUoZFq6OTlJaUw= Received: from CYZPR10CA0010.namprd10.prod.outlook.com (2603:10b6:930:8a::23) by PH7PR12MB6936.namprd12.prod.outlook.com (2603:10b6:510:1ba::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.24; Wed, 21 Jun 2023 23:55:46 +0000 Received: from CY4PEPF0000E9CD.namprd03.prod.outlook.com (2603:10b6:930:8a:cafe::e2) by CYZPR10CA0010.outlook.office365.com (2603:10b6:930:8a::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.23 via Frontend Transport; Wed, 21 Jun 2023 23:55:46 +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 CY4PEPF0000E9CD.mail.protection.outlook.com (10.167.241.140) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6521.24 via Frontend Transport; Wed, 21 Jun 2023 23:55:46 +0000 Received: from ruby-95f9host.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.2507.23; Wed, 21 Jun 2023 18:55:45 -0500 From: Suravee Suthikulpanit To: , , CC: , , , , , , , , , , , , , , , "Suravee Suthikulpanit" Subject: [RFC PATCH 04/21] iommu/amd: Modify domain_enable_v2() to add giov parameter Date: Wed, 21 Jun 2023 18:54:51 -0500 Message-ID: <20230621235508.113949-5-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230621235508.113949-1-suravee.suthikulpanit@amd.com> References: <20230621235508.113949-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: CY4PEPF0000E9CD:EE_|PH7PR12MB6936:EE_ X-MS-Office365-Filtering-Correlation-Id: 9e9241bf-7f61-4604-8cb9-08db72b30846 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4CfxtBXxwUn+qPhpiUn/h+ZibwitajE/9uMykXHvjgLgtLz9V/JGS8YW5SHzUbdcdho5uSNMvVKTnvK8CvKs+jPxFglmfYx68T2kTe72TmK29kEkaKqOuIM1vV5YOEwMLmR/JGWMVcL6wwsF2AkyUjUJEQxLvaf0QOFy1/H5vI9hSGYulsy7uCYAXmRYr9ro+N/wcTFZxlsy1FTq+4viiTrC2Qz7JVjnw30bMAitHBu6114yoZMhud4dfRYloKRpwB9B5Ksk6bnAcmA7qCpvcB5PJIZXnlp5t0wNqiRvUTbkEFagYNx1qwCxwWzKfzJVG7qRwWZm2WuGTKUtbL8DqdmsqOHucs7onxD3A3Rqkxvsf9TAB09OXv+2HNm8pmn1ZVpWOPbTn92u7I6mbVWUInR69ZKrXq1AvZPW0Q6uawufHiGnbc8RmeU8hQnSSO3gtHb2leoemQjguGdLbWaNvLVshiqolsfxZ0ZTm/BkKrrTgazyvusX4Iv/QDV4ED0aBWSfU0lKncYlnMUP050XFiTVWcry3MHyfChqqNLAfDVo7j3xQ6WOPumgx/cx31I0s7iEZu+d8MjHm/Qiv9q25A90MRmIbfjBXNTsw8khtwfugp/6Qep/1U/jDStTgRRYlWqKTj11jVzcSsk6Eby3g8TzvM7ah6VRasHxrIaoKTMdd3bKlMEXxsD92dXsXt/eHYeyTHzbMe6CkO5cxj6QkFYj/w3ksSO7oWRY6mIZCl8q3Wrec3tOJhHw/zZvDjAtRFzbQU+b9CElrAqCequuDg== 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:(13230028)(4636009)(136003)(376002)(39860400002)(346002)(396003)(451199021)(36840700001)(40470700004)(46966006)(82740400003)(81166007)(356005)(16526019)(26005)(186003)(40460700003)(1076003)(47076005)(2616005)(36860700001)(40480700001)(83380400001)(426003)(336012)(82310400005)(54906003)(110136005)(70586007)(478600001)(70206006)(44832011)(5660300002)(7416002)(4326008)(86362001)(2906002)(316002)(8676002)(41300700001)(7696005)(8936002)(6666004)(36756003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jun 2023 23:55:46.5517 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9e9241bf-7f61-4604-8cb9-08db72b30846 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: CY4PEPF0000E9CD.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6936 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=no 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?1769359822372353212?= X-GMAIL-MSGID: =?utf-8?q?1769359822372353212?= To preparation for subsequent changes. There is no functional change. Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/amd_iommu.h | 2 +- drivers/iommu/amd/iommu.c | 14 +++++++------- drivers/iommu/amd/iommu_v2.c | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/iommu/amd/amd_iommu.h b/drivers/iommu/amd/amd_iommu.h index 827d065bbe8e..5d2eed07a1fa 100644 --- a/drivers/iommu/amd/amd_iommu.h +++ b/drivers/iommu/amd/amd_iommu.h @@ -70,7 +70,7 @@ extern int amd_iommu_pc_set_reg(struct amd_iommu *iommu, u8 bank, u8 cntr, extern int amd_iommu_register_ppr_notifier(struct notifier_block *nb); extern int amd_iommu_unregister_ppr_notifier(struct notifier_block *nb); extern void amd_iommu_domain_direct_map(struct iommu_domain *dom); -extern int amd_iommu_domain_enable_v2(struct iommu_domain *dom, int pasids); +extern int amd_iommu_domain_enable_v2(struct iommu_domain *dom, int pasids, bool giov); extern int amd_iommu_flush_page(struct iommu_domain *dom, u32 pasid, u64 address); extern void amd_iommu_update_and_flush_device_table(struct protection_domain *domain); diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index 356e52f478f1..6017fce8d7fd 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -79,7 +79,7 @@ struct iommu_cmd { struct kmem_cache *amd_iommu_irq_cache; static void detach_device(struct device *dev); -static int domain_enable_v2(struct protection_domain *domain, int pasids); +static int domain_enable_v2(struct protection_domain *domain, int pasids, bool giov); /**************************************************************************** * @@ -2051,11 +2051,9 @@ static int protection_domain_init_v2(struct protection_domain *domain) return -ENOMEM; INIT_LIST_HEAD(&domain->dev_list); - domain->flags |= PD_GIOV_MASK; - domain->domain.pgsize_bitmap = AMD_IOMMU_PGSIZES_V2; - if (domain_enable_v2(domain, 1)) { + if (domain_enable_v2(domain, 1, true)) { domain_id_free(domain->id); return -ENOMEM; } @@ -2484,7 +2482,7 @@ void amd_iommu_domain_direct_map(struct iommu_domain *dom) EXPORT_SYMBOL(amd_iommu_domain_direct_map); /* Note: This function expects iommu_domain->lock to be held prior calling the function. */ -static int domain_enable_v2(struct protection_domain *domain, int pasids) +static int domain_enable_v2(struct protection_domain *domain, int pasids, bool giov) { int levels; @@ -2501,13 +2499,15 @@ static int domain_enable_v2(struct protection_domain *domain, int pasids) domain->glx = levels; domain->flags |= PD_IOMMUV2_MASK; + if (giov) + domain->flags |= PD_GIOV_MASK; amd_iommu_domain_update(domain); return 0; } -int amd_iommu_domain_enable_v2(struct iommu_domain *dom, int pasids) +int amd_iommu_domain_enable_v2(struct iommu_domain *dom, int pasids, bool giov) { struct protection_domain *pdom = to_pdomain(dom); unsigned long flags; @@ -2525,7 +2525,7 @@ int amd_iommu_domain_enable_v2(struct iommu_domain *dom, int pasids) goto out; if (!pdom->gcr3_tbl) - ret = domain_enable_v2(pdom, pasids); + ret = domain_enable_v2(pdom, pasids, giov); out: spin_unlock_irqrestore(&pdom->lock, flags); diff --git a/drivers/iommu/amd/iommu_v2.c b/drivers/iommu/amd/iommu_v2.c index 864e4ffb6aa9..0ddd10953d41 100644 --- a/drivers/iommu/amd/iommu_v2.c +++ b/drivers/iommu/amd/iommu_v2.c @@ -784,7 +784,7 @@ int amd_iommu_init_device(struct pci_dev *pdev, int pasids) dev_state->domain->type = IOMMU_DOMAIN_IDENTITY; amd_iommu_domain_direct_map(dev_state->domain); - ret = amd_iommu_domain_enable_v2(dev_state->domain, pasids); + ret = amd_iommu_domain_enable_v2(dev_state->domain, pasids, false); if (ret) goto out_free_domain; From patchwork Wed Jun 21 23:54:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suravee Suthikulpanit X-Patchwork-Id: 111358 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp4726136vqr; Wed, 21 Jun 2023 17:06:02 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5CuhYK827DtbtWv9b6xmx5op3Wj9SNP69Qf/ciZvDyXIBmG9ZX8onP4ju2WRN9efqKzPbi X-Received: by 2002:a05:6a20:7f81:b0:114:7637:344f with SMTP id d1-20020a056a207f8100b001147637344fmr23275799pzj.49.1687392361691; Wed, 21 Jun 2023 17:06:01 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1687392361; cv=pass; d=google.com; s=arc-20160816; b=V0kGnc5ff3XW1aQPEwHzIvzQqME8X83lJBb84L0Pu5ZaEMKeZ68yQdY+8n+oKNdtSU gzJEilPuq/777kXYuo7rderquY3bo0XF00AZM+qpr1sDZFEhtNv1ykeWtU1vG9hRu7JK nh2kna70mQDhMmtsSLLkLn0fDh3iTomAALAh09bt1eKILUTUdsyYp8GvFNcCVMMtxDTA PL7S/CA2zlacoyJrg+DRAcZvF6sbmzItyWbaKQmEU3BAo4bYoeD+aXs8YxsuOdu6bzYy 20Qt3J8g4yo8VQYD6pRhAPgytzQYANh6ggJoD5Gv8v2Zt7YwexEHfkyiJ1cgJtCHiFJD rJaQ== 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=gSPrSEAa3+LIYJDZ4lFCFstgZyqmi5f7j1/nqqglRWc=; b=nrBK4svk8oETHEU7AJe/17Ul20kQFz72ysnVyTR31i4LFfsOc5kmhrzbjhU13v9e3l lCkFXxfk+oXNeTF4MeOdn2GG9lUWPw1WmMJicXHCtgLeV1l3EigdQy3N/LrA6w0S5W82 8av8MyN9rxOaBeGwfF7FH5QxgGTdi76WJ/a6qkpILActJ6B4A15yDgnBoVS0+Ok1jW3F tayCThIcrQVdwoQPHza+cIaLGLCNtuyK7BFAR1VWVaTwB/vMtq0lwDYzzmPbF7zDflqp j85eaa1soXodBDwtg9+uQtn9GQh1ptJpOo6z7UgeLM6oYMhJPC4bwa5P2v2cuK5nAMW8 GyMw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=aGtRQNiD; 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 b5-20020a63eb45000000b0054f93b605cdsi5230560pgk.37.2023.06.21.17.05.47; Wed, 21 Jun 2023 17:06:01 -0700 (PDT) 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=aGtRQNiD; 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 S229501AbjFUX4K (ORCPT + 99 others); Wed, 21 Jun 2023 19:56:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229999AbjFUXzv (ORCPT ); Wed, 21 Jun 2023 19:55:51 -0400 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2041.outbound.protection.outlook.com [40.107.223.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A5F1F171C; Wed, 21 Jun 2023 16:55:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JeFrL9n2r6WsMWSJUad5tQFMBoGVxeSoNVT6eFciLGbQQDKu/JHqh1y5WWHveHgLIs+J6UBVR/J2FoB2vEiAERG4HdQCNVeZZt5nZ5su/Z9h2CyVe/lqvTE2utWXwx/RwLaaGEe7du0ZK8XyQQMzX0TH+IqxCDD+rRXItf7zhly9pe3Ges8B5AknpIvLpHPDM0Jy9sse5RJqNvKgQGvr+ggKOSeWgqjcC5HUQ0TDSZEZBQxL57gGiLbR/cIwEYwE0TnqJpPfFbD5Kuky2Eeq4FqSA6l9Bwr1Hwwn8iRXYnPjSH9IqAqMIx6T93d6KLJMXnQhZjM0gvl0yAScSMlzgg== 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=gSPrSEAa3+LIYJDZ4lFCFstgZyqmi5f7j1/nqqglRWc=; b=nZA2dINL0Y5faZc48HtDIkOQi69pffkKS2X/wBL3Zh0V31WJ03Y29xO0dxrnLNz9qjIn9NZIt0oy4cqWHli1IBdIreZUpgv5WOBurMCjj7uF/hbACAcxEAFmyuBgyElUpgwDOujPkB0vX7BHl/Adx4T3L7C/aHSqf8+oYBQgo07DOMMsLQrNvw9Eaxa41r7rCTnQ+8JQdDVwakrAhuaBOezwOIo/9WPVcOhw+37xjRU+LMc2swPuiVFmN7NGT/TXL9aVmuP5z/nvgLhWFdRHTpQGI8OwuJxCHZQNLZt5usZf6UhfDCH2ZQ0xTAyoZyH+UBE4/MdfuE5uIRgPJED8RQ== 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=gSPrSEAa3+LIYJDZ4lFCFstgZyqmi5f7j1/nqqglRWc=; b=aGtRQNiDffePbOTn9fTzYEPWRs6paWCTa8m2hpHwlTxeQE7UW04qXQMoxrKxuWGzdIIOjuh1eJ20N+HRHOr3VnAkt6aaQHSYz4LE5IiB9XZ+o1FwQuiFy1X8ACSJP3p7t/g1hOtbPLC52uJndet41ztykZ+69ggr8v+sHxD8D60= Received: from CY5PR15CA0052.namprd15.prod.outlook.com (2603:10b6:930:1b::9) by IA0PR12MB7625.namprd12.prod.outlook.com (2603:10b6:208:439::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6500.37; Wed, 21 Jun 2023 23:55:48 +0000 Received: from CY4PEPF0000E9D4.namprd03.prod.outlook.com (2603:10b6:930:1b:cafe::c4) by CY5PR15CA0052.outlook.office365.com (2603:10b6:930:1b::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.21 via Frontend Transport; Wed, 21 Jun 2023 23:55:47 +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 CY4PEPF0000E9D4.mail.protection.outlook.com (10.167.241.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6521.21 via Frontend Transport; Wed, 21 Jun 2023 23:55:47 +0000 Received: from ruby-95f9host.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.2507.23; Wed, 21 Jun 2023 18:55:46 -0500 From: Suravee Suthikulpanit To: , , CC: , , , , , , , , , , , , , , , "Suravee Suthikulpanit" Subject: [RFC PATCH 05/21] iommu/amd: Refactor set_dte_entry() helper function Date: Wed, 21 Jun 2023 18:54:52 -0500 Message-ID: <20230621235508.113949-6-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230621235508.113949-1-suravee.suthikulpanit@amd.com> References: <20230621235508.113949-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: CY4PEPF0000E9D4:EE_|IA0PR12MB7625:EE_ X-MS-Office365-Filtering-Correlation-Id: dd94c437-1e02-4831-622e-08db72b3090d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: GHCHekY8JjVpha0ypVrIWbrwQ0gPLCWww0oL2WuoWGHlR8hVjblKKbySoMGiHzhT1aGfDh4oizSa3Qt6qdR5M3rje0q/7MLmKTQrVimjVdpFP1wlb6uxaCdFblMe4M95aucRvhvTErYZLOdpGXoGvRWHFaZtH5aJNbszWaSPqv3chyEkdhe1+eRcG1/sDhM00KNkY+6QnSdhUf5a/iHWkGKthioh1eUWngv9RVvqS3Yx48XN/0e9ejDgWM3RC0i22He2TuvOoNfZ5N1M50Fdfb76mnyWDFBGluZIoOoMClCPNxr1clqdihkBb3vseYUmwd2nxPXUa+ZJQ9knatwtRxOxPkVskDOAHegxpdo5dDfxJp1YvRnz3WtrOZll4zJUsnUO2ZQCFtoMLR4rnp7EUj0t3tLoEqjS5CRbiBFw30xM1VTDrbd2LYPk+O1zJhBaiME+rgdArxy/RrhgShoZUGHGhrZNr3vj8ZCltO8/+rpt/oRiWCFF/C++yySLerbD76KarIGDnVaipEvS1DrhpmmLrhQgNEV2wiXBeosf1PZwC4ikxE5gD8zl6kkTIH+I5l5Mu5zw1/aw2odonJOiHQJvaCwGBFcguzBv8hme+XXDXSARJHIxNXs/ggzb+wnp1I3HqU2f2iLpWKY4qei31GX1UXpcmbXwgp4+pAa3DteTV9HdyiNRygXkGL2mkyeH4+BRQ5v884+OZwDEBXdt0JuplItAC8SCX9wiXyrK5Y5cxbw85nkm2PBGA+HCrWCcHu2Cm6nTDolIrjhH+1zC1w== 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:(13230028)(4636009)(396003)(346002)(39860400002)(376002)(136003)(451199021)(36840700001)(40470700004)(46966006)(356005)(81166007)(36756003)(82740400003)(40480700001)(86362001)(40460700003)(82310400005)(70586007)(2616005)(41300700001)(8936002)(316002)(8676002)(478600001)(4326008)(70206006)(44832011)(47076005)(426003)(83380400001)(1076003)(336012)(7416002)(5660300002)(6666004)(7696005)(16526019)(186003)(54906003)(110136005)(26005)(36860700001)(2906002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jun 2023 23:55:47.8547 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: dd94c437-1e02-4831-622e-08db72b3090d 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: CY4PEPF0000E9D4.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB7625 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=no 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?1769359132867793886?= X-GMAIL-MSGID: =?utf-8?q?1769359132867793886?= To separate logic for IOMMU guest (v2) page table into another helper function in preparation for subsequent changes. There is no functional change. Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/iommu.c | 72 ++++++++++++++++++++++----------------- 1 file changed, 41 insertions(+), 31 deletions(-) diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index 6017fce8d7fd..3b31ecde0122 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -1553,6 +1553,42 @@ static void free_gcr3_table(struct protection_domain *domain) free_page((unsigned long)domain->gcr3_tbl); } +static void set_dte_entry_v2(struct amd_iommu *iommu, + struct protection_domain *domain, + u64 *gcr3_tbl, u64 *pte_root, u64 *flags) +{ + u64 gcr3 = iommu_virt_to_phys(gcr3_tbl); + u64 glx = domain->glx; + u64 tmp; + + if (!(domain->flags & PD_IOMMUV2_MASK)) + return; + + if ((domain->flags & PD_GIOV_MASK) && + iommu_feature(iommu, FEATURE_GIOSUP)) + *pte_root |= DTE_FLAG_GIOV; + + *pte_root |= DTE_FLAG_GV; + *pte_root |= (glx & DTE_GLX_MASK) << DTE_GLX_SHIFT; + + /* First mask out possible old values for GCR3 table */ + tmp = DTE_GCR3_VAL_B(~0ULL) << DTE_GCR3_SHIFT_B; + *flags &= ~tmp; + + tmp = DTE_GCR3_VAL_C(~0ULL) << DTE_GCR3_SHIFT_C; + *flags &= ~tmp; + + /* Encode GCR3 table into DTE */ + tmp = DTE_GCR3_VAL_A(gcr3) << DTE_GCR3_SHIFT_A; + *pte_root |= tmp; + + tmp = DTE_GCR3_VAL_B(gcr3) << DTE_GCR3_SHIFT_B; + *flags |= tmp; + + tmp = DTE_GCR3_VAL_C(gcr3) << DTE_GCR3_SHIFT_C; + *flags |= tmp; +} + void set_dte_entry(struct amd_iommu *iommu, u16 devid, struct protection_domain *domain, bool ats, bool ppr) { @@ -1586,38 +1622,12 @@ void set_dte_entry(struct amd_iommu *iommu, u16 devid, pte_root |= 1ULL << DEV_ENTRY_PPR; } - if (domain->flags & PD_IOMMUV2_MASK) { - u64 gcr3 = iommu_virt_to_phys(domain->gcr3_tbl); - u64 glx = domain->glx; - u64 tmp; - - pte_root |= DTE_FLAG_GV; - pte_root |= (glx & DTE_GLX_MASK) << DTE_GLX_SHIFT; - - /* First mask out possible old values for GCR3 table */ - tmp = DTE_GCR3_VAL_B(~0ULL) << DTE_GCR3_SHIFT_B; - flags &= ~tmp; - - tmp = DTE_GCR3_VAL_C(~0ULL) << DTE_GCR3_SHIFT_C; - flags &= ~tmp; - - /* Encode GCR3 table into DTE */ - tmp = DTE_GCR3_VAL_A(gcr3) << DTE_GCR3_SHIFT_A; - pte_root |= tmp; - - tmp = DTE_GCR3_VAL_B(gcr3) << DTE_GCR3_SHIFT_B; - flags |= tmp; - - tmp = DTE_GCR3_VAL_C(gcr3) << DTE_GCR3_SHIFT_C; - flags |= tmp; - - if (amd_iommu_gpt_level == PAGE_MODE_5_LEVEL) { - dev_table[devid].data[2] |= - ((u64)GUEST_PGTABLE_5_LEVEL << DTE_GPT_LEVEL_SHIFT); - } + set_dte_entry_v2(iommu, domain, domain->gcr3_tbl, &pte_root, &flags); - if (domain->flags & PD_GIOV_MASK) - pte_root |= DTE_FLAG_GIOV; + if ((domain->flags & PD_IOMMUV2_MASK) && + amd_iommu_gpt_level == PAGE_MODE_5_LEVEL) { + dev_table[devid].data[2] |= + ((u64)GUEST_PGTABLE_5_LEVEL << DTE_GPT_LEVEL_SHIFT); } flags &= ~DEV_DOMID_MASK; From patchwork Wed Jun 21 23:54:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suravee Suthikulpanit X-Patchwork-Id: 111349 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp4721684vqr; Wed, 21 Jun 2023 16:57:25 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5GR/Eap+Gdubhw6W4JFFNOGVaCe0bW5sVLgf0nw3MeTnTREaRoq2vWOuMk3iVKlpF+Dc6U X-Received: by 2002:a05:6a00:1956:b0:668:7292:b2d1 with SMTP id s22-20020a056a00195600b006687292b2d1mr9080421pfk.9.1687391845068; Wed, 21 Jun 2023 16:57:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1687391845; cv=pass; d=google.com; s=arc-20160816; b=pej9TZG6K9uwfrdpOi9qzdYcXvD8RtvjAAr53gpmCF7fVKYdGuhX0asTXCJfw88Oa0 NyvC/502FRSjsoWGoDbiPezyF0GKHCXGcmww6hUd4207tQPbpwiKwPJLVUabrdEgoWDL IYNJJJBNBkvx6zw2zrvC+cntZw7qOlGyS8vVbKgXd9wjMnT4516fGxrvy1ylt59m81oY JDe2niVVPiilJuNLOQLcTjmOa2MMQDGZ6j83XiUzLjc3bXG9Tl6b0h8DJfiBD8dSTVin BboSag61ET+xxJ4y13iRoj7PvDYtyjK1j2Ryl1XHM98AGRHgMjFXCr3VwtqtBE/Uh8Um dbiA== 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=zGNRyfGK4mdTMzFSz+GKDdonCpxeLi7YSFP+IeRBqlc=; b=U5o9P1jajyB+CVVXx1jcQf6W4ZEGnEaySLiU+Fj0CfT8ZEI7ZUj+pskXOTakBpu2Df 3AVssBwoLTaVKOjGYoEXPOAa6Ugb04lFUqFfdBoZNU3vVX2icOvY43l0dzoygPw8mAZ5 aj4KsKZ1UDYZbCNS3lEj0I+l1enNyPmLGVS69v7olZs0UjkghLhtt+KWDfAiGUGWvpej Mfh6FC3qHB6fD9ynSCDLZJTmgoo8U6Rpzh4fEKOw7uo0DL5Dad3iu4LoyW0rPODv8fmV Cek+Z+TiNIA7GhXM8IYWxZoV/CtjMT/Z/Dt2brA7FEhCe09UjUhzsho26aQnRMxs+uR0 qx7g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b="pNUvl/1b"; 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 t190-20020a625fc7000000b006687388a0b6si5043078pfb.309.2023.06.21.16.57.10; Wed, 21 Jun 2023 16:57:25 -0700 (PDT) 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="pNUvl/1b"; 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 S230241AbjFUX4O (ORCPT + 99 others); Wed, 21 Jun 2023 19:56:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230007AbjFUXzw (ORCPT ); Wed, 21 Jun 2023 19:55:52 -0400 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2057.outbound.protection.outlook.com [40.107.94.57]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A0CC1710; Wed, 21 Jun 2023 16:55:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gd6c6DWiafCTp2ztB4go7PY8HSdmHMSH9OUfhk413TjCTdF59gpgZsw58IJ3Nk9hanua5CpuGMpiEFP5QJUjV0pUVlF0ayzCGviBRPXMVJV0orzobDrVv60bD8wPRDNQYWmIMy29SKktxMwnn1RhLtRoU44NTLod5YB0AxEn+L+ZTqpdd1UIsppxMiJ9fsPX31+Nfk5VxfBjP+k/VdN9MJ23RVQ6aglR3k/CkIJtuFS/DL66Hb45RPjBrLRLlcFug0n4uVnny7JdtjH3nYQ4P5qu5rCp9TT8BTXs+KXhDTzLpDCxx5exCmTbZc85Poz+RI58Ay8csWLYh+/Wb+JRFw== 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=zGNRyfGK4mdTMzFSz+GKDdonCpxeLi7YSFP+IeRBqlc=; b=iwIZuJv9aKkQBQnBdRmoz8vR1wF/IYQjc/h1brmBO1Kjpya/s34rec04u24BK4gASnVYLSTYHi8bz+5Wj4VaXckpDm316EAUqY2UI3E4qp1zQ7Hc8W+Y4z2z7jk6JhXXn07whtEQCv0Twnfepkr0WYEyGbWU45+BvYE7EYBvtnE1aWpeINwD+APKUjHU3RP0p6/pW4h4vug+IG0eFKW3z8PFSNNLC313QrWgZAwCwytF0y4f9IwgEQAOmuLUmS3O1H/6NRcZdvlFeenDYiEvRC+ISUAOO43XiGRIl3VnrbBHVRebfCRv2ENTIRa0QI5EDAaAF7P0QK8ON0jfhAdBbw== 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=zGNRyfGK4mdTMzFSz+GKDdonCpxeLi7YSFP+IeRBqlc=; b=pNUvl/1bFvCscc5WAVEJdVWq86k37pBRMP0C1ogX6IyJ6ASQN9DK68Ir195onPLIbs5si1aWfoVqQCOQvcoDR4MXVPCnV7IYRF6PEGusyuTmkRi3qZv017HRz8qlIH9XDk+ENlHEzky8CTftjvoPOY1ihokiaHtVTNIbYiy/KtU= Received: from CY5PR15CA0035.namprd15.prod.outlook.com (2603:10b6:930:1b::22) by DM6PR12MB5008.namprd12.prod.outlook.com (2603:10b6:5:1b7::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.23; Wed, 21 Jun 2023 23:55:49 +0000 Received: from CY4PEPF0000E9D4.namprd03.prod.outlook.com (2603:10b6:930:1b:cafe::68) by CY5PR15CA0035.outlook.office365.com (2603:10b6:930:1b::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.21 via Frontend Transport; Wed, 21 Jun 2023 23:55:48 +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 CY4PEPF0000E9D4.mail.protection.outlook.com (10.167.241.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6521.21 via Frontend Transport; Wed, 21 Jun 2023 23:55:48 +0000 Received: from ruby-95f9host.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.2507.23; Wed, 21 Jun 2023 18:55:47 -0500 From: Suravee Suthikulpanit To: , , CC: , , , , , , , , , , , , , , , "Suravee Suthikulpanit" Subject: [RFC PATCH 06/21] iommu/amd: Modify set_dte_entry() to add gcr3 input parameter Date: Wed, 21 Jun 2023 18:54:53 -0500 Message-ID: <20230621235508.113949-7-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230621235508.113949-1-suravee.suthikulpanit@amd.com> References: <20230621235508.113949-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: CY4PEPF0000E9D4:EE_|DM6PR12MB5008:EE_ X-MS-Office365-Filtering-Correlation-Id: 9cac8257-46cc-4cc0-e63e-08db72b30992 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: CKJYfh11c6zLG16peuQ70hb/dk0m6rk2zRP1HESICEfzbWNds/HcbZ8X7LVlGLXpba02dv0qcxwJqB59DxtONMz6DAJ5KuH0MyHUdDmsrux65o5+J9jYc+ASoRFwhVLi/3+W+dcm5yC9lAvtLGanscK+RsQT5e8RgZ2UdfbUfFtGaU/ehQw5iMd3wQ46FUKfRzn8i3otg65VnDQIf74JFutRSEPBiWeZ10hF5+fAGTGC7ZEzldGOX3+Q7b5XyYkrywW044yjrIKexx+5riWrMrF1iV5AsIBoySV4rQrHP12Tz1WN2hmZyx6g1Zv3n6n/LyKHGm2GCSJZCDLRcMovgDUg2Mj3xPb9aKqt6heJuJLPb1qaXXsTkbWHrBTDintnCHFIjF8+JUzcVXsFyTvL3cxKf9+2VRzynaaXf/9UYPngQH5Wp+m0A13G6hmo8FlJTvUxujIMUAOJNsHYLJ2iJyA/36Im1nd3tH0sgukndP9Ve4O5NZ1V8CRfPoXdsBUXLeini/2pfxIciFu82u61Gu8yiWScs5vvdRCtxaAnCU5rxp7SYMyT+mHp9k+Mv8sonXz8t0K7SZmpSxHDqVA74PJD4LfezfrHjignp5lj9JF3MSKCu8b2cNwqSz+1hY9Eg2EynmPQQ2qRCR/NolWbkXAgU7JALcxfA7tRwVhYC4T7hN7jAeMBsbswiPtG+Oswdig4B2eVANHjd8S7EtFqXHyK5aLHBc0K3dEBrHjIP/OR/3z60vIs97a/UMl24KOSNa0qTJmqX2ISvmwBVT/gmg== 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:(13230028)(4636009)(346002)(136003)(39860400002)(396003)(376002)(451199021)(40470700004)(46966006)(36840700001)(6666004)(110136005)(4326008)(54906003)(478600001)(47076005)(40480700001)(336012)(2616005)(426003)(83380400001)(36756003)(86362001)(36860700001)(40460700003)(2906002)(186003)(82310400005)(70586007)(16526019)(7696005)(1076003)(26005)(356005)(82740400003)(81166007)(316002)(70206006)(8676002)(41300700001)(8936002)(5660300002)(44832011)(7416002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jun 2023 23:55:48.7297 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9cac8257-46cc-4cc0-e63e-08db72b30992 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: CY4PEPF0000E9D4.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB5008 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=no 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?1769358591324699913?= X-GMAIL-MSGID: =?utf-8?q?1769358591324699913?= To preparation for subsequent changes. There is no functional change. Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/amd_iommu.h | 1 + drivers/iommu/amd/iommu.c | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/amd/amd_iommu.h b/drivers/iommu/amd/amd_iommu.h index 5d2eed07a1fa..dbfc70556220 100644 --- a/drivers/iommu/amd/amd_iommu.h +++ b/drivers/iommu/amd/amd_iommu.h @@ -16,6 +16,7 @@ extern void iommu_feature_disable(struct amd_iommu *iommu, u8 bit); extern u8 __iomem * __init iommu_map_mmio_space(u64 address, u64 end); extern void set_dte_entry(struct amd_iommu *iommu, u16 devid, struct protection_domain *domain, + u64 *gcr3_tbl, bool ats, bool ppr); extern int iommu_flush_dte(struct amd_iommu *iommu, u16 devid); extern struct protection_domain *to_pdomain(struct iommu_domain *dom); diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index 3b31ecde0122..4728929657f5 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -1590,7 +1590,9 @@ static void set_dte_entry_v2(struct amd_iommu *iommu, } void set_dte_entry(struct amd_iommu *iommu, u16 devid, - struct protection_domain *domain, bool ats, bool ppr) + struct protection_domain *domain, + u64 *gcr3_tbl, + bool ats, bool ppr) { u64 pte_root = 0; u64 flags = 0; @@ -1622,7 +1624,7 @@ void set_dte_entry(struct amd_iommu *iommu, u16 devid, pte_root |= 1ULL << DEV_ENTRY_PPR; } - set_dte_entry_v2(iommu, domain, domain->gcr3_tbl, &pte_root, &flags); + set_dte_entry_v2(iommu, domain, gcr3_tbl, &pte_root, &flags); if ((domain->flags & PD_IOMMUV2_MASK) && amd_iommu_gpt_level == PAGE_MODE_5_LEVEL) { @@ -1686,7 +1688,7 @@ static void do_attach(struct iommu_dev_data *dev_data, domain->dev_cnt += 1; /* Update device table */ - set_dte_entry(iommu, dev_data->devid, domain, + set_dte_entry(iommu, dev_data->devid, domain, domain->gcr3_tbl, ats, dev_data->iommu_v2); clone_aliases(iommu, dev_data->dev); @@ -1965,7 +1967,7 @@ static void update_device_table(struct protection_domain *domain) if (!iommu) continue; - set_dte_entry(iommu, dev_data->devid, domain, + set_dte_entry(iommu, dev_data->devid, domain, domain->gcr3_tbl, dev_data->ats.enabled, dev_data->iommu_v2); clone_aliases(iommu, dev_data->dev); } From patchwork Wed Jun 21 23:54:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suravee Suthikulpanit X-Patchwork-Id: 111361 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp4728869vqr; Wed, 21 Jun 2023 17:11:56 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6XQn3/R8Zt1P3SHmu40g8YFiH55Esw7dymfWDkFy+L5Pk7BEX4XZOAV3iZabeQ+fxbRMNt X-Received: by 2002:a17:902:d489:b0:1b0:3a03:50d0 with SMTP id c9-20020a170902d48900b001b03a0350d0mr20765480plg.26.1687392716173; Wed, 21 Jun 2023 17:11:56 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1687392716; cv=pass; d=google.com; s=arc-20160816; b=HlyAZ/OAlFpkDrFDuo7ym/knOSoWJIo6lJyvyZw0wOx+IUo5sAiAH7J/Wd8kBd+6Aj vhzG6AGA22QqLXrcpkMfRrr0ct6BN0unFBZwW6A+tXsrYXJrliCmdIUHDYgYexvoFPOg hWnhrwrdJJTo2lYRoTGwFgS0RNkpoRwmmDOdPDWYHjcwUC1REmUXGf6DxV/LRkJJfiZ3 SzhRDjokF47ZHpaeSwdcnQgDQXn92Z+/fsLCv4CObutSbCQhg9WjC7u/StdQ8Ngk/6zy QYsjJ/93V7UihA8m4woni2dpe4k0zSBBsy+FS5L9XA6ELGQV/6RTMgnMfpGrcsiZhlrc npVw== 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=Zhubrmf4ky5HkOPhrtywcxqqAIJ6An6kzyc696QJ8CA=; b=SgVJfvZiVjYwNJdDC2YsTOFQ1FXeLVGE+OJD3D47b4BdUfFscqXXUSjUeJwgEw0gOB EBPiczqtXLzI+TyvGhH4Srbv3jdVxE0+UA5z5FdnS6MFVb3F39afXm+wdlH2h1wEwoLZ hWR6Vc17QvkR90FvLUJfMtGLi5tdiCHWQcTTdmaE7/kat43hj6UFWb73pJSgqdWaLxb5 hUTW0rT0+CCFZiLCbfBgv0ZLCeEwy/HhTb04xJ4Qk3X22WBujDbIVQ2Mc7l6YuJZ2+dx 49c4+s4uomknGfAmAjpgiQACtmRrmJF43fw2+bdFf4ktJYHT0r0MwRuNwywdzwLSSYKd 9xUg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=mNKjOjaB; 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 t18-20020a170902e85200b001b69af99ad9si2629111plg.401.2023.06.21.17.11.42; Wed, 21 Jun 2023 17:11:56 -0700 (PDT) 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=mNKjOjaB; 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 S229779AbjFUX4X (ORCPT + 99 others); Wed, 21 Jun 2023 19:56:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229994AbjFUXzz (ORCPT ); Wed, 21 Jun 2023 19:55:55 -0400 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2044.outbound.protection.outlook.com [40.107.244.44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03D451735; Wed, 21 Jun 2023 16:55:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gQTC225F29bDjIizZLCPBygr4CsOSNEr7kCs20fHnsUertI8uE4dPY8inQCAV9IvgB8/U3sf8sn49ynJei3OUxJ1K8CRLBuIe/LuI6Ls04Ee6t/zNbFJ54Xxp2B7YPWS9TUGs+SKktkTu3H/xyznvgsNhTLvluPwIeUBCLyduGerIrSNXHZaPoZTZ+zPUp3bX+0Ihp2aU26tNCmOnJRNvEcSWefyQfgJfejq/MdX+e3zg6ZHuSLoqUNyLan8DiA1ieQ3i0c6M7EbZC8LM+4dpGF4nIdyPIZYQE7eKinf+rqjAdRuE0gzRgwq9lIxIXsz4nyyRTGR00mz/rx9FkcByg== 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=Zhubrmf4ky5HkOPhrtywcxqqAIJ6An6kzyc696QJ8CA=; b=Uq2SzgdRca52Tom2fuphbafldLeQkEgk5Sg9fXBbauPN+DUbleqrm+pFtjmtWmpkDEqWhHZ8fJykn5yfNpyZegqRxcR6oeZNQRHmml9JXHDrpchJ57Hk1y4mx4FssQaFEo7dTlBDAbRB3NwWkRBePssNfMGJjq8lNr9OZNvoz+8ji02HFzeRZF+0fvc0/GWbsI2use8sxyS3X54+KNPMdEgTeG9A1gX9erwizjkkfdOoL2jOokhJvqArn+7OD8d6rL6IslyOqp4JmQlpwSWibJG+5Hye7+qDuLTSAiXxh3KrHhMv26nFkhdyq1rq10l/Nlyqc2F7VdwLKnH3wN+2JA== 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=Zhubrmf4ky5HkOPhrtywcxqqAIJ6An6kzyc696QJ8CA=; b=mNKjOjaBWijKU3ZYO6XMqrdKrXxet4IF6cCNXeuwAGqwwW1IsdthATEPuvfnSHE/wdpf709xabtBjiUHf8HCCf8yVZ+Q/W3sbOu9ehtAIIJWJzVDZfEoDzOfVE4pL0Jo26Ea2RUBV2g4ZCGE38zbi2RsYmK4yCJuCywXSrKXGyU= Received: from CY5PR15CA0042.namprd15.prod.outlook.com (2603:10b6:930:1b::26) by SJ0PR12MB5469.namprd12.prod.outlook.com (2603:10b6:a03:37f::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.23; Wed, 21 Jun 2023 23:55:50 +0000 Received: from CY4PEPF0000E9D4.namprd03.prod.outlook.com (2603:10b6:930:1b:cafe::c8) by CY5PR15CA0042.outlook.office365.com (2603:10b6:930:1b::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.21 via Frontend Transport; Wed, 21 Jun 2023 23:55:50 +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 CY4PEPF0000E9D4.mail.protection.outlook.com (10.167.241.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6521.21 via Frontend Transport; Wed, 21 Jun 2023 23:55:50 +0000 Received: from ruby-95f9host.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.2507.23; Wed, 21 Jun 2023 18:55:48 -0500 From: Suravee Suthikulpanit To: , , CC: , , , , , , , , , , , , , , , "Suravee Suthikulpanit" Subject: [RFC PATCH 07/21] iommu/amd: Modify set_dte_entry() to add user domain input parameter Date: Wed, 21 Jun 2023 18:54:54 -0500 Message-ID: <20230621235508.113949-8-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230621235508.113949-1-suravee.suthikulpanit@amd.com> References: <20230621235508.113949-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: CY4PEPF0000E9D4:EE_|SJ0PR12MB5469:EE_ X-MS-Office365-Filtering-Correlation-Id: 75a552d4-1f28-4ec4-a08f-08db72b30a8f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7FUQNR7dFw/Z+Vytpw4B2arlz4W2AxifmZj1i/bCMTyKzVATqKzYTy1DV0ZO4wXWr7TUt+y9Fk30+QZgn5SRaeYfDGWBLWIaJsxMKE4DXiCAMjXxmHC/TJ1BDAQBh6EHkjjZA+LZwNQblk3egc0TpKyMpfCSU7CTY8W1gF+VR4IswwlrEz2yhQVKQ3eESZiDH8N6smhkLyjsgRoYAy8xUWiNR+M1E1hEyUr0ZLiY+zZ1FXmiwNS0BuMuBeTnGcBTH3wi60l5hHkt71Lg+2M/NVhta0xESJ8SzxkVg3lSPa0xBTcfgNVG1XoFI0qYKR/Sb/73GWiJdOXaSZ0YpSIu4HXkvX7xPlyr8zuaMPpfwhUOWEcWnpkf0UU5GqByGFDaZAQuAUnvpKzE5tbc1utmsOUChMbCD7YaAu4nqm+s3q+unOjcQw/GyDYf9SWrQu/FePPSi5ZLQkYApTbaD+RM3e7JNGXlSgwDrkMAydBd4m+7qh8HaWkMTEkplKejGkW0HfpDFQ5pmnyrgyjaONXq+Hvp5lrlSiE7rAy67bjPRRnr981UuMpbPqiprxZwfOB0vokCN2ox/lYi75zU4ZQ98a973pDMCH22satQKJiXCxo6oYD4plT4wm6C7zycjEZRyKIj/L3JTEBBCP7KesSi/HdYnK05CogDwt2cOHEMXhUOklpmx+JQsFXnXdZLcgfBvM3d4vdIpZLpZrNTf4aYrcqXPAVnvWGUHIg6vPGoFtq2bBYUlD4lHq9+xANHKGqZGkL7y5FdF+qCZuSHMlFwPQ== 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:(13230028)(4636009)(136003)(396003)(39860400002)(376002)(346002)(451199021)(36840700001)(46966006)(40470700004)(7696005)(6666004)(82310400005)(83380400001)(356005)(81166007)(40480700001)(26005)(16526019)(1076003)(186003)(336012)(2616005)(47076005)(426003)(36860700001)(40460700003)(36756003)(70586007)(70206006)(4326008)(316002)(2906002)(8936002)(8676002)(7416002)(44832011)(5660300002)(86362001)(110136005)(41300700001)(54906003)(82740400003)(478600001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jun 2023 23:55:50.3860 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 75a552d4-1f28-4ec4-a08f-08db72b30a8f 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: CY4PEPF0000E9D4.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB5469 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=no 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?1769359504632410940?= X-GMAIL-MSGID: =?utf-8?q?1769359504632410940?= When setting up IOMMU page table in nested mode, the host (v1) table is managed by the hypervisor, while the guest (v2) table is managed by the guest kernel. In this case, IOMMU driver needs to program IOMMU device table entry (DTE) using the set_dte_entry() helper function with guest table information (i.e. gcr3 table, glx, max pasid), which is stored in the user domain. There is no functional change. Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/amd_iommu.h | 1 + drivers/iommu/amd/iommu.c | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/amd/amd_iommu.h b/drivers/iommu/amd/amd_iommu.h index dbfc70556220..d36a39796c2f 100644 --- a/drivers/iommu/amd/amd_iommu.h +++ b/drivers/iommu/amd/amd_iommu.h @@ -16,6 +16,7 @@ extern void iommu_feature_disable(struct amd_iommu *iommu, u8 bit); extern u8 __iomem * __init iommu_map_mmio_space(u64 address, u64 end); extern void set_dte_entry(struct amd_iommu *iommu, u16 devid, struct protection_domain *domain, + struct protection_domain *udomain, u64 *gcr3_tbl, bool ats, bool ppr); extern int iommu_flush_dte(struct amd_iommu *iommu, u16 devid); diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index 4728929657f5..333c8a4831be 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -1591,9 +1591,11 @@ static void set_dte_entry_v2(struct amd_iommu *iommu, void set_dte_entry(struct amd_iommu *iommu, u16 devid, struct protection_domain *domain, + struct protection_domain *udomain, u64 *gcr3_tbl, bool ats, bool ppr) { + struct protection_domain *dom; u64 pte_root = 0; u64 flags = 0; u32 old_domid; @@ -1624,7 +1626,8 @@ void set_dte_entry(struct amd_iommu *iommu, u16 devid, pte_root |= 1ULL << DEV_ENTRY_PPR; } - set_dte_entry_v2(iommu, domain, gcr3_tbl, &pte_root, &flags); + dom = udomain ? udomain : domain; + set_dte_entry_v2(iommu, dom, gcr3_tbl, &pte_root, &flags); if ((domain->flags & PD_IOMMUV2_MASK) && amd_iommu_gpt_level == PAGE_MODE_5_LEVEL) { @@ -1688,7 +1691,7 @@ static void do_attach(struct iommu_dev_data *dev_data, domain->dev_cnt += 1; /* Update device table */ - set_dte_entry(iommu, dev_data->devid, domain, domain->gcr3_tbl, + set_dte_entry(iommu, dev_data->devid, domain, NULL, domain->gcr3_tbl, ats, dev_data->iommu_v2); clone_aliases(iommu, dev_data->dev); @@ -1967,7 +1970,7 @@ static void update_device_table(struct protection_domain *domain) if (!iommu) continue; - set_dte_entry(iommu, dev_data->devid, domain, domain->gcr3_tbl, + set_dte_entry(iommu, dev_data->devid, domain, NULL, domain->gcr3_tbl, dev_data->ats.enabled, dev_data->iommu_v2); clone_aliases(iommu, dev_data->dev); } From patchwork Wed Jun 21 23:54:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suravee Suthikulpanit X-Patchwork-Id: 111360 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp4726542vqr; Wed, 21 Jun 2023 17:06:49 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7pLtwH1Obk4OeQWPrxdKqEdXi8d+cu6Q7V7DYWfUvqE9q4GjrTiKi4nOO5T1e9oLS/ZZF3 X-Received: by 2002:a17:902:d34b:b0:1b3:f8db:6f0e with SMTP id l11-20020a170902d34b00b001b3f8db6f0emr12644591plk.43.1687392409308; Wed, 21 Jun 2023 17:06:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1687392409; cv=pass; d=google.com; s=arc-20160816; b=KhmDsQIuqYeXJ1Yac3L02iCGb74/5VUe0QqYqfInxNR3A+A+Ue5we1AbP6w5eFmdas tJ1oClm8i1Mlpy0Ey9G6TVVBIM4X1BdddctpANS4/4eM1TgVDKW6w4u6RsSid4gz84rF tNFcjsotRCRFdaDda6CcmYBKrlBc8maKU9HYaihVvAXqY2WAqSoos8Y8vQ+GUmk/ZMb2 M5eREOELmiw+Id1zjqpd55ATg3/HbQ0GIJtRe8K4V9eaLTKB2o0nYdQ7zOsOQC9M4R6a 6NH7yo084tpT0a64SP4zG8xEqS60jqvyNFPmQ9W3+CHIHeCRcKFYmtnMc6ctcPiGrYQV 5N8w== 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=rLb5xtN5TaWay0gJVTKsVlxdX6r0nThc1E7uO+JsurY=; b=uVteIS+U9m57ZvDHei/fBxgl/R1C+77RrEy6CfpfuS+/j7yaCOOFBzna7Mtb0V3DIZ mBxqHiXV51I+eD6FMgULP9tgwhdSzaVQjUT6BSmALvrtHwBD+W+zm7ShHgJIG60gM8KQ xaNnJZe3syscPe78Mn+w24VhKAXRU6Kl7hgZ3ZPqgUeMHCcLsMFwGogK8EjeDA96xtGV k9PoZI2WvuA6XHmC1hBPitbrWmag8CKJrDCL5U2o3HsrKoAj2OXItTOYXEaRSDRJI6So ggnFxLSsMfHL2vsdCNuSCynnVHNS8LTEFtZJ33iLxLLQ4YewAeSfZu3E4Yh4EU2k43tW ZPzg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=xBIDnbTR; 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 h9-20020a170902f7c900b001b231cb6f51si5202059plw.150.2023.06.21.17.06.36; Wed, 21 Jun 2023 17:06:49 -0700 (PDT) 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=xBIDnbTR; 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 S229908AbjFUX41 (ORCPT + 99 others); Wed, 21 Jun 2023 19:56:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229961AbjFUXzy (ORCPT ); Wed, 21 Jun 2023 19:55:54 -0400 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2054.outbound.protection.outlook.com [40.107.220.54]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43E4F1710; Wed, 21 Jun 2023 16:55:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZOJN4TC/0/d+E25u2CDXMKiSWOPVOw5oL3VjsLH1Lu7BpulJtOMOJXSWrxSQqTE/E75LMBHMf/RJF+k7G+S2JIGbzrvp8VSY7RZM/9MxPm+ErRbGhWQzsN2K4x+PELfaMqyUKkF0AoSakszwEj/YEm0PQNwGcnrWRTfbj6jhw/JWiB7kwefD4PqcIiiaK+gLePZUQgorrS/4nQUowSrtC7SvOh/QY8LbVgRl3rgHXCGJ2cmrQNiVuKw3pgTpObnn7UhNnQ3zHf/5Qwj5DSS6muA6UMfp0L/+lD1s79pMLFiv/KtQWvSmX/RXcg3Xg2nUUBfvn44bQD5g16/Pllir/A== 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=rLb5xtN5TaWay0gJVTKsVlxdX6r0nThc1E7uO+JsurY=; b=Uhhnllxe8q5oAzBIfMkDoOfuuROrut8KhYWEahZFR6uLKfUyGmLOm7YweTVgcfM3ZtE1yFcQq+eDa15R8uTTRQKiGBaLTcdNAgSJP5unsUuK03X8ougNaNKfA4OfAcgiqeJRw1vYFWdlHrwdmaOlY66Hggw1pRvAmlRw7iMHBsSSCL0eoCR5bUtXqCl/wumbzBXj/lIhFT243ZfIY2btvQBSX3L+mDpfGGELcHl4ql4r/R81DkZ0JyaV2/n7HBLRhFBr+bdEm29TobYLChdd6P4UJ/3GvscR6C2jth0zQUM+85YTnuIQlVhgMOzLYOt2ASe3aXF2PuNJSHlWbuQIGQ== 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=rLb5xtN5TaWay0gJVTKsVlxdX6r0nThc1E7uO+JsurY=; b=xBIDnbTRWPnsUnmg66556YLdXdfiwCs2UOmi/Ju3/oubKfs4zAVreaGBbrKrRv6ZgFixSJ0so2fpB0Qh/+aE5gNsOs6f3rckDOu69ZKjwNUlLmYFUwV1RQTPl4Xb6Kt0tqfKAPGaUlRa7XxWL8ZRmjsYJrs39S8W2FR6fLiEcJw= Received: from CY5PR15CA0053.namprd15.prod.outlook.com (2603:10b6:930:1b::30) by BL1PR12MB5302.namprd12.prod.outlook.com (2603:10b6:208:31d::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.21; Wed, 21 Jun 2023 23:55:51 +0000 Received: from CY4PEPF0000E9D4.namprd03.prod.outlook.com (2603:10b6:930:1b:cafe::df) by CY5PR15CA0053.outlook.office365.com (2603:10b6:930:1b::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.23 via Frontend Transport; Wed, 21 Jun 2023 23:55:50 +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 CY4PEPF0000E9D4.mail.protection.outlook.com (10.167.241.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6521.21 via Frontend Transport; Wed, 21 Jun 2023 23:55:50 +0000 Received: from ruby-95f9host.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.2507.23; Wed, 21 Jun 2023 18:55:49 -0500 From: Suravee Suthikulpanit To: , , CC: , , , , , , , , , , , , , , , "Suravee Suthikulpanit" Subject: [RFC PATCH 08/21] iommu/amd: Allow nested IOMMU page tables Date: Wed, 21 Jun 2023 18:54:55 -0500 Message-ID: <20230621235508.113949-9-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230621235508.113949-1-suravee.suthikulpanit@amd.com> References: <20230621235508.113949-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: CY4PEPF0000E9D4:EE_|BL1PR12MB5302:EE_ X-MS-Office365-Filtering-Correlation-Id: f84711e7-3783-4837-3b31-08db72b30acb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: KJT4n4Ec4KvH2bEojB86+baQFYdyYGnSWIxaOLQ9kK1k063657lOs8l3mtaUFPhVn+4IUASeaZribS9hrEvgzxmVsVdDnISSBg9QYfc6AwK7dqar34VBAKSA8n7HEaiQEr+w5MIHX4zvjye3pJWFcmqllkSG7Z/YlKayKyjd7OXpsxDQavDV7JqM9IVrkVrUGCFxaCSYdLUa+mRzb82VxMSQpBMlUc1n/8Ve90hVYjoRxK0bo32vJxoIvcHVPnhYKhmW/h2OIRgkI747b1CewDp25vFITzFISDdmwfqKoitKEGqQvYGMamxulSOcBMe9RDqVNpoO+7UMdCX/ZIgSSd4Aub5VIlGNDqAC9+0kRQ3vfCGN4tpVaZO91Xi11DvDLdppeqtkzFHuaNMysWKHm+Nhid74Dzm67ZxR1sle59H3xzQVhZ6mYnjquploOvJ0isO7w5ncvVoAK7g04sAArPyb1aNOIlvp77X6PdjZ1UgRNNvfw9oPMLmmFLPi09F+KrZFzFkEwPhJB2a38e1wLbpH2UnmSeWJE25O6apemxOsbApmC2kQ5eOT2SF4Vr22dh4lIBH5fg9d/CxLNrt+9Ox4wC80VOxZ8+0twU/euJjRuoFFT3eZ9whlcCNr997Z831dxBTLrXx/6e+u3HsMRZQUB5SS0PezCKLbjeSeETB3Vs7SuDQPd++XXvxUsPfbA2hKk05+NS8QVCo6QgQB7lG3O6aQHu6CauuxkvLEletcQEjL+lvHbjpUsxmLDLXzGkwF12aF8Mr/pqQp0PVLuQ== 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:(13230028)(4636009)(39860400002)(136003)(396003)(376002)(346002)(451199021)(46966006)(40470700004)(36840700001)(40460700003)(7696005)(6666004)(478600001)(83380400001)(16526019)(186003)(47076005)(426003)(26005)(336012)(2616005)(82310400005)(86362001)(82740400003)(36756003)(356005)(1076003)(81166007)(40480700001)(36860700001)(70586007)(70206006)(4326008)(41300700001)(316002)(7416002)(44832011)(8936002)(8676002)(5660300002)(110136005)(54906003)(2906002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jun 2023 23:55:50.7766 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f84711e7-3783-4837-3b31-08db72b30acb 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: CY4PEPF0000E9D4.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5302 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=no 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?1769359183150643239?= X-GMAIL-MSGID: =?utf-8?q?1769359183150643239?= The GCR3 table contains guest CR3 registers, and it is used to setup guest page tables. Current logic only allow guest CR3 table setup only when the host table is not setup (i.e. PAGE_MODE_NONE). Therefore, only 1-level page translation is allowed (e.g. host only vs. guest only). Remove this restriction to allow nested page table setup. Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/iommu.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index 333c8a4831be..c23f99ebdffc 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -2531,12 +2531,12 @@ int amd_iommu_domain_enable_v2(struct iommu_domain *dom, int pasids, bool giov) spin_lock_irqsave(&pdom->lock, flags); /* - * Save us all sanity checks whether devices already in the - * domain support IOMMUv2. Just force that the domain has no - * devices attached when it is switched into IOMMUv2 mode. + * With nested page table, we can enable * v2 (i.e GCR3) + * on a existing domain. Therefore, only check if domain + * already enable v2. */ ret = -EBUSY; - if (pdom->dev_cnt > 0 || pdom->flags & PD_IOMMUV2_MASK) + if (pdom->flags & PD_IOMMUV2_MASK) goto out; if (!pdom->gcr3_tbl) @@ -2688,9 +2688,6 @@ static int __set_gcr3(struct protection_domain *domain, u32 pasid, { u64 *pte; - if (domain->iop.mode != PAGE_MODE_NONE) - return -EINVAL; - pte = __get_gcr3_pte(domain->gcr3_tbl, domain->glx, pasid, true); if (pte == NULL) return -ENOMEM; From patchwork Wed Jun 21 23:54:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suravee Suthikulpanit X-Patchwork-Id: 111364 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp4731244vqr; Wed, 21 Jun 2023 17:17:31 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5uLC2J6+Wp6GJO6ElBCZ4j4eb3ymvbpGsDtBSf8aWB5Omk+FvNp9WK0JhWeAYAAvwJQX9W X-Received: by 2002:a17:90b:3687:b0:25e:aeaa:521d with SMTP id mj7-20020a17090b368700b0025eaeaa521dmr13457920pjb.15.1687393050974; Wed, 21 Jun 2023 17:17:30 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1687393050; cv=pass; d=google.com; s=arc-20160816; b=Mllep/DT1yN7CvR+fQs0IpfSB9Fra50caOat0eEjLaKO3AASWUKgn6hQKkcvoyeKHQ Nqe2OIy9fcw9Q/4KEsK2pMPGaUBRM2L7qlUSrRw6dy4gtwOBps1f3pZ5xE90PmARcgZw NqW+hedjhyQhxCvfHTltFkcT7kUDO/S5g90H23Yq7YzklRFft5W2QyJSf6gdIRy0nPDJ BON6sg/HuuhHuZS3KQ9ovRMQGh85VUPsO4bGTJbUyqNflv7CmtGVwwnHsGHHB1lA0BhL R5QgDbyK8IU23bRYQ1OeP0X+zTItroMNhz5f8J+jxs+Yct3jssADF853rbiN2WgFPxak ybpw== 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=h9c1V23bWJTyTuJZVhIWQIcbksX0hPKqLTQpOJXmFuI=; b=pu1LkXgsE38xk0WuFGj+W91fdWOCWIIUqmlE587BvbJuJ7pJZq+YSwhe5Eq3symmUG 6HCZEnfIB3yP8AbzGQWKcW37RjKm/obrbXW+5JjShhUonu69T0T8UqAV5cSNr4pO5f1i Np1YoNlZtK/AluKIR4dW+6xJkRiwqicL+uRgMMduIzKHjjFEXCaE7MtkEjmvekr/nlVQ j5mjU3fTkyBywom32g+zj9R5RWevFKhe3CfFs11AjpzE0tTMHS8YZFkuvcxaQ8Tds3gS HySR6ObHd0T20z06TbRDlczV03YDnFYZdMOv/BjK5K3rs2ELPEkPmxk6OZGtWBvWOAWk 0MhQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=Y8bE+0nL; 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 q92-20020a17090a756500b00232f57260c1si13146033pjk.1.2023.06.21.17.17.18; Wed, 21 Jun 2023 17:17:30 -0700 (PDT) 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=Y8bE+0nL; 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 S230260AbjFUX4S (ORCPT + 99 others); Wed, 21 Jun 2023 19:56:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230089AbjFUXz6 (ORCPT ); Wed, 21 Jun 2023 19:55:58 -0400 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2088.outbound.protection.outlook.com [40.107.223.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9AB6919BD; Wed, 21 Jun 2023 16:55:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=M3LVJ2yqU1aXUTHCcQgrOjNRLJ+zZbPG9P34N7WiO9vyRUyuj6vQuQDArKW9iQhKh5nuQevPcRxhMissYHpbZMKR6QyWTgyRs3MZ21G9XGRAR8hDGINW65/hs/CWYAn4p0V2i8n5EZlT+PQLj80VJW68gf33VJ5kGCkl2aKPSS/V22uFMcu64SbnF1n9bi0P3uS4zzJ7PCGa0M8pqzXpXMu8RZ7Y+8X66l1BhK9BeDb0UY9zbE3Eem9oshmgW1O+mrWQ9oe2hfl7EUKcZoq9+4/ojtW1VsuJ9V2dBD86Xj5tmrkDmScn7FEf8qBKa+qYRPnwhWf9Jw1KnYBdbMxQKg== 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=h9c1V23bWJTyTuJZVhIWQIcbksX0hPKqLTQpOJXmFuI=; b=YSGBmx7CEeJslVo02evsO3raheiPB1d5XcpEotG9B+n8BB4boQfQQmiTijrIU29l676zFfGe3YccdmX96Jj8M9BBJxp+erhlNoDzwqkDo5m0HzJCqW/A/UQk1X6GtOstIVuC10PqN0q7LaC6oovpG6HUXwcixfBF7550oyICYwiL/y77cyvrjwFI5n+GZkx4yg4+Hy1q7XC2D5AWM4SfdXfZFang0T6nadS4lM7/MLDvRRR3GeW4MqdI69PcUg841RXTVokIlNn2u075dSPtCnvl/xEohQUFe1sO4tRovRzX9Szn7uYSJ6q5J1s+eux/1kY+Ig6y7Nxi3lwECABjHw== 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=h9c1V23bWJTyTuJZVhIWQIcbksX0hPKqLTQpOJXmFuI=; b=Y8bE+0nLzbMB67Jep2o2nFTxii+5WFEcGW+q9fhpFq2DKp/NLzmOWv4OFRNVUNg7QNs9vfba3QUUoDXbQCxN4nUg4ztGY+ku6JFyux5Bh3kRckeZMyOSh8CHxtPKcgioN5Z7XPieOmV1dirATzxnVP2wgR/jvKGL1tSh4fxfOy0= Received: from CY5PR15CA0033.namprd15.prod.outlook.com (2603:10b6:930:1b::24) by BY5PR12MB4163.namprd12.prod.outlook.com (2603:10b6:a03:202::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.21; Wed, 21 Jun 2023 23:55:52 +0000 Received: from CY4PEPF0000E9D4.namprd03.prod.outlook.com (2603:10b6:930:1b:cafe::5f) by CY5PR15CA0033.outlook.office365.com (2603:10b6:930:1b::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.23 via Frontend Transport; Wed, 21 Jun 2023 23:55:52 +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 CY4PEPF0000E9D4.mail.protection.outlook.com (10.167.241.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6521.21 via Frontend Transport; Wed, 21 Jun 2023 23:55:52 +0000 Received: from ruby-95f9host.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.2507.23; Wed, 21 Jun 2023 18:55:50 -0500 From: Suravee Suthikulpanit To: , , CC: , , , , , , , , , , , , , , , "Suravee Suthikulpanit" Subject: [RFC PATCH 09/21] iommu/amd: Add support for hw_info for iommu capability query Date: Wed, 21 Jun 2023 18:54:56 -0500 Message-ID: <20230621235508.113949-10-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230621235508.113949-1-suravee.suthikulpanit@amd.com> References: <20230621235508.113949-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: CY4PEPF0000E9D4:EE_|BY5PR12MB4163:EE_ X-MS-Office365-Filtering-Correlation-Id: 9555c499-7111-4111-4358-08db72b30bd6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SXdP8JRmtUCCodN7DF4QalKVNOFfxQ+icg6IrcJPCynEHNz4BBYDrEkJGO5GQj/768kgIrb5pdbJt+olgH0SPhhdHv13+K0gKBM7r5p5PK31Uqyl1STutqV08QcLxGwZZGqIPOM4huBqLMMPQZHVglHQjNN6TEPxv/Z9pfZYrLbE8pbUKhtAwCqBoAC34Yroa/h0kO03SYzyxU8AGwqnO/H30w13wx2QOXQnzCxk3Qep5hFRULKWh8PSmBetZlTj6a8UPs+yOfI7JrxgbQEeFRwVBfnLGv0uNgY+hti5dfUhv0E0p1/ZKeD+1v7ar3LctHqMHFVy7XW3azNGd6uh4aHrHCtQAaVXAWoNxsqPYk7xxM8lUPNeMYS7EzXeH+EhMF8u0PwinThm2oUlrUtdCQcu8tIGOLMHeZNxmTf3nCJk06wQJYScZX5mmepXRepvkeP0pgqxTAkpDiv/A4OTZ9eNQXfYVcG/rlHHp7YmlBqMqMKnHmKK9z6/9aQq5iLVyGsnUcLYcrsdTOHHRQkHzfDn1LyRdkUmNjqyRfpfXYe1upa6lpGGYzLflLoyu+Lp1PN5iC+AUh6nsLmfoJwoKdYPAP4xkf9wplbFeOEHGb4PCasEbDv+DuK4VnRD788HJ49PB6P9sw85nFxZ2mUNOvobxq/vXKaFzWblfpeIrEF5s5nlb48TKsk0+m+xsz4z4qW4LqMYGuAFkcVpRphN5IR/M7OHOjwrnnpqezqE+4yBHoHj9OQ2MiQTRKR2DD6W7Y4F6pEaTRDuFA8ByKoulg== 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:(13230028)(4636009)(39860400002)(396003)(136003)(376002)(346002)(451199021)(40470700004)(46966006)(36840700001)(36860700001)(36756003)(82310400005)(40460700003)(81166007)(356005)(70206006)(5660300002)(44832011)(7416002)(41300700001)(8936002)(86362001)(4326008)(8676002)(316002)(40480700001)(82740400003)(70586007)(47076005)(426003)(26005)(1076003)(2616005)(16526019)(186003)(2906002)(7696005)(336012)(478600001)(110136005)(54906003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jun 2023 23:55:52.5267 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9555c499-7111-4111-4358-08db72b30bd6 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: CY4PEPF0000E9D4.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4163 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=no 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?1769359855557578004?= X-GMAIL-MSGID: =?utf-8?q?1769359855557578004?= AMD IOMMU Extended Feature(2) Register (EFR/EFR2) specifies features supported by each IOMMU hardware instance. The IOMMU driver checks each feature-specific bits before enabling each feature at run time. For hardware-assisted vIOMMU, the hypervisor determines which IOMMU features to supported in the guest, and communicates this information to user-space (e.g. QEMU) via iommufd IOMMU_DEVICE_GET_HW_INFO ioctl. Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/amd_iommu.h | 2 ++ drivers/iommu/amd/amd_iommu_types.h | 3 +++ drivers/iommu/amd/iommu.c | 37 +++++++++++++++++++++++++++++ include/uapi/linux/iommufd.h | 11 +++++++++ 4 files changed, 53 insertions(+) diff --git a/drivers/iommu/amd/amd_iommu.h b/drivers/iommu/amd/amd_iommu.h index d36a39796c2f..c9dfa4734801 100644 --- a/drivers/iommu/amd/amd_iommu.h +++ b/drivers/iommu/amd/amd_iommu.h @@ -84,6 +84,8 @@ extern int amd_iommu_domain_set_gcr3(struct iommu_domain *dom, u32 pasid, unsigned long cr3); extern int amd_iommu_domain_clear_gcr3(struct iommu_domain *dom, u32 pasid); +extern void amd_iommu_build_efr(u64 *efr, u64 *efr2); + #ifdef CONFIG_IRQ_REMAP extern int amd_iommu_create_irq_domain(struct amd_iommu *iommu); #else diff --git a/drivers/iommu/amd/amd_iommu_types.h b/drivers/iommu/amd/amd_iommu_types.h index 09df25779fe9..8830f511bee4 100644 --- a/drivers/iommu/amd/amd_iommu_types.h +++ b/drivers/iommu/amd/amd_iommu_types.h @@ -98,12 +98,15 @@ #define FEATURE_EPHSUP (1ULL<<50) #define FEATURE_SNP (1ULL<<63) +#define FEATURE_GATS_5LEVEL 1ULL #define FEATURE_GATS_SHIFT 12 #define FEATURE_GATS_MASK (0x03ULL << FEATURE_GATS_SHIFT) +#define FEATURE_GLX_3LEVEL 0ULL #define FEATURE_GLX_SHIFT 14 #define FEATURE_GLX_MASK (0x03ULL << FEATURE_GLX_SHIFT) +#define FEATURE_PASMAX_16 0xFULL #define FEATURE_PASMAX_SHIFT 32 #define FEATURE_PASMAX_MASK (0x1FULL << FEATURE_PASMAX_SHIFT) diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index c23f99ebdffc..4a42af85664e 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -2435,8 +2435,45 @@ static bool amd_iommu_enforce_cache_coherency(struct iommu_domain *domain) return true; } +void amd_iommu_build_efr(u64 *efr, u64 *efr2) +{ + if (efr) { + *efr = (FEATURE_GT | FEATURE_GIOSUP); + + /* 5-level v2 page table support */ + *efr |= ((FEATURE_GATS_5LEVEL << FEATURE_GATS_SHIFT) & + FEATURE_GATS_MASK); + + /* 3-level GCR3 table support */ + *efr |= ((FEATURE_GLX_3LEVEL << FEATURE_GLX_SHIFT) & + FEATURE_GLX_MASK); + + /* 16-bit PASMAX support */ + *efr |= ((FEATURE_PASMAX_16 << FEATURE_PASMAX_SHIFT) & + FEATURE_PASMAX_MASK); + } + + if (efr2) + *efr2 = 0; +} + +static void *amd_iommu_hw_info(struct device *dev, u32 *length) +{ + struct iommu_hw_info_amd *hwinfo; + + hwinfo = kzalloc(sizeof(*hwinfo), GFP_KERNEL); + if (!hwinfo) + return ERR_PTR(-ENOMEM); + + *length = sizeof(*hwinfo); + + amd_iommu_build_efr(&hwinfo->efr, &hwinfo->efr2); + return hwinfo; +} + const struct iommu_ops amd_iommu_ops = { .capable = amd_iommu_capable, + .hw_info = amd_iommu_hw_info, .domain_alloc = amd_iommu_domain_alloc, .probe_device = amd_iommu_probe_device, .release_device = amd_iommu_release_device, diff --git a/include/uapi/linux/iommufd.h b/include/uapi/linux/iommufd.h index ec870e2d32fd..f8ea9faf6770 100644 --- a/include/uapi/linux/iommufd.h +++ b/include/uapi/linux/iommufd.h @@ -508,6 +508,17 @@ struct iommu_hw_info_smmuv3 { __u32 idr[6]; }; +/** + * struct iommu_hw_info_amd - AMD IOMMU device info + * + * @efr : Value of AMD IOMMU Extended Feature Register (EFR) + * @efr2: Value of AMD IOMMU Extended Feature 2 Register (EFR2) + */ +struct iommu_hw_info_amd { + __u64 efr; + __u64 efr2; +}; + /** * enum iommu_hw_info_type - IOMMU Hardware Info Types * @IOMMU_HW_INFO_TYPE_INTEL_VTD: Intel VT-d iommu info type From patchwork Wed Jun 21 23:54:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suravee Suthikulpanit X-Patchwork-Id: 111350 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp4721787vqr; Wed, 21 Jun 2023 16:57:45 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7D6odxY7be7mG539IPAIyujVNE+Yz9QkAfDlp1mtkS8uWzFjWXSR2mU4xQDaHJ10FmgRhO X-Received: by 2002:a05:6214:262b:b0:626:2e07:c080 with SMTP id gv11-20020a056214262b00b006262e07c080mr24914035qvb.15.1687391865253; Wed, 21 Jun 2023 16:57:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1687391865; cv=pass; d=google.com; s=arc-20160816; b=AyzV+B3mMm7FYWNzTByzztb/esxRFQMgcbpMO+22M3GjuvlT/y5QXZLRW1S0byoLrg SFj+vWwKEVdI2dqJcqbaC+relTzrXsfrkgmaLz8M/Mqtk/fZCcMg2Xdz7rLI0BAOIqZq hpVItir8x/53I2O1cQil1NSrCN0T3ozj0Y896ls5o2JiNzEfF5jovRsgRijNnIg0vvoX eqlil15V7timC7nga7e//7brs8Wf/g6PI/qhpPQurqNF5D8Yd8XkUEch9v3IZyBclyUW V0v7l0wWEVaaiX24/qRBgcvdCKYegjHLlweyC3QcnsnhaKotlhmNqYXILRlFe7mLL8Jd jfLA== 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=iNi76l97aG+cBmxW0ckshX+65t8V4Tsn+yZofetA6J0=; b=fT37jYKLtzEggrj5KPdYqZMvIwoK9IIvA0MmUfkyggVRARtK5tQfKaWJU3cRyaMMCM xLImU6rP0+FMw1wqlw+sBQaJT2TbBwgaB20Hl14mLCWELko8Wm3CmQJBO+3DiXvREVe3 P/CijMPyaXT4F/SpNaPXV84N8g1v/CfzKWtQ/lGcZCbryPySp0u+qFz8uz0etMLIPcp9 6mUgQ5PT2boDlvpeF3t1DKDOcjh1OBIHQ9n1H0mkvpLVaqA+qqOL33KeVl/IC/SfPcJ6 rAlAyoSoTdctQNHj7Z0fBznLdcuHE615gHtVYYZyLsCO1ne59x/HZMyMxAgOgXDVx0Xr mTuQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=VvH7gKy7; 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 17-20020a630011000000b0053eef60f940si5023318pga.765.2023.06.21.16.57.32; Wed, 21 Jun 2023 16:57:45 -0700 (PDT) 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=VvH7gKy7; 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 S230089AbjFUX4e (ORCPT + 99 others); Wed, 21 Jun 2023 19:56:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230107AbjFUXz7 (ORCPT ); Wed, 21 Jun 2023 19:55:59 -0400 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2084.outbound.protection.outlook.com [40.107.237.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 545B11BD1; Wed, 21 Jun 2023 16:55:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=e0O2U0605ZDGGWcIgrfzdEl94LGHf/CmOtu3b9MOLDEtAT/CbyLXXyGClB6ZWAWL6eS3HrYQybSMYRcMMWUXMgD+w2Qe7joFT1SSQiqsY25vSV5zrVzH53O+PcyFfADgCrm3t01FoOJOjpVcxI6OifN7s6PVeMh6ni+dNHpFFBsv1T3D5u2y1LVwK38u2Mr/LiWk16vw8UtbPe6lHpziNsthENRlo//dWeVLN9VEU+aEMROAdX3v4jEJ7d33iNTCvuTHqg1QYCZj6t3ARSUwY+wWEglUkGYuqi/EB/DydEUc27X8AICoUdlvfrj4OZ49fyTOmb3DLYZscKyq2eg16w== 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=iNi76l97aG+cBmxW0ckshX+65t8V4Tsn+yZofetA6J0=; b=IpgEgjvfBPoP2hisnZS2QG/8pAmcoLS3g1ZlIp0Ky0W6OpRFtP3LpuZ9AiKV/rftoxqng2zFE3jlNO9YV1rh0N1M4OGGDC7tRyxOwmYYisD3GsdJzm2IJ2vn96gLWU+7SO2X6OE2DBfMHZEoQuWjx8fwVaxJUd9lsEDW3FFKLevFwkZ8EvMATpcRCtFpWiewJNcUx0fMZvKSt1+uMVvJN1LVsmHUKGcQ1RK6imxiaCJGGWYiSPhv64nk6aCD2bsUc7snBqFfgpA4DDG1ZwD4bpiMZdJsAE5cP8ZnaKWcTpvrHoPjqIrmE7C35o6jP60w5CGVzizKAN2ltJRIFlmE8Q== 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=iNi76l97aG+cBmxW0ckshX+65t8V4Tsn+yZofetA6J0=; b=VvH7gKy7SpWAkHREpxkmwjrX2h3XRTvMSQWWcw+qXy4Oadn9SnAt3M6G1h7jPJ7OvPG1DwgUh9vmM0Xkiz3O34wAwRdKk4e58sxnS44X4XORGsI0RbhBUT8KmD+8eDQ8VVqb21KJR4GytiwT7ZFSvkHEorenqJQ59OZG1wZQQEs= Received: from CY5PR15CA0050.namprd15.prod.outlook.com (2603:10b6:930:1b::16) by CY8PR12MB7337.namprd12.prod.outlook.com (2603:10b6:930:53::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.23; Wed, 21 Jun 2023 23:55:54 +0000 Received: from CY4PEPF0000E9D4.namprd03.prod.outlook.com (2603:10b6:930:1b:cafe::68) by CY5PR15CA0050.outlook.office365.com (2603:10b6:930:1b::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.23 via Frontend Transport; Wed, 21 Jun 2023 23:55:54 +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 CY4PEPF0000E9D4.mail.protection.outlook.com (10.167.241.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6521.21 via Frontend Transport; Wed, 21 Jun 2023 23:55:54 +0000 Received: from ruby-95f9host.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.2507.23; Wed, 21 Jun 2023 18:55:51 -0500 From: Suravee Suthikulpanit To: , , CC: , , , , , , , , , , , , , , , "Suravee Suthikulpanit" Subject: [RFC PATCH 10/21] iommu/amd: Introduce vIOMMU-specific events and event info Date: Wed, 21 Jun 2023 18:54:57 -0500 Message-ID: <20230621235508.113949-11-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230621235508.113949-1-suravee.suthikulpanit@amd.com> References: <20230621235508.113949-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: CY4PEPF0000E9D4:EE_|CY8PR12MB7337:EE_ X-MS-Office365-Filtering-Correlation-Id: 1a412335-fbd6-45bd-5fd5-08db72b30cd5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Xa18HEMfdNdkm+uq4BS9+eAkt9R6wUNH//HHw4LsXJYrwRnMfP0nABxVHjdDhazqu8Hth09N95IS1pQIH9z2aigxeLFa+F9/yBokBYN5PfgJWUJzCLY8tHuyntZCIR3vUkl5O4UX6y0KqK1dYYIeozoVkWpd3Y5wUNi2mBVYB8DZuh9i6K1Or3CwdC+6ZQogOdZLi7frjpU7vuRV9fByrYo4f1OCExSkKrffdrZNlCSI87s74TwatCPiakzKLdWhy2x8w/+y1qYeH3Jp4YuM3xfY8Z9z0+2lniV/pP5O3RuTo9C5/q9VcG+msLgjmSh7GDSU6w7DHvDZ4BS+7SlMv9wnkMuUhd+4OizGUMmIdDaXw0qtdWwwKhNkV1UwF/UW4E/IbBpSvAbbPyW412aM8aO5DcZTCJQgj/aFh9AL4AxIvnpl3V/jAckLrN84N45gQHkWvPMgkuvcv25Ck8/CiU7nRhIg8uOr8WkkpxCKUeCFlZNMMMZHJjJN+B7VNLIRJHZ/odhVjyuejCPIlXzj8gMc2ad3pJL3mCtqBeMgjnoSDLsM1ZTNuiyjfLdcBYQBWetYBB2jZ/7VinkY8pwGPg1zKnA1OyOEbuLkQe2we9GXJ66m1O+3K0fzQpoTEJdNXYP/OsDCv5IyajFp84Hjana2lJ5VHsvmefPGc/beZwb/eDmyxiSZyh6L4UsWZmd3mM8PUxodsj+zja1GXtWnQYtydbInD5ncVoTKNkZ6FwSR0PsrpcwYt8YFlRmHP0/eduKAFwTuaqHTzSGFrLZQrA== 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:(13230028)(4636009)(39860400002)(396003)(136003)(376002)(346002)(451199021)(40470700004)(36840700001)(46966006)(54906003)(7696005)(478600001)(110136005)(70206006)(70586007)(16526019)(26005)(186003)(1076003)(2906002)(82310400005)(8676002)(4326008)(41300700001)(5660300002)(44832011)(8936002)(7416002)(316002)(356005)(81166007)(82740400003)(86362001)(36756003)(40460700003)(47076005)(336012)(83380400001)(2616005)(36860700001)(40480700001)(426003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jun 2023 23:55:54.1986 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1a412335-fbd6-45bd-5fd5-08db72b30cd5 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: CY4PEPF0000E9D4.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7337 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=no 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?1769358612122209495?= X-GMAIL-MSGID: =?utf-8?q?1769358612122209495?= Adding support for new vIOMMU events: * Guest Event Fault event * vIOMMU Hardware Error event Also, adding support for the additional vIOMMU related flags in existing events. Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/amd_iommu_types.h | 3 ++ drivers/iommu/amd/iommu.c | 58 ++++++++++++++++++++++------- 2 files changed, 48 insertions(+), 13 deletions(-) diff --git a/drivers/iommu/amd/amd_iommu_types.h b/drivers/iommu/amd/amd_iommu_types.h index 8830f511bee4..d832e0c36a21 100644 --- a/drivers/iommu/amd/amd_iommu_types.h +++ b/drivers/iommu/amd/amd_iommu_types.h @@ -145,6 +145,9 @@ #define EVENT_TYPE_IOTLB_INV_TO 0x7 #define EVENT_TYPE_INV_DEV_REQ 0x8 #define EVENT_TYPE_INV_PPR_REQ 0x9 +#define EVENT_TYPE_GUEST_EVENT_FAULT 0xb +#define EVENT_TYPE_VIOMMU_HW_ERR 0xc + #define EVENT_TYPE_RMP_FAULT 0xd #define EVENT_TYPE_RMP_HW_ERR 0xe #define EVENT_DEVID_MASK 0xffff diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index 4a42af85664e..efced59ba8a5 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -541,7 +541,7 @@ static void amd_iommu_report_rmp_fault(struct amd_iommu *iommu, volatile u32 *ev static void amd_iommu_report_page_fault(struct amd_iommu *iommu, u16 devid, u16 domain_id, - u64 address, int flags) + u64 address, int flags, u8 vflags) { struct iommu_dev_data *dev_data = NULL; struct pci_dev *pdev; @@ -576,13 +576,13 @@ static void amd_iommu_report_page_fault(struct amd_iommu *iommu, } if (__ratelimit(&dev_data->rs)) { - pci_err(pdev, "Event logged [IO_PAGE_FAULT domain=0x%04x address=0x%llx flags=0x%04x]\n", - domain_id, address, flags); + pci_err(pdev, "Event logged [IO_PAGE_FAULT domain=0x%04x address=0x%llx flags=0x%04x vflags=%#x]\n", + domain_id, address, flags, vflags); } } else { - pr_err_ratelimited("Event logged [IO_PAGE_FAULT device=%04x:%02x:%02x.%x domain=0x%04x address=0x%llx flags=0x%04x]\n", + pr_err_ratelimited("Event logged [IO_PAGE_FAULT device=%04x:%02x:%02x.%x domain=0x%04x address=0x%llx flags=0x%04x vflags=%#x]\n", iommu->pci_seg->id, PCI_BUS_NUM(devid), PCI_SLOT(devid), PCI_FUNC(devid), - domain_id, address, flags); + domain_id, address, flags, vflags); } out: @@ -618,28 +618,41 @@ static void iommu_print_event(struct amd_iommu *iommu, void *__evt) } if (type == EVENT_TYPE_IO_FAULT) { - amd_iommu_report_page_fault(iommu, devid, pasid, address, flags); + u8 vflags = (event[0] >> 27) & 0x1F; + + amd_iommu_report_page_fault(iommu, devid, pasid, address, flags, vflags); return; } switch (type) { case EVENT_TYPE_ILL_DEV: - dev_err(dev, "Event logged [ILLEGAL_DEV_TABLE_ENTRY device=%04x:%02x:%02x.%x pasid=0x%05x address=0x%llx flags=0x%04x]\n", + { + u8 vflags = (event[0] >> 27) & 0x1F; + + dev_err(dev, "Event logged [ILLEGAL_DEV_TABLE_ENTRY deice=%04x:%02x:%02x.%x pasid=0x%05x address=0x%llx flags=0x%04x vflags=%#x]\n", iommu->pci_seg->id, PCI_BUS_NUM(devid), PCI_SLOT(devid), PCI_FUNC(devid), - pasid, address, flags); + pasid, address, flags, vflags); dump_dte_entry(iommu, devid); break; + } case EVENT_TYPE_DEV_TAB_ERR: - dev_err(dev, "Event logged [DEV_TAB_HARDWARE_ERROR device=%04x:%02x:%02x.%x " - "address=0x%llx flags=0x%04x]\n", + { + u8 vflags = (event[0] >> 27) & 0x1F; + + dev_err(dev, "Event logged [DEV_TAB_HARDWARE_ERROR device=%04x:%02x:%02x.%x address=%#llx flags=%#04x vlfags=%#x]\n", iommu->pci_seg->id, PCI_BUS_NUM(devid), PCI_SLOT(devid), PCI_FUNC(devid), - address, flags); + address, flags, vflags); break; + } case EVENT_TYPE_PAGE_TAB_ERR: - dev_err(dev, "Event logged [PAGE_TAB_HARDWARE_ERROR device=%04x:%02x:%02x.%x pasid=0x%04x address=0x%llx flags=0x%04x]\n", + { + u8 vflags = (event[0] >> 27) & 0x1F; + + dev_err(dev, "Event logged [PAGE_TAB_HARDWARE_ERROR device=%04x:%02x:%02x.%x pasid=0x%04x address=0x%llx flags=0x%04x vflags=%#x]\n", iommu->pci_seg->id, PCI_BUS_NUM(devid), PCI_SLOT(devid), PCI_FUNC(devid), - pasid, address, flags); + pasid, address, flags, vflags); break; + } case EVENT_TYPE_ILL_CMD: dev_err(dev, "Event logged [ILLEGAL_COMMAND_ERROR address=0x%llx]\n", address); dump_command(address); @@ -671,6 +684,25 @@ static void iommu_print_event(struct amd_iommu *iommu, void *__evt) iommu->pci_seg->id, PCI_BUS_NUM(devid), PCI_SLOT(devid), PCI_FUNC(devid), pasid, address, flags, tag); break; + case EVENT_TYPE_GUEST_EVENT_FAULT: + { + u8 gid = event[1] & 0xFFFF; + u8 vflags = (event[0] >> 27) & 0x1F; + + dev_err(dev, "Event logged [GUEST_EVENT_FAULT gid=#%x flags=0x%04x vflags=%#x]\n", + gid, flags, vflags); + break; + } + case EVENT_TYPE_VIOMMU_HW_ERR: + { + u16 gid = event[0] & 0xFFFF; + u8 src = (event[0] >> 16) & 0x3; + u8 vflags = (event[0] >> 27) & 0x1F; + + dev_err(dev, "Event logged [VIOMMU_HW_ERR gid=%#x address=%#llx src=%#x flags=%#x vflags=%#x]\n", + gid, address, src, flags, vflags); + break; + } default: dev_err(dev, "Event logged [UNKNOWN event[0]=0x%08x event[1]=0x%08x event[2]=0x%08x event[3]=0x%08x\n", event[0], event[1], event[2], event[3]); From patchwork Wed Jun 21 23:54:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suravee Suthikulpanit X-Patchwork-Id: 111368 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp4734790vqr; Wed, 21 Jun 2023 17:26:59 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6D+TgZ2oQkX2NZTNpKoTi/fADmjERco+kN40uDWS+M9fWlwMEgvxekmhgFFqfEh8OJlGfd X-Received: by 2002:a17:902:c24c:b0:1b0:e0a:b7ab with SMTP id 12-20020a170902c24c00b001b00e0ab7abmr11995625plg.31.1687393619198; Wed, 21 Jun 2023 17:26:59 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1687393619; cv=pass; d=google.com; s=arc-20160816; b=zdEYNVHRi6M1o/Q916Nz7bq5R36iwS4hCMgJgHlapFUzHMPdLGayyGCs0yPUhfde36 bA+rDfdnpfIPrBb2KsC6WcuB58ipxn+l8m+wTLX+bbJZUubVCdiszkEYD1sDbWpDdW81 ixDCJKppK3NcxBvy+3OcmsmVPQodwMwRNFJ+pH6GvhJg2tUn7Gc4SjOpQQ0Fgo/zuxG4 9QibV02aB/pZF3Z1zDVXKuCoaerl0KpsN9zxcWuSPFf/hXNNXjcPoWjUVGRgflEeUOda b9s/qWgc4CEpDZ6a6UewMO6e+R+r6nCxsI/+kfeiuhzi9gYMEBFG3bjdCWPpnkgiFgv2 eVyA== 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=0uTs75xJ8qf6SN4WoGmm5L5a0Tzd0cCIt37Rg7Rj3zs=; b=08wBQ8D+Wnl0OxwoLrJkg8J8uu9e9HdlA1073RZbOybWuwAn3r/EJrkWJOnwaghb6V kRK8HAHWLAZOagFmngc1KbBoJcXuqUCruJQpYO13ROS8papIONakPhcdLXkUz7dquKgA HFoA25gfRuMK7otcRNCdgnkRpAorAxIG8VqU2Rph46Q/8g3r3gXHkz5bxkOurRaCSkZW mZ9/OAI1wOAFtone1NcyKjPVEJY6e3YTsn3lOUKQ1Whs8e+mjgXvKSXeYBQGZphdna5p RKUBMgpffvvRJrYVhABDXMqiTN7tTfyN+xAjcQ2ks3RnVMENyTQl3X2xKUGrtRsG70+O BBmw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=UTdeTcZv; 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 c2-20020a170902d90200b001aafb271d13si5031227plz.235.2023.06.21.17.26.46; Wed, 21 Jun 2023 17:26:59 -0700 (PDT) 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=UTdeTcZv; 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 S229966AbjFUX4b (ORCPT + 99 others); Wed, 21 Jun 2023 19:56:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230106AbjFUXz7 (ORCPT ); Wed, 21 Jun 2023 19:55:59 -0400 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2073.outbound.protection.outlook.com [40.107.220.73]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C89A11BD3; Wed, 21 Jun 2023 16:55:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=drvnfwpajwecAS44VNcbAkz6rFdmEShbMbEU0Xb85mO3+fhvfQY1YhUchGDOfjNdLcoUD7nyn6A9//tcC0xpKMnO+PS9JR5iD3QouahqS/pGfhkYEvp/AGGAtXfB94gnSoK+sonywnVBVe/fHeYKntQTHSd2P4g20po5FemIJoyW7B6BPC9QiEemkz4XIiNNbq8ULO4vXCoJSHYiW4LT77ziU8Z4E7xGCNK/fxlXKCP5pCpFP6+bmY/RDwT5JOI+G3fl6WXv6DQqDTEViy/f5oHs6vla1P6f/ZzgHeTmrw0MGw6LfBVyKrlmE65JqXl/fngaJjVm6hX+TBTFmOKbYg== 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=0uTs75xJ8qf6SN4WoGmm5L5a0Tzd0cCIt37Rg7Rj3zs=; b=UTNDYyrC4tfGqa9ScIqcmneJGdd2I9lXjBZY382/zPYEEjiXfhpnD+Bpbr4gZQkLz0DHWLFe4znC8WYoigQ2x+d6gJNuj8erQbSorVZ01AW5PAkIF0Rm2d/Kj6jBMUxxS8peEYpFj325DeUAUA2NYXo0bn8ixed5xeNTeb3KglPKw1puFzpGkGssr6bHBGHLuIeWWxUxTPV9cks2TRkrlmMJt9UcgiW37rPF0pkSa+71PFACcrV24dtblHFtUSwT/6ojLOxVnkM5YiFGfRsjtpX4jsnsh7NCYR24rJ8hO9OIKinO/80xxukkQ9RvaLBBvyDxQIIr3PsGCiu0PyIQCw== 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=0uTs75xJ8qf6SN4WoGmm5L5a0Tzd0cCIt37Rg7Rj3zs=; b=UTdeTcZvGQHwibhr9GHsfXsXa0Kp/n4WLKZSLNk+jou/yFmtVlkgtjmFHvShR9BBm8XjNqNEE6X1ckIe6mImBaIPmdS4BKFevBS8Bxse+uXMIKBywoIaavHeHwEGo3fKDX3npRO2kNR2RZvLxH+JGrynGzH6k9GStT4xhXDNkzY= Received: from CY5PR15CA0042.namprd15.prod.outlook.com (2603:10b6:930:1b::26) by SJ0PR12MB5485.namprd12.prod.outlook.com (2603:10b6:a03:305::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.23; Wed, 21 Jun 2023 23:55:55 +0000 Received: from CY4PEPF0000E9D4.namprd03.prod.outlook.com (2603:10b6:930:1b:cafe::c8) by CY5PR15CA0042.outlook.office365.com (2603:10b6:930:1b::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.21 via Frontend Transport; Wed, 21 Jun 2023 23:55:55 +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 CY4PEPF0000E9D4.mail.protection.outlook.com (10.167.241.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6521.21 via Frontend Transport; Wed, 21 Jun 2023 23:55:55 +0000 Received: from ruby-95f9host.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.2507.23; Wed, 21 Jun 2023 18:55:52 -0500 From: Suravee Suthikulpanit To: , , CC: , , , , , , , , , , , , , , , "Suravee Suthikulpanit" Subject: [RFC PATCH 11/21] iommu/amd: Introduce Reset vMMIO Command Date: Wed, 21 Jun 2023 18:54:58 -0500 Message-ID: <20230621235508.113949-12-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230621235508.113949-1-suravee.suthikulpanit@amd.com> References: <20230621235508.113949-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: CY4PEPF0000E9D4:EE_|SJ0PR12MB5485:EE_ X-MS-Office365-Filtering-Correlation-Id: 9087e2a9-a382-4fbe-7ff5-08db72b30d77 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: YQtQyBvuxD49C4F+5hqCn4CWDuqFS6AnbNSPrSiqboIWpw8tjxTqpoOO1Vy8Rot+p6blqnaUQrTYMobO6Z0DR7UeQPCAdCNP9jmhoSxBWZ9ElSqamYGTym/6Xrw8coeULIqTyNMYzlxelxcWfwaejiHn1bbwNWVgBhn3qVRIW1Jgl0HInzDADGs3jPdSvb9FhF5nUb85GdbWF8WM27StfgjbCloe3drgpk9CyZYypE4B1D+/yP4xHnE49ONDqwH5P+SKZQUyaIauS7WDY2OAn7cEapfqJ8tpBmBYfGE6xbmEO2ZptQdGiX3Mo4ydjxpcr3pDkrii8U9gmsTtAbrM0QesWY33Zl3E+gKGe6ibc+PVJbYY3sieViVkpSyg+jvJc2T/YgIxB9y31TxATq3udvjhysCN+5KUFFVF4o2x3yDlRmeyTzgum3eFrW9q/Ymvn5Fjr09g26xDtU9vWf3GH4bvtH3VPs7UxoqYKaCfn+N3xgOHeZLEGrxxW7hlk/EheGJf2y5wCjjfye22dLMVkfbk2qZodQ6HurXNoQbOgFWyTYkt7BK8zD8tNjPvPoyzN3zxSIhWzqKa0C2tbQzazJK7JQs4/QhmwlmvuAuv0wqvP1EKZcLA+D9OuEHmhPOq4rY3tUA4V6Gy7FGXVxX3YccLgU7U35IfEGLoibYbsopCEZPEVjvjb5jGq+h4W0I8sbxxRCSOqPKejcFZxQvtw6z9ScoQzy6z+v5SeBTGbI0fkZFxzGl72Xa2c0yBHHYk7KRTVM4sLoDRXVAykojTJg== 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:(13230028)(4636009)(376002)(396003)(39860400002)(346002)(136003)(451199021)(46966006)(36840700001)(40470700004)(40480700001)(7696005)(110136005)(478600001)(26005)(54906003)(4326008)(36860700001)(186003)(1076003)(16526019)(82310400005)(70586007)(70206006)(41300700001)(356005)(5660300002)(7416002)(8936002)(8676002)(44832011)(82740400003)(81166007)(316002)(40460700003)(86362001)(47076005)(426003)(336012)(2616005)(36756003)(2906002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jun 2023 23:55:55.2611 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9087e2a9-a382-4fbe-7ff5-08db72b30d77 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: CY4PEPF0000E9D4.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB5485 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=no 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?1769360451671837401?= X-GMAIL-MSGID: =?utf-8?q?1769360451671837401?= Introduce new IOMMU commands for vIOMMU for resetting virtualized MMIO registers of a particular guest. Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/amd_iommu_types.h | 1 + drivers/iommu/amd/iommu.c | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/drivers/iommu/amd/amd_iommu_types.h b/drivers/iommu/amd/amd_iommu_types.h index d832e0c36a21..aa16a7079b5c 100644 --- a/drivers/iommu/amd/amd_iommu_types.h +++ b/drivers/iommu/amd/amd_iommu_types.h @@ -200,6 +200,7 @@ #define CMD_INV_IRT 0x05 #define CMD_COMPLETE_PPR 0x07 #define CMD_INV_ALL 0x08 +#define CMD_RESET_VMMIO 0x0A #define CMD_COMPL_WAIT_STORE_MASK 0x01 #define CMD_COMPL_WAIT_INT_MASK 0x02 diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index efced59ba8a5..b5c62bc8249c 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -1133,6 +1133,18 @@ static void build_inv_irt(struct iommu_cmd *cmd, u16 devid) CMD_SET_TYPE(cmd, CMD_INV_IRT); } +static void build_reset_vmmio(struct iommu_cmd *cmd, u16 guestId, + bool vcmd, bool all) +{ + memset(cmd, 0, sizeof(*cmd)); + cmd->data[0] = guestId; + if (all) + cmd->data[0] |= (1 << 28); + if (vcmd) + cmd->data[0] |= (1 << 31); + CMD_SET_TYPE(cmd, CMD_RESET_VMMIO); +} + /* * Writes the command to the IOMMUs command buffer and informs the * hardware about the new command. @@ -1315,6 +1327,16 @@ void iommu_flush_all_caches(struct amd_iommu *iommu) } } +void iommu_reset_vmmio(struct amd_iommu *iommu, u16 guestId) +{ + struct iommu_cmd cmd; + + build_reset_vmmio(&cmd, guestId, 1, 1); + + iommu_queue_command(iommu, &cmd); + iommu_completion_wait(iommu); +} + /* * Command send function for flushing on-device TLB */ From patchwork Wed Jun 21 23:54:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suravee Suthikulpanit X-Patchwork-Id: 111351 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp4721806vqr; Wed, 21 Jun 2023 16:57:50 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ61j1xHYf8aRuqDlZwExl0wAdhxeOxxA/kkIOJojgDVNJzwyCa8MLeSDcTUgBmVd++yPuZ/ X-Received: by 2002:a92:d090:0:b0:338:d170:6e32 with SMTP id h16-20020a92d090000000b00338d1706e32mr17436614ilh.7.1687391870512; Wed, 21 Jun 2023 16:57:50 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1687391870; cv=pass; d=google.com; s=arc-20160816; b=xhxnR3/Vhp9bKxaKiKc1r8dDj4Zf2KoBM3XTIN430nx6zrEk7EMxXKJIXvVMI9SXKG XDhU6sNyzmdsoFJfvShEk2ID8AWIdKtEyWixLq5VUDUqDj1CGMXfMaH/iXLXR/9wVX6y ogk/o9KpOWScLmp4Wxg1HNtwRIauE7b9F31AXnY3TGdHX2SbOZLEJMqEOs2A9L8RWdRn zpu27QE5wGNBy6Yh65Rk796rE/t0T76b3uma2kzz9Kv8d4qJ8UAdCjjNiiC7KTlcgO3P slG8ngSI5P8PwjFryB9UjXqEx+mUsgI6c/IXPhuSl3TaPd+8glt/pAFGqF8Kuu0G7p8e Q87g== 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=Es4QkeoqKK9Q+iYRHWZ9ALKb26xop5VvYjHJNvJR12M=; b=JKhx4xO2picu82F73EG29mijD69qoftwlpEIE+/60tn1lkL7tkh0aRKlHTh5Clu33z ibPeWhMV/C9koAROGt/xcsxTU/pvqznAM6wakb95w7a4BNP7kj3vozDc9RJuMdiqULWG Hea32fpiaEfp9Alqx7WAJZL8TXmiQXAX+pzU4HC7dBs07xR4a6Pi0fRe2wMCruEOZ2he DnGxbrezf1IhN3MrfObKO3WkzVsDPBfv/Hs7npDbKJ2WrGrS1cM73t9BPqH/IsJ+0OJv 879BIiL+jiztl2cIAtiVwHL53GNzQ9MK4RU+TyJ1S23SqMXbzIH7Ps4jzrlOTnjCLx4a N+sA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=w30vbHQd; 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 l16-20020a17090aaa9000b0025c1af5672fsi1426061pjq.112.2023.06.21.16.57.38; Wed, 21 Jun 2023 16:57:50 -0700 (PDT) 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=w30vbHQd; 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 S229472AbjFUX4h (ORCPT + 99 others); Wed, 21 Jun 2023 19:56:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230121AbjFUXz7 (ORCPT ); Wed, 21 Jun 2023 19:55:59 -0400 Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam04on2073.outbound.protection.outlook.com [40.107.102.73]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C7981BDC; Wed, 21 Jun 2023 16:55:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=M5ZkctAjQUQLBUoEH7S3yVVXJD5+hLN1K29MpLbMvAUXJXWidtNtuZhKVTywk84aySrGou0B6OiAvv3MFdbZMPKnsxEDSa8iQQcCWf90+hy+jZCbRxr1HZZ/Eml4DvKxzHqD8deq+IwWJht9/BFbgiWja/0L9GUH5fiUCVJiPigguNQ/pUwulVKkC1sL/wwwP3tO9qL9dUnQSC3aVdXj+VU5/wGXnV9MCDvMXL39U4VHunMBquq9mh8U1bI7CmnFLtj2KyXsIcXc+m9WUlrDRfaefOAW5eVf2sTeXZvMPfR4c8wwWQ6dJa9k+cx8LgsJMIfE28RaxID9SRjC8oaKUw== 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=Es4QkeoqKK9Q+iYRHWZ9ALKb26xop5VvYjHJNvJR12M=; b=Oxei3InNcG/JkngoYzBQFiXBmpAJ/1IXcZGVq1CMdwRTewNLV1D5zTxM757Uu/8kvNSxzMVH1ndO1qFi1jMXZ0R4PCeeWksu551HcWbCLEhMaqjNkbWEBq0uE53/yd7XNlNnCVS+P6k+C/+8im5w8EfS/K9+vmirHfINzQc+EDgq8/SnKyMq9UR1lSW4UfHSHqHDe0hGZUNd11td/sSUhwSV4SfkWYC92pvdXygWgaBo6N4LFxiYfEAjVW0jYGP99bE62IEF8Ovo4f659xFlGDLbGW78tJMllXLzeZs5YwfXeOGezGg6vrN2PqgHo+GM2XqcNxDMorBaWRmVd1DxGQ== 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=Es4QkeoqKK9Q+iYRHWZ9ALKb26xop5VvYjHJNvJR12M=; b=w30vbHQd0V9vKom3mVkyoegeKyyxSWoJc7JpQKHdthOC2BRKVJ7r/DgGClQNQAVjCUkTGf8LhDHdfg8v9SdGaCSN4h2CgW7V05C0WhKchQGfLeFi+XAP/R197e6pXGsMx6ncghmiCbunrEoOm4/O8DpMc8xutvfuMdn2D5hBZdA= Received: from CY5PR15CA0045.namprd15.prod.outlook.com (2603:10b6:930:1b::23) by SA0PR12MB4560.namprd12.prod.outlook.com (2603:10b6:806:97::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.23; Wed, 21 Jun 2023 23:55:56 +0000 Received: from CY4PEPF0000E9D4.namprd03.prod.outlook.com (2603:10b6:930:1b:cafe::5e) by CY5PR15CA0045.outlook.office365.com (2603:10b6:930:1b::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.23 via Frontend Transport; Wed, 21 Jun 2023 23:55:55 +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 CY4PEPF0000E9D4.mail.protection.outlook.com (10.167.241.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6521.21 via Frontend Transport; Wed, 21 Jun 2023 23:55:55 +0000 Received: from ruby-95f9host.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.2507.23; Wed, 21 Jun 2023 18:55:53 -0500 From: Suravee Suthikulpanit To: , , CC: , , , , , , , , , , , , , , , "Suravee Suthikulpanit" Subject: [RFC PATCH 12/21] iommu/amd: Introduce AMD vIOMMU-specific UAPI Date: Wed, 21 Jun 2023 18:54:59 -0500 Message-ID: <20230621235508.113949-13-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230621235508.113949-1-suravee.suthikulpanit@amd.com> References: <20230621235508.113949-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: CY4PEPF0000E9D4:EE_|SA0PR12MB4560:EE_ X-MS-Office365-Filtering-Correlation-Id: 65208709-462b-44ff-9034-08db72b30dc8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ky6UDFtn0ptih9xO7AaC5pH083ReWvflDIojiTAbYoWtzrFM5V45f/DwauxL2imB+Loy5Qdf3JWo3MqWgajdX65kSLpeP7k20cWfTZXxxQsjcproKInUTerGNZl/UQemiuPP0qI3t21AkV8ZP5JRqjeCnaOEi2HWV2Qq+2guaqYsGyYajTWXCI8eZd/yHIUtZeQ8cv35b6j8d3qtKP29/PD3KWWIZPRmKv6bJDKwpjxPKvRR1FXwAGPxlDam+E4cnOs35fcYoDQVyWSLA6/rAfbcZk9eZsMfMH9MYyWeEatiy5t/6i3rZu6o5GVP0NmqXOtqmOgCzP6Ij5CzkxQmKBouOuq2ekwyP2WQeNbUDzqflds3vFexyn95B1bBdXnWPmJ2/Gj5VQqnB6c8YazsFwJa5l2CnPiRl7g+LQ/SGfer73ZGBtaAvU/YosWUpPtUjhkm9qRMnOojVbGJ/cTe+pT3OlpGc+koN1pRIysH0d74xuxfBbftU8Z6THGn378TefzIiaOHxNQ0pZeINkhk35rh76NUOy/Ye5gBxZQzwkDlzic2WyJF7vZPbJpwRLgq6ohKadoJe3kJ+Zkws/KyXRdQAwdy/Cwm+yn5LtbKq/7TG0J8nsprwykyU0AgMwrnJrku3ELtHPvsp2Jg64yLLmfvdg/ryorQM8WWYmHPrQIE+6quats8juhJ9khk/3eoU7aBER9ERDK5MrZm9XiRl60hfGps9Rtn+dpnGPLMRDzqooCd6s2hpeC5jSwz7H3HdFNvQ0Y9kGPV6nhpcxA7MtZ8kSd41R6pnWlunYz90E+ivpi9Fc/WJbVOMixIr5Bu 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:(13230028)(4636009)(376002)(39860400002)(396003)(346002)(136003)(451199021)(36840700001)(40470700004)(46966006)(54906003)(110136005)(478600001)(4326008)(26005)(16526019)(186003)(1076003)(70586007)(2906002)(82310400005)(7696005)(41300700001)(7416002)(8936002)(70206006)(8676002)(44832011)(5660300002)(316002)(82740400003)(356005)(81166007)(2616005)(86362001)(36756003)(40480700001)(47076005)(426003)(336012)(83380400001)(36860700001)(40460700003)(71600200004)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jun 2023 23:55:55.7923 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 65208709-462b-44ff-9034-08db72b30dc8 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: CY4PEPF0000E9D4.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4560 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=no 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?1769358618173290168?= X-GMAIL-MSGID: =?utf-8?q?1769358618173290168?= To handle various operations necessary for setting up the vIOMMU hardware. These operations are specific to AMD hardware. Signed-off-by: Suravee Suthikulpanit --- include/uapi/linux/amd_viommu.h | 145 ++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 include/uapi/linux/amd_viommu.h diff --git a/include/uapi/linux/amd_viommu.h b/include/uapi/linux/amd_viommu.h new file mode 100644 index 000000000000..f4a91ecd5dc2 --- /dev/null +++ b/include/uapi/linux/amd_viommu.h @@ -0,0 +1,145 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* + * AMD Hardwaer Accelerated Virtualized IOMMU (HW-vIOMMU) + * + * Copyright (c) 2023, Advanced Micro Devices, Inc. + * + */ +#ifndef _UAPI_AMD_VIOMMU_H_ +#define _UAPI_AMD_VIOMMU_H_ + +#include +#include + +/** + * The ioctl interfaces in this file are specific for AMD HW-vIOMMU. + * They are an extension of extend the IOMMUFD ioctl interfaces. + * Please see include/uapi/linux/iommufd.h for more detail. + */ +#include + +enum iommufd_viommu_cmd { + IOMMUFD_VIOMMU_CMD_BASE = 0x60, + IOMMUFD_CMD_IOMMU_INIT = IOMMUFD_VIOMMU_CMD_BASE, + IOMMUFD_CMD_IOMMU_DESTROY, + IOMMUFD_CMD_DEVICE_ATTACH, + IOMMUFD_CMD_DEVICE_DETACH, + IOMMUFD_CMD_DOMAIN_ATTACH, + IOMMUFD_CMD_DOMAIN_DETACH, + IOMMUFD_CMD_MMIO_ACCESS, + IOMMUFD_CMD_CMDBUF_UPDATE, +}; + +/** + * struct amd_viommu_iommu_info - ioctl(VIOMMU_IOMMU_[INIT|DESTROY]) + * @size: sizeof(struct amd_viommu_iommu_info) + * @iommu_id: PCI device ID of the AMD IOMMU instance + * @gid: guest ID + * + * Initialize and destroy AMD HW-vIOMMU instances for the specified + * guest ID. + */ +struct amd_viommu_iommu_info { + __u32 size; + __u32 iommu_id; + __u32 gid; +}; +#define VIOMMU_IOMMU_INIT _IO(IOMMUFD_TYPE, IOMMUFD_CMD_IOMMU_INIT) +#define VIOMMU_IOMMU_DESTROY _IO(IOMMUFD_TYPE, IOMMUFD_CMD_IOMMU_DESTROY) + +/** + * struct amd_viommu_dev_info - ioctl(VIOMMU_DEVICE_[ATTACH|DETACH]) + * @size: sizeof(struct amd_viommu_dev_info) + * @iommu_id: PCI device ID of the AMD IOMMU instance + * @gid: guest ID + * @hdev_id: host PCI device ID + * @gdev_id: guest PCI device ID + * @queue_id: guest PCI device queue ID + * + * Attach / Detach PCI device to a HW-vIOMMU instance, and program + * the IOMMU Device ID mapping table for the specified guest. + */ +struct amd_viommu_dev_info { + __u32 size; + __u32 iommu_id; + __u32 gid; + __u16 hdev_id; + __u16 gdev_id; + __u16 queue_id; +}; + +#define VIOMMU_DEVICE_ATTACH _IO(IOMMUFD_TYPE, IOMMUFD_CMD_DEVICE_ATTACH) +#define VIOMMU_DEVICE_DETACH _IO(IOMMUFD_TYPE, IOMMUFD_CMD_DEVICE_DETACH) + +/** + * struct amd_viommu_dom_info - ioctl(VIOMMU_DOMAIN_[ATTACH|DETACH]) + * @size: sizeof(struct amd_viommu_dom_info) + * @iommu_id: PCI device ID of the AMD IOMMU instance + * @gid: guest ID + * @hdev_id: host PCI device ID + * @gdev_id: guest PCI device ID + * @gdom_id: guest domain ID + * + * Attach / Detach domain of a PCI device to a HW-vIOMMU instance, and program + * the IOMMU Domain ID mapping table for the specified guest. + */ +struct amd_viommu_dom_info { + __u32 size; + __u32 iommu_id; + __u32 gid; + __u16 gdev_id; + __u16 gdom_id; +}; + +#define VIOMMU_DOMAIN_ATTACH _IO(IOMMUFD_TYPE, IOMMUFD_CMD_DOMAIN_ATTACH) +#define VIOMMU_DOMAIN_DETACH _IO(IOMMUFD_TYPE, IOMMUFD_CMD_DOMAIN_DETACH) + +/** + * struct amd_viommu_mmio_data- ioctl(VIOMMU_MMIO_ACCESS) + * @size: sizeof(struct amd_viommu_mmio_data) + * @iommu_id: PCI device ID of the AMD IOMMU instance + * @gid: guest ID + * @offset: specify MMIO offset + * @value: specify MMIO write value or retrieving MMIO read value + * @mmio_size: specify MMIO size + * @is_write: specify MMIO read (0) / write (1) + * + * - Trap guest IOMMU MMIO write to program HW-vIOMMU for the specified + * guest. + * - Trap guest IOMMU MMIO read to emulate return value for the specified + * guest. + */ +struct amd_viommu_mmio_data { + __u32 size; + __u32 iommu_id; + __u32 gid; + __u32 offset; + __u64 value; + __u32 mmio_size; + __u8 is_write; +}; + +#define VIOMMU_MMIO_ACCESS _IO(IOMMUFD_TYPE, IOMMUFD_CMD_MMIO_ACCESS) + +/** + * struct amd_viommu_cmdbuf_data - ioctl(VIOMMU_CMDBUF_UPDATE) + * @size: sizeof(struct amd_viommu_cmdbuf_data) + * @iommu_id: PCI device ID of the AMD IOMMU instance + * @gid: guest ID + * @gcmdbuf_size: guest command buffer size + * @hva: host virtual address for the guest command buffer + * + * Trap guest command buffer initialization to setup HW-vIOMMU command buffer + * for the specified guest. + */ +struct amd_viommu_cmdbuf_data { + __u32 size; + __u32 iommu_id; + __u32 gid; + __u32 cmdbuf_size; + __u64 hva; +}; + +#define VIOMMU_CMDBUF_UPDATE _IO(IOMMUFD_TYPE, IOMMUFD_CMD_CMDBUF_UPDATE) + +#endif From patchwork Wed Jun 21 23:55:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suravee Suthikulpanit X-Patchwork-Id: 111352 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp4721859vqr; Wed, 21 Jun 2023 16:57:58 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6D1IsKbM8L0mGNacHjGnyXpfl/RNViHs7ZIT8RXbUqWYj8kwlntsgiWW2KU6yFMmbi9ADf X-Received: by 2002:a05:622a:391:b0:3f6:ba9d:50fc with SMTP id j17-20020a05622a039100b003f6ba9d50fcmr21567664qtx.31.1687391878004; Wed, 21 Jun 2023 16:57:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1687391877; cv=pass; d=google.com; s=arc-20160816; b=PZX6pTynW5pD56anfgW7Qu5UuDN/aK+amxSi6W+jKY8Z5L18QX3EsnA7QeDnlaTiOU vB/SF9S/1r2HOT3HH0t/9Bs939uUVLx8CDNaoyu6m2vLvEc/3uDqxcz8UH01bfHUnxHi IN+L3BZuFmYlL+ViRPQ8yEEhXHXLmaA3MHH1OKz3W7ohJnKk0bzAfKr6uFYylBV/8Bwg KnFpXvLzYdE9AKXFnWxh23aiSD3c+opnXGeZNUsxSmJcjYPc/qf+5X5zFpVFmtWYYKS4 tuiwwm1CCCyhPlb8yDdrxXxRTqbnWtZLWrOVqn2bgSk9ViznTb/hjXLeTlRh/GQf/WKR eN4w== 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=aju7L6FAaEB7q7q5mybI04vPRz51MsXL4lyz1nHz12s=; b=ZIljz5luyDyGQtcJV9P278QaEq1s4TZ9Ya/hD0UlPod4pEGPeCuFOIthW/yYDLFHDO 158G01IiAYtv77QGMagSH8Ever5Jr1Duj7m2Vl928qZQOE/NUHfBU4X/8wdy6ZW358PY poBSkyns9wbOUo7+D9tuGN2ueKKG7yM3SS0KdNDFLt715TDwTCg0JAKM+RvW9rAbFd1g JS9HGXuOPk1VAopoV3dscDbm66hTmLbDa32k3kAEth2+yVTOtEdlyRIguwEmC4Ej2QRR rj6OsDtUkEZ9EQyW4fjXjaDszZWU0HLOWMwLVAZdnM2zJBwLOo1KkMjeOp2GYWhugz1Z p9Ww== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=HKCzeK5f; 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 q90-20020a17090a4fe300b0025c095abe89si12656441pjh.56.2023.06.21.16.57.45; Wed, 21 Jun 2023 16:57:57 -0700 (PDT) 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=HKCzeK5f; 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 S230009AbjFUX4p (ORCPT + 99 others); Wed, 21 Jun 2023 19:56:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230214AbjFUX4G (ORCPT ); Wed, 21 Jun 2023 19:56:06 -0400 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2068.outbound.protection.outlook.com [40.107.237.68]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 237771BF7; Wed, 21 Jun 2023 16:56:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RDU9CqgLRnSat+0kpOXWxajenIa5E0UkUmZj7tAs/qlSeEM5egg4orf1whxdaeWn+PKVB3mjhIz9DDc6vQnDTCjjhZx+vYbA3KHzqigWuslNdUS7S431QoT7O121KLw6o1fLmYzpXrrxTlRXQg6TeNqFjPDWnqri9LtPy/EUEWxSZtGXCKrIRpS8AocWZvj+OZXLJ3sy+4ygT9acGRiYqLB++/Z7Qj6shf9nnbEbnAzbCVSCDrgHAgRwo8A1ixAFZxwPwzfu2kG+fHLDxcsYIdfrGiuS9Ya0Zxxjk4JOx8nRQXl0AZ6aumqkiYUDK6R0VuhlN09K+g1FP4API/DsZw== 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=aju7L6FAaEB7q7q5mybI04vPRz51MsXL4lyz1nHz12s=; b=bmluJ3C83ZgqvVnvs0H+stVclcR5c4pzgngubRq2gHYaFOZYPuRoPdTvuBhVJEMM5whqdoWp8Sh2LAqOigXFzUoOtN/mDGfwnxiNYfSGKaISYMiGLMOhlShQD/W9tUmwNslJweo277DxC8bdbJEXJqO1uavbiGP7TknTVEXYCnhMOjfv6IPPJD6/83741IEGawkx7phzWX1sl1d+C2G964+vOnpybYLUnMjn/g68kNrylJcKMppRcrNlZu6obidBwMLWchhS39gK3wcyCyAGEMgOuEopwuFazAZIrS66TUqbT7mc+AbNIErcMCc95lV1C5lMB2XTm5d3T+w5oymlUA== 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=aju7L6FAaEB7q7q5mybI04vPRz51MsXL4lyz1nHz12s=; b=HKCzeK5fiIA79UjlNIU5SUBw5R1wR2wKLWfjU4Mkd6ElEV9MtBmMwLJfJQILRgr+GD9jA9p7nGiW7XQRC3g7uPhJDV7E3XRAFCcPzvhPxnjBSIn19/GUoN1dznFLXcWn1623Wi486XFCyk7R7OahvqWqczm5Ie0BOfgpQHfGSGg= Received: from CY5PR15CA0034.namprd15.prod.outlook.com (2603:10b6:930:1b::15) by MN2PR12MB4285.namprd12.prod.outlook.com (2603:10b6:208:1d7::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.23; Wed, 21 Jun 2023 23:55:56 +0000 Received: from CY4PEPF0000E9D4.namprd03.prod.outlook.com (2603:10b6:930:1b:cafe::f6) by CY5PR15CA0034.outlook.office365.com (2603:10b6:930:1b::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.24 via Frontend Transport; Wed, 21 Jun 2023 23:55: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 CY4PEPF0000E9D4.mail.protection.outlook.com (10.167.241.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6521.21 via Frontend Transport; Wed, 21 Jun 2023 23:55:56 +0000 Received: from ruby-95f9host.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.2507.23; Wed, 21 Jun 2023 18:55:54 -0500 From: Suravee Suthikulpanit To: , , CC: , , , , , , , , , , , , , , , "Suravee Suthikulpanit" Subject: [RFC PATCH 13/21] iommu/amd: Introduce vIOMMU command-line option Date: Wed, 21 Jun 2023 18:55:00 -0500 Message-ID: <20230621235508.113949-14-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230621235508.113949-1-suravee.suthikulpanit@amd.com> References: <20230621235508.113949-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: CY4PEPF0000E9D4:EE_|MN2PR12MB4285:EE_ X-MS-Office365-Filtering-Correlation-Id: 906e513c-5a50-4fcc-3e1e-08db72b30e17 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: UxT0EgDSsKp73JKt7WUKZiCC9+5VYYCi7DU2nj0yRuGhfcf0OeH46GY+8Q7EyoJx7HEJwwFbe3ye9bkhmShx4E1UaqyKPVtQcvAAUEAhyVPXKAgKR8lJ4ZegvdIlpRa4wtePJO7fytDTqNKuRslLs3TxHZQeHw3J3rxeGpcWKiXlpjAO6TavR6ziCvDT120ajXatSiqPPxt/k4fhSuDkY+EYoaNmgiojIie0Ok4uJGG1S7O6vmxabjVHHOLjoDtxxUTzqGTrNxUDQT7nHSfbYsR0O+DGQNxB2wItVJDMFnP1CKaD85velbA13XM1g6UjxmTUXkHLnT0d5crSa7WBH4PKbAvYeorLO2wi25gqTV+P3TK2qumIp/FeCbj4iAyobH6N7Rfms0LbaqvcdTZsoK1uDKUq6abs+LrAryfsxoayAbcgTyNUtza/XTjqoesNFcGi7y322WJV9nELih+ubshZtiDtlLUyBldYZzHF1TASZkEBvwtDPefL/p16Y0vlN9AwTrT3gZs+XrckrxMl8CAtxy+Y8apexBQ45H7EPxo51Q8lMrcaMdQHnrcMQSkXQYDBPrA43SL6gLmOasBelFeKb/yFGHy6Duxw7xLMQIKMyQOdBrK5FpbWXQEwkRKQ+WRuphc3xTgsDascfAzpt5j4HbwnoNDmhq+DA6OLXB8EICFq6b7UtZ8QiHPDUwM8p/UJiGzNdPGJ7oZsHYyLAM2djIWvdYfLJwEafWT8XDYJ3Laiw4gcker7by2JYh0JA8MiRK0VCegvC9FShJSWjw== 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:(13230028)(4636009)(346002)(376002)(136003)(39860400002)(396003)(451199021)(40470700004)(36840700001)(46966006)(6666004)(478600001)(54906003)(110136005)(4326008)(47076005)(40480700001)(336012)(426003)(83380400001)(2616005)(86362001)(36756003)(36860700001)(40460700003)(2906002)(70586007)(82310400005)(16526019)(186003)(7696005)(1076003)(26005)(356005)(82740400003)(81166007)(70206006)(41300700001)(8936002)(8676002)(316002)(5660300002)(7416002)(44832011)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jun 2023 23:55:56.3080 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 906e513c-5a50-4fcc-3e1e-08db72b30e17 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: CY4PEPF0000E9D4.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4285 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=no 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?1769358625664875354?= X-GMAIL-MSGID: =?utf-8?q?1769358625664875354?= To disable vIOMMU feature, specify option "amd_iommu=viommu_disable". Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/amd_iommu.h | 2 ++ drivers/iommu/amd/amd_iommu_types.h | 1 + drivers/iommu/amd/init.c | 10 ++++++++++ 3 files changed, 13 insertions(+) diff --git a/drivers/iommu/amd/amd_iommu.h b/drivers/iommu/amd/amd_iommu.h index c9dfa4734801..a65d22384ab8 100644 --- a/drivers/iommu/amd/amd_iommu.h +++ b/drivers/iommu/amd/amd_iommu.h @@ -46,6 +46,8 @@ void amd_iommu_debugfs_setup(struct amd_iommu *iommu); static inline void amd_iommu_debugfs_setup(struct amd_iommu *iommu) {} #endif +extern bool amd_iommu_viommu; + /* Needed for interrupt remapping */ extern int amd_iommu_prepare(void); extern int amd_iommu_enable(void); diff --git a/drivers/iommu/amd/amd_iommu_types.h b/drivers/iommu/amd/amd_iommu_types.h index aa16a7079b5c..019a9182df87 100644 --- a/drivers/iommu/amd/amd_iommu_types.h +++ b/drivers/iommu/amd/amd_iommu_types.h @@ -96,6 +96,7 @@ #define FEATURE_GAM_VAPIC (1ULL<<21) #define FEATURE_GIOSUP (1ULL<<48) #define FEATURE_EPHSUP (1ULL<<50) +#define FEATURE_VIOMMU (1ULL<<55) #define FEATURE_SNP (1ULL<<63) #define FEATURE_GATS_5LEVEL 1ULL diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c index 6a045a187971..4dd9f09e16c4 100644 --- a/drivers/iommu/amd/init.c +++ b/drivers/iommu/amd/init.c @@ -194,6 +194,9 @@ bool amdr_ivrs_remap_support __read_mostly; bool amd_iommu_force_isolation __read_mostly; +/* VIOMMU enabling flag */ +bool amd_iommu_viommu = true; + /* * AMD IOMMU allows up to 2^16 different protection domains. This is a bitmap * to know which ones are already in use. @@ -2154,6 +2157,9 @@ static void print_iommu_info(void) if (iommu->features & FEATURE_SNP) pr_cont(" SNP"); + if (iommu->features & FEATURE_VIOMMU) + pr_cont(" vIOMMU"); + pr_cont("\n"); } } @@ -2166,6 +2172,8 @@ static void print_iommu_info(void) pr_info("V2 page table enabled (Paging mode : %d level)\n", amd_iommu_gpt_level); } + if (amd_iommu_viommu) + pr_info("AMD-Vi: vIOMMU enabled\n"); } static int __init amd_iommu_init_pci(void) @@ -3402,6 +3410,8 @@ static int __init parse_amd_iommu_options(char *str) amd_iommu_pgtable = AMD_IOMMU_V1; } else if (strncmp(str, "pgtbl_v2", 8) == 0) { amd_iommu_pgtable = AMD_IOMMU_V2; + } else if (strncmp(str, "viommu_disable", 14) == 0) { + amd_iommu_viommu = false; } else { pr_notice("Unknown option - '%s'\n", str); } From patchwork Wed Jun 21 23:55:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suravee Suthikulpanit X-Patchwork-Id: 111359 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp4726135vqr; Wed, 21 Jun 2023 17:06:02 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ71qOcTVncZ12ntp+FYGoTWDhBs6cXdvx9HgAH7TlSoCGlPbNfag8/5qUdr+PJWadP147vU X-Received: by 2002:a05:6808:210a:b0:39e:db27:ed90 with SMTP id r10-20020a056808210a00b0039edb27ed90mr12261207oiw.42.1687392361735; Wed, 21 Jun 2023 17:06:01 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1687392361; cv=pass; d=google.com; s=arc-20160816; b=IY2xKq8G0YJoltS25JOkJCE0MCizW/ZHg20i+ENlf6Oq2VyGIJeq5qUR/y8CTsRA/u lxNIPwy91BrduZn5ahtCMpgXMtzkQXPddt88VLsIwKBr22gYIrz3o65IO+h2nVjrqsxL TgdhtY9eMApkaz7SMhJVuSpj+JH6K10ahYheNeBrNPoGKphK8GqW/THknCpdr2yfQGGa DUvGV71hXVk+kGnAdh031Bh1KBeUOy3n+Pd+IQMjupC7vUi4kpHQtugMwNXag759qL5Z E4uLjguqAN9qZaNzBi6wUeGZG3xnSqta+nABSSuQ1KPhb8FAGTsRfhshAOULBthGuzQ3 PPqw== 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=Yz2e1ho/bJYIFckNsG7A9GQvcwB0Nzbs6swFKcCVxkM=; b=tLEnUB49Ic53jGW77PsjOxcKuUUGS/7Sk/JpDNe5C9O03DHzeDBR4ZeZAzJxjsDpi9 A9VlmYtvjX+XpEU9IDtCWM50HVK/HzDwl8Kq4uVwQxaT0AXpnb81cTvmW4gN4UZegApL XsmHQ8zDpPDK7uB4LsNmi0O171UH5CS8qpqUMbrNvH8zjy9H0VgSrulSXdSA4SKzAVBH zXLvitjf6BNTsbWIue8vBX32U4G731lQ+l04o/Y1dSV9CatDqyTZNcgWyAGYzWqB4T0I wrfuXIzMwnfEA2xEzZKC3PKFkgevhmPRs6g4w4E7EEXaWAby/KqxBMKDrGTZ1gurcK6o l4kQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=f0sbbkep; 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 z20-20020a637e14000000b0054f93b261cfsi2372921pgc.88.2023.06.21.17.05.48; Wed, 21 Jun 2023 17:06:01 -0700 (PDT) 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=f0sbbkep; 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 S229676AbjFUX4x (ORCPT + 99 others); Wed, 21 Jun 2023 19:56:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230252AbjFUX4R (ORCPT ); Wed, 21 Jun 2023 19:56:17 -0400 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2056.outbound.protection.outlook.com [40.107.100.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31DFD19BF; Wed, 21 Jun 2023 16:56:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Hk/TJ3InfuZo4HKmP9eFhOS4C8NUIwtG4z3L+jL2cgHBmycYwhnIcMhL1VA7snTNOdHOF6xglK9/lSqfQ8UIKZoV9L09j5l9AporMkPIdoMVCZKpAcgf4/2TB5Wo+dLlrg7mP5QDPFPLFWNl3aNr1nPkP05X82P3Fzx6NLoB2ZC7sZTChbw67zI2NqbjE4P3lnQKDaadR4uYMCTgFmgUEFcaDheG/za8IiYdeCpM8naUPiI5HvvfRJjZWTm2BToZ7kUJVUrH0BmFP0spHFNpjH383GSPCTN3Bdo0cAK5KrD14GHe0OdvdQ/YNUYiWsUDx0KKSn5JzN+cDtOD7c9O1A== 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=Yz2e1ho/bJYIFckNsG7A9GQvcwB0Nzbs6swFKcCVxkM=; b=Ewsq2SPp/5a462qP3iyIXt2hcZ34gc9N90v4PH//4pdPE534POqCvrQC0PcvPEwPKCYzxBw29j0VYp6zcR5vjbJY/M/os3BOcrR3Trct/umqXfT4OHYkQZrdNVj8OhiCvUrU4kTBT/F/paRnVneud8LoEN9Cpkxg5tvKjB90EXUHqJJNYC0LSBKJqMojhqj6UVfFc+tMbLeUtXkebjRIhCeFvOYs9UEvQztCaefMyjfrNoRsx8BCwjlXAFwKq2/TmfCjmhtjYbi0wxXLPSUoC8SUYUQTx48qswtpjtPbsVA3jkXcxk8S+H3tjpJoGVAsIg6iotHe1qFAou8LEGNVCw== 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=Yz2e1ho/bJYIFckNsG7A9GQvcwB0Nzbs6swFKcCVxkM=; b=f0sbbkep96LrVfmXMH7Fane5D2Nzt/5BLpPKPnrOpSECxnFnfw8hfQ3ZRrTfeGcx1Te+slXQnLfQ46JL83SCygpT4IJUEIxk+qmKP18vrooFVW1+ASvDlTpt1hqomSyyLh2+b4p1p9KRK9zG8fJo47DbjpHzys7xO7hyeeodX+U= Received: from CY5PR15CA0040.namprd15.prod.outlook.com (2603:10b6:930:1b::35) by CO6PR12MB5460.namprd12.prod.outlook.com (2603:10b6:5:357::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.21; Wed, 21 Jun 2023 23:55:57 +0000 Received: from CY4PEPF0000E9D4.namprd03.prod.outlook.com (2603:10b6:930:1b:cafe::5d) by CY5PR15CA0040.outlook.office365.com (2603:10b6:930:1b::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.21 via Frontend Transport; Wed, 21 Jun 2023 23:55:57 +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 CY4PEPF0000E9D4.mail.protection.outlook.com (10.167.241.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6521.21 via Frontend Transport; Wed, 21 Jun 2023 23:55:57 +0000 Received: from ruby-95f9host.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.2507.23; Wed, 21 Jun 2023 18:55:55 -0500 From: Suravee Suthikulpanit To: , , CC: , , , , , , , , , , , , , , , "Suravee Suthikulpanit" Subject: [RFC PATCH 14/21] iommu/amd: Initialize vIOMMU private address space regions Date: Wed, 21 Jun 2023 18:55:01 -0500 Message-ID: <20230621235508.113949-15-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230621235508.113949-1-suravee.suthikulpanit@amd.com> References: <20230621235508.113949-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: CY4PEPF0000E9D4:EE_|CO6PR12MB5460:EE_ X-MS-Office365-Filtering-Correlation-Id: ab321304-2be8-4053-eaa2-08db72b30e84 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5TmKQVtWa0LJAlYgCx4H2bWbMsyM2AMIZQjuU1nQlbRLTrNXadeKTOp8A/DRrya7CLqtr7P5rT4Ax+Q/pqaItIgGK9t3jaSFTUb3h2894zsGFLFNQ9FdQRGSnhC7kSrtdMP4e/xzfxorlzMU/0cUxoxE7IxmjblbFaXQRm9wUNsD1zNCf8CIm26fHM9cHyta5JyAo6qWyAflcVb6fmkOQhA3pdJ2AVgqEHnReBccfJ0jFAJCVFxk0/5BwjtfUMGlDVZwW1yFTADw3BfVaWztl/MWXmeweb4ilGOZK5vrsx2wg5/t365+nb5hEAsXv86HaOsBG/Ws1O91eZb5/ReBcF5AKmFLT4sKkxZD7fXPTB+QpyyAEiTKt7bO2+Kt5Mv8rhWsgzQe+LRfjBhY9hgH6sMMgJJx278/tcbGBzYkJY8sDyc2Putj4kHtlCC0+lZ7J92GjwaXBO6m9hv5PmYLYvIsISn3cuAHZqdu+D5ZPQl3HxuKnXYdOk2TFNz/2g43dxcg7pn30CWp7ZyhtRiUOeRsEwzPERPusn5NR3MJIjA5vGsltyLvaVo566EreZCsol9uqZHXcx1JCNzxDpQTy5eVS9mU7/KHZLYipnI8agqBdek8Ky0iSoWQplNeKHqG5JV5MUSLWc4FsDcpQWUOSBW2siAlIaFH+oDEQIzZ0DTf2rh2KcifQeqIXHStbwUeew7GcIBQV5LuLW7aPp1t0M+YDg1mvpJVw2QrrFDGT824mKrv6ybmvfAdEoFRLikmawsF4iK54gY1NXwYRp6ryQ== 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:(13230028)(4636009)(136003)(39860400002)(396003)(376002)(346002)(451199021)(36840700001)(46966006)(40470700004)(82310400005)(36860700001)(16526019)(36756003)(356005)(81166007)(7416002)(70206006)(40460700003)(44832011)(5660300002)(41300700001)(8936002)(8676002)(4326008)(70586007)(40480700001)(316002)(86362001)(82740400003)(30864003)(1076003)(47076005)(426003)(2616005)(186003)(2906002)(26005)(336012)(54906003)(6666004)(7696005)(478600001)(110136005)(83380400001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jun 2023 23:55:57.0267 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ab321304-2be8-4053-eaa2-08db72b30e84 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: CY4PEPF0000E9D4.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR12MB5460 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=no 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?1769359133291308279?= X-GMAIL-MSGID: =?utf-8?q?1769359133291308279?= Initialing vIOMMU private address space regions includes parsing PCI vendor-specific capability (VSC), and use information to setup vIOMMU private address space regions. Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/Makefile | 2 +- drivers/iommu/amd/amd_iommu_types.h | 40 +++++ drivers/iommu/amd/amd_viommu.h | 57 +++++++ drivers/iommu/amd/init.c | 3 + drivers/iommu/amd/viommu.c | 227 ++++++++++++++++++++++++++++ 5 files changed, 328 insertions(+), 1 deletion(-) create mode 100644 drivers/iommu/amd/amd_viommu.h create mode 100644 drivers/iommu/amd/viommu.c diff --git a/drivers/iommu/amd/Makefile b/drivers/iommu/amd/Makefile index 773d8aa00283..89c045716448 100644 --- a/drivers/iommu/amd/Makefile +++ b/drivers/iommu/amd/Makefile @@ -1,4 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only -obj-$(CONFIG_AMD_IOMMU) += iommu.o init.o quirks.o io_pgtable.o io_pgtable_v2.o +obj-$(CONFIG_AMD_IOMMU) += iommu.o init.o quirks.o io_pgtable.o io_pgtable_v2.o viommu.o obj-$(CONFIG_AMD_IOMMU_DEBUGFS) += debugfs.o obj-$(CONFIG_AMD_IOMMU_V2) += iommu_v2.o diff --git a/drivers/iommu/amd/amd_iommu_types.h b/drivers/iommu/amd/amd_iommu_types.h index 019a9182df87..5cb5a709b31b 100644 --- a/drivers/iommu/amd/amd_iommu_types.h +++ b/drivers/iommu/amd/amd_iommu_types.h @@ -34,6 +34,17 @@ #define MMIO_RANGE_OFFSET 0x0c #define MMIO_MISC_OFFSET 0x10 +/* vIOMMU Capability offsets (from IOMMU Capability Header) */ +#define MMIO_VSC_HDR_OFFSET 0x00 +#define MMIO_VSC_INFO_OFFSET 0x00 +#define MMIO_VSC_VF_BAR_LO_OFFSET 0x08 +#define MMIO_VSC_VF_BAR_HI_OFFSET 0x0c +#define MMIO_VSC_VF_CNTL_BAR_LO_OFFSET 0x10 +#define MMIO_VSC_VF_CNTL_BAR_HI_OFFSET 0x14 + +#define IOMMU_VSC_INFO_REV(x) ((x >> 16) & 0xFF) +#define IOMMU_VSC_INFO_ID(x) (x & 0xFFFF) + /* Masks, shifts and macros to parse the device range capability */ #define MMIO_RANGE_LD_MASK 0xff000000 #define MMIO_RANGE_FD_MASK 0x00ff0000 @@ -61,12 +72,15 @@ #define MMIO_PPR_LOG_OFFSET 0x0038 #define MMIO_GA_LOG_BASE_OFFSET 0x00e0 #define MMIO_GA_LOG_TAIL_OFFSET 0x00e8 +#define MMIO_PPRB_LOG_OFFSET 0x00f0 +#define MMIO_EVTB_LOG_OFFSET 0x00f8 #define MMIO_MSI_ADDR_LO_OFFSET 0x015C #define MMIO_MSI_ADDR_HI_OFFSET 0x0160 #define MMIO_MSI_DATA_OFFSET 0x0164 #define MMIO_INTCAPXT_EVT_OFFSET 0x0170 #define MMIO_INTCAPXT_PPR_OFFSET 0x0178 #define MMIO_INTCAPXT_GALOG_OFFSET 0x0180 +#define MMIO_VIOMMU_STATUS_OFFSET 0x0190 #define MMIO_EXT_FEATURES2 0x01A0 #define MMIO_CMD_HEAD_OFFSET 0x2000 #define MMIO_CMD_TAIL_OFFSET 0x2008 @@ -180,8 +194,16 @@ #define CONTROL_GAM_EN 25 #define CONTROL_GALOG_EN 28 #define CONTROL_GAINT_EN 29 +#define CONTROL_DUALPPRLOG_EN 30 +#define CONTROL_DUALEVTLOG_EN 32 + +#define CONTROL_PPR_AUTO_RSP_EN 39 +#define CONTROL_BLKSTOPMRK_EN 41 +#define CONTROL_PPR_AUTO_RSP_AON 48 #define CONTROL_XT_EN 50 #define CONTROL_INTCAPXT_EN 51 +#define CONTROL_VCMD_EN 52 +#define CONTROL_VIOMMU_EN 53 #define CONTROL_SNPAVIC_EN 61 #define CTRL_INV_TO_MASK (7 << CONTROL_INV_TIMEOUT) @@ -414,6 +436,13 @@ #define DTE_GPT_LEVEL_SHIFT 54 +/* vIOMMU bit fields */ +#define DTE_VIOMMU_EN_SHIFT 15 +#define DTE_VIOMMU_GUESTID_SHIFT 16 +#define DTE_VIOMMU_GUESTID_MASK 0xFFFF +#define DTE_VIOMMU_GDEVICEID_SHIFT 32 +#define DTE_VIOMMU_GUESTID_MASK 0xFFFF + #define GCR3_VALID 0x01ULL #define IOMMU_PAGE_MASK (((1ULL << 52) - 1) & ~0xfffULL) @@ -694,6 +723,17 @@ struct amd_iommu { */ u16 cap_ptr; + /* Vendor-Specific Capability (VSC) pointer. */ + u16 vsc_offset; + + /* virtual addresses of vIOMMU VF/VF_CNTL BAR */ + u8 __iomem *vf_base; + u8 __iomem *vfctrl_base; + + struct protection_domain *viommu_pdom; + void *guest_mmio; + void *cmdbuf_dirty_mask; + /* pci domain of this IOMMU */ struct amd_iommu_pci_seg *pci_seg; diff --git a/drivers/iommu/amd/amd_viommu.h b/drivers/iommu/amd/amd_viommu.h new file mode 100644 index 000000000000..c1dbc2e37eab --- /dev/null +++ b/drivers/iommu/amd/amd_viommu.h @@ -0,0 +1,57 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (C) 2023 Advanced Micro Devices, Inc. + * Author: Suravee Suthikulpanit + */ + +#ifndef AMD_VIOMMU_H +#define AMD_VIOMMU_H + +#define VIOMMU_MAX_GUESTID (1 << 16) + +#define VIOMMU_VF_MMIO_ENTRY_SIZE 4096 +#define VIOMMU_VFCTRL_MMIO_ENTRY_SIZE 64 + +#define VIOMMU_VFCTRL_GUEST_DID_MAP_CONTROL0_OFFSET 0x00 +#define VIOMMU_VFCTRL_GUEST_DID_MAP_CONTROL1_OFFSET 0x08 +#define VIOMMU_VFCTRL_GUEST_MISC_CONTROL_OFFSET 0x10 + +#define VIOMMU_VFCTRL_GUEST_CMD_CONTROL_OFFSET 0x20 +#define VIOMMU_VFCTRL_GUEST_EVT_CONTROL_OFFSET 0x28 +#define VIOMMU_VFCTRL_GUEST_PPR_CONTROL_OFFSET 0x30 + +#define VIOMMU_VF_MMIO_BASE(iommu, guestId) \ + (iommu->vf_base + (guestId * VIOMMU_VF_MMIO_ENTRY_SIZE)) +#define VIOMMU_VFCTRL_MMIO_BASE(iommu, guestId) \ + (iommu->vfctrl_base + (guestId * VIOMMU_VFCTRL_MMIO_ENTRY_SIZE)) + +#define VIOMMU_GUEST_MMIO_BASE 0 +#define VIOMMU_GUEST_MMIO_SIZE (64 * VIOMMU_MAX_GUESTID) + +#define VIOMMU_CMDBUF_DIRTY_STATUS_BASE 0x400000ULL +#define VIOMMU_CMDBUF_DIRTY_STATUS_SIZE 0x2000 + +#define VIOMMU_DEVID_MAPPING_BASE 0x1000000000ULL +#define VIOMMU_DEVID_MAPPING_ENTRY_SIZE (1 << 20) + +#define VIOMMU_DOMID_MAPPING_BASE 0x2000000000ULL +#define VIOMMU_DOMID_MAPPING_ENTRY_SIZE (1 << 19) + +#define VIOMMU_GUEST_CMDBUF_BASE 0x2800000000ULL +#define VIOMMU_GUEST_CMDBUF_SIZE (1 << 19) + +#define VIOMMU_GUEST_PPR_LOG_BASE 0x3000000000ULL +#define VIOMMU_GUEST_PPR_LOG_SIZE (1 << 19) + +#define VIOMMU_GUEST_PPR_B_LOG_BASE 0x3800000000ULL +#define VIOMMU_GUEST_PPR_B_LOG_SIZE (1 << 19) + +#define VIOMMU_GUEST_EVT_LOG_BASE 0x4000000000ULL +#define VIOMMU_GUEST_EVT_LOG_SIZE (1 << 19) + +#define VIOMMU_GUEST_EVT_B_LOG_BASE 0x4800000000ULL +#define VIOMMU_GUEST_EVT_B_LOG_SIZE (1 << 19) + +extern int iommu_init_viommu(struct amd_iommu *iommu); + +#endif /* AMD_VIOMMU_H */ diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c index 4dd9f09e16c4..48aa71fe76dc 100644 --- a/drivers/iommu/amd/init.c +++ b/drivers/iommu/amd/init.c @@ -34,6 +34,7 @@ #include #include "amd_iommu.h" +#include "amd_viommu.h" #include "../irq_remapping.h" /* @@ -2068,6 +2069,8 @@ static int __init iommu_init_pci(struct amd_iommu *iommu) if (iommu_feature(iommu, FEATURE_PPR) && alloc_ppr_log(iommu)) return -ENOMEM; + iommu_init_viommu(iommu); + if (iommu->cap & (1UL << IOMMU_CAP_NPCACHE)) { pr_info("Using strict mode due to virtualization\n"); iommu_set_dma_strict(); diff --git a/drivers/iommu/amd/viommu.c b/drivers/iommu/amd/viommu.c new file mode 100644 index 000000000000..18036d03c747 --- /dev/null +++ b/drivers/iommu/amd/viommu.c @@ -0,0 +1,227 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2023 Advanced Micro Devices, Inc. + * Author: Suravee Suthikulpanit + */ + +#define pr_fmt(fmt) "AMD-Vi: " fmt +#define dev_fmt(fmt) pr_fmt(fmt) + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "amd_iommu.h" +#include "amd_iommu_types.h" +#include "amd_viommu.h" + +#define GET_CTRL_BITS(reg, bit, msk) (((reg) >> (bit)) & (ULL(msk))) +#define SET_CTRL_BITS(reg, bit1, bit2, msk) \ + ((((reg) >> (bit1)) & (ULL(msk))) << (bit2)) + +LIST_HEAD(viommu_devid_map); + +struct amd_iommu *get_amd_iommu_from_devid(u16 devid) +{ + struct amd_iommu *iommu; + + for_each_iommu(iommu) + if (iommu->devid == devid) + return iommu; + return NULL; +} + +static void viommu_enable(struct amd_iommu *iommu) +{ + if (!amd_iommu_viommu) + return; + iommu_feature_enable(iommu, CONTROL_VCMD_EN); + iommu_feature_enable(iommu, CONTROL_VIOMMU_EN); +} + +static int viommu_init_pci_vsc(struct amd_iommu *iommu) +{ + iommu->vsc_offset = pci_find_capability(iommu->dev, PCI_CAP_ID_VNDR); + if (!iommu->vsc_offset) + return -ENODEV; + + DUMP_printk("device:%s, vsc offset:%04x\n", + pci_name(iommu->dev), iommu->vsc_offset); + return 0; +} + +static int __init viommu_vf_vfcntl_init(struct amd_iommu *iommu) +{ + u32 lo, hi; + u64 vf_phys, vf_cntl_phys; + + /* Setting up VF and VF_CNTL MMIOs */ + pci_read_config_dword(iommu->dev, iommu->vsc_offset + MMIO_VSC_VF_BAR_LO_OFFSET, &lo); + pci_read_config_dword(iommu->dev, iommu->vsc_offset + MMIO_VSC_VF_BAR_HI_OFFSET, &hi); + vf_phys = hi; + vf_phys = (vf_phys << 32) | lo; + if (!(vf_phys & 1)) { + pr_err(FW_BUG "vf_phys disabled\n"); + return -EINVAL; + } + + pci_read_config_dword(iommu->dev, iommu->vsc_offset + MMIO_VSC_VF_CNTL_BAR_LO_OFFSET, &lo); + pci_read_config_dword(iommu->dev, iommu->vsc_offset + MMIO_VSC_VF_CNTL_BAR_HI_OFFSET, &hi); + vf_cntl_phys = hi; + vf_cntl_phys = (vf_cntl_phys << 32) | lo; + if (!(vf_cntl_phys & 1)) { + pr_err(FW_BUG "vf_cntl_phys disabled\n"); + return -EINVAL; + } + + if (!vf_phys || !vf_cntl_phys) { + pr_err(FW_BUG "AMD-Vi: Unassigned VF resources.\n"); + return -ENOMEM; + } + + /* Mapping 256MB of VF and 4MB of VF_CNTL BARs */ + vf_phys &= ~1ULL; + iommu->vf_base = iommu_map_mmio_space(vf_phys, 0x10000000); + if (!iommu->vf_base) { + pr_err("Can't reserve vf_base\n"); + return -ENOMEM; + } + + vf_cntl_phys &= ~1ULL; + iommu->vfctrl_base = iommu_map_mmio_space(vf_cntl_phys, 0x400000); + + if (!iommu->vfctrl_base) { + pr_err("Can't reserve vfctrl_base\n"); + return -ENOMEM; + } + + pr_debug("%s: IOMMU device:%s, vf_base:%#llx, vfctrl_base:%#llx\n", + __func__, pci_name(iommu->dev), vf_phys, vf_cntl_phys); + return 0; +} + +static void *alloc_private_region(struct amd_iommu *iommu, + u64 base, size_t size) +{ + int ret; + void *region; + + region = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, + get_order(size)); + if (!region) + return NULL; + + ret = set_memory_uc((unsigned long)region, size >> PAGE_SHIFT); + if (ret) + goto err_out; + + if (amd_iommu_v1_map_pages(&iommu->viommu_pdom->iop.iop.ops, base, + iommu_virt_to_phys(region), PAGE_SIZE, (size / PAGE_SIZE), + IOMMU_PROT_IR | IOMMU_PROT_IW, GFP_KERNEL, NULL)) + goto err_out; + + pr_debug("%s: base=%#llx, size=%#lx\n", __func__, base, size); + + return region; + +err_out: + free_pages((unsigned long)region, get_order(size)); + return NULL; +} + +static int viommu_private_space_init(struct amd_iommu *iommu) +{ + u64 pte_root = 0; + struct iommu_domain *dom; + struct protection_domain *pdom; + + /* + * Setup page table root pointer, Guest MMIO and + * Cmdbuf Dirty Status regions. + */ + dom = amd_iommu_domain_alloc(IOMMU_DOMAIN_UNMANAGED); + if (!dom) + goto err_out; + + pdom = to_pdomain(dom); + iommu->viommu_pdom = pdom; + set_dte_entry(iommu, iommu->devid, pdom, NULL, pdom->gcr3_tbl, + false, false); + + iommu->guest_mmio = alloc_private_region(iommu, + VIOMMU_GUEST_MMIO_BASE, + VIOMMU_GUEST_MMIO_SIZE); + if (!iommu->guest_mmio) + goto err_out; + + iommu->cmdbuf_dirty_mask = alloc_private_region(iommu, + VIOMMU_CMDBUF_DIRTY_STATUS_BASE, + VIOMMU_CMDBUF_DIRTY_STATUS_SIZE); + if (!iommu->cmdbuf_dirty_mask) + goto err_out; + + pte_root = iommu_virt_to_phys(pdom->iop.root); + pr_debug("%s: devid=%#x, pte_root=%#llx(%#llx), guest_mmio=%#llx(%#llx), cmdbuf_dirty_mask=%#llx(%#llx)\n", + __func__, iommu->devid, (unsigned long long)pdom->iop.root, pte_root, + (unsigned long long)iommu->guest_mmio, iommu_virt_to_phys(iommu->guest_mmio), + (unsigned long long)iommu->cmdbuf_dirty_mask, + iommu_virt_to_phys(iommu->cmdbuf_dirty_mask)); + + return 0; +err_out: + if (iommu->guest_mmio) + free_pages((unsigned long)iommu->guest_mmio, get_order(VIOMMU_GUEST_MMIO_SIZE)); + + if (dom) + amd_iommu_domain_free(dom); + return -ENOMEM; +} + +/* + * When IOMMU Virtualization is enabled, host software must: + * - allocate system memory for IOMMU private space + * - program IOMMU as an I/O device in Device Table + * - maintain the I/O page table for IOMMU private addressing to SPA translations. + * - specify the base address of the IOMMU Virtual Function MMIO and + * IOMMU Virtual Function Control MMIO region. + * - enable Guest Virtual APIC enable (MMIO Offset 0x18[GAEn]). + */ +int __init iommu_init_viommu(struct amd_iommu *iommu) +{ + int ret = -EINVAL; + + if (!amd_iommu_viommu) + return 0; + + if (!iommu_feature(iommu, FEATURE_VIOMMU)) + goto err_out; + + ret = viommu_init_pci_vsc(iommu); + if (ret) + goto err_out; + + ret = viommu_vf_vfcntl_init(iommu); + if (ret) + goto err_out; + + ret = viommu_private_space_init(iommu); + if (ret) + goto err_out; + + viommu_enable(iommu); + + return ret; + +err_out: + amd_iommu_viommu = false; + return ret; +} From patchwork Wed Jun 21 23:55:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suravee Suthikulpanit X-Patchwork-Id: 111355 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp4722258vqr; Wed, 21 Jun 2023 16:59:21 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4dxVYORyKoa6RGjPP7P4QOzjLB1sucQzdhC/5SKHpIC4o5+wkdgWLDodbGA4mznic5xaf4 X-Received: by 2002:a17:903:190:b0:1b1:9968:53be with SMTP id z16-20020a170903019000b001b1996853bemr11959309plg.64.1687391961220; Wed, 21 Jun 2023 16:59:21 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1687391961; cv=pass; d=google.com; s=arc-20160816; b=kS/Z+rTUEPV6i7S3ek/J8gOFsTetw2qmB8I/I5D79ucJEdT7JqNZuigKxnQM7PGu45 BoEWCuqlXIsRbje1gg1GSMq9xP6FfgLGK1pR/gW9CGqX1B/+CeGk8FQ2tWmVgfdF8DJq 4TTblVITBWf930jbXMu6k6LpgbOka46oe2sWN5/eQkYc1HxsQqRDhEno2T/jKwJlpT4H hkxwMheu4o9dvwgVEHlVTbHZkOTth70mAgKqgyWHJHDPsyaVdXcn7k7+NYgzl+w2e5lJ clL71K32mj3rxLEBfcDYsoMGWxmyJatAjQxUZnlQlIRzdN4fo7Z9Tg9qhu6TgxgT+RSY yhrg== 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=opL4/QhswK9hoboF9zUynw6Y50TRvS1CdR+6bH2e+kE=; b=nngxf5EtGYougsJOVzPLh3YgmYa6PYz5G9SY83hqD7pcytJoXXmiNTApK/pi3lL/Z8 BTXjnU/9cKnhqSPsKEUVS3Tr/76psFQlGg7G33vjonlCrb4vD4356JBqZjnJvYQEU3kR zjs0xwPMEN5HaOMRdtX5y4b9BkH1PCAlyJXSKfQAs8EXmo68/hZnIffNXux8fF+dBEWo Lp23xtgT8iEqfRHTM2SvufBtZOguJ17yl27XkImYXqPcPih6Lwe4KP9v2vCeDMtn4hP1 fAlV2RWlDFwyEoA378tbG0fCsStEyBvGvllmciMB+yVithg/X9vC0bhjsPJqSePiJrAr z3BQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=uErT5tbh; 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 j17-20020a170902da9100b001a963979936si2867532plx.153.2023.06.21.16.59.09; Wed, 21 Jun 2023 16:59:21 -0700 (PDT) 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=uErT5tbh; 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 S230352AbjFUX46 (ORCPT + 99 others); Wed, 21 Jun 2023 19:56:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229602AbjFUX4R (ORCPT ); Wed, 21 Jun 2023 19:56:17 -0400 Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam02on2081.outbound.protection.outlook.com [40.107.212.81]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8AE4D1BF9; Wed, 21 Jun 2023 16:56:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Z90loEt/J/SzYvoAOvlnQyOw6KwxisBGnmF8VzUCLmqGA/o95CleIau7pdU8LlOfixZ8qTFd2fZAf9Rh2ntt+4t+SdBZivgQG9nS6UiuRLiczoYs2jpdpxjo+HTjKMjoK4dI4f3Wg4hQWsg9jG0OwXuZDBWbD7OPXlGkv+kpboqBSYjg0MDhRLLm2ifi3TuAimvIUuaQowmjPQA9sbtdrswQ9p+j4rH4L7Gzcxw/QbvjeI/W9fnW0szjEKA7uxEyPTSz7AgveUUYbtuZjsHwFcQX7J/X+EIxaqNGFGE8MVrzwOSvw+omFtH8B00Sz/HJStaTWhwEmGH0ai4DPpxXEA== 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=opL4/QhswK9hoboF9zUynw6Y50TRvS1CdR+6bH2e+kE=; b=WrwjPVJ3wbCL494Hz+9kk3x/4HMLiSaboXrwKKNVRgf3ddHMt8gcYlszmUVEdMNVDMRUhnW2eBKJjJ5fBC2h+PrV8rNx4x9KQjso/w2CXY6TItKXwwazd1BT1f01e7w1AhEekdLFqhD+L+GZ1cJHNZyjCrmDW5w9il1bClF7wshsRx3c0bfy4TS5rE8nWkp0u22oh7Ze71s5Ql5uA+cWEgIiyeoRB10DLLcbSRpovx/OlJzaUcKTvFEXLU1q6e5/wmk7Tp5kJROhxsdV6XBbzV3j/CP/7TuCsrPRcC0n6JQNZ+BbvSwRyDIt0IbhFwtjIJXnToqhErpXV8NbydSnZA== 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=opL4/QhswK9hoboF9zUynw6Y50TRvS1CdR+6bH2e+kE=; b=uErT5tbhrZdn0qu0+xH8yuhyW/ixtdKXI5AYl/AY+oNTUwK722LYVhXElWwbnWKkfGhieBLLbZUAjCe4rz1PUMjPZjll+zRuKJGOjZIUsTUboK2UUqeY5fe3QpIg8oGRqeWzQdhQyQtUuQ1lgguOrN4unEi/Lfx9XwqUYyZlMsE= Received: from CY5PR15CA0035.namprd15.prod.outlook.com (2603:10b6:930:1b::22) by CY5PR12MB6227.namprd12.prod.outlook.com (2603:10b6:930:21::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.23; Wed, 21 Jun 2023 23:55:57 +0000 Received: from CY4PEPF0000E9D4.namprd03.prod.outlook.com (2603:10b6:930:1b:cafe::ff) by CY5PR15CA0035.outlook.office365.com (2603:10b6:930:1b::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.21 via Frontend Transport; Wed, 21 Jun 2023 23:55:57 +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 CY4PEPF0000E9D4.mail.protection.outlook.com (10.167.241.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6521.21 via Frontend Transport; Wed, 21 Jun 2023 23:55:57 +0000 Received: from ruby-95f9host.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.2507.23; Wed, 21 Jun 2023 18:55:56 -0500 From: Suravee Suthikulpanit To: , , CC: , , , , , , , , , , , , , , , "Suravee Suthikulpanit" Subject: [RFC PATCH 15/21] iommu/amd: Introduce vIOMMU vminit and vmdestroy ioctl Date: Wed, 21 Jun 2023 18:55:02 -0500 Message-ID: <20230621235508.113949-16-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230621235508.113949-1-suravee.suthikulpanit@amd.com> References: <20230621235508.113949-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: CY4PEPF0000E9D4:EE_|CY5PR12MB6227:EE_ X-MS-Office365-Filtering-Correlation-Id: cbf2ec24-0f7d-40a0-fabb-08db72b30ed5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zNAboEXd2bsyD3s3CDBqGoVMAdHLGpltkD6QjkC+e2iFF94T9JP6e+5DMv3yGDpyQCBkJYICUS5tFJOkM1eweAPypdzkjVDi+dUh7vmfWxioCgTn9T3J6l/bRlB23Z3JYEe+DR5qEcfXGkp27z9xcCTETldyYO9ELm6quaPwTwpjD2aVm9Ael+4O3DvdTeMUXDdH2IVFn9z0e/pAnJsgMYntXRk9+HghKKwqdEZUSoMh6BSZQYjKjOZxaimCu/pqdz2L8sPbjAEnL4UgCBEmEYcUaP3McP9yiKr606BFhBLZTdHgZ+d0Co4zhjILKsNbWrdbSSLnhnMJEz9y8t4duLItBrRJ8wlMYX+MFsY29+13CHOq+g62WjocEqZB5kuszrh122psQjFDDQ5GFHHOkQ+7yBAYlyaGBPrHXgeGG8A4yybvxPNxCnSyp3NtcgSvWp83njGTR5aM0Va2npyQtfsgQ6Mtz0ANlM5d7Di4eymmhJd7CPb3BcmrCT3bQxXLJyUlHBVh15lHfFMx0/Jdpu0je9Y6VtNzNb+LSqcasxI++pZfUuMtlf1UzY100gxGbvwbPWig2NXu43jxkkQ0H5uWeC43bHaxhNkTHUtYrP2mMOeovPb9+qTjFvAl8T+mmSY3qZPLhpNlZoOL32+vFQ6bZsLpvto8ZlDLokKj62iPhhOBOSQxSGsyEP2Xsc5ibpBf9T0Nr2AckYbbOUv8kCaWxGLdQ0tPmQHZtxNBTAR/Th6LYNSL4uuW7PUJqXLdHfGfnmZ2A++coVLXr2qybw== 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:(13230028)(4636009)(396003)(136003)(376002)(346002)(39860400002)(451199021)(40470700004)(46966006)(36840700001)(83380400001)(426003)(336012)(1076003)(186003)(16526019)(26005)(2616005)(110136005)(54906003)(70206006)(7696005)(478600001)(70586007)(36756003)(86362001)(316002)(82740400003)(4326008)(81166007)(356005)(47076005)(36860700001)(6666004)(5660300002)(44832011)(7416002)(8676002)(41300700001)(8936002)(40460700003)(2906002)(40480700001)(82310400005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jun 2023 23:55:57.5580 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cbf2ec24-0f7d-40a0-fabb-08db72b30ed5 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: CY4PEPF0000E9D4.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6227 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=no 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?1769358713269091684?= X-GMAIL-MSGID: =?utf-8?q?1769358713269091684?= These ioctl interfaces are called when QEMU initialize and destroy VMs. Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/amd_iommu.h | 2 + drivers/iommu/amd/iommu.c | 4 +- drivers/iommu/amd/viommu.c | 294 ++++++++++++++++++++++++++++++++++ 3 files changed, 298 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/amd/amd_iommu.h b/drivers/iommu/amd/amd_iommu.h index a65d22384ab8..fccae07e8c9f 100644 --- a/drivers/iommu/amd/amd_iommu.h +++ b/drivers/iommu/amd/amd_iommu.h @@ -85,6 +85,8 @@ extern int amd_iommu_flush_tlb(struct iommu_domain *dom, u32 pasid); extern int amd_iommu_domain_set_gcr3(struct iommu_domain *dom, u32 pasid, unsigned long cr3); extern int amd_iommu_domain_clear_gcr3(struct iommu_domain *dom, u32 pasid); +extern void amd_iommu_iotlb_sync(struct iommu_domain *domain, + struct iommu_iotlb_gather *gather); extern void amd_iommu_build_efr(u64 *efr, u64 *efr2); diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index b5c62bc8249c..f22b2a5a8bfc 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -2447,8 +2447,8 @@ static void amd_iommu_flush_iotlb_all(struct iommu_domain *domain) spin_unlock_irqrestore(&dom->lock, flags); } -static void amd_iommu_iotlb_sync(struct iommu_domain *domain, - struct iommu_iotlb_gather *gather) +void amd_iommu_iotlb_sync(struct iommu_domain *domain, + struct iommu_iotlb_gather *gather) { struct protection_domain *dom = to_pdomain(domain); unsigned long flags; diff --git a/drivers/iommu/amd/viommu.c b/drivers/iommu/amd/viommu.c index 18036d03c747..2bafa5102ffa 100644 --- a/drivers/iommu/amd/viommu.c +++ b/drivers/iommu/amd/viommu.c @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -28,8 +29,25 @@ #define SET_CTRL_BITS(reg, bit1, bit2, msk) \ ((((reg) >> (bit1)) & (ULL(msk))) << (bit2)) +#define VIOMMU_MAX_GDEVID 0xFFFF +#define VIOMMU_MAX_GDOMID 0xFFFF + +#define VIOMMU_GID_HASH_BITS 16 +static DEFINE_HASHTABLE(viommu_gid_hash, VIOMMU_GID_HASH_BITS); +static DEFINE_SPINLOCK(viommu_gid_hash_lock); +static u32 viommu_next_gid; +static bool next_viommu_gid_wrapped; + LIST_HEAD(viommu_devid_map); +struct amd_iommu_vminfo { + u16 gid; + bool init; + struct hlist_node hnode; + u64 *devid_table; + u64 *domid_table; +}; + struct amd_iommu *get_amd_iommu_from_devid(u16 devid) { struct amd_iommu *iommu; @@ -138,6 +156,50 @@ static void *alloc_private_region(struct amd_iommu *iommu, return NULL; } +static int alloc_private_vm_region(struct amd_iommu *iommu, u64 **entry, + u64 base, size_t size, u16 guestId) +{ + int ret; + u64 addr = base + (guestId * size); + + *entry = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, get_order(size)); + + ret = set_memory_uc((unsigned long)*entry, size >> PAGE_SHIFT); + if (ret) + return ret; + + pr_debug("%s: entry=%#llx(%#llx), addr=%#llx\n", __func__, + (unsigned long long)*entry, iommu_virt_to_phys(*entry), addr); + + ret = amd_iommu_v1_map_pages(&iommu->viommu_pdom->iop.iop.ops, addr, + iommu_virt_to_phys(*entry), PAGE_SIZE, (size / PAGE_SIZE), + IOMMU_PROT_IR | IOMMU_PROT_IW, GFP_KERNEL, NULL); + + return ret; +} + +static void free_private_vm_region(struct amd_iommu *iommu, u64 **entry, + u64 base, size_t size, u16 guestId) +{ + size_t ret; + struct iommu_iotlb_gather gather; + u64 addr = base + (guestId * size); + + pr_debug("entry=%#llx(%#llx), addr=%#llx\n", + (unsigned long long)*entry, + iommu_virt_to_phys(*entry), addr); + + if (!iommu || iommu->viommu_pdom) + return; + ret = amd_iommu_v1_unmap_pages(&iommu->viommu_pdom->iop.iop.ops, + addr, PAGE_SIZE, (size / PAGE_SIZE), &gather); + if (ret) + amd_iommu_iotlb_sync(&iommu->viommu_pdom->domain, &gather); + + free_pages((unsigned long)*entry, get_order(size)); + *entry = NULL; +} + static int viommu_private_space_init(struct amd_iommu *iommu) { u64 pte_root = 0; @@ -225,3 +287,235 @@ int __init iommu_init_viommu(struct amd_iommu *iommu) amd_iommu_viommu = false; return ret; } + +static void viommu_uninit_one(struct amd_iommu *iommu, struct amd_iommu_vminfo *vminfo, u16 guestId) +{ + free_private_vm_region(iommu, &vminfo->devid_table, + VIOMMU_DEVID_MAPPING_BASE, + VIOMMU_DEVID_MAPPING_ENTRY_SIZE, + guestId); + free_private_vm_region(iommu, &vminfo->domid_table, + VIOMMU_DOMID_MAPPING_BASE, + VIOMMU_DOMID_MAPPING_ENTRY_SIZE, + guestId); +} + +/* + * Clear the DevID via VFCTRL registers + * This function will be called during VM destroy via VFIO. + */ +static void clear_device_mapping(struct amd_iommu *iommu, u16 hDevId, u16 guestId, + u16 queueId, u16 gDevId) +{ + u64 val, tmp1, tmp2; + u8 __iomem *vfctrl; + + /* + * Clear the DevID in VFCTRL registers + */ + tmp1 = gDevId; + tmp1 = ((tmp1 & 0xFFFFULL) << 46); + tmp2 = hDevId; + tmp2 = ((tmp2 & 0xFFFFULL) << 14); + val = tmp1 | tmp2 | 0x8000000000000001ULL; + vfctrl = VIOMMU_VFCTRL_MMIO_BASE(iommu, guestId); + writeq(val, vfctrl + VIOMMU_VFCTRL_GUEST_DID_MAP_CONTROL0_OFFSET); +} + +/* + * Clear the DomID via VFCTRL registers + * This function will be called during VM destroy via VFIO. + */ +static void clear_domain_mapping(struct amd_iommu *iommu, u16 hDomId, u16 guestId, u16 gDomId) +{ + u64 val, tmp1, tmp2; + u8 __iomem *vfctrl = VIOMMU_VFCTRL_MMIO_BASE(iommu, guestId); + + tmp1 = gDomId; + tmp1 = ((tmp1 & 0xFFFFULL) << 46); + tmp2 = hDomId; + tmp2 = ((tmp2 & 0xFFFFULL) << 14); + val = tmp1 | tmp2 | 0x8000000000000001UL; + writeq(val, vfctrl + VIOMMU_VFCTRL_GUEST_DID_MAP_CONTROL1_OFFSET); +} + +static void viommu_clear_mapping(struct amd_iommu *iommu, u16 guestId) +{ + int i; + + for (i = 0; i <= VIOMMU_MAX_GDEVID; i++) + clear_device_mapping(iommu, 0, guestId, 0, i); + + for (i = 0; i <= VIOMMU_MAX_GDOMID; i++) + clear_domain_mapping(iommu, 0, guestId, i); +} + +static void viommu_clear_dirty_status_mask(struct amd_iommu *iommu, unsigned int gid) +{ + u32 offset, index, bits; + u64 *group, val; + + if (gid >= 256 * 256) + return; + + group = (u64 *)(iommu->cmdbuf_dirty_mask + + (((gid & 0xFF) << 4) | (((gid >> 13) & 0x7) << 2))); + offset = (gid >> 8) & 0x1F; + index = offset >> 6; + bits = offset & 0x3F; + + val = READ_ONCE(group[index]); + val &= ~(1ULL << bits); + WRITE_ONCE(group[index], val); +} + +/* + * Allocate pages for the following regions: + * - Guest MMIO + * - DeviceID/DomainId Mapping Table + * - Cmd buffer + * - Event/PRR (A/B) logs + */ +static int viommu_init_one(struct amd_iommu *iommu, struct amd_iommu_vminfo *vminfo) +{ + int ret; + + ret = alloc_private_vm_region(iommu, &vminfo->devid_table, + VIOMMU_DEVID_MAPPING_BASE, + VIOMMU_DEVID_MAPPING_ENTRY_SIZE, + vminfo->gid); + if (ret) + goto err_out; + + ret = alloc_private_vm_region(iommu, &vminfo->domid_table, + VIOMMU_DOMID_MAPPING_BASE, + VIOMMU_DOMID_MAPPING_ENTRY_SIZE, + vminfo->gid); + if (ret) + goto err_out; + + viommu_clear_mapping(iommu, vminfo->gid); + viommu_clear_dirty_status_mask(iommu, vminfo->gid); + + return 0; +err_out: + viommu_uninit_one(iommu, vminfo, vminfo->gid); + return -ENOMEM; +} + +int viommu_gid_alloc(struct amd_iommu *iommu, struct amd_iommu_vminfo *vminfo) +{ + u32 gid; + struct amd_iommu_vminfo *tmp; + unsigned long flags; + + spin_lock_irqsave(&viommu_gid_hash_lock, flags); +again: + gid = viommu_next_gid = (viommu_next_gid + 1) & 0xFFFF; + + if (gid == 0) { /* id is 1-based, zero is not allowed */ + next_viommu_gid_wrapped = 1; + goto again; + } + /* Is it still in use? Only possible if wrapped at least once */ + if (next_viommu_gid_wrapped) { + hash_for_each_possible(viommu_gid_hash, tmp, hnode, gid) { + if (tmp->gid == gid) + goto again; + } + } + + pr_debug("%s: gid=%u\n", __func__, gid); + vminfo->gid = gid; + hash_add(viommu_gid_hash, &vminfo->hnode, vminfo->gid); + spin_unlock_irqrestore(&viommu_gid_hash_lock, flags); + return 0; +} + +static void viommu_gid_free(struct amd_iommu *iommu, + struct amd_iommu_vminfo *vminfo) +{ + unsigned long flags; + + pr_debug("%s: gid=%u\n", __func__, vminfo->gid); + spin_lock_irqsave(&viommu_gid_hash_lock, flags); + hash_del(&vminfo->hnode); + spin_unlock_irqrestore(&viommu_gid_hash_lock, flags); +} + +struct amd_iommu_vminfo *get_vminfo(struct amd_iommu *iommu, int gid) +{ + unsigned long flags; + struct amd_iommu_vminfo *tmp, *ptr = NULL; + + spin_lock_irqsave(&viommu_gid_hash_lock, flags); + hash_for_each_possible(viommu_gid_hash, tmp, hnode, gid) { + if (tmp->gid == gid) { + ptr = tmp; + break; + } + } + if (!ptr) + pr_debug("%s : gid=%u not found\n", __func__, gid); + spin_unlock_irqrestore(&viommu_gid_hash_lock, flags); + return ptr; +} + +int amd_viommu_iommu_init(struct amd_viommu_iommu_info *data) +{ + int ret; + struct amd_iommu_vminfo *vminfo; + unsigned int iommu_id = data->iommu_id; + struct amd_iommu *iommu = get_amd_iommu_from_devid(iommu_id); + + if (!iommu) + return -ENODEV; + + vminfo = kzalloc(sizeof(*vminfo), GFP_KERNEL); + if (!vminfo) + return -ENOMEM; + + ret = viommu_gid_alloc(iommu, vminfo); + if (ret) + goto err_out; + + ret = viommu_init_one(iommu, vminfo); + if (ret) + goto err_out; + + vminfo->init = true; + data->gid = vminfo->gid; + pr_debug("%s: iommu_id=%#x, gid=%#x\n", __func__, + pci_dev_id(iommu->dev), vminfo->gid); + + return ret; + +err_out: + viommu_gid_free(iommu, vminfo); + kfree(vminfo); + return ret; +} +EXPORT_SYMBOL(amd_viommu_iommu_init); + +int amd_viommu_iommu_destroy(struct amd_viommu_iommu_info *data) +{ + unsigned int gid = data->gid; + struct amd_iommu_vminfo *vminfo; + unsigned int iommu_id = data->iommu_id; + struct amd_iommu *iommu = get_amd_iommu_from_devid(iommu_id); + + if (!iommu) + return -ENODEV; + + vminfo = get_vminfo(iommu, gid); + if (!vminfo) + return -EINVAL; + + viommu_uninit_one(iommu, vminfo, gid); + + if (vminfo->init) + vminfo->init = false; + return 0; + +} +EXPORT_SYMBOL(amd_viommu_iommu_destroy); From patchwork Wed Jun 21 23:55:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suravee Suthikulpanit X-Patchwork-Id: 111353 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp4721933vqr; Wed, 21 Jun 2023 16:58:14 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5ZTkIucDcKd2CsJFnl28cxVy/+JzUhVb78NASz2VQ7U9FZii4qoPNsiDRCo6vqJLcaBO86 X-Received: by 2002:a92:4b02:0:b0:340:5860:e823 with SMTP id m2-20020a924b02000000b003405860e823mr15307194ilg.32.1687391894098; Wed, 21 Jun 2023 16:58:14 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1687391894; cv=pass; d=google.com; s=arc-20160816; b=emT+EJAyrpc7mDjY1Vlx+zJRnXrvC73OpT5ErBBjPTj4daXhfWrbJRO4MCinozc+Ub pjzJbQbdFYwCY4MWphXzaO9akXKh56r5ulQdwyDvV+jfYm97TDuvhNAefH3X/aQAbX5w CGSUZPjNhaA33IuDDYdlZDNgDJNYtCh5/Wr0lvWbKGv8El0psN0MrHjVtPLTv+ir/BlF w8Vaf9dzb0KqfjpJA6ftLtrQfPbgZQ5OfdpfXZOBAxwp9Y08Gync55LbAVHhhqz6UpnP 3DWag2HIogiFNUSMn3rl/KuvXPkeyJcWdwCbp17RwqnowzT3kE/v81c0C86A+AqLmTBj ZvIg== 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=RuhQRGzbi7lBRXFwlEjVeymmrd3P+hgmDTsczuRKx8g=; b=QU9Utj/TBGFaEZy6eJRRwrF97R3tte5ZuOiyqwHwy8XUJ1/LtY7qljmWFfIUWURElL g4tToETZDyGAGn3ITYj4qGlFYnRbkfPR9Cd2MvUy8Q7m1WstFImggeyDwRJ+k/G0dVAA 4hwn39nYZ+rejybmfdBIOTHJaayQzXgMl8f+JFvaiDRIEQe/120UBO3e7xsdvU3qGNDg vDC9FCQB0/SqXcJjm/bv9lZ9g44cqj9POLButZT0Uc60BA10EQ4jnuT3O0uDcp7Kq7b1 bglkzOsG4ruVD6yJjwJ23CBmb30ayhujnX22faoYf/iz1h4VbpdrUQREc1/xVKi/zi4U j5OA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=xXJ2mRGm; 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 o16-20020a17090ac71000b0025bcf85bda2si505207pjt.7.2023.06.21.16.58.01; Wed, 21 Jun 2023 16:58:14 -0700 (PDT) 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=xXJ2mRGm; 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 S229710AbjFUX4t (ORCPT + 99 others); Wed, 21 Jun 2023 19:56:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230253AbjFUX4R (ORCPT ); Wed, 21 Jun 2023 19:56:17 -0400 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2080.outbound.protection.outlook.com [40.107.243.80]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B2AF1BFA; Wed, 21 Jun 2023 16:56:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UVTurVIAoleTdXv0R+OilOUHI/vr6boJS+SjmkHDrFVhwQO257zZoYqo51dbJnPN6SPy9Uz2yEL/57V/BP0cw1e0rjyxYXKCzZ4ZlApdLxpQr8Aymos/Xvf/xy7DwQQdpkr51xk8wdEz77PS8QW/X1F5IFs/6AfU/uDeGZU2/H/IERXtoO9v+K+BCUYFsKAxkVa+BaQ7+D56y6DUOevbLQYbGoynMV4vsOo3jb3XbHuILeXrEOO7Axflt0DSHgQFaRmIvfH2czwzCXjuc1vfFCv11qhvK9TfGRSygbf5NbR8hQcbJYs10/K6EP1QgeJ/LbiwrrQ8XiYHzF/IhT1foQ== 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=RuhQRGzbi7lBRXFwlEjVeymmrd3P+hgmDTsczuRKx8g=; b=HuRrjnfeC9yw56tBZ0Wo5AttsXYAlZDrzBkzlq81rsGlgbxUbJ0DIuM3RusTgbsxuKh+Ta1azZ36VXERRq5zMSUg6E8xqW9B0QKuxnBc/nKgwsobZzAp1lmaTHdpqVkYJODdVQRlDjwvgEVktp/Qpancq3ulCwjw/ioxcNuGrx+F4SqUqLU4fA0bfGNNzpAyb3OJqQ0JaM8Hc3AfjVHgMSuOLcjQ2+vicBWoT+WQnsAR0nyahjAceRS/vIHIYN7ivgDOv5onJ6l4uWp70hlrrwNuYlb1XjiFrPQsGWq9o5Fnp8UgUjt/ODbXcuZ/5y4/tTMRBKjQMNepxiC5+o5mvA== 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=RuhQRGzbi7lBRXFwlEjVeymmrd3P+hgmDTsczuRKx8g=; b=xXJ2mRGmKDnSa15ejkK6hFVzmLhOnmOHN2JzxRWFXqX9tldJ9l9mSaB8MLVy7PqyswHdAGe4JpyhPxmxzr+Iy7EFWun/3x6jugQv7VVljDIbxtM7Y3tqMaMJR9pn9g4cyiSFuGUF47NOMcuDOQw29ZvZi+ikXoQWODalD+aOJ3M= Received: from CY8PR11CA0046.namprd11.prod.outlook.com (2603:10b6:930:4a::6) by BL1PR12MB5127.namprd12.prod.outlook.com (2603:10b6:208:31b::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.21; Wed, 21 Jun 2023 23:55:59 +0000 Received: from CY4PEPF0000E9D1.namprd03.prod.outlook.com (2603:10b6:930:4a:cafe::c4) by CY8PR11CA0046.outlook.office365.com (2603:10b6:930:4a::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.23 via Frontend Transport; Wed, 21 Jun 2023 23:55:58 +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 CY4PEPF0000E9D1.mail.protection.outlook.com (10.167.241.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6521.23 via Frontend Transport; Wed, 21 Jun 2023 23:55:58 +0000 Received: from ruby-95f9host.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.2507.23; Wed, 21 Jun 2023 18:55:57 -0500 From: Suravee Suthikulpanit To: , , CC: , , , , , , , , , , , , , , , "Suravee Suthikulpanit" Subject: [RFC PATCH 16/21] iommu/amd: Introduce vIOMMU ioctl for updating device mapping table Date: Wed, 21 Jun 2023 18:55:03 -0500 Message-ID: <20230621235508.113949-17-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230621235508.113949-1-suravee.suthikulpanit@amd.com> References: <20230621235508.113949-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: CY4PEPF0000E9D1:EE_|BL1PR12MB5127:EE_ X-MS-Office365-Filtering-Correlation-Id: def41212-f7b6-4b3a-ecbe-08db72b30f7f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: z26dcwE+uIJSfxzi+AN7yEXhrF3IhSX7ILeOHg3L+cQiyWc8s+l/43BJMYfMe3ROH8J0wtDZDkSVcaMVvcSFHJvpoDeDajkhPGHUTdnfZYoF+YQxgxciMqfR4hrjAIpUb6D0d2/fsGkc0X1cZsgcVac7z4sJ7U3LL6imxGiSRQIjibvAOs2/xJduu7R8jRYD6zgfla7ZJvGMXEy+MKmb3b1wiRadk4giSrq+6mNLGbu2Euld1MGRebYO813qFqGqaIlq0z2xYYumGsXwEVALnsiR45axAIAMkBwDz5fq3U89sbaV5ncCRdUy/Npn+0buKBJYdjOa196QHJZtffv6Vu2lETO7/+AqzDrIVMH7/BcLsa8DoBomOIOprcMgqVjzgMiHVmanq2HDtKNbrj8aga5Knb5QeRjvd8RHTg4ITDI4zzeX+V1XjX4zOWvxIiKM0ODjdwAG5wkrLEvkw481InonvRHFwmovh7QI+usUBmVtHqm/LwZLkl53Szy+SIr440rde62r41el/gxbB1EYs4Qd7NGw1Cqg+dy4aY05u8AR6v/lxJNxYVnXvtnoJd5OFREvWnrC9ndSra0LXe7FLsgeDliaYJk401Sa3a2uXUikjyb90nRUCKtg9G8T/kz7P27Z+Q8kIgHOXDPkGzg2wAL6NQn5G85636522Y3reU1dwzleCpw1jGzjBHBk4gZpbD09uAft2it/GpFfM9Vi3XAXis9+qhwnOPOQVk5ckwkC1Q9CPj3PgEKksLj9c9NWnDttrqsyFaDXOjLwgb3e2g== 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:(13230028)(4636009)(396003)(136003)(39860400002)(346002)(376002)(451199021)(40470700004)(46966006)(36840700001)(82310400005)(36860700001)(36756003)(70206006)(40460700003)(356005)(5660300002)(44832011)(7416002)(8676002)(41300700001)(86362001)(8936002)(4326008)(316002)(40480700001)(70586007)(82740400003)(81166007)(47076005)(1076003)(478600001)(26005)(16526019)(426003)(2906002)(2616005)(186003)(83380400001)(6666004)(336012)(7696005)(110136005)(54906003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jun 2023 23:55:58.6717 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: def41212-f7b6-4b3a-ecbe-08db72b30f7f 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: CY4PEPF0000E9D1.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5127 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=no 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?1769358642935525207?= X-GMAIL-MSGID: =?utf-8?q?1769358642935525207?= These ioctl interfaces are used for updating device host-to-guest device ID mappings. Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/viommu.c | 130 +++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) diff --git a/drivers/iommu/amd/viommu.c b/drivers/iommu/amd/viommu.c index 2bafa5102ffa..f6f0056c7fe6 100644 --- a/drivers/iommu/amd/viommu.c +++ b/drivers/iommu/amd/viommu.c @@ -519,3 +519,133 @@ int amd_viommu_iommu_destroy(struct amd_viommu_iommu_info *data) } EXPORT_SYMBOL(amd_viommu_iommu_destroy); + +static void set_dte_viommu(struct amd_iommu *iommu, u16 hDevId, u16 gid, u16 gDevId) +{ + u64 tmp, dte; + struct dev_table_entry *dev_table = get_dev_table(iommu); + + // vImuEn + dte = dev_table[hDevId].data[3]; + dte |= (1ULL << DTE_VIOMMU_EN_SHIFT); + + // GDeviceID + tmp = gDevId & DTE_VIOMMU_GUESTID_MASK; + dte |= (tmp << DTE_VIOMMU_GUESTID_SHIFT); + + // GuestID + tmp = gid & DTE_VIOMMU_GUESTID_MASK; + dte |= (tmp << DTE_VIOMMU_GDEVICEID_SHIFT); + + dev_table[hDevId].data[3] = dte; + + dte = dev_table[hDevId].data[0]; + dte |= DTE_FLAG_GV; + dev_table[hDevId].data[0] = dte; + + iommu_flush_dte(iommu, hDevId); +} + +void dump_device_mapping(struct amd_iommu *iommu, u16 guestId, u16 gdev_id) +{ + void *addr; + u64 offset, val; + struct amd_iommu_vminfo *vminfo; + + vminfo = get_vminfo(iommu, guestId); + if (!vminfo) + return; + + addr = vminfo->devid_table; + offset = gdev_id << 4; + val = *((u64 *)(addr + offset)); + + pr_debug("%s: guestId=%#x, gdev_id=%#x, base=%#llx, offset=%#llx(val=%#llx)\n", __func__, + guestId, gdev_id, (unsigned long long)iommu_virt_to_phys(vminfo->devid_table), + (unsigned long long)offset, (unsigned long long)val); +} + +/* + * Program the DevID via VFCTRL registers + * This function will be called during VM init via VFIO. + */ +static void set_device_mapping(struct amd_iommu *iommu, u16 hDevId, + u16 guestId, u16 queueId, u16 gDevId) +{ + u64 val, tmp1, tmp2; + u8 __iomem *vfctrl; + + pr_debug("%s: iommu_id=%#x, gid=%#x, hDevId=%#x, gDevId=%#x\n", + __func__, pci_dev_id(iommu->dev), guestId, hDevId, gDevId); + + set_dte_viommu(iommu, hDevId, guestId, gDevId); + + tmp1 = gDevId; + tmp1 = ((tmp1 & 0xFFFFULL) << 46); + tmp2 = hDevId; + tmp2 = ((tmp2 & 0xFFFFULL) << 14); + val = tmp1 | tmp2 | 0x8000000000000001ULL; + vfctrl = VIOMMU_VFCTRL_MMIO_BASE(iommu, guestId); + writeq(val, vfctrl + VIOMMU_VFCTRL_GUEST_DID_MAP_CONTROL0_OFFSET); + wbinvd_on_all_cpus(); + + tmp1 = hDevId; + val = ((tmp1 & 0xFFFFULL) << 16); + writeq(val, vfctrl + VIOMMU_VFCTRL_GUEST_MISC_CONTROL_OFFSET); +} + +static void clear_dte_viommu(struct amd_iommu *iommu, u16 hDevId) +{ + struct dev_table_entry *dev_table = get_dev_table(iommu); + u64 dte = dev_table[hDevId].data[3]; + + dte &= ~(1ULL << DTE_VIOMMU_EN_SHIFT); + dte &= ~(0xFFFFULL << DTE_VIOMMU_GUESTID_SHIFT); + dte &= ~(0xFFFFULL << DTE_VIOMMU_GDEVICEID_SHIFT); + + dev_table[hDevId].data[3] = dte; + + dte = dev_table[hDevId].data[0]; + dte &= ~DTE_FLAG_GV; + dev_table[hDevId].data[0] = dte; + + iommu_flush_dte(iommu, hDevId); +} + +int amd_viommu_device_update(struct amd_viommu_dev_info *data, bool is_set) +{ + struct pci_dev *pdev; + struct iommu_domain *dom; + int gid = data->gid; + struct amd_iommu *iommu = get_amd_iommu_from_devid(data->iommu_id); + + if (!iommu) + return -ENODEV; + + clear_dte_viommu(iommu, data->hdev_id); + + if (is_set) { + set_device_mapping(iommu, data->hdev_id, gid, + data->queue_id, data->gdev_id); + + pdev = pci_get_domain_bus_and_slot(0, PCI_BUS_NUM(data->hdev_id), + data->hdev_id & 0xff); + dom = iommu_get_domain_for_dev(&pdev->dev); + if (!dom) { + pr_err("%s: Domain not found (devid=%#x)\n", + __func__, pci_dev_id(pdev)); + return -EINVAL; + } + + /* TODO: Only support pasid 0 for now */ + amd_iommu_flush_tlb(dom, 0); + dump_device_mapping(iommu, gid, data->gdev_id); + + } else { + clear_device_mapping(iommu, data->hdev_id, gid, + data->queue_id, data->gdev_id); + } + + return 0; +} +EXPORT_SYMBOL(amd_viommu_device_update); From patchwork Wed Jun 21 23:55:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suravee Suthikulpanit X-Patchwork-Id: 111363 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp4731239vqr; Wed, 21 Jun 2023 17:17:30 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7lOHH8srY3DVUPTsaQYLZVhwZ+lDSZfhhkOiTJH6LNOHX1ZnGd7gw+onawgUR33i3JYyLX X-Received: by 2002:a17:90a:1a45:b0:256:2fd4:e238 with SMTP id 5-20020a17090a1a4500b002562fd4e238mr13840128pjl.38.1687393050573; Wed, 21 Jun 2023 17:17:30 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1687393050; cv=pass; d=google.com; s=arc-20160816; b=EYYCoXHz/nDagvPfHVjStEqQaSEyMkoDZfv7HdQme85nUMRYLrrLkHjI9sWJl3/nbd Hyzdvu6HBgGdqyhDQDB/logUnA5a5KdAmrDlVpmUEfNFRlG+GbdrqRtxh1h3NokWx8fR DctIFRACFwMxl9GGPUWZkXzenQ+2aTniT8ir5tbNmubKhNu7Xcw7TtV38+OegKbdC/e+ FxMyh7pI1xXwyog45n4Mt2EO3jMgVh1CRCQ96aZl3Y8tZi35zhsDiIhOmh9QKoRknrN/ abALnJ3mq74Jb8jkcRjoxIXFy1bSK0LOq4Wh5bIp38ZDJ2eg9UkR0KapKZRoFlPDvXu0 Ga1g== 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=I/VvDHsJmf9dnALNK7qOxaQqho6s79GG+SmVZtCnGxg=; b=qjflNsirskXbHwjF1kVBqOH0VZENbHahGwfccB+361hKXdnqBlsX9ACrgcSvYeAIpR H0rzxpwlRRLi6FWKvY4BOgT0w+T3bBTfdGGKpPH0eq3TwY90FdGWq85FiqsWeghW0TGv ziXbugq2r4OP7faL/Hf6BYMiw5kOWFHZnIj4Eo21sHR6HdGGUblNyDFQ9WAysiNIYp4n VlDOt7G4eCBrq6GVkgGMMQqWN8IqUmypjlq6jkGyFf+G7CZMnQ96UoJqRZ+644xLeNWd 0hmFZQ4B7G9aLTEZj2/jbROHMHEJCPuStl+jTbXXkAMY44wuDBhcxcoDsYrK9hyPjtrK cPyA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=HWNqZFUZ; 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 j64-20020a638b43000000b005533ac674a9si5162187pge.286.2023.06.21.17.17.18; Wed, 21 Jun 2023 17:17:30 -0700 (PDT) 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=HWNqZFUZ; 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 S230285AbjFUX5M (ORCPT + 99 others); Wed, 21 Jun 2023 19:57:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230189AbjFUX4o (ORCPT ); Wed, 21 Jun 2023 19:56:44 -0400 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2054.outbound.protection.outlook.com [40.107.237.54]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EEFE21FCF; Wed, 21 Jun 2023 16:56:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GXu1LWIXOQiD38SKsv/WHaeN+pafma22OPQZhwK8jwC/5h5/LwayU7F2pNSmz4q8zEcPgLV9JZrdveZvcyIG6BFPDUrH9rIVM+iVan8kMm/TZ+MIdMt8bMJqPNVs1JITOg3UKK5S9t4EIz4rLlkH26uhqbVb+taFVj55CRMGjcFAFF2jq3M/Vs/UOJKhL3xSofK/wBh3TeZo51ywiwgygxAbpabcarHkp0TerHelEO1no1usLzlqe1v/LFPLO0sla8PMm9+pBEZP4ZdU6miRhBYXDg8Mscm3iYQXvjMBLqesgkGyQ5uOe99QyDodj4SIRQnHq+JeFw8GThOzNas5PQ== 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=I/VvDHsJmf9dnALNK7qOxaQqho6s79GG+SmVZtCnGxg=; b=P6QR6HpFRw+o5Wcl4eG8nkecyf7LINT/ymSmFHO1jBf0z6EIx5B0XocoRGh/dhSkxqbM6PbHc/J1BdfEb3cvcW6SHvgxTXlyQWxetWIl35Al6a6RDz2tZ65hNriAoW1xeIi460BroXqZq6BAgsEFFsh4PBfeX4UT+Icelua1QcvxQoChfavLEmDW17CELVF3OPYMQ8zr3QcHcPIEcy+MeIgPfmEWwqsWEOaZ+PEE+PxTpj1jvt+UtmAINqSGX/PZiJQ/dXYi8E8wShFCRpcVAPoGlRYUIqW0jULaChbqDTqj1BJin10ckUIAFR4MwZJWgrZc448QsUecfIQPDwtvZA== 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=I/VvDHsJmf9dnALNK7qOxaQqho6s79GG+SmVZtCnGxg=; b=HWNqZFUZ18WbQb4neTpzRlbW/DifoVynX+eywl5dxjEZpFnAF6eptVryxjxt0CGlX4R4rIhFVR+5+hl47LMfPtaooIQXPK+5qoENJUPumxMBhcLw2QCalVpg47hKbtnrl9fWNgzUqrU1y6918GxcOi0QXMC3rUGD0gH4pU8gjcM= Received: from CYZPR10CA0006.namprd10.prod.outlook.com (2603:10b6:930:8a::12) by SJ2PR12MB7920.namprd12.prod.outlook.com (2603:10b6:a03:4c6::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6500.37; Wed, 21 Jun 2023 23:56:03 +0000 Received: from CY4PEPF0000E9CD.namprd03.prod.outlook.com (2603:10b6:930:8a:cafe::bd) by CYZPR10CA0006.outlook.office365.com (2603:10b6:930:8a::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.24 via Frontend Transport; Wed, 21 Jun 2023 23:56:02 +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 CY4PEPF0000E9CD.mail.protection.outlook.com (10.167.241.140) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6521.24 via Frontend Transport; Wed, 21 Jun 2023 23:56:02 +0000 Received: from ruby-95f9host.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.2507.23; Wed, 21 Jun 2023 18:55:58 -0500 From: Suravee Suthikulpanit To: , , CC: , , , , , , , , , , , , , , , "Suravee Suthikulpanit" Subject: [RFC PATCH 17/21] iommu/amd: Introduce vIOMMU ioctl for updating domain mapping Date: Wed, 21 Jun 2023 18:55:04 -0500 Message-ID: <20230621235508.113949-18-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230621235508.113949-1-suravee.suthikulpanit@amd.com> References: <20230621235508.113949-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: CY4PEPF0000E9CD:EE_|SJ2PR12MB7920:EE_ X-MS-Office365-Filtering-Correlation-Id: 587bf228-48bd-4c05-18f3-08db72b311f6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: QISvJwkL6Vsyd6Ew5uZsOVaBxKih8X/elzhodu/UZqxZyH7uHwy1Jx54v+EPJMNYjvgt6rzBaglYhABNuKhPQNkexJtvEp4b8lYSz0yi6QcrnQbYfJRUrDJXZ+4+Juu0B7XHBczPywHvFz6Ax7hMn6nsUQ7LwBVOSlEEW6UKZ/DQmVKUDIWEh1xLPdkTU4WL98i+qiL8ofCluWT//0AKxNkB+kEcuMQppJO6tEWU4vYE/zWDEjVAaWkaxITyW+7pGsuHy2PHOrZm/4eXgBsvYGoN7OHlOsA1CpheYLOSMYGqunU0UGd5ZZCj3HBjIpQNkZVvALpF9+zXFJS2QneO9gnd42G9FK40cbDqjNJ7ylV7ZepbDIhsIcMNPYu94ZzIy8JWI6B1LJfft2jSkbGW/qMdCtViEuFS/cttpMe73EqG7XS9N21Ed1qcyP5WmOO26ARD8tvz3r7Wv/RXk5+CYKjQ2BSTJ69gC/zBG/UoYhxnkMZzz6b755nNWjhZL0hjhef8TXcLwmeYDYrsMEeZQQ2PsV6HJmiV0c3x+9dM1FxA+1u9blhGEOJDDqrX5Y10nmn1vFrATB6J1wmlj63RjdxU9YDgvV1tiRnd4CXX7ySEcS2rJivX3+A7kIbANLX42CaxaUyO/OA9/5RxkvnRC2uOMdHkgCbDXHPBPVlXXR99APzCFde42Zq6u3UbbXjVOYb1zFd86KBHGOcCEAn+bNxtFiuvAuMz717m2hSz+kR4XVobvR/YG9oviEDfPfC+26umxKEyuuALKZO/Q1fUkQ== 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:(13230028)(4636009)(376002)(136003)(346002)(396003)(39860400002)(451199021)(40470700004)(36840700001)(46966006)(110136005)(47076005)(44832011)(2906002)(82310400005)(36756003)(36860700001)(70206006)(83380400001)(81166007)(426003)(336012)(7416002)(86362001)(356005)(82740400003)(5660300002)(186003)(41300700001)(16526019)(8936002)(8676002)(26005)(2616005)(316002)(6666004)(7696005)(4326008)(478600001)(40460700003)(70586007)(54906003)(1076003)(40480700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jun 2023 23:56:02.8173 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 587bf228-48bd-4c05-18f3-08db72b311f6 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: CY4PEPF0000E9CD.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB7920 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=no 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?1769359854964816091?= X-GMAIL-MSGID: =?utf-8?q?1769359854964816091?= These ioctl interfaces are used for updating device host-to-guest domain ID mappings. Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/viommu.c | 95 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) diff --git a/drivers/iommu/amd/viommu.c b/drivers/iommu/amd/viommu.c index f6f0056c7fe6..1bcb895cffbf 100644 --- a/drivers/iommu/amd/viommu.c +++ b/drivers/iommu/amd/viommu.c @@ -520,6 +520,101 @@ int amd_viommu_iommu_destroy(struct amd_viommu_iommu_info *data) } EXPORT_SYMBOL(amd_viommu_iommu_destroy); +/* + * Program the DomID via VFCTRL registers + * This function will be called during VM init via VFIO. + */ +static void set_domain_mapping(struct amd_iommu *iommu, u16 guestId, u16 hDomId, u16 gDomId) +{ + u64 val, tmp1, tmp2; + u8 __iomem *vfctrl = VIOMMU_VFCTRL_MMIO_BASE(iommu, guestId); + + pr_debug("%s: iommu_id=%#x, gid=%#x, dom_id=%#x, gdom_id=%#x, val=%#llx\n", + __func__, pci_dev_id(iommu->dev), guestId, hDomId, gDomId, val); + + tmp1 = gDomId; + tmp1 = ((tmp1 & 0xFFFFULL) << 46); + tmp2 = hDomId; + tmp2 = ((tmp2 & 0xFFFFULL) << 14); + val = tmp1 | tmp2 | 0x8000000000000001UL; + writeq(val, vfctrl + VIOMMU_VFCTRL_GUEST_DID_MAP_CONTROL1_OFFSET); + wbinvd_on_all_cpus(); +} + +u64 get_domain_mapping(struct amd_iommu *iommu, u16 gid, u16 gdom_id) +{ + void *addr; + u64 offset, val; + struct amd_iommu_vminfo *vminfo; + + vminfo = get_vminfo(iommu, gid); + if (!vminfo) + return -EINVAL; + + addr = vminfo->domid_table; + offset = gdom_id << 3; + val = *((u64 *)(addr + offset)); + + return val; +} + +void dump_domain_mapping(struct amd_iommu *iommu, u16 gid, u16 gdom_id) +{ + void *addr; + u64 offset, val; + struct amd_iommu_vminfo *vminfo; + + vminfo = get_vminfo(iommu, gid); + if (!vminfo) + return; + + addr = vminfo->domid_table; + offset = gdom_id << 3; + val = *((u64 *)(addr + offset)); + + pr_debug("%s: offset=%#llx(val=%#llx)\n", __func__, + (unsigned long long)offset, + (unsigned long long)val); +} + +static u16 viommu_get_hdev_id(struct amd_iommu *iommu, u16 guestId, u16 gdev_id) +{ + struct amd_iommu_vminfo *vminfo; + void *addr; + u64 offset; + + vminfo = get_vminfo(iommu, guestId); + if (!vminfo) + return -1; + + addr = vminfo->devid_table; + offset = gdev_id << 4; + return (*((u64 *)(addr + offset)) >> 24) & 0xFFFF; +} + +int amd_viommu_domain_update(struct amd_viommu_dom_info *data, bool is_set) +{ + u16 hdom_id, hdev_id; + int gid = data->gid; + struct amd_iommu *iommu = get_amd_iommu_from_devid(data->iommu_id); + struct dev_table_entry *dev_table = get_dev_table(iommu); + + if (!iommu) + return -ENODEV; + + hdev_id = viommu_get_hdev_id(iommu, gid, data->gdev_id); + hdom_id = dev_table[hdev_id].data[1] & 0xFFFFULL; + + if (is_set) { + set_domain_mapping(iommu, gid, hdom_id, data->gdom_id); + dump_domain_mapping(iommu, 0, data->gdom_id); + } else + clear_domain_mapping(iommu, gid, hdom_id, data->gdom_id); + + return 0; +} +EXPORT_SYMBOL(amd_viommu_domain_update); + static void set_dte_viommu(struct amd_iommu *iommu, u16 hDevId, u16 gid, u16 gDevId) { u64 tmp, dte; From patchwork Wed Jun 21 23:55:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suravee Suthikulpanit X-Patchwork-Id: 111366 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp4732342vqr; Wed, 21 Jun 2023 17:20:44 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4OhE3o5DOAAA4CUKhF0VnRZHuiEfHV+LNwKXHovUgDwVWv1eB9VFLOQMy8Ru5X1EKYlfnD X-Received: by 2002:a05:6214:2262:b0:623:9e5c:e625 with SMTP id gs2-20020a056214226200b006239e5ce625mr22661680qvb.29.1687393244527; Wed, 21 Jun 2023 17:20:44 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1687393244; cv=pass; d=google.com; s=arc-20160816; b=pjCIxFcE+aD4BzstB+0WBhqlTKntF7Nr9QzfWTsRWpEIlaQq+lCEU51pX+0THwtBXz vBRX7r1DhqP76u9NRKfib7Ox6H9uZheX4XQkbqdAY/TRzSCWaqVueCBUSobjvA1FiZHV lHMjPPKFSwN73DJ7afCmNZfv1+TJI162XxwsAtpIVsLgXJWnLBBG6Z2n7kcy5hs7Hf+9 nIRTPtPgmFbZx8aUSXISgrJcsovSV1f3/rG9+FDlUDkGFQLFfnyPgxO7jMXYN3X7cjz5 cyleeN0vPHM7le/KIdVyoCokSmPtazq7SK+TAjeEI7R2tB0o6OdSrdAk/Y7ZiMLWgRMf uBug== 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=nIFai9SvDltThSc5w+t701fPid1b+Bnhu1xgFf/9xf0=; b=rMU1yGXPA321FFA7XVo4iU/FO23gmTVjKmAIY+dkSorAHP3A3u9CENPJjdChMqruyy rS85xMBlJ+MCFvkMoQqFxhLpm7NjOl3ik7zAXtpmLn0QttUTqojFZvBEyHWJjdvMeFHx jZGMyggT/0w8hWGSavl+O75OqRglpvzsLDkInFYhVsGuM17mC1sZq8KMyUq04gHXS1eW oQJKXXGMNUpx+vnczTbBQgeYNLZNHnBIzQftxCl7EPh8OozEBqhz5fNK4z6stKUlguC1 Mwj+2yl0rfkqKAQ+QuJR6xBMheLYX0lPhh6iiMXrI+IsqKJdXqz57u25kapIh2or6LqA 90Zw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=nwziml1c; 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 i189-20020a6387c6000000b005533bc87744si5155605pge.816.2023.06.21.17.20.31; Wed, 21 Jun 2023 17:20:44 -0700 (PDT) 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=nwziml1c; 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 S230312AbjFUX5U (ORCPT + 99 others); Wed, 21 Jun 2023 19:57:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230291AbjFUX4p (ORCPT ); Wed, 21 Jun 2023 19:56:45 -0400 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2041.outbound.protection.outlook.com [40.107.236.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99D6C1FF1; Wed, 21 Jun 2023 16:56:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=e/2kAoU7DJhIOZ8tUC35VVmxqhH4PSpFRA1nys+iYvGROb8GSav3tfCzhGScDwojgct72JI+lkyZq1NjNv8KXwv2zo+zQ1hLnWhUjxe2kOPHJNGTjR0ya+mAV14UJLGglf1gTCw+Too2ZsnrAp0XCIVi+5wbehR+VASe5Eg09cq+hFHYylRAnmR8t/3Ho5P/OVx4puYmnHuWHI1NIEHEEHRzVj0RDyF5heNwVLKfxOj2gHU9CmN68QDG8SNART+cXQ8b+3YxLwGQVnwHmBK/AdT2zcdB0exIzK/eDCAtPblkh51UFxajPPU80QDnJ5LDkMuukZ1HbAP76Ygcvq/bsA== 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=nIFai9SvDltThSc5w+t701fPid1b+Bnhu1xgFf/9xf0=; b=HTEGm/H3WAx/0KvQ4csgKg6hG2vUXNgxxaR91eI9jC9TVxkwtd541CFlAGdLYogesXjUnOHr2iGv33qoyBONSD4QB2Zt/v83xuUA09Es/J8Xvn6dRQtZO8uy/AxG9W3ZgJEh81gDFuC7LxppKNCChFBD0tvxJoOn+/nad+caGgwCEk4N4Uf9IWODHkxtuiL7XCStKyONm37mvJxDL72KYk0M5GTZIk6Dd/EoCYyj1YEfjMmU7NnJ4LwzhVXRBCGSmHtUyQIyYBKgjxlgHB+lcxnCdbGGraOZCKCjevsywXky6xtwhevohHaInPWDnIZM8pmuqTwA9fXfpz1fNsdo4g== 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=nIFai9SvDltThSc5w+t701fPid1b+Bnhu1xgFf/9xf0=; b=nwziml1cx+IRmizYygzPqpZ3EqRuVLZfVNK/XBPuKnZZzCeQKV/495opJzBT/npTQQUUIHLbhruZS+3RWaIdEkEAHEx4WxffxtG22q3B9/iz2CE0c3e33XYIpCK3S4Knw11ZFPmPQn8fR46p4f0Vz/2fj6E7PlV6A0zHAx2/D2U= Received: from CY8PR11CA0037.namprd11.prod.outlook.com (2603:10b6:930:4a::29) by SJ0PR12MB5502.namprd12.prod.outlook.com (2603:10b6:a03:300::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.23; Wed, 21 Jun 2023 23:56:05 +0000 Received: from CY4PEPF0000E9D1.namprd03.prod.outlook.com (2603:10b6:930:4a:cafe::f0) by CY8PR11CA0037.outlook.office365.com (2603:10b6:930:4a::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.23 via Frontend Transport; Wed, 21 Jun 2023 23:56:05 +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 CY4PEPF0000E9D1.mail.protection.outlook.com (10.167.241.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6521.23 via Frontend Transport; Wed, 21 Jun 2023 23:56:05 +0000 Received: from ruby-95f9host.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.2507.23; Wed, 21 Jun 2023 18:55:59 -0500 From: Suravee Suthikulpanit To: , , CC: , , , , , , , , , , , , , , , "Suravee Suthikulpanit" Subject: [RFC PATCH 18/21] iommu/amd: Introduce vIOMMU ioctl for handling guest MMIO accesses Date: Wed, 21 Jun 2023 18:55:05 -0500 Message-ID: <20230621235508.113949-19-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230621235508.113949-1-suravee.suthikulpanit@amd.com> References: <20230621235508.113949-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: CY4PEPF0000E9D1:EE_|SJ0PR12MB5502:EE_ X-MS-Office365-Filtering-Correlation-Id: f86a63b5-5a58-47bc-4a1d-08db72b3134a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: K+eWQbLq+6h6zLu+oY8IsTrRLo8EMykWEEYXSkK7D4iQvlOwsG9N1DaEflok9CLNoCKgWJgFQVEAV1RLjNBEEJjoZji4aGhj/8mupl1pMqZa04hM+L6HGtY9ghjNcHxAo81TN9xIBrp5TzSTMRsMrQ/aElUt/2Q+2MyE9QhmweLN5ha5Mqwu/aW+3hOOEAYatJ+mQ2iSfmHZsXoOWIHO+shRWIh4wxg0zwQqh5j/nN0/mH6l+ySzfAiYi6GIUjz6biEtXnTkqXWPyT611QCZVIyWpK93DWCo5oQ0HlPJ89kd1QZVVVTj1K1xUYZ/4oRKUTkYk9+j3/+CCe6URTYxGErgGQakNN3AXWdvKwl2E3VSq3lBr2xcN3gnQsNvuLQLRlqBChccJJgK/njVVMmnaRJmsG5ySGInCfYxSl2PkFd2Oe9LUQdBWUFgJGsOBPcah8z5to2ck1QUhTNAugcY3vGDkdqY5QQ8SX3Nm6md/pvxVETac1xSwD1qWKFvsyMGaXy7Vf8Cq7Ys/Nuh9mHJx9siOIIqGrqxh8hTsKH5h+MIrf/HnHJr/Ij+EQu/qFYyQboKGY/XPoRHxp6VqtlgQVKaHc39f4xAjvOw0TaHOpXyyQ0ByKAnVhjic10P1lnBtDDBjuyzlsPAAB7FvGesO+7yRe2uPQzYxA8vI3yJSZe45/Y2TRV92tf1ZU0lNyK+81rWsMIWrvdZUM1bMMXPR/NUJ3ZfRO5E49qVjoqAj2OlCgOAsjfkQVSiBVcYdafLiWW08I4eVqNi1XIFHbdQMQ== 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:(13230028)(4636009)(346002)(396003)(39860400002)(376002)(136003)(451199021)(36840700001)(46966006)(40470700004)(7696005)(6666004)(478600001)(36860700001)(82310400005)(36756003)(47076005)(16526019)(83380400001)(426003)(336012)(2616005)(86362001)(186003)(81166007)(40480700001)(356005)(82740400003)(1076003)(40460700003)(26005)(8936002)(8676002)(41300700001)(7416002)(44832011)(5660300002)(2906002)(110136005)(54906003)(316002)(70586007)(70206006)(4326008)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jun 2023 23:56:05.0311 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f86a63b5-5a58-47bc-4a1d-08db72b3134a 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: CY4PEPF0000E9D1.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB5502 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=no 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?1769360058469972519?= X-GMAIL-MSGID: =?utf-8?q?1769360058469972519?= This ioctl interface is used for handling guest MMIO read / write to IOMMU MMIO registers. Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/viommu.c | 250 +++++++++++++++++++++++++++++++++++++ 1 file changed, 250 insertions(+) diff --git a/drivers/iommu/amd/viommu.c b/drivers/iommu/amd/viommu.c index 1bcb895cffbf..9ddbdbec4a75 100644 --- a/drivers/iommu/amd/viommu.c +++ b/drivers/iommu/amd/viommu.c @@ -744,3 +744,253 @@ int amd_viommu_device_update(struct amd_viommu_dev_info *data, bool is_set) return 0; } EXPORT_SYMBOL(amd_viommu_device_update); + +int amd_viommu_guest_mmio_read(struct amd_viommu_mmio_data *data) +{ + u8 __iomem *vfctrl, *vf; + u64 val, tmp = 0; + int gid = data->gid; + struct amd_iommu *iommu = get_amd_iommu_from_devid(data->iommu_id); + + if (!iommu) + return -ENODEV; + + vf = VIOMMU_VF_MMIO_BASE(iommu, gid); + vfctrl = VIOMMU_VFCTRL_MMIO_BASE(iommu, gid); + + switch (data->offset) { + case MMIO_CONTROL_OFFSET: + { + /* VFCTRL offset 20h */ + val = readq(vfctrl + 0x20); + tmp |= SET_CTRL_BITS(val, 8, CONTROL_CMDBUF_EN, 1); // [12] + tmp |= SET_CTRL_BITS(val, 9, CONTROL_COMWAIT_EN, 1); // [4] + + /* VFCTRL offset 28h */ + val = readq(vfctrl + 0x28); + tmp |= SET_CTRL_BITS(val, 8, CONTROL_EVT_LOG_EN, 1); // [2] + tmp |= SET_CTRL_BITS(val, 9, CONTROL_EVT_INT_EN, 1); // [3] + tmp |= SET_CTRL_BITS(val, 10, CONTROL_DUALEVTLOG_EN, 3); // [33:32] + + /* VFCTRL offset 30h */ + val = readq(vfctrl + 0x30); + tmp |= SET_CTRL_BITS(val, 8, CONTROL_PPRLOG_EN, 1); // [13] + tmp |= SET_CTRL_BITS(val, 9, CONTROL_PPRINT_EN, 1); // [14] + tmp |= SET_CTRL_BITS(val, 10, CONTROL_PPR_EN, 1); // [15] + tmp |= SET_CTRL_BITS(val, 11, CONTROL_DUALPPRLOG_EN, 3); // [31:30] + tmp |= SET_CTRL_BITS(val, 13, CONTROL_PPR_AUTO_RSP_EN, 1); // [39] + tmp |= SET_CTRL_BITS(val, 14, CONTROL_BLKSTOPMRK_EN, 1); // [41] + tmp |= SET_CTRL_BITS(val, 15, CONTROL_PPR_AUTO_RSP_AON, 1); // [42] + + data->value = tmp; + break; + } + case MMIO_CMD_BUF_OFFSET: + { + val = readq(vfctrl + 0x20); + /* CmdLen [59:56] */ + tmp |= SET_CTRL_BITS(val, 0, 56, 0xF); + data->value = tmp; + break; + } + case MMIO_EVT_BUF_OFFSET: + { + val = readq(vfctrl + 0x28); + /* EventLen [59:56] */ + tmp |= SET_CTRL_BITS(val, 0, 56, 0xF); + data->value = tmp; + break; + } + case MMIO_EVTB_LOG_OFFSET: + { + val = readq(vfctrl + 0x28); + /* EventLenB [59:56] */ + tmp |= SET_CTRL_BITS(val, 4, 56, 0xF); + data->value = tmp; + break; + } + case MMIO_PPR_LOG_OFFSET: + { + val = readq(vfctrl + 0x30); + /* PPRLogLen [59:56] */ + tmp |= SET_CTRL_BITS(val, 0, 56, 0xF); + data->value = tmp; + break; + } + case MMIO_PPRB_LOG_OFFSET: + { + val = readq(vfctrl + 0x30); + /* PPRLogLenB [59:56] */ + tmp |= SET_CTRL_BITS(val, 4, 56, 0xF); + data->value |= tmp; + break; + } + case MMIO_CMD_HEAD_OFFSET: + { + val = readq(vf + 0x0); + data->value = (val & 0x7FFF0); + break; + } + case MMIO_CMD_TAIL_OFFSET: + { + val = readq(vf + 0x8); + data->value = (val & 0x7FFF0); + break; + } + case MMIO_EXT_FEATURES: + { + amd_iommu_build_efr(&data->value, NULL); + break; + } + default: + break; + } + + pr_debug("%s: iommu_id=%#x, gid=%u, offset=%#x, value=%#llx, mmio_size=%u, is_write=%u\n", + __func__, data->iommu_id, gid, data->offset, + data->value, data->mmio_size, data->is_write); + return 0; +} +EXPORT_SYMBOL(amd_viommu_guest_mmio_read); + +/* Note: + * This function maps the guest MMIO write to AMD IOMMU MMIO registers + * into vIOMMU VFCTRL register bits. + */ +int amd_viommu_guest_mmio_write(struct amd_viommu_mmio_data *data) +{ + u8 __iomem *vfctrl, *vf; + int gid = data->gid; + u64 val, tmp, ctrl = data->value; + struct amd_iommu *iommu = get_amd_iommu_from_devid(data->iommu_id); + + if (!iommu) + return -ENODEV; + + pr_debug("%s: iommu_id=%#x, gid=%u, offset=%#x, value=%#llx, mmio_size=%u, is_write=%u\n", + __func__, data->iommu_id, gid, data->offset, + ctrl, data->mmio_size, data->is_write); + + vf = VIOMMU_VF_MMIO_BASE(iommu, gid); + vfctrl = VIOMMU_VFCTRL_MMIO_BASE(iommu, gid); + + switch (data->offset) { + case MMIO_CONTROL_OFFSET: + { + /* VFCTRL offset 20h */ + val = readq(vfctrl + 0x20); + val &= ~(0x3ULL << 8); + tmp = GET_CTRL_BITS(ctrl, CONTROL_CMDBUF_EN, 1); // [12] + val |= (tmp << 8); + tmp = GET_CTRL_BITS(ctrl, CONTROL_COMWAIT_EN, 1); // [4] + val |= (tmp << 9); + writeq(val, vfctrl + 0x20); + + /* VFCTRL offset 28h */ + val = readq(vfctrl + 0x28); + val &= ~(0xFULL << 8); + tmp = GET_CTRL_BITS(ctrl, CONTROL_EVT_LOG_EN, 1); // [2] + val |= (tmp << 8); + tmp = GET_CTRL_BITS(ctrl, CONTROL_EVT_INT_EN, 1); // [3] + val |= (tmp << 9); + tmp = GET_CTRL_BITS(ctrl, CONTROL_DUALEVTLOG_EN, 3); // [33:32] + val |= (tmp << 10); + writeq(val, vfctrl + 0x28); + + /* VFCTRL offset 30h */ + val = readq(vfctrl + 0x30); + val &= ~(0xFFULL << 8); + tmp = GET_CTRL_BITS(ctrl, CONTROL_PPRLOG_EN, 1); // [13] + val |= (tmp << 8); + tmp = GET_CTRL_BITS(ctrl, CONTROL_PPRINT_EN, 1); // [14] + val |= (tmp << 9); + tmp = GET_CTRL_BITS(ctrl, CONTROL_PPR_EN, 1); // [15] + val |= (tmp << 10); + tmp = GET_CTRL_BITS(ctrl, CONTROL_DUALPPRLOG_EN, 3); // [31:30] + val |= (tmp << 11); + tmp = GET_CTRL_BITS(ctrl, CONTROL_PPR_AUTO_RSP_EN, 1); // [39] + val |= (tmp << 13); + tmp = GET_CTRL_BITS(ctrl, CONTROL_BLKSTOPMRK_EN, 1); // [41] + val |= (tmp << 14); + tmp = GET_CTRL_BITS(ctrl, CONTROL_PPR_AUTO_RSP_AON, 1); // [42] + val |= (tmp << 15); + writeq(val, vfctrl + 0x30); + break; + } + case MMIO_CMD_BUF_OFFSET: + { + val = readq(vfctrl + 0x20); + val &= ~(0xFULL); + /* CmdLen [59:56] */ + tmp = GET_CTRL_BITS(ctrl, 56, 0xF); + val |= tmp; + writeq(val, vfctrl + 0x20); + break; + } + case MMIO_EVT_BUF_OFFSET: + { + val = readq(vfctrl + 0x28); + val &= ~(0xFULL); + /* EventLen [59:56] */ + tmp = GET_CTRL_BITS(ctrl, 56, 0xF); + val |= tmp; + writeq(val, vfctrl + 0x28); + break; + } + case MMIO_EVTB_LOG_OFFSET: + { + val = readq(vfctrl + 0x28); + val &= ~(0xF0ULL); + /* EventLenB [59:56] */ + tmp = GET_CTRL_BITS(ctrl, 56, 0xF); + val |= (tmp << 4); + writeq(val, vfctrl + 0x28); + break; + } + case MMIO_PPR_LOG_OFFSET: + { + val = readq(vfctrl + 0x30); + val &= ~(0xFULL); + /* PPRLogLen [59:56] */ + tmp = GET_CTRL_BITS(ctrl, 56, 0xF); + val |= tmp; + writeq(val, vfctrl + 0x30); + break; + } + case MMIO_PPRB_LOG_OFFSET: + { + val = readq(vfctrl + 0x30); + val &= ~(0xF0ULL); + /* PPRLogLenB [59:56] */ + tmp = GET_CTRL_BITS(ctrl, 56, 0xF); + val |= (tmp << 4); + writeq(val, vfctrl + 0x30); + break; + } + case MMIO_CMD_HEAD_OFFSET: + { + val = readq(vf + 0x0); + val &= ~(0x7FFFULL << 4); + tmp = GET_CTRL_BITS(ctrl, 4, 0x7FFF); + val |= (tmp << 4); + writeq(val, vf + 0x0); + break; + } + case MMIO_CMD_TAIL_OFFSET: + { + val = readq(vf + 0x8); + val &= ~(0x7FFFULL << 4); + tmp = GET_CTRL_BITS(ctrl, 4, 0x7FFF); + val |= (tmp << 4); + writeq(val, vf + 0x8); + break; + } + default: + break; + } + + pr_debug("%s: offset=%#x, val=%#llx, ctrl=%#llx\n", + __func__, data->offset, val, ctrl); + return 0; +} +EXPORT_SYMBOL(amd_viommu_guest_mmio_write); From patchwork Wed Jun 21 23:55:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suravee Suthikulpanit X-Patchwork-Id: 111356 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp4722277vqr; Wed, 21 Jun 2023 16:59:24 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6MC+aQUhP2bbH9IPK0XTG0heKDdNUs4D9JC0c6nymbMibyvrwY7thKZCi1dwwo7fyDK8Sr X-Received: by 2002:aca:1917:0:b0:39e:c885:3d9a with SMTP id l23-20020aca1917000000b0039ec8853d9amr7412540oii.20.1687391964003; Wed, 21 Jun 2023 16:59:24 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1687391963; cv=pass; d=google.com; s=arc-20160816; b=hGJqfIjN3wcrtAyjJ5D8aiafuuCTAf+756mklYrHucMcwwtIJHAHxON0/K1HUOHAhy ooC0Q7SSZ6bnBqB5XYSv1eOQpW6id7JFTXdnseNnxP2in42AdM6mfHgM7a+etQvptQnG SfRcjolL+kV1q97uNxW87TyLlnSPs3B8skKNNPLumu/vXrFxOq3xpT4TIlLQm8aM3azW ju24gI/x7heFyNk5tmxafCkkKn5c8tBm0gxTM0kRCIFO7zw+YkfT2Bg+OTZWWNngWGV/ LAH8PSTIta7eG+pjsp4zwYMK+Lhle3XL5d436Fff4lnmJkTskJBM+jdC6cLkFFI/3Uar Bk1A== 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=ieHhxeGQrpKO5YoYf2E5ByWC0tKJRrqhHcmw9fCwYhs=; b=XqUQi5nH082HsYwJpAxn97XYAje9huiUhrECOkCHnLliD2eFGNVpijKVfG52xVyuM2 RYAZLJGJOGQrKqW9bt/UVS5xxe1L5bxopyFYTuFEXJgHv4/XDpy9XewXr937Jj2LVKe8 UMPrCVR8hwLPaY5QWHtxb7ueET3L3MJ96rQaLluI9QAPUwPKYFv7dR+km+VufLThu/SB tdYlC7Cr1QgUxabRPyJQDTCtIeNrie+px3NJIeJ8EfXR3A/hcU30dO5mG2lfhqpuITlA y7rByJqq541veBaWb0mD+EoN49TlU8aecpZgEOQliwe9VjK8000nXbRtoeUR1+b/7R7b aLkw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=sHCuqlgr; 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 q90-20020a17090a4fe300b0025c095abe89si12656441pjh.56.2023.06.21.16.59.12; Wed, 21 Jun 2023 16:59:23 -0700 (PDT) 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=sHCuqlgr; 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 S230367AbjFUX5q (ORCPT + 99 others); Wed, 21 Jun 2023 19:57:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230357AbjFUX5F (ORCPT ); Wed, 21 Jun 2023 19:57:05 -0400 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2050.outbound.protection.outlook.com [40.107.243.50]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4DA6C2121; Wed, 21 Jun 2023 16:56:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iMO7RVt1aYIN2AtV4Hq7RVWcEPvWZNZT1+L021AwpAIQ412AMNUIUsAw4l4x7O9Qy3Gt5Oidf5uDXA0z0UQZYEJNefo4uGI9dOQNwAXb1ksqhO7UFPDtMbAqW25U2izdaRhGK3uX36WAhUUQ0Frg+eXtFDpSOtoSPelh4RPkk/UgEaXWJ5qGekCEvlnJfGnZXINsEdaQPjzjkYpA8mF5GPbun0bj1hkz5tmS/YVtr1V+zpz5oOjejithYFCcWX4+hcEuGcSMTwPCG+o/xpDhETNacd4btdbR0/0BTUXwsKSp2GqIVsC0dW1D26G8vcSYR0e7wNYSBYET7EI8kNVahQ== 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=ieHhxeGQrpKO5YoYf2E5ByWC0tKJRrqhHcmw9fCwYhs=; b=QCGFJnBUzsiAHWfc2ojY6OrR7wzJ9Cl8X6f46x4n83jUeZ2FH5wCH5E6zz9lRxQqE2YEpxBC2hOmzyFcpOBSdw7WOCPrqHoyKVG3hRu84llexJ95TzSux2KXsjMSvGa9l9qDjDk+QMYBpRFdWnBWY0b2BAKV3VfeM/NA2+CzD/E8shIZf9OzxcWcxZb8f97fl8QyYHmMBncMAJv6tY1wpwYOqvAtZpDfywtuw2Y+GIlRoJBUpr97+wpVyC1Rpg8ezMrxU4QfAGHKoidK60cbaNSgCDKs0hASeQyubM1KGrOe+X5z69rECZEqufy50+MtU+X9DVh4fx+TC+jZRx9Qbg== 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=ieHhxeGQrpKO5YoYf2E5ByWC0tKJRrqhHcmw9fCwYhs=; b=sHCuqlgrNiiqrTrl3mMZMYLmWcFn0wXfGgdEqkxzWKhoHVkNtj/sIuK1wRCBhsgykiYV9BuEPMWNOWsaeOjOFV0ZgOb65LiFJq58XbGi1AxP/Ub9G0y6qB28AM3EC25rEOqR9Lw1RcnKl3rKpe/7SuT5h/0upbUiWE7tq1eQjI8= Received: from CY8PR11CA0048.namprd11.prod.outlook.com (2603:10b6:930:4a::26) by CY8PR12MB7148.namprd12.prod.outlook.com (2603:10b6:930:5c::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.21; Wed, 21 Jun 2023 23:56:07 +0000 Received: from CY4PEPF0000E9D1.namprd03.prod.outlook.com (2603:10b6:930:4a:cafe::19) by CY8PR11CA0048.outlook.office365.com (2603:10b6:930:4a::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.23 via Frontend Transport; Wed, 21 Jun 2023 23:56:05 +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 CY4PEPF0000E9D1.mail.protection.outlook.com (10.167.241.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6521.23 via Frontend Transport; Wed, 21 Jun 2023 23:56:05 +0000 Received: from ruby-95f9host.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.2507.23; Wed, 21 Jun 2023 18:56:00 -0500 From: Suravee Suthikulpanit To: , , CC: , , , , , , , , , , , , , , , "Suravee Suthikulpanit" Subject: [RFC PATCH 19/21] iommu/amd: Introduce vIOMMU ioctl for handling command buffer mapping Date: Wed, 21 Jun 2023 18:55:06 -0500 Message-ID: <20230621235508.113949-20-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230621235508.113949-1-suravee.suthikulpanit@amd.com> References: <20230621235508.113949-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: CY4PEPF0000E9D1:EE_|CY8PR12MB7148:EE_ X-MS-Office365-Filtering-Correlation-Id: 4a5cdd97-f8c3-4eb0-45c3-08db72b313a7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ShpCa1PHCT+XWRo14zCD3j+C9Gtwrk7rMGbrKrSkCWT580XDL5UrbNZRZaJ4QJ8sCiqBsfNbNv7GRlJHSHJInC0OpdbzAuk1oGVVHWa28QK+coX8NxssdeCWv65WbVuVBCZjQ93M1FwzZzgNoOvRaQDv6U62Bl+NAh7u5b4gIIB6XPkMoXMYu826IRjLmFWdC00JQ2wr6D3RExKVMPy644hgJ7tnm/eQKp3n0ez1Wf1TmmOPQJIyY23QNcjuOHZUtPC57RjDdUzwun/qjDuEHDX8Rv4UkMms+PSIHTKJ7TXN9KOq3syXHUPGlcL1TMGojYelQqvxDZiOPfxfHUvt9Q7ilAAkPpWThw/NEWkiOTnWEMejLs35qoOBTPoas6mPbsZeZ8bMKptOZqIpiSfosfKOk0MtUl83a4O9ruEn3kvV5enfoqf/gyY7VI6hijeiibpG3OAYKEDIT09Ek1xEtnQ/FBB6zNNT9AV5390XBKvjGtCI7B1FutpQmp+YPhifvudO410E7D+bbhUtikIp/YAfu2ojT5gifsOHgXUDo3d1JYVGnVjUHn7H2mvRfG2Ya1OOd6qhRZvbHXJM3LVM8qdElfqKr3BuQ9SN9+V0fnuK8bsaTRBWnGryksQaOqZ/e7JI/X814SOEj+wOhQ/W1V1AjDAdj5qKBtq03HyJUC22teODA1ifCx0hN711P1rclQNy2HTJ582Uyo+f6sQ1MTupg07xl8cFSre2kiiIEyD+oLlofK3rTSSb4msbmdHiwtwDvTHOUtiPio4w41TRRQ== 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:(13230028)(4636009)(136003)(346002)(396003)(376002)(39860400002)(451199021)(40470700004)(46966006)(36840700001)(36860700001)(82310400005)(40460700003)(81166007)(36756003)(70206006)(356005)(44832011)(5660300002)(7416002)(8676002)(41300700001)(40480700001)(86362001)(4326008)(8936002)(70586007)(316002)(82740400003)(426003)(47076005)(1076003)(26005)(16526019)(186003)(2906002)(7696005)(54906003)(110136005)(2616005)(478600001)(83380400001)(336012)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jun 2023 23:56:05.6405 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4a5cdd97-f8c3-4eb0-45c3-08db72b313a7 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: CY4PEPF0000E9D1.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7148 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=no 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?1769358716202533087?= X-GMAIL-MSGID: =?utf-8?q?1769358716202533087?= This ioctl interface is used for handling vIOMMU command buffer mapping. Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/amd_iommu_types.h | 1 + drivers/iommu/amd/viommu.c | 78 +++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) diff --git a/drivers/iommu/amd/amd_iommu_types.h b/drivers/iommu/amd/amd_iommu_types.h index 5cb5a709b31b..dd3c79e454d8 100644 --- a/drivers/iommu/amd/amd_iommu_types.h +++ b/drivers/iommu/amd/amd_iommu_types.h @@ -261,6 +261,7 @@ #define CMD_BUFFER_SIZE 8192 #define CMD_BUFFER_UNINITIALIZED 1 #define CMD_BUFFER_ENTRIES 512 +#define CMD_BUFFER_MAXSIZE 0x80000 #define MMIO_CMD_SIZE_SHIFT 56 #define MMIO_CMD_SIZE_512 (0x9ULL << MMIO_CMD_SIZE_SHIFT) diff --git a/drivers/iommu/amd/viommu.c b/drivers/iommu/amd/viommu.c index 9ddbdbec4a75..1bd4282384c4 100644 --- a/drivers/iommu/amd/viommu.c +++ b/drivers/iommu/amd/viommu.c @@ -994,3 +994,81 @@ int amd_viommu_guest_mmio_write(struct amd_viommu_mmio_data *data) return 0; } EXPORT_SYMBOL(amd_viommu_guest_mmio_write); + +static void viommu_cmdbuf_free(struct protection_domain *dom, struct io_pgtable_ops *ops, + unsigned long iova, struct page **pages, unsigned long npages) +{ + int i; + unsigned long flags; + unsigned long tmp = iova; + + spin_lock_irqsave(&dom->lock, flags); + for (i = 0; i < npages; i++, tmp += PAGE_SIZE) { + amd_iommu_v1_unmap_pages(ops, tmp, PAGE_SIZE, 1, NULL); + /* + * Flush domain TLB(s) and wait for completion. Any Device-Table + * Updates and flushing already happened in + * increase_address_space(). + */ + amd_iommu_domain_flush_tlb_pde(dom); + amd_iommu_domain_flush_complete(dom); + + unpin_user_pages(&pages[i], 1); + } + spin_unlock_irqrestore(&dom->lock, flags); +} + +int amd_viommu_cmdbuf_update(struct amd_viommu_cmdbuf_data *data) +{ + int i, numpg = data->cmdbuf_size >> PAGE_SHIFT; + struct amd_iommu *iommu = get_amd_iommu_from_devid(data->iommu_id); + struct amd_iommu_vminfo *vminfo; + unsigned int gid = data->gid; + struct page **pages; + unsigned long npages = 0; + unsigned long iova; + unsigned long hva = data->hva; + + pages = kcalloc(numpg, sizeof(struct page *), GFP_KERNEL); + if (!pages) + return -ENOMEM; + + vminfo = get_vminfo(iommu, gid); + if (!vminfo) + return -EINVAL; + + /* + * Setup vIOMMU guest command buffer in IOMMU Private Address (IPA) space + * for the specified GID. + */ + for (i = 0 ; i < numpg; i++, hva += (0x1000 * i)) { + int ret; + u64 phys; + + if (get_user_pages_fast(hva, 1, FOLL_WRITE, &pages[i]) != 1) { + pr_err("%s: Failure locking page:%#lx.\n", __func__, hva); + goto err_out; + } + + phys = __sme_set(page_to_pfn(pages[i]) << PAGE_SHIFT); + iova = VIOMMU_GUEST_CMDBUF_BASE + (i * PAGE_SIZE) + (gid * CMD_BUFFER_MAXSIZE); + + pr_debug("%s: iova=%#lx, phys=%#llx\n", __func__, iova, phys); + ret = amd_iommu_v1_map_pages(&iommu->viommu_pdom->iop.iop.ops, + iova, phys, PAGE_SIZE, 1, + IOMMU_PROT_IR | IOMMU_PROT_IW, + GFP_KERNEL, NULL); + if (ret) { + pr_err("%s: Failure to map page iova:%#lx, phys=%#llx\n", + __func__, iova, phys); + goto err_out; + } + npages++; + } + return 0; +err_out: + viommu_cmdbuf_free(iommu->viommu_pdom, &iommu->viommu_pdom->iop.iop.ops, + iova, pages, npages); + return -EINVAL; +} +EXPORT_SYMBOL(amd_viommu_cmdbuf_update); From patchwork Wed Jun 21 23:55:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suravee Suthikulpanit X-Patchwork-Id: 111367 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp4733497vqr; Wed, 21 Jun 2023 17:23:38 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6PAik11Gs6U8vaiWiZ1rHrd5D0PbqtfUuAmKbmHzEDtFvwrU3MWu5ynAh9B7g2f+cTCDy7 X-Received: by 2002:a05:6a20:43a8:b0:122:edbd:aa74 with SMTP id i40-20020a056a2043a800b00122edbdaa74mr4470799pzl.16.1687393418020; Wed, 21 Jun 2023 17:23:38 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1687393418; cv=pass; d=google.com; s=arc-20160816; b=GtvIRtcD2yPADcGDCZmEOArnWkSJrBr/Ciy0BiCYFEpmkDrIPmSw5XnOSpFTRRkyQs +ByDNGmzCS94y2iXCNGoYKgQ0r/6V44BuKuan7qxOvbzD1VLfDq8h18VIUFVJnXVGhk/ O2RsPy9ftQWoZsFNwR1j+2NykbD8AgNah3ZsDW7Ys4AyW0i12b4GUgbe19fVX71XSw7T +VdHvlgmNKwmGcyHNobVkjM1SZEeaW4p3XyJmJRURW28mIDvKVvVYv1EX93kuOy2BUxW avdlPUHVez8DCTGhi0OJhStT0NiseTkiCnH0lPKk/onAjCzRCr8O7NpfDjBHhGDcAMv4 V9dg== 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=VAczIqgFx2hTWhMkvPvyOwJLCXkcxgD6pD3uo9Cwn4M=; b=CHVpiO5Zj3vfm9X0Ha+f+TQemoOY4jsyT7VOFUtPprb2p8IdgoVbTNhGQcrgpry986 1Nxntf109xQdqQdTiPsbA2VNb8Z5BJveZ+Pf+CSCTH7DD/7+UlV19qkguBwGpMDBjmom meHqwYbcsrZU2+c8vroRsbERsquZQf7QAYBKbans9DaBUpDcWN1f1C40U/tM5sH0mbS5 ptGLBz0vYrJC8GX2io+ihg73jXXkE1yEgLPehmnoLpC0vjxD/Is7uj/QOc1cNsf+uC+o ABjDEsXZXkHtksCxpD9mSBCI2xYXeGuseJw6vmQox6wdTigwVUal71YlDukrvGP3+hBv 6Beg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=PsfvQwVc; 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 c191-20020a624ec8000000b0064d545c8466si5052001pfb.287.2023.06.21.17.23.25; Wed, 21 Jun 2023 17:23:38 -0700 (PDT) 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=PsfvQwVc; 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 S229993AbjFUX5u (ORCPT + 99 others); Wed, 21 Jun 2023 19:57:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38714 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230262AbjFUX5F (ORCPT ); Wed, 21 Jun 2023 19:57:05 -0400 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2063.outbound.protection.outlook.com [40.107.100.63]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E807B212F; Wed, 21 Jun 2023 16:56:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AnzCNY2o5YhQSbNvVTww+NalEP1SJOEf1FOJFZBZN+bAudjNepcx4ZUpCgCgn1zSTfZfRlykCylJVN3X2CaWMNqa7xFTPBKJcofg50ofa97RDCrxkr2Im4Y7UiUuDMYQ0SnEZFPxMk+oetwZ5ncT9YcSAwtCrecGuNfSJeMLmeRDALkr7isxR6ouO4bgszs8PrW3B7Q2XH11UEWbrmRF8g+j+pqCcu7SQSQYJIyoe03s54C95sZWIDUcHa9LIxqn3vH1OnvrnHeGvgBXa8BVQwxqFiOyli6riM+v4is1nA2a5t1yJqO+lQ//cYzYgxUwxZ9+9Gp4YnJipzyqne+HEw== 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=VAczIqgFx2hTWhMkvPvyOwJLCXkcxgD6pD3uo9Cwn4M=; b=oMEzv4voc7C2d0bERutFdb2qxT/bPKqzkNgWiqIemUuRKLeD1bp/91slnDKFna7pUCKcO9V8/kqycqVvetqOYM5+4cE+GCvwbNii6dE3UylkZSPKS+OCL0OGruUSDUu1499MFh+4sxUSU2V2YYlvLQ+PYnB4Tv9pAd9fYycSMsT/ZMqHbQLRzEJWKFSXJkSCjRJAsySbe1IPUpcePmy7oB7Vv3WeTk3eSYlq9PIlUEwMmf9XRA0Pe7HJe6V1nLyfJIdiSPz3UvLp7aFSU95EBaPUMddJnJjo59Ora68THAkl+K5hGHQ6I05fja7amtfKMpJLjT+FWoorxXUoD/crbA== 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=VAczIqgFx2hTWhMkvPvyOwJLCXkcxgD6pD3uo9Cwn4M=; b=PsfvQwVcE3beBn5VRhM3bIN7jTTIDz8gy6JIyI/qCHsZih5MEYDZ/0Hf8UtD+jEurxvi/wFD/8Hiiub6hrkc2K+UfzE5PZK3UTjbmpD8FUn/cxuOXY7Z8nSvxMuyyTHINgeJQRCjHWkP8yBEUVQPmgkgnq1KQ/0K3u+PbA3KzcA= Received: from CYZPR10CA0021.namprd10.prod.outlook.com (2603:10b6:930:8a::14) by DM4PR12MB5842.namprd12.prod.outlook.com (2603:10b6:8:65::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6500.25; Wed, 21 Jun 2023 23:56:07 +0000 Received: from CY4PEPF0000E9CD.namprd03.prod.outlook.com (2603:10b6:930:8a:cafe::2d) by CYZPR10CA0021.outlook.office365.com (2603:10b6:930:8a::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.23 via Frontend Transport; Wed, 21 Jun 2023 23:56:06 +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 CY4PEPF0000E9CD.mail.protection.outlook.com (10.167.241.140) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6521.24 via Frontend Transport; Wed, 21 Jun 2023 23:56:06 +0000 Received: from ruby-95f9host.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.2507.23; Wed, 21 Jun 2023 18:56:01 -0500 From: Suravee Suthikulpanit To: , , CC: , , , , , , , , , , , , , , , "Suravee Suthikulpanit" Subject: [RFC PATCH 20/21] iommu/amd: Introduce vIOMMU ioctl for setting up guest CR3 Date: Wed, 21 Jun 2023 18:55:07 -0500 Message-ID: <20230621235508.113949-21-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230621235508.113949-1-suravee.suthikulpanit@amd.com> References: <20230621235508.113949-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: CY4PEPF0000E9CD:EE_|DM4PR12MB5842:EE_ X-MS-Office365-Filtering-Correlation-Id: d10155f6-2187-4aa4-72af-08db72b31458 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kZfYj/q2zEDQK2d3y2sSW7Fql3fozr/we5OP/QrgnTVvStpGVU3W9kRq5A6ZkPr3V4kdWT69lnf7WxF3YVeAUftSvs4xvYkLT1c0rrmq12VbsRRO8OvwAJzyr9vWfsSsdzukI2CO4w/5Q2gVAhFkr5PiJtig4cT+w1fvnzulYfeq5ta+KZe57khjDaOSVO9iKpKHqppYXGYM87RKc3aevjy/dWy9a2WG6bYzALUjiP324nv0Dw2uWSM/LB3GALVvad1YG1UK4bilQbLt5RYvkhBNyHjNRUdcmFwvkIIN0cZWvoZcjdQBsGCWYFCZQJ6I5znYfb2Mpxj6yiiormnMf/SkkARexS7YUgHFU0GbNxoi6ySDL/jiTYb4YN9e+np8g8b8TC5JyQrHhF37zj0cZzWpFe3NCySNHR4E4QTB/DZTdBj8QW6FKmD+2OV1X29h3sc4yMIckhTH9QjpR4xbqdkVqdzgZyxSNPJVaZ9cOaGtlApEkxj0eUW96jnEfHPzTUTQxwqmbVMGghi9vbvgdCbqj7UKnJuj5B2j/3iDn05rQzEAJi9UhQ1o990CUP+SK18cwO65Wmjfg6cjBbOMj07xIUdMwph72zMVShUtigjuJjFzwKUuBrOcLm1payWQYm/9xuZpvk5LtK8Z5QDx4yixVrYb/p4HNRHo6MwF5roGh6izZ4+Nk9DMAuBejQB97s7PrS4wF/WyL0ro8IFbnlfZQshbJMm2OHr05KW+AVgyIoiB14ndYw+Pew1PLobHQ855hKroxNO1abLEfqMaNw== 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:(13230028)(4636009)(396003)(39860400002)(376002)(136003)(346002)(451199021)(36840700001)(40470700004)(46966006)(478600001)(36756003)(16526019)(1076003)(26005)(186003)(40460700003)(40480700001)(2906002)(7696005)(316002)(44832011)(41300700001)(82310400005)(356005)(8936002)(81166007)(5660300002)(8676002)(7416002)(86362001)(82740400003)(110136005)(426003)(336012)(54906003)(83380400001)(2616005)(47076005)(4326008)(70206006)(70586007)(36860700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jun 2023 23:56:06.8016 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d10155f6-2187-4aa4-72af-08db72b31458 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: CY4PEPF0000E9CD.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5842 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=no 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?1769360240783101337?= X-GMAIL-MSGID: =?utf-8?q?1769360240783101337?= This ioctl interface sets up guest CR3 (gCR3) table, which is defined by guest IOMMU driver. It also enables nested I/O page translation in the host. Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/amd_iommu.h | 12 ++++ drivers/iommu/amd/iommu.c | 107 ++++++++++++++++++++++++++++++++++ drivers/iommu/amd/viommu.c | 36 ++++++++++++ include/linux/iommu.h | 1 + include/uapi/linux/iommufd.h | 20 +++++++ 5 files changed, 176 insertions(+) diff --git a/drivers/iommu/amd/amd_iommu.h b/drivers/iommu/amd/amd_iommu.h index fccae07e8c9f..463cd59127b7 100644 --- a/drivers/iommu/amd/amd_iommu.h +++ b/drivers/iommu/amd/amd_iommu.h @@ -84,6 +84,18 @@ extern void amd_iommu_domain_flush_tlb_pde(struct protection_domain *domain); extern int amd_iommu_flush_tlb(struct iommu_domain *dom, u32 pasid); extern int amd_iommu_domain_set_gcr3(struct iommu_domain *dom, u32 pasid, unsigned long cr3); +extern int amd_viommu_user_gcr3_update(const void *user_data, + struct iommu_domain *udom); +extern int amd_iommu_setup_gcr3_table(struct amd_iommu *iommu, + struct pci_dev *pdev, + struct iommu_domain *dom, + struct iommu_domain *udom, + int pasids, bool giov); +extern int amd_iommu_user_set_gcr3(struct amd_iommu *iommu, + struct iommu_domain *dom, + struct iommu_domain *udom, + struct pci_dev *pdev, u32 pasid, + unsigned long cr3); extern int amd_iommu_domain_clear_gcr3(struct iommu_domain *dom, u32 pasid); extern void amd_iommu_iotlb_sync(struct iommu_domain *domain, struct iommu_iotlb_gather *gather); diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index f22b2a5a8bfc..bff53977f8f7 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -80,6 +80,8 @@ struct kmem_cache *amd_iommu_irq_cache; static void detach_device(struct device *dev); static int domain_enable_v2(struct protection_domain *domain, int pasids, bool giov); +static int __set_gcr3(struct protection_domain *domain, u32 pasid, + unsigned long cr3); /**************************************************************************** * @@ -2525,10 +2527,43 @@ static void *amd_iommu_hw_info(struct device *dev, u32 *length) return hwinfo; } +static struct iommu_domain * +amd_iommu_domain_alloc_user(struct device *dev, + enum iommu_hwpt_type hwpt_type, + struct iommu_domain *parent, + const union iommu_domain_user_data *user_data) +{ + int ret; + struct iommu_domain *dom = iommu_domain_alloc(dev->bus); + + if (!dom || !parent) + return dom; + + /* + * The parent is not null only when external driver calls IOMMUFD kAPI + * to create IOMMUFD_OBJ_HW_PAGETABLE to attach a bound device to IOAS. + * This is for nested (v2) page table. + * + * TODO: Currently, only support nested table w/ 1 pasid for GIOV use case. + * Add support for multiple pasids. + */ + dom->type = IOMMU_DOMAIN_NESTED; + + ret = amd_viommu_user_gcr3_update(user_data, dom); + if (ret) + goto err_out; + + return dom; +err_out: + iommu_domain_free(dom); + return NULL; +} + const struct iommu_ops amd_iommu_ops = { .capable = amd_iommu_capable, .hw_info = amd_iommu_hw_info, .domain_alloc = amd_iommu_domain_alloc, + .domain_alloc_user = amd_iommu_domain_alloc_user, .probe_device = amd_iommu_probe_device, .release_device = amd_iommu_release_device, .probe_finalize = amd_iommu_probe_finalize, @@ -2537,6 +2572,7 @@ const struct iommu_ops amd_iommu_ops = { .is_attach_deferred = amd_iommu_is_attach_deferred, .pgsize_bitmap = AMD_IOMMU_PGSIZES, .def_domain_type = amd_iommu_def_domain_type, + .hw_info_type = IOMMU_HW_INFO_TYPE_AMD, .default_domain_ops = &(const struct iommu_domain_ops) { .attach_dev = amd_iommu_attach_device, .map_pages = amd_iommu_map_pages, @@ -2639,6 +2675,77 @@ int amd_iommu_domain_enable_v2(struct iommu_domain *dom, int pasids, bool giov) } EXPORT_SYMBOL(amd_iommu_domain_enable_v2); +int amd_iommu_setup_gcr3_table(struct amd_iommu *iommu, struct pci_dev *pdev, + struct iommu_domain *dom, + struct iommu_domain *udom, + int pasids, bool giov) +{ + int levels; + struct protection_domain *pdom = to_pdomain(dom); + struct protection_domain *updom = to_pdomain(udom); + struct iommu_dev_data *dev_data = dev_iommu_priv_get(&pdev->dev); + + if (updom->gcr3_tbl) + return -EINVAL; + + /* Number of GCR3 table levels required */ + for (levels = 0; (pasids - 1) & ~0x1ff; pasids >>= 9) + levels += 1; + + if (levels > amd_iommu_max_glx_val) + return -EINVAL; + + updom->gcr3_tbl = (void *)get_zeroed_page(GFP_ATOMIC); + if (updom->gcr3_tbl == NULL) + return -ENOMEM; + + updom->glx = levels; + updom->flags |= PD_IOMMUV2_MASK; + if (giov) + updom->flags |= PD_GIOV_MASK; + + set_dte_entry(iommu, dev_data->devid, pdom, updom, + updom->gcr3_tbl, + dev_data->ats.enabled, false); + clone_aliases(iommu, dev_data->dev); + + iommu_flush_dte(iommu, dev_data->devid); + iommu_completion_wait(iommu); + return 0; +} + +/* + * Note: For vIOMMU, the guest could be using different + * GCR3 table for each VFIO pass-through device. + * Therefore, we need to per-device GCR3 table. + */ +int amd_iommu_user_set_gcr3(struct amd_iommu *iommu, + struct iommu_domain *dom, + struct iommu_domain *udom, + struct pci_dev *pdev, u32 pasid, + unsigned long cr3) +{ + struct iommu_dev_data *dev_data = dev_iommu_priv_get(&pdev->dev); + struct protection_domain *domain = to_pdomain(dom); + struct protection_domain *udomain = to_pdomain(udom); + unsigned long flags; + int ret; + + spin_lock_irqsave(&domain->lock, flags); + spin_lock_irqsave(&udomain->lock, flags); + + ret = __set_gcr3(udomain, pasid, cr3); + if (!ret) { + device_flush_dte(dev_data); + iommu_completion_wait(iommu); + } + + spin_unlock_irqrestore(&udomain->lock, flags); + spin_unlock_irqrestore(&domain->lock, flags); + + return ret; +} + static int __flush_pasid(struct protection_domain *domain, u32 pasid, u64 address, bool size) { diff --git a/drivers/iommu/amd/viommu.c b/drivers/iommu/amd/viommu.c index 1bd4282384c4..8ce3ee3d6bf5 100644 --- a/drivers/iommu/amd/viommu.c +++ b/drivers/iommu/amd/viommu.c @@ -1072,3 +1072,39 @@ int amd_viommu_cmdbuf_update(struct amd_viommu_cmdbuf_data *data) return -EINVAL; } EXPORT_SYMBOL(amd_viommu_cmdbuf_update); + +int amd_viommu_user_gcr3_update(const void *user_data, struct iommu_domain *udom) +{ + int ret; + struct pci_dev *pdev; + unsigned long npinned; + struct page *pages[2]; + struct iommu_domain *dom; + struct iommu_hwpt_amd_v2 *hwpt = (struct iommu_hwpt_amd_v2 *)user_data; + struct amd_iommu *iommu = get_amd_iommu_from_devid(hwpt->iommu_id); + u16 hdev_id = viommu_get_hdev_id(iommu, hwpt->gid, hwpt->gdev_id); + + pr_debug("%s: gid=%u, hdev_id=%#x, gcr3_va=%#llx\n", + __func__, hwpt->gid, hdev_id, (unsigned long long) hwpt->gcr3_va); + + npinned = get_user_pages_fast(hwpt->gcr3_va, 1, FOLL_WRITE, pages); + if (!npinned) { + pr_err("Failure locking grc3 page (%#llx).\n", hwpt->gcr3_va); + return -EINVAL; + } + + /* Allocate gcr3 table */ + pdev = pci_get_domain_bus_and_slot(0, PCI_BUS_NUM(hdev_id), + hdev_id & 0xff); + dom = iommu_get_domain_for_dev(&pdev->dev); + if (!dom) + return -EINVAL; + + /* TODO: Only support 1 pasid (zero) for now */ + ret = amd_iommu_setup_gcr3_table(iommu, pdev, dom, udom, 1, + iommu_feature(iommu, FEATURE_GIOSUP)); + if (ret) + pr_err("%s: Fail to enable gcr3 (devid=%#x)\n", __func__, pci_dev_id(pdev)); + + return amd_iommu_user_set_gcr3(iommu, dom, udom, pdev, 0, hwpt->gcr3); +} diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 4116f12d5f97..9239cd01d77c 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -236,6 +236,7 @@ union iommu_domain_user_data { #endif struct iommu_hwpt_vtd_s1 vtd; struct iommu_hwpt_arm_smmuv3 smmuv3; + struct iommu_hwpt_amd_v2 amdv2; }; /** diff --git a/include/uapi/linux/iommufd.h b/include/uapi/linux/iommufd.h index f8ea9faf6770..4147171429e1 100644 --- a/include/uapi/linux/iommufd.h +++ b/include/uapi/linux/iommufd.h @@ -408,6 +408,23 @@ struct iommu_hwpt_arm_smmuv3 { __aligned_u64 out_event_uptr; }; +/** + * struct iommu_hwpt_amd_v2 - AMD IOMMU specific user-managed + * v2 I/O page table data + * @gcr3: GCR3 guest physical ddress + * @gcr3_va: GCR3 host virtual address + * @gid: Guest ID + * @iommu_id: IOMMU host device ID + * @gdev_id: Guest device ID + */ +struct iommu_hwpt_amd_v2 { + __u64 gcr3; + __u64 gcr3_va; + __u32 gid; + __u32 iommu_id; + __u16 gdev_id; +}; + /** * enum iommu_hwpt_type - IOMMU HWPT Type * @IOMMU_HWPT_TYPE_DEFAULT: default @@ -418,6 +435,7 @@ enum iommu_hwpt_type { IOMMU_HWPT_TYPE_DEFAULT, IOMMU_HWPT_TYPE_VTD_S1, IOMMU_HWPT_TYPE_ARM_SMMUV3, + IOMMU_HWPT_TYPE_AMD_V2, }; /** @@ -523,11 +541,13 @@ struct iommu_hw_info_amd { * enum iommu_hw_info_type - IOMMU Hardware Info Types * @IOMMU_HW_INFO_TYPE_INTEL_VTD: Intel VT-d iommu info type * @IOMMU_HW_INFO_TYPE_ARM_SMMUV3: ARM SMMUv3 iommu info type + * @IOMMU_HW_INFO_TYPE_AMD: AMD IOMMU info type */ enum iommu_hw_info_type { IOMMU_HW_INFO_TYPE_NONE, IOMMU_HW_INFO_TYPE_INTEL_VTD, IOMMU_HW_INFO_TYPE_ARM_SMMUV3, + IOMMU_HW_INFO_TYPE_AMD, }; /** From patchwork Wed Jun 21 23:55:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suravee Suthikulpanit X-Patchwork-Id: 111357 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp4723653vqr; Wed, 21 Jun 2023 17:01:47 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5RWv0TxMW7HjcWsFCGMyvT0d2pNbZ9Ecp3ZAgxkcHiewk9vUwI41nZLSRgQVr8v4Tg4F+T X-Received: by 2002:a17:903:41d1:b0:1b3:d5ec:673a with SMTP id u17-20020a17090341d100b001b3d5ec673amr13202886ple.33.1687392107035; Wed, 21 Jun 2023 17:01:47 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1687392107; cv=pass; d=google.com; s=arc-20160816; b=jOX03mzYh+9WqnETwnqExziSJQsngpU0tppNE4KFrst3MMZfuazlYgU8cuCMO0jP6n ASwspgI5G51MZCrpLKlUICzdKrk1jS+RoWwuF4lKjl5wF3KKrvlWUpKzL20a6+g2Ak26 MZztDL5fUECTASGw/CExzJP7/jXmaMo2L9sywH3PyOKxmLgynIjmuATAkPgSUmoSSQhz PMnmxNbYc9eyjemNfys2BwZs5tLAOY8TPglXNRlJ0XsmQjU2ejBKs3tUu/mKj3uObGOj 8k+JJzQzBsuxPV/naQ1g0YKe0WmJ33/NeuLohgTX34v6+Wv2oXM5YpWryUYJfHixYKkc 6s7Q== 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=wdQMrgOTXfgV72RZpei832Z4XyMWSKHyjQtp0oqj+xw=; b=AidUsRSw1Tiq3UXQpM8iUHuz0PkHVdouRBCZ1aaeBAmNhUUH9Ssi7LbongvCI8j9KR rCp3Ds1yfioaizRhfSBGB/b3PbBADyLmDukLN12qwf1FTkXAxKKa3PP2oZvRNSvwkJXm J2gLj4DtpP6aWWkH5I0JDFh5ngK3CCrP7K/sYFr0rMjD4IPlR2XY6/OrO0/0Objlb5HS Ne/r2z4nCKNxo1PQDlfgG7SN2sQfVnEsgb6IDd6TQPWnHWHovlijCvGVuuYR5D1zB3x+ YaPHtVgryE5LruuO1+9w1MCz4znWmfcejZi4oZ80RqvsItrE4nqSumSp+yWsD+V+Xb2P opGQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=xMSY3TlT; 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 j17-20020a170902da9100b001a963979936si2867532plx.153.2023.06.21.17.01.33; Wed, 21 Jun 2023 17:01:47 -0700 (PDT) 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=xMSY3TlT; 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 S230387AbjFUX54 (ORCPT + 99 others); Wed, 21 Jun 2023 19:57:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230272AbjFUX5L (ORCPT ); Wed, 21 Jun 2023 19:57:11 -0400 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2055.outbound.protection.outlook.com [40.107.220.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8F1C268C; Wed, 21 Jun 2023 16:56:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CbBS6Lixh5nIfZDdspesuU9ejdwEfggKKGnEMyfdJh7FHzUnnNT0MdsCnDtQCj7Xb3+/MDOPVLxi7cBXG8FmYqTp3mPiXDdeFmpYeuGNhceTj255EWbo8rIal3ylhFI6Uu/v9Pa6t0wLf90CW0TTGCAbaFPgDYnbZz1iy3GBl+itqTaZz1jyLGwGsAsFmFXEJmbGmHdH2lmVTiBnCbgT0+ID7a3ppsdWm+pRcH9Clv1llDGEyMd/SQIcC5lipiiBpzhQh3xyWIm8G4v3KpfswQTJutWM99XbF63rfCALIWCCHQc7B1mT0nBYXR85AytFqa1mSCT22CsaIiF2mbge4Q== 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=wdQMrgOTXfgV72RZpei832Z4XyMWSKHyjQtp0oqj+xw=; b=kvKOLLQWIAFMIA1HtQ13vnJZycphsT9z4YA8CMqj8BTImFFMNY75r7JIE7l9YNMZ0odQlMp/sNozuNDBmL1GiSWpaQqTxHHAElq1+GoByCL1huTLCtQl23YevT+vTaGirVmqzu9XR5zfmzANPorrc867t9bzl0WmflJQwH0xqtQ0E77NLUADkSPsR3xsERXxKKyVjVl4cFo250+DZFOz7M0xouHu21Ko8VHGqxfpNqRdTq+VH+sKh+ILnOfw/lhWcFTF1zinxmC5mUDYpPG4fZTZkZUDnXQib323LKSI0jVKMUfLOGnhvs6w9QrsJxhIWMmxv9iKS0gZcF0KFRW4zw== 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=wdQMrgOTXfgV72RZpei832Z4XyMWSKHyjQtp0oqj+xw=; b=xMSY3TlT8x+PCtElLwfpEl1IA2FANM2Iq39x614KaemLdE1W6BtFyfedJfhi9ty16NJdO503bq9FJLWmH7y5ws5wXrO5Sej9QYNvIKnhA832eQwfZZF1IfvUgPObyfm4rwZ5CXxfqrpN+Bs67GteesmOkpcN+kQWvTRXeg4oX7I= Received: from CYZPR10CA0008.namprd10.prod.outlook.com (2603:10b6:930:8a::18) by PH7PR12MB6812.namprd12.prod.outlook.com (2603:10b6:510:1b6::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.23; Wed, 21 Jun 2023 23:56:07 +0000 Received: from CY4PEPF0000E9CD.namprd03.prod.outlook.com (2603:10b6:930:8a:cafe::e4) by CYZPR10CA0008.outlook.office365.com (2603:10b6:930:8a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.23 via Frontend Transport; Wed, 21 Jun 2023 23:56:07 +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 CY4PEPF0000E9CD.mail.protection.outlook.com (10.167.241.140) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6521.24 via Frontend Transport; Wed, 21 Jun 2023 23:56:07 +0000 Received: from ruby-95f9host.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.2507.23; Wed, 21 Jun 2023 18:56:02 -0500 From: Suravee Suthikulpanit To: , , CC: , , , , , , , , , , , , , , , "Suravee Suthikulpanit" Subject: [RFC PATCH 21/21] iommufd: Introduce AMD HW-vIOMMU IOCTL Date: Wed, 21 Jun 2023 18:55:08 -0500 Message-ID: <20230621235508.113949-22-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230621235508.113949-1-suravee.suthikulpanit@amd.com> References: <20230621235508.113949-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: CY4PEPF0000E9CD:EE_|PH7PR12MB6812:EE_ X-MS-Office365-Filtering-Correlation-Id: 7213e5fa-480b-4a71-3491-08db72b3149b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nemnw003TM6NrfSHZUQqKMi1p4t+51nk25Hw9wpP1bTVSgFs+tw60mNJ7t1yC/DHtGqBG3u4u2x2RlEyKq6LiICdXIwDeFo4mnS917VqMoUOtWQgnWZtq6deHHVVHGwToFd+csr04qhzEJniX0p1X/2RfBNqd78agX9g239KXZdPm0QBZNGcoDfFkG4xt0KEiZqx33KxONggBp3FFEYdNZmCLQP/dpcKwU9EdbtOlh3jntQBA/B98lyQGHIsPdJxsYKVIkSDNZFFxkYLo47R9Q0soOxclr/NZ60aN0kfkPGVgay/9CuUyabShE2iOFgtbaz7o1HWxer9tywaKXu822X/5sJvQKnuTDO4REIUbOztYVrpq9MTLO/jK3f5wiuwpSv7TzcIcyINBfWoUezx2gYcK9BAFiiZxtEabxH0D+jpqxMACHUDPzQB67U3DtK7S2v4ENyPRO7Md4MHTV+QQ7IW+QzJOutSDlphoUlFB0proI2zki8kh4oWYltPINMqucc68xAzlIf/GvX84oGdt3w+YWKTGLuUV8l2e0zRkkC15Fq2YHPIBERhRKJQVjOY7v1A50xfjzITyGaqQWxSGOxTBNzHrDFxtb7E7Q/PinXl3U2hGPfwwQsWagBs363P5M5QNha+SvVIk1XKhgFcGGE84OUIecTu9dM9gwzHzc8+noUi/bFu793nsIQmces72LO7XT7OImYruYE+S/DrXQ4c8btnrTyk/4o0bOBeDcq6Bp+/1lQelrQDYZHhO7tX8pm3Quq0r1DeFF/1ZV5SAQ== 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:(13230028)(4636009)(346002)(396003)(39860400002)(376002)(136003)(451199021)(36840700001)(46966006)(40470700004)(7696005)(478600001)(36860700001)(82310400005)(36756003)(47076005)(16526019)(83380400001)(426003)(336012)(2616005)(86362001)(186003)(81166007)(40480700001)(356005)(82740400003)(1076003)(40460700003)(26005)(8936002)(8676002)(41300700001)(7416002)(44832011)(5660300002)(2906002)(110136005)(54906003)(316002)(70586007)(70206006)(4326008)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jun 2023 23:56:07.2547 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7213e5fa-480b-4a71-3491-08db72b3149b 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: CY4PEPF0000E9CD.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6812 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=no 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?1769358866133032842?= X-GMAIL-MSGID: =?utf-8?q?1769358866133032842?= Add support for AMD HW-vIOMMU in the iommufd /dev/iommu devfs. Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/iommufd/Makefile | 3 +- drivers/iommu/iommufd/amd_viommu.c | 158 +++++++++++++++++++++++++++++ drivers/iommu/iommufd/main.c | 17 ++-- include/linux/amd-viommu.h | 26 +++++ include/linux/iommufd.h | 8 ++ 5 files changed, 203 insertions(+), 9 deletions(-) create mode 100644 drivers/iommu/iommufd/amd_viommu.c create mode 100644 include/linux/amd-viommu.h diff --git a/drivers/iommu/iommufd/Makefile b/drivers/iommu/iommufd/Makefile index 8aeba81800c5..84d771c9cfba 100644 --- a/drivers/iommu/iommufd/Makefile +++ b/drivers/iommu/iommufd/Makefile @@ -6,7 +6,8 @@ iommufd-y := \ ioas.o \ main.o \ pages.o \ - vfio_compat.o + vfio_compat.o \ + amd_viommu.o iommufd-$(CONFIG_IOMMUFD_TEST) += selftest.o diff --git a/drivers/iommu/iommufd/amd_viommu.c b/drivers/iommu/iommufd/amd_viommu.c new file mode 100644 index 000000000000..1836e19cb37d --- /dev/null +++ b/drivers/iommu/iommufd/amd_viommu.c @@ -0,0 +1,158 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2023 Advanced Micro Devices, Inc. + * Author: Suravee Suthikulpanit + */ + +#include +#include +#include +#include +#include + +#include "iommufd_private.h" + +union amd_viommu_ucmd_buffer { + struct amd_viommu_iommu_info iommu; + struct amd_viommu_dev_info dev; + struct amd_viommu_dom_info dom; + struct amd_viommu_mmio_data mmio; + struct amd_viommu_cmdbuf_data cmdbuf; +}; + +#define IOCTL_OP(_ioctl, _fn, _struct, _last) \ + [_IOC_NR(_ioctl) - IOMMUFD_VIOMMU_CMD_BASE] = { \ + .size = sizeof(_struct) + \ + BUILD_BUG_ON_ZERO(sizeof(union amd_viommu_ucmd_buffer) < \ + sizeof(_struct)), \ + .min_size = offsetofend(_struct, _last), \ + .ioctl_num = _ioctl, \ + .execute = _fn, \ + } + +int viommu_iommu_init(struct iommufd_ucmd *ucmd) +{ + int ret; + struct amd_viommu_iommu_info *data = ucmd->cmd; + + ret = amd_viommu_iommu_init(data); + if (ret) + return ret; + + if (copy_to_user(ucmd->ubuffer, data, sizeof(*data))) + ret = -EFAULT; + return ret; +} + +int viommu_iommu_destroy(struct iommufd_ucmd *ucmd) +{ + struct amd_viommu_iommu_info *data = ucmd->cmd; + + return amd_viommu_iommu_destroy(data); +} + +int viommu_domain_attach(struct iommufd_ucmd *ucmd) +{ + struct amd_viommu_dom_info *data = ucmd->cmd; + + return amd_viommu_domain_update(data, true); +} + +int viommu_domain_detach(struct iommufd_ucmd *ucmd) +{ + struct amd_viommu_dom_info *data = ucmd->cmd; + + return amd_viommu_domain_update(data, false); +} + +int viommu_device_attach(struct iommufd_ucmd *ucmd) +{ + struct amd_viommu_dev_info *data = ucmd->cmd; + + return amd_viommu_device_update(data, true); +} + +int viommu_device_detach(struct iommufd_ucmd *ucmd) +{ + struct amd_viommu_dev_info *data = ucmd->cmd; + + return amd_viommu_device_update(data, false); +} + +int viommu_mmio_access(struct iommufd_ucmd *ucmd) +{ + int ret; + struct amd_viommu_mmio_data *data = ucmd->cmd; + + if (data->is_write) { + ret = amd_viommu_guest_mmio_write(data); + } else { + ret = amd_viommu_guest_mmio_read(data); + if (ret) + return ret; + + if (copy_to_user(ucmd->ubuffer, data, sizeof(*data))) + ret = -EFAULT; + } + return ret; +} + +int viommu_cmdbuf_update(struct iommufd_ucmd *ucmd) +{ + struct amd_viommu_cmdbuf_data *data = ucmd->cmd; + + return amd_viommu_cmdbuf_update(data); +} + +struct iommufd_ioctl_op viommu_ioctl_ops[] = { + IOCTL_OP(VIOMMU_IOMMU_INIT, viommu_iommu_init, + struct amd_viommu_iommu_info, gid), + IOCTL_OP(VIOMMU_IOMMU_DESTROY, viommu_iommu_destroy, + struct amd_viommu_iommu_info, gid), + IOCTL_OP(VIOMMU_DEVICE_ATTACH, viommu_device_attach, + struct amd_viommu_dev_info, queue_id), + IOCTL_OP(VIOMMU_DEVICE_DETACH, viommu_device_detach, + struct amd_viommu_dev_info, queue_id), + IOCTL_OP(VIOMMU_DOMAIN_ATTACH, viommu_domain_attach, + struct amd_viommu_dom_info, gdom_id), + IOCTL_OP(VIOMMU_DOMAIN_DETACH, viommu_domain_detach, + struct amd_viommu_dom_info, gdom_id), + IOCTL_OP(VIOMMU_MMIO_ACCESS, viommu_mmio_access, + struct amd_viommu_mmio_data, is_write), + IOCTL_OP(VIOMMU_CMDBUF_UPDATE, viommu_cmdbuf_update, + struct amd_viommu_cmdbuf_data, hva), +}; + +long iommufd_amd_viommu_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) +{ + struct iommufd_ctx *ictx = filp->private_data; + struct iommufd_ucmd ucmd = {}; + struct iommufd_ioctl_op *op; + union amd_viommu_ucmd_buffer buf; + unsigned int nr; + int ret; + + nr = _IOC_NR(cmd); + if (nr < IOMMUFD_VIOMMU_CMD_BASE || + (nr - IOMMUFD_VIOMMU_CMD_BASE) >= ARRAY_SIZE(viommu_ioctl_ops)) + return -ENOIOCTLCMD; + + ucmd.ictx = ictx; + ucmd.ubuffer = (void __user *)arg; + ret = get_user(ucmd.user_size, (u32 __user *)ucmd.ubuffer); + if (ret) + return ret; + + op = &viommu_ioctl_ops[nr - IOMMUFD_VIOMMU_CMD_BASE]; + if (op->ioctl_num != cmd) + return -ENOIOCTLCMD; + if (ucmd.user_size < op->min_size) + return -EOPNOTSUPP; + + ucmd.cmd = &buf; + ret = copy_struct_from_user(ucmd.cmd, op->size, ucmd.ubuffer, + ucmd.user_size); + if (ret) + return ret; + return op->execute(&ucmd); +} diff --git a/drivers/iommu/iommufd/main.c b/drivers/iommu/iommufd/main.c index 83f8b8f19bcb..d5c2738a8355 100644 --- a/drivers/iommu/iommufd/main.c +++ b/drivers/iommu/iommufd/main.c @@ -17,6 +17,8 @@ #include #include #include +#include +#include #include "../iommu-priv.h" #include "io_pagetable.h" @@ -442,13 +444,6 @@ union ucmd_buffer { struct iommu_hwpt_arm_smmuv3_invalidate smmuv3; }; -struct iommufd_ioctl_op { - unsigned int size; - unsigned int min_size; - unsigned int ioctl_num; - int (*execute)(struct iommufd_ucmd *ucmd); -}; - #define IOCTL_OP(_ioctl, _fn, _struct, _last) \ [_IOC_NR(_ioctl) - IOMMUFD_CMD_BASE] = { \ .size = sizeof(_struct) + \ @@ -503,8 +498,14 @@ static long iommufd_fops_ioctl(struct file *filp, unsigned int cmd, nr = _IOC_NR(cmd); if (nr < IOMMUFD_CMD_BASE || - (nr - IOMMUFD_CMD_BASE) >= ARRAY_SIZE(iommufd_ioctl_ops)) + (nr - IOMMUFD_CMD_BASE) >= ARRAY_SIZE(iommufd_ioctl_ops)) { + /* AMD VIOMMU ioctl */ + if (!iommufd_amd_viommu_ioctl(filp, cmd, arg)) + return 0; + + /* VFIO ioctl */ return iommufd_vfio_ioctl(ictx, cmd, arg); + } ucmd.ictx = ictx; ucmd.ubuffer = (void __user *)arg; diff --git a/include/linux/amd-viommu.h b/include/linux/amd-viommu.h new file mode 100644 index 000000000000..645e25c493c2 --- /dev/null +++ b/include/linux/amd-viommu.h @@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (C) 2022 Advanced Micro Devices, Inc. + */ + +#ifndef _LINUX_AMD_VIOMMU_H +#define _LINUX_AMD_VIOMMU_H + +#include + +extern long iommufd_amd_viommu_ioctl(struct file *filp, + unsigned int cmd, + unsigned long arg); + +extern long iommufd_viommu_ioctl(struct file *filp, unsigned int cmd, + unsigned long arg); + +extern int amd_viommu_iommu_init(struct amd_viommu_iommu_info *data); +extern int amd_viommu_iommu_destroy(struct amd_viommu_iommu_info *data); +extern int amd_viommu_domain_update(struct amd_viommu_dom_info *data, bool is_set); +extern int amd_viommu_device_update(struct amd_viommu_dev_info *data, bool is_set); +extern int amd_viommu_guest_mmio_write(struct amd_viommu_mmio_data *data); +extern int amd_viommu_guest_mmio_read(struct amd_viommu_mmio_data *data); +extern int amd_viommu_cmdbuf_update(struct amd_viommu_cmdbuf_data *data); + +#endif /* _LINUX_AMD_VIOMMU_H */ diff --git a/include/linux/iommufd.h b/include/linux/iommufd.h index 9269ce668d9b..91912e044038 100644 --- a/include/linux/iommufd.h +++ b/include/linux/iommufd.h @@ -17,6 +17,14 @@ struct iommufd_ctx; struct iommufd_access; struct file; struct iommu_group; +struct iommufd_ucmd; + +struct iommufd_ioctl_op { + unsigned int size; + unsigned int min_size; + unsigned int ioctl_num; + int (*execute)(struct iommufd_ucmd *ucmd); +}; struct iommufd_device *iommufd_device_bind(struct iommufd_ctx *ictx, struct device *dev, u32 *id);