From nobody Sat Jul 25 06:09:17 2026 Received: from mail-ej1-f73.google.com (mail-ej1-f73.google.com [209.85.218.73]) (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 112C62D9ECA for ; Fri, 17 Jul 2026 02:41:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784256107; cv=none; b=RkGVtz8O+oPt+Yq3en3mdtwUqbzWeIedvO7RH7hztDXhFPU4PiaSBZ2bOxji6MJPVXvU2HPqnDYh9jkNiQUAf/x4LZ5PBYr8IzY/tDsWiucfWMD4bMbKcZcvMhA3LEsrEOud5DyW7fguyi06zIDNUB9ERyVjQ+ZZk8q9NDN6mCM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784256107; c=relaxed/simple; bh=O/Swl4p41vnXyf3QyhUiXUdXKMg+dvofMUMHqzzQhEI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=eCVvhn21neHGNPIFEzq4/wM07yP/VV8eQRkAppRlzbEJSKkQIS1knlmGJDNa9uH1qNX4nYrW6Mpzd3ULd7b+Wcr//OZ8ZyVtnj/f3rcC3RdvVkUZRIka1HURqMB2agHRwSIzUqaaVns71D6zkxMEsj0JXRrNIkRmfILVmIV66vk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--tarunsahu.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=m61VX7HW; arc=none smtp.client-ip=209.85.218.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--tarunsahu.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="m61VX7HW" Received: by mail-ej1-f73.google.com with SMTP id a640c23a62f3a-c16740eb587so239581666b.1 for ; Thu, 16 Jul 2026 19:41:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1784256103; x=1784860903; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=DbIYBGDrxSWIIJNYURi+rPKwz3J+f2cnmzz2JP395M0=; b=m61VX7HWp/9Ncnpbc1SVBIMJGvlGvQFk0Fo/6xQswCj83wbh/dWYBTlyATyDQMBx/U Txs5u/v3E1e/qz81nGq+011hOe8lZF0ED9nD2+M/+SXqnhGxHHZ4LpmKtsUaFVFLwWAF /bJIuvdCDV0zqhgPiG/U6jOQiwWsqMxm7maTcJO0hUxo3w3VtouP05KgH+Nw25/bAJtR JvwvHMgVivuM+FOUbGzBuXuqt0vjsaomUcNNErp7QEmyNpzQSDoc85AkYAgIhvcUPrZt vBiwRJs0tYY/Bg//dFrcn/koL+NIBzWNLe9eFaaUXdG2IMx/vHyIn549rE4GueWCdO3h HxXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784256103; x=1784860903; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=DbIYBGDrxSWIIJNYURi+rPKwz3J+f2cnmzz2JP395M0=; b=RUf+eubm+XFqkKoEIWhax/itmYshYDgZ0fLaAO6Ewmz1wjvLAbF6Ohw2e1Ks4xkSoV ySBTPG6GnjM5Ihwl1ynedcjm4OdqJzpAdCi9XVUGj99juFQpeT6PHX54hfvqZJ+T3jYh pSwlRoeEKIutjW0srW3yeccGvWo3aaLJF4DIGXWPDvJDcloZpM8Qn2VX3U20RmJAU7Qk CeGvPimJiOjxTE6SGxNkXWEtpiuRVHLI2BhpUwF88ngh+QGdCXx7wOxpZ72hsXsB0Uyc SC6QV/MBsNRIasozlThok+0ysdWtEwTU1r3UbFSqzmNhaIjO10bjHJTiiJWzRTOTRhU8 NzmQ== X-Forwarded-Encrypted: i=1; AHgh+RoknqPGoFowtAHhmg97jqZSXrFQ1zrqoS+r2tRCzIwSczmwb5wQC7GUXsx5Du0oLyWOb7EpNi0MagW/ztA=@vger.kernel.org X-Gm-Message-State: AOJu0YyTiTIEGS4UgeNanl5jnr0uQIJefo4q6anu1ARsUXpfNZhU8a5F q6EUgc6KBRR5CLmh84h/85WFeED6PT/QZCmf+7b/wuoO+fgTLSE8SiINKTlPYrwjx+zInGEVDgy Iz2t+xU4LwKw5tXWEKg== X-Received: from ejbse11.prod.google.com ([2002:a17:906:ce4b:b0:c12:6d92:3b02]) (user=tarunsahu job=prod-delivery.src-stubby-dispatcher) by 2002:a17:907:1b0d:b0:c12:67e9:bf2b with SMTP id a640c23a62f3a-c16b4799b95mr19191766b.40.1784256102996; Thu, 16 Jul 2026 19:41:42 -0700 (PDT) Date: Thu, 16 Jul 2026 23:04:05 +0000 In-Reply-To: <20260716230411.2767394-1-tarunsahu@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260716230411.2767394-1-tarunsahu@google.com> X-Mailer: git-send-email 2.55.0.229.g6434b31f56-goog Message-ID: <20260716230411.2767394-2-tarunsahu@google.com> Subject: [PATCH v19 1/7] device_core: rely on put_device to free dev->p From: Tarun Sahu To: Shuah Khan , Danilo Krummrich , Bjorn Helgaas , Greg Kroah-Hartman , "Martin K. Petersen" , "James E.J. Bottomley" , Jonathan Corbet , "Rafael J. Wysocki" Cc: bvanassche@acm.org, john.g.garry@oracle.com, mlombard@redhat.com, loberman@redhat.com, mclapinski@google.com, dmatlack@google.com, driver-core@lists.linux.dev, linux-pci@vger.kernel.org, Pasha Tatashin , jordanrichards@google.com, souravsgl@google.com, stuart.w.hayes@gmail.com, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, emilne@redhat.com, jmeneghi@redhat.com, linux-scsi@vger.kernel.org, Tarun Sahu , David Jeffery Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" device_add allocate private_data for device and assigns to dev->p. If device_add fails in later steps of the function, it cleans up this dev->p which is not necessary because In the next call, put_device free it anyway (if reference to the device is 0 which will be unless someone concurrently get the reference to this device). This avoids unnecessary races introduced in system. After device is added in device_kset->list by device_add and later steps in the device_add function failures occur, it will free dev->p manually, while in between there might be a user of device_kset->list will take reference to the device just added by device_add. and might try to access dev->p. So relying on put_device to free dev->p prevents such problem. Signed-off-by: Tarun Sahu Signed-off-by: David Jeffery --- drivers/base/core.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/base/core.c b/drivers/base/core.c index 4d026682944f..76ba02c26aa5 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -2614,6 +2614,7 @@ static void device_release(struct kobject *kobj) struct device *dev =3D kobj_to_dev(kobj); struct device_private *p =3D dev->p; =20 + dev->p =3D NULL; /* * Some platform devices are driven without driver attached * and managed resources may have been acquired. Make sure @@ -3824,8 +3825,6 @@ int device_add(struct device *dev) parent_error: put_device(parent); name_error: - kfree(dev->p); - dev->p =3D NULL; goto done; } EXPORT_SYMBOL_GPL(device_add); --=20 2.55.0.229.g6434b31f56-goog From nobody Sat Jul 25 06:09:17 2026 Received: from mail-ed1-f74.google.com (mail-ed1-f74.google.com [209.85.208.74]) (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 5B1F633B6C4 for ; Fri, 17 Jul 2026 02:41:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784256108; cv=none; b=A/1dp0l4+zm3iYTj0qRsx/XJGkTP3VJeuGN0Aj/cHfmDzOcp2W2kbeEBk3sg3saN7/oP9j/GhOr+NtyxynyylodzNX6VvIUsYbYDzMl5JEOyspPNXyiUtMqSqCA0uRQZsFKjrB+jgsyyerW83MLRcXUYyD4sRmCB12Yxn7P2Cc4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784256108; c=relaxed/simple; bh=MaTtIurVU/bnO1ZT5CRFSCEj/7sWYmboGDsIvXo0XIE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=QlfPjKjHegH5x1Nk07vnZ9F/326nGJa38eqPDRXFziHfRILyzV0GXVKnYKILkWJhJavotMsGc1Ow2Kpi7g/AcsVXTWrx6+hK+roDz7Y2ueOWCnybIuoO/xac8HswwQ0cryX7tA3GK+CfejwDY1q0B0RVpYLf1gUQA2mGiHV1l2U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--tarunsahu.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=t7Nz91jS; arc=none smtp.client-ip=209.85.208.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--tarunsahu.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="t7Nz91jS" Received: by mail-ed1-f74.google.com with SMTP id 4fb4d7f45d1cf-698accdb6beso6662444a12.0 for ; Thu, 16 Jul 2026 19:41:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1784256104; x=1784860904; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=lxDFoRfGjuVIhbnGliVFSK9UCSyMCMGPz0ptJpXcFDo=; b=t7Nz91jSu88+8CYTtgiuZuW9ug1i5eIK4israPGJRl692KgL6IGofsaBuR++cyD3ZO vkwEYFi0CBdZsbpASx5ZpA4ifqon2iFwKDhjNTkpowMFn6CczqLeZnZm5cXZaD+v9xHs lPkvOQPqAk1R4zF9s4V8/MqTiYkaSoX1+7DHGA/swgEcwBD7PLWiB8oRFpUv1oCmHpK+ +M7eyovL8Ftt3vsanR0mB81tFxMwgyzOdb1E11Uv97PxDDpKBy5YQmt6ekm/pcKiM9eN TgKmuGRw7bDYIcDuta/Z/RUmiesKKR5McndMRccfYawyUn78jZX+T3M+yB/bn4oWVkQV Yh2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784256104; x=1784860904; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=lxDFoRfGjuVIhbnGliVFSK9UCSyMCMGPz0ptJpXcFDo=; b=gZSI84f1M9J1irnT9gj24TnYzhh27YGsx+ytV7VdTor+kM818VYEO2Me8Yn3igxvRK 8muOsL3O107YnDifbUp25jfcLAX+QyN8a5lxLPmRJEW80+YxWpFcXmrAKdhx+dAaGcK6 PnIBQEw+QYDgNVOlKZ39rcGC0EWXlnGgVvtOilXOV8XxwG9+ZPKFFfmwPC+LmKb/mqpz +mdcsbV281I0S1W3uJ7Ek8MkEscsPqPz9s2JIRGP1ILpdHZI+BYSaIAv3HSmPdJqW858 BcUKfMBSV4J8p6DxREttEyptmkgDwpnVNWyS687BSSfNWoWZBwONOE18beBgYMhSaJkr 7UqQ== X-Forwarded-Encrypted: i=1; AHgh+RoU2oB/xkZXdEPrlKW4u52mISyn20QJC403N/GFrlAsfuzSER9Id61i6B3JSUtMCQEFtxHJT2s1XVb7VpQ=@vger.kernel.org X-Gm-Message-State: AOJu0YwpEWBJ/8ZdtQjchNpt5XO/JzEYJOprlkBApwMfeLbykzOiheNh PPS6GMc/7498qGi4X2QwQ21bJI8KBi3Go4xoZPhxfkTyemU62y+wdZIV111fPJah+QtxZ/lK4YC eENUluS6JSTlLKGvJkQ== X-Received: from ejcev5.prod.google.com ([2002:a17:907:29c5:b0:c16:a4bc:757f]) (user=tarunsahu job=prod-delivery.src-stubby-dispatcher) by 2002:a17:906:c146:b0:c16:6dac:a015 with SMTP id a640c23a62f3a-c16b46f14b4mr17436966b.29.1784256104296; Thu, 16 Jul 2026 19:41:44 -0700 (PDT) Date: Thu, 16 Jul 2026 23:04:06 +0000 In-Reply-To: <20260716230411.2767394-1-tarunsahu@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260716230411.2767394-1-tarunsahu@google.com> X-Mailer: git-send-email 2.55.0.229.g6434b31f56-goog Message-ID: <20260716230411.2767394-3-tarunsahu@google.com> Subject: [PATCH v19 2/7] driver core: Prevent device_add() during system shutdown From: Tarun Sahu To: Shuah Khan , Danilo Krummrich , Bjorn Helgaas , Greg Kroah-Hartman , "Martin K. Petersen" , "James E.J. Bottomley" , Jonathan Corbet , "Rafael J. Wysocki" Cc: bvanassche@acm.org, john.g.garry@oracle.com, mlombard@redhat.com, loberman@redhat.com, mclapinski@google.com, dmatlack@google.com, driver-core@lists.linux.dev, linux-pci@vger.kernel.org, Pasha Tatashin , jordanrichards@google.com, souravsgl@google.com, stuart.w.hayes@gmail.com, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, emilne@redhat.com, jmeneghi@redhat.com, linux-scsi@vger.kernel.org, Tarun Sahu , David Jeffery Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In Async device shutdown, device_kset->list lock is released to handle asynchronisation and hold again to get entry from device_kset->list. Which will leave window when device_add can try to add the device to device_kset list and temper with ongoing shutdown process. New added device can be async type or sync type and might also introduce new dependency which can cause device_shutdown path to deadlock. S is waiting C to finish but C is never scheduled as it was added recently from device_add path. And C can only be scheduled when main loops continue to reach to C which is waiting on S. So, When a system enters shutdown (SYSTEM_HALT, SYSTEM_POWER_OFF, or SYSTEM_RESTART), new devices should not be allowed to be added. Adding system_state check (system_is_shutting_down()) to avoid device_add incase of these states of the system. While device_add() performs an initial check of system_is_shutting_down(), a race window exists between this initial check and kobject_add(), during which device_shutdown() may already be scanning devices_kset->list. If device_shutdown() passes the device after kobject_add() registers it onto devices_kset->list, device_add() would otherwise complete device initialization and driver matching, leaving an active device running after system shutdown finishes. Fix this TOCTOU race by re-checking system_is_shutting_down() under devices_kset->list_lock right after kobject_add(). Signed-off-by: Tarun Sahu Signed-off-by: David Jeffery --- drivers/base/core.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/drivers/base/core.c b/drivers/base/core.c index 76ba02c26aa5..78b90326addb 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -47,6 +47,22 @@ static bool fw_devlink_drv_reg_done; static bool fw_devlink_best_effort; static struct workqueue_struct *device_link_wq; =20 +/** + * system_is_shutting_down - Check if system state is not active. + * + * When system state is not active and in shutdown state, new devices + * should not be allowed to be added. + * + * If system_state is SYSTEM_HALT || SYSTEM_POWER_OFF || SYSTEM_RESTART + * this function will return true. + */ +static inline bool system_is_shutting_down(void) +{ + return system_state =3D=3D SYSTEM_HALT || + system_state =3D=3D SYSTEM_POWER_OFF || + system_state =3D=3D SYSTEM_RESTART; +} + /** * __fwnode_link_add - Create a link between two fwnode_handles. * @con: Consumer end of the link. @@ -3650,6 +3666,11 @@ int device_add(struct device *dev) if (!dev) goto done; =20 + if (unlikely(system_is_shutting_down())) { + error =3D -ESHUTDOWN; + goto done; + } + if (!dev->p) { error =3D device_private_init(dev); if (error) @@ -3699,6 +3720,18 @@ int device_add(struct device *dev) goto Error; } =20 + /* + * Check system_state again under list_lock to prevent a TOCTOU race + * where device_shutdown() runs concurrently and misses this device. + */ + spin_lock(&devices_kset->list_lock); + if (unlikely(system_is_shutting_down())) { + spin_unlock(&devices_kset->list_lock); + error =3D -ESHUTDOWN; + goto ShutdownError; + } + spin_unlock(&devices_kset->list_lock); + /* notify platform of device entry */ device_platform_notify(dev); =20 @@ -3818,6 +3851,7 @@ int device_add(struct device *dev) attrError: device_platform_notify_remove(dev); kobject_uevent(&dev->kobj, KOBJ_REMOVE); + ShutdownError: glue_dir =3D get_glue_dir(dev); kobject_del(&dev->kobj); Error: --=20 2.55.0.229.g6434b31f56-goog From nobody Sat Jul 25 06:09:17 2026 Received: from mail-wr1-f73.google.com (mail-wr1-f73.google.com [209.85.221.73]) (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 A31EA33F59E for ; Fri, 17 Jul 2026 02:41:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784256110; cv=none; b=ks+tj0fgjyxPg/Ie532loc57LA1fuxIoyCxQNheQ5kDKn2yP9XaxRuRe+eh6hWrwuM+WyaSbO7oZwrSbwE/TW8bz8j8Lh2ii9kmTxAy6JLiJZTSPju6S3c2len7J3q+G/Aakn95znksYVNhF6fFm+d5ukha+u9J7y+gFA2wWM98= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784256110; c=relaxed/simple; bh=84Dxy+IQXZ+Io/tsnEE56Nrw1ZiDroBdIIccATE0oog=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ogfLZGPzthhr69z3DAaRhasYip6kEd0yeH+THvhOTM4IYtB3p+H3832LpvDXbE/IpkOfsdbI61Q5/fs+A2nfulmbsb09Gtde66o7jO2huDliCTNNaLGcMe2P1+/vvJaxIAap5US9NSjg49CsIfwWNcN3ifwzOp6ensATNrmgVNw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--tarunsahu.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=aV0NDUUa; arc=none smtp.client-ip=209.85.221.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--tarunsahu.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="aV0NDUUa" Received: by mail-wr1-f73.google.com with SMTP id ffacd0b85a97d-47e81aca584so3792025f8f.2 for ; Thu, 16 Jul 2026 19:41:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1784256106; x=1784860906; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=v9ZzsR0v39hzEb6iXWVS0iiD5j1ThrMppOubfeQ9NoI=; b=aV0NDUUalJEVRuA4IO9jSbMXoB0AMDr5fprzU6ZVzx4b0dY+r1xs0R2RMJ3nK2BLYi /LNT3fkqTSK++WOOs1JSFn2RtDIq2rxcJDu+GJH0bfZTT/lBeaiCShtFuEKGKYLPhVkK mLeU+xBayM3jnah645b69Q1tO3LRPoCAY9UchHrPN8ZQWH7+uSj7+Mv7Jt4uSdZRzY9e k4lB3izQeu0KJ8QPRegQPmPvDN7AhSPzpZeiS84voDXN/PfS9SGu/vJ6eDc1hpHH3TGw l8vhDj+GzqJ1lWlj4GYjBPyT7IGP4Oi3FJ+CwMM1F5gMihaG+eUxF8nuzGKxTl1DeUR5 IIWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784256106; x=1784860906; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=v9ZzsR0v39hzEb6iXWVS0iiD5j1ThrMppOubfeQ9NoI=; b=RWoj2XqoVSYnIzyNY0y7Gfbu0GtwkmCetoMXtQV0t45lsjz3tOPkZZBOSl6qI4KrUd 0IpgIa9TnWUxnSbbZyjFbo7SPWs7uwHzw+2qvXF4HLm5Jny4aivfyr9w4IyndYy0+gMo sf6LqKnQhX6ibwe99c/fuXBbGHE5tkUaIk/rPkbug72sCE9vbWiUqgyru4q3Hfke2zNX S4XQsU58s8EXeICZFK6U1n07VQuDNb5RgSHjicp5yJRWHxhYAEiJ17NJ8cue/d5TaHX0 NlOe8zoAyWdO4C/qxJpk9rzWSGqyDP4LkD7YKQbR7Bihrw2L62yDqHuFpC9KPbWBGsuA K+zg== X-Forwarded-Encrypted: i=1; AHgh+RqkGvKjZ4dpUAZNEljz9sQYvkP9ia5b/xDQQsxV26j/ZJlb1dJVH3oGrL4REIP28aToFKOC2djm22zXwYA=@vger.kernel.org X-Gm-Message-State: AOJu0YzYnHNCLJMk28iMQuo6AeAh9M6fqOxB3gkbaQju2JjHn+f/TfWZ gKVi2spuZEEqoZd19PZvITZ4OopHLaRvANCLGP+W4pwu1KPErdhaKlOuCd5xS0rjUAgbVBeHi0W KOUTs1eeTVfxqABE+jg== X-Received: from wrmh8.prod.google.com ([2002:adf:e988:0:b0:463:dd19:ae30]) (user=tarunsahu job=prod-delivery.src-stubby-dispatcher) by 2002:a5d:5d12:0:b0:475:f0f0:9f04 with SMTP id ffacd0b85a97d-47f6235475bmr740733f8f.59.1784256105583; Thu, 16 Jul 2026 19:41:45 -0700 (PDT) Date: Thu, 16 Jul 2026 23:04:07 +0000 In-Reply-To: <20260716230411.2767394-1-tarunsahu@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260716230411.2767394-1-tarunsahu@google.com> X-Mailer: git-send-email 2.55.0.229.g6434b31f56-goog Message-ID: <20260716230411.2767394-4-tarunsahu@google.com> Subject: [PATCH v19 3/7] driver core: separate function to shutdown one device From: Tarun Sahu To: Shuah Khan , Danilo Krummrich , Bjorn Helgaas , Greg Kroah-Hartman , "Martin K. Petersen" , "James E.J. Bottomley" , Jonathan Corbet , "Rafael J. Wysocki" Cc: bvanassche@acm.org, john.g.garry@oracle.com, mlombard@redhat.com, loberman@redhat.com, mclapinski@google.com, dmatlack@google.com, driver-core@lists.linux.dev, linux-pci@vger.kernel.org, Pasha Tatashin , jordanrichards@google.com, souravsgl@google.com, stuart.w.hayes@gmail.com, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, emilne@redhat.com, jmeneghi@redhat.com, linux-scsi@vger.kernel.org, David Jeffery Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: David Jeffery Make a separate function for the part of device_shutdown() that does the shutown for a single device. This is in preparation for making device shutdown asynchronous. Signed-off-by: Stuart Hayes Signed-off-by: David Jeffery Tested-by: Laurence Oberman Reviewed-by: Martin K. Petersen Reviewed-by: Pasha Tatashin --- drivers/base/core.c | 71 +++++++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 32 deletions(-) diff --git a/drivers/base/core.c b/drivers/base/core.c index 78b90326addb..82a7af1f3ba2 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -4898,12 +4898,48 @@ int device_change_owner(struct device *dev, kuid_t = kuid, kgid_t kgid) return error; } =20 +static void shutdown_one_device(struct device *dev) +{ + struct device *parent =3D dev->parent; + + /* hold lock to avoid race with probe/release */ + if (parent) + device_lock(parent); + device_lock(dev); + + /* Don't allow any more runtime suspends */ + pm_runtime_get_noresume(dev); + pm_runtime_barrier(dev); + + if (dev->class && dev->class->shutdown_pre) { + if (initcall_debug) + dev_info(dev, "shutdown_pre\n"); + dev->class->shutdown_pre(dev); + } + if (dev->bus && dev->bus->shutdown) { + if (initcall_debug) + dev_info(dev, "shutdown\n"); + dev->bus->shutdown(dev); + } else if (dev->driver && dev->driver->shutdown) { + if (initcall_debug) + dev_info(dev, "shutdown\n"); + dev->driver->shutdown(dev); + } + + device_unlock(dev); + if (parent) + device_unlock(parent); + + put_device(parent); + put_device(dev); +} + /** * device_shutdown - call ->shutdown() on each device to shutdown. */ void device_shutdown(void) { - struct device *dev, *parent; + struct device *dev; =20 wait_for_device_probe(); device_block_probing(); @@ -4925,7 +4961,7 @@ void device_shutdown(void) * prevent it from being freed because parent's * lock is to be held */ - parent =3D get_device(dev->parent); + get_device(dev->parent); get_device(dev); /* * Make sure the device is off the kset list, in the @@ -4934,36 +4970,7 @@ void device_shutdown(void) list_del_init(&dev->kobj.entry); spin_unlock(&devices_kset->list_lock); =20 - /* hold lock to avoid race with probe/release */ - if (parent) - device_lock(parent); - device_lock(dev); - - /* Don't allow any more runtime suspends */ - pm_runtime_get_noresume(dev); - pm_runtime_barrier(dev); - - if (dev->class && dev->class->shutdown_pre) { - if (initcall_debug) - dev_info(dev, "shutdown_pre\n"); - dev->class->shutdown_pre(dev); - } - if (dev->bus && dev->bus->shutdown) { - if (initcall_debug) - dev_info(dev, "shutdown\n"); - dev->bus->shutdown(dev); - } else if (dev->driver && dev->driver->shutdown) { - if (initcall_debug) - dev_info(dev, "shutdown\n"); - dev->driver->shutdown(dev); - } - - device_unlock(dev); - if (parent) - device_unlock(parent); - - put_device(dev); - put_device(parent); + shutdown_one_device(dev); =20 spin_lock(&devices_kset->list_lock); } --=20 2.55.0.229.g6434b31f56-goog From nobody Sat Jul 25 06:09:17 2026 Received: from mail-ej1-f74.google.com (mail-ej1-f74.google.com [209.85.218.74]) (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 9D85733D6ED for ; Fri, 17 Jul 2026 02:41:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784256111; cv=none; b=Cqite/HaBjtgBcaDXFcpWdRdTwUWSfzhGSMciz6AHlYUqqg6iv+jlovOExFQ2p0TEG8TYZJ+di7HhD+Z78XvC5O5bnMpzvUzsM8uOb0svc4IIA5969N+xdG0gR65xTu9dNmoUVBhHrjybcXuxUnyD6spal3+t/LVGEbiZyBhkHk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784256111; c=relaxed/simple; bh=KH/ARVjO6KZqlgIJZ1WbqwS9YnBGnwAD01sy0uaFPNc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=mCUnJ1R9YcRsSl9PyFMciUWcYcgJ/1XXAw2sNuoXxKpIx8UJSRzR4wLCRCzF727U37i4W1PcnJftxdY7sfcb2mtrkaiOQGgICmEpJyZlhC/iVn3VbGX5vBH1xX6N2ahLPSq/DvZhDI0CHH4dfKDR3Sn8pcgdFYAZZQG48VIK34o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--tarunsahu.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=DcJqkWZB; arc=none smtp.client-ip=209.85.218.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--tarunsahu.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="DcJqkWZB" Received: by mail-ej1-f74.google.com with SMTP id a640c23a62f3a-c166d70977dso93152866b.1 for ; Thu, 16 Jul 2026 19:41:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1784256107; x=1784860907; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=kNEDG9WfHYH4efBdhIMziRHnrMAb5uPezNVzt5EuvWI=; b=DcJqkWZBRf2GuSm85TbSk//3Q06uwxJu6aO496mHJV3VBZY3e66PiCZLTe7F+tP4vg Z2/Z/zWWZDKP9q+4ESQ9rPnfuxZJ6isaI10ZipudmIveNlnsn/U1io3D2+1cYeMSKtRA I3ZsviIBeeodUHfvwtvmbwyO+mz9P2gS98NyIoLfnzgjGs/uZwkNGhVP72iz6WNZaO14 88ftNlOaXXFTrqrLO+MUBCrTcv6HDF3HlkelU+PTYEGpEoA+cFfOXBduG68X62V91hv0 iULuKBlZ0QDi7oL5IxgQYiYAgJe2FsVplDoPwzxe2YJfbneQ9ARbFlsc0RNnObQa/Qkt PZiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784256107; x=1784860907; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=kNEDG9WfHYH4efBdhIMziRHnrMAb5uPezNVzt5EuvWI=; b=Noo7mxDc+MmcIQZcRPkRh8DAEQklaEejgHGLLc+O63yWFkFjT8Gsb9Ti4C2QkmaORa 0KWTnUbzkVINBpqO2UftBry3XU51avjkW5UNuehuaUIGQdJqSMFZUC5+ocgPxAKQOTi8 Ygsl0R3nibpED4epCoS/JPwSJJKF6GqddYwIcwxn4P1IlQ/Z41Ycxs0D7aprwT+cOQwu OKdj6Z11YqFQzJvfLhv/n8LVSGPP9cfAcXbd+rj/Xu6j2Wfk7C4ftM1ik3P5uRcF1YoZ JhZDyqAVt9zD5Prb1unTW7TQTP3+wMJsSn0efyk7Pu934oFW1X/FZUNKu4Vknwsk8v9E vHwQ== X-Forwarded-Encrypted: i=1; AHgh+RoDk2E1gPZzm43vxnoK3ftB/M8kahrRB5of5Cw9VGHzegi4OI0u7q7nIyJ7pBdiPAoRLp1qEgzSVV36Pgs=@vger.kernel.org X-Gm-Message-State: AOJu0YwFy+QsQwQ2F4B+O6lYAw7fKuNx2IP9BDghxhAWATgOHE7X6Iz3 FGgjUKk/2FWvHGAZ0ElblU2A9EFRxQqXNbiut77xrX/BZv8xx4l27LHyGCPFz+KDLlMw1KZSDj+ pwv6pSbyMUe1lI3QLjQ== X-Received: from ejbgg8.prod.google.com ([2002:a17:906:e288:b0:c12:6e0e:a4b6]) (user=tarunsahu job=prod-delivery.src-stubby-dispatcher) by 2002:a17:906:abcc:b0:c17:1295:265c with SMTP id a640c23a62f3a-c1712952993mr6792166b.21.1784256106546; Thu, 16 Jul 2026 19:41:46 -0700 (PDT) Date: Thu, 16 Jul 2026 23:04:08 +0000 In-Reply-To: <20260716230411.2767394-1-tarunsahu@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260716230411.2767394-1-tarunsahu@google.com> X-Mailer: git-send-email 2.55.0.229.g6434b31f56-goog Message-ID: <20260716230411.2767394-5-tarunsahu@google.com> Subject: [PATCH v19 4/7] driver core: do not always lock parent in shutdown From: Tarun Sahu To: Shuah Khan , Danilo Krummrich , Bjorn Helgaas , Greg Kroah-Hartman , "Martin K. Petersen" , "James E.J. Bottomley" , Jonathan Corbet , "Rafael J. Wysocki" Cc: bvanassche@acm.org, john.g.garry@oracle.com, mlombard@redhat.com, loberman@redhat.com, mclapinski@google.com, dmatlack@google.com, driver-core@lists.linux.dev, linux-pci@vger.kernel.org, Pasha Tatashin , jordanrichards@google.com, souravsgl@google.com, stuart.w.hayes@gmail.com, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, emilne@redhat.com, jmeneghi@redhat.com, linux-scsi@vger.kernel.org, David Jeffery , Tarun Sahu Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: David Jeffery Don't lock a parent device unless it is needed in device_shutdown. This is in preparation for making device shutdown asynchronous, when it will be needed to allow children of a common parent to shut down simultaneously. And only acquire a reference to the parent device if the parent is to be locked. Signed-off-by: Stuart Hayes Signed-off-by: David Jeffery Signed-off-by: Tarun Sahu Tested-by: Laurence Oberman --- drivers/base/core.c | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/drivers/base/core.c b/drivers/base/core.c index 82a7af1f3ba2..31f95e86856e 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -4898,14 +4898,10 @@ int device_change_owner(struct device *dev, kuid_t = kuid, kgid_t kgid) return error; } =20 -static void shutdown_one_device(struct device *dev) +static void __shutdown_one_device(struct device *dev) { - struct device *parent =3D dev->parent; - - /* hold lock to avoid race with probe/release */ - if (parent) - device_lock(parent); - device_lock(dev); + if (!dev->p || dev->p->dead) + return; =20 /* Don't allow any more runtime suspends */ pm_runtime_get_noresume(dev); @@ -4925,12 +4921,32 @@ static void shutdown_one_device(struct device *dev) dev_info(dev, "shutdown\n"); dev->driver->shutdown(dev); } +} =20 - device_unlock(dev); - if (parent) +static void shutdown_one_device(struct device *dev) +{ + struct device *parent; + + device_lock(dev); + + /* use parent lock if needed to avoid race with probe/release */ + if (dev->bus && dev->bus->need_parent_lock && dev->p && !dev->p->dead && + (parent =3D get_device(dev->parent))) { + /* the parent lock needs to be acquired first, so re-lock */ + device_unlock(dev); + + device_lock(parent); + device_lock(dev); + + __shutdown_one_device(dev); + device_unlock(dev); device_unlock(parent); + put_device(parent); + } else { + __shutdown_one_device(dev); + device_unlock(dev); + } =20 - put_device(parent); put_device(dev); } =20 @@ -4956,12 +4972,6 @@ void device_shutdown(void) dev =3D list_entry(devices_kset->list.prev, struct device, kobj.entry); =20 - /* - * hold reference count of device's parent to - * prevent it from being freed because parent's - * lock is to be held - */ - get_device(dev->parent); get_device(dev); /* * Make sure the device is off the kset list, in the --=20 2.55.0.229.g6434b31f56-goog From nobody Sat Jul 25 06:09:17 2026 Received: from mail-ej1-f73.google.com (mail-ej1-f73.google.com [209.85.218.73]) (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 ABBEE33BBCB for ; Fri, 17 Jul 2026 02:41:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784256114; cv=none; b=kbVoeT9I6cVHSm5MkhqJ4oIMxlk3j4VH+t+PnB/jCbObRhq6m+qOpNipJetowwy+Q4XurZ6OZuBosvbN9dc3BegRxiBECRb72IfvnX9tdoTWGYKIbLwf3+8cZV13zMCxQtexXMYJomgDIkNhHnAfIXYaQdBnwUZktFCKE5YiN2s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784256114; c=relaxed/simple; bh=vtM/iS4dqfQrB9RkKv94sd0lDNxuzz1siA09RPr39Tc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=I1edvs053FAePY3R7+4JbEKspHd6/AogQGaMiVtrdP0/FN234VypGFMFA2XdPw+IEuMAwpFmppYUNmxEL9Au4gxMehbkpgD3xncUzX2ReXwoDBZswhiSbD2BzKKAJINU0D/hXAcfa00uaXzD8jjyFIoqCOMQxNdfBjN2JJbyjJ4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--tarunsahu.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=XkVABHwx; arc=none smtp.client-ip=209.85.218.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--tarunsahu.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="XkVABHwx" Received: by mail-ej1-f73.google.com with SMTP id a640c23a62f3a-c15ff68c858so819782466b.0 for ; Thu, 16 Jul 2026 19:41:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1784256108; x=1784860908; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=xttAFdPKvha9rdtsgqnJxKaba7YH7uAmltDFNffmYC0=; b=XkVABHwxSucrUXIg/csVgZDF5wKQAmvdkSF5r3ectuvufF624aJAqH54aGm2sd1U+m SeUk3NFJ/Tzoz59a4ufKX8njP+zMbzhUe1ET6K4LS6O1/LfXwgpcfYIqUPOli4q1KJO/ yqra2yY4ewWmdD/61aDPnZLzJr3Ye8rmQ3ok1iyKarT5kaSSbvMT94JA0szF9jicz8EG w2VRcQnIrkdCxrgyH6V6YsZwJx9nLGhnwSc+xUa5Dj/MSqytfeof1k3ynGFVuz/r6pP+ xXCMrzuW+CKi6yzg9Tp2h+oU2Vujp5P5TqnUPkm4DR5KuRbBUc6yuKYM9tG0MNk5J6F4 tJBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784256108; x=1784860908; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=xttAFdPKvha9rdtsgqnJxKaba7YH7uAmltDFNffmYC0=; b=NuthWnmczqrTWaHvNLX98Ovc7hpvdptaYx1NN+W8b6CGM0lx2zDbjQMPsp+FPu8k4N Khtl8OD9wpko0IiUltXaMRaC0mAe2nmC0zqa4lkIwQw7IwGkqwMR1KqGTYiWyVP4XVCq 8t/8FG6YC7M9FWr62QfS3N25bWCEoC97fTENSr4BGuAfhOM21dV0EhutglBGb1MddPqH ygE4WSRVYMGW2Q+capmtrk6B+7+iZo+PVJnY9Z9MJXVmrWcthuCtUsCHue6Xpg6yXNBB FITUwawzyW9+KllVGo9+ABt1fy+7b3RogHk+OCdgbStHu7svmakkW8Kj4YAow0VLUT/7 dXqw== X-Forwarded-Encrypted: i=1; AHgh+Ro8j/oo3QkXCSU4ZWRI6GaHdNmw6n16l4R0ZhWNFVS8h/Q0PgGbxHyX1HeFGz+aT+lVKHEnT3nsdtSxUL4=@vger.kernel.org X-Gm-Message-State: AOJu0Yyr0jRYvQapFdj620jxkfZtKR/Xsw4SSEaObQ/+qt8DqL+XeT2e Sp5BieXx0qtwPr1isaTQv8qndXnK3jboBQLwjfV7AJ9SKBoKGZdIVyiMlbb1fN6PQ4dGwBgNX9U NI9XZDr0PcJAwLzT8yA== X-Received: from ejbga4.prod.google.com ([2002:a17:906:b844:b0:c12:583d:cdca]) (user=tarunsahu job=prod-delivery.src-stubby-dispatcher) by 2002:a17:907:724b:b0:c15:a06c:2bc6 with SMTP id a640c23a62f3a-c16b4834e99mr15780066b.47.1784256107376; Thu, 16 Jul 2026 19:41:47 -0700 (PDT) Date: Thu, 16 Jul 2026 23:04:09 +0000 In-Reply-To: <20260716230411.2767394-1-tarunsahu@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260716230411.2767394-1-tarunsahu@google.com> X-Mailer: git-send-email 2.55.0.229.g6434b31f56-goog Message-ID: <20260716230411.2767394-6-tarunsahu@google.com> Subject: [PATCH v19 5/7] driver core: async device shutdown infrastructure From: Tarun Sahu To: Shuah Khan , Danilo Krummrich , Bjorn Helgaas , Greg Kroah-Hartman , "Martin K. Petersen" , "James E.J. Bottomley" , Jonathan Corbet , "Rafael J. Wysocki" Cc: bvanassche@acm.org, john.g.garry@oracle.com, mlombard@redhat.com, loberman@redhat.com, mclapinski@google.com, dmatlack@google.com, driver-core@lists.linux.dev, linux-pci@vger.kernel.org, Pasha Tatashin , jordanrichards@google.com, souravsgl@google.com, stuart.w.hayes@gmail.com, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, emilne@redhat.com, jmeneghi@redhat.com, linux-scsi@vger.kernel.org, David Jeffery , Tarun Sahu Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: David Jeffery Patterned after async suspend, allow devices to mark themselves as wanting to perform async shutdown. Devices using async shutdown wait only for their dependencies to shutdown before executing their shutdown routine. Sync shutdown devices are shut down one at a time and will only wait for an async shutdown device if the async device is a dependency. Enabled by default, async shutdown can be explicitly enabled or disabled by using the kernel parameter "core.async_shutdown=3D" Signed-off-by: David Jeffery Signed-off-by: Stuart Hayes Signed-off-by: Tarun Sahu Tested-by: Laurence Oberman --- .../admin-guide/kernel-parameters.txt | 10 ++ drivers/base/base.h | 2 + drivers/base/core.c | 141 +++++++++++++++++- include/linux/device.h | 2 + 4 files changed, 154 insertions(+), 1 deletion(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentatio= n/admin-guide/kernel-parameters.txt index b5493a7f8f22..f0de215963c6 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -989,6 +989,16 @@ Kernel parameters seconds. A value of 0 disables the blank timer. Defaults to 0. =20 + core.async_shutdown=3D + [KNL] + Format: + Enable or disable asynchronous shutdown support. When + enabled, on system shutdown unrelated devices flagged + as async shutdown compatible may be shut down in + parallel and asynchronously. When disabled, device + shutdown is performed serially and synchronously. + Enabled by default. + coredump_filter=3D [KNL] Change the default value for /proc//coredump_filter. diff --git a/drivers/base/base.h b/drivers/base/base.h index a5b7abc10ff0..40dbf588a5d6 100644 --- a/drivers/base/base.h +++ b/drivers/base/base.h @@ -103,6 +103,7 @@ struct driver_private { * dev_err_probe() for later retrieval via debugfs * @device: pointer back to the struct device that this structure is * associated with. + * @complete: completion for device shutdown ordering * @dead: This device is currently either in the process of or has been * removed from the system. Any asynchronous events scheduled for this * device should exit without taking any action. @@ -119,6 +120,7 @@ struct device_private { const struct device_driver *async_driver; char *deferred_probe_reason; struct device *device; + struct completion complete; u8 dead:1; }; #define to_device_private_parent(obj) \ diff --git a/drivers/base/core.c b/drivers/base/core.c index 31f95e86856e..55287f13b8d1 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -9,6 +9,7 @@ */ =20 #include +#include #include #include #include @@ -37,6 +38,11 @@ #include "physical_location.h" #include "power/power.h" =20 +static bool async_shutdown =3D true; +module_param(async_shutdown, bool, 0644); +MODULE_PARM_DESC(async_shutdown, "Enable asynchronous device shutdown supp= ort"); +static bool async_shutdown_enabled; + /* Device links support. */ static LIST_HEAD(deferred_sync); static unsigned int defer_sync_state_count =3D 1; @@ -3623,6 +3629,7 @@ static int device_private_init(struct device *dev) klist_init(&dev->p->klist_children, klist_children_get, klist_children_put); INIT_LIST_HEAD(&dev->p->deferred_probe); + init_completion(&dev->p->complete); return 0; } =20 @@ -3928,6 +3935,7 @@ bool kill_device(struct device *dev) if (dev->p->dead) return false; dev->p->dead =3D true; + complete_all(&dev->p->complete); return true; } EXPORT_SYMBOL_GPL(kill_device); @@ -4898,6 +4906,40 @@ int device_change_owner(struct device *dev, kuid_t k= uid, kgid_t kgid) return error; } =20 +static bool wants_async_shutdown(struct device *dev) +{ + return async_shutdown_enabled && dev_async_shutdown(dev); +} + +static int wait_for_device_shutdown(struct device *dev, void *data) +{ + bool async =3D *(bool *)data; + + if (!dev->p || !device_is_registered(dev)) + return 0; + + if (async || wants_async_shutdown(dev)) + wait_for_completion(&dev->p->complete); + + return 0; +} + +static void wait_for_shutdown_dependencies(struct device *dev, bool async) +{ + struct device_link *link; + int idx; + + device_for_each_child(dev, &async, wait_for_device_shutdown); + + idx =3D device_links_read_lock(); + + dev_for_each_link_to_consumer(link, dev) + if (!device_link_flag_is_sync_state_only(link->flags)) + wait_for_device_shutdown(link->consumer, &async); + + device_links_read_unlock(idx); +} + static void __shutdown_one_device(struct device *dev) { if (!dev->p || dev->p->dead) @@ -4921,6 +4963,8 @@ static void __shutdown_one_device(struct device *dev) dev_info(dev, "shutdown\n"); dev->driver->shutdown(dev); } + + complete_all(&dev->p->complete); } =20 static void shutdown_one_device(struct device *dev) @@ -4950,6 +4994,88 @@ static void shutdown_one_device(struct device *dev) put_device(dev); } =20 +static void async_shutdown_handler(void *data, async_cookie_t cookie) +{ + struct device *dev =3D data; + + wait_for_shutdown_dependencies(dev, true); + shutdown_one_device(dev); +} + +static bool shutdown_device_async(struct device *dev) +{ + if (async_schedule_dev_nocall(async_shutdown_handler, dev)) + return true; + + dev_clear_async_shutdown(dev); + return false; +} + + +static void start_async_shutdown_devices(void) +{ + struct device *dev, *next, *ndev, *needs_put =3D NULL; + bool clear_async =3D false; + + if (!async_shutdown_enabled) + return; + + spin_lock(&devices_kset->list_lock); +restart: + list_for_each_entry_safe_reverse(dev, next, &devices_kset->list, + kobj.entry) { + if (wants_async_shutdown(dev)) { + if (clear_async) { + dev_clear_async_shutdown(dev); + continue; + } + /* one device reference for this function */ + get_device(dev); + /* another to pass to the async task */ + get_device(dev); + + if (!list_entry_is_head(next, &devices_kset->list, + kobj.entry)) + ndev =3D get_device(next); + else + ndev =3D NULL; + spin_unlock(&devices_kset->list_lock); + + if (shutdown_device_async(dev)) { + spin_lock(&devices_kset->list_lock); + list_del_init(&dev->kobj.entry); + spin_unlock(&devices_kset->list_lock); + } else { + /* + * async failed, clean up extra reference + * and run shutdown from the sync shutdown loop + */ + clear_async =3D true; + put_device(dev); + } + put_device(dev); + + if (needs_put) + put_device(needs_put); + needs_put =3D ndev; + spin_lock(&devices_kset->list_lock); + /* + * If the next device has been marked dead while the + * spinlock was released, or if it has been unlinked + * from the list, it may no longer be on the + * devices_kset list. Restart the list walk to be safe. + */ + if (ndev && (ndev->p->dead || list_empty(&ndev->kobj.entry))) + goto restart; + } + } + + spin_unlock(&devices_kset->list_lock); + + if (needs_put) + put_device(needs_put); +} + /** * device_shutdown - call ->shutdown() on each device to shutdown. */ @@ -4962,6 +5088,14 @@ void device_shutdown(void) =20 cpufreq_suspend(); =20 + async_shutdown_enabled =3D async_shutdown; + + /* + * Start async device threads where possible to maximize potential + * parallelism and minimize false dependency on unrelated sync devices + */ + start_async_shutdown_devices(); + spin_lock(&devices_kset->list_lock); /* * Walk the devices list backward, shutting down each in turn. @@ -4980,11 +5114,16 @@ void device_shutdown(void) list_del_init(&dev->kobj.entry); spin_unlock(&devices_kset->list_lock); =20 - shutdown_one_device(dev); + if (!wants_async_shutdown(dev) || !shutdown_device_async(dev)) { + wait_for_shutdown_dependencies(dev, false); + shutdown_one_device(dev); + } =20 spin_lock(&devices_kset->list_lock); } spin_unlock(&devices_kset->list_lock); + + async_synchronize_full(); } =20 /* diff --git a/include/linux/device.h b/include/linux/device.h index 7b2baffdd2f5..f913d72218f8 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -610,6 +610,7 @@ enum struct_device_flags { DEV_FLAG_OF_NODE_REUSED =3D 7, DEV_FLAG_OFFLINE_DISABLED =3D 8, DEV_FLAG_OFFLINE =3D 9, + DEV_FLAG_ASYNC_SHUTDOWN =3D 10, =20 DEV_FLAG_COUNT }; @@ -827,6 +828,7 @@ __create_dev_flag_accessors(dma_coherent, DEV_FLAG_DMA_= COHERENT); __create_dev_flag_accessors(of_node_reused, DEV_FLAG_OF_NODE_REUSED); __create_dev_flag_accessors(offline_disabled, DEV_FLAG_OFFLINE_DISABLED); __create_dev_flag_accessors(offline, DEV_FLAG_OFFLINE); +__create_dev_flag_accessors(async_shutdown, DEV_FLAG_ASYNC_SHUTDOWN); =20 #undef __create_dev_flag_accessors =20 --=20 2.55.0.229.g6434b31f56-goog From nobody Sat Jul 25 06:09:17 2026 Received: from mail-ej1-f74.google.com (mail-ej1-f74.google.com [209.85.218.74]) (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 D253A345CCE for ; Fri, 17 Jul 2026 02:41:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784256114; cv=none; b=QK7K4loPdxeFdj+JXD67B7Aw+wahl5CdoxnLar8X/+Dtvs3nOahpJpToFnVf3x3Ff2uko1P+def/uq6nWbO3OwPFBwoXw/57C7sj3WilLbB/mzSTFhmUdPUwXEXTxsNNKfvC0qAWow4Weh083bdgNs2WsUyqeicKEn1CcIf+dmQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784256114; c=relaxed/simple; bh=DDh2GgbdI5RQMq7gxZncAkacOeotdu9Fzy33SzeLtQY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=IppfadO8cdsitofpekHcdu9l9jc/jTdUEsHT+vGzBDhP77NMdd7YJP0URMQPL/jGFT7maORSEF9joIppKacTAsMCZGpEZe81Z6czUSApBEmr78XtovR5MMTqhdt8MV5dr0Dvp9+g76fz7ivBeRL2TuMdsfxyLSMrKjsDhWncLro= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--tarunsahu.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=orv+ecfv; arc=none smtp.client-ip=209.85.218.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--tarunsahu.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="orv+ecfv" Received: by mail-ej1-f74.google.com with SMTP id a640c23a62f3a-c15fed5653eso365628366b.2 for ; Thu, 16 Jul 2026 19:41:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1784256109; x=1784860909; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=j3nhX204PbzOZptNzEwfrJ1tihihmuj8AGndCLVcQhw=; b=orv+ecfvKYOj/yUJ9oD4U8h51O7yL9kYoEFD77GjnYHcrC7r1TX+pEyEgIjl/W1uc8 ypb7qUSt3+iIF3/wK7fNZnYYyhJH8i6q+LtNOx5XnM3RGFbWPdwlSZmaO7bJx3QJY5yz wsMW3wukE8obNz901dtKRSneP+3WIsg6OtooP9O0Dxru+VfNgu5tERuzWp+bRVjNl2eN 7aoepUmCqPU6qUNXGZIrup5xpUyWsqMYEvcd++EkZRwxSb7sAhyLcx801cRrRzhf+KLI H6UG7CR8j+raBCBpuuylPQTpZebyvbXQ40JUSFzPgG4iuw1e4XNdnl3OQScgIR/xikKU nWgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784256109; x=1784860909; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=j3nhX204PbzOZptNzEwfrJ1tihihmuj8AGndCLVcQhw=; b=NeCTqdI2cM93n2sGLuxfK+3t7+JE+fxSvy/0qhCNQ8yPJFIEm5se99WBmKRqjesex3 Gg9/mSh3w0yy0wWqV5PmqxO2dD+sC+/+CsAHAd+q3XKIz/eIFUc9fu9+GmMihhxjpp48 gnK1WF8UOle0n8lZT93gtOSLADG+V21jf0UgvPNVWFf02LtfkMm4L9sN7BplXyYG66zT 1CrUf3KdTWncWmZr3ycLooRArlnOxijUclrIEmtiniRrkR1PykYBZQzGl3AItGi2EyQN R68MyRzqUzUwPRSHyiCtITFOlRDlsFNV7F1bYe9zMSUiTB/zKx6WXeIzwV42Ejj3oNbG rtog== X-Forwarded-Encrypted: i=1; AHgh+RrrLk0xbkqlqqP69/Cx9L3hqNq6xm6Ok1tDi4z8udCdpXwi2Iwtvet4VQvESRKrx/VLpTh0kRwD0Uiq2Ew=@vger.kernel.org X-Gm-Message-State: AOJu0Yzr6/KOtjjJaQPpLrddG9cpbcgI4braeNx5avOwbqopsgi0vpZS oYP2RGxBN5hr2puGSeZeuXO/xdqMniE6fUBNj1RGRNX5aw3eNbqbQ59Gzn8p8HVLyouZXPk4NtA Ti26wYTRDKTaN3kGO6w== X-Received: from ejfr10.prod.google.com ([2002:a17:906:3d6a:b0:c12:5875:9cda]) (user=tarunsahu job=prod-delivery.src-stubby-dispatcher) by 2002:a17:907:7203:b0:bed:19af:f89a with SMTP id a640c23a62f3a-c16b46caa65mr21546866b.7.1784256108367; Thu, 16 Jul 2026 19:41:48 -0700 (PDT) Date: Thu, 16 Jul 2026 23:04:10 +0000 In-Reply-To: <20260716230411.2767394-1-tarunsahu@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260716230411.2767394-1-tarunsahu@google.com> X-Mailer: git-send-email 2.55.0.229.g6434b31f56-goog Message-ID: <20260716230411.2767394-7-tarunsahu@google.com> Subject: [PATCH v19 6/7] PCI: Enable async shutdown support From: Tarun Sahu To: Shuah Khan , Danilo Krummrich , Bjorn Helgaas , Greg Kroah-Hartman , "Martin K. Petersen" , "James E.J. Bottomley" , Jonathan Corbet , "Rafael J. Wysocki" Cc: bvanassche@acm.org, john.g.garry@oracle.com, mlombard@redhat.com, loberman@redhat.com, mclapinski@google.com, dmatlack@google.com, driver-core@lists.linux.dev, linux-pci@vger.kernel.org, Pasha Tatashin , jordanrichards@google.com, souravsgl@google.com, stuart.w.hayes@gmail.com, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, emilne@redhat.com, jmeneghi@redhat.com, linux-scsi@vger.kernel.org, David Jeffery Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: David Jeffery Like its async suspend support, allow PCI device shutdown to be performed asynchronously to reduce shutdown time. Signed-off-by: David Jeffery Signed-off-by: Stuart Hayes Tested-by: Laurence Oberman Reviewed-by: Martin K. Petersen Reviewed-by: Pasha Tatashin Reviewed-by: Bjorn Helgaas --- drivers/pci/probe.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index dd0abbc63e18..af2381446406 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -1046,6 +1046,7 @@ static int pci_register_host_bridge(struct pci_host_b= ridge *bridge) =20 bus->bridge =3D get_device(&bridge->dev); device_enable_async_suspend(bus->bridge); + dev_set_async_shutdown(bus->bridge); pci_set_bus_of_node(bus); pci_set_bus_msi_domain(bus); if (bridge->msi_domain && !dev_get_msi_domain(&bus->dev) && @@ -2748,6 +2749,7 @@ void pci_device_add(struct pci_dev *dev, struct pci_b= us *bus) pci_reassigndev_resource_alignment(dev); =20 pci_init_capabilities(dev); + dev_set_async_shutdown(&dev->dev); =20 /* * Add the device to our list of discovered devices --=20 2.55.0.229.g6434b31f56-goog From nobody Sat Jul 25 06:09:17 2026 Received: from mail-ed1-f73.google.com (mail-ed1-f73.google.com [209.85.208.73]) (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 1F538348C64 for ; Fri, 17 Jul 2026 02:41:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784256114; cv=none; b=hPboL3QjZPlvUdkv9Kgrtbb8qBRya4RKPd20JdtdiUW0/Ufy/e9MmCKecD4/xFPW1LptiPGekerF9LysWlH6J0xofSnoReeyjep4Rd3IiNfAEiMDQOE7JxuoFw+aKjW2q+pguBgHUCTFWCqqHlCOBq7cU+PDc91vI0MI8QB0iF4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784256114; c=relaxed/simple; bh=tzn/iEqTad6dQhUjU9RzDdcmlVaMSOCPaaD5tYvzKjM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=N9A2Z+tZmpact5w5JH+QneDo4hFMkRpgEQwnvueGL82WGEbU2QvERF2kgXO6R16iPy2pyCHSMnobIUds2FkfcCUHNFa9guu4wAZKXGyNITYxUij5dNjMGCWnMrM5RWG6DHMbnvNOKmIwOmjFcz/d/vjh82uZku8yNQbXxfqzjPM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--tarunsahu.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=GRqA6RIE; arc=none smtp.client-ip=209.85.208.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--tarunsahu.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="GRqA6RIE" Received: by mail-ed1-f73.google.com with SMTP id 4fb4d7f45d1cf-698a99b6140so8426839a12.1 for ; Thu, 16 Jul 2026 19:41:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1784256110; x=1784860910; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=hJfRBT3Ki0wq3tOrZx9x5Dfjc24sd8ItMQ1cbR5ZfR8=; b=GRqA6RIEtpo0UeJaKQcIICezzadIEn6yz99Ovs0SeinsFju8niM+huD/Ql+fVjl/hu ytMzk16cNIESuopiLH0SW9NydPEFZzZxeYlofCvnURlgshUuUnRMocpqgg7FlDur8f1H S1ElLhZe+4R0ZO9bi2mzg9QwXpldrmqKrVviwoyqsS5scM7lhWE+RBXgIavnowpmqkzp 5GJF3LqmSr8EbMa1lq881LIFxb04GGkMKbFaW+KRVBKeymM9KWZyIvcDlBGpb49JkS0O 2ZNshLtvQeYRfau3sz9PO+64I1kk1zLfFB2dIlhx9ZCgrn4rGL3HIQaJRMnL6r4JDxuo +JGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784256110; x=1784860910; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=hJfRBT3Ki0wq3tOrZx9x5Dfjc24sd8ItMQ1cbR5ZfR8=; b=TPVq24jwxQwlTiNHPKx2SonoYAulPyl2xcnNy57L4m4HmY5YllCiPW+e8AvL23Excr 2h1RSkMRX6HAnjn5o5KqX/zo3MBQ62bflJh27sODtzR2nAh8Loolw16FskF9vVR25AMc 3C3SgBCtk0LBsTCV5UfVH93LEJXUiIWDLppw1Tf5N+kQmEy7Gk1P6wbZe2frOqazn4sD TQt/2+/aWrgxvGLC+8cNpTqB3foNkobneSylbuFrPt2G6Zfe8HYjNYK0m3H3JB9ERjKF qgMbvjIGUVb3C6171s7US5K5/k84gLWS62ri56POCqzvq/cUvXutya6YinP6PD0VeK5r VjOg== X-Forwarded-Encrypted: i=1; AHgh+RpKJ6G1hHpZH0kkRlqFBPIdsAJmTCj6kSSuNuuIvNGeSMxI9H37yfDKuUc5o8ndla26S/Crwl3JNy8sn08=@vger.kernel.org X-Gm-Message-State: AOJu0Yx8u3kpRgXlW1zOaQIIRaBxP94W2YHcML31J7yl9R5ow9DrHPSO fNyXlFC1shHF3p2shCsysURfVXutml/2D9URlCWEBHWwTY5tzaKssbYfXNw98BtM2YtkOVix16o yPdSE/EvV6FUpiz4sxg== X-Received: from edvu22.prod.google.com ([2002:a05:6402:1116:b0:69a:9bdd:206f]) (user=tarunsahu job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6402:11c8:b0:698:3b7c:be65 with SMTP id 4fb4d7f45d1cf-69e652c5662mr148592a12.33.1784256109719; Thu, 16 Jul 2026 19:41:49 -0700 (PDT) Date: Thu, 16 Jul 2026 23:04:11 +0000 In-Reply-To: <20260716230411.2767394-1-tarunsahu@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260716230411.2767394-1-tarunsahu@google.com> X-Mailer: git-send-email 2.55.0.229.g6434b31f56-goog Message-ID: <20260716230411.2767394-8-tarunsahu@google.com> Subject: [PATCH v19 7/7] scsi: Enable async shutdown support From: Tarun Sahu To: Shuah Khan , Danilo Krummrich , Bjorn Helgaas , Greg Kroah-Hartman , "Martin K. Petersen" , "James E.J. Bottomley" , Jonathan Corbet , "Rafael J. Wysocki" Cc: bvanassche@acm.org, john.g.garry@oracle.com, mlombard@redhat.com, loberman@redhat.com, mclapinski@google.com, dmatlack@google.com, driver-core@lists.linux.dev, linux-pci@vger.kernel.org, Pasha Tatashin , jordanrichards@google.com, souravsgl@google.com, stuart.w.hayes@gmail.com, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, emilne@redhat.com, jmeneghi@redhat.com, linux-scsi@vger.kernel.org, David Jeffery Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: David Jeffery Like scsi's async suspend support, allow scsi devices to be shut down asynchronously to reduce system shutdown time. Signed-off-by: David Jeffery Signed-off-by: Stuart Hayes Tested-by: Laurence Oberman Reviewed-by: Martin K. Petersen Reviewed-by: Pasha Tatashin Reviewed-by: John Garry --- drivers/scsi/hosts.c | 2 ++ drivers/scsi/scsi_sysfs.c | 3 +++ 2 files changed, 5 insertions(+) diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c index e047747d4ecf..bf691acc7a67 100644 --- a/drivers/scsi/hosts.c +++ b/drivers/scsi/hosts.c @@ -273,6 +273,7 @@ int scsi_add_host_with_dma(struct Scsi_Host *shost, str= uct device *dev, pm_runtime_set_active(&shost->shost_gendev); pm_runtime_enable(&shost->shost_gendev); device_enable_async_suspend(&shost->shost_gendev); + dev_set_async_shutdown(&shost->shost_gendev); =20 error =3D device_add(&shost->shost_gendev); if (error) @@ -282,6 +283,7 @@ int scsi_add_host_with_dma(struct Scsi_Host *shost, str= uct device *dev, get_device(shost->shost_gendev.parent); =20 device_enable_async_suspend(&shost->shost_dev); + dev_set_async_shutdown(&shost->shost_dev); =20 get_device(&shost->shost_gendev); error =3D device_add(&shost->shost_dev); diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c index dfc3559e7e04..8fd317aef37b 100644 --- a/drivers/scsi/scsi_sysfs.c +++ b/drivers/scsi/scsi_sysfs.c @@ -1386,6 +1386,7 @@ static int scsi_target_add(struct scsi_target *starge= t) pm_runtime_set_active(&starget->dev); pm_runtime_enable(&starget->dev); device_enable_async_suspend(&starget->dev); + dev_set_async_shutdown(&starget->dev); =20 return 0; } @@ -1412,6 +1413,7 @@ int scsi_sysfs_add_sdev(struct scsi_device *sdev) transport_configure_device(&starget->dev); =20 device_enable_async_suspend(&sdev->sdev_gendev); + dev_set_async_shutdown(&sdev->sdev_gendev); scsi_autopm_get_target(starget); pm_runtime_set_active(&sdev->sdev_gendev); if (!sdev->rpm_autosuspend) @@ -1431,6 +1433,7 @@ int scsi_sysfs_add_sdev(struct scsi_device *sdev) } =20 device_enable_async_suspend(&sdev->sdev_dev); + dev_set_async_shutdown(&sdev->sdev_dev); error =3D device_add(&sdev->sdev_dev); if (error) { sdev_printk(KERN_INFO, sdev, --=20 2.55.0.229.g6434b31f56-goog