Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3372048pxb; Wed, 13 Oct 2021 04:48:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxO/rCEPdtl8pmajErm9pxtc+3USBsFS6HkEQKUTrvDq9RmZl2M44vEXjgBpt5Rig9ViRIW X-Received: by 2002:a17:90a:b314:: with SMTP id d20mr13074497pjr.174.1634125721531; Wed, 13 Oct 2021 04:48:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634125721; cv=none; d=google.com; s=arc-20160816; b=mAthMKY7jseLowoNbAejnjcf8fGD9VFB6ZUSPWUwacrI7nD9hdJcLD5DwkVN0TrIP2 dNjwHIxpYJsI/jCll0D46FdO0iZSeL/Q+CiO2x0iFyIXlA9qgSCu28fHRvDHE0NzpUYy Wjg705OKeuQAXJvDsQZB91jBniCAxgUBjnOMS/6iuRDcBnC2sbImAkYI+9SF7PNzBySl mUhIP9yylD6frRJuxqVfimkWmMRN3ef2f7baymXMHhG72R+6Fr4u7ThYrQCyGIlTeNFQ wZs/TSdf8FU+pkfJojCdqVZKGgpKZ7VlyDbih+rYc/LYv9yH70PAOH9ca3S4oM+24XGq ukhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:references:cc:to:from :subject; bh=vZlaAnKHEp86pNIQd6Gjjh0BK5qZE07/46bg3qBDr5Y=; b=aEjrAyVJFRxHM8YUOIzlbW4v5jxxkPnFh4gU9ei6URcbSJR8fCzXIyxNBUI/8in3CU eeCa+MZaE/D0kpFihK1KzC0iN0wPiTUejLIFhiZ+Sp7eYqcaP9pyPYMN6JHZN0GcK9vf weFDrAUQPgln9ukwlYK79uOIPYiUwVoJ6Y2HRwBQZvyiORKrcENIZBeTmTBUvYu6N6GN 4mw1+P01sUmeZQiHvV+bfsSQUTnV8TK7tNxpqDCCCmb7ChHWPbSdd+1qAJ0dbwTFDG/x 434nCjh7F+d/kPYfZqApX1fGE506ZQn6m/tt4Ul4TAbvwrn3oZyusGi1nmY+w5X6PqR5 md6g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l64si17550493pgd.574.2021.10.13.04.48.28; Wed, 13 Oct 2021 04:48:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231145AbhJMLta (ORCPT + 99 others); Wed, 13 Oct 2021 07:49:30 -0400 Received: from szxga03-in.huawei.com ([45.249.212.189]:25182 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229571AbhJMLta (ORCPT ); Wed, 13 Oct 2021 07:49:30 -0400 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.57]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4HTrMs4sSqz8tdj; Wed, 13 Oct 2021 19:46:17 +0800 (CST) Received: from dggema762-chm.china.huawei.com (10.1.198.204) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2308.8; Wed, 13 Oct 2021 19:47:24 +0800 Received: from [10.174.176.73] (10.174.176.73) by dggema762-chm.china.huawei.com (10.1.198.204) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.8; Wed, 13 Oct 2021 19:47:24 +0800 Subject: Re: [PATCH] blk-cgroup: check blkcg policy is enabled in blkg_create() From: "yukuai (C)" To: Tejun Heo CC: , , , , References: <20211008072720.797814-1-yukuai3@huawei.com> <9d9ac88b-43e6-5b50-bc0b-98ad4704eca5@huawei.com> Message-ID: <68bd1b2c-f4a6-664c-0812-30cb458d0f15@huawei.com> Date: Wed, 13 Oct 2021 19:47:23 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <9d9ac88b-43e6-5b50-bc0b-98ad4704eca5@huawei.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.176.73] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggema762-chm.china.huawei.com (10.1.198.204) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021/10/12 9:39, yukuai (C) wrote: > On 2021/10/12 1:16, Tejun Heo wrote: >> On Fri, Oct 08, 2021 at 03:27:20PM +0800, Yu Kuai wrote: >>> diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c >>> index eb48090eefce..00e1d97621ea 100644 >>> --- a/block/blk-cgroup.c >>> +++ b/block/blk-cgroup.c >>> @@ -226,6 +226,20 @@ struct blkcg_gq *blkg_lookup_slowpath(struct >>> blkcg *blkcg, >>>   } >>>   EXPORT_SYMBOL_GPL(blkg_lookup_slowpath); >>> +static void blkg_check_pd(struct request_queue *q, struct blkcg_gq >>> *blkg) >>> +{ >>> +    int i; >>> + >>> +    for (i = 0; i < BLKCG_MAX_POLS; i++) { >>> +        struct blkcg_policy *pol = blkcg_policy[i]; >>> + >>> +        if (blkg->pd[i] && !blkcg_policy_enabled(q, pol)) { >>> +            pol->pd_free_fn(blkg->pd[i]); >>> +            blkg->pd[i] = NULL; >>> +        } >>> +    } >>> +} >>> + >>>   /* >>>    * If @new_blkg is %NULL, this function tries to allocate a new one as >>>    * necessary using %GFP_NOWAIT.  @new_blkg is always consumed on >>> return. >>> @@ -252,6 +266,9 @@ static struct blkcg_gq *blkg_create(struct blkcg >>> *blkcg, >>>           goto err_free_blkg; >>>       } >>> +    if (new_blkg) >>> +        blkg_check_pd(q, new_blkg); >>> + >> >> Can't this happen the other way around too? ie. Linking a pd which >> doesn't >> have an entry for a policy which got enabled inbetween? And what if an >> existing policy was de-registered and another policy got the policy id >> inbetween? I think the correct solution here would be synchronizing >> alloc - >> create blocks against policy deactivation rather than trying to patch an >> allocated blkg later. Deactivation being a really slow path, there are >> plenty of options. The main challenge would making it difficult to make >> mistakes with, I guess. > > For the case policy was de-registered, I think there won't be a problem > because pd_init_fn() is not called yet, and the blkg is not at > blkg_list, it's fine to use this blkg for the new policy. > > For the case policy got enabled inbetween, the problem is that the pd > still doesn't have an entry for the policy, perhaps we can call > pd_alloc_fn() additionally in blkg_create? > > If checking the blkg in blkg_create() is not a good solution, and we > decide to synchronize alloc-create blkg against policy deactivation. > Since only bfq policy can be deactivated or activated while queue is > not dying, and queue is freezed during activation and deactivation, > can we get a q->q_usage_counter and put it after blkg_create() is done > to prevent concurrent bfq policy activation and deactivation? Just found that blkcg_deactivate_policy() will call blk_mq_freeze_queue(), thus get q->q_usage_counter is wrong... Thanks, Kuai