Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp9919332rwp; Thu, 20 Jul 2023 11:39:43 -0700 (PDT) X-Google-Smtp-Source: APBJJlHVQOTulcyBwG99vGPpo84Jk0mTVYyTkiIX0ml++7bvTFZwh2RDzX9Pe+L2P0bDFDWhoqlD X-Received: by 2002:a05:6402:5249:b0:51e:5aac:6bad with SMTP id t9-20020a056402524900b0051e5aac6badmr6748173edd.11.1689878382847; Thu, 20 Jul 2023 11:39:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689878382; cv=none; d=google.com; s=arc-20160816; b=cdB/+D7VX3PeiEyIC8QJ3LXdRVIsLLXtftFaS8MhLo6RNHEgJTCrYwfpLSsjPlCR+4 hDo3wRRcdG8ixE/9qElu+Bv8DQ+HYa/LLrJLmve0V168q3xLd77EQSbc0yoCewX3Jx/0 BVeysUo3UAmv4JZp2KFbWI+aNgUsZ4NFFOLDBAEoHMVIU1krcRNDwH9B/14eSbm9ze4R 1m9FwCx+6a7JsmV5JoQm9VgbflB8MDmQIY7sTmeNRInc66IxtxsYmHSHqlN4IE5UO6VW MGVB4WUR7L3q5y0G48POttxaDE1xkPVkhXo0NNDK5uWPGxcMcZVDtCNGgyHuTaHL+EmT xV6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=u4VLuqs87NWGQCUTxtubMK/slyG8pf53VAnmuuijbec=; fh=MPBKgfLUjaqF5RbiOGgAiAyxH9hVBSpkI+VfjiS50sM=; b=UVO3QBWrmKMWDj2eeKX4XfNIrx2fTjny+oZwXyfBEjvrxBoIn58YUGSHv5U0/fqn1R lQ+g6HIKyH/PGKtl52e4rUCHMkw7bt8gd9q6vZR8ItF/odAfDTzhjzorMqUd5hA55dFa 51j6ELh4nDaG3YIM5yhzGqZk4Vcs/tNuRKDW4zhjBcRXSp7ZMZ3Ijt8RhDrJvnQM3NEB UJT51z6YeafeubKxFYNqV2a0kB2FTV5INJH4UUHd6oAMB8AmIKt5SENzw42NARt/lKbO N3zHT1coF/iV3qI+bMV4L7S+c05AYViqDQqrVl+erUjU6yXF7uN5P19l23bm2d8VKiTg uJZw== 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 u20-20020a056402111400b0051e0f7c1502si1076012edv.606.2023.07.20.11.39.17; Thu, 20 Jul 2023 11:39:42 -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 S232063AbjGTS2y convert rfc822-to-8bit (ORCPT + 99 others); Thu, 20 Jul 2023 14:28:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232034AbjGTS2x (ORCPT ); Thu, 20 Jul 2023 14:28:53 -0400 Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B09C135; Thu, 20 Jul 2023 11:28:52 -0700 (PDT) Received: by mail-ej1-f42.google.com with SMTP id a640c23a62f3a-991f9148334so31401666b.1; Thu, 20 Jul 2023 11:28:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689877730; x=1690482530; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dSLBVGx3HoP3RFoIMod2KbCcM9a83USRqNgkAkEojzk=; b=izNatHukOSk4Xo2qrDOE4Ysza0tF0iXH3qM1zhMLW04CliKcYhYGROQkJXecHlEHX6 0MBg9Tn7lpFl+t/BVy1mrDCntNCgYnHxvPsOtYAmUhrp2c+nazE+5KWxbHbLnLhXwHoJ ULaDJVV0s4xW54PgWqPekUyB6pbZr4HcL+s4kcQkHumKI1m4WoAR9kT/3op6WruW7ArP StJoaHnM9qY7XOMyodmpaRZDWKhX95JlObvkKy3irsNwNDIgz/0iqxEZXNSWOLpt7z3T 8Aw6H18BOzw63A+V3LS/zdawtTqOITixUrLUK+kVYtLM3KMup0vPN4/qa8wWLMcF0rZ5 HmRA== X-Gm-Message-State: ABy/qLaEDpp5AlZ7OV07AO02L8o0iCPASJ7cOF2HsYzlTDwKkhgdnRZY b/ixOhMLev/48RuhJsgA4K2T/TKi/Z5f0OAahzE= X-Received: by 2002:a17:906:5192:b0:994:1808:176b with SMTP id y18-20020a170906519200b009941808176bmr2803227ejk.6.1689877730287; Thu, 20 Jul 2023 11:28:50 -0700 (PDT) MIME-Version: 1.0 References: <20230718101726.1864761-1-cristian.marussi@arm.com> <20230718132028.wtycky4amu35xxcy@bogus> In-Reply-To: <20230718132028.wtycky4amu35xxcy@bogus> From: "Rafael J. Wysocki" Date: Thu, 20 Jul 2023 20:28:39 +0200 Message-ID: Subject: Re: [PATCH v2] powercap: arm_scmi: Remove recursion while parsing zones To: Sudeep Holla , Cristian Marussi Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org, james.quinlan@broadcom.com, f.fainelli@gmail.com, vincent.guittot@linaro.org, lukasz.luba@arm.com, "Rafael J . Wysocki" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT 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_BLOCKED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 Tue, Jul 18, 2023 at 3:20 PM Sudeep Holla wrote: > > On Tue, Jul 18, 2023 at 11:17:26AM +0100, Cristian Marussi wrote: > > Powercap zones can be defined as arranged in a hierarchy of trees and when > > registering a zone with powercap_register_zone(), the kernel powercap > > subsystem expects this to happen starting from the root zones down to the > > leaves; on the other side, de-registration by powercap_deregister_zone() > > must begin from the leaf zones. > > > > Available SCMI powercap zones are retrieved dynamically from the platform > > at probe time and, while any defined hierarchy between the zones is > > described properly in the zones descriptor, the platform returns the > > availables zones with no particular well-defined order: as a consequence, > > the trees possibly composing the hierarchy of zones have to be somehow > > walked properly to register the retrieved zones from the root. > > > > Currently the ARM SCMI Powercap driver walks the zones using a recursive > > algorithm; this approach, even though correct and tested can lead to kernel > > stack overflow when processing a returned hierarchy of zones composed by > > particularly high trees. > > > > Avoid possible kernel stack overflow by substituting the recursive approach > > with an iterative one supported by a dynamically allocated stack-like data > > structure. > > > > Cc: Rafael J. Wysocki > > Fixes: b55eef5226b7 ("powercap: arm_scmi: Add SCMI Powercap based driver") > > Makes sense, > > Acked-by: Sudeep Holla Applied as 6.6 material, thanks!