From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B3E1A273D7D for ; Tue, 1 Jul 2025 12:54:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751374459; cv=none; b=CJ5O+xa7BCcWtYXrj+S6COVAGJNR+OdiO71eQiaYf5GXm4apImSpEJ2+19b9OWRXm5Efcr0bgnbikzjssAZEqfOXQYmeP43jbRVuuEvc5Hob17aJuoDKcvdWSNFIxK4zhgf4tp1hlnKp2ouTz6CSioJ5hOcnrgODOqHD+pPPyAY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751374459; c=relaxed/simple; bh=3gJtS77mHK7VTcYFcjrd5hF6WARIXk6d2X2+wZ3Hta4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=IU20O83KXUuVjoOcPIbmPMOvaE7HX92SnP3zXpt4IY6aYwvzRInWcrnV7Hh6jtfPV3evxyQeo7dG4po8C4S44GRPPS8u1zaiNVgCuAruyoNxwcH5wv1p44mLm28vRwDw8l6PIkOHPz3OWs01wBjHVeYVb0UiyR8mZXFOuXonrlQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=jzF0FoCA; arc=none smtp.client-ip=209.85.214.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="jzF0FoCA" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-235e389599fso211055ad.0 for ; Tue, 01 Jul 2025 05:54:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1751374456; x=1751979256; darn=lists.linux.dev; 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=/L74aNTJbvTixP9x7JPOzIa2qX6+0XWisdXXC8NLNbk=; b=jzF0FoCA+El+kxFgOqE/7z98VejgQFp9NJdLfe6ERhNHJT5VW8/svwSqQc/5fAeyJX 66/BRaO/pUIarisVF3jl00/yDMw8FMK82NzGp5vHunmwp/fO8mRYkrC7gLSpsWfVTy8s 45UDY+tnksiyMFofsIJfHFbiiGpdf3K6wfLn2avQEX0TWJldy99H43pyHN0JPrA4nFE/ VIbI2l5tKbpu9Waad6p4vW6+l2ZT1pmW/Wn3CnwUUM7/odhp5nrEOg+8g10zNGXGdTyQ ubjl126leQ0YFcvgW2iOJzZ9hQf7phxHpn8ekkOJVOAMhsO/e+ChIO4cYsnKjRj9aDVX TPMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751374456; x=1751979256; 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=/L74aNTJbvTixP9x7JPOzIa2qX6+0XWisdXXC8NLNbk=; b=XtDJOM93y8nw197016QZM22b9MvL5bvxgqx05jRb/6PDnq90+82DQY4LHg6q37k2vM FXmNYKytfs5ncIs5PaKDeK047IsH7h8c8jGmbyfn9hBKx7Q/j5tEhL6b2FhBSTqs3e04 jpTdJDIfNluEzXtS2XgietHnuLbqQCCkiNz8ScyuRxdaqS+wzt//Yn5r2YGURl7jCI0Q J9jHdU/jOT7c/fJRor//RcPd7Y1W3WAyIqtip07w0FRQaoqz1BrFu9GL1+eZ7NyxJ7t6 8ZZOSvIuOPpadeh/49IMIKOXKYvhXfMQqck1G9tGEhJ95fHO7JW9hbFRWwUk8ghVYEX0 j2dg== X-Forwarded-Encrypted: i=1; AJvYcCVaeKjtt901yeuW+CCfd5d65we+p2o0LOLqNwZOz30bFslXxohq34u+tg3Zd8EhOBleanjpXo0V@lists.linux.dev X-Gm-Message-State: AOJu0YwTAVSpLYbGeG3XQ6z+/muFuYVAZPTPBJkCyEimFnI7+oyMWgf8 /F6v4SN/Woz7LlBE2x+DB9MMoTf4S2haaCDNbIV8xZbNBUyePFzVbAt7FfHXuxkPKA== X-Gm-Gg: ASbGncu10dArU+hV6WNNNo22g+3B6xC2K4NLnzpwoKVr9RNAtfvay+bY70oHfAczNZn 3jwetQTSVAGEJMOgXsfCGtW+mNdUINJ4M6JDk7VZx69DDmpB8Q1wvvVktKZC4OVfnPUUxQWk0rL JFEFhKcYf43AWa1EtIl4IYrURnSb4fJS7Jr/oIkWhU2yTfQaqPhVdP5+gQYlF92sAUXF4GlLxlg BN6nol1kXn4gZsVNrxhlnDUJHE43NUvtMHPbQlw31meAyTabNHbTsMF68GC4hayXNSmr+HkLBsQ 98Jc+GU88oKgTk53f9qH1B5OnmQ2lhHVIkyYC9cgOlIS62FGxjRTMkqq2q06vAXFn6Z4oOoOcyE LNHd2rBWYxzaQD+D9Phcb X-Google-Smtp-Source: AGHT+IFmb6IkHO5vc0UO9aOVGDXMpB2kmzp4LmZ2sU6rPiqzBx0SBn3BZ18jaHfT4NmGETFHxk/nSg== X-Received: by 2002:a17:902:f688:b0:231:ed22:e230 with SMTP id d9443c01a7336-23c6010f25amr2110315ad.15.1751374455431; Tue, 01 Jul 2025 05:54:15 -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-23acb3b7a47sm108535025ad.166.2025.07.01.05.54.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Jul 2025 05:54:13 -0700 (PDT) Date: Tue, 1 Jul 2025 12:54:05 +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 19/28] iommu: Allow an input type in hw_info op Message-ID: References: Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Thu, Jun 26, 2025 at 12:34:50PM -0700, Nicolin Chen wrote: > The hw_info uAPI will support a bidirectional data_type field that can be > used as an input field for user space to request for a specific info data. > > To prepare for the uAPI update, change the iommu layer first: > - Add a new IOMMU_HW_INFO_TYPE_DEFAULT as an input, for which driver can > output its only (or firstly) supported type > - Update the kdoc accordingly > - Roll out the type validation in the existing drivers > > Reviewed-by: Kevin Tian > Reviewed-by: Jason Gunthorpe > Reviewed-by: Lu Baolu > Signed-off-by: Nicolin Chen > --- > include/linux/iommu.h | 3 ++- > include/uapi/linux/iommufd.h | 4 +++- > drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c | 4 ++++ > drivers/iommu/intel/iommu.c | 4 ++++ > drivers/iommu/iommufd/device.c | 3 +++ > drivers/iommu/iommufd/selftest.c | 4 ++++ > 6 files changed, 20 insertions(+), 2 deletions(-) > > diff --git a/include/linux/iommu.h b/include/linux/iommu.h > index e06a0fbe4bc7..e8b59ef54e48 100644 > --- a/include/linux/iommu.h > +++ b/include/linux/iommu.h > @@ -603,7 +603,8 @@ __iommu_copy_struct_to_user(const struct iommu_user_data *dst_data, > * @capable: check capability > * @hw_info: report iommu hardware information. The data buffer returned by this > * op is allocated in the iommu driver and freed by the caller after > - * use. > + * use. @type can input a requested type and output a supported type. > + * Driver should reject an unsupported data @type input > * @domain_alloc: Do not use in new drivers > * @domain_alloc_identity: allocate an IDENTITY domain. Drivers should prefer to > * use identity_domain instead. This should only be used > diff --git a/include/uapi/linux/iommufd.h b/include/uapi/linux/iommufd.h > index f091ea072c5f..6ad361ff9b06 100644 > --- a/include/uapi/linux/iommufd.h > +++ b/include/uapi/linux/iommufd.h > @@ -593,13 +593,15 @@ struct iommu_hw_info_arm_smmuv3 { > > /** > * enum iommu_hw_info_type - IOMMU Hardware Info Types > - * @IOMMU_HW_INFO_TYPE_NONE: Used by the drivers that do not report hardware > + * @IOMMU_HW_INFO_TYPE_NONE: Output by the drivers that do not report hardware > * info > + * @IOMMU_HW_INFO_TYPE_DEFAULT: Input to request for a default type > * @IOMMU_HW_INFO_TYPE_INTEL_VTD: Intel VT-d iommu info type > * @IOMMU_HW_INFO_TYPE_ARM_SMMUV3: ARM SMMUv3 iommu info type > */ > enum iommu_hw_info_type { > IOMMU_HW_INFO_TYPE_NONE = 0, > + IOMMU_HW_INFO_TYPE_DEFAULT = 0, > IOMMU_HW_INFO_TYPE_INTEL_VTD = 1, > IOMMU_HW_INFO_TYPE_ARM_SMMUV3 = 2, > }; > diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c > index 170d69162848..eb9fe1f6311a 100644 > --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c > +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c > @@ -15,6 +15,10 @@ void *arm_smmu_hw_info(struct device *dev, u32 *length, > u32 __iomem *base_idr; > unsigned int i; > > + if (*type != IOMMU_HW_INFO_TYPE_DEFAULT && > + *type != IOMMU_HW_INFO_TYPE_ARM_SMMUV3) > + return ERR_PTR(-EOPNOTSUPP); > + > info = kzalloc(sizeof(*info), GFP_KERNEL); > if (!info) > return ERR_PTR(-ENOMEM); > diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c > index 850f1a6f548c..5f75faffca15 100644 > --- a/drivers/iommu/intel/iommu.c > +++ b/drivers/iommu/intel/iommu.c > @@ -4098,6 +4098,10 @@ static void *intel_iommu_hw_info(struct device *dev, u32 *length, > struct intel_iommu *iommu = info->iommu; > struct iommu_hw_info_vtd *vtd; > > + if (*type != IOMMU_HW_INFO_TYPE_DEFAULT && > + *type != IOMMU_HW_INFO_TYPE_INTEL_VTD) > + return ERR_PTR(-EOPNOTSUPP); > + > vtd = kzalloc(sizeof(*vtd), GFP_KERNEL); > if (!vtd) > return ERR_PTR(-ENOMEM); > diff --git a/drivers/iommu/iommufd/device.c b/drivers/iommu/iommufd/device.c > index 8f078fda795a..64a51993e6a1 100644 > --- a/drivers/iommu/iommufd/device.c > +++ b/drivers/iommu/iommufd/device.c > @@ -1519,6 +1519,9 @@ int iommufd_get_hw_info(struct iommufd_ucmd *ucmd) > 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; > + > idev = iommufd_get_device(ucmd, cmd->dev_id); > if (IS_ERR(idev)) > return PTR_ERR(idev); > diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/iommu/iommufd/selftest.c > index 8b2c44b32530..a5dc36219a90 100644 > --- a/drivers/iommu/iommufd/selftest.c > +++ b/drivers/iommu/iommufd/selftest.c > @@ -310,6 +310,10 @@ static void *mock_domain_hw_info(struct device *dev, u32 *length, > { > struct iommu_test_hw_info *info; > > + if (*type != IOMMU_HW_INFO_TYPE_DEFAULT && > + *type != IOMMU_HW_INFO_TYPE_SELFTEST) > + return ERR_PTR(-EOPNOTSUPP); > + > info = kzalloc(sizeof(*info), GFP_KERNEL); > if (!info) > return ERR_PTR(-ENOMEM); Reviewed-by: Pranjal Shrivastava > -- > 2.43.0 >