From: Nicolin Chen <nicolinc@nvidia.com>
To: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
Cc: <jgg@nvidia.com>, <linux-kernel@vger.kernel.org>,
<robin.murphy@arm.com>, <will@kernel.org>, <joro@8bytes.org>,
<kevin.tian@intel.com>, <jsnitsel@redhat.com>,
<vasant.hegde@amd.com>, <iommu@lists.linux.dev>,
<santosh.shukla@amd.com>, <sairaj.arunkodilkar@amd.com>,
<jon.grimm@amd.com>, <prashanthpra@google.com>, <wvw@google.com>,
<wnliu@google.com>, <gptran@google.com>, <kpsingh@google.com>,
<joao.m.martins@oracle.com>, <alejandro.j.jimenez@oracle.com>
Subject: Re: [PATCH v2 10/12] iommu/amd: Add support for nested domain allocation
Date: Thu, 2 Oct 2025 11:29:29 -0700 [thread overview]
Message-ID: <aN7Eie0PtZnp3jVl@Asurada-Nvidia> (raw)
In-Reply-To: <20251001060954.5030-11-suravee.suthikulpanit@amd.com>
On Wed, Oct 01, 2025 at 06:09:52AM +0000, Suravee Suthikulpanit wrote:
> The nested domain is allocated with IOMMU_DOMAIN_NESTED type to store
> stage-1 translation (i.e. GVA->GPA). This includes the GCR3 root pointer
> table along with guest page tables. The struct iommu_hwpt_amd_guest
> contains this information, and is passed from user-space as a parameter
> of the struct iommu_ops.domain_alloc_nested().
>
> Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
> diff --git a/drivers/iommu/amd/amd_iommu.h b/drivers/iommu/amd/amd_iommu.h
> index d533bb8851ea..cc1f14899dfe 100644
> --- a/drivers/iommu/amd/amd_iommu.h
> +++ b/drivers/iommu/amd/amd_iommu.h
> @@ -8,6 +8,7 @@
> #define AMD_IOMMU_H
>
> #include <linux/iommu.h>
> +#include <uapi/linux/iommufd.h>
>
> #include "amd_iommu_types.h"
amd_iommu_types.h is adding the uAPI header in this patch too. So,
this new "include" here is redundant.
> +++ b/drivers/iommu/amd/nested.c
> @@ -0,0 +1,67 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Copyright (C) 2025 Advanced Micro Devices, Inc.
> + */
> +
> +#define pr_fmt(fmt) "AMD-Vi: " fmt
> +#define dev_fmt(fmt) pr_fmt(fmt)
#define pr_fmt(fmt) "AMD-Vi: " fmt
#define dev_fmt pr_fmt
> +
> +#include <linux/iommu.h>
> +
> +#include "amd_iommu.h"
> +#include "amd_iommu_types.h"
amd_iommu.h covers both linux/iommu.h and amd_iommu_types.h.
> +struct iommu_domain *
> +amd_iommu_alloc_domain_nested(struct iommufd_viommu *viommu, u32 flags,
> + const struct iommu_user_data *user_data)
> +{
> + int ret;
> + struct iommu_hwpt_amd_guest gdte;
> + struct nested_domain *ndom;
> +
> + if (user_data->type != IOMMU_HWPT_DATA_AMD_GUEST)
> + return ERR_PTR(-EOPNOTSUPP);
> +
> + /*
> + * Need to make sure size of struct iommu_hwpt_amd_guest and
> + * struct dev_table_entry are the same since it will be copied
> + * from one to the other later on.
> + */
> + if (WARN_ON(sizeof(struct dev_table_entry) != sizeof(gdte)))
> + return ERR_PTR(-EINVAL);
static_assert(sizeof(struct dev_table_entry) == sizeof(gdte));
> +
> + ret = iommu_copy_struct_from_user(&gdte, user_data,
> + IOMMU_HWPT_DATA_AMD_GUEST,
> + dte);
> + if (ret)
> + return ERR_PTR(ret);
> +
> + ndom = kzalloc(sizeof(*ndom), GFP_KERNEL);
> + if (IS_ERR(ndom))
> + return ERR_PTR(-ENOMEM);
if (!ndom)
return ERR_PTR(-ENOMEM);
> +
> + ndom->domain.ops = &nested_domain_ops;
> + ndom->domain.type = IOMMU_DOMAIN_NESTED;
> + memcpy(&ndom->guest_dte, &gdte, sizeof(struct dev_table_entry));
> +
> + /* Due to possible aliasing issue use per-device nested domain ID */
> + ndom->id = amd_iommu_pdom_id_alloc();
> + if (ndom->id <= 0) {
> + ret = ndom->id;
> + goto out_err;
if ndom->id = 0, ret = 0, meaning this function does not fail..
Given that ida_alloc_range has the range [1, MAX_DOMAIN_ID - 1],
0 should never be returned. So just check if (ndom->id < 0) will
be enough.
Or you could override the "ret" entirely like other places do:
if (ndom->id <= 0) {
ret = -ENOSPC;
goto out_err;
}
With all these fixed,
Reviewed-by: Nicolin Chen <nicolinc@nvidia.com>
next prev parent reply other threads:[~2025-10-02 18:29 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-01 6:09 [PATCH v2 00/12] iommu/amd: Introduce Nested Translation support Suravee Suthikulpanit
2025-10-01 6:09 ` [PATCH v2 01/12] iommu/amd: Rename DEV_DOMID_MASK to DTE_DOMID_MASK Suravee Suthikulpanit
2025-10-02 17:12 ` Nicolin Chen
2025-10-06 14:36 ` Jason Gunthorpe
2025-10-01 6:09 ` [PATCH v2 02/12] iommu/amd: Make amd_iommu_pdom_id_alloc() non-static Suravee Suthikulpanit
2025-10-02 17:12 ` Nicolin Chen
2025-10-01 6:09 ` [PATCH v2 03/12] iommu/amd: Make amd_iommu_pdom_id_free() non-static Suravee Suthikulpanit
2025-10-02 17:13 ` Nicolin Chen
2025-10-06 14:37 ` Jason Gunthorpe
2025-10-01 6:09 ` [PATCH v2 04/12] iommu/amd: Make amd_iommu_device_flush_dte() non-static Suravee Suthikulpanit
2025-10-02 17:14 ` Nicolin Chen
2025-10-06 14:37 ` Jason Gunthorpe
2025-10-01 6:09 ` [PATCH v2 05/12] iommu/amd: Make amd_iommu_update_dte256() non-static Suravee Suthikulpanit
2025-10-02 17:15 ` Nicolin Chen
2025-10-01 6:09 ` [PATCH v2 06/12] iommu/amd: Make amd_iommu_make_clear_dte() non-static inline Suravee Suthikulpanit
2025-10-02 17:17 ` Nicolin Chen
2025-10-01 6:09 ` [PATCH v2 07/12] iommu/amd: Make amd_iommu_completion_wait() non-static Suravee Suthikulpanit
2025-10-02 17:24 ` Nicolin Chen
2025-10-01 6:09 ` [PATCH v2 08/12] iommufd: Introduce data struct for AMD nested domain allocation Suravee Suthikulpanit
2025-10-02 17:31 ` Nicolin Chen
2025-10-01 6:09 ` [PATCH v2 09/12] iommu/amd: Add support for nest parent " Suravee Suthikulpanit
2025-10-02 18:00 ` Nicolin Chen
2025-10-06 14:43 ` Jason Gunthorpe
2025-10-08 14:16 ` Suthikulpanit, Suravee
2025-10-01 6:09 ` [PATCH v2 10/12] iommu/amd: Add support for nested " Suravee Suthikulpanit
2025-10-02 18:29 ` Nicolin Chen [this message]
2025-10-06 14:49 ` Jason Gunthorpe
2025-10-07 20:36 ` Suthikulpanit, Suravee
2025-10-07 23:39 ` Jason Gunthorpe
2025-10-09 6:22 ` Sairaj Kodilkar
2025-10-09 9:16 ` Sairaj Kodilkar
2025-10-09 14:34 ` Jason Gunthorpe
2025-10-01 6:09 ` [PATCH v2 11/12] iommu/amd: Add support for nested domain attach/detach Suravee Suthikulpanit
2025-10-02 19:04 ` Nicolin Chen
2025-10-06 14:59 ` Jason Gunthorpe
2025-10-07 19:22 ` Suthikulpanit, Suravee
2025-10-07 23:43 ` Jason Gunthorpe
2025-10-09 7:18 ` Sairaj Kodilkar
2025-10-09 14:35 ` Jason Gunthorpe
2025-10-01 6:09 ` [PATCH v2 12/12] iommu/amd: Introduce IOMMUFD vIOMMU support for AMD Suravee Suthikulpanit
2025-10-02 20:05 ` Nicolin Chen
2025-10-06 15:01 ` Jason Gunthorpe
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=aN7Eie0PtZnp3jVl@Asurada-Nvidia \
--to=nicolinc@nvidia.com \
--cc=alejandro.j.jimenez@oracle.com \
--cc=gptran@google.com \
--cc=iommu@lists.linux.dev \
--cc=jgg@nvidia.com \
--cc=joao.m.martins@oracle.com \
--cc=jon.grimm@amd.com \
--cc=joro@8bytes.org \
--cc=jsnitsel@redhat.com \
--cc=kevin.tian@intel.com \
--cc=kpsingh@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=prashanthpra@google.com \
--cc=robin.murphy@arm.com \
--cc=sairaj.arunkodilkar@amd.com \
--cc=santosh.shukla@amd.com \
--cc=suravee.suthikulpanit@amd.com \
--cc=vasant.hegde@amd.com \
--cc=will@kernel.org \
--cc=wnliu@google.com \
--cc=wvw@google.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
Powered by JetHome