From patchwork Thu May 11 14:30:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 92662 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp4429285vqo; Thu, 11 May 2023 07:44:31 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4NMLx0NQDaL4tDHXrCmLYmC+/0yWIV4OHW+VMInqLCFu74UkpjLIhoEjWAXNfHQ0NtfHxJ X-Received: by 2002:a05:6a21:789c:b0:100:607:b986 with SMTP id bf28-20020a056a21789c00b001000607b986mr19898344pzc.56.1683816270897; Thu, 11 May 2023 07:44:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683816270; cv=none; d=google.com; s=arc-20160816; b=PPOuooopOuuEdeUrp9jRshk8AahBFm805x12HWDq2Vl0UBTx5w+X62pqx1ZDoXUdQD VDcQJRlGEBbWUTRzW0doyVdP/0TzKjPGWW2NNEk09NYiceXuoUn5X5nSRLSydIKNzvYa TNeWi37KBiYdpLWmXoZ/DyAxt1cdoBAk1Xyhl6JL83ke4MJacATtOkXByi53AXouBkno YDfUDPJTBHJ9pqK5iBM6ns2BSC9JWBmTyvhf643/EeP8DmRdu8DeZGj2WyF7izVxULGf N7wmUy2nOzAetqwPnuVOUgKwqZPtrbbQGkuW2uuqK005DcTP0wYPKVnoZY7bXyqJws45 di6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=8wUyUguSznca4W4L+1Ue781UC7aKJqVn4P3/+V3vb0M=; b=QBOIGXghpzRXCEBxuzGWkrVbW5PeK6AOvawgccsAkSAbG3pOc+t/9zfsqh43DktOmu +UI8lU9iARX+HH9A3z76h5log6PiL54/EjPjsf9SsQv0fwuk8lZrqz0TKpaYZtsaXr2G 4XZ05Znh5vC5mr6sFJlMuFDuprOWSphPa8VzKfi8n4anv59C92Tu0QPAanRpwTjv45PO UuNcbgmnE0eA6Z2cbz6NrcXVhGB8vVVnl0xmiOncI/1j/ip/txqJ0B5lwDQ0G4yV4ReG B6LtRvUgdzbed+ZYS33H8dIu2BxhKNV9vh0OAys1yhwJtYOuonuBfqP88rftLn96KSGJ Sr3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=cLJQPurY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bs126-20020a632884000000b0052023579876si6738527pgb.710.2023.05.11.07.44.18; Thu, 11 May 2023 07:44:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=cLJQPurY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238579AbjEKOcU (ORCPT + 99 others); Thu, 11 May 2023 10:32:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238556AbjEKObZ (ORCPT ); Thu, 11 May 2023 10:31:25 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F87610E43; Thu, 11 May 2023 07:30:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1683815452; x=1715351452; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=nrDK8GkK0LqwlZMb1ilRfBE7tsHA7HCzaP978cfWRvc=; b=cLJQPurYUAVIv5cnSG9Pu51wqeg6/KQZQdmu8Ba+ekKDP5JC3iIiEJw6 CKFQ/ntTTVZrjkOZEDBHETRUZjeso56eCn0Zm0RK1qTk669nhoscpgz6K 3epAvG0J+RChqsSa+ZmWVoBbpoIzi7871U4t9IEfaUPgSD8vq35j1EioX fTs86MYPhUczPjaTJgqKXB/iBX8gysLnX8cs66qOz86ozKcvOTaqX/f92 KADb8s3Ew8PiEu1t96cuuS0UXWtQRcLRyaDZkRMNXHODo08sMrxZLOL16 SGApK93O0QgC01k6o6C4fuC4kDWg8eGhQQaIJ81IRzcHUPF/LUk97FnRd g==; X-IronPort-AV: E=McAfee;i="6600,9927,10707"; a="378639871" X-IronPort-AV: E=Sophos;i="5.99,266,1677571200"; d="scan'208";a="378639871" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 May 2023 07:30:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10707"; a="874004429" X-IronPort-AV: E=Sophos;i="5.99,266,1677571200"; d="scan'208";a="874004429" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by orsmga005.jf.intel.com with ESMTP; 11 May 2023 07:30:29 -0700 From: Yi Liu To: joro@8bytes.org, alex.williamson@redhat.com, jgg@nvidia.com, kevin.tian@intel.com, robin.murphy@arm.com, baolu.lu@linux.intel.com Cc: cohuck@redhat.com, eric.auger@redhat.com, nicolinc@nvidia.com, kvm@vger.kernel.org, mjrosato@linux.ibm.com, chao.p.peng@linux.intel.com, yi.l.liu@intel.com, yi.y.sun@linux.intel.com, peterx@redhat.com, jasowang@redhat.com, shameerali.kolothum.thodi@huawei.com, lulu@redhat.com, suravee.suthikulpanit@amd.com, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, zhenzhong.duan@intel.com Subject: [PATCH v3 2/4] iommu: Add new iommu op to get iommu hardware information Date: Thu, 11 May 2023 07:30:22 -0700 Message-Id: <20230511143024.19542-3-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230511143024.19542-1-yi.l.liu@intel.com> References: <20230511143024.19542-1-yi.l.liu@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765609330354542259?= X-GMAIL-MSGID: =?utf-8?q?1765609330354542259?= From: Lu Baolu Introduce a new iommu op to get the IOMMU hardware capabilities for iommufd. This information will be used by any vIOMMU driver which is owned by userspace. This op chooses to make the special parameters opaque to the core. This suits the current usage model where accessing any of the IOMMU device special parameters does require a userspace driver that matches the kernel driver. If a need for common parameters, implemented similarly by several drivers, arises then there's room in the design to grow a generic parameter set as well. No wrapper API is added as it is supposed to be used by iommufd only. Different IOMMU hardware would have different hardware information. So the information reported differs as well. To let the external user understand the difference. enum iommu_hw_info_type is defined. For the iommu drivers that are capable to report hardware information, it should have a unique iommu_hw_info_type. The iommu_hw_info_type is stored in struct iommu_ops. For the driver doesn't report hardware information, just use IOMMU_HW_INFO_TYPE_NONE. Signed-off-by: Lu Baolu Co-developed-by: Nicolin Chen Signed-off-by: Nicolin Chen Signed-off-by: Yi Liu --- include/linux/iommu.h | 16 ++++++++++++++++ include/uapi/linux/iommufd.h | 7 +++++++ 2 files changed, 23 insertions(+) diff --git a/include/linux/iommu.h b/include/linux/iommu.h index e7d70548e597..a748d60206e7 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -14,6 +14,7 @@ #include #include #include +#include #define IOMMU_READ (1 << 0) #define IOMMU_WRITE (1 << 1) @@ -222,6 +223,11 @@ struct iommu_iotlb_gather { /** * struct iommu_ops - iommu ops and capabilities * @capable: check capability + * @hw_info: IOMMU hardware information. The type of the returned data is + * marked by @hw_info_type. The data buffer returned by this op + * is allocated in the IOMMU driver and the caller should free it + * after use. Return the data buffer if success, or ERR_PTR on + * failure. * @domain_alloc: allocate iommu domain * @probe_device: Add device to iommu driver handling * @release_device: Remove device from iommu driver handling @@ -246,11 +252,20 @@ struct iommu_iotlb_gather { * @remove_dev_pasid: Remove any translation configurations of a specific * pasid, so that any DMA transactions with this pasid * will be blocked by the hardware. + * @hw_info_type: One of enum iommu_hw_info_type defined in + * include/uapi/linux/iommufd.h. It is used to tag the type + * of data returned by .hw_info callback. The drivers that + * support .hw_info callback should define a unique type + * in include/uapi/linux/iommufd.h. For the drivers that do + * not implement .hw_info callback, this field is + * IOMMU_HW_INFO_TYPE_NONE which is 0. Hence, such drivers + * do not need to care this field. * @pgsize_bitmap: bitmap of all possible supported page sizes * @owner: Driver module providing these ops */ struct iommu_ops { bool (*capable)(struct device *dev, enum iommu_cap); + void *(*hw_info)(struct device *dev, u32 *length); /* Domain allocation and freeing by the iommu driver */ struct iommu_domain *(*domain_alloc)(unsigned iommu_domain_type); @@ -279,6 +294,7 @@ struct iommu_ops { void (*remove_dev_pasid)(struct device *dev, ioasid_t pasid); const struct iommu_domain_ops *default_domain_ops; + enum iommu_hw_info_type hw_info_type; unsigned long pgsize_bitmap; struct module *owner; }; diff --git a/include/uapi/linux/iommufd.h b/include/uapi/linux/iommufd.h index 8245c01adca6..99bf0715f545 100644 --- a/include/uapi/linux/iommufd.h +++ b/include/uapi/linux/iommufd.h @@ -370,4 +370,11 @@ struct iommu_hwpt_alloc { __u32 __reserved; }; #define IOMMU_HWPT_ALLOC _IO(IOMMUFD_TYPE, IOMMUFD_CMD_HWPT_ALLOC) + +/** + * enum iommu_hw_info_type - IOMMU Hardware Info Types + */ +enum iommu_hw_info_type { + IOMMU_HW_INFO_TYPE_NONE, +}; #endif