On Mon, Jul 14, 2025 at 04:59:35PM +0100, Shameer Kolothum wrote: > +static int > +smmuv3_accel_dev_install_nested_ste(SMMUv3AccelDevice *accel_dev, > + uint32_t data_type, uint32_t data_len, > + void *data) > +{ > + SMMUViommu *viommu = accel_dev->viommu; > + SMMUS1Hwpt *s1_hwpt = accel_dev->s1_hwpt; > + HostIOMMUDeviceIOMMUFD *idev = accel_dev->idev; > + uint32_t flags = 0; > + > + if (!idev || !viommu) { > + return -ENOENT; > + } > + > + if (s1_hwpt) { > + smmuv3_accel_dev_uninstall_nested_ste(accel_dev, true); > + } > + > + s1_hwpt = g_new0(SMMUS1Hwpt, 1); > + s1_hwpt->iommufd = idev->iommufd; > + iommufd_backend_alloc_hwpt(idev->iommufd, idev->devid, > + viommu->core.viommu_id, flags, data_type, > + data_len, data, &s1_hwpt->hwpt_id, > &error_abort);
Let's check the return value. > + host_iommu_device_iommufd_attach_hwpt(idev, s1_hwpt->hwpt_id, > &error_abort); > + accel_dev->s1_hwpt = s1_hwpt; > + return 0; > +} > + > +void smmuv3_accel_install_nested_ste(SMMUState *bs, SMMUDevice *sdev, int > sid) > +{ > + SMMUv3AccelDevice *accel_dev; > + SMMUEventInfo event = {.type = SMMU_EVT_NONE, .sid = sid, > + .inval_ste_allowed = true}; > + struct iommu_hwpt_arm_smmuv3 nested_data = {}; > + uint32_t config; > + STE ste; > + int ret; > + > + if (!bs->accel) { > + return; > + } > + > + accel_dev = container_of(sdev, SMMUv3AccelDevice, sdev); > + if (!accel_dev->viommu) { > + return; > + } > + > + ret = smmu_find_ste(sdev->smmu, sid, &ste, &event); > + if (ret) { > + error_report("failed to find STE for sid 0x%x", sid); > + return; > + } > + > + config = STE_CONFIG(&ste); > + if (!STE_VALID(&ste) || !STE_CFG_S1_ENABLED(config)) { > + smmuv3_accel_dev_uninstall_nested_ste(accel_dev, > STE_CFG_ABORT(config)); > + smmuv3_flush_config(sdev); > + return; > + } > + > + nested_data.ste[0] = (uint64_t)ste.word[0] | (uint64_t)ste.word[1] << 32; > + nested_data.ste[1] = (uint64_t)ste.word[2] | (uint64_t)ste.word[3] << 32; > + /* V | CONFIG | S1FMT | S1CTXPTR | S1CDMAX */ > + nested_data.ste[0] &= 0xf80fffffffffffffULL; > + /* S1DSS | S1CIR | S1COR | S1CSH | S1STALLD | EATS */ > + nested_data.ste[1] &= 0x380000ffULL; Likely we need to make sure that values here are little endians, in alignment with the kernel uABI. > + ret = smmuv3_accel_dev_install_nested_ste(accel_dev, > + IOMMU_HWPT_DATA_ARM_SMMUV3, > + sizeof(nested_data), > + &nested_data); > + if (ret) { > + error_report("Unable to install nested STE=%16LX:%16LX, sid=0x%x," > + "ret=%d", nested_data.ste[1], nested_data.ste[0], > + sid, ret); > + } > + > + trace_smmuv3_accel_install_nested_ste(sid, nested_data.ste[1], > + nested_data.ste[0]); > +} > + > +static void > +smmuv3_accel_ste_range(gpointer key, gpointer value, gpointer user_data) > +{ > + SMMUDevice *sdev = (SMMUDevice *)key; > + uint32_t sid = smmu_get_sid(sdev); > + SMMUSIDRange *sid_range = (SMMUSIDRange *)user_data; > + > + if (sid >= sid_range->start && sid <= sid_range->end) { > + SMMUv3State *s = sdev->smmu; > + SMMUState *bs = &s->smmu_state; Can we use ARM_SMMU and ARM_SMMUV3 macros? > + > + smmuv3_accel_install_nested_ste(bs, sdev, sid); > + } > +} > + > +void > +smmuv3_accel_install_nested_ste_range(SMMUState *bs, SMMUSIDRange *range) Fits in one line. > typedef struct SMMUv3AccelDevice { > SMMUDevice sdev; > AddressSpace as_sysmem; > HostIOMMUDeviceIOMMUFD *idev; > + SMMUS1Hwpt *s1_hwpt; No need of an extra space. > SMMUViommu *viommu; > QLIST_ENTRY(SMMUv3AccelDevice) next; > } SMMUv3AccelDevice; > @@ -45,10 +51,21 @@ typedef struct SMMUv3AccelState { > > #if defined(CONFIG_ARM_SMMUV3) && defined(CONFIG_IOMMUFD) > void smmuv3_accel_init(SMMUv3State *s); > +void smmuv3_accel_install_nested_ste(SMMUState *bs, SMMUDevice *sdev, int > sid); > +void smmuv3_accel_install_nested_ste_range(SMMUState *bs, > + SMMUSIDRange *range); Fits in one line. > diff --git a/hw/arm/smmuv3-internal.h b/hw/arm/smmuv3-internal.h > index b6b7399347..738061c6ad 100644 > --- a/hw/arm/smmuv3-internal.h > +++ b/hw/arm/smmuv3-internal.h > @@ -547,6 +547,10 @@ typedef struct CD { > uint32_t word[16]; > } CD; > > +int smmu_find_ste(SMMUv3State *s, uint32_t sid, STE *ste, > + SMMUEventInfo *event); Ditto > diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c > index 2f5a8157dd..c94bfe6564 100644 > --- a/hw/arm/smmuv3.c > +++ b/hw/arm/smmuv3.c > @@ -630,8 +630,8 @@ bad_ste: > * Supports linear and 2-level stream table > * Return 0 on success, -EINVAL otherwise > */ > -static int smmu_find_ste(SMMUv3State *s, uint32_t sid, STE *ste, > - SMMUEventInfo *event) > +int smmu_find_ste(SMMUv3State *s, uint32_t sid, STE *ste, > + SMMUEventInfo *event) Ditto Thanks Nicolin