From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 98538C7EE30 for ; Tue, 1 Jul 2025 14:30:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=uzw4uNd5li2mXa+WfFMUaVuwZFHwRlbcR3UhOImbWD4=; b=eTK4B+zBUv+0W6o4EibNLx/KbW FPlMoMuvFVoZiIw2der7LglYlkXENYZTSsLpU4CNZt5KOLlhDI1bkeullR2l6e4COUNmvtqFzPgax S2KBt3BLz2cGL1Szu/hfVBGicV5gn7wwJM8su2VXYkJLeCc/tgRWw73R5C2qb0qQE2pUgBDThdjSw pmP4GpwoLjBeOmP0HAhd6/8vcGu92ixnDbhuAPAsoSRUEVhMuMN0AmPuGQp7PEwzFf5gTTlDMpdR3 Emqi6v1CLYHBXtN4Z75tBnGgItPfr6VjWK5S3SoF+ZwzJ1vPpK8B+1VAD49l2XFU+fd/4pA50Emf4 +RP+pfSw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1uWbzg-00000005i43-2ba5; Tue, 01 Jul 2025 14:29:56 +0000 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1uWaZT-00000005PXS-2nLm for linux-arm-kernel@lists.infradead.org; Tue, 01 Jul 2025 12:58:48 +0000 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-235e389599fso212065ad.0 for ; Tue, 01 Jul 2025 05:58:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1751374727; x=1751979527; darn=lists.infradead.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=uzw4uNd5li2mXa+WfFMUaVuwZFHwRlbcR3UhOImbWD4=; b=NZI0nEcfG3LbdLgbRWuT+g0WLw6mpJv57G1C2P6amnCI2WLKV0ofi+f8RQtUFjtPfi BYLQWnRjrpqDYxvEZIb2d17zvjgVEZ+toCeXGEKJAbU4RT99p3x8b56t2BuDF7Y1GgO1 vZw9YOkF/BiuKLZvyDCqHzfsQ9EXdu5/ytMkde+unnV+f4ZnRNBfWq5tv1xKKuPDTZxX YOAzGGGuWMRKZjEU2391u/KbGBMZxPCLQnPhl9pwsaza5UCuuIuwq8EKsTdKN3/UIVHa Bb+QzwDN/hpLyu0hu5t3tWmLhLvFBnPytiscWC8f2aag5uhFNzb+FUtHrYt1bsvLqy1z KJFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751374727; x=1751979527; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=uzw4uNd5li2mXa+WfFMUaVuwZFHwRlbcR3UhOImbWD4=; b=LPWFpGK5EiIiNSjerv4+KIwcfH7KhIiGZCpEKMKEvUmRJ/TSjgEme/3e5o0021sjmM kd32w74By3izJihmMVV1cAahXjO0xPRaqE+TgUoMXTQuDb5zLriFkH+dTsl6VVoqc+KP ZZAvs870kUxGWXiZysf5lTKiduGWgxlh/vX1GSkb2mUeTwRDBAyTV3908jzDeRbjDBDM rUNUHblbNksqzrQrrcnvKAfwH6SPP+ltvJQ+DClkU8U2D/fE3/6KE1Zeml4jhiuJFpiM K4u0CPpCVxcbuZ1YGTWIDDk8dQRk4j05rMGliHHOtV4Zef9K286ZRzEvGPYLvKH9tUij YI3A== X-Forwarded-Encrypted: i=1; AJvYcCWGe2i8sz2NJzEVuHuhqkbK7jjpiVQU3VaqMngwS7SisFFhb+SooFAnQfY50vklu3M87mtvmEsh+Ti9wc60WS36@lists.infradead.org X-Gm-Message-State: AOJu0Yxn4gtpAi8BgkM57FXLlQOuCURsFu/raretN8V+YMVdIXGJdoJr 2FWLmnJv6uPp4rcIbAf9htP1T6DKhHtm61Q2XsCmKmJavMGPB/WT438K/cJuJ8hnTg== X-Gm-Gg: ASbGncvPgXnatFQUo+3lv/CTze2QZqPZDhuOUTpv4f9y9miArhk7vbLy9ueWx5Xi1l1 m1H8nN9P1uYfzACAOBMrHQsPIlbKY+RmRbwmjFbPScjmTDPzDJkqg6Qmf7ddeG8d9CAC8E6w94z AZ/6sG5mrbeI31XaL1b+8bbNiF4K4RxMiIveGj12TFAWR97V3IpNtMjHqNLpBhjd/hjjT1inN9n yW/AJdQeA1rbsblgRtWR2EEV01HpUhZXAnReuJQYiZII/K0zAv0VvvBOQdvmqNEi/fw38jb2PLy CVjCua7S3C8rjB6emXJXEo5UK+YOiVMn4DnS0vzNJCe33fnjC9esaJ8QibLuaoqdoLE4HBwqbkf KEzEwsgcPyZGKhAFGzb6+qRXh5cm4fDE= X-Google-Smtp-Source: AGHT+IGmj2MAzmEBH+PWX1NsLuSUKrLgxpjLMp3KA3CIsShNt/Sqit3dWlHjLZzB1pekp9REtBE7WA== X-Received: by 2002:a17:902:f70b:b0:234:bca7:2934 with SMTP id d9443c01a7336-23c5fef098cmr2059855ad.6.1751374726581; Tue, 01 Jul 2025 05:58:46 -0700 (PDT) Received: from google.com (232.98.126.34.bc.googleusercontent.com. [34.126.98.232]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-23acb39bcbcsm104502905ad.134.2025.07.01.05.58.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Jul 2025 05:58:45 -0700 (PDT) Date: Tue, 1 Jul 2025 12:58:36 +0000 From: Pranjal Shrivastava To: Nicolin Chen Cc: jgg@nvidia.com, kevin.tian@intel.com, corbet@lwn.net, will@kernel.org, bagasdotme@gmail.com, robin.murphy@arm.com, joro@8bytes.org, thierry.reding@gmail.com, vdumpa@nvidia.com, jonathanh@nvidia.com, shuah@kernel.org, jsnitsel@redhat.com, nathan@kernel.org, peterz@infradead.org, yi.l.liu@intel.com, mshavit@google.com, zhangzekun11@huawei.com, iommu@lists.linux.dev, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-tegra@vger.kernel.org, linux-kselftest@vger.kernel.org, patches@lists.linux.dev, mochs@nvidia.com, alok.a.tiwari@oracle.com, vasant.hegde@amd.com, dwmw2@infradead.org, baolu.lu@linux.intel.com Subject: Re: [PATCH v7 20/28] iommufd: Allow an input data_type via iommu_hw_info Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250701_055847_707535_4F88ED38 X-CRM114-Status: GOOD ( 29.52 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, Jun 26, 2025 at 12:34:51PM -0700, Nicolin Chen wrote: > The iommu_hw_info can output via the out_data_type field the vendor data > type from a driver, but this only allows driver to report one data type. > > Now, with SMMUv3 having a Tegra241 CMDQV implementation, it has two sets > of types and data structs to report. > > One way to support that is to use the same type field bidirectionally. > > Reuse the same field by adding an "in_data_type", allowing user space to > request for a specific type and to get the corresponding data. > > For backward compatibility, since the ioctl handler has never checked an > input value, add an IOMMU_HW_INFO_FLAG_INPUT_TYPE to switch between the > old output-only field and the new bidirectional field. > > Reviewed-by: Kevin Tian > Reviewed-by: Jason Gunthorpe > Reviewed-by: Lu Baolu > Signed-off-by: Nicolin Chen > --- > include/uapi/linux/iommufd.h | 20 +++++++++++++++++++- > drivers/iommu/iommufd/device.c | 9 ++++++--- > 2 files changed, 25 insertions(+), 4 deletions(-) > > diff --git a/include/uapi/linux/iommufd.h b/include/uapi/linux/iommufd.h > index 6ad361ff9b06..6ae9d2102154 100644 > --- a/include/uapi/linux/iommufd.h > +++ b/include/uapi/linux/iommufd.h > @@ -628,6 +628,15 @@ enum iommufd_hw_capabilities { > IOMMU_HW_CAP_PCI_PASID_PRIV = 1 << 2, > }; > > +/** > + * enum iommufd_hw_info_flags - Flags for iommu_hw_info > + * @IOMMU_HW_INFO_FLAG_INPUT_TYPE: If set, @in_data_type carries an input type > + * for user space to request for a specific info > + */ > +enum iommufd_hw_info_flags { > + IOMMU_HW_INFO_FLAG_INPUT_TYPE = 1 << 0, > +}; > + > /** > * struct iommu_hw_info - ioctl(IOMMU_GET_HW_INFO) > * @size: sizeof(struct iommu_hw_info) > @@ -637,6 +646,12 @@ enum iommufd_hw_capabilities { > * data that kernel supports > * @data_uptr: User pointer to a user-space buffer used by the kernel to fill > * the iommu type specific hardware information data > + * @in_data_type: This shares the same field with @out_data_type, making it be > + * a bidirectional field. When IOMMU_HW_INFO_FLAG_INPUT_TYPE is > + * set, an input type carried via this @in_data_type field will > + * be valid, requesting for the info data to the given type. If > + * IOMMU_HW_INFO_FLAG_INPUT_TYPE is unset, any input value will > + * be seen as IOMMU_HW_INFO_TYPE_DEFAULT > * @out_data_type: Output the iommu hardware info type as defined in the enum > * iommu_hw_info_type. > * @out_capabilities: Output the generic iommu capability info type as defined > @@ -666,7 +681,10 @@ struct iommu_hw_info { > __u32 dev_id; > __u32 data_len; > __aligned_u64 data_uptr; > - __u32 out_data_type; > + union { > + __u32 in_data_type; > + __u32 out_data_type; > + }; > __u8 out_max_pasid_log2; > __u8 __reserved[3]; > __aligned_u64 out_capabilities; > diff --git a/drivers/iommu/iommufd/device.c b/drivers/iommu/iommufd/device.c > index 64a51993e6a1..cbd86aabdd1c 100644 > --- a/drivers/iommu/iommufd/device.c > +++ b/drivers/iommu/iommufd/device.c > @@ -1506,6 +1506,7 @@ EXPORT_SYMBOL_NS_GPL(iommufd_access_rw, "IOMMUFD"); > > int iommufd_get_hw_info(struct iommufd_ucmd *ucmd) > { > + const u32 SUPPORTED_FLAGS = IOMMU_HW_INFO_FLAG_INPUT_TYPE; > struct iommu_hw_info *cmd = ucmd->cmd; > void __user *user_ptr = u64_to_user_ptr(cmd->data_uptr); > const struct iommu_ops *ops; > @@ -1515,12 +1516,14 @@ int iommufd_get_hw_info(struct iommufd_ucmd *ucmd) > void *data; > int rc; > > - if (cmd->flags || cmd->__reserved[0] || cmd->__reserved[1] || > - cmd->__reserved[2]) > + if (cmd->flags & ~SUPPORTED_FLAGS) > + return -EOPNOTSUPP; > + if (cmd->__reserved[0] || cmd->__reserved[1] || cmd->__reserved[2]) > return -EOPNOTSUPP; > > /* Clear the type field since drivers don't support a random input */ > - cmd->out_data_type = IOMMU_HW_INFO_TYPE_DEFAULT; > + if (!(cmd->flags & IOMMU_HW_INFO_FLAG_INPUT_TYPE)) > + cmd->in_data_type = IOMMU_HW_INFO_TYPE_DEFAULT; > > idev = iommufd_get_device(ucmd, cmd->dev_id); > if (IS_ERR(idev)) Reviewed-by: Pranjal Shrivastava > -- > 2.43.0 >