Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp694166pxj; Fri, 14 May 2021 13:19:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw55XSglxSJSOWtsbhZmsXwvW653pIwg7DmgST9saUL28qyUaDVKfAAH3BDDoq5u+q4aCSK X-Received: by 2002:a17:906:c1c9:: with SMTP id bw9mr51021837ejb.239.1621023552866; Fri, 14 May 2021 13:19:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621023552; cv=none; d=google.com; s=arc-20160816; b=Ko6vUHlAhu5LhW9pTS7abNgorXYfemyjaUHwxyEAhPWYbKnr5VDfkP3hP+j2pO0ge2 FV+xB6fBXihwkGBSbjUhEipRa0g6tjWDOm0GZlWByM4Id3qFpUYmeOPZAMRADnegt0wz YCTZ8TYBgPIDB936NegMFsXbG3F0H4SJWb8JQMSbapEW1Z52XGcsKjGyU538/+j0Ew83 62KmR2HLcYa+0NnoyCg+lvPAbVybn7EseToEfW2V3xSFvx5/Y4KLMtw3KDgx3p5iOeRH XebvPiR7Kid2idZeReUKSR4JuzmvfWvzlxb7VODO1oYWU5XA8oJmSOTtmc8vANx0AUEF xAWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=N6GbbFUH/VMpBMHoheQ0ldYJeT1OXV4JklGm9ik7JP4=; b=RfaP93ieLniumc/WMe0aF1a6vnCXcag0+ZpgAOGpcAu25TRdEofYk6Mz2TZN2uakaa idIOpZkg+9WKJ1jcAXXqiKKFSrpzK19hfxuVTiiWZaqaWSgIl+oEulbhNiJGQspXY5NK Rk4zXj2D/WR2oAhn7RuUk01qxOsdIcc/O3KP1brSfcO5+d1VCNdzskIG/wGojL1zPxI0 59k7/hNum/QngszIYziychjtHHC8qpUCdM/8HJ6gC4JFvT+5zsOp5y3cmSq4I67sD6H8 uvEZIv/wE+O/llZpngUm/Qmy17MF/Rcn5PDBpMvhzPQ3X86s7XsL3KDbv6IVeJdW0Bcd jRRQ== ARC-Authentication-Results: i=1; mx.google.com; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id js19si8950593ejc.277.2021.05.14.13.18.49; Fri, 14 May 2021 13:19:12 -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; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233680AbhENSe6 (ORCPT + 99 others); Fri, 14 May 2021 14:34:58 -0400 Received: from mail-ot1-f53.google.com ([209.85.210.53]:34577 "EHLO mail-ot1-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229952AbhENSe6 (ORCPT ); Fri, 14 May 2021 14:34:58 -0400 Received: by mail-ot1-f53.google.com with SMTP id u25-20020a0568302319b02902ac3d54c25eso96105ote.1 for ; Fri, 14 May 2021 11:33:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=N6GbbFUH/VMpBMHoheQ0ldYJeT1OXV4JklGm9ik7JP4=; b=hV2vFjB2wLo7eIFhqYJS+GLViaVmDeQ/efCW+I8QA53cZZUp1uGwLPKF3DUZzujznu lcCmkcw/VLeVKuE6mK8rLx8wa9jKomkWTjDihEfjmvg2mdYmzpBwoHtpedeIZ9tzDGN7 i56sfOiEc45rMre3z01WYRKmpSTIYILrWfqEZHgCuhe8Sh+JO1SoB18JrF7vozYylkBU MMjJUO2v8dhGlPMBhsOSSyvsgSKFE/V3w2oSKeY9829N5KGAMGvPoq6/PZtraLASif2Y prQUUYZSurbGfiZ+ziBj3aRjuqy5Vf8/GcXAUQy6S7hQlfT+YM0WCiTV8PJ5gynG1/qa FJuw== X-Gm-Message-State: AOAM531dvUoN3Tw6/UpX0kQ3GRUIEqjicLpqMfA3E0dEskciLDQHKh87 wkpvpybKiRuLhwEYMhXz2xHFdAAh5N12qJRNUlI= X-Received: by 2002:a05:6830:55b:: with SMTP id l27mr40664239otb.260.1621017224275; Fri, 14 May 2021 11:33:44 -0700 (PDT) MIME-Version: 1.0 References: <11761395.O9o76ZdvQC@kreacher> <4326215.LvFx2qVVIh@kreacher> In-Reply-To: From: "Rafael J. Wysocki" Date: Fri, 14 May 2021 20:33:33 +0200 Message-ID: Subject: Re: [PATCH v1 2/2] drivers: base: Reduce device link removal code duplication To: Saravana Kannan Cc: "Rafael J. Wysocki" , Greg Kroah-Hartman , LKML , "Rafael J. Wysocki" , chenxiang Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 14, 2021 at 6:05 PM Saravana Kannan wrote: > > On Fri, May 14, 2021 at 5:12 AM Rafael J. Wysocki wrote: > > > > From: Rafael J. Wysocki > > > > Reduce device link removal code duplication between the cases when > > SRCU is enabled and when it is disabled by moving the only differing > > piece of it (which is the removal of the link from the consumer and > > supplier lists) into a separate wrapper function (defined differently > > for each of the cases in question). > > > > No intentional functional impact. > > > > Signed-off-by: Rafael J. Wysocki > > --- > > drivers/base/core.c | 31 +++++++++++++------------------ > > 1 file changed, 13 insertions(+), 18 deletions(-) > > > > Index: linux-pm/drivers/base/core.c > > =================================================================== > > --- linux-pm.orig/drivers/base/core.c > > +++ linux-pm/drivers/base/core.c > > @@ -198,6 +198,12 @@ static void device_link_synchronize_remo > > { > > synchronize_srcu(&device_links_srcu); > > } > > + > > +static void device_link_remove_from_lists(struct device_link *link) > > +{ > > + list_del_rcu(&link->s_node); > > + list_del_rcu(&link->c_node); > > +} > > #else /* !CONFIG_SRCU */ > > static DECLARE_RWSEM(device_links_lock); > > > > @@ -232,6 +238,12 @@ int device_links_read_lock_held(void) > > static inline void device_link_synchronize_removal(void) > > { > > } > > + > > +static void device_link_remove_from_lists(struct device_link *link) > > +{ > > + list_del(&link->s_node); > > + list_del(&link->c_node); > > +} > > #endif /* !CONFIG_SRCU */ > > > > static bool device_is_ancestor(struct device *dev, struct device *target) > > @@ -854,7 +866,6 @@ out: > > } > > EXPORT_SYMBOL_GPL(device_link_add); > > > > -#ifdef CONFIG_SRCU > > static void __device_link_del(struct kref *kref) > > { > > struct device_link *link = container_of(kref, struct device_link, kref); > > @@ -864,25 +875,9 @@ static void __device_link_del(struct kre > > > > pm_runtime_drop_link(link); > > > > - list_del_rcu(&link->s_node); > > - list_del_rcu(&link->c_node); > > + device_link_remove_from_lists(link); > > Remind me again why we can't do the synchronize_srcu() here (I'm not > too familiar with the SRCU API semantics)? Is it because > synchronize_srcu() can take indefinitely long? Not indefinitely, but it may take time. And because it is not actually useful before we end up freeing the device link memory. And I'd rather not do it under the device links write lock. > I just vaguely remember > it does some checks during CPUs going idle (which can be a long time > later) but I'm not sure if that's the earliest you can synchronize. If > it's not indefinitely long and we just need to wait for other SRCU > critical sections to exit, maybe we can just synchronize here and make > the code a lot simpler? Well, maybe not "a lot". > This function is anyway called in a sleepable context. But I'm not sure how long this context expects to be sleeping and sleeping under a mutex potentially blocks others.