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
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <BN9PR11MB52764D7CD86448C5E4EB46668CAA9@BN9PR11MB5276.namprd11.prod.outlook.com>
Date:   Tue, 14 Jun 2022 07:16:17 +0000
From:   "Tian, Kevin" <kevin.tian@...el.com>
To:     Lu Baolu <baolu.lu@...ux.intel.com>,
        Joerg Roedel <joro@...tes.org>,
        "Raj, Ashok" <ashok.raj@...el.com>,
        Christoph Hellwig <hch@...radead.org>,
        "Jason Gunthorpe" <jgg@...dia.com>
CC:     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

> 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...

> @@ -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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