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: <BN9PR11MB527679AB260190162007F2018C4BA@BN9PR11MB5276.namprd11.prod.outlook.com>
Date: Fri, 11 Jul 2025 04:01:08 +0000
From: "Tian, Kevin" <kevin.tian@...el.com>
To: Baolu Lu <baolu.lu@...ux.intel.com>, Peter Zijlstra <peterz@...radead.org>
CC: Joerg Roedel <joro@...tes.org>, Will Deacon <will@...nel.org>, "Robin
 Murphy" <robin.murphy@....com>, Jason Gunthorpe <jgg@...dia.com>, Jann Horn
	<jannh@...gle.com>, Vasant Hegde <vasant.hegde@....com>, "Hansen, Dave"
	<dave.hansen@...el.com>, Alistair Popple <apopple@...dia.com>, "Uladzislau
 Rezki" <urezki@...il.com>, Jean-Philippe Brucker <jean-philippe@...aro.org>,
	Andy Lutomirski <luto@...nel.org>, "Lai, Yi1" <yi1.lai@...el.com>,
	"iommu@...ts.linux.dev" <iommu@...ts.linux.dev>, "security@...nel.org"
	<security@...nel.org>, "linux-kernel@...r.kernel.org"
	<linux-kernel@...r.kernel.org>, "stable@...r.kernel.org"
	<stable@...r.kernel.org>
Subject: RE: [PATCH v2 1/1] iommu/sva: Invalidate KVA range on kernel TLB
 flush

> From: Baolu Lu <baolu.lu@...ux.intel.com>
> Sent: Friday, July 11, 2025 11:00 AM
> 
> On 7/10/25 21:54, Peter Zijlstra wrote:
> > On Wed, Jul 09, 2025 at 02:28:00PM +0800, Lu Baolu wrote:
> >> +
> >> +	if (list_empty(&iommu_mm->sva_domains)) {
> >> +		scoped_guard(spinlock_irqsave, &iommu_mms_lock) {
> >> +			list_del(&iommu_mm->mm_list_elm);
> >> +			if (list_empty(&iommu_sva_mms))
> >> +				static_branch_disable(&iommu_sva_present);
> >> +		}
> >> +	}
> >> +
> >>   	mutex_unlock(&iommu_sva_lock);
> >>   	kfree(handle);
> >>   }
> >
> > This seems an odd coding style choice; why the extra unneeded
> > indentation? That is, what's wrong with:
> >
> > 	if (list_empty()) {
> > 		guard(spinlock_irqsave)(&iommu_mms_lock);
> > 		list_del();
> > 		if (list_empty()
> > 			static_branch_disable();
> > 	}
> 
> Perhaps I overlooked or misunderstood something, but my understanding
> is,
> 
> The lock order in this function is:
> 
> 	mutex_lock(&iommu_sva_lock);
> 	spin_lock(&iommu_mms_lock);
> 	spin_unlock(&iommu_mms_lock);
> 	mutex_unlock(&iommu_sva_lock);
> 
> With above change, it is changed to:
> 
> 	mutex_lock(&iommu_sva_lock);
> 	spin_lock(&iommu_mms_lock);
> 	mutex_unlock(&iommu_sva_lock);
> 	spin_unlock(&iommu_mms_lock);
> 

guard() follows the scope of variable declaration. Actually above
is a perfect match to the example in cleanup.h:

* The lifetime of the lock obtained by the guard() helper follows the
 * scope of automatic variable declaration. Take the following example::
 *
 *      func(...)
 *      {
 *              if (...) {
 *                      ...
 *                      guard(pci_dev)(dev); // pci_dev_lock() invoked here
 *                      ...
 *              } // <- implied pci_dev_unlock() triggered here
 *      }
 *
 * Observe the lock is held for the remainder of the "if ()" block not
 * the remainder of "func()".

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