Received: by 2002:a05:6500:2018:b0:1fb:9675:f89d with SMTP id t24csp232373lqh; Thu, 30 May 2024 22:22:19 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWi7jxiQaBsrLv5cxrXPQitVycaDTnpt8EapNQU3FwnH5fy7rAq8Z0x82hiLMFG+bc1PaqfEC05vOmhAX209wxtGlTKB0MmSeT5jtklKg== X-Google-Smtp-Source: AGHT+IEsYO2n5KxKg3PXdTc/YDcMr0RQuT3hWttDnAsXob+HNZ72Lxx578f+Zj0SiWIAh8dVc3kq X-Received: by 2002:a17:902:e748:b0:1f6:1562:6e40 with SMTP id d9443c01a7336-1f63704b422mr9928445ad.38.1717132939323; Thu, 30 May 2024 22:22:19 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717132939; cv=pass; d=google.com; s=arc-20160816; b=wdCLF+38bbg6QVzx2kTYfwnKh9JOvc6gkGS7uxxSspjVUphTW79tNhUqsJvHr9+DVJ zj9pZAEEJB5ts+9A2l8r2xnD/RQaOzcHG68RGpapBE31ztC0P6P9TBIIYlp+IZoPB7hJ W+tg6//SPJiV2ZDnGXmNC7a6nFM7nhIw71XxGRRN0RtvBSdaSEMFxPDBtvmkKNx/ZFqZ J8idGs3BpUi+oI4DbEnkXyq0RcIfjoNFgPVe5X+8QgJm8jfXf6xn2sf8dvpvmEq2hRBc IN1DQWoh+6w5tIg3Wm490boHt9m9yI+Q7K0l/TbUYUB9H0/QRC/wiuZ8jnbDanNIxtX6 M/kg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:cc:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=2aQgQoQ3x0J8I/ANNsISBseuVLgo//ueTFtwhM7kgpA=; fh=k1nEXbxcUvh7ZgNVvRmkyJOmnpTKvkfpURBr2MiT3yo=; b=oJr/w4iqz+RrKLxbqKwyZcifFk4UIs41hAQ1ql2Cuo7tKVDxPj7eH0sIz6VIpUNp+a 19Ev3ViNfvwr9ElHn7P4FQGeDgSxZ7jQbnzRiwTonFWQIIIVaWNvHmk+92U0RQI/TDXm OgZRISILLO/maD2NJbXyx0Y5z/1ofP0L7zj/IUKwgqUTAEXuQvaOtmbdfgHROTKp9tfX LT1Csy1OCtccPaqeIBLWJen3IEKOfyTFdVj+HZaYJR/CZDe285ateSw/VsTKA3ooRwzr FqZk/3Pr21O/btEevNdShvd9kUyY3BorMdvx8WlagST83AMqkF6eUF18/JTe8eSma0ew BArw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Mi7WIbfA; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-196203-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-196203-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id d9443c01a7336-1f6323eb703si9603915ad.412.2024.05.30.22.22.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 22:22:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-196203-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Mi7WIbfA; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-196203-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-196203-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 1424BB2526C for ; Fri, 31 May 2024 02:54:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0997678C6C; Fri, 31 May 2024 02:54:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Mi7WIbfA" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7092E256D for ; Fri, 31 May 2024 02:54:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.12 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717124079; cv=none; b=rVYSc3fUwDBMr/WxNNVIvBvd2Z1ANCh0tlwGr8vhkSKE4cQDQesy/XGTsPYZ6wlsrFy3o2/HIVAsvrCTyy8wElf2SWV+6afIzKmh6Ua2su6O0kn+7b9a3cUa7xtdoZQ6RJer7+hiHL1xKyWvS6WLGbMPtUYkFxnqFvzZfU+kC2k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717124079; c=relaxed/simple; bh=3qoAmgqtvz5n2DFxkNTr1ulFou6xmODb43pmh5+qrGU=; h=Message-ID:Date:MIME-Version:Cc:Subject:To:References:From: In-Reply-To:Content-Type; b=NyhRYayqf+AgJB/U6ChsKUSLRLP5Lyi87yWrJbCUw+y5dv2xQyR4aeYOZEyPWf4JWJ/24yLIwv5XiHkYEbTd5YIIQ6NQBpH2DgqiqXkgYG4vl4ZX1phdKod/SkWHBO5OAQRqD8n1DWJs1UIIr2jo4VcxLsDg2QogPZBdCbXGWGk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Mi7WIbfA; arc=none smtp.client-ip=198.175.65.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1717124078; x=1748660078; h=message-id:date:mime-version:cc:subject:to:references: from:in-reply-to:content-transfer-encoding; bh=3qoAmgqtvz5n2DFxkNTr1ulFou6xmODb43pmh5+qrGU=; b=Mi7WIbfA2QtJZhjofhggdccIwvvQbhPexynK/DY0PlC24WRgZ2MYCPXg toa7DdNgEd+hQ+J91jBguDvgbVBEj0ojVcfJoBAzsQyD1rtzEqVFw3Ope ChBhziKyHsfWb6ZwVvgonCcHtr0vYBmVfYrTRHWItFkPiMa3Obe1wqFAi ZmwGequ4vyG+vpGEHSauBheGGkDzAmj69lchvRa1JSpEWmCZi0GjkW9XW 5nWhWVmIZjOpWqQQXtA9kROjmnLH0B3MwvHOfE6Q0SgpaI3QnPhUQXXdh uLzgAoQPqpQnlDzatGOBYuFSqEzE2b83XAx941YTLhCvKlwJIaYlNdvVx Q==; X-CSE-ConnectionGUID: bLtUxMNZST6OKbE6mM3k1w== X-CSE-MsgGUID: h1/NaM3GRbS9Db+L+wqF7g== X-IronPort-AV: E=McAfee;i="6600,9927,11088"; a="25054812" X-IronPort-AV: E=Sophos;i="6.08,203,1712646000"; d="scan'208";a="25054812" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 May 2024 19:54:38 -0700 X-CSE-ConnectionGUID: C4V03CkPTL2PiPlQZwr4rA== X-CSE-MsgGUID: BRb7C+xcRqafLJFt/HMIsg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,203,1712646000"; d="scan'208";a="36067256" Received: from unknown (HELO [10.239.159.127]) ([10.239.159.127]) by fmviesa006.fm.intel.com with ESMTP; 30 May 2024 19:54:32 -0700 Message-ID: Date: Fri, 31 May 2024 10:52:25 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Cc: baolu.lu@linux.intel.com, Yi Liu , David Airlie , Daniel Vetter , Kalle Valo , Bjorn Andersson , Mathieu Poirier , Alex Williamson , mst@redhat.com, Jason Wang , Thierry Reding , Jonathan Hunter , Mikko Perttunen , iommu@lists.linux.dev, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 00/20] iommu: Refactoring domain allocation interface To: Robin Murphy , Joerg Roedel , Will Deacon , Jason Gunthorpe , Kevin Tian References: <20240529053250.91284-1-baolu.lu@linux.intel.com> Content-Language: en-US From: Baolu Lu In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 5/31/24 1:59 AM, Robin Murphy wrote: > On 29/05/2024 6:32 am, Lu Baolu wrote: >> The IOMMU subsystem has undergone some changes, including the removal >> of iommu_ops from the bus structure. Consequently, the existing domain >> allocation interface, which relies on a bus type argument, is no longer >> relevant: >> >>      struct iommu_domain *iommu_domain_alloc(struct bus_type *bus) >> >> This series is designed to refactor the use of this interface. It >> proposes two new interfaces to replace iommu_domain_alloc(): >> >> - iommu_user_domain_alloc(): This interface is intended for allocating >>    iommu domains managed by userspace for device passthrough scenarios, >>    such as those used by iommufd, vfio, and vdpa. It clearly indicates >>    that the domain is for user-managed device DMA. >> >>    If an IOMMU driver does not implement iommu_ops->domain_alloc_user, >>    this interface will rollback to the generic paging domain allocation. >> >> - iommu_paging_domain_alloc(): This interface is for allocating iommu >>    domains managed by kernel drivers for kernel DMA purposes. It takes a >>    device pointer as a parameter, which better reflects the current >>    design of the IOMMU subsystem. >> >> The majority of device drivers currently using iommu_domain_alloc() do >> so to allocate a domain for a specific device and then attach that >> domain to the device. These cases can be straightforwardly migrated to >> the new interfaces. > > Ooh, nice! This was rising back up my to-do list as well, but I concur > it's rather more straightforward than my version that did devious things > to keep the iommu_domain_alloc() name... > >> However, there are some drivers with more complex use cases that do >> not fit neatly into this new scheme. For example: >> >> $ git grep "= iommu_domain_alloc" >> arch/arm/mm/dma-mapping.c:      mapping->domain = >> iommu_domain_alloc(bus); > > This one's simple enough, the refactor just needs to go one step deeper. > I've just rebased and pushed my old patch for that, if you'd like it [1]. Great! With this change, we can safely replace iommu_domain_alloc(). diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c index 52f9c56cc3cb..88c2d68a69c9 100644 --- a/arch/arm/mm/dma-mapping.c +++ b/arch/arm/mm/dma-mapping.c @@ -1585,9 +1585,11 @@ arm_iommu_create_mapping(struct device *dev, dma_addr_t base, u64 size) spin_lock_init(&mapping->lock); - mapping->domain = iommu_domain_alloc(dev->bus); - if (!mapping->domain) + mapping->domain = iommu_paging_domain_alloc(dev); + if (IS_ERR(mapping->domain)) { + err = PTR_ERR(mapping->domain); goto err4; + } kref_init(&mapping->kref); return mapping; > >> drivers/gpu/drm/rockchip/rockchip_drm_drv.c:    private->domain = >> iommu_domain_alloc(private->iommu_dev->bus); > > Both this one and usnic_uiom_alloc_pd() should be OK - back when I did > all the figuring out to clean up iommu_present(), I specifically > reworked them into "dev->bus" style as a reminder that it *is* supposed > to be the right device for doing this with, even if the attach is a bit > more distant. Yeah! I will cleanup these two in the next version. > >> drivers/gpu/drm/tegra/drm.c:            tegra->domain = >> iommu_domain_alloc(&platform_bus_type); > > This is the tricky one, where the device to hand may *not* be the right > device for IOMMU API use [2]. FWIW my plan was to pull the "walk the > platform bus to find any IOMMU-mapped device" trick into this code and > use it both to remove the final iommu_present() and for a device-based > domain allocation. I am not familiar with this driver, so the solution you mentioned above is the best option I can think of for now. I will incorporate this into the next version. > >> drivers/infiniband/hw/usnic/usnic_uiom.c:       pd->domain = domain = >> iommu_domain_alloc(dev->bus); >> >> This series leave those cases unchanged and keep iommu_domain_alloc() >> for their usage. But new drivers should not use it anymore. > > I'd certainly be keen for it to be gone ASAP, since I'm seeing > increasing demand for supporting multiple IOMMU drivers, and this is the > last bus-based thing standing in the way of that. Agreed. With all iommu_domain_alloc() removed, iommu_domain_alloc() could be dropped. > > Thanks, > Robin. > > [1] > https://gitlab.arm.com/linux-arm/linux-rm/-/commit/f048cc6a323d8641898025ca96071df7cbe8bd52 > [2] > https://lore.kernel.org/linux-iommu/add31812-50d5-6cb0-3908-143c523abd37@collabora.com/ Best regards, baolu