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 245C1C71136 for ; Mon, 16 Jun 2025 03:43:41 +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:Content-Transfer-Encoding: Content-Type:In-Reply-To:From:References:Cc:To:Subject: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-Owner; bh=b28MWKZYitQfUKk0aXxJSeOGNoYpjTeZblSBvXUxFD4=; b=nD+rhelNbP4HS06fZdrFXQReiJ GdU7cj0p3RQS2AXFM53z84ssvdf2VU7IkTgpnWmqKWR3tvIdaV/SYZ4JVgIKYg0WihrZLpnPxgJya T4oj6XtgFfgJpbFqkykAj49RdYC7Mc3ze12rApoDUFY1/fGtWVwbVGW04MeEN7gLhq9xL8xbiUzg1 HDjHsMNnTrvPVz4p3fjGFy+sY5j4Zb97xfMT0ea0nVvgk6RxthvgSsDlx4S8ydi+ZYHN8GWFvODVD 5kdlqUYIFBaLD5ub4HMVqZ/BsCXvigpn4PoCY8OAy6y1mIkbGyANDJ9EYier5E76L7q8vaKAGSr5/ y70tvs/A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1uR0kw-00000003HTz-31VU; Mon, 16 Jun 2025 03:43:34 +0000 Received: from mgamail.intel.com ([198.175.65.20]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1uR0Uc-00000003FdI-1ifs for linux-arm-kernel@lists.infradead.org; Mon, 16 Jun 2025 03:26:43 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1750044403; x=1781580403; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=OdSR+LnU8m8mt5Z/YXaqvXjCQ0b6HSOJ3zep8WRESSs=; b=f+Lo9Q7ZzmW3356mSAcTdg/egpm/czq7YymEvd4CmrxSh5ZR/+4CnhqT aJZSOvRgwshjZHnwATKC70DEr/tdPK2x7F32+HXe1POf4bP6rYxjMPBka X4QXSLK1PkvHyV1706cW6gJcK0iH6VfnEMj1ZR60W2j6bu9IbCyEHnngX O1PToKf7CLQdsgCbFI2R2RijVB2NYuQgObB8QW3k2VoA+Kp9Z6eCC8sHn G0dNK1tmoivse15/Rly6NxDe5MxATAF2x9+p6+/t0bVKZ9XBbP1vaFQyr myHb5kIwVObWHM942XQ4zEPM9q2z6H8lKcru0oHzZJjSpOkXtt60RJGsl A==; X-CSE-ConnectionGUID: 2mgyDjWmRqqE9vNP8Y3S1Q== X-CSE-MsgGUID: MSkbGKHETkmIpj9F8crKvw== X-IronPort-AV: E=McAfee;i="6800,10657,11465"; a="51889559" X-IronPort-AV: E=Sophos;i="6.16,240,1744095600"; d="scan'208";a="51889559" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa112.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Jun 2025 20:26:42 -0700 X-CSE-ConnectionGUID: PVYnN9jsR3+8VkdpFkfBvg== X-CSE-MsgGUID: yh81fqcOQcOBJqZhwK9EVg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,240,1744095600"; d="scan'208";a="149229856" Received: from allen-sbox.sh.intel.com (HELO [10.239.159.30]) ([10.239.159.30]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Jun 2025 20:26:38 -0700 Message-ID: Date: Mon, 16 Jun 2025 11:25:39 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 06/14] iommu: Introduce get_viommu_size and viommu_init ops To: Nicolin Chen , jgg@nvidia.com, kevin.tian@intel.com Cc: will@kernel.org, robin.murphy@arm.com, joro@8bytes.org, praan@google.com, yi.l.liu@intel.com, peterz@infradead.org, jsnitsel@redhat.com, linux-arm-kernel@lists.infradead.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, patches@lists.linux.dev References: <3ab52c5b622dad476c43b1b1f1636c8b902f1692.1749882255.git.nicolinc@nvidia.com> Content-Language: en-US From: Baolu Lu In-Reply-To: <3ab52c5b622dad476c43b1b1f1636c8b902f1692.1749882255.git.nicolinc@nvidia.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250615_202642_502905_BC4AC527 X-CRM114-Status: GOOD ( 16.66 ) 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 6/14/25 14:35, Nicolin Chen wrote: > So far, a vIOMMU object has been allocated by IOMMU driver and initialized > with the driver-level structure, before it returns to the iommufd core for > core-level structure initialization. It has been requiring iommufd core to > expose some core structure/helpers in its driver.c file, which result in a > size increase of this driver module. > > Meanwhile, IOMMU drivers are now requiring more vIOMMU-base structures for > some advanced feature, such as the existing vDEVICE and a future HW_QUEUE. > Initializing a core-structure later than driver-structure gives for-driver > helpers some trouble, when they are used by IOMMU driver assuming that the > new structure (including core) are fully initialized, for example: > > core: viommu = ops->viommu_alloc(); > driver: // my_viommu is successfully allocated > driver: my_viommu = iommufd_viommu_alloc(...); > driver: // This may crash if it reads viommu->ictx > driver: new = iommufd_new_viommu_helper(my_viommu->core ...); > core: viommu->ictx = ucmd->ictx; > core: ... > > To ease such a condition, allow the IOMMU driver to report the size of its > vIOMMU structure, let the core allocate a vIOMMU object and initialize the > core-level structure first, and then hand it over the driver to initialize > its driver-level structure. > > Thus, this requires two new iommu ops, get_viommu_size and viommu_init, so > iommufd core can communicate with drivers to replace the viommu_alloc op: > > core: viommu = ops->get_viommu_size(); > driver: return VIOMMU_STRUCT_SIZE(); > core: viommu->ictx = ucmd->ictx; // and others > core: rc = ops->viommu_init(); > driver: // This is safe now as viommu->ictx is inited > driver: new = iommufd_new_viommu_helper(my_viommu->core ...); > core: ... > > This also adds a VIOMMU_STRUCT_SIZE macro, for drivers to use, which would > statically sanitize the driver structure. > > Suggested-by: Jason Gunthorpe > Signed-off-by: Nicolin Chen Reviewed-by: Lu Baolu