Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp849481imi; Fri, 22 Jul 2022 10:49:18 -0700 (PDT) X-Google-Smtp-Source: AGRyM1szXCmwzZ748T7M9pV7IW0AtD/svBk5F6U0ERQWRTZT8wA2yPD5fwZDKoJJod+0SmtMOCEi X-Received: by 2002:a17:902:d711:b0:16d:1665:1162 with SMTP id w17-20020a170902d71100b0016d16651162mr657666ply.5.1658512158185; Fri, 22 Jul 2022 10:49:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658512158; cv=none; d=google.com; s=arc-20160816; b=b9KrdUeO5of7gYrDG4A1x3cg03Tw2hTWwmGdiLMIDsUnlD7yLS/Imcb2jxOcFlqp+7 D0olKUOYxAWl9vU08TS2Wnios0mkpNmseOJaZFINgOqD+m3jSXZkPxjqUZocqokrmV2L KwjLz/uVWPhRPQBq1U29klLIutwolkuBNjLj1AicY6n13fZboq4wdD8/UPvbD6NMhTHQ q1Rjpin4T0JALxWfq5tCjY8EcTCfgiawevwiqCVZ6Mjh0wOrRHs7JZOQIUVnfZz86BHA VwBd+6Z/Tb95LmG7qBjDjfQzkpVCg9z8Wv8ddcEj8zVmE9BDNSvSySQ1U+RfGIPe0bQP Fa7w== 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=XPCuVtxNHlRTKlO2xHRASVydOgpgbtbD+QagU1qAmdw=; b=ctnY7ZAzRKVfFBwq6Y5Kk/HiDq6VqJoI7Ad0F385OVETwsDoJ37G5MK72n2VlJ1ojo c0wDOD8sLJp1OUNLOvoXr/YaJ05mxWSB5GLM09VCPj82XKoLmFXJsrizLn1A8O74eeFF ipE6oJw6mzBzgS0JZB01jH+n441Dp+TAv2DkbONHpf9OebDxBmo8Nc/Z06VqW+WaRSmr G97CYQmefJJmsqhxOG51ISOT8zTzykEY68piN2GzaedFQ4yHtFG+pJCedAeAn1TWv11u c285LWlV3VPOkJuc5skgF7lvDNp/KqlabYsB1Nt5u3AnMiv/DVv8DU1qHEZ1jrWZ/sgf BiZg== ARC-Authentication-Results: i=1; mx.google.com; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 126-20020a630284000000b00412ac5a482csi6429381pgc.854.2022.07.22.10.49.03; Fri, 22 Jul 2022 10:49:18 -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; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236038AbiGVRS6 (ORCPT + 99 others); Fri, 22 Jul 2022 13:18:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235584AbiGVRS5 (ORCPT ); Fri, 22 Jul 2022 13:18:57 -0400 Received: from mail-yb1-f173.google.com (mail-yb1-f173.google.com [209.85.219.173]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16DD31CFDD; Fri, 22 Jul 2022 10:18:57 -0700 (PDT) Received: by mail-yb1-f173.google.com with SMTP id r3so9115324ybr.6; Fri, 22 Jul 2022 10:18:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=XPCuVtxNHlRTKlO2xHRASVydOgpgbtbD+QagU1qAmdw=; b=E0nwYNvI+c9quWZTSwOlaQIz4pxQSrj+7jYBh82UKaXW4U+LszwK/gzPXV3ppfwDTs UdLeecCLIFFy6c1yIYvTmC0ix6HUwvFcUxe2GL6zD8T/mNce6rF3dEZn8xHAT464e3lQ s8c+XW6KEnrhQWPKj4hXpJ8y+7nwhs/c1UWgNcdjnx46QlhNasDHnG8Lht36LW1qP8eG BUemZgjvIsGIQJ4CseeW7SGdwyFTYzeN87PlQ6df8fk9gf4V2pO0i1G83gdSazQ04hD7 VD8g4HU4FovGlgJWL07HLmJnr/rBFhdSqzewGUGASupHko8Z+EorrmVparToIyDG0/A2 9wow== X-Gm-Message-State: AJIora+WYj9MFP/NYbPMVI31yxJU794LzFTY5aTPEHdym8ww7VOyAxYJ sW3c9qHSf+NtsR2zw9sSq+EDCdBJ1ytKAye3CgA= X-Received: by 2002:a25:828f:0:b0:670:22f9:f7eb with SMTP id r15-20020a25828f000000b0067022f9f7ebmr879346ybk.137.1658510336244; Fri, 22 Jul 2022 10:18:56 -0700 (PDT) MIME-Version: 1.0 References: <20220722084314.17816-1-di.shen@unisoc.com> In-Reply-To: <20220722084314.17816-1-di.shen@unisoc.com> From: "Rafael J. Wysocki" Date: Fri, 22 Jul 2022 19:18:42 +0200 Message-ID: Subject: Re: [PATCH V2 1/1] thermal/sysfs: Clear cooling_device_stats_attr_group before initialized To: Di Shen Cc: "Rafael J. Wysocki" , Daniel Lezcano , "Zhang, Rui" , Viresh Kumar , Amit Kucheria , Linux PM , Linux Kernel Mailing List , jeson.gao@unisoc.com, xuewen.yan@unisoc.com, cindygm567@gmail.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no 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 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. 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. > 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; > > --