Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1397579ybz; Thu, 16 Apr 2020 08:27:53 -0700 (PDT) X-Google-Smtp-Source: APiQypJ0iW4kP6qdIfooRTohrSUyg8yAaWvs/+/bJj4x/UTMACBlgy5sxVvep2ih7UGgTq1l/4sz X-Received: by 2002:a50:d0d5:: with SMTP id g21mr19726097edf.92.1587050873400; Thu, 16 Apr 2020 08:27:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587050873; cv=none; d=google.com; s=arc-20160816; b=uQlVuzWXX9hcJNhyLtmsWohvD5cige/HpjolutgFhdK4CsI7SyhmpEULNZzhQ97TCK b2UCQFeHii2xhZoW+rk43neS1Gh2jS5MxKvYIc1I2s1iI3e+45+Tit1uI2Wb73+hZN87 mvumcUb3qai54QTSxZCCAvntNuynpbaPjtdQYiH4m79jZDXtQkevkZklIZ3h5Jjw3qTq G7gTnek2114VZgUXLohuIHcr94h7NOxPqYD5tgNMYEK6bMDIl0eLAGxJwsI2WFcpmldz RrGUDHAIzf88ws+MCnypJ1FW7N6CxNZMVmkjJ3E/GQ0lTYav2Tarr2bpeR+ONRvaDv21 7iyA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=SrgtjusB2oGdkwLlPKnYLhBCQuXdoM7rnyHnDKlLE7A=; b=LUMMGyXMUemPGW6WsHLo5yAvFC/3naARkVvRYRq9SsUof19QC+vQ2QonDQN1alCcCc mxmxagwxt0Te7nk4gGI84+wGpapE7WlpzbXUwaQRgmMh9ev8/YaxuKhTCULeC0vw6Z88 +vbOeMhSeNrsvIJax/gpxUkYABrEuIxAFh74pAmEmKBELrQ8QjfRIvzJkq2g7iemo4JM KobmthLUyNBi1VGfhC2HPvi0S0q+rqm0+AayzFVYd/cll9/X0FOFruUia+97L8t22CeT xib0fVs5BQ2ol1kmsOSHhgQa3c/OCOBRgkcjjyu82W4Va1xk7uwFSV8wuDr4bLJsnn01 RL1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=djTw6Uyz; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i15si12634330ejc.172.2020.04.16.08.27.29; Thu, 16 Apr 2020 08:27:53 -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; dkim=pass header.i=@kernel.org header.s=default header.b=djTw6Uyz; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2442471AbgDPPXK (ORCPT + 99 others); Thu, 16 Apr 2020 11:23:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:58762 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2898496AbgDPNpS (ORCPT ); Thu, 16 Apr 2020 09:45:18 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B27272076D; Thu, 16 Apr 2020 13:45:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587044718; bh=HeFoJtQMHA3FTTcjMfTXMgiQSyrQtjY1Nu2+TAJH6kg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=djTw6UyzykWygimxM2aWepTkSE3hX3Dyd+Pb8/GhiCBgJLi225913ISbmBLe06XVO vxlrACz4P9yhlSKXXBALyk/UGhBdok8Dl1IwX3Ia51rAFWfH13F0tBbilzV+QG5vEM MGYohtH8fj4iqlJK4MWvNEnXzoig3ACLBY3ToMXo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, cki-project@redhat.com, Paolo Valente , Jens Axboe , Sasha Levin Subject: [PATCH 5.4 046/232] block, bfq: move forward the getting of an extra ref in bfq_bfqq_move Date: Thu, 16 Apr 2020 15:22:20 +0200 Message-Id: <20200416131321.543285467@linuxfoundation.org> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200416131316.640996080@linuxfoundation.org> References: <20200416131316.640996080@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Paolo Valente [ Upstream commit fd1bb3ae54a9a2e0c42709de861c69aa146b8955 ] Commit ecedd3d7e199 ("block, bfq: get extra ref to prevent a queue from being freed during a group move") gets an extra reference to a bfq_queue before possibly deactivating it (temporarily), in bfq_bfqq_move(). This prevents the bfq_queue from disappearing before being reactivated in its new group. Yet, the bfq_queue may also be expired (i.e., its service may be stopped) before the bfq_queue is deactivated. And also an expiration may lead to a premature freeing. This commit fixes this issue by simply moving forward the getting of the extra reference already introduced by commit ecedd3d7e199 ("block, bfq: get extra ref to prevent a queue from being freed during a group move"). Reported-by: cki-project@redhat.com Tested-by: cki-project@redhat.com Signed-off-by: Paolo Valente Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- block/bfq-cgroup.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/block/bfq-cgroup.c b/block/bfq-cgroup.c index 86cd718e0380b..5611769e15690 100644 --- a/block/bfq-cgroup.c +++ b/block/bfq-cgroup.c @@ -625,6 +625,12 @@ void bfq_bfqq_move(struct bfq_data *bfqd, struct bfq_queue *bfqq, { struct bfq_entity *entity = &bfqq->entity; + /* + * Get extra reference to prevent bfqq from being freed in + * next possible expire or deactivate. + */ + bfqq->ref++; + /* If bfqq is empty, then bfq_bfqq_expire also invokes * bfq_del_bfqq_busy, thereby removing bfqq and its entity * from data structures related to current group. Otherwise we @@ -635,12 +641,6 @@ void bfq_bfqq_move(struct bfq_data *bfqd, struct bfq_queue *bfqq, bfq_bfqq_expire(bfqd, bfqd->in_service_queue, false, BFQQE_PREEMPTED); - /* - * get extra reference to prevent bfqq from being freed in - * next possible deactivate - */ - bfqq->ref++; - if (bfq_bfqq_busy(bfqq)) bfq_deactivate_bfqq(bfqd, bfqq, false, false); else if (entity->on_st) @@ -660,7 +660,7 @@ void bfq_bfqq_move(struct bfq_data *bfqd, struct bfq_queue *bfqq, if (!bfqd->in_service_queue && !bfqd->rq_in_driver) bfq_schedule_dispatch(bfqd); - /* release extra ref taken above */ + /* release extra ref taken above, bfqq may happen to be freed now */ bfq_put_queue(bfqq); } -- 2.20.1