Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp729191pxj; Wed, 16 Jun 2021 12:10:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwyYeZh6UcsVGkrrLTHeGiaX6rLegRC/GRyzwVH76hvQ3J2Idb50NuBf0RfyJnXe0znGs3P X-Received: by 2002:a50:ed82:: with SMTP id h2mr1592390edr.140.1623870653990; Wed, 16 Jun 2021 12:10:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623870653; cv=none; d=google.com; s=arc-20160816; b=pL08toWS4RqQN9Xq4576+IOY37BUu7c8I4HV6RfGK23bs6kQy79Ye5vOaF5hVRwUaK 1Ff+IEoyV10zaBFnrwBaqZLlUIDSICXso6nqxr6mtfkrRUqbboqmJDrA+gCZ2svL6OAp S7qC1yAJh+MJKysSPFD9p+eJKNNCtwZlg/gkd9F3xVKaGnrcikIQQPzPJUDB9ps509BI MgXCK2oOggQUODiZj2+X6de4eiBHVDs7OikuCwk7uHh5gII+fJv0DipQUCPnAhmODglj zeJeLg3Cvst9vYIV71Ul7XaDeeRFuJ4pdHREDCShO4psTQsE656bPd0gJUjPIYH7+rcf ra3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=IvtAfkdui48DNcpbQR2o5Pss84Ycf8cKv7uo587U+1U=; b=u0TpabhHcMDwam/7fB2k8Qkg8ONPG+TTD/cf66r8hc1vhFu8NHN2hZMTL+ZNoCRXe0 3TwDER5PcpVKSYplDDL17+80XjTPqTeIeVIbKgvB4tpHWLNMv6TP1aWUV/j/KHBC1lPZ rST7tVR3hSlMrDhiEpgnzEiVGJ/8uc7W6KgAKHrcWy2tngddArfCPt0ZxYMs5Su+msX0 co9f2nIk3uoAEILhvTS60e4XFgh3K3hmIDHxj9lQp0o16D/soc9TWJxRgVrCqtEy9d9H YMgw5aGW2sOldvljQIdunrt/gLmAxDbm4aJ+U/Raq870YaqzdAaJZy230FhD+Y6MY5+G VmCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="Dsv5D/41"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i14si3093708edc.516.2021.06.16.12.10.31; Wed, 16 Jun 2021 12:10:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="Dsv5D/41"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233914AbhFPOuT (ORCPT + 99 others); Wed, 16 Jun 2021 10:50:19 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:52445 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234153AbhFPOuS (ORCPT ); Wed, 16 Jun 2021 10:50:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623854892; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IvtAfkdui48DNcpbQR2o5Pss84Ycf8cKv7uo587U+1U=; b=Dsv5D/41lNWm5G2miVC5+4KJXSVizqg/zo2jjiBTY033Iz8sBwjIHpVvK4J5A5ccOZdQHQ 1Un87t5kGShyutDqc24FPM11lp6VVQIzqYvU9XtZ0N2d+OaRuqDCKiklNIK2iHzJtCabkY jyLnOQrPSKVpDq3b4bZmQrgcUxNG0Kc= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-63-R8USG57xPqun0TuMoypWhw-1; Wed, 16 Jun 2021 10:48:10 -0400 X-MC-Unique: R8USG57xPqun0TuMoypWhw-1 Received: by mail-ed1-f69.google.com with SMTP id j3-20020aa7c3430000b0290393f7aad447so1173142edr.18 for ; Wed, 16 Jun 2021 07:48:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=IvtAfkdui48DNcpbQR2o5Pss84Ycf8cKv7uo587U+1U=; b=Yyz4rkkcsP5P3/Owhxt6OqTxp1TOzIevM8bHzNhnM9nzoq8/qsMU9IXjJj5FYbIqST HMBmYJqF2FhOdRCMmgp0qIw4c1mCTqqzkBg93pZQNtYRRcjoeWz3Bs3cjmFlqmUgHOO1 XAVLuOLWhveLVt6IOHZ1fZT0IZMDzW3ZA9gD5UkS5BNUaJ45TC21Xsat71oAIq9xkF6b tVQIkZeiuxYo0B10nJZtcneKBdFJqdofNpJHr9Tz+pZPydZvaJfC3AZYUE+SHAdjsOAW X/h7C5xIoyDq7H5AoyC+Pvqr3yIPrqePqBYbZplBCCvBCSaQczBabDD9bwWCBydaoG05 jeRg== X-Gm-Message-State: AOAM533wgZY7IZQEvopH50c+W+KwrEgU6ikxtA3CT4dwOSJsf+K9eRLI MVp6+FT3Qr1aC3pWvCZp4/1OAZt2vTUQUhyAxmNMDKzFCCZz7kO1cZGSfxQGuSTgnSCzIw0AoW9 0Hg8YpdTOac0Ssr3iV6hNp+6yMNlIueg+loCwXXAViHDdlFknAc6XPl9vvCzYDD1BR4vABM/sAh 4+ X-Received: by 2002:a05:6402:31a8:: with SMTP id dj8mr4735674edb.296.1623854889445; Wed, 16 Jun 2021 07:48:09 -0700 (PDT) X-Received: by 2002:a05:6402:31a8:: with SMTP id dj8mr4735650edb.296.1623854889281; Wed, 16 Jun 2021 07:48:09 -0700 (PDT) Received: from x1.localdomain (2001-1c00-0c1e-bf00-1054-9d19-e0f0-8214.cable.dynamic.v6.ziggo.nl. [2001:1c00:c1e:bf00:1054:9d19:e0f0:8214]) by smtp.gmail.com with ESMTPSA id n11sm1793001ejg.43.2021.06.16.07.48.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 16 Jun 2021 07:48:08 -0700 (PDT) Subject: Re: [PATCH 3/5] ACPI: scan: Fix device object rescan in acpi_scan_clear_dep() To: "Rafael J. Wysocki" , Linux ACPI Cc: LKML References: <3140195.44csPzL39Z@kreacher> <7272740.EvYhyI6sBW@kreacher> From: Hans de Goede Message-ID: <0cd3a0b5-f656-2b4f-b5bc-67680bc80603@redhat.com> Date: Wed, 16 Jun 2021 16:48:08 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: <7272740.EvYhyI6sBW@kreacher> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On 6/16/21 4:23 PM, Rafael J. Wysocki wrote: > From: Rafael J. Wysocki > > In general, acpi_bus_attach() can only be run safely under > acpi_scan_lock, but that lock cannot be acquired under > acpi_dep_list_lock, so make acpi_scan_clear_dep() schedule deferred > execution of acpi_bus_attach() under acpi_scan_lock instead of > calling it directly. > > This also fixes a possible race between acpi_scan_clear_dep() and > device removal that might cause a device object that went away to > be accessed, because acpi_scan_clear_dep() is changed to acquire > a reference on the consumer device object. > > Signed-off-by: Rafael J. Wysocki > --- > drivers/acpi/scan.c | 50 +++++++++++++++++++++++++++++++++++++++++++++----- > 1 file changed, 45 insertions(+), 5 deletions(-) > > Index: linux-pm/drivers/acpi/scan.c > =================================================================== > --- linux-pm.orig/drivers/acpi/scan.c > +++ linux-pm/drivers/acpi/scan.c > @@ -2115,16 +2115,56 @@ static int acpi_dev_get_first_consumer_d > return 0; > } > > -static int acpi_scan_clear_dep(struct acpi_dep_data *dep, void *data) > -{ > +struct acpi_scan_clear_dep_work { > + struct work_struct work; > struct acpi_device *adev; > +}; > + > +static void acpi_scan_clear_dep_fn(struct work_struct *work) > +{ > + struct acpi_scan_clear_dep_work *cdw; > + > + cdw = container_of(work, struct acpi_scan_clear_dep_work, work); > > - acpi_bus_get_device(dep->consumer, &adev); > + acpi_scan_lock_acquire(); > + acpi_bus_attach(cdw->adev, true); > + acpi_scan_lock_release(); > + > + acpi_dev_put(cdw->adev); > + kfree(cdw); > +} > + > +static bool acpi_scan_clear_dep_queue(struct acpi_device *adev) > +{ > + struct acpi_scan_clear_dep_work *cdw; > + > + if (adev->dep_unmet) > + return false; > + > + cdw = kmalloc(sizeof(*cdw), GFP_KERNEL); > + if (!cdw) > + return false; > + > + cdw->adev = adev; > + INIT_WORK(&cdw->work, acpi_scan_clear_dep_fn); > + /* > + * Since the work function may block on the lock until the entire > + * initial enumeration of devices is complete, put it into the unbound > + * workqueue. > + */ > + queue_work(system_unbound_wq, &cdw->work); Hmm, I'm a bit worried about this. Even with the system_unbound_wq some code may expect at least some progress being made with processing works during the initial enumeration. OTOH this does run pretty early on. Still I wonder if it would not be better to create + use our own workqueue for this ? I guess we can always do this if we run into issues later... With that said / otherwise the patch looks good to me: Reviewed-by: Hans de Goede Regards, Hans > + > + return true; > +} > + > +static int acpi_scan_clear_dep(struct acpi_dep_data *dep, void *data) > +{ > + struct acpi_device *adev = acpi_bus_get_acpi_device(dep->consumer); > > if (adev) { > adev->dep_unmet--; > - if (!adev->dep_unmet) > - acpi_bus_attach(adev, true); > + if (!acpi_scan_clear_dep_queue(adev)) > + acpi_dev_put(adev); > } > > list_del(&dep->node); > > >