> From: Liu, Yi L <yi.l.liu@xxxxxxxxx> > Sent: Thursday, December 19, 2024 9:36 PM > > @@ -1317,6 +1320,34 @@ int iommufd_get_hw_info(struct iommufd_ucmd > *ucmd) > if (device_iommu_capable(idev->dev, > IOMMU_CAP_DIRTY_TRACKING)) > cmd->out_capabilities |= > IOMMU_HW_CAP_DIRTY_TRACKING; > > + /* > + * Currently, major iommu drivers enable PASID in the probe_device() s/major/all/? otherwise it's not correct to make such assumption even if there is just one exception. > + * op if iommu and device supports it. So the max_pasids stored in > + * dev->iommu indicates both PASID support and enable status. A > + * non-zero dev->iommu->max_pasids means PASID is supported > and > + * enabled, The iommufd only reports PASID capability to userspace s/, The/./ > + * if it's enabled. > + */ > + if (idev->dev->iommu->max_pasids) { > + cmd->out_max_pasid_log2 = ilog2(idev->dev->iommu- > >max_pasids); > + > + if (dev_is_pci(idev->dev)) { > + struct pci_dev *pdev = to_pci_dev(idev->dev); > + int ctrl; > + > + ctrl = pci_pasid_ctrl_status(pdev); > + > + WARN_ON_ONCE(!(ctrl & PCI_PASID_CTRL_ENABLE)); If not enabled then also clear cmd->out_max_pasid_log2? btw pci_pasid_ctrl_status() could return a errno but the check above treat it as an unsigned value. > + > +/** > + * pci_pasid_ctrl_status - Check the PASID status > + * @pdev: PCI device structure > + * > + * Returns a negative value when no PASID capability is present. > + * Otherwise the value of the control register is returned. > + * Status reported are: > + * > + * PCI_PASID_CTRL_ENABLE - PASID enabled > + * PCI_PASID_CTRL_EXEC - Execute permission enabled > + * PCI_PASID_CTRL_PRIV - Privileged mode enabled > + */ > +int pci_pasid_ctrl_status(struct pci_dev *pdev) while this value is read from the ctrl register, it's not necessary to make it explicit in the function name. The caller just cares about the status so calling it pci_pasid_status() is clearer.