* [PATCH] blk-cgroup: Reinit blkg_iostat_set after clearing in blkcg_reset_stats()
@ 2023-06-06 18:07 Waiman Long
2023-06-06 19:46 ` Tejun Heo
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Waiman Long @ 2023-06-06 18:07 UTC (permalink / raw)
To: Tejun Heo, Jens Axboe, Josef Bacik
Cc: cgroups, linux-block, linux-kernel, Ming Lei, Waiman Long
When blkg_alloc() is called to allocate a blkcg_gq structure
with the associated blkg_iostat_set's, there are 2 fields within
blkg_iostat_set that requires proper initialization - blkg & sync.
The former field was introduced by commit 3b8cc6298724 ("blk-cgroup:
Optimize blkcg_rstat_flush()") while the later one was introduced by
commit f73316482977 ("blk-cgroup: reimplement basic IO stats using
cgroup rstat").
Unfortunately those fields in the blkg_iostat_set's are not properly
re-initialized when they are cleared in v1's blkcg_reset_stats(). This
can lead to a kernel panic due to NULL pointer access of the blkg
pointer. The missing initialization of sync is less problematic and
can be a problem in a debug kernel due to missing lockdep initialization.
Fix these problems by re-initializing them after memory clearing.
Fixes: 3b8cc6298724 ("blk-cgroup: Optimize blkcg_rstat_flush()")
Fixes: f73316482977 ("blk-cgroup: reimplement basic IO stats using cgroup rstat")
Signed-off-by: Waiman Long <longman@redhat.com>
---
block/blk-cgroup.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
index 90c2efc3767f..48084321e3e0 100644
--- a/block/blk-cgroup.c
+++ b/block/blk-cgroup.c
@@ -636,8 +636,13 @@ static int blkcg_reset_stats(struct cgroup_subsys_state *css,
struct blkg_iostat_set *bis =
per_cpu_ptr(blkg->iostat_cpu, cpu);
memset(bis, 0, sizeof(*bis));
+
+ /* Re-initialize the cleared blkg_iostat_set */
+ u64_stats_init(&bis->sync);
+ bis->blkg = blkg;
}
memset(&blkg->iostat, 0, sizeof(blkg->iostat));
+ u64_stats_init(&blkg->iostat.sync);
for (i = 0; i < BLKCG_MAX_POLS; i++) {
struct blkcg_policy *pol = blkcg_policy[i];
--
2.31.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] blk-cgroup: Reinit blkg_iostat_set after clearing in blkcg_reset_stats()
2023-06-06 18:07 [PATCH] blk-cgroup: Reinit blkg_iostat_set after clearing in blkcg_reset_stats() Waiman Long
@ 2023-06-06 19:46 ` Tejun Heo
2023-06-07 1:28 ` Ming Lei
2023-06-07 13:52 ` Jens Axboe
2 siblings, 0 replies; 4+ messages in thread
From: Tejun Heo @ 2023-06-06 19:46 UTC (permalink / raw)
To: Waiman Long
Cc: Jens Axboe, Josef Bacik, cgroups, linux-block, linux-kernel,
Ming Lei
On Tue, Jun 06, 2023 at 02:07:24PM -0400, Waiman Long wrote:
> When blkg_alloc() is called to allocate a blkcg_gq structure
> with the associated blkg_iostat_set's, there are 2 fields within
> blkg_iostat_set that requires proper initialization - blkg & sync.
> The former field was introduced by commit 3b8cc6298724 ("blk-cgroup:
> Optimize blkcg_rstat_flush()") while the later one was introduced by
> commit f73316482977 ("blk-cgroup: reimplement basic IO stats using
> cgroup rstat").
>
> Unfortunately those fields in the blkg_iostat_set's are not properly
> re-initialized when they are cleared in v1's blkcg_reset_stats(). This
> can lead to a kernel panic due to NULL pointer access of the blkg
> pointer. The missing initialization of sync is less problematic and
> can be a problem in a debug kernel due to missing lockdep initialization.
>
> Fix these problems by re-initializing them after memory clearing.
>
> Fixes: 3b8cc6298724 ("blk-cgroup: Optimize blkcg_rstat_flush()")
> Fixes: f73316482977 ("blk-cgroup: reimplement basic IO stats using cgroup rstat")
> Signed-off-by: Waiman Long <longman@redhat.com>
Acked-by: Tejun Heo <tj@kernel.org>
Thanks.
--
tejun
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] blk-cgroup: Reinit blkg_iostat_set after clearing in blkcg_reset_stats()
2023-06-06 18:07 [PATCH] blk-cgroup: Reinit blkg_iostat_set after clearing in blkcg_reset_stats() Waiman Long
2023-06-06 19:46 ` Tejun Heo
@ 2023-06-07 1:28 ` Ming Lei
2023-06-07 13:52 ` Jens Axboe
2 siblings, 0 replies; 4+ messages in thread
From: Ming Lei @ 2023-06-07 1:28 UTC (permalink / raw)
To: Waiman Long
Cc: Tejun Heo, Jens Axboe, Josef Bacik, cgroups, linux-block,
linux-kernel
On Tue, Jun 06, 2023 at 02:07:24PM -0400, Waiman Long wrote:
> When blkg_alloc() is called to allocate a blkcg_gq structure
> with the associated blkg_iostat_set's, there are 2 fields within
> blkg_iostat_set that requires proper initialization - blkg & sync.
> The former field was introduced by commit 3b8cc6298724 ("blk-cgroup:
> Optimize blkcg_rstat_flush()") while the later one was introduced by
> commit f73316482977 ("blk-cgroup: reimplement basic IO stats using
> cgroup rstat").
>
> Unfortunately those fields in the blkg_iostat_set's are not properly
> re-initialized when they are cleared in v1's blkcg_reset_stats(). This
> can lead to a kernel panic due to NULL pointer access of the blkg
> pointer. The missing initialization of sync is less problematic and
> can be a problem in a debug kernel due to missing lockdep initialization.
>
> Fix these problems by re-initializing them after memory clearing.
>
> Fixes: 3b8cc6298724 ("blk-cgroup: Optimize blkcg_rstat_flush()")
> Fixes: f73316482977 ("blk-cgroup: reimplement basic IO stats using cgroup rstat")
> Signed-off-by: Waiman Long <longman@redhat.com>
> ---
> block/blk-cgroup.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
> index 90c2efc3767f..48084321e3e0 100644
> --- a/block/blk-cgroup.c
> +++ b/block/blk-cgroup.c
> @@ -636,8 +636,13 @@ static int blkcg_reset_stats(struct cgroup_subsys_state *css,
> struct blkg_iostat_set *bis =
> per_cpu_ptr(blkg->iostat_cpu, cpu);
> memset(bis, 0, sizeof(*bis));
> +
> + /* Re-initialize the cleared blkg_iostat_set */
> + u64_stats_init(&bis->sync);
> + bis->blkg = blkg;
> }
> memset(&blkg->iostat, 0, sizeof(blkg->iostat));
> + u64_stats_init(&blkg->iostat.sync);
>
> for (i = 0; i < BLKCG_MAX_POLS; i++) {
> struct blkcg_policy *pol = blkcg_policy[i];
Looks fine,
Reviewed-by: Ming Lei <ming.lei@redhat.com>
Thanks,
Ming
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] blk-cgroup: Reinit blkg_iostat_set after clearing in blkcg_reset_stats()
2023-06-06 18:07 [PATCH] blk-cgroup: Reinit blkg_iostat_set after clearing in blkcg_reset_stats() Waiman Long
2023-06-06 19:46 ` Tejun Heo
2023-06-07 1:28 ` Ming Lei
@ 2023-06-07 13:52 ` Jens Axboe
2 siblings, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2023-06-07 13:52 UTC (permalink / raw)
To: Tejun Heo, Josef Bacik, Waiman Long
Cc: cgroups, linux-block, linux-kernel, Ming Lei
On Tue, 06 Jun 2023 14:07:24 -0400, Waiman Long wrote:
> When blkg_alloc() is called to allocate a blkcg_gq structure
> with the associated blkg_iostat_set's, there are 2 fields within
> blkg_iostat_set that requires proper initialization - blkg & sync.
> The former field was introduced by commit 3b8cc6298724 ("blk-cgroup:
> Optimize blkcg_rstat_flush()") while the later one was introduced by
> commit f73316482977 ("blk-cgroup: reimplement basic IO stats using
> cgroup rstat").
>
> [...]
Applied, thanks!
[1/1] blk-cgroup: Reinit blkg_iostat_set after clearing in blkcg_reset_stats()
commit: 3d2af77e31ade05ff7ccc3658c3635ec1bea0979
Best regards,
--
Jens Axboe
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-06-07 13:52 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-06 18:07 [PATCH] blk-cgroup: Reinit blkg_iostat_set after clearing in blkcg_reset_stats() Waiman Long
2023-06-06 19:46 ` Tejun Heo
2023-06-07 1:28 ` Ming Lei
2023-06-07 13:52 ` Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox