Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1198137rwd; Tue, 13 Jun 2023 06:15:40 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ40+5CdEfrj2aBf4UaJwO7EtV83ifoVe58JFJVd7UghPJWG54T878kVilxZ9ttOjLMoZSDo X-Received: by 2002:aa7:d804:0:b0:514:91bd:a967 with SMTP id v4-20020aa7d804000000b0051491bda967mr6595780edq.9.1686662140279; Tue, 13 Jun 2023 06:15:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686662140; cv=none; d=google.com; s=arc-20160816; b=0epjAtSy5l8cv23YqETtATdZOc7Q6uuEwWCiyLYWGUGTJUlx755ytSqNVQAMjm5DBL o2qLTc2lv2Vr0w1uKpdmKSLuB54jSrGxHFOBQgd4240j63V+7/5rIFHDXtjY+xpWlz2Y BrqmYDC+QvRxenXT6aHQk3GBdA/nRA2SVLGr1YW8lvYfxhmq49AdusJXJm84TODsNgg4 7uRbDzoi+NhyS+ZvyimtP9ZIy93l8Do510jwb2FBKEOi0nX1OCnlfq2swEtLeA6tujvf YXppn9IMK76LVVFfEakAMyXC1grql12+cUovvHqUphnQqFQjs7tNdAYx9NRuGsATEGJa IzXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=xL3SKjwiHCpd8kLBPoRyAkV9GFKfhsegjy/weRwTSYw=; b=lFEMmjKpeIdiNPcMmNDVeevnN2U1RrgDBxQSCsP+baDG4MEEKiUt+zZbPPL1oSan9b GvmQa6KZyVY8gOuziyGZ/eVzrDNMfMCtkXToohfauUnv2sNjthAmWCm4vVoz7DUyUigs gof6lBMBFOKcQKEk0FZ1NJlfqUwliWytRv4y+8uLCvVuCQ7Kj1397gWcMmavwUnKS10I zGAz0SDja260Y5GzWtZJ1HCyf15td6YcsQ0I41+CahAni9dr3BvQI31bf447LOKGzeob QbQGYm5WE4OR9XvgJcxUA+zr5e+2MrD/KBI3R4JhO1lZNZQCqORIZvBEJ9MOt2/nECGj dCxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernkonzept.com header.s=mx1 header.b=TMoFAiN5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernkonzept.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n25-20020a056402515900b005187ad3094esi286456edd.403.2023.06.13.06.15.14; Tue, 13 Jun 2023 06:15:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernkonzept.com header.s=mx1 header.b=TMoFAiN5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernkonzept.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242578AbjFMNB7 (ORCPT + 99 others); Tue, 13 Jun 2023 09:01:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242501AbjFMNBe (ORCPT ); Tue, 13 Jun 2023 09:01:34 -0400 Received: from mx.kernkonzept.com (serv1.kernkonzept.com [IPv6:2a01:4f8:1c1c:b490::2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7806019B1; Tue, 13 Jun 2023 06:01:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=kernkonzept.com; s=mx1; h=In-Reply-To:Content-Type:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Content-Transfer-Encoding:Reply-To: Content-ID:Content-Description; bh=xL3SKjwiHCpd8kLBPoRyAkV9GFKfhsegjy/weRwTSYw=; b=TMoFAiN5y9di+xneXdNc+1XQyA Oebum0Mk/l6qXAeAGIeqG01E6iM+kAZpnABB0/jimSicC2ILv1Dp0YQaNxVMJ9+y/5GikO646vewT 6UovqZo+xJL3b0fHB3FqTM2StsR8WVwaIgnV/ybjbSUVUyrRb6nw7G2Vxzrx9Zh9mf4nKReYZPrX2 ZSk7X7UzwxkRXTyAI0OF0wS4JwtoucggNdajvWHsuTCmI+0TtHwFR9UY6JxuMpvQdUu2ENS2LjqgJ AhdMxPfpws8vMFJYmprFE/xRVJ4pkV56pnhD4c21aLjoIiZXiUvaoebtgxHqZdxT9Ar9niur5MxKa t0MT18zg==; Received: from [10.22.3.24] (helo=kernkonzept.com) by mx.kernkonzept.com with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.94.2) id 1q93e2-000zHL-NE; Tue, 13 Jun 2023 15:01:10 +0200 Date: Tue, 13 Jun 2023 15:01:02 +0200 From: Stephan Gerhold To: Viresh Kumar Cc: Viresh Kumar , Nishanth Menon , Stephen Boyd , linux-pm@vger.kernel.org, Vincent Guittot , "Rafael J. Wysocki" , linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/2] OPP: Protect `lazy_opp_tables` list with `opp_table_lock` Message-ID: References: <167eb2bd947d9c04b0f6f1a5495ce4a99eeab598.1686210112.git.viresh.kumar@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 08, 2023 at 01:13:23PM +0530, Viresh Kumar wrote: > The `opp_table_lock` lock is already used to protect the list elsewhere, > use it while adding or removing entries from it. > > Reported-by: Stephan Gerhold > Signed-off-by: Viresh Kumar > --- > Stephan: Can you please give this a try ? Thanks, works fine for me. (Note that I don't have any races or corruption without this patch either so the testing result might not mean too much.) The patch also looks good! Tested-by: Stephan Gerhold > > drivers/opp/of.c | 14 ++++++++++++-- > 1 file changed, 12 insertions(+), 2 deletions(-) > > diff --git a/drivers/opp/of.c b/drivers/opp/of.c > index c740a907ef76..ac2179d5da4c 100644 > --- a/drivers/opp/of.c > +++ b/drivers/opp/of.c > @@ -21,7 +21,7 @@ > > #include "opp.h" > > -/* OPP tables with uninitialized required OPPs */ > +/* OPP tables with uninitialized required OPPs, protected by opp_table_lock */ > static LIST_HEAD(lazy_opp_tables); > > /* > @@ -148,7 +148,10 @@ static void _opp_table_free_required_tables(struct opp_table *opp_table) > > opp_table->required_opp_count = 0; > opp_table->required_opp_tables = NULL; > + > + mutex_lock(&opp_table_lock); > list_del(&opp_table->lazy); > + mutex_unlock(&opp_table_lock); > } > > /* > @@ -197,8 +200,15 @@ static void _opp_table_alloc_required_tables(struct opp_table *opp_table, > } > > /* Let's do the linking later on */ > - if (lazy) > + if (lazy) { > + /* > + * The OPP table is not held while allocating the table, take it > + * now to avoid corruption to the lazy_opp_tables list. > + */ > + mutex_lock(&opp_table_lock); > list_add(&opp_table->lazy, &lazy_opp_tables); > + mutex_unlock(&opp_table_lock); > + } > else > _update_set_required_opps(opp_table); > > -- > 2.31.1.272.g89b43f80a514 > -- Stephan Gerhold Kernkonzept GmbH at Dresden, Germany, HRB 31129, CEO Dr.-Ing. Michael Hohmuth