Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp1885359lqe; Tue, 9 Apr 2024 03:32:38 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWl+GUMT+CYjNWKl6np71GA1DEMhJGBvI/uBAioO2XCIlcEq4GxlZjGJsRABljS5ORuJxr6boo2A4/hdackdX5opFSDUN75k3ipxbTA+g== X-Google-Smtp-Source: AGHT+IH3sElAF8ETmDPuZTEzz6gB5azl/+8u8mFmVo1Mt5815VG8tu8baHjBotmDGpHZVpLZ23/v X-Received: by 2002:a05:6870:3118:b0:22e:8954:79e0 with SMTP id v24-20020a056870311800b0022e895479e0mr13396823oaa.27.1712658758337; Tue, 09 Apr 2024 03:32:38 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712658758; cv=pass; d=google.com; s=arc-20160816; b=KHxM4uHrGzOKtjPnAyplEAUybVMixXgPXUFoTUQVGjQtzCHmKNX8A1Q0RnTQq6VwPV xjxCbo1ljIuW1JONnbzaWhT48Cfko4GYmmz3GVJD/Zn+DnFzpP+ysZwNta+bEevy23NC gy2ZWg050aBGdwVQHz6EsTZLIYwEG1TAdD19AQQVvX1Z35dZv7UMlUckiBfBkIx46Jmw Z795Y1A5OMfFik7lJgOTnWpdlH2Hzd1JUwnOtho93bKHe1dB5v6dvVlEPVbnMGKFieOT bqbVqnrZ7sXEWcWBlZuHNTNuB+ooYI6Ytk/s0hqOY1jgSSKx0+Wg1rwAVL/m90mt3mof 36gw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=E6wiRCdd89h1sVMfB48/ixg+/YiJUwbUXTRR0BuEf6E=; fh=TjBhBOoSoZ3DYqV26jPjQQrGsNQD+WHxaQ6me5uRbOs=; b=b4zEIqLPpYEZDtY7TtKjCLqf88xaLI6p+HTTQztVbVjhbNsMASsAj1zVG8NfEwGw9L eyUJ094sCHwwsXPQMgaYhyD2BxlfT+8NLYE/bpFyukXTBcBMByztluI7ken0t4pAQzLe jl9lpJ68sJlOCsoewlj9BaDr1llaoasSYsYvRgHA9+uJAHMoB7CqCptNIxVa6bBCTOIc Ss+17qiRiSUpN+DpwEJ57vw+5iwrv/kKsL+Rn10JW/iTQiX6FU+dShcz9yRpK2TBmDNV gdBmBGr4GmHG1uT7ZA76n/CU8I6qwRC2MGD1pPuZ49dTBYh3NDeD9QAEGlewAhov2uDE /u8Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SB08Rwjx; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-136680-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-136680-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id t31-20020a63535f000000b005dc80f256ccsi8442117pgl.849.2024.04.09.03.32.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 03:32:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-136680-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SB08Rwjx; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-136680-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-136680-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id D0BA7281E33 for ; Tue, 9 Apr 2024 10:32:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E065581729; Tue, 9 Apr 2024 10:32:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="SB08Rwjx" Received: from mail-oo1-f42.google.com (mail-oo1-f42.google.com [209.85.161.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 49D9A58119 for ; Tue, 9 Apr 2024 10:32:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712658751; cv=none; b=G4YWgdbkjk0l7bsikts7G6ymvOEFlUFrnPSZ6yUZ6HWjOvhp+9NjOzJ18ez1BCZnCnnfom4lntFzVABr5jj+XJ3CR8LUxejlGsQ6+WxONmVdIVqnnf6Ie76kY/4RK1iH+//YafxPcQT4fD5E3UoGdk/qcB7qnaiRXgixlYcZCDg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712658751; c=relaxed/simple; bh=UX9k3/oswSpfOSvNZcldfTNpVEuueE8+0oPvL3d72Ok=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=bgwmF7llq/Bn7WEB518QkionNPcALoLDyjA9IQTqYJgBNOJqPlCT1adaKzCy7A8S4Rgh9nXOD1gg6okMYkSim6r7/IBAWr3um3hKJGj39ptnJtElyyRJgIWorxy9Ia82in4KXUda6rnhU+C6qW23/vHidZYX3QC7T+D3ea8msrY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=SB08Rwjx; arc=none smtp.client-ip=209.85.161.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-oo1-f42.google.com with SMTP id 006d021491bc7-5aa16c0583eso1791465eaf.1 for ; Tue, 09 Apr 2024 03:32:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712658748; x=1713263548; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=E6wiRCdd89h1sVMfB48/ixg+/YiJUwbUXTRR0BuEf6E=; b=SB08Rwjxu7Ls+gAb3fV8ixQMYHqvxvETrfahPNf8G5XiVDnP/O0L8Rm2nPyxe4UysD qvQX/m7OYxot2c31tTYnz/aHRQSRqj6Be9GPAKx7hO85pLDdrIDqc+2gOCZp/TWTmpmx lRj7+bfGoUOyBrGQ1h4+Rvcvsn3wnW64R6nnTRjGWu/VpvVFy+wXWOVRJQRFGSvLDi8s YgDjsj6UUwsFeVHe9smE3OrBjYEzOLt/vyM30du/OJtX9vb2qiI3uQvt50E1svHuebCP 85V+aYa1LpXSdirkF94z9ZZMz6gtUMY8z3u+3oqpEx0VbkxjnidB1VW2f4WMk0uXzs5u hRfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712658748; x=1713263548; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=E6wiRCdd89h1sVMfB48/ixg+/YiJUwbUXTRR0BuEf6E=; b=qiMGLxPpMlkONtRSPVQkl87IcMarMd3kXCWDSOb989kD8SFzkPeNZUNvzvHcDjjQh1 4/NklkRC23aE0Wcz79HDf0wxozeQz1N4zogd2hwt5gyqzh44Xxu0t2B2+hS01omlY1l+ gzQ0j/tDpJkbDRP0cAyWQRYqiuBDaWJlCu8hXvJD04CVXtceOsL8qrf+Mxy5je54krVZ GUXtTmox8or2wAWHUsm+96RUc28xf+msSKSLOMERZxXSjvGQEuuvw2hrlDLJdFeja92u ISAi+3QvqgmSb64c+zjjCnATxf6bkhg76OTq3Cts9yNdTkztIXYazncZ74pSfT6dXe0u vk5w== X-Forwarded-Encrypted: i=1; AJvYcCUOUNyPEp8ftr8z4jvtA7NNoahihHA+FvwlFPnzA4AlKvH/ShaFg+9x9Q1UelmZ+vO4m0R2bIxlKUBZ1P9ld20EUOLbAEzMNyTePogW X-Gm-Message-State: AOJu0YwySryS3bwlZktmkMrq4u3OCH9wQDJ/RyQHMfFzP9HvKMJREkvZ a0+OqwtV1UCRZQmRLomY3GYpVZGMIrs3dmoBTnpwhpwyVuRP/oLpFQqVrxZbkDDkM2ljXjbVwRB 7 X-Received: by 2002:a05:6358:d3a7:b0:186:5f1:3827 with SMTP id mp39-20020a056358d3a700b0018605f13827mr11380787rwb.18.1712658748170; Tue, 09 Apr 2024 03:32:28 -0700 (PDT) Received: from localhost ([122.172.85.136]) by smtp.gmail.com with ESMTPSA id e1-20020a630f01000000b005f072084432sm7878536pgl.38.2024.04.09.03.32.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 03:32:27 -0700 (PDT) From: Viresh Kumar To: Vladimir Lypak , Viresh Kumar , Nishanth Menon , Stephen Boyd , Ulf Hansson , "Rafael J. Wysocki" Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , Thorsten Leemhuis , linux-kernel@vger.kernel.org Subject: [PATCH] OPP: Fix required_opp_tables for multiple genpds using same table Date: Tue, 9 Apr 2024 16:02:19 +0530 Message-Id: X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The required_opp_tables parsing is not perfect, as the OPP core does the parsing solely based on the DT node pointers. The core sets the required_opp_tables entry to the first OPP table in the "opp_tables" list, that matches with the node pointer. If the target DT OPP table is used by multiple devices and they all create separate instances of 'struct opp_table' from it, then it is possible that the required_opp_tables entry may be set to the incorrect sibling device. Unfortunately, there is no clear way to initialize the right values during the initial parsing and we need to do this at a later point of time. Cross check the OPP table again while the genpds are attached and fix them if required. Also add a new API for the genpd core to fetch the device pointer for the genpd. Cc: Thorsten Leemhuis Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=218682 Reported-by: Vladimir Lypak Co-developed-by: Vladimir Lypak Signed-off-by: Viresh Kumar --- Vladimir Lypak, Can you please give this a try and confirm that it fixes the issue. drivers/opp/core.c | 31 ++++++++++++++++++++++++++++++- drivers/pmdomain/core.c | 10 ++++++++++ include/linux/pm_domain.h | 6 ++++++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index e233734b7220..1f64b703b744 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -2394,7 +2394,8 @@ static void _opp_detach_genpd(struct opp_table *opp_table) static int _opp_attach_genpd(struct opp_table *opp_table, struct device *dev, const char * const *names, struct device ***virt_devs) { - struct device *virt_dev; + struct device *virt_dev, *gdev; + struct opp_table *genpd_table; int index = 0, ret = -EINVAL; const char * const *name = names; @@ -2427,6 +2428,34 @@ static int _opp_attach_genpd(struct opp_table *opp_table, struct device *dev, goto err; } + /* + * The required_opp_tables parsing is not perfect, as the OPP + * core does the parsing solely based on the DT node pointers. + * The core sets the required_opp_tables entry to the first OPP + * table in the "opp_tables" list, that matches with the node + * pointer. + * + * If the target DT OPP table is used by multiple devices and + * they all create separate instances of 'struct opp_table' from + * it, then it is possible that the required_opp_tables entry + * may be set to the incorrect sibling device. + * + * Cross check it again and fix if required. + */ + gdev = dev_to_genpd_dev(virt_dev); + if (!IS_ERR(gdev)) + return PTR_ERR(gdev); + + genpd_table = _find_opp_table(gdev); + if (!IS_ERR(genpd_table)) { + if (genpd_table != opp_table->required_opp_tables[index]) { + dev_pm_opp_put_opp_table(opp_table->required_opp_tables[index]); + opp_table->required_opp_tables[index] = genpd_table; + } else { + dev_pm_opp_put_opp_table(genpd_table); + } + } + /* * Add the virtual genpd device as a user of the OPP table, so * we can call dev_pm_opp_set_opp() on it directly. diff --git a/drivers/pmdomain/core.c b/drivers/pmdomain/core.c index 4215ffd9b11c..c40eda92a85a 100644 --- a/drivers/pmdomain/core.c +++ b/drivers/pmdomain/core.c @@ -184,6 +184,16 @@ static struct generic_pm_domain *dev_to_genpd(struct device *dev) return pd_to_genpd(dev->pm_domain); } +struct device *dev_to_genpd_dev(struct device *dev) +{ + struct generic_pm_domain *genpd = dev_to_genpd(dev); + + if (IS_ERR(genpd)) + return ERR_CAST(genpd); + + return &genpd->dev; +} + static int genpd_stop_dev(const struct generic_pm_domain *genpd, struct device *dev) { diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h index 772d3280d35f..f24546a3d3db 100644 --- a/include/linux/pm_domain.h +++ b/include/linux/pm_domain.h @@ -260,6 +260,7 @@ int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd, int pm_genpd_init(struct generic_pm_domain *genpd, struct dev_power_governor *gov, bool is_off); int pm_genpd_remove(struct generic_pm_domain *genpd); +struct device *dev_to_genpd_dev(struct device *dev); int dev_pm_genpd_set_performance_state(struct device *dev, unsigned int state); int dev_pm_genpd_add_notifier(struct device *dev, struct notifier_block *nb); int dev_pm_genpd_remove_notifier(struct device *dev); @@ -307,6 +308,11 @@ static inline int pm_genpd_remove(struct generic_pm_domain *genpd) return -EOPNOTSUPP; } +static inline struct device *dev_to_genpd_dev(struct device *dev) +{ + return ERR_PTR(-EOPNOTSUPP); +} + static inline int dev_pm_genpd_set_performance_state(struct device *dev, unsigned int state) { -- 2.31.1.272.g89b43f80a514