From nobody Sun Jun 14 12:44:33 2026 Received: from mail-dl1-f43.google.com (mail-dl1-f43.google.com [74.125.82.43]) (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 953DA257435 for ; Fri, 3 Apr 2026 00:51:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775177508; cv=none; b=k5rKq1wJl9XKZW5gbVM96ZF+jlqPg0XvSeKBFw1K6KpC1YmIBAhwbC2J45C7tGrPs2OmLGPaUJcMkvpk/6FCJeCYfmZcszB1JI92exBcDb7XIHsaX8X7gMxNgvIYNay7V8JQocCU3w07qNcLTUMs3oS2Go1SZf5NTppPz/ZTY/Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775177508; c=relaxed/simple; bh=KnJo6R0iyyoFy+tL/8ZQZh458HxfnzrOB+hwzmicJNA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=M/jgbysZRDqnJMORfKqMHNjKoHldtbWh1q41cWzIpjSzmp5+i3SITd/yQ9b3zY3ZMMF49KJyXNWo82QLuPKb/ihVl5Nchden9nfWt/kvvc/Tm3Zc9WM7H4Qad9MOLwg7yODCl/g1TaIOqeUKNtGIaH0ESmgwVW71GA0RC7AIo4Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=Pz9c4HMB; arc=none smtp.client-ip=74.125.82.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="Pz9c4HMB" Received: by mail-dl1-f43.google.com with SMTP id a92af1059eb24-12776bebe9fso3556435c88.1 for ; Thu, 02 Apr 2026 17:51:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1775177499; x=1775782299; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=GSIiwaCtYR5157C3DMqOicVwO2x1esOFHTqM3gbjMuc=; b=Pz9c4HMBtkVaD/KsFdLKohY7pQSJXDN+zD6U5N09UXf5m/tXWlnF4wyrwt2yj3nXtW xK5MV/SwK7A/yMk3GKTUlECvv7hWI4E6AHr0bhfaTI2WQL7o93M7b0oROXTY2Wl6b+ut c2GVxDgDe2yZb7Ro/610JlPjiUz5Zx0Untemo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775177499; x=1775782299; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=GSIiwaCtYR5157C3DMqOicVwO2x1esOFHTqM3gbjMuc=; b=NaJTtHTlWwUDnI3sm4MmQhp1djP+VNJHOHnHgIwDQIwKlVQznjf/3nDYokKHDJDq/T 7jVI0NQNapmPMM6pOamQZdfsS3FsTkl3jdZtQCUgwV5WHRtuQKg1Mg2NMk0AEvdZ3fzD L4i4vxE+sm/nE0uP70ZU6FhJ2InIF618p4ZwLwTt2gGTH/JauyK5QVXY0ACgvlWG3n4E Sd14O5SIVaU+KJWorkhPVhQNwzA3SgJMAINI78j4wRheP2l8cD8PMRuzfa2Yj9KE6utG IkjKPaKTXHxXs8hnXYp/nzC90Oor5ZQ9lWOUHUSHtlZ3YFkyfdXvtq8f4kmriNRYOOWW 0Wrw== X-Forwarded-Encrypted: i=1; AJvYcCVTEAx/qDJbHv+phQO48PIi03gdCzBuYXzrFLY/Nez+vgUxDvonHerqPt64t1wYzygMaHLn1YajpbI86qY=@vger.kernel.org X-Gm-Message-State: AOJu0Yy/GqnOEidqbQ0ENZ77AuqkR6gYOShMCzW+OEYE2+0hdFd+Fsec YhGMPW0HuRVQ54+BrH59WuswDccYDmOhucnLW3s1pbh678J5D7+De11iFwQqExgcfQ== X-Gm-Gg: ATEYQzw9dDrSZ2rgqh4Hr11UAWaBk6qPiFSvhdgAAA+X6S+PBfvMFJtHTD8w0NEq229 nRmGjlecTKb2UDn/7YIW528HQEVJvG3EJYKVsIyTSq3eVzlQ9I64qGt365kXeb2+UUZXkgoxcm6 3nRl/MzUHYnFREHE3ULE618V/k8VSig0balGeImxrImGnZNOR2cczOWQ1rusgnXiewPh86O+INy uWAXqqVdo8muZZsvTh1RgZw+mX5SoqLl/N8PPV0DRdPbwGzkt4b43jxriqYXvAwKzxloH3aFvfl SDRblidpfYBy8zqSp5QRo7i/IaCVQjQGHo6gMCjGHNog/dMv6FEwSzmdq+Qq7w3aQ4k+OckkOO8 1gz1gb6Ptw3AaOZUJk1/KnVeb9KdudJZuy7ZY+/FsDpW7t318n5owaQU2X6qBlDFCS4Khln0Rc1 xKO9QPvnj7u794wP1ID+pWBRfUZ80XkVVmulf4a1D02zBHrrL3HX9FVaqhO8b5cJhSELAUk1tqZ EA7n4BtLj0= X-Received: by 2002:a05:7022:401:b0:12a:b932:81d2 with SMTP id a92af1059eb24-12bfb745cecmr660075c88.21.1775177498569; Thu, 02 Apr 2026 17:51:38 -0700 (PDT) Received: from dianders.sjc.corp.google.com ([2a00:79e0:2e7c:8:5db3:7542:a530:f43a]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2ca78df3b84sm3630074eec.5.2026.04.02.17.51.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Apr 2026 17:51:36 -0700 (PDT) From: Douglas Anderson To: Greg Kroah-Hartman , "Rafael J . Wysocki" , Danilo Krummrich , Alan Stern Cc: Robin Murphy , Leon Romanovsky , Paul Burton , Saravana Kannan , Alexander Lobakin , Eric Dumazet , Toshi Kani , Christoph Hellwig , Alexey Kardashevskiy , Johan Hovold , Douglas Anderson , stable@vger.kernel.org, driver-core@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v3 1/9] driver core: Don't let a device probe until it's ready Date: Thu, 2 Apr 2026 17:49:47 -0700 Message-ID: <20260402174925.v3.1.Id750b0fbcc94f23ed04b7aecabcead688d0d8c17@changeid> X-Mailer: git-send-email 2.53.0.1213.gd9a14994de-goog In-Reply-To: <20260403005005.30424-1-dianders@chromium.org> References: <20260403005005.30424-1-dianders@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The moment we link a "struct device" into the list of devices for the bus, it's possible probe can happen. This is because another thread can load the driver at any time and that can cause the device to probe. This has been seen in practice with a stack crawl that looks like this [1]: really_probe() __driver_probe_device() driver_probe_device() __driver_attach() bus_for_each_dev() driver_attach() bus_add_driver() driver_register() __platform_driver_register() init_module() [some module] do_one_initcall() do_init_module() load_module() __arm64_sys_finit_module() invoke_syscall() As a result of the above, it was seen that device_links_driver_bound() could be called for the device before "dev->fwnode->dev" was assigned. This prevented __fw_devlink_pickup_dangling_consumers() from being called which meant that other devices waiting on our driver's sub-nodes were stuck deferring forever. It's believed that this problem is showing up suddenly for two reasons: 1. Android has recently (last ~1 year) implemented an optimization to the order it loads modules [2]. When devices opt-in to this faster loading, modules are loaded one-after-the-other very quickly. This is unlike how other distributions do it. The reproduction of this problem has only been seen on devices that opt-in to Android's "parallel module loading". 2. Android devices typically opt-in to fw_devlink, and the most noticeable issue is the NULL "dev->fwnode->dev" in device_links_driver_bound(). fw_devlink is somewhat new code and also not in use by all Linux devices. Even though the specific symptom where "dev->fwnode->dev" wasn't assigned could be fixed by moving that assignment higher in device_add(), other parts of device_add() (like the call to device_pm_add()) are also important to run before probe. Only moving the "dev->fwnode->dev" assignment would likely fix the current symptoms but lead to difficult-to-debug problems in the future. Fix the problem by preventing probe until device_add() has run far enough that the device is ready to probe. If somehow we end up trying to probe before we're allowed, __driver_probe_device() will return -EPROBE_DEFER which will make certain the device is noticed. In the race condition that was seen with Android's faster module loading, we will temporarily add the device to the deferred list and then take it off immediately when device_add() probes the device. Instead of adding another flag to the bitfields already in "struct device", instead add a new "flags" field and use that. This allows us to freely change the bit from different thread without holding the device lock and without worrying about corrupting nearby bits. [1] Captured on a machine running a downstream 6.6 kernel [2] https://cs.android.com/android/platform/superproject/main/+/main:system= /core/libmodprobe/libmodprobe.cpp?q=3DLoadModulesParallel Cc: stable@vger.kernel.org Fixes: 2023c610dc54 ("Driver core: add new device to bus's list before prob= ing") Reviewed-by: Alan Stern Reviewed-by: Rafael J. Wysocki (Intel) Signed-off-by: Douglas Anderson --- v1: https://lore.kernel.org/r/20260320200656.RFC.1.Id750b0fbcc94f23ed04b7ae= cabcead688d0d8c17@changeid v2: https://lore.kernel.org/r/20260330072839.v2.1.Id750b0fbcc94f23ed04b7aec= abcead688d0d8c17@changeid As of v2 this feels like a very safe change. It doesn't change the ordering of any steps of probe and it _just_ prevents the early probe from happening. I ran tests where I turned the printout "Device not ready_to_probe" on and I could see the printout happening, evidence of the race occurring from other printouts, and things successfully being resolved. I kept Alan and Rafael's Reviewed-by tags in v3 even though I changed the implementation to use "flags" as per Danilo's request. This didn't seem like a major enough change to remove tags, but please shout if you'd like your tag removed. Changes in v3: - Use a new "flags" bitfield - Add missing \n in probe error message Changes in v2: - Instead of adjusting the ordering, use "ready_to_probe" flag drivers/base/core.c | 13 +++++++++++++ drivers/base/dd.c | 12 ++++++++++++ include/linux/device.h | 15 +++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/drivers/base/core.c b/drivers/base/core.c index 09b98f02f559..8d4028a2165f 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -3688,6 +3688,19 @@ int device_add(struct device *dev) fw_devlink_link_device(dev); } =20 + /* + * The moment the device was linked into the bus's "klist_devices" in + * bus_add_device() then it's possible that probe could have been + * attempted in a different thread via userspace loading a driver + * matching the device. "DEV_FLAG_READY_TO_PROBE" being unset would have + * blocked those attempts. Now that all of the above initialization has + * happened, unblock probe. If probe happens through another thread + * after this point but before bus_probe_device() runs then it's fine. + * bus_probe_device() -> device_initial_probe() -> __device_attach() + * will notice (under device_lock) that the device is already bound. + */ + set_bit(DEV_FLAG_READY_TO_PROBE, &dev->flags); + bus_probe_device(dev); =20 /* diff --git a/drivers/base/dd.c b/drivers/base/dd.c index 37c7e54e0e4c..3aead51173f8 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -848,6 +848,18 @@ static int __driver_probe_device(const struct device_d= river *drv, struct device if (dev->driver) return -EBUSY; =20 + /* + * In device_add(), the "struct device" gets linked into the subsystem's + * list of devices and broadcast to userspace (via uevent) before we're + * quite ready to probe. Those open pathways to driver probe before + * we've finished enough of device_add() to reliably support probe. + * Detect this and tell other pathways to try again later. device_add() + * itself will also try to probe immediately after setting + * "DEV_FLAG_READY_TO_PROBE". + */ + if (!test_bit(DEV_FLAG_READY_TO_PROBE, &dev->flags)) + return dev_err_probe(dev, -EPROBE_DEFER, "Device not ready to probe\n"); + dev->can_match =3D true; dev_dbg(dev, "bus: '%s': %s: matched device with driver %s\n", drv->bus->name, __func__, drv->name); diff --git a/include/linux/device.h b/include/linux/device.h index e65d564f01cd..5b7ace5921aa 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -458,6 +458,18 @@ struct device_physical_location { bool lid; }; =20 +/** + * enum struct_device_flags - Flags in struct device + * + * Should be accessed with thread-safe bitops. + * + * @DEV_FLAG_READY_TO_PROBE: If set then device_add() has finished enough + * initialization that probe could be called. + */ +enum struct_device_flags { + DEV_FLAG_READY_TO_PROBE, +}; + /** * struct device - The basic device structure * @parent: The device's "parent" device, the device to which it is attach= ed. @@ -553,6 +565,7 @@ struct device_physical_location { * @dma_skip_sync: DMA sync operations can be skipped for coherent buffers. * @dma_iommu: Device is using default IOMMU implementation for DMA and * doesn't rely on dma_ops structure. + * @flags: DEV_FLAG_XXX flags. Use atomic bitfield operations to modify. * * At the lowest level, every device in a Linux system is represented by an * instance of struct device. The device structure contains the information @@ -675,6 +688,8 @@ struct device { #ifdef CONFIG_IOMMU_DMA bool dma_iommu:1; #endif + + unsigned long flags; }; =20 /** --=20 2.53.0.1213.gd9a14994de-goog From nobody Sun Jun 14 12:44:33 2026 Received: from mail-dy1-f177.google.com (mail-dy1-f177.google.com [74.125.82.177]) (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 3B6FA225403 for ; Fri, 3 Apr 2026 00:51:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775177503; cv=none; b=oEhc/oe+bSnp5+ZXkpElXziIKMPmh33S31e+b3zYrnHmExJiuzwu+5wUnfV+8RVNOaP4F+GwBTWmZ0YwR8WUgFraLPm10uSSD9qAQMSlRbzFT/bQfCBxOIX9kn6gknyWzxrWhZ2EFvYl51+TdmN5LCyaNk0bG427SBaZkS+g5sk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775177503; c=relaxed/simple; bh=Bo2GWZohNn292lukZgzff2DpfwhmF9Z6e0841aFT4Zs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZuHDZYkwZK+minuiVek6SPwA+XGaaMz99h8uGPSZg4FxczbrlpREEmlVOAfD1j9ZAjCNhLY74jzozxsTu4+17WgB/UmYZMy+1jb1QWDLphBJau44tvL3sbjPimevyYTGwsj+u2qJLXS35rFgryFX2UztH6hj1Ja/w4PJVSjda6A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=SV2KPazR; arc=none smtp.client-ip=74.125.82.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="SV2KPazR" Received: by mail-dy1-f177.google.com with SMTP id 5a478bee46e88-2c15849aa2cso1763351eec.0 for ; Thu, 02 Apr 2026 17:51:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1775177501; x=1775782301; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=XoCbtVdJT6LJXHOLiB7SAxTxtsznK4H2L8Y6Y6a13vM=; b=SV2KPazReojbP7oVKWLo318Tpn5wEbAnI99+jcF0LvEUs0ZheGy6R6dsRdUjY7k1mm MCnotM9HV/M0GEdZn9dhxsi8YUJ8i19J4JxWvlTiYQGhXSvaZzeppppVfTh1HFMTTJUZ WmSddk4XNC6uRSE4M+SKyEX8LVxi6jLKG1i2c= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775177501; x=1775782301; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=XoCbtVdJT6LJXHOLiB7SAxTxtsznK4H2L8Y6Y6a13vM=; b=VJxnLACjW8ZfIgpUy0VN4s3sHigT7DMQCzJAebQNrMIcTKhxZaytgtezKN7+Mculcf xxQHe6OTK5XOoIcryB7Vz4h6LREPLW1ugKhFL6Zu2iOaKqrR28ka6f7cZkpR19B8DlxO BLZ2ePf0bGppNa1c2Rw9tmQjI+aXbEhAGtXteONxeH8bxkTigjPFdKBfXGrZC7o5H/nE sH7I8c0s0gFKejrmNqRHdPLNzH+rx9ExLKu2CTOzORlrl9yh/BO2G2i2P2/fjlOeaqlb 61w3gXNHgLezTHuJhlnOQiVpWmZYKrun1a6o2hdiwYHC43qk7iMyfgEgdAKbbgNw8lEl PxOA== X-Forwarded-Encrypted: i=1; AJvYcCXCMSOaOImXKmPXw64T5TKjPvYEosRH7foIfiDVQYj0rhVsH8iNLcrTXQXRSD2ZsUzE9Y5TZb7i85WPvfM=@vger.kernel.org X-Gm-Message-State: AOJu0YwCAAUJvAeFp4XjMFH9bjTRcXxgBKjNwv7Neb3+xlFqpTIM+wKH 9ktyRRwmI+goowgApBQAOGKMv/qQ4zvHDg6o782utxEjF9X5S3A5xr+w9Gi+Zx0WSw== X-Gm-Gg: AeBDiet95xPNya7xSUJMIqpbmZXCxTT7BRmeQ/hN54p5b+mvDTUZ4RwUo4MxMXzFtNh uVOrzh1wuL3bN/xjxK72u7cQ1XSGKO0N2t/DSZwI9gZ6XYgob3iE41X+cskYgpiOxpjAdG+RdXM cyISnpwhcegwlMs/pqvCyC/b288C8Pu9TFpjt/MqeSGisDKPmHGm2P6pAxBbDlJXGXs3WymP6Uy qGEfhdAp+AhU6QsulomBBSFnMg43S41FApXy/bwJsjyPFv5aiBDN9f+TW+JqlpsKu1dlCrCS2v7 eK9vd0GxnvP6blR4JH7Pt1Dxk9XQ9tH+cToJpz1BLk1ETHKqxIVLkmHYNzTlZSqnSisYYnw5Puo j+UI8kh6MWEJMK+YldEhcmUltR/gtrh3npztgvOdH0RpKKzitEhhJYTZBKp2CemFf6FqPKYh8r5 mOLyeCg1TIIopahuZQ6bKDHXnZrXo6DLtUenHQ2MUlyXvHY1k82K4uKma0eZyz8Ib2cBZzhr9y5 e9diOpaBP0= X-Received: by 2002:a05:7300:fd05:b0:2c0:d46d:cfc2 with SMTP id 5a478bee46e88-2cbfbe7d5e0mr573537eec.23.1775177501410; Thu, 02 Apr 2026 17:51:41 -0700 (PDT) Received: from dianders.sjc.corp.google.com ([2a00:79e0:2e7c:8:5db3:7542:a530:f43a]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2ca78df3b84sm3630074eec.5.2026.04.02.17.51.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Apr 2026 17:51:39 -0700 (PDT) From: Douglas Anderson To: Greg Kroah-Hartman , "Rafael J . Wysocki" , Danilo Krummrich , Alan Stern Cc: Robin Murphy , Leon Romanovsky , Paul Burton , Saravana Kannan , Alexander Lobakin , Eric Dumazet , Toshi Kani , Christoph Hellwig , Alexey Kardashevskiy , Johan Hovold , Douglas Anderson , Saravana Kannan , driver-core@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v3 2/9] driver core: Replace dev->can_match with DEV_FLAG_CAN_MATCH Date: Thu, 2 Apr 2026 17:49:48 -0700 Message-ID: <20260402174925.v3.2.I54b3ae6311ff34ad30227659d91bb109911a4aea@changeid> X-Mailer: git-send-email 2.53.0.1213.gd9a14994de-goog In-Reply-To: <20260403005005.30424-1-dianders@chromium.org> References: <20260403005005.30424-1-dianders@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In C, bitfields are not necessarily safe to modify from multiple threads without locking. Switch "can_match" over to the "flags" field so modifications are safe. Cc: Saravana Kannan Signed-off-by: Douglas Anderson --- Not fixing any known bugs; problem is theoretical and found by code inspection. Change is done somewhat manually and only lightly tested (mostly compile-time tested). Changes in v3: - New drivers/base/core.c | 10 +++++----- drivers/base/dd.c | 8 ++++---- include/linux/device.h | 8 ++++---- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/drivers/base/core.c b/drivers/base/core.c index 8d4028a2165f..cbdfee887833 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -1011,7 +1011,7 @@ static void device_links_missing_supplier(struct devi= ce *dev) =20 static bool dev_is_best_effort(struct device *dev) { - return (fw_devlink_best_effort && dev->can_match) || + return (fw_devlink_best_effort && test_bit(DEV_FLAG_CAN_MATCH, &dev->flag= s)) || (dev->fwnode && (dev->fwnode->flags & FWNODE_FLAG_BEST_EFFORT)); } =20 @@ -1079,7 +1079,7 @@ int device_links_check_suppliers(struct device *dev) =20 if (dev_is_best_effort(dev) && device_link_test(link, DL_FLAG_INFERRED) && - !link->supplier->can_match) { + !test_bit(DEV_FLAG_CAN_MATCH, &link->supplier->flags)) { ret =3D -EAGAIN; continue; } @@ -1370,7 +1370,7 @@ void device_links_driver_bound(struct device *dev) } else if (dev_is_best_effort(dev) && device_link_test(link, DL_FLAG_INFERRED) && link->status !=3D DL_STATE_CONSUMER_PROBE && - !link->supplier->can_match) { + !test_bit(DEV_FLAG_CAN_MATCH, &link->supplier->flags)) { /* * When dev_is_best_effort() is true, we ignore device * links to suppliers that don't have a driver. If the @@ -1758,7 +1758,7 @@ static int fw_devlink_no_driver(struct device *dev, v= oid *data) { struct device_link *link =3D to_devlink(dev); =20 - if (!link->supplier->can_match) + if (!test_bit(DEV_FLAG_CAN_MATCH, &link->supplier->flags)) fw_devlink_relax_link(link); =20 return 0; @@ -3708,7 +3708,7 @@ int device_add(struct device *dev) * match with any driver, don't block its consumers from probing in * case the consumer device is able to operate without this supplier. */ - if (dev->fwnode && fw_devlink_drv_reg_done && !dev->can_match) + if (dev->fwnode && fw_devlink_drv_reg_done && !test_bit(DEV_FLAG_CAN_MATC= H, &dev->flags)) fw_devlink_unblock_consumers(dev); =20 if (parent) diff --git a/drivers/base/dd.c b/drivers/base/dd.c index 3aead51173f8..66df31696349 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -132,7 +132,7 @@ static DECLARE_WORK(deferred_probe_work, deferred_probe= _work_func); =20 void driver_deferred_probe_add(struct device *dev) { - if (!dev->can_match) + if (!test_bit(DEV_FLAG_CAN_MATCH, &dev->flags)) return; =20 mutex_lock(&deferred_probe_mutex); @@ -860,7 +860,7 @@ static int __driver_probe_device(const struct device_dr= iver *drv, struct device if (!test_bit(DEV_FLAG_READY_TO_PROBE, &dev->flags)) return dev_err_probe(dev, -EPROBE_DEFER, "Device not ready to probe\n"); =20 - dev->can_match =3D true; + set_bit(DEV_FLAG_CAN_MATCH, &dev->flags); dev_dbg(dev, "bus: '%s': %s: matched device with driver %s\n", drv->bus->name, __func__, drv->name); =20 @@ -1006,7 +1006,7 @@ static int __device_attach_driver(struct device_drive= r *drv, void *_data) return 0; } else if (ret =3D=3D -EPROBE_DEFER) { dev_dbg(dev, "Device match requests probe deferral\n"); - dev->can_match =3D true; + set_bit(DEV_FLAG_CAN_MATCH, &dev->flags); driver_deferred_probe_add(dev); /* * Device can't match with a driver right now, so don't attempt @@ -1258,7 +1258,7 @@ static int __driver_attach(struct device *dev, void *= data) return 0; } else if (ret =3D=3D -EPROBE_DEFER) { dev_dbg(dev, "Device match requests probe deferral\n"); - dev->can_match =3D true; + set_bit(DEV_FLAG_CAN_MATCH, &dev->flags); driver_deferred_probe_add(dev); /* * Driver could not match with device, but may match with diff --git a/include/linux/device.h b/include/linux/device.h index 5b7ace5921aa..7e5737c6d7d1 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -465,9 +465,13 @@ struct device_physical_location { * * @DEV_FLAG_READY_TO_PROBE: If set then device_add() has finished enough * initialization that probe could be called. + * @DEV_FLAG_CAN_MATCH: The device has matched with a driver at least once= or it + * is in a bus (like AMBA) which can't check for matching drivers + * until other devices probe successfully. */ enum struct_device_flags { DEV_FLAG_READY_TO_PROBE, + DEV_FLAG_CAN_MATCH, }; =20 /** @@ -552,9 +556,6 @@ enum struct_device_flags { * @state_synced: The hardware state of this device has been synced to mat= ch * the software state of this device by calling the driver/bus * sync_state() callback. - * @can_match: The device has matched with a driver at least once or it is= in - * a bus (like AMBA) which can't check for matching drivers until - * other devices probe successfully. * @dma_coherent: this particular device is dma coherent, even if the * architecture supports non-coherent devices. * @dma_ops_bypass: If set to %true then the dma_ops are bypassed for the @@ -673,7 +674,6 @@ struct device { bool offline:1; bool of_node_reused:1; bool state_synced:1; - bool can_match:1; #if defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_DEVICE) || \ defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU) || \ defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU_ALL) --=20 2.53.0.1213.gd9a14994de-goog From nobody Sun Jun 14 12:44:33 2026 Received: from mail-dl1-f48.google.com (mail-dl1-f48.google.com [74.125.82.48]) (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 C0E8D2405EB for ; Fri, 3 Apr 2026 00:51:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775177507; cv=none; b=Fj7aqPqz9oTHiknP74D63DGm9Zqq0VatZveUCnxBHVDebqawe63w20g2Y4eSOufx4jc54mPJGPm4kwfdrPfeGn8vdmx17eK3m47CCTqH5klnnVV7dHDZMnaYPrM6/kNyAECI8CEp9msk7i854/G1Agv11I+WFn7OYa8+5N+F/XY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775177507; c=relaxed/simple; bh=/M0FfRzU7RVjhShiy7G7rTfAd90/jtHt9dofWLRy5KY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CFaNM09Ju41zaBaPgTXg7zi2k21FS1hFnvDxRkycc8NcFyQ+T4brRRauWlhTqWfgwk/Rh7/c07mv7mV/wCPANIyVk7lxhQYw5Oe2slaV2WWHVYKbhCVKIat1SnEO/hqN6Cx9tUs5HPiYUDaqdKHl30whuYEcPhC2RQ9YydWzTEQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=JuGSxSBS; arc=none smtp.client-ip=74.125.82.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="JuGSxSBS" Received: by mail-dl1-f48.google.com with SMTP id a92af1059eb24-12a74039dc6so1290300c88.0 for ; Thu, 02 Apr 2026 17:51:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1775177505; x=1775782305; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/7YjIBbL/N3pUe7DW8lfq5UV0N0T+SK6BvJG2WvPW8U=; b=JuGSxSBScOdAkiCNii9hAXQga9GRrDb7g56qDDKcTgvyIXlBs2JNdClnn8hWFkmcop VfWnW3MTQSnoYz7RtWh5o7XtvNL2BLeFy5bQJaQHOxkZ2FJ9WWP4D269ae15nx9mKqLu K0rEa3CBp3Sh1TQKFfLrOi17ecQFicNApD+Ak= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775177505; x=1775782305; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=/7YjIBbL/N3pUe7DW8lfq5UV0N0T+SK6BvJG2WvPW8U=; b=XW7G/jgTdCjclKEPb5jdYfu3O80Ov04eWOqcmKVlnZE8PHJAxikch/gIDlMJ6TrRrP eM3lj242iS0qCRdGLt5gNwF8QOjb85gRGVY43c3xNuY9Zdfgo0kfkSgtkszxbA/gjX0P 9csRg3H1GasjMt6tNnp2+GNJqmqi9j/xmFTIlQfdSx2dcmalHErSY3F5soLPS3ZT3s0P 94H2JVI5u6jwaioCRG3O/fDjigCWo/D3+6kSHJRfbVZELPjPejFiUmEj173Hd4dGKQ3S Sfigg581iTn8FD5uDhQ9PKxPfZSTxv5iQ3EouGGM9Z/QNeRFFTXBMLCrlsUub7J1n9mS 6d8Q== X-Forwarded-Encrypted: i=1; AJvYcCV7eNS25u7dbCBGS/5x3VE6Kel5NRWbNtLfSJdoIO5j/C7ffkJ77CZIuiIWtQ77ZM9m75/kmcsXhSGDtf8=@vger.kernel.org X-Gm-Message-State: AOJu0Yy3ddcSJ+KUqS5HKSR8Q1DYXsx9nAqaAEYrX5ioIs+IZWV3lIF3 MtikmccJDV7EjpAa/QDAWvz+D2b1gRsJs6Tf7ba0hZJdL2B79BO1COBbj0jsKp/Axg== X-Gm-Gg: ATEYQzw0tPckOrFUdKucKiihhRr75Tn0tE24Pu80wC8FLI6Sra/FIqRBghYnhSZGcif WnmQ1c2y/62SDVKrpu0iGhkinGMQVruc+/K1arArivRlF+gsYay02r93U8I80wZKyj0UNIT4hR2 qNs5R1zEiH0evLj1EDWoPUwinX/6CmEWIdnpXx/usLHwCFSQ3SdYGSt7dqx8lTD3WsItKyuXyUg /9d14UFnJgSqVkT3FCxj5GFf8tc5k8DovpeyYvriHlfb2pVL7V9Mk9cneDaDDWqSogXGZ/0HeYN 2lfwKLh4Mhl5lqJd0/mz0VP7LBH52i8S6nLacFZ+KE+1xNmDIVK0JdMTlA+r7l1p9CfYNAxRy/G HqpEiDt+Tt8zHZPsrujwN+qP+99Ryu+1ymSWwV7XpRxrLr43LcR2Zfp7swrW9HaZD5N5mKb68al VpmptBYawSXwRdZ8xT1Smk95L4OR6clqIZW1lyK3mzBb8NjqPXRPohzqj8fyrN3VPdm7VO8WVe2 CkAl3mY2cQ= X-Received: by 2002:a05:7022:6881:b0:12a:747e:5b5c with SMTP id a92af1059eb24-12bfb7459b2mr534683c88.24.1775177504969; Thu, 02 Apr 2026 17:51:44 -0700 (PDT) Received: from dianders.sjc.corp.google.com ([2a00:79e0:2e7c:8:5db3:7542:a530:f43a]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2ca78df3b84sm3630074eec.5.2026.04.02.17.51.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Apr 2026 17:51:42 -0700 (PDT) From: Douglas Anderson To: Greg Kroah-Hartman , "Rafael J . Wysocki" , Danilo Krummrich , Alan Stern Cc: Robin Murphy , Leon Romanovsky , Paul Burton , Saravana Kannan , Alexander Lobakin , Eric Dumazet , Toshi Kani , Christoph Hellwig , Alexey Kardashevskiy , Johan Hovold , Douglas Anderson , driver-core@lists.linux.dev, iommu@lists.linux.dev, joro@8bytes.org, linux-kernel@vger.kernel.org, will@kernel.org Subject: [PATCH v3 3/9] driver core: Replace dev->dma_iommu with DEV_FLAG_DMA_IOMMU Date: Thu, 2 Apr 2026 17:49:49 -0700 Message-ID: <20260402174925.v3.3.Id20d5973cbff542fea290e13177e9423f5d81342@changeid> X-Mailer: git-send-email 2.53.0.1213.gd9a14994de-goog In-Reply-To: <20260403005005.30424-1-dianders@chromium.org> References: <20260403005005.30424-1-dianders@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In C, bitfields are not necessarily safe to modify from multiple threads without locking. Switch "dma_iommu" over to the "flags" field so modifications are safe. Cc: Leon Romanovsky Cc: Robin Murphy Cc: Christoph Hellwig Signed-off-by: Douglas Anderson --- Not fixing any known bugs; problem is theoretical and found by code inspection. Change is done somewhat manually and only lightly tested (mostly compile-time tested). NOTE: even though previously we only took up a bit if CONFIG_IOMMU_DMA, in this change I reserve the bit unconditionally. While we could get the "dynamic" behavior by changing the flags definition to be an "enum", it doesn't seem worth it at this point. This also allows us to move one "#ifdef" to an "if", getting better compile-time testing of both sides of the "if". Changes in v3: - New drivers/iommu/dma-iommu.c | 9 ++++++--- drivers/iommu/iommu.c | 5 ++--- include/linux/device.h | 8 +++----- include/linux/iommu-dma.h | 4 +++- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 94d514169642..a3423ece9578 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -2112,18 +2112,21 @@ EXPORT_SYMBOL_GPL(dma_iova_destroy); =20 void iommu_setup_dma_ops(struct device *dev, struct iommu_domain *domain) { + bool dma_iommu; + if (dev_is_pci(dev)) dev->iommu->pci_32bit_workaround =3D !iommu_dma_forcedac; =20 - dev->dma_iommu =3D iommu_is_dma_domain(domain); - if (dev->dma_iommu && iommu_dma_init_domain(domain, dev)) + dma_iommu =3D iommu_is_dma_domain(domain); + assign_bit(DEV_FLAG_DMA_IOMMU, &dev->flags, dma_iommu); + if (dma_iommu && iommu_dma_init_domain(domain, dev)) goto out_err; =20 return; out_err: pr_warn("Failed to set up IOMMU for device %s; retaining platform DMA ops= \n", dev_name(dev)); - dev->dma_iommu =3D false; + clear_bit(DEV_FLAG_DMA_IOMMU, &dev->flags); } =20 static bool has_msi_cookie(const struct iommu_domain *domain) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 50718ab810a4..7722ac086981 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -589,9 +589,8 @@ static void iommu_deinit_device(struct device *dev) dev->iommu_group =3D NULL; module_put(ops->owner); dev_iommu_free(dev); -#ifdef CONFIG_IOMMU_DMA - dev->dma_iommu =3D false; -#endif + if (IS_ENABLED(CONFIG_IOMMU_DMA)) + clear_bit(DEV_FLAG_DMA_IOMMU, &dev->flags); } =20 static struct iommu_domain *pasid_array_entry_to_domain(void *entry) diff --git a/include/linux/device.h b/include/linux/device.h index 7e5737c6d7d1..e74c7d0813ce 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -468,10 +468,13 @@ struct device_physical_location { * @DEV_FLAG_CAN_MATCH: The device has matched with a driver at least once= or it * is in a bus (like AMBA) which can't check for matching drivers * until other devices probe successfully. + * @DEV_FLAG_DMA_IOMMU: Device is using default IOMMU implementation for D= MA and + * doesn't rely on dma_ops structure. */ enum struct_device_flags { DEV_FLAG_READY_TO_PROBE, DEV_FLAG_CAN_MATCH, + DEV_FLAG_DMA_IOMMU, }; =20 /** @@ -564,8 +567,6 @@ enum struct_device_flags { * for dma allocations. This flag is managed by the dma ops * instance from ->dma_supported. * @dma_skip_sync: DMA sync operations can be skipped for coherent buffers. - * @dma_iommu: Device is using default IOMMU implementation for DMA and - * doesn't rely on dma_ops structure. * @flags: DEV_FLAG_XXX flags. Use atomic bitfield operations to modify. * * At the lowest level, every device in a Linux system is represented by an @@ -685,9 +686,6 @@ struct device { #ifdef CONFIG_DMA_NEED_SYNC bool dma_skip_sync:1; #endif -#ifdef CONFIG_IOMMU_DMA - bool dma_iommu:1; -#endif =20 unsigned long flags; }; diff --git a/include/linux/iommu-dma.h b/include/linux/iommu-dma.h index a92b3ff9b934..b6177672539d 100644 --- a/include/linux/iommu-dma.h +++ b/include/linux/iommu-dma.h @@ -7,12 +7,14 @@ #ifndef _LINUX_IOMMU_DMA_H #define _LINUX_IOMMU_DMA_H =20 +#include #include +#include =20 #ifdef CONFIG_IOMMU_DMA static inline bool use_dma_iommu(struct device *dev) { - return dev->dma_iommu; + return test_bit(DEV_FLAG_DMA_IOMMU, &dev->flags); } #else static inline bool use_dma_iommu(struct device *dev) --=20 2.53.0.1213.gd9a14994de-goog From nobody Sun Jun 14 12:44:33 2026 Received: from mail-dl1-f53.google.com (mail-dl1-f53.google.com [74.125.82.53]) (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 6CB52258ED5 for ; Fri, 3 Apr 2026 00:51:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775177510; cv=none; b=V+bymh8QJnxY1QVGgXrtooGbpoBZ4QJtsw1vqWyBkjXxIJcj9h0A5pS3d0KJdOv4HZ7S8Sili3ZvkkI25cGtD/ThGZyPNwiHDCpOhtbG9p17taTowjuGGaUNU/Du2Dd4PzT8EFvMEQwFhoX87Uvb9udNEh7zhsOL9/PjQO05Zc0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775177510; c=relaxed/simple; bh=MbYSEBw2mR7uS899ItjNFULIEA7303rlJjU6gRTcFao=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZRJnOVeDWbT5Pz96e+gho+Ggd+bkfVu3XIckkkD3VdDJb/AJtkDA3hTZZtmw5xrdvQ9DrfGwqap+Rxig8r5Fj1xBNRONDdVJuExwt7fjjMOP8+UeKSFaKJd14WnocMxQrwFT7iYa+HxpniAeOcw3+JObF6Mk5ItVI4zNdpxSdcI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=KLL4miLP; arc=none smtp.client-ip=74.125.82.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="KLL4miLP" Received: by mail-dl1-f53.google.com with SMTP id a92af1059eb24-12bfa7fe691so688868c88.0 for ; Thu, 02 Apr 2026 17:51:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1775177507; x=1775782307; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HM9+eAkKdOrABgkFmwCHnBiWfkCG9uPNCsfKJXOxWMI=; b=KLL4miLPOWT8z8EfixQQtsUSKBmXgUSjmMVfxmknvE+lB065W6y744qGI6H6mGqvt0 TGFSOMiHa6IMAbLvojSsGemEfc0IS8EQVQ+DhVO9h+KNaBafO/7BgflTy2rwU4Ac6Y8J t9u4t7qyX4aenmB6gNkyyuPQA9NjcufvfLMeg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775177507; x=1775782307; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=HM9+eAkKdOrABgkFmwCHnBiWfkCG9uPNCsfKJXOxWMI=; b=qbPLIyHi7s76zb2bGsTK8eGc6VnpX2SNYIoAHpJ0pSg2diwUdcx+OfzIKyA5pblGDY m5vUGw05VMVFZBoaLkhHy+u+In1ImML9HWjyhEgZAS5Tfdj2GKuqzHJ3JFHkheZCkjzK jraW5wIZ2aHZlbM2eWQtpzRLolS5JfAHkOjarLGK8R3hfGBgtDc9mcOTHSHpH9qWIYV1 GEKTtHA1N8RhWwhNMF5AoYtA2ZmN+sOXw9Cb/hC5f1KWJ5+gYkpdTf1Vc6sTjp4lHW+a wCpHReDzXTgVMrP/b+oQGLlxFkmhWOrQncBfKQlpbxwbY2tLqBsS/li2eiy6sIvBgjtK KsGQ== X-Forwarded-Encrypted: i=1; AJvYcCUlT6mpFK9p/KGFELqkCU/c9MeW1lVGMhNmgDxnWcdpqe++2Fdsy0uWEhZpfl72xhiRnfvXeaMZSer+IP0=@vger.kernel.org X-Gm-Message-State: AOJu0YxsFm6gbubq7IiqesAm4brgKsPvD5bJmaesMxU/23XMzUXl/XYL mXEEdugfktzLWzzMNISPSV3HCUasxwHwuQ/rNkLnUW85bosWXgTOLzC4i9SFy9kLhQ== X-Gm-Gg: AeBDieuoJaxrmMD3f+7EAMmd1aP7Tpoo5nzhVkSj0AfUAGCcz1JZ1tlskocDAE0CrVF kI87Tlb7Fa53xOJYsBsCDe3tVmY9iboHvDkgGGfZJRreBd0V1niWo5VQcrkkm4iSnOmpLnHekDM +kMfrdc5O8Jmx5A0PytsQpC1lRVA9Vw8ZaZ6vK0ipcP1m10/PP/WbSuoqn3aoFoZ/9ivQ5y7VZ4 C/rSi2jqTdN8g35+52Eodag8Ee5e/pk8w+is6gsfC3sUxiRAuOdAdGl13zkPqNF3aFfO1tQFlTJ Gz1P7l7bWWRNccRZMltNFGaFhnEAMxWa7GzVY7o0C+2ncFzToKeT2KZWselDaJgJV7XlOZ/Sia3 ieHskCBTBOujFLOAXSvxy8qMaSGc1QyYLlU5dxGaWeClyoD9GZaKyKZwcTp3S7sjmWF6Exjys6U 5iyC2naUD8cHrVG236GKOLbRLzlbYNTJ77WBQp8fLkRVF1k7CWs8gTIjf4Ww1ohnKwojgisbzph 65hL6cWPF0= X-Received: by 2002:a05:7300:a506:b0:2c5:50fe:c786 with SMTP id 5a478bee46e88-2cbfa2ce19dmr720875eec.9.1775177507537; Thu, 02 Apr 2026 17:51:47 -0700 (PDT) Received: from dianders.sjc.corp.google.com ([2a00:79e0:2e7c:8:5db3:7542:a530:f43a]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2ca78df3b84sm3630074eec.5.2026.04.02.17.51.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Apr 2026 17:51:46 -0700 (PDT) From: Douglas Anderson To: Greg Kroah-Hartman , "Rafael J . Wysocki" , Danilo Krummrich , Alan Stern Cc: Robin Murphy , Leon Romanovsky , Paul Burton , Saravana Kannan , Alexander Lobakin , Eric Dumazet , Toshi Kani , Christoph Hellwig , Alexey Kardashevskiy , Johan Hovold , Douglas Anderson , Andrew Morton , Jason Gunthorpe , driver-core@lists.linux.dev, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org, m.szyprowski@samsung.com Subject: [PATCH v3 4/9] driver core: Replace dev->dma_skip_sync with DEV_FLAG_DMA_SKIP_SYNC Date: Thu, 2 Apr 2026 17:49:50 -0700 Message-ID: <20260402174925.v3.4.Icf072aa4184dd86a88fa8ca195b09d1651984000@changeid> X-Mailer: git-send-email 2.53.0.1213.gd9a14994de-goog In-Reply-To: <20260403005005.30424-1-dianders@chromium.org> References: <20260403005005.30424-1-dianders@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In C, bitfields are not necessarily safe to modify from multiple threads without locking. Switch "dma_skip_sync" over to the "flags" field so modifications are safe. Cc: Alexander Lobakin Cc: Eric Dumazet Cc: Christoph Hellwig Signed-off-by: Douglas Anderson --- Not fixing any known bugs; problem is theoretical and found by code inspection. Change is done somewhat manually and only lightly tested (mostly compile-time tested). NOTE: even though previously we only took up a bit if CONFIG_DMA_NEED_SYNC, in this change I reserve the bit unconditionally. While we could get the "dynamic" behavior by changing the flags definition to be an "enum", it doesn't seem worth it at this point. Changes in v3: - New include/linux/device.h | 7 +++---- include/linux/dma-map-ops.h | 4 ++-- include/linux/dma-mapping.h | 2 +- kernel/dma/mapping.c | 8 ++++---- mm/hmm.c | 2 +- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/include/linux/device.h b/include/linux/device.h index e74c7d0813ce..e900748d3038 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -470,11 +470,14 @@ struct device_physical_location { * until other devices probe successfully. * @DEV_FLAG_DMA_IOMMU: Device is using default IOMMU implementation for D= MA and * doesn't rely on dma_ops structure. + * @DEV_FLAG_DMA_SKIP_SYNC: DMA sync operations can be skipped for coherent + * buffers. */ enum struct_device_flags { DEV_FLAG_READY_TO_PROBE, DEV_FLAG_CAN_MATCH, DEV_FLAG_DMA_IOMMU, + DEV_FLAG_DMA_SKIP_SYNC, }; =20 /** @@ -566,7 +569,6 @@ enum struct_device_flags { * and optionall (if the coherent mask is large enough) also * for dma allocations. This flag is managed by the dma ops * instance from ->dma_supported. - * @dma_skip_sync: DMA sync operations can be skipped for coherent buffers. * @flags: DEV_FLAG_XXX flags. Use atomic bitfield operations to modify. * * At the lowest level, every device in a Linux system is represented by an @@ -683,9 +685,6 @@ struct device { #ifdef CONFIG_DMA_OPS_BYPASS bool dma_ops_bypass : 1; #endif -#ifdef CONFIG_DMA_NEED_SYNC - bool dma_skip_sync:1; -#endif =20 unsigned long flags; }; diff --git a/include/linux/dma-map-ops.h b/include/linux/dma-map-ops.h index 60b63756df82..4d9d1fe3277c 100644 --- a/include/linux/dma-map-ops.h +++ b/include/linux/dma-map-ops.h @@ -245,8 +245,8 @@ static inline void dma_reset_need_sync(struct device *d= ev) { #ifdef CONFIG_DMA_NEED_SYNC /* Reset it only once so that the function can be called on hotpath */ - if (unlikely(dev->dma_skip_sync)) - dev->dma_skip_sync =3D false; + if (unlikely(test_bit(DEV_FLAG_DMA_SKIP_SYNC, &dev->flags))) + clear_bit(DEV_FLAG_DMA_SKIP_SYNC, &dev->flags); #endif } =20 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h index 99ef042ecdb4..23273b0fe84e 100644 --- a/include/linux/dma-mapping.h +++ b/include/linux/dma-mapping.h @@ -419,7 +419,7 @@ bool __dma_need_sync(struct device *dev, dma_addr_t dma= _addr); static inline bool dma_dev_need_sync(const struct device *dev) { /* Always call DMA sync operations when debugging is enabled */ - return !dev->dma_skip_sync || IS_ENABLED(CONFIG_DMA_API_DEBUG); + return !test_bit(DEV_FLAG_DMA_SKIP_SYNC, &dev->flags) || IS_ENABLED(CONFI= G_DMA_API_DEBUG); } =20 static inline void dma_sync_single_for_cpu(struct device *dev, dma_addr_t = addr, diff --git a/kernel/dma/mapping.c b/kernel/dma/mapping.c index 6d3dd0bd3a88..f50b648ed460 100644 --- a/kernel/dma/mapping.c +++ b/kernel/dma/mapping.c @@ -467,7 +467,7 @@ bool dma_need_unmap(struct device *dev) { if (!dma_map_direct(dev, get_dma_ops(dev))) return true; - if (!dev->dma_skip_sync) + if (!test_bit(DEV_FLAG_DMA_SKIP_SYNC, &dev->flags)) return true; return IS_ENABLED(CONFIG_DMA_API_DEBUG); } @@ -483,16 +483,16 @@ static void dma_setup_need_sync(struct device *dev) * mapping, if any. During the device initialization, it's * enough to check only for the DMA coherence. */ - dev->dma_skip_sync =3D dev_is_dma_coherent(dev); + assign_bit(DEV_FLAG_DMA_SKIP_SYNC, &dev->flags, dev_is_dma_coherent(dev)= ); else if (!ops->sync_single_for_device && !ops->sync_single_for_cpu && !ops->sync_sg_for_device && !ops->sync_sg_for_cpu) /* * Synchronization is not possible when none of DMA sync ops * is set. */ - dev->dma_skip_sync =3D true; + set_bit(DEV_FLAG_DMA_SKIP_SYNC, &dev->flags); else - dev->dma_skip_sync =3D false; + clear_bit(DEV_FLAG_DMA_SKIP_SYNC, &dev->flags); } #else /* !CONFIG_DMA_NEED_SYNC */ static inline void dma_setup_need_sync(struct device *dev) { } diff --git a/mm/hmm.c b/mm/hmm.c index 5955f2f0c83d..137450e096bc 100644 --- a/mm/hmm.c +++ b/mm/hmm.c @@ -709,7 +709,7 @@ int hmm_dma_map_alloc(struct device *dev, struct hmm_dm= a_map *map, * best approximation to ensure no swiotlb buffering happens. */ #ifdef CONFIG_DMA_NEED_SYNC - dma_need_sync =3D !dev->dma_skip_sync; + dma_need_sync =3D !test_bit(DEV_FLAG_DMA_SKIP_SYNC, &dev->flags); #endif /* CONFIG_DMA_NEED_SYNC */ if (dma_need_sync || dma_addressing_limited(dev)) return -EOPNOTSUPP; --=20 2.53.0.1213.gd9a14994de-goog From nobody Sun Jun 14 12:44:33 2026 Received: from mail-dy1-f177.google.com (mail-dy1-f177.google.com [74.125.82.177]) (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 C4BA226059D for ; Fri, 3 Apr 2026 00:51:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775177514; cv=none; b=EPIn7qqSyiBUbeNVc6TfwaJQ0r34EGOQ+s5oGIj7FWsOx6h1R6iryPwffj4RHtfkaiw22Nx3UiSAmTSBOeN8+CQcLWvy/E4/oNuGGTvyv92tvfXIvwvZHtN/f/vA/TmCVp+MgLnnDMeJYLeLCW9UUtSpQD1npcc/XV3D/u1Ioqk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775177514; c=relaxed/simple; bh=ORnE0BsVMRNzS+pVx3neQe1CQGlfWvsbwoU0QJEuCPo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bMkbWJrKVCBUC06ytflLPGWBM7YZ+Y7JLqRAShHu8Do9JvM3zPejL44vMvJrtq22antrGCfnSeKZaf2ZbdyNvAuhuK+cCM1+i4aCnkngZcLNYaixlOsmLu+ryfmvPEDifn/EtFCwOLJ0WdjKhiZ2+C3N28Ru+80HnXsRtxY1dZ8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=NG7Hgqkw; arc=none smtp.client-ip=74.125.82.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="NG7Hgqkw" Received: by mail-dy1-f177.google.com with SMTP id 5a478bee46e88-2c1632faeb9so2914276eec.0 for ; Thu, 02 Apr 2026 17:51:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1775177511; x=1775782311; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lZiTiKY0xg6ysj9D1M7VJbCxfmHcK2OdGCIMJgNJnE8=; b=NG7HgqkwZDMXVJqonhHtH+ejnO9rivCPwHfHyEXHkzaNEn8sqr9ud+1n51p5YOt0k5 3/2IpnZ6uUSiujtT+/51qBr2XGWn8NrNj5L029AYvE95pQWK6d8bUBFUEs+JZpDeuTm9 MRZJYdQTkJFW3yObQM9vTHpBfjXBhVM9aH/Rk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775177511; x=1775782311; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=lZiTiKY0xg6ysj9D1M7VJbCxfmHcK2OdGCIMJgNJnE8=; b=jMYxBb5efT6hJKKshYH3NDRwaHT56jYuc0fq3g2PsVOHlTfQ3v2mR5Dfmsyos9eJWG kBtLi849ta3gAyLHcOY2RN78FBDVabijglqs/bE9thBTwhmgPiuCv2cn2mNWpuwYeawL zuNqSeSDmSQqjMhd7+VwMfUUI744J0xMLAKfbJwLwUaxYtVjCZ4JBenC1sEFvMvJ129q Wakvq+wRnvmaW2NNc9H7/iuyEISQEvNtt4lTbuKgUx861Lk5GRQwhmuW3HQGBh+xNGtE oFVljjH0H3k1kdmE8SXLEyZLPba1SueiuaYWTdEMeHOn9xmS9M0/wBXkDEu+XFff9Nlz I+Fg== X-Forwarded-Encrypted: i=1; AJvYcCWl53NDSOMNY4UCH0X4n0jaxWhn3ZDa4nhck6XqdBRvxXuGfs4Jzzq5e/Vk1+PNghlfaQb+69CvPrN7ECc=@vger.kernel.org X-Gm-Message-State: AOJu0YxwQ42+FJOh0F3uvCNNsaRj8/ICK/sVHsLhpcUZti4P8CQ6kp3S grYAaGJOqIsGgrlPahYfko9/GgTu556l4SywOQ2mD6SNvq2RT9cHmPPq5oTR9GlOlw== X-Gm-Gg: AeBDievYwbJKJDlleAi/Md42yPskr4/cxeq/r22niSUPrJ0y4230+MmRo52GRltpmib BOJfEGx4IZk3HGWbWs7hDYemk5S+kdKwiEiv46ArIVhlyl3slGos82rKhNeDsO5VCbG72q7n6bL bhRq9tidCWe6pa6XX3ArMeMB+L2F9Tb9GZt3oXQa3rTIq0VEYU2ZIWsvtT1n1PA+Q76BFwSBhZ3 6sobOSIt2+pRHFBuEdByZpxgVkLAtZwAGhXBqGT9dnB5egzzr0W6bBzLTVWz6xhPPy2nplhQnAR Qq1wzZVMSCcHfebjtFIjsWSB3y3XWnJLun4H4qIvpvndxZECGjLU/u83KuE74jDKkaeIldNBISg st1ZlyDGg9JTvYUdhoZ56hTom5U5mOrPahAqqdt/GIVyO2zpHZmQDb0W0lOS3H2ezEi5g/GBRhQ VwxmkM5OC8TwFwuPKGq+0f4xnTuqiVpvnDs4sRFoqaeoI11rvD8cGZ8ph9IdsAzUgS93ma24QeH zpC5CYp9os= X-Received: by 2002:a05:7300:371f:b0:2c5:b23e:48a6 with SMTP id 5a478bee46e88-2cbfc268d12mr658562eec.23.1775177510944; Thu, 02 Apr 2026 17:51:50 -0700 (PDT) Received: from dianders.sjc.corp.google.com ([2a00:79e0:2e7c:8:5db3:7542:a530:f43a]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2ca78df3b84sm3630074eec.5.2026.04.02.17.51.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Apr 2026 17:51:49 -0700 (PDT) From: Douglas Anderson To: Greg Kroah-Hartman , "Rafael J . Wysocki" , Danilo Krummrich , Alan Stern Cc: Robin Murphy , Leon Romanovsky , Paul Burton , Saravana Kannan , Alexander Lobakin , Eric Dumazet , Toshi Kani , Christoph Hellwig , Alexey Kardashevskiy , Johan Hovold , Douglas Anderson , chleroy@kernel.org, driver-core@lists.linux.dev, gbatra@linux.ibm.com, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, m.szyprowski@samsung.com, maddy@linux.ibm.com, mpe@ellerman.id.au, npiggin@gmail.com Subject: [PATCH v3 5/9] driver core: Replace dev->dma_ops_bypass with DEV_FLAG_DMA_OPS_BYPASS Date: Thu, 2 Apr 2026 17:49:51 -0700 Message-ID: <20260402174925.v3.5.If62b84471ef2c85e7ad250f0468867d6dba965ab@changeid> X-Mailer: git-send-email 2.53.0.1213.gd9a14994de-goog In-Reply-To: <20260403005005.30424-1-dianders@chromium.org> References: <20260403005005.30424-1-dianders@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In C, bitfields are not necessarily safe to modify from multiple threads without locking. Switch "dma_ops_bypass" over to the "flags" field so modifications are safe. Cc: Christoph Hellwig Cc: Alexey Kardashevskiy Signed-off-by: Douglas Anderson --- Not fixing any known bugs; problem is theoretical and found by code inspection. Change is done somewhat manually and only lightly tested (mostly compile-time tested). NOTE: even though previously we only took up a bit if CONFIG_DMA_OPS_BYPASS, in this change I reserve the bit unconditionally. While we could get the "dynamic" behavior by changing the flags definition to be an "enum", it doesn't seem worth it at this point. This also allows us to move one "#ifdef" to an "if", getting better compile-time testing of both sides of the "if". Changes in v3: - New arch/powerpc/kernel/dma-iommu.c | 8 ++++---- include/linux/device.h | 14 ++++++-------- kernel/dma/mapping.c | 8 +++----- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/arch/powerpc/kernel/dma-iommu.c b/arch/powerpc/kernel/dma-iomm= u.c index 73e10bd4d56d..6486417c8acb 100644 --- a/arch/powerpc/kernel/dma-iommu.c +++ b/arch/powerpc/kernel/dma-iommu.c @@ -67,7 +67,7 @@ bool arch_dma_unmap_sg_direct(struct device *dev, struct = scatterlist *sg, } bool arch_dma_alloc_direct(struct device *dev) { - if (dev->dma_ops_bypass) + if (test_bit(DEV_FLAG_DMA_OPS_BYPASS, &dev->flags)) return true; =20 return false; @@ -75,7 +75,7 @@ bool arch_dma_alloc_direct(struct device *dev) =20 bool arch_dma_free_direct(struct device *dev, dma_addr_t dma_handle) { - if (!dev->dma_ops_bypass) + if (!test_bit(DEV_FLAG_DMA_OPS_BYPASS, &dev->flags)) return false; =20 return is_direct_handle(dev, dma_handle); @@ -164,7 +164,7 @@ int dma_iommu_dma_supported(struct device *dev, u64 mas= k) * fixed ops will be used for RAM. This is limited by * bus_dma_limit which is set when RAM is pre-mapped. */ - dev->dma_ops_bypass =3D true; + set_bit(DEV_FLAG_DMA_OPS_BYPASS, &dev->flags); dev_info(dev, "iommu: 64-bit OK but direct DMA is limited by %llx\n", dev->bus_dma_limit); return 1; @@ -185,7 +185,7 @@ int dma_iommu_dma_supported(struct device *dev, u64 mas= k) } =20 dev_dbg(dev, "iommu: not 64-bit, using default ops\n"); - dev->dma_ops_bypass =3D false; + clear_bit(DEV_FLAG_DMA_OPS_BYPASS, &dev->flags); return 1; } =20 diff --git a/include/linux/device.h b/include/linux/device.h index e900748d3038..f5845bd7c3e6 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -472,12 +472,18 @@ struct device_physical_location { * doesn't rely on dma_ops structure. * @DEV_FLAG_DMA_SKIP_SYNC: DMA sync operations can be skipped for coherent * buffers. + * @DEV_FLAG_DMA_OPS_BYPASS: If set then the dma_ops are bypassed for the + * streaming DMA operations (->map_* / ->unmap_* / ->sync_*), and + * optional (if the coherent mask is large enough) also for dma + * allocations. This flag is managed by the dma ops instance from + * ->dma_supported. */ enum struct_device_flags { DEV_FLAG_READY_TO_PROBE, DEV_FLAG_CAN_MATCH, DEV_FLAG_DMA_IOMMU, DEV_FLAG_DMA_SKIP_SYNC, + DEV_FLAG_DMA_OPS_BYPASS, }; =20 /** @@ -564,11 +570,6 @@ enum struct_device_flags { * sync_state() callback. * @dma_coherent: this particular device is dma coherent, even if the * architecture supports non-coherent devices. - * @dma_ops_bypass: If set to %true then the dma_ops are bypassed for the - * streaming DMA operations (->map_* / ->unmap_* / ->sync_*), - * and optionall (if the coherent mask is large enough) also - * for dma allocations. This flag is managed by the dma ops - * instance from ->dma_supported. * @flags: DEV_FLAG_XXX flags. Use atomic bitfield operations to modify. * * At the lowest level, every device in a Linux system is represented by an @@ -682,9 +683,6 @@ struct device { defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU_ALL) bool dma_coherent:1; #endif -#ifdef CONFIG_DMA_OPS_BYPASS - bool dma_ops_bypass : 1; -#endif =20 unsigned long flags; }; diff --git a/kernel/dma/mapping.c b/kernel/dma/mapping.c index f50b648ed460..44d4c319ffad 100644 --- a/kernel/dma/mapping.c +++ b/kernel/dma/mapping.c @@ -126,11 +126,9 @@ static bool dma_go_direct(struct device *dev, dma_addr= _t mask, if (likely(!ops)) return true; =20 -#ifdef CONFIG_DMA_OPS_BYPASS - if (dev->dma_ops_bypass) + if (IS_ENABLED(CONFIG_DMA_OPS_BYPASS) && test_bit(DEV_FLAG_DMA_OPS_BYPASS= , &dev->flags)) return min_not_zero(mask, dev->bus_dma_limit) >=3D dma_direct_get_required_mask(dev); -#endif return false; } =20 @@ -895,8 +893,8 @@ bool dma_pci_p2pdma_supported(struct device *dev) const struct dma_map_ops *ops =3D get_dma_ops(dev); =20 /* - * Note: dma_ops_bypass is not checked here because P2PDMA should - * not be used with dma mapping ops that do not have support even + * Note: DEV_FLAG_DMA_OPS_BYPASS is not checked here because P2PDMA + * should not be used with dma mapping ops that do not have support even * if the specific device is bypassing them. */ =20 --=20 2.53.0.1213.gd9a14994de-goog From nobody Sun Jun 14 12:44:33 2026 Received: from mail-dy1-f178.google.com (mail-dy1-f178.google.com [74.125.82.178]) (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 5A1EA24A076 for ; Fri, 3 Apr 2026 00:51:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775177517; cv=none; b=G8nZqXRaSQHqvn1rmo6SHQ2pg8aHCuk3uGHCPqvcDYnXoAnfGyV30Rg4d0SExQ8sBZeWqBUyIu897mzzPJK2yOtcsU1xLdU3BCqaGtw7JFpXY+ykMpS5LCej5JMTgU854m1Ezx+6Yva3MsT/kA2+xHuR9TDfcuMfQp5F/syyI1Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775177517; c=relaxed/simple; bh=5N3do3f1bda60XdV+FFEIMw3KG/6XRb7QL0OIJu2YW4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FI1swjWpushOezAxzG71I6Kc2CViTDBBW/G6i4NdQHgEhtbHg1hXgX//N+SPkR5H6LCCObUA7xf30tSEUKsa+RrU19BzCRLGx1cAnn2uYzjrSYTS44MCNQCeoAd/uUEMZSCh+EtvaFadHIO1xwfH6oeoi7AI/SjvPzKA5TrcTeY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=MJOWREH5; arc=none smtp.client-ip=74.125.82.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="MJOWREH5" Received: by mail-dy1-f178.google.com with SMTP id 5a478bee46e88-2bd9a485bd6so3281064eec.1 for ; Thu, 02 Apr 2026 17:51:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1775177514; x=1775782314; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kgGJ3qVhvTnihbeXgwabOY+LFFKSLUKoX7zSIc0h7aU=; b=MJOWREH5oyC45qfgHrVAB9ODdmPvqDuTB5vJ63LL8HStgOgSB5xqw5VGVxSrGOg8Fz zbNw2lBxB/bSG3GznWoNHaW/NU6B0bvv0Mn9oOXR2TNlC2f7aYGTofnqUchhDq2DrfxQ cilrpZOno5Yj81e93EK/IuQnJgw3qoC+TML70= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775177514; x=1775782314; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=kgGJ3qVhvTnihbeXgwabOY+LFFKSLUKoX7zSIc0h7aU=; b=fcuolo7Xl43IJixlfBAk1jpSD9SYZuwXc7gnC/j01v0OutrUt9aSqUxILPqU5WJ3bd STakdsDTMRX/Krm/4nCZWClL5mKtsKdGfZMGXfJZLgFJQnH+mW4Mp4YSoxEacO+Ta8CB 00vB5wwDaHjH+gc0wGKzVDUSijaIY7peU6muHDtYVbCzhFD/vn9UM36FNvPJ0kyADJU2 NN24bGDYrlEicxr9JZ3DH52JcHy4DSxMLVSlfWj/zdcg+ni9eo8yWwaKbcBrpmYB5Gax GOuAFx/40WGGnQugnP4n8Mblm/9BwBrxYudSMfBM3CGNU9y4ASlTb/4CILaVIvbJgOK/ c4Ww== X-Forwarded-Encrypted: i=1; AJvYcCUfrP2lyyRGiYjM1p/Dea8Y4Bls7CNDqAffC7tA0SS4b0vZ+J9PZiWVI2sOQCk0h7pbYp5FA2L648GIhqM=@vger.kernel.org X-Gm-Message-State: AOJu0Yzu/aADIuAxnmYPix67WNxOSzMugOHhz/UGgJ0SS72JmRQL71c0 3hR2LdEXi6NhaBYrip3Rj0MAv6Apg+eR6tWuGBZNuwuzjra8hEtfGZMcf18IBeydrw== X-Gm-Gg: AeBDiesPmgtMJA8dqHoe/JirZO7COSE3bMKiqX4LlIyyeqBMDvbcGfGldQfGL/DAEWy uhUki8oZfXg+TpW72PE7T+0q9P5RF9irVUPhaulGnqY2yML5hWWiBreVP4Lc0CTNlY0Mi5IqZaM gwtIk2N+OCg6kP4mMbeA4bqRQqJxzBzZ/pnr9K9XBxuKXlSNLagrkXxyoSdwjJuKeh/PcQN2uey AX1YBGGfREDlkLwPoiFx9BQeXn4Mvpr7VgnyW4wR2ydYTJw0o0r7EHT4fhlDTrbojBJg6nYia+K /AdOPML3YMbfH2/BTaLiaZhBNz9lNQgcldbmbuzC02C35AWjrecrfpPexZ+JENYi3O5se4VBBXB 5FOcJTtUYMOVekp/KrSQQIj8vGOjAHzXTnPNJqPRs0wjteWtNKRlqknmilyPyP+4pJwJ1J/qiDh vkZqUs8CQ45eY4Rpvbh01r7CLpw6/RrG8GJwHCfzTUPdp1TIn1OeL/gOTRBP2pRJL8nKE4oGDa3 Nq8YXlMuuQ= X-Received: by 2002:a05:7301:1003:b0:2c5:ed1b:c8a with SMTP id 5a478bee46e88-2cbf9afd5e5mr636627eec.5.1775177514535; Thu, 02 Apr 2026 17:51:54 -0700 (PDT) Received: from dianders.sjc.corp.google.com ([2a00:79e0:2e7c:8:5db3:7542:a530:f43a]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2ca78df3b84sm3630074eec.5.2026.04.02.17.51.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Apr 2026 17:51:52 -0700 (PDT) From: Douglas Anderson To: Greg Kroah-Hartman , "Rafael J . Wysocki" , Danilo Krummrich , Alan Stern Cc: Robin Murphy , Leon Romanovsky , Paul Burton , Saravana Kannan , Alexander Lobakin , Eric Dumazet , Toshi Kani , Christoph Hellwig , Alexey Kardashevskiy , Johan Hovold , Douglas Anderson , Saravana Kannan , driver-core@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v3 6/9] driver core: Replace dev->state_synced with DEV_FLAG_STATE_SYNCED Date: Thu, 2 Apr 2026 17:49:52 -0700 Message-ID: <20260402174925.v3.6.Idb4818e1159fef104c7756bfd6e7ba8f374bebcd@changeid> X-Mailer: git-send-email 2.53.0.1213.gd9a14994de-goog In-Reply-To: <20260403005005.30424-1-dianders@chromium.org> References: <20260403005005.30424-1-dianders@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In C, bitfields are not necessarily safe to modify from multiple threads without locking. Switch "state_synced" over to the "flags" field so modifications are safe. Cc: Saravana Kannan Signed-off-by: Douglas Anderson --- Not fixing any known bugs; problem is theoretical and found by code inspection. Change is done somewhat manually and only lightly tested (mostly compile-time tested). Changes in v3: - New drivers/base/core.c | 9 +++++---- drivers/base/dd.c | 8 +++----- include/linux/device.h | 8 ++++---- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/drivers/base/core.c b/drivers/base/core.c index cbdfee887833..8dbb7a9c7aab 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -1123,7 +1123,7 @@ static void __device_links_queue_sync_state(struct de= vice *dev, =20 if (!dev_has_sync_state(dev)) return; - if (dev->state_synced) + if (test_bit(DEV_FLAG_STATE_SYNCED, &dev->flags)) return; =20 list_for_each_entry(link, &dev->links.consumers, s_node) { @@ -1138,7 +1138,7 @@ static void __device_links_queue_sync_state(struct de= vice *dev, * than once. This can happen if new consumers get added to the device * and probed before the list is flushed. */ - dev->state_synced =3D true; + set_bit(DEV_FLAG_STATE_SYNCED, &dev->flags); =20 if (WARN_ON(!list_empty(&dev->links.defer_sync))) return; @@ -1779,7 +1779,8 @@ static int fw_devlink_dev_sync_state(struct device *d= ev, void *data) struct device *sup =3D link->supplier; =20 if (!device_link_test(link, DL_FLAG_MANAGED) || - link->status =3D=3D DL_STATE_ACTIVE || sup->state_synced || + link->status =3D=3D DL_STATE_ACTIVE || + test_bit(DEV_FLAG_STATE_SYNCED, &sup->flags) || !dev_has_sync_state(sup)) return 0; =20 @@ -1793,7 +1794,7 @@ static int fw_devlink_dev_sync_state(struct device *d= ev, void *data) return 0; =20 dev_warn(sup, "Timed out. Forcing sync_state()\n"); - sup->state_synced =3D true; + set_bit(DEV_FLAG_STATE_SYNCED, &sup->flags); get_device(sup); list_add_tail(&sup->links.defer_sync, data); =20 diff --git a/drivers/base/dd.c b/drivers/base/dd.c index 66df31696349..f5d004f919ae 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -581,12 +581,10 @@ static ssize_t state_synced_store(struct device *dev, return -EINVAL; =20 device_lock(dev); - if (!dev->state_synced) { - dev->state_synced =3D true; + if (!test_and_set_bit(DEV_FLAG_STATE_SYNCED, &dev->flags)) dev_sync_state(dev); - } else { + else ret =3D -EINVAL; - } device_unlock(dev); =20 return ret ? ret : count; @@ -598,7 +596,7 @@ static ssize_t state_synced_show(struct device *dev, bool val; =20 device_lock(dev); - val =3D dev->state_synced; + val =3D test_bit(DEV_FLAG_STATE_SYNCED, &dev->flags); device_unlock(dev); =20 return sysfs_emit(buf, "%u\n", val); diff --git a/include/linux/device.h b/include/linux/device.h index f5845bd7c3e6..6c961dac9fdb 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -477,6 +477,9 @@ struct device_physical_location { * optional (if the coherent mask is large enough) also for dma * allocations. This flag is managed by the dma ops instance from * ->dma_supported. + * @DEV_FLAG_STATE_SYNCED: The hardware state of this device has been sync= ed to + * match the software state of this device by calling the + * driver/bus sync_state() callback. */ enum struct_device_flags { DEV_FLAG_READY_TO_PROBE, @@ -484,6 +487,7 @@ enum struct_device_flags { DEV_FLAG_DMA_IOMMU, DEV_FLAG_DMA_SKIP_SYNC, DEV_FLAG_DMA_OPS_BYPASS, + DEV_FLAG_STATE_SYNCED, }; =20 /** @@ -565,9 +569,6 @@ enum struct_device_flags { * @offline: Set after successful invocation of bus type's .offline(). * @of_node_reused: Set if the device-tree node is shared with an ancestor * device. - * @state_synced: The hardware state of this device has been synced to mat= ch - * the software state of this device by calling the driver/bus - * sync_state() callback. * @dma_coherent: this particular device is dma coherent, even if the * architecture supports non-coherent devices. * @flags: DEV_FLAG_XXX flags. Use atomic bitfield operations to modify. @@ -677,7 +678,6 @@ struct device { bool offline_disabled:1; bool offline:1; bool of_node_reused:1; - bool state_synced:1; #if defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_DEVICE) || \ defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU) || \ defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU_ALL) --=20 2.53.0.1213.gd9a14994de-goog From nobody Sun Jun 14 12:44:33 2026 Received: from mail-dy1-f171.google.com (mail-dy1-f171.google.com [74.125.82.171]) (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 9250E25DB12 for ; Fri, 3 Apr 2026 00:51:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775177520; cv=none; b=u/CaIqnIHGpYz5Ks+fP4bEx3pj6UG/eADc4l//DxQgCv7qoIAr8AUVEQWua01/TN7qHbKFzCHJEoP2Z/IlCID8a/yEi+IT5KnzF4GbW0fA1xq0lcu3btHvgeHMm1Cfv4dyxnqfHjZKMwPAYb+kEyd+qrexwW1eIgym28fw9tOjw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775177520; c=relaxed/simple; bh=CzWURY1x7xTxgzszk61vgWPH8/mqcsOMZyU04EtdnPg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ElQ59Z+fCOZFkRKD8SK+kQ+5bBXO1p4k8Dqgn7kMBZKk+15aHd9dOkk0rUi0Msu2k7ioebY2hcqaO64kd9+KD476UpWdtV5mQmDbVAEXj+i51hRe2ghjjnny84WtHuBDa15aluM4oLp2ipRm4u6RVu2vyK1ObLQUQQ/wvRIOf6U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=DJ+PZeva; arc=none smtp.client-ip=74.125.82.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="DJ+PZeva" Received: by mail-dy1-f171.google.com with SMTP id 5a478bee46e88-2c5b3d8eab1so607897eec.1 for ; Thu, 02 Apr 2026 17:51:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1775177518; x=1775782318; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7B9SH08OctcmckbQMLfLF1d3L3yf5IwR4rnNqOjePIg=; b=DJ+PZevaNm42EY7bzXPlrMtpIAXRf3d7tJIRY1gzynBhTTbyZ2BbM06bylLfHMM2S2 EO3t/G90jhIUu3qWAb9PgF8cAbydnzdkCrJy1bEv8t1m9zKNEsxKQ0dzIqhrQ5T3YQ5I 3UTt43cnDJNkQvsxtz8+oJAw/jA3AyIziherU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775177518; x=1775782318; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=7B9SH08OctcmckbQMLfLF1d3L3yf5IwR4rnNqOjePIg=; b=Q5fDkYg+LN3SRHB2WCMRWOQyPiUrmmcpTzrVMTgC0EIlkAhl8F0pzBIExViyP1O4ST HSTEvbieToslOcBAYi1yB4EX7Ta75rxW2ymoEVWqF2XBvkj2ubbjRtiQZaRzMWsq3/xt 8/E+qEikdc91123rDrL5+fmfTHLfgsopaM9LawgvOWd01A2iJW34DWGySE3gpM6wACFy XCX/znO3FfaS4YrVf9wteErhW9ELuv0uEDds/MNc6/Nm3Z7z+BARcii9IOaSmfYsOrGw yZP7+cuSxs3sQJQPnEdb7PXtRZdv4/6Cf5U2fXmxH7dV/HtHnx9Nw7QEqzwgnoPORC1/ PUSw== X-Forwarded-Encrypted: i=1; AJvYcCUdkAdJye6e4VT8Q8UcEo0yCtw+WVHWthroRpr/HRnfSJydFi6pZaIQUSNZpjmX8/hh7K38+JiwmlI12jk=@vger.kernel.org X-Gm-Message-State: AOJu0YzqOovhKC/2+3YrH5JNMpKgUbU+BCiAf35hTReIjcLt12fUj8SO j1LBE/DKQXHOd79wZ++21p7lmcP4GENuRWOAIs7Z5V/ueUFlYmOl7/v1hC7sCweTmA== X-Gm-Gg: AeBDievLvF74Zya66KTFqjoUP0S8wAFZR07X87YVDRq9ajO1CN44anNi+/vFyHMWUDy wfWQuR+p8wuSIpFekITKeBQX8AoDXSYweizHtgabKMf5qJKSCOrpH4SAQJkfIn2hprTqlKcLY/8 DeCt0zka4/8hwcmERk6NRNtju87mnOhNx5H5lqS+uJ5CEHK65NXU/eTouUTE5Nk5hdWw6dxQVGE 2rvtmgU25tnWfw3H6XTTXZLJ4mia/82pVRGovEu36UiCzQGVGDaapzge7casvhjUpsH0GOAQxTV xJWY9lEoLjqyQZTUn9imppAwiOP5CSSluiPCPmcn91MPb47W632P4mUS0XRJdlvJxjip3zgA7ys bVn+GRlLeY2r+winYIMNHdeXnRaGvXZUv2i29jUelOBh8RPMr60o0mrcMJaNmbsyzFrjJF/zGut iYRxeajG6DTcWqNxplqi3TkhSLNyntRr4ueld/Hk4sd33T+wVkSZ7e/B4B3Tt09HRE+07BXWfMw gUDcIpDNc4= X-Received: by 2002:a05:693c:3018:b0:2c0:cc90:a71 with SMTP id 5a478bee46e88-2cbf9df22d4mr651415eec.8.1775177517695; Thu, 02 Apr 2026 17:51:57 -0700 (PDT) Received: from dianders.sjc.corp.google.com ([2a00:79e0:2e7c:8:5db3:7542:a530:f43a]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2ca78df3b84sm3630074eec.5.2026.04.02.17.51.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Apr 2026 17:51:56 -0700 (PDT) From: Douglas Anderson To: Greg Kroah-Hartman , "Rafael J . Wysocki" , Danilo Krummrich , Alan Stern Cc: Robin Murphy , Leon Romanovsky , Paul Burton , Saravana Kannan , Alexander Lobakin , Eric Dumazet , Toshi Kani , Christoph Hellwig , Alexey Kardashevskiy , Johan Hovold , Douglas Anderson , Frank.Li@kernel.org, alex@ghiti.fr, andre.przywara@arm.com, andrew@lunn.ch, aou@eecs.berkeley.edu, catalin.marinas@arm.com, dmaengine@vger.kernel.org, driver-core@lists.linux.dev, gregory.clement@bootlin.com, iommu@lists.linux.dev, jgg@ziepe.ca, kees@kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, linux-riscv@lists.infradead.org, linux-snps-arc@lists.infradead.org, linux@armlinux.org.uk, m.szyprowski@samsung.com, palmer@dabbelt.com, peter.ujfalusi@gmail.com, pjw@kernel.org, sebastian.hesselbarth@gmail.com, tsbogend@alpha.franken.de, vgupta@kernel.org, vkoul@kernel.org, will@kernel.org, willy@infradead.org Subject: [PATCH v3 7/9] driver core: Replace dev->dma_coherent with DEV_FLAG_DMA_COHERENT Date: Thu, 2 Apr 2026 17:49:53 -0700 Message-ID: <20260402174925.v3.7.If839f6dde98979fce177f70c6c74689a1904ee76@changeid> X-Mailer: git-send-email 2.53.0.1213.gd9a14994de-goog In-Reply-To: <20260403005005.30424-1-dianders@chromium.org> References: <20260403005005.30424-1-dianders@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In C, bitfields are not necessarily safe to modify from multiple threads without locking. Switch "dma_coherent" over to the "flags" field so modifications are safe. Cc: Christoph Hellwig Cc: Paul Burton Signed-off-by: Douglas Anderson --- Not fixing any known bugs; problem is theoretical and found by code inspection. Change is done somewhat manually and only lightly tested (mostly compile-time tested). NOTE: even though previously we only took up a bit if CONFIG_ARCH_HAS_SYNC_DMA_FOR_DEVICE, CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU, or CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU_ALL, in this change I reserve the bit unconditionally. While we could get the "dynamic" behavior by changing the flags definition to be an "enum", it doesn't seem worth it at this point. Changes in v3: - New arch/arc/mm/dma.c | 4 ++-- arch/arm/mach-highbank/highbank.c | 2 +- arch/arm/mach-mvebu/coherency.c | 2 +- arch/arm/mm/dma-mapping-nommu.c | 4 ++-- arch/arm/mm/dma-mapping.c | 30 ++++++++++++++++-------------- arch/arm64/mm/dma-mapping.c | 2 +- arch/mips/mm/dma-noncoherent.c | 2 +- arch/riscv/mm/dma-noncoherent.c | 2 +- drivers/base/core.c | 2 +- drivers/dma/ti/k3-udma-glue.c | 6 +++--- drivers/dma/ti/k3-udma.c | 6 +++--- include/linux/device.h | 10 +++------- include/linux/dma-map-ops.h | 2 +- 13 files changed, 36 insertions(+), 38 deletions(-) diff --git a/arch/arc/mm/dma.c b/arch/arc/mm/dma.c index 6b85e94f3275..3d56878cb6a2 100644 --- a/arch/arc/mm/dma.c +++ b/arch/arc/mm/dma.c @@ -98,8 +98,8 @@ void arch_setup_dma_ops(struct device *dev, bool coherent) * DMA buffers. */ if (is_isa_arcv2() && ioc_enable && coherent) - dev->dma_coherent =3D true; + set_bit(DEV_FLAG_DMA_COHERENT, &dev->flags); =20 dev_info(dev, "use %scoherent DMA ops\n", - dev->dma_coherent ? "" : "non"); + test_bit(DEV_FLAG_DMA_COHERENT, &dev->flags) ? "" : "non"); } diff --git a/arch/arm/mach-highbank/highbank.c b/arch/arm/mach-highbank/hig= hbank.c index 47335c7dadf8..ffa3f591f57a 100644 --- a/arch/arm/mach-highbank/highbank.c +++ b/arch/arm/mach-highbank/highbank.c @@ -98,7 +98,7 @@ static int highbank_platform_notifier(struct notifier_blo= ck *nb, if (of_property_read_bool(dev->of_node, "dma-coherent")) { val =3D readl(sregs_base + reg); writel(val | 0xff01, sregs_base + reg); - dev->dma_coherent =3D true; + set_bit(DEV_FLAG_DMA_COHERENT, &dev->flags); } =20 return NOTIFY_OK; diff --git a/arch/arm/mach-mvebu/coherency.c b/arch/arm/mach-mvebu/coherenc= y.c index fa2c1e1aeb96..8391303a6a17 100644 --- a/arch/arm/mach-mvebu/coherency.c +++ b/arch/arm/mach-mvebu/coherency.c @@ -95,7 +95,7 @@ static int mvebu_hwcc_notifier(struct notifier_block *nb, =20 if (event !=3D BUS_NOTIFY_ADD_DEVICE) return NOTIFY_DONE; - dev->dma_coherent =3D true; + set_bit(DEV_FLAG_DMA_COHERENT, &dev->flags); =20 return NOTIFY_OK; } diff --git a/arch/arm/mm/dma-mapping-nommu.c b/arch/arm/mm/dma-mapping-nomm= u.c index fecac107fd0d..ac0a976e30a0 100644 --- a/arch/arm/mm/dma-mapping-nommu.c +++ b/arch/arm/mm/dma-mapping-nommu.c @@ -42,11 +42,11 @@ void arch_setup_dma_ops(struct device *dev, bool cohere= nt) * enough to check if MPU is in use or not since in absence of * MPU system memory map is used. */ - dev->dma_coherent =3D cacheid ? coherent : true; + assign_bit(DEV_FLAG_DMA_COHERENT, &dev->flags, cacheid ? coherent : true= ); } else { /* * Assume coherent DMA in case MMU/MPU has not been set up. */ - dev->dma_coherent =3D (get_cr() & CR_M) ? coherent : true; + assign_bit(DEV_FLAG_DMA_COHERENT, &dev->flags, (get_cr() & CR_M) ? coher= ent : true); } } diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c index f304037d1c34..9c2c635d7ac0 100644 --- a/arch/arm/mm/dma-mapping.c +++ b/arch/arm/mm/dma-mapping.c @@ -1076,7 +1076,7 @@ static void *arm_iommu_alloc_attrs(struct device *dev= , size_t size, pgprot_t prot =3D __get_dma_pgprot(attrs, PAGE_KERNEL); struct page **pages; void *addr =3D NULL; - int coherent_flag =3D dev->dma_coherent ? COHERENT : NORMAL; + int coherent_flag =3D test_bit(DEV_FLAG_DMA_COHERENT, &dev->flags) ? COHE= RENT : NORMAL; =20 *handle =3D DMA_MAPPING_ERROR; size =3D PAGE_ALIGN(size); @@ -1124,7 +1124,7 @@ static int arm_iommu_mmap_attrs(struct device *dev, s= truct vm_area_struct *vma, if (vma->vm_pgoff >=3D nr_pages) return -ENXIO; =20 - if (!dev->dma_coherent) + if (!test_bit(DEV_FLAG_DMA_COHERENT, &dev->flags)) vma->vm_page_prot =3D __get_dma_pgprot(attrs, vma->vm_page_prot); =20 err =3D vm_map_pages(vma, pages, nr_pages); @@ -1141,7 +1141,7 @@ static int arm_iommu_mmap_attrs(struct device *dev, s= truct vm_area_struct *vma, static void arm_iommu_free_attrs(struct device *dev, size_t size, void *cp= u_addr, dma_addr_t handle, unsigned long attrs) { - int coherent_flag =3D dev->dma_coherent ? COHERENT : NORMAL; + int coherent_flag =3D test_bit(DEV_FLAG_DMA_COHERENT, &dev->flags) ? COHE= RENT : NORMAL; struct page **pages; size =3D PAGE_ALIGN(size); =20 @@ -1202,7 +1202,8 @@ static int __map_sg_chunk(struct device *dev, struct = scatterlist *sg, phys_addr_t phys =3D page_to_phys(sg_page(s)); unsigned int len =3D PAGE_ALIGN(s->offset + s->length); =20 - if (!dev->dma_coherent && !(attrs & DMA_ATTR_SKIP_CPU_SYNC)) + if (!test_bit(DEV_FLAG_DMA_COHERENT, &dev->flags) && + !(attrs & DMA_ATTR_SKIP_CPU_SYNC)) arch_sync_dma_for_device(sg_phys(s), s->length, dir); =20 prot =3D __dma_info_to_prot(dir, attrs); @@ -1304,7 +1305,8 @@ static void arm_iommu_unmap_sg(struct device *dev, if (sg_dma_len(s)) __iommu_remove_mapping(dev, sg_dma_address(s), sg_dma_len(s)); - if (!dev->dma_coherent && !(attrs & DMA_ATTR_SKIP_CPU_SYNC)) + if (!test_bit(DEV_FLAG_DMA_COHERENT, &dev->flags) && + !(attrs & DMA_ATTR_SKIP_CPU_SYNC)) arch_sync_dma_for_cpu(sg_phys(s), s->length, dir); } } @@ -1323,7 +1325,7 @@ static void arm_iommu_sync_sg_for_cpu(struct device *= dev, struct scatterlist *s; int i; =20 - if (dev->dma_coherent) + if (test_bit(DEV_FLAG_DMA_COHERENT, &dev->flags)) return; =20 for_each_sg(sg, s, nents, i) @@ -1345,7 +1347,7 @@ static void arm_iommu_sync_sg_for_device(struct devic= e *dev, struct scatterlist *s; int i; =20 - if (dev->dma_coherent) + if (test_bit(DEV_FLAG_DMA_COHERENT, &dev->flags)) return; =20 for_each_sg(sg, s, nents, i) @@ -1371,7 +1373,7 @@ static dma_addr_t arm_iommu_map_phys(struct device *d= ev, phys_addr_t phys, dma_addr_t dma_addr; int ret, prot; =20 - if (!dev->dma_coherent && + if (!test_bit(DEV_FLAG_DMA_COHERENT, &dev->flags) && !(attrs & (DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_MMIO))) arch_sync_dma_for_device(phys, size, dir); =20 @@ -1412,7 +1414,7 @@ static void arm_iommu_unmap_phys(struct device *dev, = dma_addr_t handle, if (!iova) return; =20 - if (!dev->dma_coherent && + if (!test_bit(DEV_FLAG_DMA_COHERENT, &dev->flags) && !(attrs & (DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_MMIO))) { phys_addr_t phys =3D iommu_iova_to_phys(mapping->domain, iova); =20 @@ -1431,7 +1433,7 @@ static void arm_iommu_sync_single_for_cpu(struct devi= ce *dev, unsigned int offset =3D handle & ~PAGE_MASK; phys_addr_t phys; =20 - if (dev->dma_coherent || !iova) + if (test_bit(DEV_FLAG_DMA_COHERENT, &dev->flags) || !iova) return; =20 phys =3D iommu_iova_to_phys(mapping->domain, iova); @@ -1446,7 +1448,7 @@ static void arm_iommu_sync_single_for_device(struct d= evice *dev, unsigned int offset =3D handle & ~PAGE_MASK; phys_addr_t phys; =20 - if (dev->dma_coherent || !iova) + if (test_bit(DEV_FLAG_DMA_COHERENT, &dev->flags) || !iova) return; =20 phys =3D iommu_iova_to_phys(mapping->domain, iova); @@ -1701,13 +1703,13 @@ static void arm_teardown_iommu_dma_ops(struct devic= e *dev) { } void arch_setup_dma_ops(struct device *dev, bool coherent) { /* - * Due to legacy code that sets the ->dma_coherent flag from a bus - * notifier we can't just assign coherent to the ->dma_coherent flag + * Due to legacy code that sets DEV_FLAG_DMA_COHERENT from a bus + * notifier we can't just assign coherent to DEV_FLAG_DMA_COHERENT * here, but instead have to make sure we only set but never clear it * for now. */ if (coherent) - dev->dma_coherent =3D true; + set_bit(DEV_FLAG_DMA_COHERENT, &dev->flags); =20 /* * Don't override the dma_ops if they have already been set. Ideally diff --git a/arch/arm64/mm/dma-mapping.c b/arch/arm64/mm/dma-mapping.c index b2b5792b2caa..256c7631aff5 100644 --- a/arch/arm64/mm/dma-mapping.c +++ b/arch/arm64/mm/dma-mapping.c @@ -48,7 +48,7 @@ void arch_setup_dma_ops(struct device *dev, bool coherent) dev_driver_string(dev), dev_name(dev), ARCH_DMA_MINALIGN, cls); =20 - dev->dma_coherent =3D coherent; + assign_bit(DEV_FLAG_DMA_COHERENT, &dev->flags, coherent); =20 xen_setup_dma_ops(dev); } diff --git a/arch/mips/mm/dma-noncoherent.c b/arch/mips/mm/dma-noncoherent.c index ab4f2a75a7d0..496bf5f4999c 100644 --- a/arch/mips/mm/dma-noncoherent.c +++ b/arch/mips/mm/dma-noncoherent.c @@ -139,6 +139,6 @@ void arch_sync_dma_for_cpu(phys_addr_t paddr, size_t si= ze, #ifdef CONFIG_ARCH_HAS_SETUP_DMA_OPS void arch_setup_dma_ops(struct device *dev, bool coherent) { - dev->dma_coherent =3D coherent; + assign_bit(DEV_FLAG_DMA_COHERENT, &dev->flags, coherent); } #endif diff --git a/arch/riscv/mm/dma-noncoherent.c b/arch/riscv/mm/dma-noncoheren= t.c index cb89d7e0ba88..3b793a1cc607 100644 --- a/arch/riscv/mm/dma-noncoherent.c +++ b/arch/riscv/mm/dma-noncoherent.c @@ -140,7 +140,7 @@ void arch_setup_dma_ops(struct device *dev, bool cohere= nt) "%s %s: device non-coherent but no non-coherent operations supported", dev_driver_string(dev), dev_name(dev)); =20 - dev->dma_coherent =3D coherent; + assign_bit(DEV_FLAG_DMA_COHERENT, &dev->flags, coherent); } =20 void riscv_noncoherent_supported(void) diff --git a/drivers/base/core.c b/drivers/base/core.c index 8dbb7a9c7aab..00005777c21f 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -3174,7 +3174,7 @@ void device_initialize(struct device *dev) #if defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_DEVICE) || \ defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU) || \ defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU_ALL) - dev->dma_coherent =3D dma_default_coherent; + assign_bit(DEV_FLAG_DMA_COHERENT, &dev->flags, dma_default_coherent); #endif swiotlb_dev_init(dev); } diff --git a/drivers/dma/ti/k3-udma-glue.c b/drivers/dma/ti/k3-udma-glue.c index f87d244cc2d6..cda8f4a8f440 100644 --- a/drivers/dma/ti/k3-udma-glue.c +++ b/drivers/dma/ti/k3-udma-glue.c @@ -312,7 +312,7 @@ k3_udma_glue_request_tx_chn_common(struct device *dev, =20 if (xudma_is_pktdma(tx_chn->common.udmax)) { /* prepare the channel device as coherent */ - tx_chn->common.chan_dev.dma_coherent =3D true; + set_bit(DEV_FLAG_DMA_COHERENT, &tx_chn->common.chan_dev.flags); dma_coerce_mask_and_coherent(&tx_chn->common.chan_dev, DMA_BIT_MASK(48)); } @@ -1003,7 +1003,7 @@ k3_udma_glue_request_rx_chn_priv(struct device *dev, = const char *name, =20 if (xudma_is_pktdma(rx_chn->common.udmax)) { /* prepare the channel device as coherent */ - rx_chn->common.chan_dev.dma_coherent =3D true; + set_bit(DEV_FLAG_DMA_COHERENT, &rx_chn->common.chan_dev.flags); dma_coerce_mask_and_coherent(&rx_chn->common.chan_dev, DMA_BIT_MASK(48)); } @@ -1104,7 +1104,7 @@ k3_udma_glue_request_remote_rx_chn_common(struct k3_u= dma_glue_rx_channel *rx_chn =20 if (xudma_is_pktdma(rx_chn->common.udmax)) { /* prepare the channel device as coherent */ - rx_chn->common.chan_dev.dma_coherent =3D true; + set_bit(DEV_FLAG_DMA_COHERENT, &rx_chn->common.chan_dev.flags); dma_coerce_mask_and_coherent(&rx_chn->common.chan_dev, DMA_BIT_MASK(48)); rx_chn->single_fdq =3D false; diff --git a/drivers/dma/ti/k3-udma.c b/drivers/dma/ti/k3-udma.c index c964ebfcf3b6..770aae467fc5 100644 --- a/drivers/dma/ti/k3-udma.c +++ b/drivers/dma/ti/k3-udma.c @@ -428,18 +428,18 @@ static void k3_configure_chan_coherency(struct dma_ch= an *chan, u32 asel) /* No special handling for the channel */ chan->dev->chan_dma_dev =3D false; =20 - chan_dev->dma_coherent =3D false; + clear_bit(DEV_FLAG_DMA_COHERENT, &chan_dev->flags); chan_dev->dma_parms =3D NULL; } else if (asel =3D=3D 14 || asel =3D=3D 15) { chan->dev->chan_dma_dev =3D true; =20 - chan_dev->dma_coherent =3D true; + set_bit(DEV_FLAG_DMA_COHERENT, &chan_dev->flags); dma_coerce_mask_and_coherent(chan_dev, DMA_BIT_MASK(48)); chan_dev->dma_parms =3D chan_dev->parent->dma_parms; } else { dev_warn(chan->device->dev, "Invalid ASEL value: %u\n", asel); =20 - chan_dev->dma_coherent =3D false; + clear_bit(DEV_FLAG_DMA_COHERENT, &chan_dev->flags); chan_dev->dma_parms =3D NULL; } } diff --git a/include/linux/device.h b/include/linux/device.h index 6c961dac9fdb..c2a6dba7a036 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -480,6 +480,8 @@ struct device_physical_location { * @DEV_FLAG_STATE_SYNCED: The hardware state of this device has been sync= ed to * match the software state of this device by calling the * driver/bus sync_state() callback. + * @DEV_FLAG_DMA_COHERENT: This particular device is dma coherent, even if= the + * architecture supports non-coherent devices. */ enum struct_device_flags { DEV_FLAG_READY_TO_PROBE, @@ -488,6 +490,7 @@ enum struct_device_flags { DEV_FLAG_DMA_SKIP_SYNC, DEV_FLAG_DMA_OPS_BYPASS, DEV_FLAG_STATE_SYNCED, + DEV_FLAG_DMA_COHERENT, }; =20 /** @@ -569,8 +572,6 @@ enum struct_device_flags { * @offline: Set after successful invocation of bus type's .offline(). * @of_node_reused: Set if the device-tree node is shared with an ancestor * device. - * @dma_coherent: this particular device is dma coherent, even if the - * architecture supports non-coherent devices. * @flags: DEV_FLAG_XXX flags. Use atomic bitfield operations to modify. * * At the lowest level, every device in a Linux system is represented by an @@ -678,11 +679,6 @@ struct device { bool offline_disabled:1; bool offline:1; bool of_node_reused:1; -#if defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_DEVICE) || \ - defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU) || \ - defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU_ALL) - bool dma_coherent:1; -#endif =20 unsigned long flags; }; diff --git a/include/linux/dma-map-ops.h b/include/linux/dma-map-ops.h index 4d9d1fe3277c..91d34678657c 100644 --- a/include/linux/dma-map-ops.h +++ b/include/linux/dma-map-ops.h @@ -230,7 +230,7 @@ int dma_direct_set_offset(struct device *dev, phys_addr= _t cpu_start, extern bool dma_default_coherent; static inline bool dev_is_dma_coherent(struct device *dev) { - return dev->dma_coherent; + return test_bit(DEV_FLAG_DMA_COHERENT, &dev->flags); } #else #define dma_default_coherent true --=20 2.53.0.1213.gd9a14994de-goog From nobody Sun Jun 14 12:44:33 2026 Received: from mail-dy1-f171.google.com (mail-dy1-f171.google.com [74.125.82.171]) (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 A01FB23F40D for ; Fri, 3 Apr 2026 00:52:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775177524; cv=none; b=RX0OQ8zgNQ7q/st6s7srHdmSHz9I6HggCwiBlmHHprox80l4tbF15zhtNRmsrC93CzhnmseA7liUtKLqrFALO2acRWijn5RyATRNOcU7IOaB4mVCH0PfNgCWeu0HVnYLr44MjXOq2iAttWMb3yK2VPhptdpAIzJhyaJfnnZSzpY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775177524; c=relaxed/simple; bh=tRMVu6GM7+H2C7gIhSHYmeG83ofUKG+ZKGYfkloYcYI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SXlL9VHKbKSXOWO5hPxh3CJtGrwIJJtCGcuxDD2pvz73HrnYVL9vhkob+73J03Kc9nTP8jWuUNYj9ais6NjH9RgPqEIvdfvMnu25M+WtELMHQgs+wL+SF79YqY6oPdf1zZPnmlwFKDUtxJEQziDMLbkFjf60q0TD8tWjQcQWhAc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=W+jXmbwg; arc=none smtp.client-ip=74.125.82.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="W+jXmbwg" Received: by mail-dy1-f171.google.com with SMTP id 5a478bee46e88-2b4520f6b32so1695616eec.0 for ; Thu, 02 Apr 2026 17:52:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1775177522; x=1775782322; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=c0XcTKJSZv00lNgVXjUFXubjiKj+C90x3kNuWZLzTwo=; b=W+jXmbwgjuoPkOv7IL+E1thwTwrIBBT8gasmaqbyDeSWvHtnqi86ApSGhttgbKQw15 h42uv5FbWBFCWL6uhbzVshUtOo6Ej39wCrsXXKAJOkHNriYr5YFM3+YPDgRPRCjqMQn0 4NFyaJM4vp3rd3szTNyHfTVMfY2Zl+o2o45GA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775177522; x=1775782322; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=c0XcTKJSZv00lNgVXjUFXubjiKj+C90x3kNuWZLzTwo=; b=Pn4frOvjhTUw4ywVPePQtv0lk6gbDTVlyC5TXmbb26nBe40toBt6SVOVFY3XOHDVkG p+jXFxCXvlr+uuRpOpgW4XsTmvpjdgE47yLmGpsUP7xKMpQOj81Lp9BeORpWQDIIrdfA ISuBQ49aUs/fk7/Ccd35U9TVyrZEJ+vyt4LqEX08ZRakqg/nSJQj1T6b7RgVKfg80AGe Tksw5QqJCLaNLcRHKdedZud7VqpEepEChq4z/JkvVx+LfY7QpWVxQajOmM9cj5+ErxOP BwEX6dUPlJVZI2I6y3VG5V5wlJTQFE/XfMCwg+ca07dqUdoChZdbWzfmkKi88VrV7Vhr SuTw== X-Forwarded-Encrypted: i=1; AJvYcCUYrpbQnvqPa1KM82R1LPcHnAGdRL9NPyOcbTn0rqxgWpa8/1sNAk/nGMr+qMUA8+6NspIl9iKsP3CMtQ0=@vger.kernel.org X-Gm-Message-State: AOJu0YxBGivHN6JzoCK91FVDBIRLsz0d8JR0fvCjvJCCs/xVY4StogRA LN6D/MZ0KmsPTIGHRVpNPuuAbSE5j4Dn1ycHHYf93xGSq0G9PC/JlWLNxePXl7JCOA== X-Gm-Gg: AeBDiesHlx5mQYdSnoKqXT3wlqyoaykZN8S+Q5bD4X3FojJo3pMTXJty5CFvmtz7wOR Gh02K8h2VP0WhRPu01dJCPimafhnuDODjOGAJEJVvX4BrTkQd8pPhfaNQ+sdKNjMR8YXevCTnq+ drPPKJkBzm5ILhZK4nMkFS2PzoWY+15O3rSDBRWglNraLaJL/SV/ZpZLlYPDMxkxwdk3Wp+Qd4I vPWCbnjOQ0qBijqoU1D/HTINEt3Q0KwOCBPiO+AIpPaQPJfrvctJqSvn70Y7K/LaPj+cROpbJYu E+knUd+nt5TZMECxbp/iY0uNPWz/+HteCjVLLtDJ7dX5MZl2dgYSqUGft5A2a2ZTJVS8xRgRqhg 6EBvBcqsLIPJrrheNc1tH7GigvQpiP73vHhMNwxjQFpwRYE2M9UarLJgOYmoZfTAX0VvaZgEb0j vUO926VKYv9E/GYbKkt8bOAJFr/OLwAobxrGo0i5tNwi4janRUwpsijWqvAFl6RWRCNAe3kPI9R ZG8dfA/qn0= X-Received: by 2002:a05:7300:2315:b0:2c8:b5e1:6b03 with SMTP id 5a478bee46e88-2cbfbf77d16mr618666eec.23.1775177521837; Thu, 02 Apr 2026 17:52:01 -0700 (PDT) Received: from dianders.sjc.corp.google.com ([2a00:79e0:2e7c:8:5db3:7542:a530:f43a]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2ca78df3b84sm3630074eec.5.2026.04.02.17.51.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Apr 2026 17:51:59 -0700 (PDT) From: Douglas Anderson To: Greg Kroah-Hartman , "Rafael J . Wysocki" , Danilo Krummrich , Alan Stern Cc: Robin Murphy , Leon Romanovsky , Paul Burton , Saravana Kannan , Alexander Lobakin , Eric Dumazet , Toshi Kani , Christoph Hellwig , Alexey Kardashevskiy , Johan Hovold , Douglas Anderson , alexander.stein@ew.tq-group.com, andrew@codeconstruct.com.au, andrew@lunn.ch, andriy.shevchenko@linux.intel.com, astewart@tektelic.com, bhelgaas@google.com, brgl@kernel.org, broonie@kernel.org, davem@davemloft.net, devicetree@vger.kernel.org, driver-core@lists.linux.dev, hkallweit1@gmail.com, jirislaby@kernel.org, joel@jms.id.au, kees@kernel.org, kuba@kernel.org, lgirdwood@gmail.com, linux-arm-kernel@lists.infradead.org, linux-aspeed@lists.ozlabs.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, linux-serial@vger.kernel.org, linux-usb@vger.kernel.org, linux@armlinux.org.uk, mani@kernel.org, netdev@vger.kernel.org, pabeni@redhat.com, robh@kernel.org Subject: [PATCH v3 8/9] driver core: Replace dev->of_node_reused with DEV_FLAG_OF_NODE_REUSED Date: Thu, 2 Apr 2026 17:49:54 -0700 Message-ID: <20260402174925.v3.8.I806b8636cd3724f6cd1f5e199318ab8694472d90@changeid> X-Mailer: git-send-email 2.53.0.1213.gd9a14994de-goog In-Reply-To: <20260403005005.30424-1-dianders@chromium.org> References: <20260403005005.30424-1-dianders@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In C, bitfields are not necessarily safe to modify from multiple threads without locking. Switch "of_node_reused" over to the "flags" field so modifications are safe. Cc: Johan Hovold Signed-off-by: Douglas Anderson Acked-by: Mark Brown --- Not fixing any known bugs; problem is theoretical and found by code inspection. Change is done somewhat manually and only lightly tested (mostly compile-time tested). Changes in v3: - New drivers/base/core.c | 2 +- drivers/base/pinctrl.c | 2 +- drivers/base/platform.c | 2 +- drivers/net/pcs/pcs-xpcs-plat.c | 2 +- drivers/of/device.c | 6 +++--- drivers/pci/of.c | 2 +- drivers/pci/pwrctrl/core.c | 2 +- drivers/regulator/bq257xx-regulator.c | 2 +- drivers/regulator/rk808-regulator.c | 2 +- drivers/tty/serial/serial_base_bus.c | 2 +- drivers/usb/gadget/udc/aspeed-vhub/dev.c | 2 +- include/linux/device.h | 6 +++--- 12 files changed, 16 insertions(+), 16 deletions(-) diff --git a/drivers/base/core.c b/drivers/base/core.c index 00005777c21f..a87bd40499b6 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -5282,7 +5282,7 @@ void device_set_of_node_from_dev(struct device *dev, = const struct device *dev2) { of_node_put(dev->of_node); dev->of_node =3D of_node_get(dev2->of_node); - dev->of_node_reused =3D true; + set_bit(DEV_FLAG_OF_NODE_REUSED, &dev->flags); } EXPORT_SYMBOL_GPL(device_set_of_node_from_dev); =20 diff --git a/drivers/base/pinctrl.c b/drivers/base/pinctrl.c index 6e250272c843..62c228c75d50 100644 --- a/drivers/base/pinctrl.c +++ b/drivers/base/pinctrl.c @@ -24,7 +24,7 @@ int pinctrl_bind_pins(struct device *dev) { int ret; =20 - if (dev->of_node_reused) + if (test_bit(DEV_FLAG_OF_NODE_REUSED, &dev->flags)) return 0; =20 dev->pins =3D devm_kzalloc(dev, sizeof(*(dev->pins)), GFP_KERNEL); diff --git a/drivers/base/platform.c b/drivers/base/platform.c index d44591d52e36..5128ff7e5e78 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -856,7 +856,7 @@ struct platform_device *platform_device_register_full( pdev->dev.parent =3D pdevinfo->parent; pdev->dev.fwnode =3D pdevinfo->fwnode; pdev->dev.of_node =3D of_node_get(to_of_node(pdev->dev.fwnode)); - pdev->dev.of_node_reused =3D pdevinfo->of_node_reused; + assign_bit(DEV_FLAG_OF_NODE_REUSED, &pdev->dev.flags, pdevinfo->of_node_r= eused); =20 if (pdevinfo->dma_mask) { pdev->platform_dma_mask =3D pdevinfo->dma_mask; diff --git a/drivers/net/pcs/pcs-xpcs-plat.c b/drivers/net/pcs/pcs-xpcs-pla= t.c index b8c48f9effbf..c2722d8bd98a 100644 --- a/drivers/net/pcs/pcs-xpcs-plat.c +++ b/drivers/net/pcs/pcs-xpcs-plat.c @@ -349,7 +349,7 @@ static int xpcs_plat_init_dev(struct dw_xpcs_plat *pxpc= s) * up later. Make sure DD-core is aware of the OF-node being re-used. */ device_set_node(&mdiodev->dev, fwnode_handle_get(dev_fwnode(dev))); - mdiodev->dev.of_node_reused =3D true; + set_bit(DEV_FLAG_OF_NODE_REUSED, &mdiodev->dev.flags); =20 /* Pass the data further so the DW XPCS driver core could use it */ mdiodev->dev.platform_data =3D (void *)device_get_match_data(dev); diff --git a/drivers/of/device.c b/drivers/of/device.c index f7e75e527667..fd77295a8c0f 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c @@ -26,7 +26,7 @@ const struct of_device_id *of_match_device(const struct of_device_id *matc= hes, const struct device *dev) { - if (!matches || !dev->of_node || dev->of_node_reused) + if (!matches || !dev->of_node || test_bit(DEV_FLAG_OF_NODE_REUSED, &dev->= flags)) return NULL; return of_match_node(matches, dev->of_node); } @@ -192,7 +192,7 @@ ssize_t of_device_modalias(struct device *dev, char *st= r, ssize_t len) { ssize_t sl; =20 - if (!dev || !dev->of_node || dev->of_node_reused) + if (!dev || !dev->of_node || test_bit(DEV_FLAG_OF_NODE_REUSED, &dev->flag= s)) return -ENODEV; =20 sl =3D of_modalias(dev->of_node, str, len - 2); @@ -254,7 +254,7 @@ int of_device_uevent_modalias(const struct device *dev,= struct kobj_uevent_env * { int sl; =20 - if ((!dev) || (!dev->of_node) || dev->of_node_reused) + if ((!dev) || (!dev->of_node) || test_bit(DEV_FLAG_OF_NODE_REUSED, &dev->= flags)) return -ENODEV; =20 /* Devicetree modalias is tricky, we add it in 2 steps */ diff --git a/drivers/pci/of.c b/drivers/pci/of.c index 9f8eb5df279e..197b60c5a660 100644 --- a/drivers/pci/of.c +++ b/drivers/pci/of.c @@ -38,7 +38,7 @@ int pci_set_of_node(struct pci_dev *dev) struct device *pdev __free(put_device) =3D bus_find_device_by_of_node(&platform_bus_type, node); if (pdev) - dev->bus->dev.of_node_reused =3D true; + set_bit(DEV_FLAG_OF_NODE_REUSED, &dev->bus->dev.flags); =20 device_set_node(&dev->dev, of_fwnode_handle(no_free_ptr(node))); return 0; diff --git a/drivers/pci/pwrctrl/core.c b/drivers/pci/pwrctrl/core.c index 7754baed67f2..cfbe9b615b88 100644 --- a/drivers/pci/pwrctrl/core.c +++ b/drivers/pci/pwrctrl/core.c @@ -39,7 +39,7 @@ static int pci_pwrctrl_notify(struct notifier_block *nb, = unsigned long action, * If we got here then the PCI device is the second after the * power control platform device. Mark its OF node as reused. */ - dev->of_node_reused =3D true; + set_bit(DEV_FLAG_OF_NODE_REUSED, &dev->flags); break; } =20 diff --git a/drivers/regulator/bq257xx-regulator.c b/drivers/regulator/bq25= 7xx-regulator.c index dab8f1ab4450..01d3139e1d87 100644 --- a/drivers/regulator/bq257xx-regulator.c +++ b/drivers/regulator/bq257xx-regulator.c @@ -143,7 +143,7 @@ static int bq257xx_regulator_probe(struct platform_devi= ce *pdev) struct regulator_config cfg =3D {}; =20 pdev->dev.of_node =3D pdev->dev.parent->of_node; - pdev->dev.of_node_reused =3D true; + set_bit(DEV_FLAG_OF_NODE_REUSED, &pdev->dev.flags); =20 pdata =3D devm_kzalloc(&pdev->dev, sizeof(struct bq257xx_reg_data), GFP_K= ERNEL); if (!pdata) diff --git a/drivers/regulator/rk808-regulator.c b/drivers/regulator/rk808-= regulator.c index e66408f23bb6..375ea7861134 100644 --- a/drivers/regulator/rk808-regulator.c +++ b/drivers/regulator/rk808-regulator.c @@ -2115,7 +2115,7 @@ static int rk808_regulator_probe(struct platform_devi= ce *pdev) int ret, i, nregulators; =20 pdev->dev.of_node =3D pdev->dev.parent->of_node; - pdev->dev.of_node_reused =3D true; + set_bit(DEV_FLAG_OF_NODE_REUSED, &pdev->dev.flags); =20 regmap =3D dev_get_regmap(pdev->dev.parent, NULL); if (!regmap) diff --git a/drivers/tty/serial/serial_base_bus.c b/drivers/tty/serial/seri= al_base_bus.c index a12935f6b992..86c6003bbebb 100644 --- a/drivers/tty/serial/serial_base_bus.c +++ b/drivers/tty/serial/serial_base_bus.c @@ -74,7 +74,7 @@ static int serial_base_device_init(struct uart_port *port, dev->parent =3D parent_dev; dev->bus =3D &serial_base_bus_type; dev->release =3D release; - dev->of_node_reused =3D true; + set_bit(DEV_FLAG_OF_NODE_REUSED, &dev->flags); =20 device_set_node(dev, fwnode_handle_get(dev_fwnode(parent_dev))); =20 diff --git a/drivers/usb/gadget/udc/aspeed-vhub/dev.c b/drivers/usb/gadget/= udc/aspeed-vhub/dev.c index 2ecd049dacc2..57048e3aa6bb 100644 --- a/drivers/usb/gadget/udc/aspeed-vhub/dev.c +++ b/drivers/usb/gadget/udc/aspeed-vhub/dev.c @@ -593,7 +593,7 @@ int ast_vhub_init_dev(struct ast_vhub *vhub, unsigned i= nt idx) d->gadget.max_speed =3D USB_SPEED_HIGH; d->gadget.speed =3D USB_SPEED_UNKNOWN; d->gadget.dev.of_node =3D vhub->pdev->dev.of_node; - d->gadget.dev.of_node_reused =3D true; + set_bit(DEV_FLAG_OF_NODE_REUSED, &d->gadget.dev.flags); =20 rc =3D usb_add_gadget_udc(d->port_dev, &d->gadget); if (rc !=3D 0) diff --git a/include/linux/device.h b/include/linux/device.h index c2a6dba7a036..f6ca067bacca 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -482,6 +482,8 @@ struct device_physical_location { * driver/bus sync_state() callback. * @DEV_FLAG_DMA_COHERENT: This particular device is dma coherent, even if= the * architecture supports non-coherent devices. + * @DEV_FLAG_OF_NODE_REUSED: Set if the device-tree node is shared with an + * ancestor device. */ enum struct_device_flags { DEV_FLAG_READY_TO_PROBE, @@ -491,6 +493,7 @@ enum struct_device_flags { DEV_FLAG_DMA_OPS_BYPASS, DEV_FLAG_STATE_SYNCED, DEV_FLAG_DMA_COHERENT, + DEV_FLAG_OF_NODE_REUSED, }; =20 /** @@ -570,8 +573,6 @@ enum struct_device_flags { * * @offline_disabled: If set, the device is permanently online. * @offline: Set after successful invocation of bus type's .offline(). - * @of_node_reused: Set if the device-tree node is shared with an ancestor - * device. * @flags: DEV_FLAG_XXX flags. Use atomic bitfield operations to modify. * * At the lowest level, every device in a Linux system is represented by an @@ -678,7 +679,6 @@ struct device { =20 bool offline_disabled:1; bool offline:1; - bool of_node_reused:1; =20 unsigned long flags; }; --=20 2.53.0.1213.gd9a14994de-goog From nobody Sun Jun 14 12:44:33 2026 Received: from mail-dy1-f169.google.com (mail-dy1-f169.google.com [74.125.82.169]) (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 05D6726A0C7 for ; Fri, 3 Apr 2026 00:52:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775177527; cv=none; b=neybZzKpASRdmeen34ih9HA/J4AYB+spY4NkcfFtTCsJgKdGFk1o5yPn1Bn4pHr2uwSj+AOk+5U9kaCXRtUJjSkVTqznKuebfp3ftR8GQ+2jcHmsfDdTwJnJNEi2yGsgO2OAQTBhaleW0mBvf7xKK66zv7oLRM6QGAMT5MMKiEw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775177527; c=relaxed/simple; bh=FRXQhiPBlmM8Nf/l1BWYW6VM0cMqLlgsypXgESCbjJ0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QQHD9WHoA7m+5OYjOIyVby2QTlcrO9sjnycccic7JhA36Tuxdd872EepaBsEabyg8d1j3zgYLeGvhPIpY4s3AzsWQx9sjwOPKmhho1gJd5dKa6D794BBRiU6bZp/R4pQXf3O5bZw0s7FXJ/4CgDSOZpDH7NgG88HNqjp2ULHkOs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=E6+Z+mSQ; arc=none smtp.client-ip=74.125.82.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="E6+Z+mSQ" Received: by mail-dy1-f169.google.com with SMTP id 5a478bee46e88-2c7e5f38b37so2036283eec.0 for ; Thu, 02 Apr 2026 17:52:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1775177525; x=1775782325; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VEt3hSd9EKLTT0Wo55fxgtHBJYKHT3uVPRy+V8bzYNY=; b=E6+Z+mSQ06Oh1k0ZMGEGUfLUFjlHVsgo2gEEWE3iaYqfLNTmR3rzqfp8wGMRY++Ohj G6a9RBOGfrVsjqvMFa/flkLa89E80C4sMxZX8OWq/lqiH3HBThUH7bG8EqZbpSaWAFXr XMYECcwrdWeEAuayPvfbCpk27cGqNfugIkFBU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775177525; x=1775782325; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=VEt3hSd9EKLTT0Wo55fxgtHBJYKHT3uVPRy+V8bzYNY=; b=HH9wJPBvWsdDRvjCjlCIptBTKGzCRTBzmHs2wE8NEbG3dbxd4xa5BxNcxWF8ezHhD0 IDea0Dkz+wxV5G6L8DnHVsqHr7sl9RMG+qjJt643FfAsPWOM+Gi1h3Aizvch1m+Zs3VE 8HsbtqI3FvBSml9t1AvOUImcMmgjbgFjGSCiHvZVXxsFODgFDRb7oxxE+d+HiQdWLtok 8DvZU8O1LADHkiLVr+b6U20Fz3XdIQs2DH0eC6SvV5qxW7CEeHX0JUhC06ViC4b+zg7B TMhSjkurROsoC76JjRFpKTOJDrf2fn92+fwTKkY6GL/Y/TA/fiV3vK4fOKxRs2hKkZcN lxyw== X-Forwarded-Encrypted: i=1; AJvYcCXrd+pIoQSYpbY6rSjTdduNMl4SU0T/biIh6P/Aqm77o/9TfnWQfME3q+zzi/fXRAJUxb6Ze1y+uKmxZ+Y=@vger.kernel.org X-Gm-Message-State: AOJu0YyvjphLjhqF44F/wqsJXV139EU2K1OI808iguzew5Tu6MITmZWF wTmbkBnkatjOLralhnPbBWEjmRgMZEVtazQ0d59us6OfS+KfucJ8RejczrtyVuh5MQ== X-Gm-Gg: ATEYQzwFArzFgnkveRsFFGR+HCqi1MnJXrkp8UBeupYgxTpz2gY/WewcAv/k5QtEtRL SVbg0rmLbXxd8a07fIZFbXewHt2zveIa5zyqoChanpWcpapiqR2nZnikE3Kp+NIY0xIR4yxcHRE skTxFxFp8Sma5EEFxJ1Sm8AopGAOHri/Az2AgPwgoVbBs+MjUmmTz7vwkIWPxWN4I9lmbTCHVLw jsxnXJsT0meRT98+Xxyd6ZWisb0H3+fYposCNner0vX/R3pWmxQmMNmKLFG6VAFEO2+bkWGbham EDn+KyE//yw3iKDx2f0yL3z5K/sF4cm0JjhPstx7TNLBKVK5iTdkkASObeRUdioto5ZNhDV3oy1 iZfGLTzfHi+aenyc3lS44VbfbxtpNh61iCu7xz4gCzKdiVUrb5fm9jb0KdfSzd+yoq7nufahCXY V2ojFVa3j8gDdpF3z/qR6mxLvlzCNebU2j16yrD63uRTi+7azpLJtXJmyoEKsjZlBY6hMGrtdRK vFhIdBChI4= X-Received: by 2002:a05:7022:423:b0:119:e56b:91ec with SMTP id a92af1059eb24-12bfb75ee38mr560487c88.29.1775177525063; Thu, 02 Apr 2026 17:52:05 -0700 (PDT) Received: from dianders.sjc.corp.google.com ([2a00:79e0:2e7c:8:5db3:7542:a530:f43a]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2ca78df3b84sm3630074eec.5.2026.04.02.17.52.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Apr 2026 17:52:04 -0700 (PDT) From: Douglas Anderson To: Greg Kroah-Hartman , "Rafael J . Wysocki" , Danilo Krummrich , Alan Stern Cc: Robin Murphy , Leon Romanovsky , Paul Burton , Saravana Kannan , Alexander Lobakin , Eric Dumazet , Toshi Kani , Christoph Hellwig , Alexey Kardashevskiy , Johan Hovold , Douglas Anderson , ardb@kernel.org, broonie@kernel.org, catalin.marinas@arm.com, chleroy@kernel.org, david@kernel.org, driver-core@lists.linux.dev, kees@kernel.org, kevin.brodsky@arm.com, lenb@kernel.org, linux-acpi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-cxl@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, maddy@linux.ibm.com, maz@kernel.org, miko.lenczewski@arm.com, mpe@ellerman.id.au, npiggin@gmail.com, osalvador@suse.de, oupton@kernel.org, peterz@infradead.org, tglx@kernel.org, will@kernel.org, yangyicong@hisilicon.com, yeoreum.yun@arm.com Subject: [PATCH v3 9/9] driver core: Replace dev->offline + ->offline_disabled with DEV_FLAGs Date: Thu, 2 Apr 2026 17:49:55 -0700 Message-ID: <20260402174925.v3.9.I897d478b4a9361d79cd5073207c1062fd4d0d0e4@changeid> X-Mailer: git-send-email 2.53.0.1213.gd9a14994de-goog In-Reply-To: <20260403005005.30424-1-dianders@chromium.org> References: <20260403005005.30424-1-dianders@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In C, bitfields are not necessarily safe to modify from multiple threads without locking. Switch "offline" and "offline_disabled" over to the "flags" field so modifications are safe. Cc: Rafael J. Wysocki Cc: Toshi Kani Signed-off-by: Douglas Anderson Acked-by: Mark Brown --- Not fixing any known bugs; problem is theoretical and found by code inspection. Change is done somewhat manually and only lightly tested (mostly compile-time tested). Changes in v3: - New arch/arm64/kernel/cpufeature.c | 2 +- .../platforms/pseries/hotplug-memory.c | 4 ++-- drivers/acpi/scan.c | 3 ++- drivers/base/core.c | 19 ++++++++++--------- drivers/base/cpu.c | 4 ++-- drivers/base/memory.c | 2 +- include/linux/device.h | 9 ++++----- kernel/cpu.c | 4 ++-- 8 files changed, 24 insertions(+), 23 deletions(-) diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c index 32c2dbcc0c64..f6f7c35b7a93 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -4042,7 +4042,7 @@ static int enable_mismatched_32bit_el0(unsigned int c= pu) */ lucky_winner =3D cpu_32bit ? cpu : cpumask_any_and(cpu_32bit_el0_mask, cpu_active_mask); - get_cpu_device(lucky_winner)->offline_disabled =3D true; + set_bit(DEV_FLAG_OFFLINE_DISABLED, &get_cpu_device(lucky_winner)->flags); setup_elf_hwcaps(compat_elf_hwcaps); elf_hwcap_fixup(); pr_info("Asymmetric 32-bit EL0 support detected on CPU %u; CPU hot-unplug= disabled on CPU %u\n", diff --git a/arch/powerpc/platforms/pseries/hotplug-memory.c b/arch/powerpc= /platforms/pseries/hotplug-memory.c index b2f14db59034..d9a0a75ada46 100644 --- a/arch/powerpc/platforms/pseries/hotplug-memory.c +++ b/arch/powerpc/platforms/pseries/hotplug-memory.c @@ -213,9 +213,9 @@ static int dlpar_change_lmb_state(struct drmem_lmb *lmb= , bool online) return -EINVAL; } =20 - if (online && mem_block->dev.offline) + if (online && test_bit(DEV_FLAG_OFFLINE, &mem_block->dev.flags)) rc =3D device_online(&mem_block->dev); - else if (!online && !mem_block->dev.offline) + else if (!online && !test_bit(DEV_FLAG_OFFLINE, &mem_block->dev.flags)) rc =3D device_offline(&mem_block->dev); else rc =3D 0; diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index e8cdbdb46fdb..f2707b704468 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c @@ -122,7 +122,8 @@ bool acpi_scan_is_offline(struct acpi_device *adev, boo= l uevent) mutex_lock_nested(&adev->physical_node_lock, SINGLE_DEPTH_NESTING); =20 list_for_each_entry(pn, &adev->physical_node_list, node) - if (device_supports_offline(pn->dev) && !pn->dev->offline) { + if (device_supports_offline(pn->dev) && + !test_bit(DEV_FLAG_OFFLINE, &pn->dev->flags)) { if (uevent) kobject_uevent_env(&pn->dev->kobj, KOBJ_CHANGE, envp); =20 diff --git a/drivers/base/core.c b/drivers/base/core.c index a87bd40499b6..63d724ece384 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -2789,7 +2789,7 @@ static ssize_t online_show(struct device *dev, struct= device_attribute *attr, bool val; =20 device_lock(dev); - val =3D !dev->offline; + val =3D !test_bit(DEV_FLAG_OFFLINE, &dev->flags); device_unlock(dev); return sysfs_emit(buf, "%u\n", val); } @@ -2914,7 +2914,7 @@ static int device_add_attrs(struct device *dev) if (error) goto err_remove_type_groups; =20 - if (device_supports_offline(dev) && !dev->offline_disabled) { + if (device_supports_offline(dev) && !test_bit(DEV_FLAG_OFFLINE_DISABLED, = &dev->flags)) { error =3D device_create_file(dev, &dev_attr_online); if (error) goto err_remove_dev_groups; @@ -4179,7 +4179,8 @@ static int device_check_offline(struct device *dev, v= oid *not_used) if (ret) return ret; =20 - return device_supports_offline(dev) && !dev->offline ? -EBUSY : 0; + return device_supports_offline(dev) && + !test_bit(DEV_FLAG_OFFLINE, &dev->flags) ? -EBUSY : 0; } =20 /** @@ -4197,7 +4198,7 @@ int device_offline(struct device *dev) { int ret; =20 - if (dev->offline_disabled) + if (test_bit(DEV_FLAG_OFFLINE_DISABLED, &dev->flags)) return -EPERM; =20 ret =3D device_for_each_child(dev, NULL, device_check_offline); @@ -4206,13 +4207,13 @@ int device_offline(struct device *dev) =20 device_lock(dev); if (device_supports_offline(dev)) { - if (dev->offline) { + if (test_bit(DEV_FLAG_OFFLINE, &dev->flags)) { ret =3D 1; } else { ret =3D dev->bus->offline(dev); if (!ret) { kobject_uevent(&dev->kobj, KOBJ_OFFLINE); - dev->offline =3D true; + set_bit(DEV_FLAG_OFFLINE, &dev->flags); } } } @@ -4237,11 +4238,11 @@ int device_online(struct device *dev) =20 device_lock(dev); if (device_supports_offline(dev)) { - if (dev->offline) { + if (test_bit(DEV_FLAG_OFFLINE, &dev->flags)) { ret =3D dev->bus->online(dev); if (!ret) { kobject_uevent(&dev->kobj, KOBJ_ONLINE); - dev->offline =3D false; + clear_bit(DEV_FLAG_OFFLINE, &dev->flags); } } else { ret =3D 1; @@ -4715,7 +4716,7 @@ static int device_attrs_change_owner(struct device *d= ev, kuid_t kuid, if (error) return error; =20 - if (device_supports_offline(dev) && !dev->offline_disabled) { + if (device_supports_offline(dev) && !test_bit(DEV_FLAG_OFFLINE_DISABLED, = &dev->flags)) { /* Change online device attributes of @dev to @kuid/@kgid. */ error =3D sysfs_file_change_owner(kobj, dev_attr_online.attr.name, kuid, kgid); diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c index 875abdc9942e..e4e6a399def4 100644 --- a/drivers/base/cpu.c +++ b/drivers/base/cpu.c @@ -422,8 +422,8 @@ int register_cpu(struct cpu *cpu, int num) cpu->dev.id =3D num; cpu->dev.bus =3D &cpu_subsys; cpu->dev.release =3D cpu_device_release; - cpu->dev.offline_disabled =3D !cpu->hotpluggable; - cpu->dev.offline =3D !cpu_online(num); + assign_bit(DEV_FLAG_OFFLINE_DISABLED, &cpu->dev.flags, !cpu->hotpluggable= ); + assign_bit(DEV_FLAG_OFFLINE, &cpu->dev.flags, !cpu_online(num)); cpu->dev.of_node =3D of_get_cpu_node(num, NULL); cpu->dev.groups =3D common_cpu_attr_groups; if (cpu->hotpluggable) diff --git a/drivers/base/memory.c b/drivers/base/memory.c index a3091924918b..7f42727dde81 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -697,7 +697,7 @@ static int __add_memory_block(struct memory_block *memo= ry) memory->dev.id =3D memory->start_section_nr / sections_per_block; memory->dev.release =3D memory_block_release; memory->dev.groups =3D memory_memblk_attr_groups; - memory->dev.offline =3D memory->state =3D=3D MEM_OFFLINE; + assign_bit(DEV_FLAG_OFFLINE, &memory->dev.flags, memory->state =3D=3D MEM= _OFFLINE); =20 ret =3D device_register(&memory->dev); if (ret) { diff --git a/include/linux/device.h b/include/linux/device.h index f6ca067bacca..fd53aa04cad9 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -484,6 +484,8 @@ struct device_physical_location { * architecture supports non-coherent devices. * @DEV_FLAG_OF_NODE_REUSED: Set if the device-tree node is shared with an * ancestor device. + * @DEV_FLAG_OFFLINE_DISABLED: If set, the device is permanently online. + * @DEV_FLAG_OFFLINE: Set after successful invocation of bus type's .offli= ne(). */ enum struct_device_flags { DEV_FLAG_READY_TO_PROBE, @@ -494,6 +496,8 @@ enum struct_device_flags { DEV_FLAG_STATE_SYNCED, DEV_FLAG_DMA_COHERENT, DEV_FLAG_OF_NODE_REUSED, + DEV_FLAG_OFFLINE_DISABLED, + DEV_FLAG_OFFLINE, }; =20 /** @@ -571,8 +575,6 @@ enum struct_device_flags { * should be set by the subsystem / bus driver that discovered * the device. * - * @offline_disabled: If set, the device is permanently online. - * @offline: Set after successful invocation of bus type's .offline(). * @flags: DEV_FLAG_XXX flags. Use atomic bitfield operations to modify. * * At the lowest level, every device in a Linux system is represented by an @@ -677,9 +679,6 @@ struct device { =20 enum device_removable removable; =20 - bool offline_disabled:1; - bool offline:1; - unsigned long flags; }; =20 diff --git a/kernel/cpu.c b/kernel/cpu.c index bc4f7a9ba64e..15a873ad8025 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -2639,7 +2639,7 @@ static void cpuhp_offline_cpu_device(unsigned int cpu) { struct device *dev =3D get_cpu_device(cpu); =20 - dev->offline =3D true; + set_bit(DEV_FLAG_OFFLINE, &dev->flags); /* Tell user space about the state change */ kobject_uevent(&dev->kobj, KOBJ_OFFLINE); } @@ -2648,7 +2648,7 @@ static void cpuhp_online_cpu_device(unsigned int cpu) { struct device *dev =3D get_cpu_device(cpu); =20 - dev->offline =3D false; + clear_bit(DEV_FLAG_OFFLINE, &dev->flags); /* Tell user space about the state change */ kobject_uevent(&dev->kobj, KOBJ_ONLINE); } --=20 2.53.0.1213.gd9a14994de-goog