From nobody Sun Dec 14 20:19:49 2025 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (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 D1444233D93 for ; Mon, 13 Jan 2025 11:23:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736767422; cv=none; b=qqHS6S74amMhV7v3HNyWjA5MbJVYcCoXpMlS/pkkbA9MnLEfKQ4JfnKfmmHqPhheaf0MT9vRnS9hePAxGZUKcWfLa9KV1cygIFqzBjn6lPx1gXb5/WfT8VgoahbPjrdcCn5hcudo+n85DXZTmLc/CAS6zZdvJKowBM56BuKT3gQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736767422; c=relaxed/simple; bh=56mpvPQsiCQvJ/qI37RI+kZkMobzbPxSKcp097e99C8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=lD7MmgtyTSQm9aU+bS7HqfFBXCTpvA/yiJGFLYA6q+y0xl5ZnKWJ4fDfJ3O3yxz9X3eO2SS+I52+i4zN9gukbYW2aB3+DZtrUaBzsHU0CtanJkXDUgVWUXEv5yD0dVYlfpnr+ebYFJtyL1pFbdwaJHmZclvL9A5J5JJJ4bC90uw= 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=zoeaKhat; arc=none smtp.client-ip=209.85.214.172 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="zoeaKhat" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-21634338cfdso51826295ad.2 for ; Mon, 13 Jan 2025 03:23:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1736767420; x=1737372220; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=pmCuXoJnBUxtp5/I8iV1DHcowuAM2GwBiNr+w7VeFWg=; b=zoeaKhatTn+ifIZiMkiG2j3DLP9fbpPpk/U28EA1lb7I2Au78wzJLNSS3m5WKglEd2 9dMU481X27b/tKaZ1JLrX1aw/4YILbogxGzTyXmUkpRFkdiGk/kWhjOBIb5z0cFdtN6o Hiy2mlXsB+f+dIQiq+ZxAie3NmU53tG6uwdi7EhvmZ6yKdqoF3M0x0SG6giN6D3wmHxN i89EHQ2YVicFju0SFWT8mA3piMSCQ+FKuXVXlE5up2ZVkU7wh5Wba3kmk3C1rmkdidyv ejUZMYUK32/rU/ybsMgmHl0KP9s9GZubI2cpdV6+X9QsLVuS+8IM2N2x33cnUfi2zLb/ Elkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736767420; x=1737372220; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pmCuXoJnBUxtp5/I8iV1DHcowuAM2GwBiNr+w7VeFWg=; b=KV6LK8oeXdaYzVk/aipFiszT3/IGaZ4k2o67VoamVIIoSMX2xh4BzjCYFJCC+vss4L xVJs1WaVHfxzpxu3y2m672EPG2ArXGlB6PwxV9dOkK8FsL9hugjfBK5l7B/0UDEkVCjV H3c9mM8CS/4b9npn67r7bFwWUY9HziuK9WaulDCtMNT7qKzReh5z+JrWJbtWK96QLnk1 N9wCV7RLMb/X6af1fJc9qM3weyUiizDLPfQ1z6N6jNeO7f5KBOW1j2Kmy+C7G+O10AGs LHt87b4z7ETDl0t9XbsHUbdrybs8pY0MAxaDDRC6qXei4D0lLGx+eWVoL8HwcVKDOeyS hdjg== X-Forwarded-Encrypted: i=1; AJvYcCUT4Ecv4NxDMbrp6lFpxf7hkcbZb0I0ziH+ak6J90UfSjo7T264AqKmNGPD6a4lmtNlV3RNddlmYw7r8Zk=@vger.kernel.org X-Gm-Message-State: AOJu0YyThw7wXdMFI+ha/yqZp+GnNmwseaKWXe2eKo9vOnowiWTDVwpx bPiPnsgpJnT4XlR7PS4Mz4kWauJyfwidNPipsekeKXXZpAwvubuGGKKdnk78iA8= X-Gm-Gg: ASbGncsL5aYyvwsGxEU4dqFGe9SWG6kvt028Dm1plC/1r7fQ/SRwhWBy8Ust/+1n+/b sXrlqdOYwXIR2xXWYwzgR8TL4y+6oJakRxc8OqzlyyPePzJOZC5+N4V//AsmfWTyCrxtnmByf1J L/Puli5fiiMqvUl76FTMcfTtTXSXmgTI4iaFlqH2vhXiCxS/eqMrWc/1Lhzf1OP7wshdplToBO7 YSsuVXf1O+wyBBkj5IARdozO+QM53WMskyAb0zGmygnopl5Od3GgnzHYjQ= X-Google-Smtp-Source: AGHT+IEBqAU9m/Dz1cRS0HnmcowXNpNvmSNlZypDvYg39Eu5fhkkroa7r15wE1tObjFtw/U6RyJuJQ== X-Received: by 2002:a17:902:f70f:b0:216:32ea:c84b with SMTP id d9443c01a7336-21a83fc3652mr310297025ad.37.1736767420205; Mon, 13 Jan 2025 03:23:40 -0800 (PST) Received: from localhost ([122.172.84.139]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21a9f10f860sm51777815ad.46.2025.01.13.03.23.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 03:23:39 -0800 (PST) From: Viresh Kumar To: "Rafael J. Wysocki" , Viresh Kumar , Nishanth Menon , Stephen Boyd , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org Subject: [PATCH V7 02/16] PM / OPP: Add reference counting helpers for Rust implementation Date: Mon, 13 Jan 2025 16:52:57 +0530 Message-Id: X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" To ensure that resources such as OPP tables or OPP nodes are not freed while in use by the Rust implementation, it is necessary to increment their reference count from Rust code. This commit introduces a new helper function, dev_pm_opp_get_opp_table_ref(), to increment the reference count of an OPP table and declares the existing helper dev_pm_opp_get() in pm_opp.h. Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 17 ++++++++++++----- drivers/opp/opp.h | 1 - include/linux/pm_opp.h | 6 ++++++ 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index be3291b53719..73e9a3b2f29b 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -1528,11 +1528,6 @@ static struct opp_table *_allocate_opp_table(struct = device *dev, int index) return ERR_PTR(ret); } =20 -void _get_opp_table_kref(struct opp_table *opp_table) -{ - kref_get(&opp_table->kref); -} - static struct opp_table *_update_opp_table_clk(struct device *dev, struct opp_table *opp_table, bool getclk) @@ -1693,6 +1688,17 @@ static void _opp_table_kref_release(struct kref *kre= f) kfree(opp_table); } =20 +void _get_opp_table_kref(struct opp_table *opp_table) +{ + kref_get(&opp_table->kref); +} + +void dev_pm_opp_get_opp_table_ref(struct opp_table *opp_table) +{ + _get_opp_table_kref(opp_table); +} +EXPORT_SYMBOL_GPL(dev_pm_opp_get_opp_table_ref); + void dev_pm_opp_put_opp_table(struct opp_table *opp_table) { kref_put_mutex(&opp_table->kref, _opp_table_kref_release, @@ -1727,6 +1733,7 @@ void dev_pm_opp_get(struct dev_pm_opp *opp) { kref_get(&opp->kref); } +EXPORT_SYMBOL_GPL(dev_pm_opp_get); =20 void dev_pm_opp_put(struct dev_pm_opp *opp) { diff --git a/drivers/opp/opp.h b/drivers/opp/opp.h index 430651e7424a..5c7c81190e41 100644 --- a/drivers/opp/opp.h +++ b/drivers/opp/opp.h @@ -250,7 +250,6 @@ struct opp_table { }; =20 /* Routines internal to opp core */ -void dev_pm_opp_get(struct dev_pm_opp *opp); bool _opp_remove_all_static(struct opp_table *opp_table); void _get_opp_table_kref(struct opp_table *opp_table); int _get_opp_count(struct opp_table *opp_table); diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h index 414146abfe81..c247317aae38 100644 --- a/include/linux/pm_opp.h +++ b/include/linux/pm_opp.h @@ -100,6 +100,7 @@ struct dev_pm_opp_data { #if defined(CONFIG_PM_OPP) =20 struct opp_table *dev_pm_opp_get_opp_table(struct device *dev); +void dev_pm_opp_get_opp_table_ref(struct opp_table *opp_table); void dev_pm_opp_put_opp_table(struct opp_table *opp_table); =20 unsigned long dev_pm_opp_get_bw(struct dev_pm_opp *opp, bool peak, int ind= ex); @@ -160,6 +161,7 @@ struct dev_pm_opp *dev_pm_opp_find_bw_ceil(struct devic= e *dev, struct dev_pm_opp *dev_pm_opp_find_bw_floor(struct device *dev, unsigned int *bw, int index); =20 +void dev_pm_opp_get(struct dev_pm_opp *opp); void dev_pm_opp_put(struct dev_pm_opp *opp); =20 int dev_pm_opp_add_dynamic(struct device *dev, struct dev_pm_opp_data *opp= ); @@ -205,6 +207,8 @@ static inline struct opp_table *dev_pm_opp_get_opp_tabl= e_indexed(struct device * return ERR_PTR(-EOPNOTSUPP); } =20 +static inline void dev_pm_opp_get_opp_table_ref(struct opp_table *opp_tabl= e) {} + static inline void dev_pm_opp_put_opp_table(struct opp_table *opp_table) {} =20 static inline unsigned long dev_pm_opp_get_bw(struct dev_pm_opp *opp, bool= peak, int index) @@ -341,6 +345,8 @@ static inline struct dev_pm_opp *dev_pm_opp_find_bw_flo= or(struct device *dev, return ERR_PTR(-EOPNOTSUPP); } =20 +static inline void dev_pm_opp_get(struct dev_pm_opp *opp) {} + static inline void dev_pm_opp_put(struct dev_pm_opp *opp) {} =20 static inline int --=20 2.31.1.272.g89b43f80a514