All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joao Martins <joao.m.martins@oracle.com>
To: "Suthikulpanit, Suravee" <suravee.suthikulpanit@amd.com>,
	iommu@lists.linux.dev
Cc: Jason Gunthorpe <jgg@nvidia.com>,
	Kevin Tian <kevin.tian@intel.com>,
	Shameerali Kolothum Thodi <shameerali.kolothum.thodi@huawei.com>,
	Lu Baolu <baolu.lu@linux.intel.com>, Yi Liu <yi.l.liu@intel.com>,
	Yi Y Sun <yi.y.sun@intel.com>, Nicolin Chen <nicolinc@nvidia.com>,
	Joerg Roedel <joro@8bytes.org>, Will Deacon <will@kernel.org>,
	Robin Murphy <robin.murphy@arm.com>,
	Alex Williamson <alex.williamson@redhat.com>,
	kvm@vger.kernel.org
Subject: Re: [PATCH v3 16/19] iommu/amd: Add domain_alloc_user based domain allocation
Date: Tue, 17 Oct 2023 10:07:11 +0100	[thread overview]
Message-ID: <401bae66-b1b4-4d02-b50b-ab2e4e2f4e2d@oracle.com> (raw)
In-Reply-To: <6c1a0f25-f701-8448-d46c-15c9848f90a3@amd.com>

On 17/10/2023 03:00, Suthikulpanit, Suravee wrote:
> Hi Joao,
> 
> On 9/23/2023 8:25 AM, Joao Martins wrote:
>> Add the domain_alloc_user op implementation. To that end, refactor
>> amd_iommu_domain_alloc() to receive a dev pointer and flags, while
>> renaming it to .. such that it becomes a common function shared with
>> domain_alloc_user() implementation. The sole difference with
>> domain_alloc_user() is that we initialize also other fields that
>> iommu_domain_alloc() does. It lets it return the iommu domain
>> correctly initialized in one function.
>>
>> This is in preparation to add dirty enforcement on AMD implementation
>> of domain_alloc_user.
>>
>> Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
>> ---
>>   drivers/iommu/amd/iommu.c | 46 ++++++++++++++++++++++++++++++++++++---
>>   1 file changed, 43 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
>> index 95bd7c25ba6f..af36c627022f 100644
>> --- a/drivers/iommu/amd/iommu.c
>> +++ b/drivers/iommu/amd/iommu.c
>> @@ -37,6 +37,7 @@
>>   #include <asm/iommu.h>
>>   #include <asm/gart.h>
>>   #include <asm/dma.h>
>> +#include <uapi/linux/iommufd.h>
>>     #include "amd_iommu.h"
>>   #include "../dma-iommu.h"
>> @@ -2155,7 +2156,10 @@ static inline u64 dma_max_address(void)
>>       return ((1ULL << PM_LEVEL_SHIFT(amd_iommu_gpt_level)) - 1);
>>   }
>>   -static struct iommu_domain *amd_iommu_domain_alloc(unsigned type)
>> +static struct iommu_domain *do_iommu_domain_alloc(unsigned int type,
>> +                          struct amd_iommu *iommu,
>> +                          struct device *dev,
>> +                          u32 flags)
> 
> Instead of passing in the struct amd_iommu here, what if we just derive it in
> the do_iommu_domain_alloc() as needed? This way, we don't need to ... (see below)
> 
Hmm, you mean to derive amd_iommu from the dev pointer. Yeah, sounds good.

