From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 628B6C10F27 for ; Tue, 10 Mar 2020 12:56:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2B1042253D for ; Tue, 10 Mar 2020 12:56:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583845014; bh=Ne+Rbl+wF0k1lMl/aPemFvLHXKkrkdgmlb5C+qtk2yg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=hdTFjcroyV4Y8UKaSHDTtZBpvv/R/p+LNd/lYgKkxmONF8lms/w5caAxcU6+gIQBy COveBneU6G6fgrf3RSFAmI3kIH94f0YvTVy6bdlh/dOrYcFKEQoZnflgV6YhcniiKa bwswE+HTay9DJ+42rS/i6GnIKt//l5l1tWUCcHlY= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729366AbgCJM4x (ORCPT ); Tue, 10 Mar 2020 08:56:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:36202 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728361AbgCJM4w (ORCPT ); Tue, 10 Mar 2020 08:56:52 -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 654C02468D; Tue, 10 Mar 2020 12:56:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583845011; bh=Ne+Rbl+wF0k1lMl/aPemFvLHXKkrkdgmlb5C+qtk2yg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AMD+S7040woPqoFipSLqMTwVDBxs9nPw51gg+w2kZJc75DwK5mLisDhTUfJFNedO0 vcGlUbD+Iqn45uBiMmqIpJdc+nqYPEM8aaqXOr1hbAq2OvMtOF7WMNvi6bDMc3KJsO QuyHm5wfA1fpPoaj4RZKuwVXF5f5B/jvkfd3jkj8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chris Evich , Oleksandr Natalenko , Paolo Valente , Jens Axboe , Sasha Levin Subject: [PATCH 5.5 003/189] block, bfq: get extra ref to prevent a queue from being freed during a group move Date: Tue, 10 Mar 2020 13:37:20 +0100 Message-Id: <20200310123639.929399082@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200310123639.608886314@linuxfoundation.org> References: <20200310123639.608886314@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Paolo Valente [ Upstream commit ecedd3d7e19911ab8fe42f17b77c0a30fe7f4db3 ] In bfq_bfqq_move(), the bfq_queue, say Q, to be moved to a new group may happen to be deactivated in the scheduling data structures of the source group (and then activated in the destination group). If Q is referred only by the data structures in the source group when the deactivation happens, then Q is freed upon the deactivation. This commit addresses this issue by getting an extra reference before the possible deactivation, and releasing this extra reference after Q has been moved. Tested-by: Chris Evich Tested-by: Oleksandr Natalenko Signed-off-by: Paolo Valente Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- block/bfq-cgroup.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/block/bfq-cgroup.c b/block/bfq-cgroup.c index e7919e76a27c2..db2a14215aeea 100644 --- a/block/bfq-cgroup.c +++ b/block/bfq-cgroup.c @@ -651,6 +651,12 @@ 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) @@ -670,6 +676,8 @@ 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 */ + bfq_put_queue(bfqq); } /** -- 2.20.1