From: Vasant Hegde <vasant.hegde@amd.com>
To: Jason Gunthorpe <jgg@ziepe.ca>
Cc: iommu@lists.linux.dev, joro@8bytes.org,
suravee.suthikulpanit@amd.com, wei.huang2@amd.com,
jsnitsel@redhat.com
Subject: Re: [PATCH v6 07/15] iommu/amd: Setup GCR3 table in advance if domain is SVA capable
Date: Mon, 11 Mar 2024 16:50:01 +0530 [thread overview]
Message-ID: <6b01274c-043c-aa1c-1fdf-19df1bf2d6b2@amd.com> (raw)
In-Reply-To: <20240305001117.GB9225@ziepe.ca>
On 3/5/2024 5:41 AM, Jason Gunthorpe wrote:
> On Fri, Feb 09, 2024 at 11:29:22AM +0000, Vasant Hegde wrote:
>> SVA can be supported if domain is in passthrough mode or paging domain
>> with v2 page table. Current code sets up GCR3 table for domain with v2
>> page table only. Setup GCR3 table for all SVA capable domains.
>>
>> - Move GCR3 init/destroy to separate function.
>>
>> - Change default GCR3 table to use MAX supported PASIDs. Ideally it
>> should use 1 level PASID table as its using PASID zero only. But we
>> don't have support to extend PASID table yet. We will fix this later.
>>
>> - When domain is configured with passthrough mode, allocate default GCR3
>> table only if device is SVA capable.
>>
>> Note that in attach_device() path it will not know whether device will use
>> SVA or not. If device is attached to passthrough domain and if it doesn't
>> use SVA then GCR3 table will never be used. We will endup wasting memory
>> allocated for GCR3 table. This is done to avoid DTE update when
>> attaching PASID to device.
>
> It is certainly not elegant, but I can appreciate why you don't want
> to tackle the DTE update right now.
>
>> +/*
>> + * If domain is SVA capable then initialize GCR3 table. Also if domain is
>> + * in v2 page table mode then update GCR3[0].
>> + */
>> +static int init_gcr3_table(struct iommu_dev_data *dev_data,
>> + struct protection_domain *pdom)
>> +{
>> + struct amd_iommu *iommu = get_amd_iommu_from_dev_data(dev_data);
>> + int max_pasids = dev_data->max_pasids;
>> + int ret = 0;
>> +
>> + /*
>> + * If domain is in pt mode then setup GCR3 table only if device
>> + * is PASID capable
>> + */
>> + if (pdom_is_in_pt_mode(pdom) && !pdev_pasid_supported(dev_data))
>> + return ret;
>
> This logic seems like it would be clearer as:
>
> if (WARN_ON(gcr3_info->gcr3_tbl))
> return -EINVAL;
> if (pdom->domain.type == IOMMU_DOMAIN_IDENTITIY)
> max_pasids = dev_data->max_pasids;
> else if (pdom_is_v2_pgtbl_mode(pdom))
> max_pasids = min(1, dev_data->pasids);
> else
> max_pasids = 0;
>
> if (!max_pasids)
> return 0;
>
> ret = setup_gcr3_table(&dev_data->gcr3_info, iommu, max_pasids)
> if (ret)
> return ret;
> return 0;
Will look into it later.
>
>> +static void destroy_gcr3_table(struct iommu_dev_data *dev_data,
>> + struct protection_domain *pdom)
>> +{
>> + struct gcr3_tbl_info *gcr3_info = &dev_data->gcr3_info;
>> +
>> + if (pdom_is_v2_pgtbl_mode(pdom))
>> + update_gcr3(dev_data, 0, 0, false);
>
> This doesn't make alot of sense, we are about to free this table
> memory, why zero it and flush? If the DTE still points here we are in
> trouble!
This is for GCR3[0].. But yeah. detach path we can just ignore this and free
gcr3 table. Will fix it later.
>
> Similar comment for storing the gcr3 in init_gcr3_table(), that should
> just stay in the caller..
>
>> @@ -2010,10 +2068,8 @@ static void do_detach(struct iommu_dev_data *dev_data)
>> struct amd_iommu *iommu = get_amd_iommu_from_dev_data(dev_data);
>>
>> /* Clear GCR3 table */
>> - if (domain->pd_mode == PD_MODE_V2) {
>> - update_gcr3(dev_data, 0, 0, false);
>> - free_gcr3_table(&dev_data->gcr3_info);
>> - }
>> + if (pdom_is_sva_capable(domain))
>> + destroy_gcr3_table(dev_data, domain);
>
> if (dev_data->gcr3_info)
> destroy_gcr3_table(dev_data, domain);
Makes sense. I will post separate patch later.
>
> ?
>
> Don't really care how we got here..
>
> Anyhow, this looks like the right thing in the big picture, nit picks
> aside, so:
>
> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Thanks
-Vasant
next prev parent reply other threads:[~2024-03-11 11:20 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-09 11:29 [PATCH v6 00/15] iommu/amd: SVA Support (Part 4) - SVA and IOPF Vasant Hegde
2024-02-09 11:29 ` [PATCH v6 01/15] iommu/amd: Rename amd_iommu_v2_supported() as amd_iommu_pasid_supported() Vasant Hegde
2024-02-09 11:29 ` [PATCH v6 02/15] iommu/amd: Introduce per device DTE update function Vasant Hegde
2024-02-09 11:29 ` [PATCH v6 03/15] iommu/amd: Add support for enabling/disabling IOMMU features Vasant Hegde
2024-02-09 11:29 ` [PATCH v6 04/15] iommu/amd: Move PPR-related functions into ppr.c Vasant Hegde
2024-02-09 11:29 ` [PATCH v6 05/15] iommu/amd: Fix PPR interrupt processing logic Vasant Hegde
2024-02-09 11:29 ` [PATCH v6 06/15] iommu/amd: Introduce iommu_dev_data.max_pasids Vasant Hegde
2024-03-04 23:46 ` Jason Gunthorpe
2024-02-09 11:29 ` [PATCH v6 07/15] iommu/amd: Setup GCR3 table in advance if domain is SVA capable Vasant Hegde
2024-03-05 0:11 ` Jason Gunthorpe
2024-03-11 11:20 ` Vasant Hegde [this message]
2024-02-09 11:29 ` [PATCH v6 08/15] iommu/amd: Enable PCI features based on attached domain capability Vasant Hegde
2024-03-05 0:32 ` Jason Gunthorpe
2024-03-05 15:10 ` Vasant Hegde
2024-03-05 16:01 ` Jason Gunthorpe
2024-03-11 10:02 ` Vasant Hegde
2024-02-09 11:29 ` [PATCH v6 09/15] iommu/amd: Define per-IOMMU iopf_queue Vasant Hegde
2024-03-05 0:33 ` Jason Gunthorpe
2024-02-09 11:29 ` [PATCH v6 10/15] iommu/amd: Add support for page response Vasant Hegde
2024-03-05 0:35 ` Jason Gunthorpe
2024-02-09 11:29 ` [PATCH v6 11/15] iommu/amd: Add IO page fault notifier handler Vasant Hegde
2024-03-05 0:40 ` Jason Gunthorpe
2024-03-11 11:00 ` Vasant Hegde
2024-03-19 17:54 ` Jason Gunthorpe
2024-02-09 11:29 ` [PATCH v6 12/15] iommu/amd: Add support for enable/disable IOPF Vasant Hegde
2024-03-05 0:42 ` Jason Gunthorpe
2024-03-05 15:21 ` Vasant Hegde
2024-02-09 11:29 ` [PATCH v6 13/15] iommu/amd: Initial SVA support for AMD IOMMU Vasant Hegde
2024-03-05 0:50 ` Jason Gunthorpe
2024-03-11 11:11 ` Vasant Hegde
2024-03-19 17:56 ` Jason Gunthorpe
2024-03-27 6:15 ` Vasant Hegde
2024-02-09 11:29 ` [PATCH v6 14/15] iommu: Add ops->domain_alloc_sva() Vasant Hegde
2024-02-09 11:29 ` [PATCH v6 15/15] iommu/amd: Add SVA domain support Vasant Hegde
2024-03-05 0:52 ` [PATCH v6 00/15] iommu/amd: SVA Support (Part 4) - SVA and IOPF Jason Gunthorpe
2024-03-05 14:59 ` 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=6b01274c-043c-aa1c-1fdf-19df1bf2d6b2@amd.com \
--to=vasant.hegde@amd.com \
--cc=iommu@lists.linux.dev \
--cc=jgg@ziepe.ca \
--cc=joro@8bytes.org \
--cc=jsnitsel@redhat.com \
--cc=suravee.suthikulpanit@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