Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp73190rwd; Tue, 6 Jun 2023 18:45:13 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4GKBbQR+33D9zFsOypVfz99oknkPCD2vAgc8fbn1e8gGofBeNh3KKr/OXn3SXUE6/BeybM X-Received: by 2002:a05:6830:1602:b0:6af:991d:126b with SMTP id g2-20020a056830160200b006af991d126bmr4264446otr.22.1686102313743; Tue, 06 Jun 2023 18:45:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686102313; cv=none; d=google.com; s=arc-20160816; b=OfA1eSLhVkAHND03sV4pSNCrfC1B3QooavdGv4g5Dcd+ClZ8fnymBKyxJCgfcEolOd y5pJzM/fa3sQcRq+kUuXr1DbK/7ZSzfRnO/pEEaJ1ROC/xJwEpBj6pREwKn/sF2OLA5D QZyA0B4WLh5jbanmR0lCrYzyaQGBUz++abYGomGHXHCzfzM92H2PPlIt/SyvedgaSGbT 3QQwKCUTuNhjcehLlvpjY106sy19SiG5c3EyDrIAAqpkweYqjfK6a//Z4zAJVGTMkfN7 N6GCRnn5Ov0U1dUFJOsa2ZauF5BWTcj7Qm+uogQD1Xoowudb3rUIlGOs8ChFKVZLF5QS 0Dig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=1h0nXm4obQWr/nMN17xlxThI6u2crQzlPISlM1jWir0=; b=yYaBQxWu0ZRDLyIkzu6V26E7My8jL/M5YMgyHCEmQYh3Obi9I2WML0pK9cUJQXu27P F2VFFJ9aR5STq4SqNq6d+GFlG9lsf/FZlLcPiXKxj3eMK1CgL3OSYFswHLNO+CJ7HneS nh+94TbBGMJwiSz9PBnvVv/ELQ11ARItnwwwHQAqXcfaqwOH+U5zZm+VFypOK8qLr+9K Y93x6oTFi/+Y1TMOU2tK1OdmIOVYAc4d4uQ07kzoAIhQeLB4NX0g27arKaFdQf32vDcI vcXFF6/wtCeG3wAQrjwxu+6bxc/EVqgzkNPmva25JIBBSUHxEh9Zx6Huc48bpDTG2ka8 JcVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XaAwKWI8; 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=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y72-20020a62644b000000b006434e20d01asi7781606pfb.199.2023.06.06.18.44.59; Tue, 06 Jun 2023 18:45:13 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XaAwKWI8; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240467AbjFGB3M (ORCPT + 99 others); Tue, 6 Jun 2023 21:29:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240383AbjFGB3I (ORCPT ); Tue, 6 Jun 2023 21:29:08 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E88AB1984 for ; Tue, 6 Jun 2023 18:28:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686101300; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=1h0nXm4obQWr/nMN17xlxThI6u2crQzlPISlM1jWir0=; b=XaAwKWI8M34st32pDbwA7SxRgVZ813Ujx0f0R6yXS5VQ3Nb/7TkkY2TtQ9OB1A5Bs7rTZg H1JeEA47bkMUCZuN0+OPdGJM1FFV8I46CgFBDrApLt8ESwg4YkskKGzssqp5yISTiVLyA3 KTx/yUieOnRU3OVXpzVqDqye3iMwh5Y= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-583-ITxAbywmO4unISCQRha-2w-1; Tue, 06 Jun 2023 21:28:17 -0400 X-MC-Unique: ITxAbywmO4unISCQRha-2w-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1DEC5801182; Wed, 7 Jun 2023 01:28:17 +0000 (UTC) Received: from ovpn-8-23.pek2.redhat.com (ovpn-8-23.pek2.redhat.com [10.72.8.23]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E961440D1B66; Wed, 7 Jun 2023 01:28:12 +0000 (UTC) Date: Wed, 7 Jun 2023 09:28:08 +0800 From: Ming Lei To: Waiman Long Cc: Tejun Heo , Jens Axboe , Josef Bacik , cgroups@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] blk-cgroup: Reinit blkg_iostat_set after clearing in blkcg_reset_stats() Message-ID: References: <20230606180724.2455066-1-longman@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230606180724.2455066-1-longman@redhat.com> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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, 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 > --- > 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 Thanks, Ming