From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 31AC3606A33A for ; Thu, 3 Dec 2026 07:01:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=zLW10Kl7; 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; 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:Content-Transfer-Encoding: Content-Type:In-Reply-To:From:References:To:Subject:Cc:MIME-Version:Date: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Unsubscribe-Post: List-Owner; bh=AuXbDMOSWntQLvp9tMzUfGfPpwSfj1L6JLCmj7DcNE0=; b=zLW10Kl7vsrTJn dEbyDFlj7w2R3LKWz29hifQlCz7kALwn+wZCO42O+jG7qkkncFMyAraBHVnIQuE9OWWIDuT5XQCN6 xZ5qs/fgQcH5uqTuEY8P446qfC3BnueWfPYMeVtAUN2wZrJsX3E95ydx5QTAz/E4ysDis/t7qQ9M5 lS6cEpcRzC/Pjj4GLn7cHo3Denz8J80g05EkIWBt0gpKRazrf8XQvw6/+jm3x2R7la4WQa1ajeb1m cUdeJU5b+8HKiZ/IMaUKa0MO81srDesTdph9kO+pomVEYeNL7Xi83jqrrK1TshPjt0T9FRXCmaP2i qz0eolhpJGS52KJyhpZw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZ0oR-0000000DihU-1L52; Thu, 03 Dec 2026 07:01:03 +0000 Received: from mgamail.intel.com ([198.175.65.14]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZ0oN-0000000DigL-2dmd for linux-arm-kernel@lists.infradead.org; Thu, 03 Dec 2026 07:01:01 +0000 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: GCXsf65USgGykg0A5ZJ3Nw== X-CSE-MsgGUID: 5BpnCuQ3Tm2UESxwuyL8Fg== X-IronPort-AV: E=McAfee;i="6800,10657,11984"; a="5140754" X-IronPort-AV: E=Sophos;i="6.27,248,1787036400"; d="scan'208";a="5140754" 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-Archived-By: 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261202_230059_801559_ADE3FCA4 X-CRM114-Status: GOOD ( 25.89 ) X-Spam-Score: -4.2 (----) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-10.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 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