All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lu Baolu <baolu.lu@linux.intel.com>
To: "Tian, Kevin" <kevin.tian@intel.com>, Jason Gunthorpe <jgg@nvidia.com>
Cc: "Raj, Ashok" <ashok.raj@intel.com>, Will Deacon <will@kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"iommu@lists.linux-foundation.org"
	<iommu@lists.linux-foundation.org>,
	Christoph Hellwig <hch@infradead.org>,
	"Alex Williamson \(alex.williamson@redhat.com\)"
	<alex.williamson@redhat.com>,
	"Pan, Jacob jun" <jacob.jun.pan@intel.com>,
	Robin Murphy <robin.murphy@arm.com>,
	Jean-Philippe Brucker <jean-philippe@linaro.com>
Subject: Re: [PATCH RFC v2 02/11] iommu: Add iommu_group_singleton_lockdown()
Date: Wed, 6 Apr 2022 19:03:12 +0800	[thread overview]
Message-ID: <a5542ef5-bacc-f527-0295-ffdedefcbdd9@linux.intel.com> (raw)
In-Reply-To: <BN9PR11MB527646AB4F3FE8E9F97ECB8D8CE79@BN9PR11MB5276.namprd11.prod.outlook.com>

On 2022/4/6 18:44, Tian, Kevin wrote:
>> From: Lu Baolu <baolu.lu@linux.intel.com>
>> Sent: Wednesday, April 6, 2022 6:02 PM
>>
>> Hi Kevin,
>>
>> On 2022/4/2 15:12, Tian, Kevin wrote:
>>>>>> Add a flag to the group that positively indicates the group can never
>>>>>> have more than one member, even after hot plug. eg because it is
>>>>>> impossible due to ACS, or lack of bridges, and so on.
>>>>> OK, I see your point. It essentially refers to a singleton group which
>>>>> is immutable to hotplug.
>>>> Yes, known at creation time, not retroactively enforced because
>>>> someone used SVA
>>>>
>>> We may check following conditions to set the immutable flag when
>>> a new group is created for a device in pci_device_group():
>>>
>>> 1) ACS is enabled in the upstream path of the device;
>>> 2) the device is single function or ACS is enabled on a multi-function device;
>>> 3) the device type is PCI_EXP_TYPE_ENDPOINT (thus no hotplug);
>>> 4) no 'dma aliasing' on this device;
>>>
>>> The last one is a bit conservative as it also precludes a device which aliasing
>>> dma due to quirks from being treated as a singleton group. But doing so
>>> saves the effort on trying to separate different aliasing scenarios as defined
>>> in pci_for_each_dma_alias(). Probably we can go this way as the first step.
>>>
>>> Once the flag is set on a group no other event can change it. If a new
>>> identified device hits an existing singleton group in pci_device_group()
>>> then it's a bug.
>>
>> How about below implementation?
>>
>> /* callback for pci_for_each_dma_alias() */
>> static int has_pci_alias(struct pci_dev *pdev, u16 alias, void *opaque)
>> {
>> 	return -EEXIST;
>> }
>>
>> static bool pci_dev_is_immutably_isolated(struct pci_dev *pdev)
>> {
>> 	/* Skip bridges. */
>> 	if (pci_is_bridge(pdev))
>> 		return false;
>>
>> 	/* Either connect to root bridge or the ACS-enabled bridge. */
>> 	if (!pci_is_root_bus(pdev->bus) &&
>> 	    !pci_acs_enabled(pdev->bus->self, REQ_ACS_FLAGS))
>> 		return false;
> 
> it's not sufficient to just check the non-root bridge itself. This needs to
> cover the entire path from the bridge to the root port, as pci_device_group()
> does.

Yes! You are right.

> 
>>
>> 	/* ACS is required for MFD. */
>> 	if (pdev->multifunction && !pci_acs_enabled(pdev, REQ_ACS_FLAGS))
>> 		return false;
> 
> Above two checks be replaced by a simple check as below:
> 
> 	if (!pci_acs_path_enabled(pdev, NULL, REQ_ACS_FLAGS))
> 		return false;

If !pdev->multifunction, do we still need to start from the device
itself? ACS is only for MFDs and bridges, do I understand it right?
Do we need to consider the SRIOV case?

> 
>>
>> 	/* Make sure no PCI alias. */
>> 	if (pci_for_each_dma_alias(pdev, has_pci_alias, NULL))
>> 		return false;
>>
>> 	return true;
>> }
>>
>> I didn't get why do we need to check the PCI_EXP_TYPE_ENDPOINT device
>> type. Can you please elaborate a bit more?
>>
> 
> I didn't know there is a pci_is_bridge() facility thus be conservative
> to restrict it to only endpoint device. If checking pci_is_bridge() alone
> excludes any hotplug possibility, then it's definitely better.

