Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp3641571ybl; Mon, 3 Feb 2020 04:02:23 -0800 (PST) X-Google-Smtp-Source: APXvYqxrQNgIgWJFhQ/Uq5qAMu7rYkQsUzyG1U2bgbe5iyuEeiKo+E9oMrN2RhQ927n3KtaiJPwW X-Received: by 2002:a05:6830:1e2d:: with SMTP id t13mr18034303otr.128.1580731343448; Mon, 03 Feb 2020 04:02:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580731343; cv=none; d=google.com; s=arc-20160816; b=tsZ/DT5s5vES4n4DKbmpIiS9iBYPGAxiPbKjrfPzU+wwWpLU2xJKdJkpRZ0suXEtE1 Bxrh9p8MSeh9zkWJyu2vXoNGJTtJ/tC+hn7bVCf2BaWK63Vc1qciQ4vDbw9tORdhl3VW m023rBnCwpoEkahf3HSIn/8nTu2CbWlag2rT2s4VlmNEY59FtNrAKiMuUOxZrTYfxjlU /ddUoxM9aPqIIDwssMMeHKYKJ0DlxspR24eWFGiqNK17RCp/ASRpL45dA3EqtXizoKHj F4gAag45CBha1nc22cvHyn/dRWPP2rjmpVjwUkB3VjxHKzshWD5QyHW3BCQAQj2Lrmbu 3bKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=rzt4yAe3s0HBIE04/HczDDOIa4+f9r0CEH+uqzj+BDc=; b=LYHoHg1ERQdOPKjZ7iqu29oooKdyBCop4Q2Yi3DTozhG3JS/ZcdzkzOk6uOevr8ki6 ok4ND5Kvszm24ZbesbbEPZte4JZLcbV79LeipVwEV1LCWXS2moSvYPhq3QCxg/DJ5WIo 2Ef9fe9fnWeNLETTniL7vD4bXVw74H1YsMBseyWFhXwDG57KI88Q/gqqjNNV2BeqDbpq ZrPhVmEgNlKREUROJk9YTCw+fbYfJ2cWWeF2Hqf4dy6hdgaLv16451ZVRRJjsvCH+lRI nowKuOjcSX14Kr5wjbyzZUa8MS0CiZ2NQYBBLQrzXLoAxNwPiViZo4NpdZA5Edvb/qmz Zrmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vJ9AQJrI; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j10si9085365otn.122.2020.02.03.04.02.11; Mon, 03 Feb 2020 04:02:23 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vJ9AQJrI; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727387AbgBCKlg (ORCPT + 99 others); Mon, 3 Feb 2020 05:41:36 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:52686 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727571AbgBCKlY (ORCPT ); Mon, 3 Feb 2020 05:41:24 -0500 Received: by mail-wm1-f65.google.com with SMTP id p9so15256620wmc.2 for ; Mon, 03 Feb 2020 02:41:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rzt4yAe3s0HBIE04/HczDDOIa4+f9r0CEH+uqzj+BDc=; b=vJ9AQJrI1BNhzha7OjhKAOLAwHr7Z+z7FaHE/TXavIB7TfKhs9SQePDc2R8bFtgs5t EVbMjFiIuIUfZfkHbLplmpieXt33rdSbtnVu2O5C1fizzkCT2brbn8/q6LwbVoW9e5wM imQ6Iwpzi1DfRuI0WZeC64+tvO8CUs2ymRxKzvpcSPOg8sPQb0PXKDg5kIRNfqVaGVF/ vw/nf6lnJ/5Ct4JrxcB4ocm+V8w1/Bp7p5AFAOZlMFFJ9yc+Y0TYrpfSalLil7S35uEl aQ0L2yQ+h9FEpQWcgR2Avz0qbvo+YbTk303y2qWju+6m8ioFjRclKCzJTXqUywsfzasl ci/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rzt4yAe3s0HBIE04/HczDDOIa4+f9r0CEH+uqzj+BDc=; b=QpFJeURMrJW+qznPHK+4L/g9418NIRnUB2hyL9THfumEI5Z8QvEZXP3ejHkgAWVPGy 68NbedE2MVByj3HKibZ/jnMsEOiVW3UFnf75JHazPydE42oiwRQf344dHBHGwW9h9xKx es505XfvRWKEoBEEdvZ7vlzKM+i7D4yncjyO6H5adfV5EHojnFJ5aQnfqe6XvE5KPET7 un+adXnBCJq5H2jYewnpkIlvlBgclXLnzT3omK7gbRU+NzWL6sY2VPCqEzyu2fi4e0X4 2joT2kUKXWBY0+Wffjul0wb74RTEOCdJoIHVBN+0IzGM9xluJE2bwJA1aNLTvLTyzwLF npXA== X-Gm-Message-State: APjAAAXfbg7ZNLz/ZGNgQ5iHnrgGBWTgLB93VSz3ZNybADn7VYOmIhC9 k6XXzOQwen9uq8iDvF7iMnhj5Q== X-Received: by 2002:a7b:cbcf:: with SMTP id n15mr28134873wmi.21.1580726482645; Mon, 03 Feb 2020 02:41:22 -0800 (PST) Received: from localhost.localdomain (84-33-65-46.dyn.eolo.it. [84.33.65.46]) by smtp.gmail.com with ESMTPSA id i204sm23798930wma.44.2020.02.03.02.41.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Feb 2020 02:41:22 -0800 (PST) From: Paolo Valente To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, bfq-iosched@googlegroups.com, oleksandr@natalenko.name, patdung100@gmail.com, cevich@redhat.com, Paolo Valente Subject: [PATCH BUGFIX V2 6/7] block, bfq: get a ref to a group when adding it to a service tree Date: Mon, 3 Feb 2020 11:40:59 +0100 Message-Id: <20200203104100.16965-7-paolo.valente@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200203104100.16965-1-paolo.valente@linaro.org> References: <20200203104100.16965-1-paolo.valente@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org BFQ schedules generic entities, which may represent either bfq_queues or groups of bfq_queues. When an entity is inserted into a service tree, a reference must be taken, to make sure that the entity does not disappear while still referred in the tree. Unfortunately, such a reference is mistakenly taken only if the entity represents a bfq_queue. This commit takes a reference also in case the entity represents a group. Tested-by: Chris Evich Signed-off-by: Paolo Valente --- block/bfq-cgroup.c | 2 +- block/bfq-iosched.h | 1 + block/bfq-wf2q.c | 12 ++++++++++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/block/bfq-cgroup.c b/block/bfq-cgroup.c index cae488b58049..09b69a3ed490 100644 --- a/block/bfq-cgroup.c +++ b/block/bfq-cgroup.c @@ -332,7 +332,7 @@ static void bfqg_put(struct bfq_group *bfqg) kfree(bfqg); } -static void bfqg_and_blkg_get(struct bfq_group *bfqg) +void bfqg_and_blkg_get(struct bfq_group *bfqg) { /* see comments in bfq_bic_update_cgroup for why refcounting bfqg */ bfqg_get(bfqg); diff --git a/block/bfq-iosched.h b/block/bfq-iosched.h index 2c7cec737b2a..d1233af9c684 100644 --- a/block/bfq-iosched.h +++ b/block/bfq-iosched.h @@ -985,6 +985,7 @@ struct bfq_group *bfq_find_set_group(struct bfq_data *bfqd, struct blkcg_gq *bfqg_to_blkg(struct bfq_group *bfqg); struct bfq_group *bfqq_group(struct bfq_queue *bfqq); struct bfq_group *bfq_create_group_hierarchy(struct bfq_data *bfqd, int node); +void bfqg_and_blkg_get(struct bfq_group *bfqg); void bfqg_and_blkg_put(struct bfq_group *bfqg); #ifdef CONFIG_BFQ_GROUP_IOSCHED diff --git a/block/bfq-wf2q.c b/block/bfq-wf2q.c index 26776bdbdf36..eb0e2a6daabe 100644 --- a/block/bfq-wf2q.c +++ b/block/bfq-wf2q.c @@ -533,7 +533,9 @@ static void bfq_get_entity(struct bfq_entity *entity) bfqq->ref++; bfq_log_bfqq(bfqq->bfqd, bfqq, "get_entity: %p %d", bfqq, bfqq->ref); - } + } else + bfqg_and_blkg_get(container_of(entity, struct bfq_group, + entity)); } /** @@ -647,8 +649,14 @@ static void bfq_forget_entity(struct bfq_service_tree *st, entity->on_st_or_in_serv = false; st->wsum -= entity->weight; - if (bfqq && !is_in_service) + if (is_in_service) + return; + + if (bfqq) bfq_put_queue(bfqq); + else + bfqg_and_blkg_put(container_of(entity, struct bfq_group, + entity)); } /** -- 2.20.1