Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp893955ybl; Fri, 31 Jan 2020 09:53:42 -0800 (PST) X-Google-Smtp-Source: APXvYqzyanMQKn45uwkmG7HQi16AnQXY6rDKJzvHprtZ4MiF78m3WukNETCvMum/R4NvR9RmZtuY X-Received: by 2002:a05:6808:2cd:: with SMTP id a13mr7224625oid.82.1580493222589; Fri, 31 Jan 2020 09:53:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580493222; cv=none; d=google.com; s=arc-20160816; b=owCCa6ueLD865xpXl8KHanZBoRI5YCljxquHATT5CJUBBKxReKsUknCmrmjcocOosP dM3tWGu+ellLCG9Qp/QAKEF/SKgAUKfvjxU6ZxATsmPTg3FTHHtOpbj7fih86v+9RiIM ZpSq6+hFSjZ4CuZOmrDPb3JWBOFBQxSwx3aHRKxnJPevJ7IqnQJYIzmxRCtcbH8zH0Gj FNe/TULsVyV4jE4MTKUQYA0elIOXvu1bnHa+hJnxRNtEsscbVBirCnhEM9tQ6ZbmvZLJ 4o/Cz855l4eF4t6SI2OlPKw9bukxY0m0tdCOlPFg7P/dF+HtDvS/EZCIxc7KUTSps1kK BwQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=pDRNuCmYtwOU66+eE+D8xCSRw8GpZz2IhiJMImQf1D0=; b=wlZLwYb9HPSPwN6HIt+81AMId9EZggLjAAvyIAQfXqHXie4t4p21YmJxlVkRDf15Pg HXRKGU4qEtvOBM58hpzf8oQxXw2Pbvtd8Ev2sO+y7ZqJc4vqHOY8wOpYtYShuWirsq3H dBDDoucTkfyWatVI+xOKr/aPHGs4OcQ9+3dRkFGYgFuBOa57BYlug/vS6GVZ2kEg7ZoO mm2Qg3nSaiztkFPNRnSih9hSAxPNceHIRxqcoCXAdU/ber96BnBgfYTpUtYr+TSWA0FJ PkB5PxGyTvShDhe+H0YL18gINVnrDEQKhWOh+MxNqA+Pr9cJw/W2T8P7AJLDjZl8h+12 aA+w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 194si4654209oii.2.2020.01.31.09.53.30; Fri, 31 Jan 2020 09:53:42 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727198AbgAaRvN (ORCPT + 99 others); Fri, 31 Jan 2020 12:51:13 -0500 Received: from mga06.intel.com ([134.134.136.31]:63451 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727168AbgAaRvM (ORCPT ); Fri, 31 Jan 2020 12:51:12 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 31 Jan 2020 09:51:06 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,386,1574150400"; d="scan'208";a="377409500" Received: from jacob-builder.jf.intel.com (HELO jacob-builder) ([10.7.199.155]) by orsmga004.jf.intel.com with ESMTP; 31 Jan 2020 09:51:06 -0800 Date: Fri, 31 Jan 2020 09:56:21 -0800 From: Jacob Pan To: Alex Williamson Cc: iommu@lists.linux-foundation.org, LKML , "Lu Baolu" , Joerg Roedel , David Woodhouse , "Yi Liu" , "Tian, Kevin" , Raj Ashok , "Christoph Hellwig" , Jean-Philippe Brucker , Jonathan Cameron , Eric Auger , jacob.jun.pan@linux.intel.com Subject: Re: [PATCH 3/3] iommu/uapi: Add helper function for size lookup Message-ID: <20200131095621.6acec2fc@jacob-builder> In-Reply-To: <20200129144046.3f91e4c1@w520.home> References: <1580277724-66994-1-git-send-email-jacob.jun.pan@linux.intel.com> <1580277724-66994-4-git-send-email-jacob.jun.pan@linux.intel.com> <20200129144046.3f91e4c1@w520.home> Organization: OTC X-Mailer: Claws Mail 3.13.2 (GTK+ 2.24.30; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 29 Jan 2020 14:40:46 -0700 Alex Williamson wrote: > On Tue, 28 Jan 2020 22:02:04 -0800 > Jacob Pan 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 > > Signed-off-by: Jacob Pan > > --- > > 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; > yes, agreed. > If we add new types in future versions, I assume we'd back fill the > table with -EINVAL as well (rather than zero). Thanks, > right, if the array increase due to new types, the older version with the new type should be filled with -EINVAL. Let me document this in the rules of extensions. > 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; > [Jacob Pan]