Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp1954161rdf; Sun, 5 Nov 2023 23:16:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IHskISKyTxzzBGcz3g12FmI5P5JE2ggSlLqkLI8wC53qL62pQQZdfzE1LeMRgnKnEL1/QSC X-Received: by 2002:a05:6a20:a10e:b0:15c:b7ba:1671 with SMTP id q14-20020a056a20a10e00b0015cb7ba1671mr13586852pzk.2.1699254974606; Sun, 05 Nov 2023 23:16:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699254974; cv=none; d=google.com; s=arc-20160816; b=MkVTn/GXy+lNclpC6rtMmsgPnQEma0NgZgCMSzOYt9QJVA2IORcMV0q87j8Ur0OUgW P4Qa8kThH3YcAjcIWIvLh06l99+uZeINi/zZC0juphotb8Z/zh6hPCKyspGqtNPne/NV 4RAUwzU5j4c8q6m1vZgAIJg66yLztFAaTnWLjPz0LEZvmXgIly+R0wUwRIw65uqdgbXc GHOOaLqGk2tP1DvyNGGLjl0bV+c3lyyGJ2MdFqI2+tC7RCc4GA38F0axMjrgfTF6UHEX KcdOIe3jd8tdtPzzrTIpBKUkzwaJuJzSjVdBJ/2s47yKeNFgZVHTEFIc6TPJujVWO2zn /d4g== ARC-Message-Signature: i=1; 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=VPARBhx4V2Q4IIVegwniKg9++M5XesASdaSiFU6LguY=; fh=Q9/c0/1s/r5nQXfLb7W3lFTON2d/CYIL48MtbxJzpb8=; b=viTKl/fKV6ihdZ3OZ1O01YCNXD8l+EorosSVkiIywHD6wqEsDLchdd3/H2kr7l6xns XXwro1UGY34Emel2hIsKUDzxgDqtvy/4FmvzYinJJnm1k70WwjPUGCyNHTI0CgZb+4ne srIdk0ekOm5dfRao1so/r+xpxFbTjbh1Fpna0Z1u7MIflu0fmYY8nd0lRtyW9/yzH7dq TEZ0AzeNG2NYN8iWwEmob8N+cyQ2DkYV4+AcDCtnu/L58P3Jtp+6N92TZYos2g+UWqqT F7phcDJtAu+FMg4mQs26ctyAwpHKnQcGJszVlpLISC8UvUyB1r9nXaBBiaElSsMsGnkW aQTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Pdvq3G9o; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id d7-20020a056a00244700b006be036f04dasi7772613pfj.225.2023.11.05.23.16.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Nov 2023 23:16:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Pdvq3G9o; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 034C880A237F; Sun, 5 Nov 2023 23:16:12 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229755AbjKFHQB (ORCPT + 99 others); Mon, 6 Nov 2023 02:16:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230527AbjKFHOO (ORCPT ); Mon, 6 Nov 2023 02:14:14 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4311AD69 for ; Sun, 5 Nov 2023 23:14:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1699254851; x=1730790851; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=JXrcRndberQgWoGawVfq93WylWTuPjjrsB1zsCyDKUk=; b=Pdvq3G9oshsK/10S7GAfl+yak1B80KtayzriiEpXy+JD8IR8QmZarkj+ 1GooCPhIB0OoS04T0mB9PgJoaiPGjdxWCEoT714ujaABCR369/0Evj3Ot A6MnCHgwx0t3GrcK330ROjNsjD6c7fYeT6XIxmiz/1CrjRZARBWjWCC/F Mrmk/5YXn9vRQkQodY26VRH2ASWb085Jw5ywtk4u4mFouRIHK8XED0xkC Dt+Llx2haVlsbuGO4C1kRhn6iHg96ZfjGrNc8EjSupLwBZJE+ZgCSDE2C +jShQeNsmNGjCh/oAOKLYu4UIjZm22lBTFQFWAToT7oxcPkCyI+jVCdXH Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10885"; a="10759075" X-IronPort-AV: E=Sophos;i="6.03,280,1694761200"; d="scan'208";a="10759075" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Nov 2023 23:14:11 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10885"; a="1093690912" X-IronPort-AV: E=Sophos;i="6.03,280,1694761200"; d="scan'208";a="1093690912" Received: from sqa-gate.sh.intel.com (HELO localhost.localdomain) ([10.239.48.212]) by fmsmga005.fm.intel.com with ESMTP; 05 Nov 2023 23:14:07 -0800 From: Tina Zhang To: Jean-Philippe Brucker , Kevin Tian , Lu Baolu , joro@8bytes.org, will@kernel.org, Yi Liu Cc: virtualization@lists.linux-foundation.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Tina Zhang Subject: [RFC PATCH 5/5] iommu/virtio-iommu: Support attaching VT-d IO pgtable Date: Mon, 6 Nov 2023 02:12:26 -0500 Message-Id: <20231106071226.9656-6-tina.zhang@intel.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20231106071226.9656-1-tina.zhang@intel.com> References: <20231106071226.9656-1-tina.zhang@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.4 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Sun, 05 Nov 2023 23:16:12 -0800 (PST) Add VT-d IO page table support to ATTACH_TABLE request. Signed-off-by: Tina Zhang --- drivers/iommu/virtio-iommu.c | 23 +++++++++++++++++++++++ include/uapi/linux/virtio_iommu.h | 26 ++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/drivers/iommu/virtio-iommu.c b/drivers/iommu/virtio-iommu.c index b1ceaac974e2..b02eeb1d27a4 100644 --- a/drivers/iommu/virtio-iommu.c +++ b/drivers/iommu/virtio-iommu.c @@ -991,12 +991,25 @@ static int viommu_attach_pgtable(struct viommu_domain *vdomain, }; /* TODO: bypass flag? */ + if (vdomain->bypass == true) + return 0; switch (fmt) { case VIRT_IO_PGTABLE: req.format = cpu_to_le16(VIRTIO_IOMMU_FORMAT_PGTF_VIRT); req.pgd = cpu_to_le64((u64)cfg->virt.pgd); break; + case INTEL_IOMMU: { + struct virtio_iommu_req_attach_pgt_vtd *vtd_req = + (struct virtio_iommu_req_attach_pgt_vtd *)&req; + + vtd_req->format = cpu_to_le16(VIRTIO_IOMMU_FORMAT_PGTF_VTD); + vtd_req->pgd = cpu_to_le64((u64)cfg->virt.pgd); + vtd_req->addr_width = cpu_to_le32(cfg->oas); + vtd_req->pasid = IOMMU_NO_PASID; + break; + } + default: return -EINVAL; }; @@ -1034,6 +1047,16 @@ static int viommu_setup_pgtable(struct viommu_domain *vdomain, case VIRTIO_IOMMU_FORMAT_PGTF_VIRT: fmt = VIRT_IO_PGTABLE; break; + case VIRTIO_IOMMU_FORMAT_PGTF_VTD: + { + struct virtio_iommu_probe_pgt_vtd *vtd_desc = + (struct virtio_iommu_probe_pgt_vtd *)desc; + + cfg.vtd_cfg.cap_reg = le64_to_cpu(vtd_desc->cap_reg); + cfg.vtd_cfg.ecap_reg = le64_to_cpu(vtd_desc->ecap_reg); + fmt = INTEL_IOMMU; + break; + } default: dev_warn(vdev->dev, "unsupported page table format 0x%x\n", le16_to_cpu(desc->format)); diff --git a/include/uapi/linux/virtio_iommu.h b/include/uapi/linux/virtio_iommu.h index 656be1f3d926..17e0d5fcdd54 100644 --- a/include/uapi/linux/virtio_iommu.h +++ b/include/uapi/linux/virtio_iommu.h @@ -139,6 +139,22 @@ struct virtio_iommu_req_attach_pgt_virt { struct virtio_iommu_req_tail tail; }; +/* Vt-d I/O Page Table Descriptor */ +struct virtio_iommu_req_attach_pgt_vtd { + struct virtio_iommu_req_head head; + __le32 domain; + __le32 endpoint; + __le32 flags; + __le16 format; + __u8 reserved[2]; + __le32 pasid; + __le64 pgd; + __le64 fl_flags; + __le32 addr_width; + __u8 reserved2[36]; + struct virtio_iommu_req_tail tail; +}; + #define VIRTIO_IOMMU_MAP_F_READ (1 << 0) #define VIRTIO_IOMMU_MAP_F_WRITE (1 << 1) #define VIRTIO_IOMMU_MAP_F_MMIO (1 << 2) @@ -224,6 +240,8 @@ struct virtio_iommu_probe_pasid_size { #define VIRTIO_IOMMU_FORMAT_PSTF_ARM_SMMU_V3 2 /* Virt I/O page table format */ #define VIRTIO_IOMMU_FORMAT_PGTF_VIRT 3 +/* VT-d I/O page table format */ +#define VIRTIO_IOMMU_FORMAT_PGTF_VTD 4 struct virtio_iommu_probe_table_format { struct virtio_iommu_probe_property head; @@ -231,6 +249,14 @@ struct virtio_iommu_probe_table_format { __u8 reserved[2]; }; +struct virtio_iommu_probe_pgt_vtd { + struct virtio_iommu_probe_property head; + __le16 format; + __u8 reserved[2]; + __le64 cap_reg; + __le64 ecap_reg; +}; + struct virtio_iommu_req_probe { struct virtio_iommu_req_head head; __le32 endpoint; -- 2.39.3