From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C23D43B8D5C for ; Mon, 23 Mar 2026 16:46:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774284406; cv=none; b=F8fn8btX8qFXxwAo4DkglimD1235cHAYsb1fD2XWU/uHEVp7hfVzcEGxePjBds+BYVbb6YXZwL0L41BftZx4wmExKoBN1Odhdnitx9KB9k4sY7fgXM3vt4ymo1V920Mb/l5hGRqYTVbI8F8fr9sdQE8MonfjYF6kINy/6LlySpc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774284406; c=relaxed/simple; bh=uT6u28q8xN+HvfAicCvlLrLPXdRQ7Bx/s17nGsTFrHA=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=bappkS+Eu5rsQI+xDgDa3hkQjzTBGRW+VyBDn+q8NDkgJx7PjZmwS2duMeZ65mtuLFrcdVT3oUErJeNQmO7CoMdpVieXKaxM9rMn33FbKrp1OQt7wyU6K0eGtgiKhGwhxVjQBV06ZW7Dn6Ee8lBZ65ahTEUBLVD+b/Ba02B0U7I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=YKN8qofn; arc=none smtp.client-ip=209.85.128.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="YKN8qofn" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-486ff3a0fc1so25675075e9.2 for ; Mon, 23 Mar 2026 09:46:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1774284403; x=1774889203; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=cMPSjiU3n/bDrZwK2WBMoUe3M4rFzhZbrCZl3W9hGNA=; b=YKN8qofnf2P3h96EYPTa3s2HZMUHkJGtqxiKnk6Ng8/4Qp84x6jZvPoTKZsdg0u0lt poRnN1k7v4iohr22YBFnCnrMe36Lrt7L5nD6QVuuAH0iHi0HTG9gi24i4mJhoB0NJxx+ 4p6fJ61u1vWKCZtUgGHzD/iPz0WMzWz8WkbyzCdKMVBL4wQIqm+iRErbtJ9a1HfurDOR AvA/CQ0dqedDynocrpUJ4tUbmK4GfHVvSkZcz1ep3BMaWPEp1dQeK2CNonTMI7yLDn8N EuZ6yyhNVyn03QLB3FSUiptTf1+qg63l0tT8PIBzirFzBzZczFOBvVRCBHkbSu/pEX2w 8agw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774284403; x=1774889203; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=cMPSjiU3n/bDrZwK2WBMoUe3M4rFzhZbrCZl3W9hGNA=; b=Dhni0n+yQaDLLU/w4gURRbVF7Yi8VLCnT5NYs/L7Z9tEbH1h/aUlPBz0zKydtF5w5/ dR2iwcdaMOjiQmSSp/MJiCPJuAAtbWYeuKta5vJvVtptWn5nF+MvxpYB+3KzWYSESjpv HCrcTRZjpAr6vDS8nIzmQS/bfMVvMuBwxzIe+r+t0R342rUbovt5sKSlNizc7df+xAHe fnit7EHnozXvb7RnNN2Mpy7IHWlOB6g+w9rUF0nYi2bU8/WvKm8Wcfyp9WiOMaadwTiZ 5zXR5HllcBZvt7WYCbX0muKN/vD4nS/0aRKi89euPFqlX9iATLBtLYLgq1+zUcuaJJjc A3Xw== X-Forwarded-Encrypted: i=1; AJvYcCXbehqX97t5d5kmYUwwvTbQFF8cngZkbXw4x9FrVIK31/Bglwd9zeq0RT+rANYVNMTGM6c2sAq7nFJUi5g=@vger.kernel.org X-Gm-Message-State: AOJu0Yxko29vIyfDMcSF8RJerpqxGzuMg8f3WkgURu59YH8R9Jqk0CFG 9Hhva5eygAPwK2OlzL5Z/9In7CTNcuLkz2cCb3IOR5VJmMN1UdzuUF5c3FakyG039Ec= X-Gm-Gg: ATEYQzxzYpP0Y5KbrA85TAUfzG2NYQ08IpG+9e5LqNJg4oVkfiRFGQzTquw0VrtV28B sHQdQ7qNP6+C0/IOqLQJuTP+PYfqiE20jb/QWNgQzU3ZAhLfUn/GAR6zrWscyegHcd5NyYXcmus ZX072zE7AilFaNWAVxeIr2GU0aHutE4ivAH4A4bU3d/Pg1Rm+g7AC+DBLmyJNToI2HOJ7Xq6bjM FHFavfRg+4D1P2qG0OB+WkydzddE4AVpmaKwu8V6yYVKVPZETTVQUN3iUTYaiT5RlykeDQqOj3A IuSa6jym2ndUxifFF51pym6bLvK7ssy9A6SRuS5nWd/QpCJjoa3+BbPGRJKa14FJrta81qpYpYU LWnQW9li7f5K3TE3QxquGo83P13v1IxN8Xi7RWruAIB2+GYDbcv5M7X/aKhgEW9TfMnA56rWd5f 12Z/H0MJ259WeXKhIKLwbJ/Q8INoIdVpg= X-Received: by 2002:a05:600c:3b1e:b0:480:2521:4d92 with SMTP id 5b1f17b1804b1-486fee1ab10mr180454805e9.24.1774284403113; Mon, 23 Mar 2026 09:46:43 -0700 (PDT) Received: from [10.11.12.108] ([79.115.63.77]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-486f8b949e1sm600421655e9.9.2026.03.23.09.46.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 23 Mar 2026 09:46:42 -0700 (PDT) Message-ID: <1062b66d-e4d0-4eee-8fc2-dbb65491a01b@linaro.org> Date: Mon, 23 Mar 2026 18:46:39 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] iommu: Fix bypass of IOMMU readiness check for multi-IOMMU devices To: Jason Gunthorpe Cc: Joerg Roedel , Will Deacon , Robin Murphy , Lorenzo Pieralisi , "Rob Herring (Arm)" , Joerg Roedel , Bjorn Helgaas , iommu@lists.linux.dev, linux-kernel@vger.kernel.org, peter.griffin@linaro.org, andre.draszik@linaro.org, willmcvicker@google.com, jyescas@google.com, kernel-team@android.com, stable@vger.kernel.org References: <20260323-iommu-ready-check-v1-1-5f6fef8f9f59@linaro.org> <20260323135414.GA8437@ziepe.ca> Content-Language: en-US From: Tudor Ambarus In-Reply-To: <20260323135414.GA8437@ziepe.ca> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Hi, Jason, On 3/23/26 3:54 PM, Jason Gunthorpe wrote: > On Mon, Mar 23, 2026 at 01:09:27PM +0000, Tudor Ambarus wrote: >> Commit da33e87bd2bf ("iommu: Handle yet another race around >> registration") introduced a readiness check in `iommu_fwspec_init()` to >> prevent client drivers from configuring their IOMMUs before >> `bus_iommu_probe()` has completed. >> >> To optimize the replay path, the readiness check was conditionally >> gated behind `!dev->iommu`: >> if (!dev->iommu && !READ_ONCE(iommu->ready)) >> return -EPROBE_DEFER; >> >> However, this assumption breaks down for devices that map to multiple >> IOMMU instances. > > ?? We don't directly support "multiple IOMMU instances". There is only > one dev->iommu. > > AFAIK if some drivers need to support multiple different instances of > the same IOMMU driver they must deal with this fully internally and > present to the core a "single instance" view. Thanks for the quick answer. I may miss a few things, I should have marked this as an RFC. Would you please help me understand a little bit more on this topic? Downstream we have a display controller that's using: iommus = <&sysmmu_19840000>, <&sysmmu_19c40000>; These are 2 distinct platform devices, they probe independently, they each call iommu_device_register() independently. If I understood you correctly, the downstream driver shall model its architecture and call iommu_device_register() only once after both devices are configured. My downstream reality is different. Here's what I'm encountering: 1/ sysmmu_19840000: dev->iommu is NULL. iommu_fwspec_init() correctly evaluates !READ_ONCE(sysmmu_19840000->ready). Assuming it is ready, it allocates dev->iommu. 2/ dev->iommu is now NOT NULL. iommu_fwspec_init() is called for the second physical instance. 3/ Because of the !dev->iommu gate, the evaluation of !READ_ONCE(sysmmu_19c40000->ready) is short-circuited and skipped entirely. But sysmmu_19c40000 is not ready, its specific bus_iommu_probe() is executing asynchronously on another CPU. If the core's intent is to strictly enforce a single IOMMU instance, shouldn't iommu_fwspec_init() be checking fwspec->iommu_fwnode == iommu_fwnode instead of matching the ops? Because the core currently matches on ops, it permits aggregating multiple physical instances with the same ops into one fwspec. Thanks a ton! ta --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -2940,7 +2940,7 @@ int iommu_fwspec_init(struct device *dev, struct fwnode_handle *iommu_fwnode) return -EPROBE_DEFER; if (fwspec) - return iommu->ops == iommu_fwspec_ops(fwspec) ? 0 : -EINVAL; + return fwspec->iommu_fwnode == iommu_fwnode ? 0 : -EINVAL; if (!dev_iommu_get(dev)) return -ENOMEM;