From: Alex Williamson <alex.williamson@redhat.com>
To: Jacob Pan <jacob.jun.pan@linux.intel.com>
Cc: iommu@lists.linux-foundation.org,
LKML <linux-kernel@vger.kernel.org>,
"Lu Baolu" <baolu.lu@linux.intel.com>,
Joerg Roedel <joro@8bytes.org>,
David Woodhouse <dwmw2@infradead.org>,
"Yi Liu" <yi.l.liu@intel.com>,
"Tian, Kevin" <kevin.tian@intel.com>,
Raj Ashok <ashok.raj@intel.com>,
"Christoph Hellwig" <hch@infradead.org>,
Jean-Philippe Brucker <jean-philippe@linaro.com>,
Jonathan Cameron <jic23@kernel.org>,
Eric Auger <eric.auger@redhat.com>
Subject: Re: [PATCH 3/3] iommu/uapi: Add helper function for size lookup
Date: Wed, 29 Jan 2020 14:40:46 -0700 [thread overview]
Message-ID: <20200129144046.3f91e4c1@w520.home> (raw)
In-Reply-To: <1580277724-66994-4-git-send-email-jacob.jun.pan@linux.intel.com>
On Tue, 28 Jan 2020 22:02:04 -0800
Jacob Pan <jacob.jun.pan@linux.intel.com> wrote:
> IOMMU UAPI can be extended in the future by adding new
> fields at the end of each user data structure. Since we use
> a unified UAPI version for compatibility checking, a lookup
> function is needed to find the correct user data size to copy
> from user.
>
> This patch adds a helper function based on a 2D lookup with
> version and type as input arguments.
>
> Signed-off-by: Liu Yi L <yi.l.liu@intel.com>
> Signed-off-by: Jacob Pan <jacob.jun.pan@linux.intel.com>
> ---
> drivers/iommu/iommu.c | 22 ++++++++++++++++++++++
> include/linux/iommu.h | 6 ++++++
> 2 files changed, 28 insertions(+)
>
> diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
> index 7dd51c5d2ba1..9e5de9abebdf 100644
> --- a/drivers/iommu/iommu.c
> +++ b/drivers/iommu/iommu.c
> @@ -1696,6 +1696,28 @@ int iommu_sva_unbind_gpasid(struct iommu_domain *domain, struct device *dev,
> }
> EXPORT_SYMBOL_GPL(iommu_sva_unbind_gpasid);
>
> +
> +/**
> + * Maintain a UAPI version to user data structure size lookup for each
> + * API function types we support. e.g. bind guest pasid, cache invalidation.
> + * As data structures being extended with new members, the offsetofend()
> + * will identify the new sizes.
> + */
> +const static int iommu_uapi_data_size[NR_IOMMU_UAPI_TYPE][IOMMU_UAPI_VERSION] = {
> + /* IOMMU_UAPI_BIND_GPASID */
> + {offsetofend(struct iommu_gpasid_bind_data, vtd)},
> + /* IOMMU_UAPI_CACHE_INVAL */
> + {offsetofend(struct iommu_cache_invalidate_info, addr_info)},
> + /* IOMMU_UAPI_PAGE_RESP */
> + {offsetofend(struct iommu_page_response, code)},
> +};
> +
> +int iommu_uapi_get_data_size(int type, int version)
> +{
Seems like this is asking for a bounds check,
if (type >= NR_IOMMU_UAPI_TYPE || version > IOMMU_UAPI_VERSION)
return -EINVAL;
If we add new types in future versions, I assume we'd back fill the
table with -EINVAL as well (rather than zero). Thanks,
Alex
> + return iommu_uapi_data_size[type][version - 1];
> +}
> +EXPORT_SYMBOL_GPL(iommu_uapi_get_data_size);
> +
> static void __iommu_detach_device(struct iommu_domain *domain,
> struct device *dev)
> {
> diff --git a/include/linux/iommu.h b/include/linux/iommu.h
> index 9718c109ea0a..416fe02160ba 100644
> --- a/include/linux/iommu.h
> +++ b/include/linux/iommu.h
> @@ -500,6 +500,7 @@ extern int iommu_report_device_fault(struct device *dev,
> struct iommu_fault_event *evt);
> extern int iommu_page_response(struct device *dev,
> struct iommu_page_response *msg);
> +extern int iommu_uapi_get_data_size(int type, int version);
>
> extern int iommu_group_id(struct iommu_group *group);
> extern struct iommu_group *iommu_group_get_for_dev(struct device *dev);
> @@ -885,6 +886,11 @@ static inline int iommu_page_response(struct device *dev,
> return -ENODEV;
> }
>
> +static int iommu_uapi_get_data_size(int type, int version)
> +{
> + return -ENODEV;
> +}
> +
> static inline int iommu_group_id(struct iommu_group *group)
> {
> return -ENODEV;
next prev parent reply other threads:[~2020-01-29 21:40 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-29 6:02 [PATCH 0/3] IOMMU user API enhancement Jacob Pan
2020-01-29 6:02 ` [PATCH 1/3] iommu/uapi: Define uapi version and capabilities Jacob Pan
2020-02-06 10:14 ` Auger Eric
2020-02-06 18:22 ` Jacob Pan
2020-01-29 6:02 ` [PATCH 2/3] iommu/uapi: Use unified UAPI version Jacob Pan
2020-01-29 6:02 ` [PATCH 3/3] iommu/uapi: Add helper function for size lookup Jacob Pan
2020-01-29 21:40 ` Alex Williamson [this message]
2020-01-29 22:19 ` Alex Williamson
2020-01-31 19:51 ` Jacob Pan
2020-01-31 23:51 ` Jacob Pan
2020-02-03 18:27 ` Alex Williamson
2020-02-03 20:41 ` Jacob Pan
2020-02-03 21:12 ` Alex Williamson
2020-02-03 22:41 ` Jacob Pan
2020-02-06 10:14 ` Auger Eric
2020-02-07 8:47 ` Jean-Philippe Brucker
2020-01-31 17:56 ` Jacob Pan
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=20200129144046.3f91e4c1@w520.home \
--to=alex.williamson@redhat.com \
--cc=ashok.raj@intel.com \
--cc=baolu.lu@linux.intel.com \
--cc=dwmw2@infradead.org \
--cc=eric.auger@redhat.com \
--cc=hch@infradead.org \
--cc=iommu@lists.linux-foundation.org \
--cc=jacob.jun.pan@linux.intel.com \
--cc=jean-philippe@linaro.com \
--cc=jic23@kernel.org \
--cc=joro@8bytes.org \
--cc=kevin.tian@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=yi.l.liu@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 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®