* [PATCH v2] PM: EM: Fix netlink performance-domain dump pagination
@ 2026-11-25 18:10 Shubhang Kaushik
2026-11-27 9:32 ` Lukasz Luba
0 siblings, 1 reply; 2+ messages in thread
From: Shubhang Kaushik @ 2026-11-25 18:10 UTC (permalink / raw)
To: Lukasz Luba, Rafael J. Wysocki, Len Brown, Pavel Machek,
Donald Hunter, Changwoo Min, Shubhang Kaushik, Christoph Lameter
Cc: Rafael J. Wysocki, linux-pm, stable, Shubhang Kaushik
GET_PERF_DOMAINS dumps performance domains through:
netlink_dump()
-> dev_energymodel_nl_get_perf_domains_dumpit()
-> for_each_em_perf_domain()
-> __em_nl_get_pd_for_dump()
The dump handler rebuilds its local cursor from cb->args[0] on each
callback. When the response skb fills, it returns -EMSGSIZE and the
netlink core sends the nonempty skb before retrying the dump. However,
the updated cursor is not saved in cb->args[0], so the retry restarts at
domain zero.
For example, if domains 0 and 1 fit in the first skb but domain 2 does
not, every subsequent callback emits domains 0 and 1 again and never
progresses beyond domain 2. The handler also advances the cursor before
encoding the domain and finalizes its partially encoded message on
failure.
Advance the cursor only after a domain has been encoded successfully,
cancel incomplete messages, and store the next domain index in
cb->args[0]. Return skb->len whenever data was written so netlink_dump()
sends the current chunk and continues the dump, propagating errors only
when skb->len is zero.
Fixes: 380ff27af25e ("PM: EM: Add dump to get-perf-domains in the EM YNL spec")
Cc: stable@vger.kernel.org
Signed-off-by: Shubhang Kaushik <sh@gentwo.org>
---
Changes in v2:
- Return skb->len whenever data has been written to the skb, propagating
negative error codes only when skb->len == 0.
Testing:
- Validated dev-energymodel YNL spec and exercised GET_PERF_DOMAINS
dumps via tools/net/ynl/pyynl/cli.py on an 80-core Ampere Altra,
including registering 4 test performance domains and forcing
per-domain -EMSGSIZE splits across multiple netlink_dump() chunks.
Link to v1: https://lore.kernel.org/r/20261124-pm-em-dump-v1-1-8f9167d437bc@gentwo.org
---
kernel/power/em_netlink.c | 26 ++++++++++++++++++++------
1 file changed, 20 insertions(+), 6 deletions(-)
diff --git a/kernel/power/em_netlink.c b/kernel/power/em_netlink.c
index 1f68d456a713c08d7a4f690e88c03182f6ee3ef1..4e85439ed76d240e013cf372dcbc77b3af28d598 100644
--- a/kernel/power/em_netlink.c
+++ b/kernel/power/em_netlink.c
@@ -80,19 +80,25 @@ static int __em_nl_get_pd_for_dump(struct em_perf_domain *pd, void *data)
void *hdr;
int ret;
- if (ctx->idx++ < ctx->start)
+ if (ctx->idx < ctx->start) {
+ ctx->idx++;
return 0;
+ }
info = genl_info_dump(ctx->cb);
hdr = genlmsg_iput(ctx->skb, info);
- if (!hdr) {
- genlmsg_cancel(ctx->skb, hdr);
+ if (!hdr)
return -EMSGSIZE;
- }
ret = __em_nl_get_pd(pd, ctx->skb);
+ if (ret) {
+ genlmsg_cancel(ctx->skb, hdr);
+ return ret;
+ }
+
genlmsg_end(ctx->skb, hdr);
- return ret;
+ ctx->idx++;
+ return 0;
}
struct em_nl_doit_ctx {
@@ -166,7 +172,15 @@ int dev_energymodel_nl_get_perf_domains_dumpit(struct sk_buff *skb,
.cb = cb,
};
- return for_each_em_perf_domain(__em_nl_get_pd_for_dump, &ctx);
+ int ret;
+
+ ret = for_each_em_perf_domain(__em_nl_get_pd_for_dump, &ctx);
+ cb->args[0] = ctx.idx;
+
+ if (ret && !skb->len)
+ return ret;
+
+ return skb->len;
}
static int __em_nl_get_pd_table_size(const struct em_perf_domain *pd)
---
base-commit: 4dce97c6c265544342e716e62fd24bbb232590c5
change-id: 20261124-pm-em-dump-00f32b88fd6c
Best regards,
--
Shubhang Kaushik <sh@gentwo.org>
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] PM: EM: Fix netlink performance-domain dump pagination
2026-11-25 18:10 [PATCH v2] PM: EM: Fix netlink performance-domain dump pagination Shubhang Kaushik
@ 2026-11-27 9:32 ` Lukasz Luba
0 siblings, 0 replies; 2+ messages in thread
From: Lukasz Luba @ 2026-11-27 9:32 UTC (permalink / raw)
To: Shubhang Kaushik, Shubhang Kaushik
Cc: Christoph Lameter, Changwoo Min, Donald Hunter, Pavel Machek,
Len Brown, Rafael J. Wysocki, Rafael J. Wysocki, linux-pm, stable
On 11/25/26 18:10, Shubhang Kaushik wrote:
> GET_PERF_DOMAINS dumps performance domains through:
>
> netlink_dump()
> -> dev_energymodel_nl_get_perf_domains_dumpit()
> -> for_each_em_perf_domain()
> -> __em_nl_get_pd_for_dump()
>
> The dump handler rebuilds its local cursor from cb->args[0] on each
> callback. When the response skb fills, it returns -EMSGSIZE and the
> netlink core sends the nonempty skb before retrying the dump. However,
> the updated cursor is not saved in cb->args[0], so the retry restarts at
> domain zero.
>
> For example, if domains 0 and 1 fit in the first skb but domain 2 does
> not, every subsequent callback emits domains 0 and 1 again and never
> progresses beyond domain 2. The handler also advances the cursor before
> encoding the domain and finalizes its partially encoded message on
> failure.
>
> Advance the cursor only after a domain has been encoded successfully,
> cancel incomplete messages, and store the next domain index in
> cb->args[0]. Return skb->len whenever data was written so netlink_dump()
> sends the current chunk and continues the dump, propagating errors only
> when skb->len is zero.
>
> Fixes: 380ff27af25e ("PM: EM: Add dump to get-perf-domains in the EM YNL spec")
> Cc: stable@vger.kernel.org
> Signed-off-by: Shubhang Kaushik <sh@gentwo.org>
> ---
> Changes in v2:
> - Return skb->len whenever data has been written to the skb, propagating
> negative error codes only when skb->len == 0.
>
> Testing:
> - Validated dev-energymodel YNL spec and exercised GET_PERF_DOMAINS
> dumps via tools/net/ynl/pyynl/cli.py on an 80-core Ampere Altra,
> including registering 4 test performance domains and forcing
> per-domain -EMSGSIZE splits across multiple netlink_dump() chunks.
>
> Link to v1: https://lore.kernel.org/r/20261124-pm-em-dump-v1-1-8f9167d437bc@gentwo.org
> ---
> kernel/power/em_netlink.c | 26 ++++++++++++++++++++------
> 1 file changed, 20 insertions(+), 6 deletions(-)
>
> diff --git a/kernel/power/em_netlink.c b/kernel/power/em_netlink.c
> index 1f68d456a713c08d7a4f690e88c03182f6ee3ef1..4e85439ed76d240e013cf372dcbc77b3af28d598 100644
> --- a/kernel/power/em_netlink.c
> +++ b/kernel/power/em_netlink.c
> @@ -80,19 +80,25 @@ static int __em_nl_get_pd_for_dump(struct em_perf_domain *pd, void *data)
> void *hdr;
> int ret;
>
> - if (ctx->idx++ < ctx->start)
> + if (ctx->idx < ctx->start) {
> + ctx->idx++;
> return 0;
> + }
>
> info = genl_info_dump(ctx->cb);
> hdr = genlmsg_iput(ctx->skb, info);
> - if (!hdr) {
> - genlmsg_cancel(ctx->skb, hdr);
> + if (!hdr)
> return -EMSGSIZE;
> - }
>
> ret = __em_nl_get_pd(pd, ctx->skb);
> + if (ret) {
> + genlmsg_cancel(ctx->skb, hdr);
> + return ret;
> + }
> +
> genlmsg_end(ctx->skb, hdr);
> - return ret;
> + ctx->idx++;
> + return 0;
> }
>
> struct em_nl_doit_ctx {
> @@ -166,7 +172,15 @@ int dev_energymodel_nl_get_perf_domains_dumpit(struct sk_buff *skb,
> .cb = cb,
> };
>
> - return for_each_em_perf_domain(__em_nl_get_pd_for_dump, &ctx);
> + int ret;
> +
> + ret = for_each_em_perf_domain(__em_nl_get_pd_for_dump, &ctx);
> + cb->args[0] = ctx.idx;
> +
> + if (ret && !skb->len)
> + return ret;
> +
> + return skb->len;
> }
>
> static int __em_nl_get_pd_table_size(const struct em_perf_domain *pd)
>
> ---
> base-commit: 4dce97c6c265544342e716e62fd24bbb232590c5
> change-id: 20261124-pm-em-dump-00f32b88fd6c
>
> Best regards,
That looks good, it should fix the skipping entry issues.
Thanks for the fix.
Reviewed-by: Lukasz Luba <lukasz.luba@arm.com>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-27 9:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25 18:10 [PATCH v2] PM: EM: Fix netlink performance-domain dump pagination Shubhang Kaushik
2026-11-27 9:32 ` Lukasz Luba
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox