mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-05-09 19:51:25 -04:00
iommu/amd: Refactor attaching / detaching device functions
If domain is configured with V2 page table then setup default GCR3 with domain GCR3 pointer. So that all devices in the domain uses same page table for translation. Also return page table setup status from do_attach() function. Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com> Co-developed-by: Vasant Hegde <vasant.hegde@amd.com> Signed-off-by: Vasant Hegde <vasant.hegde@amd.com> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Link: https://lore.kernel.org/r/20240205115615.6053-12-vasant.hegde@amd.com Signed-off-by: Joerg Roedel <jroedel@suse.de>
This commit is contained in:
committed by
Joerg Roedel
parent
e8e1aac334
commit
4ebd4c7f25
@@ -1901,10 +1901,11 @@ static void clear_dte_entry(struct amd_iommu *iommu, u16 devid)
|
||||
amd_iommu_apply_erratum_63(iommu, devid);
|
||||
}
|
||||
|
||||
static void do_attach(struct iommu_dev_data *dev_data,
|
||||
struct protection_domain *domain)
|
||||
static int do_attach(struct iommu_dev_data *dev_data,
|
||||
struct protection_domain *domain)
|
||||
{
|
||||
struct amd_iommu *iommu = get_amd_iommu_from_dev_data(dev_data);
|
||||
int ret = 0;
|
||||
|
||||
/* Update data structures */
|
||||
dev_data->domain = domain;
|
||||
@@ -1918,11 +1919,28 @@ static void do_attach(struct iommu_dev_data *dev_data,
|
||||
domain->dev_iommu[iommu->index] += 1;
|
||||
domain->dev_cnt += 1;
|
||||
|
||||
/* Init GCR3 table and update device table */
|
||||
if (domain->pd_mode == PD_MODE_V2) {
|
||||
/* By default, setup GCR3 table to support single PASID */
|
||||
ret = setup_gcr3_table(dev_data->domain, 1);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = update_gcr3(dev_data, 0,
|
||||
iommu_virt_to_phys(domain->iop.pgd), true);
|
||||
if (ret) {
|
||||
free_gcr3_table(dev_data->domain);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
/* Update device table */
|
||||
set_dte_entry(iommu, dev_data);
|
||||
clone_aliases(iommu, dev_data->dev);
|
||||
|
||||
device_flush_dte(dev_data);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void do_detach(struct iommu_dev_data *dev_data)
|
||||
@@ -1930,6 +1948,12 @@ static void do_detach(struct iommu_dev_data *dev_data)
|
||||
struct protection_domain *domain = dev_data->domain;
|
||||
struct amd_iommu *iommu = get_amd_iommu_from_dev_data(dev_data);
|
||||
|
||||
/* Clear GCR3 table */
|
||||
if (domain->pd_mode == PD_MODE_V2) {
|
||||
update_gcr3(dev_data, 0, 0, false);
|
||||
free_gcr3_table(dev_data->domain);
|
||||
}
|
||||
|
||||
/* Update data structures */
|
||||
dev_data->domain = NULL;
|
||||
list_del(&dev_data->list);
|
||||
@@ -1972,7 +1996,7 @@ static int attach_device(struct device *dev,
|
||||
if (dev_is_pci(dev))
|
||||
pdev_enable_caps(to_pci_dev(dev));
|
||||
|
||||
do_attach(dev_data, domain);
|
||||
ret = do_attach(dev_data, domain);
|
||||
|
||||
out:
|
||||
spin_unlock(&dev_data->lock);
|
||||
|
||||
Reference in New Issue
Block a user