Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp199620ybl; Tue, 28 Jan 2020 21:58:11 -0800 (PST) X-Google-Smtp-Source: APXvYqzh4lpixoxIa0iOLhkKUfnKSeVHGIrlV7fjls4JUSeVhl+0J41TW8RU/eq4VOUV2yIiXnaj X-Received: by 2002:aca:c692:: with SMTP id w140mr5658603oif.139.1580277491579; Tue, 28 Jan 2020 21:58:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580277491; cv=none; d=google.com; s=arc-20160816; b=NOIs9sB5i4sJpO4Z8Mk2E+FqeToD/E6/wx8dzs+EmqPbT448U5twAaYBG9D0dnuWpH bDB6kWTdJoA3mwxpWnk3PNXkD43hMQN3ZGUsF87HeZW0GcVgroNjTFAuYIrgzKW0o0IQ Fyq2WLA0JPzSxN15pDR5TNKLewfq06BD0rU8NhSV1PzaPE2cDuOE4D7iBH+GIbGr0p5K GHoQl3Zt72+yZ4SyNEDuudgmfr9lDGQThGj/aeR1N9BKAFIm38IeRVEJS+hNxajjFUVG cOh6ziXOeLLGkp6y91t7iWlzfaU2+fmHEPrvoztkCxRHosE4lLrM3lnh8+PnMPn4hRyH nFWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=HThS9OEWJRfdApLigT4X9NwElIcV3dDTVPwqljyRP4g=; b=p+L4NJum6iA2PbivNgc9UE/CQfNmClbfWCe/BML4H+AH4SGZvk6jVVEJPNA6WiDxT0 FYAj4qvGt1yToV25dimYqrLAXbNHo/Tu6MAnS6RIGhObkSXS0pMwyx9yjYC2ypi3727/ LZAsWQQZz5E2fsoZ5u466erzJ/7hVCPwlxWf2YLDB9T2ndEDtx6U25+pOBXxs2HTHBkg V0jF/A4KR2CU94qjNMGjDH0b7M2TTCKWyQWqfWKS3LLd7mlpY+Hu9kJ3ZCHgHOUQmcE4 HJXty0mjly5pRnhjuErnsGwLZ/FVm5jOxq1NQwCIjuAyRSEDvqKGZs641H544S6ygmWB I3og== 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 h9si623465oie.74.2020.01.28.21.57.59; Tue, 28 Jan 2020 21:58:11 -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 S1726659AbgA2F5A (ORCPT + 99 others); Wed, 29 Jan 2020 00:57:00 -0500 Received: from mga09.intel.com ([134.134.136.24]:55027 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726590AbgA2F4y (ORCPT ); Wed, 29 Jan 2020 00:56:54 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Jan 2020 21:56:54 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,376,1574150400"; d="scan'208";a="252500720" Received: from jacob-builder.jf.intel.com ([10.7.199.155]) by fmsmga004.fm.intel.com with ESMTP; 28 Jan 2020 21:56:53 -0800 From: Jacob Pan To: iommu@lists.linux-foundation.org, LKML , "Lu Baolu" , Joerg Roedel , David Woodhouse Cc: "Yi Liu" , "Tian, Kevin" , Raj Ashok , Alex Williamson , "Christoph Hellwig" , Jean-Philippe Brucker , Jonathan Cameron , Eric Auger , Jacob Pan Subject: [PATCH 3/3] iommu/uapi: Add helper function for size lookup Date: Tue, 28 Jan 2020 22:02:04 -0800 Message-Id: <1580277724-66994-4-git-send-email-jacob.jun.pan@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1580277724-66994-1-git-send-email-jacob.jun.pan@linux.intel.com> References: <1580277724-66994-1-git-send-email-jacob.jun.pan@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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) +{ + 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; -- 2.7.4