Okay! Thanks!

> Thanks
> Kevin

Best regards,
baolu
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

WARNING: multiple messages have this Message-ID (diff)
From: Lu Baolu <baolu.lu@linux.intel.com>
To: "Tian, Kevin" <kevin.tian@intel.com>, Jason Gunthorpe <jgg@nvidia.com>
Cc: baolu.lu@linux.intel.com,
	"Alex Williamson (alex.williamson@redhat.com)" 
	<alex.williamson@redhat.com>, "Raj, Ashok" <ashok.raj@intel.com>,
	Jean-Philippe Brucker <jean-philippe@linaro.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Christoph Hellwig <hch@infradead.org>,
	"iommu@lists.linux-foundation.org"
	<iommu@lists.linux-foundation.org>,
	"Pan, Jacob jun" <jacob.jun.pan@intel.com>,
	Will Deacon <will@kernel.org>,
	Robin Murphy <robin.murphy@arm.com>
Subject: Re: [PATCH RFC v2 02/11] iommu: Add iommu_group_singleton_lockdown()
Date: Wed, 6 Apr 2022 19:03:12 +0800	[thread overview]
Message-ID: <a5542ef5-bacc-f527-0295-ffdedefcbdd9@linux.intel.com> (raw)
In-Reply-To: <BN9PR11MB527646AB4F3FE8E9F97ECB8D8CE79@BN9PR11MB5276.namprd11.prod.outlook.com>

On 2022/4/6 18:44, Tian, Kevin wrote:
>> From: Lu Baolu <baolu.lu@linux.intel.com>
>> Sent: Wednesday, April 6, 2022 6:02 PM
>>
>> Hi Kevin,
>>
>> On 2022/4/2 15:12, Tian, Kevin wrote:
>>>>>> Add a flag to the group that positively indicates the group can never
>>>>>> have more than one member, even after hot plug. eg because it is
>>>>>> impossible due to ACS, or lack of bridges, and so on.
>>>>> OK, I see your point. It essentially refers to a singleton group which
>>>>> is immutable to hotplug.
>>>> Yes, known at creation time, not retroactively enforced because
>>>> someone used SVA
>>>>
>>> We may check following conditions to set the immutable flag when
>>> a new group is created for a device in pci_device_group():
>>>
>>> 1) ACS is enabled in the upstream path of the device;
>>> 2) the device is single function or ACS is enabled on a multi-function device;
>>> 3) the device type is PCI_EXP_TYPE_ENDPOINT (thus no hotplug);
>>> 4) no 'dma aliasing' on this device;
>>>
>>> The last one is a bit conservative as it also precludes a device which aliasing
>>> dma due to quirks from being treated as a singleton group. But doing so
>>> saves the effort on trying to separate different aliasing scenarios as defined
>>> in pci_for_each_dma_alias(). Probably we can go this way as the first step.
>>>
>>> Once the flag is set on a group no other event can change it. If a new
>>> identified device hits an existing singleton group in pci_device_group()
>>> then it's a bug.
>>
>> How about below implementation?
>>
>> /* callback for pci_for_each_dma_alias() */
>> static int has_pci_alias(struct pci_dev *pdev, u16 alias, void *opaque)
>> {
>> 	return -EEXIST;
>> }
>>
>> static bool pci_dev_is_immutably_isolated(struct pci_dev *pdev)
>> {
>> 	/* Skip bridges. */
>> 	if (pci_is_bridge(pdev))
>> 		return false;
>>
>> 	/* Either connect to root bridge or the ACS-enabled bridge. */
>> 	if (!pci_is_root_bus(pdev->bus) &&
>> 	    !pci_acs_enabled(pdev->bus->self, REQ_ACS_FLAGS))
>> 		return false;
> 
> it's not sufficient to just check the non-root bridge itself. This needs to
> cover the entire path from the bridge to the root port, as pci_device_group()
> does.

Yes! You are right.

> 
>>
>> 	/* ACS is required for MFD. */
>> 	if (pdev->multifunction && !pci_acs_enabled(pdev, REQ_ACS_FLAGS))
>> 		return false;
> 
> Above two checks be replaced by a simple check as below:
> 
> 	if (!pci_acs_path_enabled(pdev, NULL, REQ_ACS_FLAGS))
> 		return false;

If !pdev->multifunction, do we still need to start from the device
itself? ACS is only for MFDs and bridges, do I understand it right?
Do we need to consider the SRIOV case?

> 
>>
>> 	/* Make sure no PCI alias. */
>> 	if (pci_for_each_dma_alias(pdev, has_pci_alias, NULL))
>> 		return false;
>>
>> 	return true;
>> }
>>
>> I didn't get why do we need to check the PCI_EXP_TYPE_ENDPOINT device
>> type. Can you please elaborate a bit more?
>>
> 
> I didn't know there is a pci_is_bridge() facility thus be conservative
> to restrict it to only endpoint device. If checking pci_is_bridge() alone
> excludes any hotplug possibility, then it's definitely better.

