From nobody Sat Nov 15 12:49:56 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1752512619; cv=none; d=zohomail.com; s=zohoarc; b=YM3s2ezsTIe6xf7qszJF3Fmqc7xnFFf7IIi6/jDabEYnef/xI2MqcT5If2xVGPLQj3/yfEFvF5VPN8bHAiA3ISAzw1OCdY5pMWAbIG2JPjwOqPcX44Cj18HYApU8odNFWzr85qRE4i5a+lXFHCCVmp8KGnsSo4rMwCwKR6p+dKc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752512619; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=gOgRcuWMWplKAgPH6COmpfMWucfW61HFqAeaMSAraAE=; b=Dm76XzzPfCIRfaM1trFt4KcFJhvm367gRFzPPV4iAHsxfuaiOi9+JPbr+4EljWK88LmylWd4E/j3YP1v23pBu8MffqtoaNq3HKDXJCP3yGo+ELNCHaaa/2EkEF9sUq4WPN18uwoEzoQFufDVW/mDZq9Xg2Y3VfAp81Wr51TiyXE= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752512619495407.5322297178129; Mon, 14 Jul 2025 10:03:39 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubMXf-0002h1-H7; Mon, 14 Jul 2025 13:00:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubLcj-0005Tu-Vd; Mon, 14 Jul 2025 12:01:52 -0400 Received: from [185.176.79.56] (helo=frasgout.his.huawei.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubLci-0008O3-2S; Mon, 14 Jul 2025 12:01:49 -0400 Received: from mail.maildlp.com (unknown [172.18.186.216]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4bgn8x28qBz6M56C; Tue, 15 Jul 2025 00:00:33 +0800 (CST) Received: from frapeml500008.china.huawei.com (unknown [7.182.85.71]) by mail.maildlp.com (Postfix) with ESMTPS id E609B14033F; Tue, 15 Jul 2025 00:01:45 +0800 (CST) Received: from A2303104131.china.huawei.com (10.203.177.241) by frapeml500008.china.huawei.com (7.182.85.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Mon, 14 Jul 2025 18:01:37 +0200 To: , CC: , , , , , , , , , , , , , , , Subject: [RFC PATCH v3 10/15] hw/arm/smmuv3-accel: Allocate a vDEVICE object for device Date: Mon, 14 Jul 2025 16:59:36 +0100 Message-ID: <20250714155941.22176-11-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20250714155941.22176-1-shameerali.kolothum.thodi@huawei.com> References: <20250714155941.22176-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.203.177.241] X-ClientProxiedBy: kwepems500002.china.huawei.com (7.221.188.17) To frapeml500008.china.huawei.com (7.182.85.71) X-Host-Lookup-Failed: Reverse DNS lookup failed for 185.176.79.56 (deferred) Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=185.176.79.56; envelope-from=shameerali.kolothum.thodi@huawei.com; helo=frasgout.his.huawei.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Shameer Kolothum From: Shameer Kolothum via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1752512621696116600 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Nicolin Chen Allocate and associate a vDEVICE object for the Guest device with the vIOMMU. This will help the kernel to do the vSID --> sid translation whenever required (eg: device specific invalidations). Signed-off-by: Nicolin Chen Signed-off-by: Shameer Kolothum --- hw/arm/smmuv3-accel.c | 25 +++++++++++++++++++++++++ hw/arm/smmuv3-accel.h | 1 + include/system/iommufd.h | 5 +++++ 3 files changed, 31 insertions(+) diff --git a/hw/arm/smmuv3-accel.c b/hw/arm/smmuv3-accel.c index 74bf20cfaf..f1584dd775 100644 --- a/hw/arm/smmuv3-accel.c +++ b/hw/arm/smmuv3-accel.c @@ -93,6 +93,23 @@ void smmuv3_accel_install_nested_ste(SMMUState *bs, SMMU= Device *sdev, int sid) return; } =20 + if (!accel_dev->vdev && accel_dev->idev) { + IOMMUFDVdev *vdev; + uint32_t vdev_id; + SMMUViommu *viommu =3D accel_dev->viommu; + + iommufd_backend_alloc_vdev(viommu->core.iommufd, accel_dev->idev->= devid, + viommu->core.viommu_id, sid, &vdev_id, + &error_abort); + vdev =3D g_new(IOMMUFDVdev, 1); + vdev->vdev_id =3D vdev_id; + vdev->dev_id =3D sid; + accel_dev->vdev =3D vdev; + host_iommu_device_iommufd_attach_hwpt(accel_dev->idev, + accel_dev->viommu->bypass_hw= pt_id, + &error_abort); + } + ret =3D smmu_find_ste(sdev->smmu, sid, &ste, &event); if (ret) { error_report("failed to find STE for sid 0x%x", sid); @@ -287,6 +304,7 @@ static void smmuv3_accel_unset_iommu_device(PCIBus *bus= , void *opaque, SMMUPciBus *sbus =3D g_hash_table_lookup(bs->smmu_pcibus_by_busptr, bu= s); SMMUv3AccelDevice *accel_dev; SMMUViommu *viommu; + IOMMUFDVdev *vdev; SMMUDevice *sdev; =20 if (!sbus) { @@ -310,6 +328,13 @@ static void smmuv3_accel_unset_iommu_device(PCIBus *bu= s, void *opaque, trace_smmuv3_accel_unset_iommu_device(devfn, smmu_get_sid(sdev)); =20 viommu =3D s->s_accel->viommu; + vdev =3D accel_dev->vdev; + if (vdev) { + iommufd_backend_free_id(viommu->iommufd, vdev->vdev_id); + g_free(vdev); + accel_dev->vdev =3D NULL; + } + if (QLIST_EMPTY(&viommu->device_list)) { iommufd_backend_free_id(viommu->iommufd, viommu->bypass_hwpt_id); iommufd_backend_free_id(viommu->iommufd, viommu->abort_hwpt_id); diff --git a/hw/arm/smmuv3-accel.h b/hw/arm/smmuv3-accel.h index 06e81b630d..21028e60c8 100644 --- a/hw/arm/smmuv3-accel.h +++ b/hw/arm/smmuv3-accel.h @@ -40,6 +40,7 @@ typedef struct SMMUv3AccelDevice { HostIOMMUDeviceIOMMUFD *idev; SMMUS1Hwpt *s1_hwpt; SMMUViommu *viommu; + IOMMUFDVdev *vdev; QLIST_ENTRY(SMMUv3AccelDevice) next; } SMMUv3AccelDevice; =20 diff --git a/include/system/iommufd.h b/include/system/iommufd.h index b7ad2cf10c..8de559d448 100644 --- a/include/system/iommufd.h +++ b/include/system/iommufd.h @@ -44,6 +44,11 @@ typedef struct IOMMUFDViommu { uint32_t viommu_id; } IOMMUFDViommu; =20 +typedef struct IOMMUFDVdev { + uint32_t vdev_id; + uint32_t dev_id; +} IOMMUFDVdev; + bool iommufd_backend_connect(IOMMUFDBackend *be, Error **errp); void iommufd_backend_disconnect(IOMMUFDBackend *be); =20 --=20 2.34.1