>>   {
>>       struct protection_domain *domain;
>>   @@ -2164,19 +2168,54 @@ static struct iommu_domain
>> *amd_iommu_domain_alloc(unsigned type)
>>        * default to use IOMMU_DOMAIN_DMA[_FQ].
>>        */
>>       if (amd_iommu_snp_en && (type == IOMMU_DOMAIN_IDENTITY))
>> -        return NULL;
>> +        return ERR_PTR(-EINVAL);
>>         domain = protection_domain_alloc(type);
>>       if (!domain)
>> -        return NULL;
>> +        return ERR_PTR(-ENOMEM);
>>         domain->domain.geometry.aperture_start = 0;
>>       domain->domain.geometry.aperture_end   = dma_max_address();
>>       domain->domain.geometry.force_aperture = true;
>>   +    if (dev) {
>> +        domain->domain.type = type;
>> +        domain->domain.pgsize_bitmap =
>> +            iommu->iommu.ops->pgsize_bitmap;
>> +        domain->domain.ops =
>> +            iommu->iommu.ops->default_domain_ops;
>> +    }
>> +
>>       return &domain->domain;
>>   }
>>   +static struct iommu_domain *amd_iommu_domain_alloc(unsigned type)
>> +{
>> +    struct iommu_domain *domain;
>> +
>> +    domain = do_iommu_domain_alloc(type, NULL, NULL, 0);
> 
> ... pass iommu = NULL here unnecessarily.
> 
OK

>> +    if (IS_ERR(domain))
>> +        return NULL;
>> +
>> +    return domain;
>> +}
>> +
>> +static struct iommu_domain *amd_iommu_domain_alloc_user(struct device *dev,
>> +                            u32 flags)
>> +{
>> +    unsigned int type = IOMMU_DOMAIN_UNMANAGED;
>> +    struct amd_iommu *iommu;
>> +
>> +    iommu = rlookup_amd_iommu(dev);
>> +    if (!iommu)
>> +        return ERR_PTR(-ENODEV);
> 
> We should not need to derive this here.
> 
> Other than this part.
> 

OK, will do.

> Reviewed-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
> 
Thanks!

Here's the diff

diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
index af36c627022f..cfc7d2992aa6 100644
--- a/drivers/iommu/amd/iommu.c
+++ b/drivers/iommu/amd/iommu.c
@@ -2157,11 +2157,17 @@ static inline u64 dma_max_address(void)
 }

 static struct iommu_domain *do_iommu_domain_alloc(unsigned int type,
-                                                 struct amd_iommu *iommu,
                                                  struct device *dev,
                                                  u32 flags)
 {
        struct protection_domain *domain;
+       struct amd_iommu *iommu = NULL;
+
+       if (dev) {
+               iommu = rlookup_amd_iommu(dev);
+               if (!iommu)
+                       return ERR_PTR(-ENODEV);
+       }

        /*
         * Since DTE[Mode]=0 is prohibited on SNP-enabled system,
@@ -2178,7 +2184,7 @@ static struct iommu_domain *do_iommu_domain_alloc(unsigned
int type,
        domain->domain.geometry.aperture_end   = dma_max_address();
        domain->domain.geometry.force_aperture = true;

-       if (dev) {
+       if (iommu) {
                domain->domain.type = type;
                domain->domain.pgsize_bitmap =
                        iommu->iommu.ops->pgsize_bitmap;
@@ -2193,7 +2199,7 @@ static struct iommu_domain
*amd_iommu_domain_alloc(unsigned type)
 {
        struct iommu_domain *domain;

-       domain = do_iommu_domain_alloc(type, NULL, NULL, 0);
+       domain = do_iommu_domain_alloc(type, NULL, 0);
        if (IS_ERR(domain))
                return NULL;

@@ -2204,16 +2210,11 @@ static struct iommu_domain
*amd_iommu_domain_alloc_user(struct device *dev,
                                                        u32 flags)
 {
        unsigned int type = IOMMU_DOMAIN_UNMANAGED;
-       struct amd_iommu *iommu;
-
-       iommu = rlookup_amd_iommu(dev);
-       if (!iommu)
-               return ERR_PTR(-ENODEV);

        if (flags & IOMMU_HWPT_ALLOC_NEST_PARENT)
                return ERR_PTR(-EOPNOTSUPP);

-       return do_iommu_domain_alloc(type, iommu, dev, flags);
+       return do_iommu_domain_alloc(type, dev, flags);
 }

  reply	other threads:[~2023-10-17  9:07 UTC|newest]

Thread overview: 140+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-23  1:24 [PATCH v3 00/19] IOMMUFD Dirty Tracking Joao Martins
2023-09-23  1:24 ` [PATCH v3 01/19] vfio/iova_bitmap: Export more API symbols Joao Martins
2023-10-13 15:43   ` Jason Gunthorpe
2023-10-13 15:57     ` Joao Martins
2023-10-13 16:03       ` Jason Gunthorpe
2023-10-13 16:22         ` Joao Martins
2023-09-23  1:24 ` [PATCH v3 02/19] vfio: Move iova_bitmap into iommu core Joao Martins
2023-10-13 15:48   ` Jason Gunthorpe
2023-10-13 16:00     ` Joao Martins
2023-10-13 16:04       ` Jason Gunthorpe
2023-10-13 16:23         ` Joao Martins
2023-10-13 17:10       ` Joao Martins
2023-10-13 17:16         ` Jason Gunthorpe
2023-10-13 17:23           ` Joao Martins
2023-10-13 17:28             ` Jason Gunthorpe
2023-10-13 17:32               ` Joao Martins
2023-10-13 20:41             ` Alex Williamson
2023-10-13 21:20               ` Joao Martins
2023-10-13 21:51                 ` Alex Williamson
2023-10-14  0:02                   ` Jason Gunthorpe
2023-10-16 16:25                     ` Joao Martins
2023-10-16 16:34                       ` Jason Gunthorpe
2023-10-16 17:52                         ` Joao Martins
2023-10-16 18:05                           ` Jason Gunthorpe
2023-10-16 18:15                             ` Joao Martins
2023-10-16 18:20                               ` Jason Gunthorpe
2023-10-16 18:37                                 ` Joao Martins
2023-10-16 18:50                                   ` Joao Martins
2023-10-17 12:58                                     ` Jason Gunthorpe
2023-10-17 15:20                                       ` Joao Martins
2023-10-17 15:23                                         ` Jason Gunthorpe
2023-10-17 15:44                                           ` Joao Martins
2023-10-18 10:19                             ` Joao Martins
2023-10-18 12:03                               ` Jason Gunthorpe
2023-10-18 12:48                                 ` Joao Martins
2023-10-18 14:23                                   ` Jason Gunthorpe
2023-10-18 15:34                                     ` Joao Martins
2023-10-18 15:43                                       ` Jason Gunthorpe
2023-09-23  1:24 ` [PATCH v3 03/19] iommu: Add iommu_domain ops for dirty tracking Joao Martins
2023-10-13 16:05   ` Jason Gunthorpe
2023-10-13 16:27     ` Joao Martins
2023-09-23  1:24 ` [PATCH v3 04/19] iommufd: Add a flag to enforce dirty tracking on attach Joao Martins
2023-10-13 15:52   ` Jason Gunthorpe
2023-10-13 16:14     ` Joao Martins
2023-10-13 16:16       ` Jason Gunthorpe
2023-10-13 16:29         ` Joao Martins
2023-09-23  1:24 ` [PATCH v3 05/19] iommufd/selftest: Expand mock_domain with dev_flags Joao Martins
2023-10-13 16:02   ` Jason Gunthorpe
2023-10-13 16:21     ` Joao Martins
2023-09-23  1:24 ` [PATCH v3 06/19] iommufd/selftest: Test IOMMU_HWPT_ALLOC_ENFORCE_DIRTY Joao Martins
2023-09-23  1:24 ` [PATCH v3 07/19] iommufd: Dirty tracking data support Joao Martins
2023-09-23  1:40   ` Joao Martins
2023-10-17 12:06     ` Joao Martins
2023-10-17 15:29       ` Jason Gunthorpe
2023-10-17 15:51         ` Joao Martins
2023-10-17 16:01           ` Jason Gunthorpe
2023-10-17 16:51             ` Joao Martins
2023-10-17 17:13               ` Jason Gunthorpe
2023-10-17 17:30                 ` Joao Martins
2023-10-17 18:14                   ` Joao Martins
2023-09-23  1:25 ` [PATCH v3 08/19] iommufd: Add IOMMU_HWPT_SET_DIRTY Joao Martins
2023-10-13 16:13   ` Jason Gunthorpe
2023-09-23  1:25 ` [PATCH v3 09/19] iommufd/selftest: Test IOMMU_HWPT_SET_DIRTY Joao Martins
2023-09-23  1:25 ` [PATCH v3 10/19] iommufd: Add IOMMU_HWPT_GET_DIRTY_IOVA Joao Martins
2023-10-13 16:22   ` Jason Gunthorpe
2023-10-13 16:58     ` Joao Martins
2023-10-13 17:03       ` Jason Gunthorpe
2023-09-23  1:25 ` [PATCH v3 11/19] iommufd/selftest: Test IOMMU_HWPT_GET_DIRTY_IOVA Joao Martins
2023-09-23  1:25 ` [PATCH v3 12/19] iommufd: Add capabilities to IOMMU_GET_HW_INFO Joao Martins
2023-09-23  1:25 ` [PATCH v3 13/19] iommufd/selftest: Test out_capabilities in IOMMU_GET_HW_INFO Joao Martins
2023-09-23  1:25 ` [PATCH v3 14/19] iommufd: Add a flag to skip clearing of IOPTE dirty Joao Martins
2023-09-23  1:25 ` [PATCH v3 15/19] iommufd/selftest: Test IOMMU_GET_DIRTY_IOVA_NO_CLEAR flag Joao Martins
2023-09-23  1:25 ` [PATCH v3 16/19] iommu/amd: Add domain_alloc_user based domain allocation Joao Martins
2023-10-17  2:00   ` Suthikulpanit, Suravee
2023-10-17  9:07     ` Joao Martins [this message]
2023-10-17 13:10       ` Jason Gunthorpe
2023-10-17 14:14         ` Joao Martins
2023-10-17 14:37           ` Joao Martins
2023-10-17 15:32             ` Jason Gunthorpe
2023-10-18  8:29             ` Vasant Hegde
2023-09-23  1:25 ` [PATCH v3 17/19] iommu/amd: Access/Dirty bit support in IOPTEs Joao Martins
2023-10-04 17:01   ` Joao Martins
2023-10-17  8:18   ` Suthikulpanit, Suravee
2023-10-17  9:54     ` Joao Martins
2023-10-17 18:32       ` Joao Martins
2023-10-17 18:49         ` Jason Gunthorpe
2023-10-17 19:03           ` Joao Martins
2023-10-17 22:04             ` Joao Martins
2023-10-18 11:47               ` Suthikulpanit, Suravee
2023-10-18 20:40             ` Joao Martins
2023-10-18 11:46       ` Suthikulpanit, Suravee
2023-10-18 13:04       ` Suthikulpanit, Suravee
2023-10-18 13:17         ` Joao Martins
2023-10-18 13:31           ` Joao Martins
2023-10-18 15:50         ` Jason Gunthorpe
2023-09-23  1:25 ` [PATCH v3 18/19] iommu/amd: Print access/dirty bits if supported Joao Martins
2023-10-17  3:48   ` Suthikulpanit, Suravee
2023-10-17  9:07     ` Joao Martins
2023-10-18  8:32   ` Vasant Hegde
2023-10-18  8:53     ` Joao Martins
2023-10-18  9:03       ` Vasant Hegde
2023-10-18  9:05         ` Joao Martins
2023-10-18 15:52         ` Jason Gunthorpe
2023-10-18 15:55           ` Joao Martins
2023-09-23  1:25 ` [PATCH v3 19/19] iommu/intel: Access/Dirty bit support for SL domains Joao Martins
2023-09-25  7:01   ` Baolu Lu
2023-09-25  9:08     ` Joao Martins
2023-10-16  2:26       ` Baolu Lu
2023-10-16  0:51   ` Baolu Lu
2023-10-16 10:42     ` Joao Martins
2023-10-16 12:41       ` Baolu Lu
2023-10-16  1:37   ` Baolu Lu
2023-10-16 10:57     ` Joao Martins
2023-10-16 11:42       ` Jason Gunthorpe
2023-10-16 12:58         ` Baolu Lu
2023-10-16 12:59           ` Jason Gunthorpe
2023-10-16 13:01             ` Baolu Lu
2023-10-17 10:51               ` Joao Martins
2023-10-17 12:41                 ` Baolu Lu
2023-10-17 14:16                   ` Joao Martins
2023-10-17 14:25                     ` Joao Martins
2023-10-18  2:06                       ` Baolu Lu
2023-10-16  2:07   ` Baolu Lu
2023-10-16 11:26     ` Joao Martins
2023-10-16 16:00       ` Joao Martins
2023-10-17  2:08         ` Baolu Lu
2023-10-17 11:22           ` Joao Martins
2023-10-17 12:49             ` Baolu Lu
2023-10-17 14:19               ` Joao Martins
2023-10-17 13:10             ` Jason Gunthorpe
2023-10-17 14:11               ` Joao Martins
2023-10-17 15:31                 ` Jason Gunthorpe
2023-10-17 15:54                   ` Joao Martins
2023-10-16  2:21   ` Baolu Lu
2023-10-16 11:39     ` Joao Martins
2023-10-16 13:06       ` Baolu Lu
2023-09-26  8:58 ` [PATCH v3 00/19] IOMMUFD Dirty Tracking Shameerali Kolothum Thodi
2023-10-13 16:29 ` Jason Gunthorpe
2023-10-13 18:11   ` Joao Martins
2023-10-14  7:53     ` Baolu Lu

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=401bae66-b1b4-4d02-b50b-ab2e4e2f4e2d@oracle.com \
    --to=joao.m.martins@oracle.com \
    --cc=alex.williamson@redhat.com \
    --cc=baolu.lu@linux.intel.com \
    --cc=iommu@lists.linux.dev \
    --cc=jgg@nvidia.com \
    --cc=joro@8bytes.org \
    --cc=kevin.tian@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=nicolinc@nvidia.com \
    --cc=robin.murphy@arm.com \
    --cc=shameerali.kolothum.thodi@huawei.com \
    --cc=suravee.suthikulpanit@amd.com \
    --cc=will@kernel.org \
    --cc=yi.l.liu@intel.com \
    --cc=yi.y.sun@intel.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 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.