From patchwork Fri Aug 11 07:14:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 134383 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b824:0:b0:3f2:4152:657d with SMTP id z4csp965825vqi; Fri, 11 Aug 2023 02:38:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFWC5cgWLDTQ1KYPuRDqLKxhc37SiTGqud3nFtEtxyYU2ClGot2iQWUk/VEBJw5/Nd7z4ow X-Received: by 2002:a17:903:2643:b0:1b8:649d:3652 with SMTP id je3-20020a170903264300b001b8649d3652mr876546plb.32.1691746700807; Fri, 11 Aug 2023 02:38:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691746700; cv=none; d=google.com; s=arc-20160816; b=ceNdSgBw1uHFRiqynBDNmfW8W57tLxDiyN9IPFvX6qGLDViJee+/NCpunX1CqGMFf1 d6KKA6L/WzcXOrz6Ys99uCMB2/IdjikeS7WgfBYotD8XF+zwz/PWdPas4g8LpeZKvOy9 53OcHrlaC2uw2Cb6rKQM1MYiQWwv4pW2YIGF5tzDd9NZDgv4DtgRKd+fOmGFyk2Qb5YM 9GMNl3ymtdac9AAbE0+UeGal1KQ4MrV4ecMroHFlWOEtt6QOa0U2hSku7hSJcpvqEo64 gBi0Rl4zoMqC4dWN4TXyZdI7Yq2XfREA4hW3n2TMyvn0dCPJnRhBsgeXT3B81UqAgTtb nzUw== 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=mNzVbIS9esikMQCX6OsBAZkjdkau0ltmXr1Ruc5Qz5o=; fh=25kVo4cotgMzE250R6E3K5ES7E7C2JawiavlW0h5mKU=; b=p0vvvuyFfHKIhnUoc2+rLlmywmzOp0BCIBFTYccBq6n1s272FX8xA/sz6hiwzk/d4F lK/rdivG8qF7thb90IPADmlLd/4QppDJteXbPx+vO5ZyUWz7e47uop00ZTrnR4NkNVLB F3rKvkjgS4NLgEPhnnr6XSQ/q0BMe3RVU32APT4Myxk8O27bpF2ImR5gLKerWjKUF4Tf y9mcdHyPApy+MADbdDBkBx5z6dqaA+amihtMddXPak7Lq7UrbUv0xJeflD8QJ4oWa7vx cp22YnTpl6eCvz7IZIc+Qxd5wKrjgYq0MD+vdMrg0eIU1oRYeLoooOPfV8i3e5wOwdV7 xwtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=iq4joCSj; 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 b11-20020a170902d50b00b001a6bb7b7a44si3109257plg.307.2023.08.11.02.38.06; Fri, 11 Aug 2023 02:38:20 -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=iq4joCSj; 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 S233800AbjHKHPZ (ORCPT + 99 others); Fri, 11 Aug 2023 03:15:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233618AbjHKHPS (ORCPT ); Fri, 11 Aug 2023 03:15:18 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 612882D70; Fri, 11 Aug 2023 00:15:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1691738113; x=1723274113; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=sxfubDWI2gwfOBW2/jdEN8IlvwFA21yaOXGd5zVExW0=; b=iq4joCSjZeuZeJeuf7/sycTZfL8uX/VHLuBn9Cm0A9Z3DcZZrZJktkX9 Am0c5grRsBb5qNNj7omWXwedks5oZNyn5TeCZrBPcEL/vEVeWXLMN2X2U V4n3c+6FV1cZDIg6EOkgt8r6LZizeQ/z62VtFdaYtcrrS6qw8rXV4RXmo tZQunHsXd5m81tN/4hfNa+OJcHX2CbPS6Ovfcq0Vbic9W1fnmBwyP6svC 3riRhPXv+NPTRLZAN0Nqmxt+3Ink84yVJRAtn6/ObqIX4Ek4n+rh+K/71 N+RjJm+lgRnMo91Bzijfs0SptRdCLGmJOWQ1XTBLa/xXEYO2J45Q9tmxI Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10798"; a="351937653" X-IronPort-AV: E=Sophos;i="6.01,164,1684825200"; d="scan'208";a="351937653" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Aug 2023 00:15:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10798"; a="979142003" X-IronPort-AV: E=Sophos;i="6.01,164,1684825200"; d="scan'208";a="979142003" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by fmsmga006.fm.intel.com with ESMTP; 11 Aug 2023 00:15:05 -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 v7 2/4] iommu: Add new iommu op to get iommu hardware information Date: Fri, 11 Aug 2023 00:14:59 -0700 Message-Id: <20230811071501.4126-3-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230811071501.4126-1-yi.l.liu@intel.com> References: <20230811071501.4126-1-yi.l.liu@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE,URIBL_BLOCKED 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: INBOX X-GMAIL-THRID: 1773924988408887456 X-GMAIL-MSGID: 1773924988408887456 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 and return to caller. For the driver doesn't report hardware information, caller just uses IOMMU_HW_INFO_TYPE_NONE if a type is required. Signed-off-by: Lu Baolu Co-developed-by: Nicolin Chen Signed-off-by: Nicolin Chen Signed-off-by: Yi Liu --- include/linux/iommu.h | 9 +++++++++ include/uapi/linux/iommufd.h | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/include/linux/iommu.h b/include/linux/iommu.h index e0245aa82b75..f2d6a3989713 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -228,6 +228,14 @@ 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 the output type of this op. Type is one of + * enum iommu_hw_info_type defined in include/uapi/linux/iommufd.h. + * The drivers that support this op should define a unique type + * in include/uapi/linux/iommufd.h. 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 @@ -257,6 +265,7 @@ struct iommu_iotlb_gather { */ struct iommu_ops { bool (*capable)(struct device *dev, enum iommu_cap); + void *(*hw_info)(struct device *dev, u32 *length, u32 *type); /* Domain allocation and freeing by the iommu driver */ struct iommu_domain *(*domain_alloc)(unsigned iommu_domain_type); diff --git a/include/uapi/linux/iommufd.h b/include/uapi/linux/iommufd.h index 8245c01adca6..ac11ace21edb 100644 --- a/include/uapi/linux/iommufd.h +++ b/include/uapi/linux/iommufd.h @@ -370,4 +370,13 @@ 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 + * @IOMMU_HW_INFO_TYPE_NONE: Used by the drivers that do not report hardware + * info + */ +enum iommu_hw_info_type { + IOMMU_HW_INFO_TYPE_NONE, +}; #endif