Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp502301imn; Tue, 26 Jul 2022 01:29:21 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sg3itGNrW43i1OU30DeBbT7LjIDTqICiO6X7ynU7P0nNKe99oCgMPp7uk8IEMEDgQCZ30s X-Received: by 2002:a17:903:d4:b0:16d:251e:5ac7 with SMTP id x20-20020a17090300d400b0016d251e5ac7mr15895374plc.56.1658824160942; Tue, 26 Jul 2022 01:29:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658824160; cv=none; d=google.com; s=arc-20160816; b=F69r0eHjWhXligYb5BmV+aebnTcI9xrXlEHqtXNHtq06eTq0Cu6zwbK/7cju6p0Xvn ezyQpcMbe9VfnWF7N0aVgcs48NzFYazKGAucWLZfc3OV7teBxJW2DHVsiakgYtVB6QHL HXl+65MVKH2vZ3ElYdsE4HJZvw2crG7dALSSJIxJE1hWkmtDFGCEPNkZcUKCFDqe6CKN s1MoTeOnNQaY35qEiWFkYkH+kX9scFu7ArsQ+dsLsVJ0Ae0/yF5fApEaaAACs8xDoMy0 B6+W22XKi4jRuTRq1P80bBzjkXjiz6ENIJCBeeb8uEfaKVs8m53iYzOyZZ/N/0td1q+x TYNQ== 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:dkim-signature; bh=wyyVAdF3KM6mtQMtcMn31iCQDsAAlD2jZ8xWGRIv5PU=; b=0RRuQbuPImI9KjpXzT6xJ22AQUYhbrIi9guPUMgYelq15PATQBhssVkYam4yK7KpKT m9EbkJW+vg55JlQLlJiX5w7dYnXZMrcW/eoGjjVGIsYyULStx2htGKMUh62VYsCq4aXj XOuDOjVGixwdRCjILRQSdDt2rBPly1GrRmjbOugdal7bfd/MrkDWKUjUeUHPlkCAqOFc 6r9Prb+YhNzEg4k5IWZb4eM+o4dtabiqzY3nsGpdekBO6wF93SoCp0D/CIxLJVltklkN k9Pdh4PKUoI2RT6RZI8Q/n/5b23upcvFA815hfTrDXhtER4ziv7skkQmFKE6kPuhY/Yd nepw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=IwyEOKsA; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o5-20020a6548c5000000b00410702fefc2si16812489pgs.390.2022.07.26.01.29.04; Tue, 26 Jul 2022 01:29:20 -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=@gmail.com header.s=20210112 header.b=IwyEOKsA; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238495AbiGZHer (ORCPT + 99 others); Tue, 26 Jul 2022 03:34:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238196AbiGZHeW (ORCPT ); Tue, 26 Jul 2022 03:34:22 -0400 Received: from mail-ua1-x92c.google.com (mail-ua1-x92c.google.com [IPv6:2607:f8b0:4864:20::92c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0EDCD2DA9E; Tue, 26 Jul 2022 00:31:59 -0700 (PDT) Received: by mail-ua1-x92c.google.com with SMTP id f3so5330024uaq.2; Tue, 26 Jul 2022 00:31:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=wyyVAdF3KM6mtQMtcMn31iCQDsAAlD2jZ8xWGRIv5PU=; b=IwyEOKsAA76Fy60siGlK0OwG8HyHG8TayGCD0MG+It7DGC/TaW22V0Qg9KLviTx2zm CLfl70Qm0rbWLCrvG3+yb8Znr/oHPjPAihh/6hjyEyRwtHXE3iE+MRjnRwvJhXoc9/zp imGWu08NIOzF0DmKfWYudtUITdDpW0oT8TGlo9O6WXztlzJLZu+H6DXhyraUNQKJkZPF 9jFuRYnILPDQ+UzR3khZJuICnZ4fSWHh0dTGaou0m0BeKMoAskD74b6k/lywfZW5epxZ zyUkyR2Fqa75hIHbzcNySLLqSTLSC3+U1AvqOUcr72HuQyg8njUV4iZZE6VUUo5qhxzG 7T1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=wyyVAdF3KM6mtQMtcMn31iCQDsAAlD2jZ8xWGRIv5PU=; b=rLJRSV5TlXy35S8C5n/Mdm2wTFQF4zuTz8eo1YlASbLwvlMyrDpKLdn+ddIDzzlKLr LnDlw2nmNr8RdDfXuzTyKP8IuNBYTLYvFC5l5ez7txBbSxu/ri0peNhLX/pi6vj4areY ZCkbYoboWy0HtseBF681/obN5WK961t+j/B7LR9fIbTl/F6EK5t1dVdyyRXdO9LX7NMc iHofAYoNXip04vMDC7VExvMePDeJ2cGX29hJW2pEuZOmVpycVvZprGyVOSgk5+uA76U3 5WGN9/yL5varIMi/oXzNgthwsx39jU4szkxRDzo3hbppOfBy9He8kMDw1hdpHM2/vGey hQ9Q== X-Gm-Message-State: AJIora9t17IysK8nAVX2cTCIwBNUXsgMO1Uhf3uAL6tvN1tG030K350m EReqs0vWGe7TOqWfpETI6tbNQsmTLVMjCKL1uOQ= X-Received: by 2002:ab0:2b06:0:b0:384:c4af:107c with SMTP id e6-20020ab02b06000000b00384c4af107cmr1423097uar.77.1658820719003; Tue, 26 Jul 2022 00:31:59 -0700 (PDT) MIME-Version: 1.0 References: <20220722084314.17816-1-di.shen@unisoc.com> In-Reply-To: From: Di Shen Date: Tue, 26 Jul 2022 15:31:48 +0800 Message-ID: Subject: Re: [PATCH V2 1/1] thermal/sysfs: Clear cooling_device_stats_attr_group before initialized To: "Rafael J. Wysocki" Cc: Di Shen , Daniel Lezcano , "Zhang, Rui" , Viresh Kumar , Amit Kucheria , Linux PM , Linux Kernel Mailing List , jeson.gao@unisoc.com, xuewen.yan@unisoc.com, ke.wang@unisoc.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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 Sat, Jul 23, 2022 at 1:18 AM Rafael J. Wysocki wrote: > > On Fri, Jul 22, 2022 at 10:44 AM Di Shen wrote: > > > > There's a space allocated for cooling_device_stats_attr_group > > within cooling_device_attr_groups. This space is shared by all > > cooling devices. > > That's correct. > > > If the stats structure of one cooling device successfully > > creates stats sysfs. After that, another cooling device fails > > to get max_states in cooling_device_stats_setup(). It can > > return directly without initializing the stats structure, but > > the cooling_device_stats_attr_group is still the attribute > > group of the last cooling device. > > I cannot parse the above, sorry. > > For example, how can a "stats structure of one cooling device" create > anything? As a data structure, it is a passive entity, so it doesn't > carry out any actions. > Sorry, I didn't describe it properly. I mean 'if it has been called back cooling_device_stats_setup() successfully for a cooling device'. > I think (but I am not sure) that you are referring to the error code > path in which the ->get_max_state() callback fails for a cooling > device after cooling_device_stats_setup() has completed successfully > for another one. > That's it. As you say, ->get_max_state() callback fails for a cooling device after cooling_device_stats_setup() has completed successfully for another one. > > At this time, read or write stats sysfs nodes can cause kernel > > crash. Like the following, kernel crashed when > > 'cat time_in_state_ms'. > > > > [<5baac8d4>] panic+0x1b4/0x3c8 > > [<9d287b0f>] arm_notify_die+0x0/0x78 > > [<094fc22c>] __do_kernel_fault+0x94/0xa4 > > [<3b4b69a4>] do_page_fault+0xd4/0x364 > > [<23793e7a>] do_translation_fault+0x38/0xc0 > > [<6e5cc52a>] do_DataAbort+0x4c/0xd0 > > [] __dabt_svc+0x5c/0xa0 > > [<747516ae>] _raw_spin_lock+0x20/0x60 > > [<9a9e4cd4>] time_in_state_ms_show+0x28/0x148 > > [] dev_attr_show+0x38/0x64 > > [] sysfs_kf_seq_show+0x8c/0xf0 > > [] seq_read+0x244/0x620 > > [] vfs_read+0xd8/0x218 > > [<3aebf5fa>] sys_read+0x80/0xe4 > > [<7cf100f5>] ret_fast_syscall+0x0/0x28 > > [<08cbe22f>] 0xbe8c1198 > > > > stats sysfs: > > phone:/sys/class/thermal/cooling_device2/stats # ls > > reset time_in_state_ms total_trans trans_table > > > > The same as cat total_trans, trans_table, and echo reset. > > > > To avoid kernel crash, this patch set clears the > > cooling_device_attr_groups before stats structure is initialized. > > > > Signed-off-by: Di Shen > > --- > > drivers/thermal/thermal_sysfs.c | 3 +++ > > 1 file changed, 3 insertions(+) > > > > diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c > > index 1c4aac8464a7..e3fae63fa0f7 100644 > > --- a/drivers/thermal/thermal_sysfs.c > > +++ b/drivers/thermal/thermal_sysfs.c > > @@ -817,6 +817,9 @@ static void cooling_device_stats_setup(struct thermal_cooling_device *cdev) > > unsigned long states; > > int var; > > > > + var = ARRAY_SIZE(cooling_device_attr_groups) - 2; > > + cooling_device_attr_groups[var] = NULL; > > + > > if (cdev->ops->get_max_state(cdev, &states)) > > return; > > > > -- -- Best regards, Di Di