lists.openwall.net | lists / announce owl-users owl-dev john-users john-dev passwdqc-users yescrypt popa3d-users / oss-security kernel-hardening musl sabotage tlsify passwords / crypt-dev xvendor / Bugtraq Full-Disclosure linux-kernel linux-netdev linux-ext4 linux-hardening linux-cve-announce PHC | |
Open Source and information security mailing list archives
| ||
|
Date: Tue, 14 Jun 2022 15:47:21 +0800 From: Baolu Lu <baolu.lu@...ux.intel.com> To: "Tian, Kevin" <kevin.tian@...el.com>, Joerg Roedel <joro@...tes.org>, "Raj, Ashok" <ashok.raj@...el.com>, Christoph Hellwig <hch@...radead.org>, Jason Gunthorpe <jgg@...dia.com> Cc: baolu.lu@...ux.intel.com, Will Deacon <will@...nel.org>, Robin Murphy <robin.murphy@....com>, "Liu, Yi L" <yi.l.liu@...el.com>, "Pan, Jacob jun" <jacob.jun.pan@...el.com>, "iommu@...ts.linux-foundation.org" <iommu@...ts.linux-foundation.org>, "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org> Subject: Re: [PATCH v2 11/12] iommu/vt-d: Use device_domain_lock accurately On 2022/6/14 15:16, Tian, Kevin wrote: >> From: Lu Baolu <baolu.lu@...ux.intel.com> >> Sent: Tuesday, June 14, 2022 10:52 AM >> >> The device_domain_lock is used to protect the device tracking list of >> a domain. Remove unnecessary spin_lock/unlock()'s and move the necessary >> ones around the list access. >> >> Signed-off-by: Lu Baolu <baolu.lu@...ux.intel.com> >> --- >> drivers/iommu/intel/iommu.c | 68 +++++++++++++++---------------------- >> 1 file changed, 27 insertions(+), 41 deletions(-) >> > [...] >> +iommu_support_dev_iotlb(struct dmar_domain *domain, struct >> intel_iommu *iommu, >> + u8 bus, u8 devfn) >> { >> - struct device_domain_info *info; >> - >> - assert_spin_locked(&device_domain_lock); >> + struct device_domain_info *info = NULL, *tmp; >> + unsigned long flags; >> >> if (!iommu->qi) >> return NULL; >> >> - list_for_each_entry(info, &domain->devices, link) >> - if (info->iommu == iommu && info->bus == bus && >> - info->devfn == devfn) { >> - if (info->ats_supported && info->dev) >> - return info; >> + spin_lock_irqsave(&device_domain_lock, flags); >> + list_for_each_entry(tmp, &domain->devices, link) { >> + if (tmp->iommu == iommu && tmp->bus == bus && >> + tmp->devfn == devfn) { >> + if (tmp->ats_supported) >> + info = tmp; > > Directly returning with unlock here is clearer than adding > another tmp variable... Sure. > >> @@ -2460,15 +2450,14 @@ static int domain_add_dev_info(struct >> dmar_domain *domain, struct device *dev) >> if (!iommu) >> return -ENODEV; >> >> - spin_lock_irqsave(&device_domain_lock, flags); >> - info->domain = domain; >> ret = domain_attach_iommu(domain, iommu); >> - if (ret) { >> - spin_unlock_irqrestore(&device_domain_lock, flags); >> + if (ret) >> return ret; >> - } >> + >> + spin_lock_irqsave(&device_domain_lock, flags); >> list_add(&info->link, &domain->devices); >> spin_unlock_irqrestore(&device_domain_lock, flags); >> + info->domain = domain; >> > > This is incorrect. You need fully initialize the object before adding > it to the list. Otherwise a search right after above unlock and > before assigning info->domain will get a wrong data Fair enough. Will fix it in the next version. Best regards, baolu
Powered by blists - more mailing lists