From: Jason Gunthorpe <jgg@ziepe.ca>
To: Vasant Hegde <vasant.hegde@amd.com>
Cc: iommu@lists.linux.dev, joro@8bytes.org,
suravee.suthikulpanit@amd.com, wei.huang2@amd.com,
jsnitsel@redhat.com
Subject: Re: [PATCH v4 10/16] iommu/amd: Refactor helper function for setting / clearing GCR3
Date: Thu, 11 Jan 2024 09:26:23 -0400 [thread overview]
Message-ID: <20240111132623.GU50608@ziepe.ca> (raw)
In-Reply-To: <434bd095-0cbb-8220-66bc-371172a2312f@amd.com>
On Thu, Jan 11, 2024 at 05:22:02PM +0530, Vasant Hegde wrote:
>
>
> On 1/6/2024 12:42 AM, Jason Gunthorpe wrote:
> > On Tue, Dec 12, 2023 at 08:52:18AM +0000, Vasant Hegde wrote:
> >> +static int __set_gcr3(struct iommu_dev_data *dev_data,
> >> + ioasid_t pasid, unsigned long gcr3)
> >> +{
> >
> > IMHO you've got the ATS layering wrong here.. The ATS invalidation
> > should be pushed out by attach/detach functions and has to be
> > carefully sequenced with the ATS disable bit in the PCI control
> > register. I don't think you can do all of this right with things
> > organized like this. Indeed this looks like it over invalidates the
> > ATS quite a bit.
>
> Currently if device is capable of ATS we just enable it. Then we invalidate
> while setting/clearing GCR3. This is extra invalidation if we always clear the
> PASID before using it (as clear path would have invalidated IOTLB).
It is simpler if ATS can just be left on, but I'm not sure you can
actually do that when you get to nesting.
The guest and the hypervisor need to agree on the ATS state, if the
guest thinks ATS is off then the guest will not generate ATC
invalidations, which means the physical ATS has to be off too.
Thus all this needs to be carefully sequenced to be dynamic, and this
doesn't look layered well for that.
> > You should only need to invalidate prior to doing the enable and when
> > a GCR3 value is changed while ATS is turned on, which is something
> > that the attach op can caculate.
> >
> > So, these functions should have a signature of:
> >
> > (struct amd_iommu *iommu, struct struct gcr3_tbl_info *gcr3_info, ...)
>
> Not sure I understood this. This path is adding PASID to devices GCR3 table.
> Hence I pass device_data. It will set GCR[PASID] and invalidates TLB (Because
> its per device things, we can get the iommu details from dev_data itself).
I think it is wrong layering to make the GCR3 table linked to the
device, it should be an object indepdent of the device. Any place you
are passing a device into a gcr3 layer function looks suspect to me.
This is why I said you should put the domain_id in the gcr3 table,
because that is the proper layers for the objects and data.
> > [and the locking can implicitly rely on the core's group lock, don't
> > need more locks]
>
> I was waiting for group->mutex to export so that I can add lockdep_asset with
> that and remove device lock here. May be I can just remove it and expand the
> description.
If you want to use it just add a 'iommu_group_mutex_assert(dev)'. It
is a couple of lines
> >> +static int __clear_gcr3(struct iommu_dev_data *dev_data, ioasid_t pasid)
> >> +{
> >> + struct gcr3_tbl_info *gcr3_info = &dev_data->gcr3_info;
> >> + u64 *pte;
> >> +
> >> + lockdep_assert_held(&dev_data->lock);
> >> +
> >> + pte = __get_gcr3_pte(gcr3_info, pasid, false);
> >> + if (pte == NULL)
> >> + return -EINVAL;
> >> +
> >> + *pte = 0;
> >> + amd_iommu_dev_flush_pasid_all(dev_data, pasid);
> >> +
> >> + return 0;
> >> +}
> >
> > What is the point of clear? By the time the attach ops will want to do
> > clear it is already certain that a non-zero value was installed in
> > pasid, and this doesn't free any memory, so what is the point of
> > 'alloc=false'?
>
> This will fetch GCR3[PASID] and clears it.
>
> We use same __get_gcr3_pte() in set/clear path. Hence alloc=false is passed.
Just call set with 0 - again there is no point in having alloc=false
since this isn't called in any case where we don't already know the
that the entry was already allocated.
Also, most likely this eventally needs splitting up like SMMU did so
that allocating memory to get an entry pointer is separate from
setting that entry pointer as a driver should strive for "fail means
no change" implemenation of their domain attach function.
Jason
next prev parent reply other threads:[~2024-01-11 13:26 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-12 8:52 [PATCH v4 00/16] iommu/amd: SVA Support (part 3) - refactor support for GCR3 table Vasant Hegde
2023-12-12 8:52 ` [PATCH v4 01/16] iommu/amd: Pass struct iommu_dev_data to set_dte_entry() Vasant Hegde
2023-12-12 8:52 ` [PATCH v4 02/16] iommu/amd: Enable Guest Translation before registering devices Vasant Hegde
2024-01-05 18:17 ` Jason Gunthorpe
2023-12-12 8:52 ` [PATCH v4 03/16] iommu/amd: Introduce get_amd_iommu_from_dev() Vasant Hegde
2024-01-05 18:27 ` Jason Gunthorpe
2024-01-10 12:07 ` Vasant Hegde
2023-12-12 8:52 ` [PATCH v4 04/16] iommu/amd: Introduce struct protection_domain.pd_mode Vasant Hegde
2023-12-12 8:52 ` [PATCH v4 05/16] iommu/amd: Introduce per-device GCR3 table Vasant Hegde
2023-12-12 8:52 ` [PATCH v4 06/16] iommu/amd: Use protection_domain.flags to check page table mode Vasant Hegde
2024-01-05 18:28 ` Jason Gunthorpe
2023-12-12 8:52 ` [PATCH v4 07/16] iommu/amd: Introduce per-device domain ID to workaround potential TLB aliasing issue Vasant Hegde
2024-01-05 18:55 ` Jason Gunthorpe
2024-01-11 11:18 ` Vasant Hegde
2024-01-11 13:59 ` Jason Gunthorpe
2024-01-12 12:45 ` Vasant Hegde
2024-01-12 14:59 ` Jason Gunthorpe
2024-01-16 10:52 ` Vasant Hegde
2024-01-16 14:00 ` Jason Gunthorpe
2024-01-16 17:08 ` Vasant Hegde
2024-01-16 17:22 ` Jason Gunthorpe
2023-12-12 8:52 ` [PATCH v4 08/16] iommu/amd: Add support for device based TLB invalidation Vasant Hegde
2024-01-05 19:03 ` Jason Gunthorpe
2023-12-12 8:52 ` [PATCH v4 09/16] iommu/amd: Rearrange GCR3 table setup code Vasant Hegde
2024-01-05 19:04 ` Jason Gunthorpe
2023-12-12 8:52 ` [PATCH v4 10/16] iommu/amd: Refactor helper function for setting / clearing GCR3 Vasant Hegde
2024-01-05 19:12 ` Jason Gunthorpe
2024-01-11 11:52 ` Vasant Hegde
2024-01-11 13:26 ` Jason Gunthorpe [this message]
2024-01-12 9:00 ` Vasant Hegde
2023-12-12 8:52 ` [PATCH v4 11/16] iommu/amd: Refactor attaching / detaching device functions Vasant Hegde
2024-01-05 19:14 ` Jason Gunthorpe
2024-01-11 10:06 ` Vasant Hegde
2023-12-12 8:52 ` [PATCH v4 12/16] iommu/amd: Refactor protection_domain helper functions Vasant Hegde
2023-12-12 8:52 ` [PATCH v4 13/16] iommu/amd: Refactor GCR3 table " Vasant Hegde
2024-01-05 19:21 ` Jason Gunthorpe
2024-01-11 5:39 ` Vasant Hegde
2023-12-12 8:52 ` [PATCH v4 14/16] iommu/amd: Remove unused flush pasid functions Vasant Hegde
2024-01-05 19:22 ` Jason Gunthorpe
2023-12-12 8:52 ` [PATCH v4 15/16] iommu/amd: Rearrange device flush code Vasant Hegde
2024-01-05 19:22 ` Jason Gunthorpe
2023-12-12 8:52 ` [PATCH v4 16/16] iommu/amd: Remove unused GCR3 table parameters from struct protection_domain Vasant Hegde
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=20240111132623.GU50608@ziepe.ca \
--to=jgg@ziepe.ca \
--cc=iommu@lists.linux.dev \
--cc=joro@8bytes.org \
--cc=jsnitsel@redhat.com \
--cc=suravee.suthikulpanit@amd.com \
--cc=vasant.hegde@amd.com \
--cc=wei.huang2@amd.com \
/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