From: Ganapatrao Kulkarni <gankulkarni@os.amperecomputing.com>
To: Jean-Philippe Brucker <jean-philippe@linaro.org>,
Bjorn Helgaas <helgaas@kernel.org>
Cc: Leon Romanovsky <leon@kernel.org>,
linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org,
bhelgaas@google.com, darren@os.amperecomputing.com,
scott@os.amperecomputing.com, Will Deacon <will@kernel.org>,
Robin Murphy <robin.murphy@arm.com>,
Joerg Roedel <joro@8bytes.org>,
linux-arm-kernel@lists.infradead.org, iommu@lists.linux.dev
Subject: Re: [PATCH] PCI/ATS: Allow to enable ATS on VFs even if it is not enabled on PF
Date: Tue, 21 Feb 2023 14:43:22 +0530 [thread overview]
Message-ID: <2fe43de6-f356-f996-c2cb-22f66f2bf593@os.amperecomputing.com> (raw)
In-Reply-To: <3877b6fe-2b7e-3e0c-8b69-65e84c09cdd2@os.amperecomputing.com>
Hi Bjorn,
On 16-02-2023 05:06 pm, Ganapatrao Kulkarni wrote:
>
>
> On 16-02-2023 04:42 pm, Jean-Philippe Brucker wrote:
>> On Wed, Feb 15, 2023 at 02:57:26PM -0600, Bjorn Helgaas wrote:
>>> [+cc Will, Robin, Joerg for arm-smmu-v3 page size question]
>>>
>>> On Sun, Feb 12, 2023 at 08:14:48PM +0200, Leon Romanovsky wrote:
>>>> On Wed, Feb 08, 2023 at 10:43:21AM -0800, Ganapatrao Kulkarni wrote:
>>>>> As per PCIe specification(section 10.5), If a VF implements an
>>>>> ATS capability, its associated PF must implement an ATS capability.
>>>>> The ATS Capabilities in VFs and their associated PFs are permitted to
>>>>> be enabled independently.
>>>>> Also, it states that the Smallest Translation Unit (STU) for VFs
>>>>> must be
>>>>> hardwired to Zero and the associated PF's value applies to VFs STU.
>>>>>
>>>>> The current code allows to enable ATS on VFs only if it is already
>>>>> enabled on associated PF, which is not necessary as per the
>>>>> specification.
>>>>>
>>>>> It is only required to have valid STU programmed on PF to enable
>>>>> ATS on VFs. Adding code to write the first VFs STU to a PF's STU
>>>>> when PFs ATS is not enabled.
>>>>
>>>> Can you please add here quotes from the spec and its version? I
>>>> don't see
>>>> anything like this in my version of PCIe specification.
>>>
>>> See PCIe r6.0, sec 10.5.1.
>>>
>>>>> Signed-off-by: Ganapatrao Kulkarni
>>>>> <gankulkarni@os.amperecomputing.com>
>>>>> ---
>>>>> drivers/pci/ats.c | 15 +++++++++++----
>>>>> 1 file changed, 11 insertions(+), 4 deletions(-)
>>>>>
>>>>> diff --git a/drivers/pci/ats.c b/drivers/pci/ats.c
>>>>> index f9cc2e10b676..a97ec67201d1 100644
>>>>> --- a/drivers/pci/ats.c
>>>>> +++ b/drivers/pci/ats.c
>>>>> @@ -67,13 +67,20 @@ int pci_enable_ats(struct pci_dev *dev, int ps)
>>>>> if (ps < PCI_ATS_MIN_STU)
>>>>> return -EINVAL;
>>>>> - /*
>>>>> - * Note that enabling ATS on a VF fails unless it's already
>>>>> enabled
>>>>> - * with the same STU on the PF.
>>>>> - */
>>>>> ctrl = PCI_ATS_CTRL_ENABLE;
>>>>> if (dev->is_virtfn) {
>>>>> pdev = pci_physfn(dev);
>>>>> +
>>>>> + if (!pdev->ats_enabled &&
>>>>> + (pdev->ats_stu < PCI_ATS_MIN_STU)) {
>>>>> + u16 ctrl2;
>>>>> +
>>>>> + /* Associated PF's STU value applies to VFs. */
>>>>> + pdev->ats_stu = ps;
>>>>> + ctrl2 = PCI_ATS_CTRL_STU(pdev->ats_stu -
>>>>> PCI_ATS_MIN_STU);
>>>>> + pci_write_config_word(pdev, pdev->ats_cap +
>>>>> PCI_ATS_CTRL, ctrl2);
>>>>> + }
>>>
>>> For reference, it is this way because of edc90fee916b ("PCI: Allocate
>>> ATS struct during enumeration"). The rationale was that since the PF
>>> STU applies to all VFs, we should require that the PF STU be
>>> programmed before enabling ATS on any of the VFs.
>>>
>>> This patch relaxes that so the PF STU would be set either by (a)
>>> enabling ATS on the PF or (b) enabling ATS on the first VF.
>>>
>>> This looks racy because theoretically drivers for VF A and VF B could
>>> independently call pci_enable_ats() with different IOMMU page sizes,
>>> and we don't know which will get there first.
>>>
>>> Most callers supply a compile-time constant (PAGE_SHIFT or
>>> VTD_PAGE_SHIFT), so it won't matter. arm_smmu_enable_ats() is
>>> fancier, but I *assume* it would still supply the same IOMMU page size
>>> for all VFs of a given PF.
>>>
>>> But it's still kind of ugly to call pci_enable_ats(dev_A) and have it
>>> muck with the configuration of dev_B. Maybe we should configure the
>>> PF STU (without enabling ATS) at enumeration-time in pci_ats_init()?
>>> Is there some way to get the IOMMU page size at that time?
>>
>> Not really, on Arm the supported page sizes are discovered when probing
>> the SMMU registers, which may happen later than enumeration, during
>> module
>> loading.
>>
>> What this patch is trying to solve is:
>> * want the PF to bypass SMMU translation, and the VF to undergo SMMU
>> translation (in order to assign it to a VM)
>> * SMMU forbids enabling ATS for a configuration that bypasses
>> translation.
>> So the PF ATS capability must be left disabled.
>>
>> For this situation I wonder if we could do: the SMMU driver, seeing that
>> the PF is configured to bypass, calls a new function
>> "pci_configure_ats()"
>
> IMO, This seems to be feasible solution for this situation, which
> addresses SMMU-ATS expectation in bypass and we could avoid PCI VFs
> race. pci_configure_ats() can be called to program/configure STU of a PF
> in smmu-bypass mode.
>
Can we add pci_configure_ats/pci_configure_ats_stu helper?
>> instead of pci_enable_ats(), which would only set the STU but leave the
>> cap disabled. Then when setting up translation for the VF, the SMMU
>> driver
>> calls pci_enable_ats() as usual, which sees the PF's STU set
>> appropriately
>> and succeeds.
>>
>> Thanks,
>> Jean
>
> Thanks,
> Ganapat
Thanks,
Ganapat
next prev parent reply other threads:[~2023-02-21 9:13 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-08 18:43 Ganapatrao Kulkarni
2023-02-12 18:14 ` Leon Romanovsky
2023-02-15 20:57 ` Bjorn Helgaas
2023-02-16 7:26 ` Leon Romanovsky
2023-02-16 7:46 ` Leon Romanovsky
2023-02-16 10:47 ` Jean-Philippe Brucker
2023-02-16 10:23 ` Joerg Roedel
2023-02-16 11:12 ` Jean-Philippe Brucker
2023-02-16 11:36 ` Ganapatrao Kulkarni
2023-02-21 9:13 ` Ganapatrao Kulkarni [this message]
2023-02-21 15:46 ` Bjorn Helgaas
2023-02-23 15:45 ` Jean-Philippe Brucker
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=2fe43de6-f356-f996-c2cb-22f66f2bf593@os.amperecomputing.com \
--to=gankulkarni@os.amperecomputing.com \
--cc=bhelgaas@google.com \
--cc=darren@os.amperecomputing.com \
--cc=helgaas@kernel.org \
--cc=iommu@lists.linux.dev \
--cc=jean-philippe@linaro.org \
--cc=joro@8bytes.org \
--cc=leon@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=robin.murphy@arm.com \
--cc=scott@os.amperecomputing.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®