From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=198.175.65.14 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796281260; b=eGViMDn1DO2CJBXkNJTl7QZtSuHQ6JYLmY4m16ab+6JFGOfu7mJOHPU7G9RQ7lxP9tn3 Ghf/NIHagQgPxfJbB/6Iyj/EMuPnsWKAQ77go84994nB/6+Q0HDpENh4s4bMuaeuepdj4 bofPQX1o7K4VWD7x7UKxIWLofhXIDLZkumWowgORIzvTCOKgf+hfpcOJrNOWesdLI/NaB qKS68PdfxsY/DNytGVq4yDmsGHpTY/SuUXwV64CiAp+O88ddIdHFx9DWqYTeeoPLYX+ks KAzeMi8175/LHPPfEh9YRTXGSwcuNixDFG+zcKG2CEUpiEbCL+uCmGwiaace+lZjvrA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796281260; 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=AuXbDMOSWntQLvp9tMzUfGfPpwSfj1L6JLCmj7DcNE0=; b=YWnvr542nk4cq0nof1QLrnRDol3C5JGvaVycgvB7Bbwan8oDYMfJjc5p3VLkIX/pto9u fsnmFSt3jo/27bF1Ntoc2tryLhyqHVno+B/DgLpUUWgVXGvBzdxhKTVIUwIqBkBc2kvF1 0A8zExCSVveuzPLmqhaOZ+ssOlCvypRy5AcyDJi10NH5Ys4Kf8ENNCXTDDial+qF2xHK5 8HfePc3dbG2nhHZsIVO2eoCWrA3Nyo3AfchDHlHz3p+ENcF0hsJaRwMWCGo+vjoiHj/bu NJpwUD1H3BVGofF/kt4IuAPQOm/Ne4dlbhFDRD/AtqFyjFoY90DRuq/UdijguCM8YpQ== 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=VpaWqkqY; arc=none smtp.remote-ip=198.175.65.14 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) (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 67715606A32C; Thu, 3 Dec 2026 07:00:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 67715606A32C 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=VpaWqkqY DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796281260; x=1827817260; h=message-id:date:mime-version:cc:subject:to:references: from:in-reply-to:content-transfer-encoding; bh=AuXbDMOSWntQLvp9tMzUfGfPpwSfj1L6JLCmj7DcNE0=; b=VpaWqkqYf9q2mFtTi2f52xdtn7rI4CZf1LouZ4A1xV8/aXnd1UFlqODl wulwsa4wvq6/+oATem9jIsD+zefzLD5+AJBZw5tiZ+AcZCjbE1xopZzmX XIofGGZKoYc0nV96w7aD6jqc0rUl42fD/9uZNTm4Jmt4Hus4DjzNxajog GMs4lG2EmmMgQHvce64v7jYws0VIxYS2h1Ul+JE6LV4/qg3OasSXQEghq 79u+krX0EkN+M8zaPO88aBwo0QLhx/9vmNyhPa8NhXdY3usufLcSTEB24 xIEj6OY0tQ2CxKhjRxHikI8rtGqc62e53fsnZSw9YzXI9xdQo3sG0N3tF A==; X-CSE-ConnectionGUID: UL7BG3hvRQeOXxCw3296iQ== X-CSE-MsgGUID: QacNA6EtQ0OMBI2+tDUYog== X-IronPort-AV: E=McAfee;i="6800,10657,11984"; a="5140748" X-IronPort-AV: E=Sophos;i="6.27,248,1787036400"; d="scan'208";a="5140748" Received: from fmviesa011.fm.intel.com ([10.60.135.151]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2026 23:00:59 -0800 X-CSE-ConnectionGUID: H2fiGKG+RtqUWxp+A56pwA== X-CSE-MsgGUID: D56P1k8lTni+/qF0hOpyZw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,248,1787036400"; d="scan'208";a="15484386" 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 23:00:51 -0800 Message-ID: Date: Thu, 3 Dec 2026 15:00:48 +0800 X-Mailing-List: linux-tegra@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 16/18] iommufd/viommu: Allow vIOMMUs without a parent HWPT To: "Aneesh Kumar K.V (Arm)" , linux-coco@lists.linux.dev References: <20261125081121.379481-1-aneesh.kumar@kernel.org> <20261125081121.379481-17-aneesh.kumar@kernel.org> Content-Language: en-US From: Baolu Lu In-Reply-To: <20261125081121.379481-17-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: > VIOMMU_ALLOC currently requires a nesting parent HWPT_PAGING even when > the selected vIOMMU implementation has no use for one. This would force > implementations such as the following Arm Realm vIOMMU to create an > unused parent. > > Add IOMMUFD_VIOMMU_NO_HWPT so an implementation can opt out. Require > hwpt_id to be zero in that case and pass a NULL parent domain to its > initialization callback. For implementations requiring a parent, verify > that it supports nesting and belongs to the selected physical IOMMU > driver before invoking viommu_init(). > > Reject nested domain and hardware queue allocation for a vIOMMU without > a parent. Nested domain allocation also requires physical IOMMU backing. > Document the two allocation modes in the UAPI. [...] > diff --git a/drivers/iommu/iommufd/hw_pagetable.c b/drivers/iommu/iommufd/hw_pagetable.c > index 859eadf05f1d..deb8a94d8b75 100644 > --- a/drivers/iommu/iommufd/hw_pagetable.c > +++ b/drivers/iommu/iommufd/hw_pagetable.c > @@ -306,6 +306,13 @@ iommufd_viommu_alloc_hwpt_nested(struct iommufd_viommu *viommu, u32 flags, > return ERR_PTR(-EOPNOTSUPP); > if (!user_data->len) > return ERR_PTR(-EOPNOTSUPP); > + > + if (!viommu->hwpt) > + return ERR_PTR(-EOPNOTSUPP); > + > + if (viommu->backing != IOMMUFD_VIOMMU_BACKING_IOMMU) > + return ERR_PTR(-EOPNOTSUPP); It's better to move this check to patch 14/18. > + > if (!viommu->ops || !viommu->ops->alloc_domain_nested) > return ERR_PTR(-EOPNOTSUPP); > > diff --git a/drivers/iommu/iommufd/viommu.c b/drivers/iommu/iommufd/viommu.c > index 909ef86f39a9..e176bc2f5235 100644 > --- a/drivers/iommu/iommufd/viommu.c > +++ b/drivers/iommu/iommufd/viommu.c > @@ -19,7 +19,9 @@ void iommufd_viommu_destroy(struct iommufd_object *obj) > if (viommu->backing == IOMMUFD_VIOMMU_BACKING_TSM) > tsm_put_device(viommu->tsm_dev); > > - refcount_dec(&viommu->hwpt->common.obj.users); > + if (viommu->hwpt) > + refcount_dec(&viommu->hwpt->common.obj.users); > + > if (viommu->kvm_file) > fput(viommu->kvm_file); > xa_destroy(&viommu->vdevs); > @@ -33,7 +35,8 @@ int iommufd_viommu_alloc_ioctl(struct iommufd_ucmd *ucmd) > .uptr = u64_to_user_ptr(cmd->data_uptr), > .len = cmd->data_len, > }; > - struct iommufd_hwpt_paging *hwpt_paging; > + struct iommufd_hwpt_paging *hwpt_paging = NULL; > + struct iommu_domain *parent_domain = NULL; > struct iommufd_viommu *viommu; > struct iommufd_device *idev; > struct iommu_device *iommu_dev = NULL; > @@ -95,15 +98,27 @@ int iommufd_viommu_alloc_ioctl(struct iommufd_ucmd *ucmd) > goto out_put_idev; > } > > - hwpt_paging = iommufd_get_hwpt_paging(ucmd, cmd->hwpt_id); > - if (IS_ERR(hwpt_paging)) { > - rc = PTR_ERR(hwpt_paging); > - goto out_put_idev; > - } > + if (ops->flags & IOMMUFD_VIOMMU_NO_HWPT) { > + if (cmd->hwpt_id) { > + rc = -EINVAL; > + goto out_put_idev; > + } > + } else { > + hwpt_paging = iommufd_get_hwpt_paging(ucmd, cmd->hwpt_id); > + if (IS_ERR(hwpt_paging)) { > + rc = PTR_ERR(hwpt_paging); > + goto out_put_idev; > + } > > - if (!hwpt_paging->nest_parent) { > - rc = -EINVAL; > - goto out_put_hwpt; > + /* > + * A parent HWPT requires physical IOMMU backing. The parent must > + * support nesting and belong to that IOMMU's driver. > + */ > + if (!hwpt_paging->nest_parent || !iommu_dev || > + hwpt_paging->common.domain->owner != iommu_dev->ops) { The owner check is new and unrelated to NO_HWPT? If so, put it in its own patch with the necessary rationale. > + rc = -EINVAL; > + goto out_put_hwpt; > + } > } > > viommu = (struct iommufd_viommu *)_iommufd_object_alloc_ucmd( > @@ -119,7 +134,9 @@ int iommufd_viommu_alloc_ioctl(struct iommufd_ucmd *ucmd) > viommu->type = cmd->type; > viommu->ictx = ucmd->ictx; > viommu->hwpt = hwpt_paging; > - refcount_inc(&viommu->hwpt->common.obj.users); > + if (viommu->hwpt) > + refcount_inc(&viommu->hwpt->common.obj.users); > + > INIT_LIST_HEAD(&viommu->veventqs); > init_rwsem(&viommu->veventqs_rwsem); > > @@ -136,8 +153,10 @@ int iommufd_viommu_alloc_ioctl(struct iommufd_ucmd *ucmd) > viommu->iommu_dev = iommu_dev; > } > > - rc = ops->viommu_init(viommu, idev->dev, > - hwpt_paging->common.domain, > + if (hwpt_paging) > + parent_domain = hwpt_paging->common.domain; > + > + rc = ops->viommu_init(viommu, idev->dev, parent_domain, > user_data.len ? &user_data : NULL); > if (rc) > goto out_put_hwpt; > @@ -148,7 +167,8 @@ int iommufd_viommu_alloc_ioctl(struct iommufd_ucmd *ucmd) > rc = iommufd_ucmd_respond(ucmd, sizeof(*cmd)); > > out_put_hwpt: > - iommufd_put_object(ucmd->ictx, &hwpt_paging->common.obj); > + if (hwpt_paging) > + iommufd_put_object(ucmd->ictx, &hwpt_paging->common.obj); > out_put_idev: > iommufd_put_object(ucmd->ictx, &idev->obj); > return rc; > @@ -472,7 +492,7 @@ int iommufd_hw_queue_alloc_ioctl(struct iommufd_ucmd *ucmd) > if (IS_ERR(viommu)) > return PTR_ERR(viommu); > > - if (!viommu->ops || !viommu->ops->get_hw_queue_size || > + if (!viommu->hwpt || !viommu->ops || !viommu->ops->get_hw_queue_size || > !viommu->ops->hw_queue_init_phys) { > rc = -EOPNOTSUPP; > goto out_put_viommu; [...] > diff --git a/include/uapi/linux/iommufd.h b/include/uapi/linux/iommufd.h > index b64f6330468e..31371ccd1ef2 100644 > --- a/include/uapi/linux/iommufd.h > +++ b/include/uapi/linux/iommufd.h > @@ -1138,7 +1138,8 @@ struct iommu_viommu_tegra241_cmdqv { > * @flags: Must be 0 > * @type: Type of the virtual IOMMU. Must be defined in enum iommu_viommu_type > * @dev_id: The device's physical IOMMU will be used to back the virtual IOMMU The comment for @dev_id is stale now: for a tsm-backed viommu it selects the device's tsm device, not its physical iommu device. Please update it. > - * @hwpt_id: ID of a nesting parent HWPT to associate to > + * @hwpt_id: ID of a nesting parent HWPT to associate to. Must be zero when the > + * selected vIOMMU implementation does not use a parent HWPT This reads a bit odd. Whether a type needs a parent is now decided by the kernel implementation, but userspace has to know it up front to pass the right hwpt_id? > * @out_viommu_id: Output virtual IOMMU ID for the allocated object > * @data_len: Length of the type specific data > * @__reserved: Must be 0 Thanks, baolu