Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp593287iog; Mon, 13 Jun 2022 08:46:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx66IyN2V7rFdkX29U2gmUG89AY2tc7aZZqwNi5iW8VkMCd6Ydl6a+stgaSEb826U3H2sHb X-Received: by 2002:aa7:c14b:0:b0:42d:d763:104 with SMTP id r11-20020aa7c14b000000b0042dd7630104mr412763edp.104.1655135217531; Mon, 13 Jun 2022 08:46:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655135217; cv=none; d=google.com; s=arc-20160816; b=U1hDSxjXQIDd/j1Me0hTcrwJwbaqbY9hEvPdRYx7TJCyzhVGECC1Y9199dUjDuB/uu DR/FoiGgDYDGjY1SODa37xCpqQIdIfGTQpFA0ONsZJM5asJ4avB9dEftW8bwkfRTTZ68 oB3s2zVc0EWECjxd1ZJ4wvvruzlbwZvLskUGFHSzf5SFm5aLc+dwmPoy5cX73Ey3OqBK RXJ6hVZgXaUFB5t4slqz3cnjqzbgOtMbXQ5WNCdGmDHX//4XQlpDHdNzg17xvFqTOs6Q l4r4yzZmmCxoAz8dh9tTDhwitdWlF7AhXh385s4ubqTOzsCiEdv/0rCm3Pd97cN50nSO s0Ag== 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=gKou2TQJnA44I5scUsdQTUenkWja//xKPZisOMdC+mw=; b=h5a6LGVy85ISoZe0mN3MjbodOjvtDJsuUN30ZzRYO7nVU5/V5bG91eTx9BuxfToIbi /peJNy5NgFd+ONVs0O/idM/sp+6doNGJESEHfDEMacdBP4ciSnxb5/aFtwae38KluFnc onAUJ4RgCL1uing0U5zICWjPHOVLDbE8xmXDkFVSMhzBchbodydV7Cn0m25mxlhNZ9Fh fJaGwxT5OWTdM2sTzcE9oqBP6fYUqoz2Hux9DbVTaj6jg7LXKNAHMzHBx1zVC+LEDCVN FucO66fjlKVFXdzCfgRube0pJuDq2c8fH4KPcCQkaUgCgaA/kVwED82yNOalVa00Anbm S+MQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=KqS5bK9f; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f10-20020a056402354a00b0042acba0b85bsi9423972edd.200.2022.06.13.08.46.32; Mon, 13 Jun 2022 08:46:57 -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=@linuxfoundation.org header.s=korg header.b=KqS5bK9f; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353870AbiFML1l (ORCPT + 99 others); Mon, 13 Jun 2022 07:27:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353572AbiFMLTu (ORCPT ); Mon, 13 Jun 2022 07:19:50 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D7F33B2A9; Mon, 13 Jun 2022 03:41:24 -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 0AC80B80EA7; Mon, 13 Jun 2022 10:41:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7A97EC34114; Mon, 13 Jun 2022 10:41:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655116881; bh=75pxU6AJ6qp+2Jj6blxovuFp3F54aXvZVsi90ESDs+k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KqS5bK9fUTrJIJfxHwOqN81BQhsVklhtOLILsjm6z3UVPCNw0JFFkH6P+8Bm6gHS9 Juxboul6IBt53hrU9e96rKYCsh7QiRSaN08i2oXD+77dF7DE08WAE3zt5hElhO17He v3NgOTuU5jsaP2ong+vPcz2GDBAZHvGNTIj4bXmI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "yukuai (C)" , Jan Kara , Christoph Hellwig , Jens Axboe Subject: [PATCH 5.4 219/411] bfq: Split shared queues on move between cgroups Date: Mon, 13 Jun 2022 12:08:12 +0200 Message-Id: <20220613094935.217764614@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094928.482772422@linuxfoundation.org> References: <20220613094928.482772422@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=-8.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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: Jan Kara commit 3bc5e683c67d94bd839a1da2e796c15847b51b69 upstream. When bfqq is shared by multiple processes it can happen that one of the processes gets moved to a different cgroup (or just starts submitting IO for different cgroup). In case that happens we need to split the merged bfqq as otherwise we will have IO for multiple cgroups in one bfqq and we will just account IO time to wrong entities etc. Similarly if the bfqq is scheduled to merge with another bfqq but the merge didn't happen yet, cancel the merge as it need not be valid anymore. CC: stable@vger.kernel.org Fixes: e21b7a0b9887 ("block, bfq: add full hierarchical scheduling and cgroups support") Tested-by: "yukuai (C)" Signed-off-by: Jan Kara Reviewed-by: Christoph Hellwig Link: https://lore.kernel.org/r/20220401102752.8599-3-jack@suse.cz Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- block/bfq-cgroup.c | 36 +++++++++++++++++++++++++++++++++--- block/bfq-iosched.c | 2 +- block/bfq-iosched.h | 1 + 3 files changed, 35 insertions(+), 4 deletions(-) --- a/block/bfq-cgroup.c +++ b/block/bfq-cgroup.c @@ -708,9 +708,39 @@ static struct bfq_group *__bfq_bic_chang } if (sync_bfqq) { - entity = &sync_bfqq->entity; - if (entity->sched_data != &bfqg->sched_data) - bfq_bfqq_move(bfqd, sync_bfqq, bfqg); + if (!sync_bfqq->new_bfqq && !bfq_bfqq_coop(sync_bfqq)) { + /* We are the only user of this bfqq, just move it */ + if (sync_bfqq->entity.sched_data != &bfqg->sched_data) + bfq_bfqq_move(bfqd, sync_bfqq, bfqg); + } else { + struct bfq_queue *bfqq; + + /* + * The queue was merged to a different queue. Check + * that the merge chain still belongs to the same + * cgroup. + */ + for (bfqq = sync_bfqq; bfqq; bfqq = bfqq->new_bfqq) + if (bfqq->entity.sched_data != + &bfqg->sched_data) + break; + if (bfqq) { + /* + * Some queue changed cgroup so the merge is + * not valid anymore. We cannot easily just + * cancel the merge (by clearing new_bfqq) as + * there may be other processes using this + * queue and holding refs to all queues below + * sync_bfqq->new_bfqq. Similarly if the merge + * already happened, we need to detach from + * bfqq now so that we cannot merge bio to a + * request from the old cgroup. + */ + bfq_put_cooperator(sync_bfqq); + bfq_release_process_ref(bfqd, sync_bfqq); + bic_set_bfqq(bic, NULL, 1); + } + } } return bfqg; --- a/block/bfq-iosched.c +++ b/block/bfq-iosched.c @@ -4914,7 +4914,7 @@ void bfq_put_queue(struct bfq_queue *bfq bfqg_and_blkg_put(bfqg); } -static void bfq_put_cooperator(struct bfq_queue *bfqq) +void bfq_put_cooperator(struct bfq_queue *bfqq) { struct bfq_queue *__bfqq, *next; --- a/block/bfq-iosched.h +++ b/block/bfq-iosched.h @@ -949,6 +949,7 @@ void bfq_weights_tree_remove(struct bfq_ void bfq_bfqq_expire(struct bfq_data *bfqd, struct bfq_queue *bfqq, bool compensate, enum bfqq_expiration reason); void bfq_put_queue(struct bfq_queue *bfqq); +void bfq_put_cooperator(struct bfq_queue *bfqq); void bfq_end_wr_async_queues(struct bfq_data *bfqd, struct bfq_group *bfqg); void bfq_release_process_ref(struct bfq_data *bfqd, struct bfq_queue *bfqq); void bfq_schedule_dispatch(struct bfq_data *bfqd);