Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp636985pxb; Tue, 5 Apr 2022 16:49:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxiRj3fEJ2mElx2BJ2ChsBhMpv5PX3r9CBEEj1CTGAnQ+5sxDY1Eou/kWVlfTuN1lsjBXme X-Received: by 2002:a17:90a:6949:b0:1ca:b37b:ba73 with SMTP id j9-20020a17090a694900b001cab37bba73mr6622195pjm.217.1649202597726; Tue, 05 Apr 2022 16:49:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649202597; cv=none; d=google.com; s=arc-20160816; b=o+kQLLsvC+fo6ofS45vIa+AEUS82CBUHuFTGbzsmMNUvcHWk7+g5nZVK8TUWtrJWfr cgA3hEnrCd1FybPab+d35WJKZ+13HK8I3lkQ9I8NBjHikSEhU7a0uP+Rh6vCFSS2HYoa jKkkL9VJTv0a64QCKIkcl7Z4x8MfJIsavW8rCNQ9e9coMFuEyinlVp/kVs3Mz8VFK9iM AsLLR2rh/e/oPwqTxlgK0PdOw49WCngZRn3IWALNE4Gdfedi7+QNzwD0VG7l2RkvlN2Z yZxoWVhxGr3eHhFDD2IT77g1ZMJThnnzBXee2bcusorGGSQZFE+2pGuxoC+AAXPsErNx eQDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=wkTsYcZhKAcnXTsCu/Zxk4bJImcojhkBhvaO3iSUuX0=; b=vCaiiDJ+0L+2gNj2WTXjofZi0jqNMuRLeYOmMOxbjYmR0klvYVC5SMLMFwQoN++waG 0r38vhq8mtsz1pVDwgN+xxPWeVq2SFYXSIkedyzaEKj/9M60iUzOKMB2cH7LGDuacliW 7RuGx9QB1f6Vy4gXgr7LLHRnKIZyBy2cPl98cd4RIWpTedDvHB3VFt5mg3Ym/nZLz16S skB10AO3StG0OXHPlyyruKSlHIFf0xIFAxQprrBlOUemHYW6WUQ0mrO5kY6W0dkEIqkx j48Ne3ECsrkQXp5uy9dr9EPtCUE1pRjRV/DNBVKTypy5NXQvQNdK6/iSp+0EBKWRlnn5 4KKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=D9Xh7COX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id c6-20020a170903234600b00153b2d16405si15654252plh.13.2022.04.05.16.49.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Apr 2022 16:49:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=D9Xh7COX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9C1C711A99C; Tue, 5 Apr 2022 16:34:18 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1385462AbiDEOjM (ORCPT + 99 others); Tue, 5 Apr 2022 10:39:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243065AbiDEJiw (ORCPT ); Tue, 5 Apr 2022 05:38:52 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16C6DA8EEC; Tue, 5 Apr 2022 02:24:36 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id A96A7B81C9D; Tue, 5 Apr 2022 09:24:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0432AC385A3; Tue, 5 Apr 2022 09:24:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649150673; bh=Ok4o6pfqdJRnWy+3ovBLWBNkxP9BwuXReBNWtb04gb4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=D9Xh7COX55SQTv/6w7fLemBwj62TfXld+kDbH59vz9qPmDe0p7FcxruVAXqRFk6wt qCTLlVFp7EZE8pMypDgO6rZt99fMaYZQlNMW6c6d91AD6yz2aPhPAGKJL5t9yA9a9V 8aj/Un0nxtNsm5p61E7K7QI31tbvnMmSoPE7QOtg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tejun Heo , Josef Bacik , Jens Axboe Subject: [PATCH 5.15 140/913] block: dont merge across cgroup boundaries if blkcg is enabled Date: Tue, 5 Apr 2022 09:20:02 +0200 Message-Id: <20220405070344.029318292@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070339.801210740@linuxfoundation.org> References: <20220405070339.801210740@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 From: Tejun Heo commit 6b2b04590b51aa4cf395fcd185ce439cab5961dc upstream. blk-iocost and iolatency are cgroup aware rq-qos policies but they didn't disable merges across different cgroups. This obviously can lead to accounting and control errors but more importantly to priority inversions - e.g. an IO which belongs to a higher priority cgroup or IO class may end up getting throttled incorrectly because it gets merged to an IO issued from a low priority cgroup. Fix it by adding blk_cgroup_mergeable() which is called from merge paths and rejects cross-cgroup and cross-issue_as_root merges. Signed-off-by: Tejun Heo Fixes: d70675121546 ("block: introduce blk-iolatency io controller") Cc: stable@vger.kernel.org # v4.19+ Cc: Josef Bacik Link: https://lore.kernel.org/r/Yi/eE/6zFNyWJ+qd@slm.duckdns.org Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- block/blk-merge.c | 11 +++++++++++ include/linux/blk-cgroup.h | 17 +++++++++++++++++ 2 files changed, 28 insertions(+) --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -7,6 +7,7 @@ #include #include #include +#include #include @@ -561,6 +562,9 @@ static inline unsigned int blk_rq_get_ma static inline int ll_new_hw_segment(struct request *req, struct bio *bio, unsigned int nr_phys_segs) { + if (!blk_cgroup_mergeable(req, bio)) + goto no_merge; + if (blk_integrity_merge_bio(req->q, req, bio) == false) goto no_merge; @@ -657,6 +661,9 @@ static int ll_merge_requests_fn(struct r if (total_phys_segments > blk_rq_get_max_segments(req)) return 0; + if (!blk_cgroup_mergeable(req, next->bio)) + return 0; + if (blk_integrity_merge_rq(q, req, next) == false) return 0; @@ -863,6 +870,10 @@ bool blk_rq_merge_ok(struct request *rq, if (rq->rq_disk != bio->bi_bdev->bd_disk) return false; + /* don't merge across cgroup boundaries */ + if (!blk_cgroup_mergeable(rq, bio)) + return false; + /* only merge integrity protected bio into ditto rq */ if (blk_integrity_merge_bio(rq->q, rq, bio) == false) return false; --- a/include/linux/blk-cgroup.h +++ b/include/linux/blk-cgroup.h @@ -24,6 +24,7 @@ #include #include #include +#include /* percpu_counter batch for blkg_[rw]stats, per-cpu drift doesn't matter */ #define BLKG_STAT_CPU_BATCH (INT_MAX / 2) @@ -604,6 +605,21 @@ static inline void blkcg_clear_delay(str atomic_dec(&blkg->blkcg->css.cgroup->congestion_count); } +/** + * blk_cgroup_mergeable - Determine whether to allow or disallow merges + * @rq: request to merge into + * @bio: bio to merge + * + * @bio and @rq should belong to the same cgroup and their issue_as_root should + * match. The latter is necessary as we don't want to throttle e.g. a metadata + * update because it happens to be next to a regular IO. + */ +static inline bool blk_cgroup_mergeable(struct request *rq, struct bio *bio) +{ + return rq->bio->bi_blkg == bio->bi_blkg && + bio_issue_as_root_blkg(rq->bio) == bio_issue_as_root_blkg(bio); +} + void blk_cgroup_bio_start(struct bio *bio); void blkcg_add_delay(struct blkcg_gq *blkg, u64 now, u64 delta); void blkcg_schedule_throttle(struct request_queue *q, bool use_memdelay); @@ -659,6 +675,7 @@ static inline void blkg_put(struct blkcg static inline bool blkcg_punt_bio_submit(struct bio *bio) { return false; } static inline void blkcg_bio_issue_init(struct bio *bio) { } static inline void blk_cgroup_bio_start(struct bio *bio) { } +static inline bool blk_cgroup_mergeable(struct request *rq, struct bio *bio) { return true; } #define blk_queue_for_each_rl(rl, q) \ for ((rl) = &(q)->root_rl; (rl); (rl) = NULL)