Okay! Thanks!

> Thanks
> Kevin

Best regards,
baolu

  reply	other threads:[~2022-04-06 11:03 UTC|newest]

Thread overview: 124+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-29  5:37 [PATCH RFC v2 00/11] iommu: SVA and IOPF refactoring Lu Baolu
2022-03-29  5:37 ` Lu Baolu
2022-03-29  5:37 ` [PATCH RFC v2 01/11] iommu: Add pasid_bits field in struct dev_iommu Lu Baolu
2022-03-29  5:37   ` Lu Baolu
2022-03-29 21:00   ` Jacob Pan
2022-03-29 21:00     ` Jacob Pan
2022-03-30  4:30     ` Lu Baolu
2022-03-30  4:30       ` Lu Baolu
2022-03-30  7:05   ` Tian, Kevin
2022-03-30  7:05     ` Tian, Kevin
2022-03-30 11:58     ` Lu Baolu
2022-03-30 11:58       ` Lu Baolu
2022-03-29  5:37 ` [PATCH RFC v2 02/11] iommu: Add iommu_group_singleton_lockdown() Lu Baolu
2022-03-29  5:37   ` Lu Baolu
2022-03-29  8:42   ` Tian, Kevin
2022-03-29  8:42     ` Tian, Kevin
2022-03-29 11:42     ` Jason Gunthorpe
2022-03-29 11:42       ` Jason Gunthorpe via iommu
2022-03-30  6:50       ` Tian, Kevin
2022-03-30  6:50         ` Tian, Kevin
2022-03-30 11:57         ` Lu Baolu
2022-03-30 11:57           ` Lu Baolu
2022-03-30 11:58         ` Jason Gunthorpe via iommu
2022-03-30 11:58           ` Jason Gunthorpe
2022-03-30 14:12           ` Tian, Kevin
2022-03-30 14:12             ` Tian, Kevin
2022-03-30 14:30             ` Jason Gunthorpe
2022-03-30 14:30               ` Jason Gunthorpe via iommu
2022-04-02  7:12               ` Tian, Kevin
2022-04-02  7:12                 ` Tian, Kevin
2022-04-02 23:29                 ` Jason Gunthorpe
2022-04-02 23:29                   ` Jason Gunthorpe via iommu
2022-04-06 10:02                 ` Lu Baolu
2022-04-06 10:02                   ` Lu Baolu
2022-04-06 10:44                   ` Tian, Kevin
2022-04-06 10:44                     ` Tian, Kevin
2022-04-06 11:03                     ` Lu Baolu [this message]
2022-04-06 11:03                       ` Lu Baolu
2022-04-06 23:56                       ` Tian, Kevin
2022-04-06 23:56                         ` Tian, Kevin
2022-03-30 14:18           ` Tian, Kevin
2022-03-30 14:18             ` Tian, Kevin
2022-03-30 15:04             ` Alex Williamson
2022-03-30 15:04               ` Alex Williamson
2022-04-04  5:43           ` Lu Baolu
2022-04-04  5:43             ` Lu Baolu
2022-04-04 17:24             ` Jason Gunthorpe via iommu
2022-04-04 17:24               ` Jason Gunthorpe
2022-04-05  6:12               ` Lu Baolu
2022-04-05  6:12                 ` Lu Baolu
2022-04-05 14:10                 ` Jason Gunthorpe via iommu
2022-04-05 14:10                   ` Jason Gunthorpe
2022-04-06  9:51                   ` Lu Baolu
2022-04-06  9:51                     ` Lu Baolu
2022-04-01  6:20       ` Yi Liu
2022-04-01  6:20         ` Yi Liu
2022-04-01 11:52         ` Jason Gunthorpe
2022-04-01 11:52           ` Jason Gunthorpe via iommu
2022-03-30  4:59     ` Lu Baolu
2022-03-30  4:59       ` Lu Baolu
2022-03-30  6:55       ` Tian, Kevin
2022-03-30  6:55         ` Tian, Kevin
2022-04-01  5:49     ` Yi Liu
2022-04-01  5:49       ` Yi Liu
2022-03-29  5:37 ` [PATCH RFC v2 03/11] iommu/sva: Add iommu_domain type for SVA Lu Baolu
2022-03-29  5:37   ` Lu Baolu
2022-03-29 21:38   ` Jacob Pan
2022-03-29 21:38     ` Jacob Pan
2022-03-30  4:35     ` Lu Baolu
2022-03-30  4:35       ` Lu Baolu
2022-03-30 19:02   ` Jason Gunthorpe
2022-03-30 19:02     ` Jason Gunthorpe via iommu
2022-04-02  8:43     ` Tian, Kevin
2022-04-02  8:43       ` Tian, Kevin
2022-04-02 23:32       ` Jason Gunthorpe
2022-04-02 23:32         ` Jason Gunthorpe via iommu
2022-04-04  6:09         ` Lu Baolu
2022-04-04  6:09           ` Lu Baolu
2022-04-06  1:00         ` Tian, Kevin
2022-04-06  1:00           ` Tian, Kevin
2022-04-06  1:23           ` Jason Gunthorpe via iommu
2022-04-06  1:23             ` Jason Gunthorpe
2022-04-06  5:58             ` Tian, Kevin
2022-04-06  5:58               ` Tian, Kevin
2022-04-06 12:32               ` Robin Murphy
2022-04-06 12:32                 ` Robin Murphy
2022-04-06 13:06                 ` Jason Gunthorpe via iommu
2022-04-06 13:06                   ` Jason Gunthorpe
2022-04-06 13:37                   ` Robin Murphy
2022-04-06 13:37                     ` Robin Murphy
2022-04-06 14:01                     ` Jason Gunthorpe via iommu
2022-04-06 14:01                       ` Jason Gunthorpe
2022-04-07  0:11                 ` Tian, Kevin
2022-04-07  0:11                   ` Tian, Kevin
2022-03-29  5:37 ` [PATCH RFC v2 04/11] iommu: Add attach/detach_dev_pasid domain ops Lu Baolu
2022-03-29  5:37   ` Lu Baolu
2022-03-30 19:08   ` Jason Gunthorpe
2022-03-30 19:08     ` Jason Gunthorpe via iommu
2022-04-04  6:47     ` Lu Baolu
2022-04-04  6:47       ` Lu Baolu
2022-03-29  5:37 ` [PATCH RFC v2 05/11] iommu/vt-d: Remove SVM_FLAG_SUPERVISOR_MODE suport Lu Baolu
2022-03-29  5:37   ` Lu Baolu
2022-03-29  5:37 ` [PATCH RFC v2 06/11] iommu/vt-d: Add SVA domain support Lu Baolu
2022-03-29  5:37   ` Lu Baolu
2022-03-30 19:09   ` Jason Gunthorpe
2022-03-30 19:09     ` Jason Gunthorpe via iommu
2022-04-04  6:52     ` Lu Baolu
2022-04-04  6:52       ` Lu Baolu
2022-03-29  5:37 ` [PATCH RFC v2 07/11] arm-smmu-v3/sva: " Lu Baolu
2022-03-29  5:37   ` Lu Baolu
2022-03-29  5:37 ` [PATCH RFC v2 08/11] iommu/sva: Use attach/detach_pasid_dev in SVA interfaces Lu Baolu
2022-03-29  5:37   ` Lu Baolu
2022-03-31 20:59   ` Jacob Pan
2022-03-31 20:59     ` Jacob Pan
2022-03-31 22:26     ` Jason Gunthorpe
2022-03-31 22:26       ` Jason Gunthorpe via iommu
2022-04-04  5:55       ` Lu Baolu
2022-04-04  5:55         ` Lu Baolu
2022-03-29  5:37 ` [PATCH RFC v2 09/11] iommu: Remove SVA related callbacks from iommu ops Lu Baolu
2022-03-29  5:37   ` Lu Baolu
2022-03-29  5:37 ` [PATCH RFC v2 10/11] iommu: Per-domain I/O page fault handling Lu Baolu
2022-03-29  5:37   ` Lu Baolu
2022-03-29  5:38 ` [PATCH RFC v2 11/11] iommu: Rename iommu-sva-lib.{c,h} Lu Baolu
2022-03-29  5:38   ` Lu Baolu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a5542ef5-bacc-f527-0295-ffdedefcbdd9@linux.intel.com \
    --to=baolu.lu@linux.intel.com \
    --cc=alex.williamson@redhat.com \
    --cc=ashok.raj@intel.com \
    --cc=hch@infradead.org \
    --cc=iommu@lists.linux-foundation.org \
    --cc=jacob.jun.pan@intel.com \
    --cc=jean-philippe@linaro.com \
    --cc=jgg@nvidia.com \
    --cc=kevin.tian@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robin.murphy@arm.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.