From mboxrd@z Thu Jan 1 00:00:00 1970 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 C36B923E358 for ; Fri, 3 Apr 2026 00:51:33 +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=1775177496; cv=none; b=bEhpmzCmDtUUoVN4er8IuK2y7tmTCdtMAskySiSCJnfSfZJugFHs2FxicSmCSfTTvvk42WZXd00CTj1WHL+tkOtxBAVAtAz/x7sR2p7+Jw34n6iV9aVugnyJo75Jyv+c3Bpj35gNPsALiXWUXH9mrIbYpBozdY6+ZxvhNLMX6Vw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775177496; c=relaxed/simple; bh=MLU3H0vT5l7RkyqJ4axMsnZCk3EEo/xxuxHDjIkeDXs=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=HPmBqcVZbIDNE1tDs9+t/YPyq1IxccsXL6CaA3KtrlDa9c7HfdpBeR4Q2uhmelSy6maesXBCUB9Jy/Uq+vTOYso0TBGBgEaV5APFyLLhzmryryJEp4e9vpHaaenq2+BMzFHg8iTnwH1ZN3fOfTx1n0q06N2+iiN9z1gs758DBtI= 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=U6fb1bYX; 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="U6fb1bYX" Received: by mail-dy1-f171.google.com with SMTP id 5a478bee46e88-2cc1534e026so206285eec.1 for ; Thu, 02 Apr 2026 17:51:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1775177493; x=1775782293; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Lb2HYWEQxB/om4yhyjxjNip9666HK8Fi8TGkiu9j7VQ=; b=U6fb1bYXSFh8hkp9cNXTZqV0oKW2o3WGWUrIJCFeMAoeuwJh4rs88N+4Ft/69+Akbe yc0JovpEZfrW8+QvEM9WOWM560NZi8j+ES3IivhSWxA+G8l1WPLEvjINJoULkNm/le+a UGkWXcH+Wlj6BoSy9+6OKmwemoOa1Y2eiqXdY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775177493; x=1775782293; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Lb2HYWEQxB/om4yhyjxjNip9666HK8Fi8TGkiu9j7VQ=; b=DlM6NdPn7Ez0UxR3xjIRTnUrlkOmzc9oKnqcUPlNWyn7l6FsF98qhUnoPpGZBgjVyA FvczE74UlJdPgXonRN10998maTZC43me8iKuV7CZerqPL/itKq9FAMLun8tDaeskGe34 slQUxiQHU8tHV5IXjfBwwA4zMHXVoWFvNRLTT23erVT+F8IK0FYVcuFlPqmqjIa0ko/0 h7/JgObRcZ5PVGL/NTc2eVn0SMEUCvz9BbnlexN+LNzAUJs8PjwPhokhewpyU10HEkSI 9jA5rfFOFTnRqciD1mLZGLrZvZuCCRzkAQ9p/E/fhG4lZ5IJB2aIt0ysVCPQ2P394KAq tJTw== X-Forwarded-Encrypted: i=1; AJvYcCWAsMt7HXUW7p3kxQNyme8525+ZOnR0zZtclGQBOK4Ta23bzPzIolACO7WhxpPu8lDg98Izrv8=@vger.kernel.org X-Gm-Message-State: AOJu0YwKjbUoVmWBddjNTE56YQcy77oUPLJpSZR0emS3pWAfUhKSDxpU GYsQnVE3vyiEw3WmaSO/vZqYY+Al6lFEJ2Rp1XoeWTvP4fEj6L8ks3RpVuaQgTpCtA== X-Gm-Gg: AeBDietzk/MslwrUlLFh6wKcIf2SQ8WLP6I0p902XLWHuzGTdAl4cNZhoexM/rj04ok 1LFd8RAvPMKtMSCyoH1jOl3LIyKxzROyCF+vsIZVBvmi05HjtbXjQj9z4pcqcc4LS35PAEdJRnx LRGujuYo0WXJj4NIHl0BJZ+bVRqBAhQLCgkpti5UPgL+ipJMXNWCmHkFPjCyB//GBw2Rsqdk7AP 0ioUGLN4XHKM8GkFhNN2SkhS2lWZkHVdTSwZ82JWs+cwOx/QVWmalx8QN6V7BPObtZAsjxHN7x4 C1BtXHijDw+IwJTWVkJkyOy+ihtis9JkBZfTewOeEzBA3qVO4W3eM0oCXX/ZmcdzT+cqB7RgF97 hA7T/sVba6qXkRqA5I/U8bg/DejyDNsdelcD83qF0YgvFbdgfKUwqZjkLNc+j10rZ5b2WZdwhLa sHoB1Ru4zr7n4REOXNpOjpJFJv3JND5xgPGek74uBnECQTeB/0gqD7+4jxj3tNGpwLTmUYOWfaJ wEBignMSucPKwSnw/uxwA== X-Received: by 2002:a05:693c:3009:b0:2c1:558c:16f7 with SMTP id 5a478bee46e88-2cbf950392cmr655589eec.6.1775177492780; Thu, 02 Apr 2026 17:51:32 -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.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Apr 2026 17:51:31 -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 , Frank.Li@kernel.org, Jason Gunthorpe , alex@ghiti.fr, alexander.stein@ew.tq-group.com, andre.przywara@arm.com, andrew@codeconstruct.com.au, andrew@lunn.ch, andriy.shevchenko@linux.intel.com, aou@eecs.berkeley.edu, ardb@kernel.org, astewart@tektelic.com, bhelgaas@google.com, brgl@kernel.org, broonie@kernel.org, catalin.marinas@arm.com, chleroy@kernel.org, davem@davemloft.net, david@kernel.org, devicetree@vger.kernel.org, dmaengine@vger.kernel.org, driver-core@lists.linux.dev, gbatra@linux.ibm.com, gregory.clement@bootlin.com, hkallweit1@gmail.com, iommu@lists.linux.dev, jirislaby@kernel.org, joel@jms.id.au, joro@8bytes.org, kees@kernel.org, kevin.brodsky@arm.com, kuba@kernel.org, lenb@kernel.org, lgirdwood@gmail.com, linux-acpi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-aspeed@lists.ozlabs.org, linux-cxl@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, linux-mm@kvack.org, linux-pci@vger.kernel.org, linux-riscv@lists.infradead.org, linux-serial@vger.kernel.org, linux-snps-arc@lists.infradead.org, linux-usb@vger.kernel.org, linux@armlinux.org.uk, linuxppc-dev@lists.ozlabs.org, m.szyprowski@samsung.com, maddy@linux.ibm.com, mani@kernel.org, maz@kernel.org, miko.lenczewski@arm.com, mpe@ellerman.id.au, netdev@vger.kernel.org, npiggin@gmail.com, osalvador@suse.de, oupton@kernel.org, pabeni@redhat.com, palmer@dabbelt.com, peter.ujfalusi@gmail.com, peterz@infradead.org, pjw@kernel.org, robh@kernel.org, sebastian.hesselbarth@gmail.com, tglx@kernel.org, tsbogend@alpha.franken.de, vgupta@kernel.org, vkoul@kernel.org, will@kernel.org, willy@infradead.org, yangyicong@hisilicon.com, yeoreum.yun@arm.com Subject: [PATCH v3 0/9] driver core: Fix some race conditions Date: Thu, 2 Apr 2026 17:49:46 -0700 Message-ID: <20260403005005.30424-1-dianders@chromium.org> X-Mailer: git-send-email 2.53.0.1213.gd9a14994de-goog Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The main goal of this series is to fix the observed bug talked about in the first patch ("driver core: Don't let a device probe until it's ready"). That patch fixes a problem that has been observed in the real world and could land even if the rest of the patches are found unacceptable or need to be spun. That said, during patch review Danilo correctly pointed out that many of the bitfield accesses in "struct device" are unsafe. I added a bunch of patches in the series to address each one. Danilo said he's most worried about "can_match", so I put that one first. After that, I tried to transition bitfields to flags in reverse order to when the bitfield was added. Even if transitioning from bitfields to flags isn't truly needed for correctness, it seems silly (and wasteful of space in struct device) to have some in bitfields and some as flags. Thus I didn't spend time for each bitfield showing that it's truly needed for correctness. Transition was done semi manually. Presumably someone skilled at coccinelle could do a better job, but I just used sed in a heavy- handed manner and then reviewed/fixed the results, undoing anything my script got wrong. My terrible/ugly script was: var=can_match caps="${var^^}" for f in $(git grep -l "[>\.]${var}[^1-9_a-zA-Z\[]"); do echo $f sed -i~ -e "s/\([a-zA-Z_0-9\.>()-][a-zA-Z_0-9\.>()-]*\)->${var} = true/set_bit(DEV_FLAG_${caps}, \&\\1->flags)/" "$f" sed -i~ -e "s/\([a-zA-Z_0-9\.>()-][a-zA-Z_0-9\.>()-]*\)\.${var} = true/set_bit(DEV_FLAG_${caps}, \&\\1.flags)/" "$f" sed -i~ -e "s/\([a-zA-Z_0-9\.>()-][a-zA-Z_0-9\.>()-]*\)->${var} = false/clear_bit(DEV_FLAG_${caps}, \&\\1->flags)/" "$f" sed -i~ -e "s/\([a-zA-Z_0-9\.>()-][a-zA-Z_0-9\.>()-]*\)\.${var} = false/clear_bit(DEV_FLAG_${caps}, \&\\1.flags)/" "$f" sed -i~ -e "s/\([a-zA-Z_0-9\.>()-][a-zA-Z_0-9\.>()-]*\)->${var} = \([^;]*\)/assign_bit(DEV_FLAG_${caps}, \&\\1->flags, \\2)/" "$f" sed -i~ -e "s/\([a-zA-Z_0-9\.>()-][a-zA-Z_0-9\.>()-]*\)\.${var} = \([^;]*\)/assign_bit(DEV_FLAG_${caps}, \&\\1.flags, \\2)/" "$f" sed -i~ -e "s/\([a-zA-Z_0-9\.>()-][a-zA-Z_0-9\.>()-]*\)->${var}\([^1-9_a-zA-Z\[]\)/test_bit(DEV_FLAG_${caps}, \&\\1->flags)\\2/" "$f" sed -i~ -e "s/\([a-zA-Z_0-9\.>()-][a-zA-Z_0-9\.>()-]*\)\.${var}\([^1-9_a-zA-Z\[]\)/test_bit(DEV_FLAG_${caps}, \&\\1.flags)\\2/" "$f" done NOTE: one potentially "controversial" choice I made in some patches was to always reserve a flag ID even if a flag is only used under certain CONFIG_ settings. This is a change from how things were before. Keeping the numbering consistent and allowing easy compile-testing of both CONFIG settings seemed worth it, especially since it won't take up any extra space until we've added a lot more flags. I only marked the first patch as a "Fix" since it is the only one fixing observed problems. Other patches could be considered fixes too if folks want. I tested the first patch in the series backported to kernel 6.6 on the Pixel phone that was experiencing the race. I added extra printouts to make sure that the problem was hitting / addressed. The rest of the patches are tested with allmodconfig with arm32, arm64, ppc, and x86. I boot tested on an arm64 Chromebook running mainline. 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 Douglas Anderson (9): driver core: Don't let a device probe until it's ready driver core: Replace dev->can_match with DEV_FLAG_CAN_MATCH driver core: Replace dev->dma_iommu with DEV_FLAG_DMA_IOMMU driver core: Replace dev->dma_skip_sync with DEV_FLAG_DMA_SKIP_SYNC driver core: Replace dev->dma_ops_bypass with DEV_FLAG_DMA_OPS_BYPASS driver core: Replace dev->state_synced with DEV_FLAG_STATE_SYNCED driver core: Replace dev->dma_coherent with DEV_FLAG_DMA_COHERENT driver core: Replace dev->of_node_reused with DEV_FLAG_OF_NODE_REUSED driver core: Replace dev->offline + ->offline_disabled with DEV_FLAGs 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/kernel/cpufeature.c | 2 +- arch/arm64/mm/dma-mapping.c | 2 +- arch/mips/mm/dma-noncoherent.c | 2 +- arch/powerpc/kernel/dma-iommu.c | 8 +- .../platforms/pseries/hotplug-memory.c | 4 +- arch/riscv/mm/dma-noncoherent.c | 2 +- drivers/acpi/scan.c | 3 +- drivers/base/core.c | 55 +++++++----- drivers/base/cpu.c | 4 +- drivers/base/dd.c | 28 +++++-- drivers/base/memory.c | 2 +- drivers/base/pinctrl.c | 2 +- drivers/base/platform.c | 2 +- drivers/dma/ti/k3-udma-glue.c | 6 +- drivers/dma/ti/k3-udma.c | 6 +- drivers/iommu/dma-iommu.c | 9 +- drivers/iommu/iommu.c | 5 +- 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 | 83 ++++++++++--------- include/linux/dma-map-ops.h | 6 +- include/linux/dma-mapping.h | 2 +- include/linux/iommu-dma.h | 4 +- kernel/cpu.c | 4 +- kernel/dma/mapping.c | 16 ++-- mm/hmm.c | 2 +- 37 files changed, 178 insertions(+), 143 deletions(-) -- 2.53.0.1213.gd9a14994de-goog