From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=192.198.163.13 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796275477; b=42WDR4Y2fGfBAqW4dfiPHyRlD1tfsshQpaE5IGmSfp2c5lSMu3hQTel1vUntzBELNv+9 fs0yU6dvv3m7RIcpXjRVl9G6zidlE+Pk8nTddQTNqHNeCx+fG/k7D8DQhXgVhj0BDM1aP FvWrBn4JfEToGrkdfsCCwDVuRYvnuwbsD1IU0I7j7EXsI6mUy4/tXBOn4iKq/CsGuSU4a muxal+vBJkADteweF8t8VOQ5Xc5O3gvP7CT9Q19VGakjh/ikCZWowjzxdeqFsLpu5wzbG G8PY12Yx+6fEPxklYR3BxHpfk5pAUK1Lx+ZwVry+ypTO0ePOHysDrWL/Oy3xqqzTUEQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796275477; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:Message-ID:Date: MIME-Version:User-Agent:Cc:Subject:To:References:Content-Language: From:In-Reply-To:Content-Type:Content-Transfer-Encoding; bh=M9tZ8dOhUNfiDyAVyYgRRXbsvjWiRg8FdGgfUpuLKnE=; b=PPsXA01ueqkWtC7BhB25JxfpVdAxLgYSs0bWXgmyMbvGftxyisQ0XP9wVgVhMr/hd8is 6LB4CfK/GL8RE9uHsvT0IgN//kdCSuIQF1NR3k306ztfk4EYf8IHvyyqUZMXCg9maWeZA 31twqugzjiqcM6Pj9L2GwM+8egx0BAPtSDQnnrMbhup1jDwB9cS53hX2ktacCH81laidB 9Pfs54Z8xOX8JEv3FTmrYo59BmnyJdvOBDKfNTOZGt3wf66sunlX2vFTXbxwZuAPX062S UsDfH+1lhuJ0v2WJo7OxC2VwCDDVyt2GJudzwUcrU9YyaFpeJXuYplTTlM0bX0XXzWA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=ERU4n1ce; arc=none smtp.remote-ip=192.198.163.13 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.13]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 05FF9606A32C; Thu, 3 Dec 2026 05:24:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 05FF9606A32C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=ERU4n1ce DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796275476; x=1827811476; h=message-id:date:mime-version:cc:subject:to:references: from:in-reply-to:content-transfer-encoding; bh=M9tZ8dOhUNfiDyAVyYgRRXbsvjWiRg8FdGgfUpuLKnE=; b=ERU4n1celciWEG0XS4BqH4cyDaIwCfgziArwWrXKI+zyrsfuDWt5LuF3 Tk6Pwmj+6thOLgoZHcWdQvIBbOR24VzegmWiCoZmCOGnjGAIjSkacxF1C kO7cjjyGb8He6AXyPBMF9oGOg3/BXstWaysiLN1RyrJwz426chhthwpoA It4cfrKjsKQZe3w6KaCYvXnk/3ixpL+BuScNEbCYyqP01gTZtqqV4EjI+ 4npgkAigutBM9KiCSgFAUNNIKjN4p5EYEqmjMwkbVYHOjyzDlOOU+Sv4s snaseBbVaNuklDd1iuS8UGwVkuPoRYs96+zKMz6wszWnhDbb61/7enokZ w==; X-CSE-ConnectionGUID: Ja1gJ9fPTwmTsUfP5quMRg== X-CSE-MsgGUID: gmq0S/K/SaaQREn5OGIbYg== X-IronPort-AV: E=McAfee;i="6800,10657,11984"; a="5189569" X-IronPort-AV: E=Sophos;i="6.27,248,1787036400"; d="scan'208";a="5189569" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2026 21:24:34 -0800 X-CSE-ConnectionGUID: hbAvrFZMSJmkPXVIcYPAFQ== X-CSE-MsgGUID: aN9m0FGQQs+vaAEVHyNX8w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,248,1787036400"; d="scan'208";a="14036346" Received: from unknown (HELO [10.238.1.144]) ([10.238.1.144]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2026 21:24:27 -0800 Message-ID: <9517555a-ca6f-4a6e-afcb-4414729ade5a@linux.intel.com> Date: Thu, 3 Dec 2026 13:24:25 +0800 X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Cc: baolu.lu@linux.intel.com, Alex Williamson , Alexey Kardashevskiy , Bjorn Helgaas , Catalin Marinas , Jacob Pan , Jason Gunthorpe , Joerg Roedel , Jonathan Cameron , Jonathan Hunter , Kevin Tian , Krishna Reddy , Lukas Wunner , Nicolin Chen , Robin Murphy , Samuel Ortiz , Shameer Kolothum , Steven Price , Suravee Suthikulpanit , Suzuki K Poulose , Thierry Reding , Vasant Hegde , Will Deacon , Xu Yilun , Ashish Kalra , Herbert Xu , Jonathan Cameron , Tom Lendacky , kvm@vger.kernel.org, iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-pci@vger.kernel.org, linux-tegra@vger.kernel.org, patches@lists.linux.dev Subject: Re: [PATCH v10 14/18] iommufd/viommu: Identify physical IOMMU backing with a tag To: "Aneesh Kumar K.V (Arm)" , linux-coco@lists.linux.dev References: <20261125081121.379481-1-aneesh.kumar@kernel.org> <20261125081121.379481-15-aneesh.kumar@kernel.org> Content-Language: en-US From: Baolu Lu In-Reply-To: <20261125081121.379481-15-aneesh.kumar@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 11/25/2026 4:11 PM, Aneesh Kumar K.V (Arm) wrote: > When allocating a vDEVICE or nested HWPT, IOMMUFD checks that the device > and its vIOMMU use the same physical IOMMU. > > The next patch adds vIOMMUs implemented by a TSM. These store a TSM > pointer instead of a physical IOMMU pointer, so the same comparison > cannot be used. > > Add a backing field to identify vIOMMUs that use a physical IOMMU, and > perform the comparison only for those vIOMMUs. All existing vIOMMUs > select that value, so their behavior is unchanged. > > Signed-off-by: Aneesh Kumar K.V (Arm) > --- > drivers/iommu/iommufd/hw_pagetable.c | 10 ++++++---- > drivers/iommu/iommufd/viommu.c | 11 +++++++---- > include/linux/iommufd.h | 5 +++++ > 3 files changed, 18 insertions(+), 8 deletions(-) > > diff --git a/drivers/iommu/iommufd/hw_pagetable.c b/drivers/iommu/iommufd/hw_pagetable.c > index ae62db50885c..859eadf05f1d 100644 > --- a/drivers/iommu/iommufd/hw_pagetable.c > +++ b/drivers/iommu/iommufd/hw_pagetable.c > @@ -404,10 +404,12 @@ int iommufd_hwpt_alloc(struct iommufd_ucmd *ucmd) > struct iommufd_viommu *viommu; > > viommu = container_of(pt_obj, struct iommufd_viommu, obj); > - iommu_dev = iommufd_device_get_iommu_dev(idev); > - if (!iommu_dev || viommu->iommu_dev != iommu_dev) { > - rc = -EINVAL; > - goto out_unlock; > + if (viommu->backing == IOMMUFD_VIOMMU_BACKING_IOMMU) { > + iommu_dev = iommufd_device_get_iommu_dev(idev); > + if (!iommu_dev || viommu->iommu_dev != iommu_dev) { > + rc = -EINVAL; > + goto out_unlock; > + } What happens when viommu->backing != IOMMUFD_VIOMMU_BACKING_IOMMU? A nested hwpt is not valid for such a viommu, but this code skips the check and still calls iommufd_viommu_alloc_hwpt_nested(). That function dereferences viommu->iommu_dev->ops, which after the next patch aliases tsm_dev. How about rejecting it explicitly: if (viommu->backing != IOMMUFD_VIOMMU_BACKING_IOMMU) { rc = -EOPNOTSUPP; goto out_unlock; } iommu_dev = iommufd_device_get_iommu_dev(idev); if (!iommu_dev || viommu->iommu_dev != iommu_dev) { rc = -EINVAL; goto out_unlock; } > } > hwpt_nested = iommufd_viommu_alloc_hwpt_nested( > viommu, cmd->flags, &user_data); > diff --git a/drivers/iommu/iommufd/viommu.c b/drivers/iommu/iommufd/viommu.c > index 472381b96a8e..dab499d24c45 100644 > --- a/drivers/iommu/iommufd/viommu.c > +++ b/drivers/iommu/iommufd/viommu.c > @@ -105,6 +105,7 @@ int iommufd_viommu_alloc_ioctl(struct iommufd_ucmd *ucmd) > * pluggable IOMMU instance (if exists) is responsible for refcounting > * on its own. > */ > + viommu->backing = IOMMUFD_VIOMMU_BACKING_IOMMU; > viommu->iommu_dev = iommu_dev; > > rc = ops->viommu_init(viommu, idev->dev, > @@ -218,10 +219,12 @@ int iommufd_vdevice_alloc_ioctl(struct iommufd_ucmd *ucmd) > goto out_put_idev; > } > > - iommu_dev = iommufd_device_get_iommu_dev(idev); > - if (!iommu_dev || viommu->iommu_dev != iommu_dev) { > - rc = -EINVAL; > - goto out_put_idev; > + if (viommu->backing == IOMMUFD_VIOMMU_BACKING_IOMMU) { > + iommu_dev = iommufd_device_get_iommu_dev(idev); > + if (!iommu_dev || viommu->iommu_dev != iommu_dev) { > + rc = -EINVAL; > + goto out_put_idev; > + } Similar concern here, although a tsm-backed viommu does need vdevices, so this path can't simply be rejected. Skipping the check means the core accepts any idev for a tsm viommu, without verifying that the device is managed by viommu->tsm_dev. > } > > mutex_lock(&idev->igroup->lock); > diff --git a/include/linux/iommufd.h b/include/linux/iommufd.h > index 5f5c67b24134..192d46b8ccfd 100644 > --- a/include/linux/iommufd.h > +++ b/include/linux/iommufd.h > @@ -98,9 +98,14 @@ void iommufd_access_detach(struct iommufd_access *access); > > void iommufd_ctx_get(struct iommufd_ctx *ictx); > > +enum iommufd_viommu_backing { > + IOMMUFD_VIOMMU_BACKING_IOMMU, > +}; > + > struct iommufd_viommu { > struct iommufd_object obj; > struct iommufd_ctx *ictx; > + enum iommufd_viommu_backing backing; > struct iommu_device *iommu_dev; > struct iommufd_hwpt_paging *hwpt; > struct file *kvm_file; Thanks, baolu