Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp3646579ybl; Mon, 3 Feb 2020 04:06:53 -0800 (PST) X-Google-Smtp-Source: APXvYqz2xJK3Gjf3Yn/PFdwLgc/DGEtKsE2gLHS2b2dhn0C4eGPBKX8w/ZNGQlfyEO4SVWXmtRi2 X-Received: by 2002:a05:6808:84:: with SMTP id s4mr3590437oic.147.1580731613078; Mon, 03 Feb 2020 04:06:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580731613; cv=none; d=google.com; s=arc-20160816; b=xuqBlArhIPlMa7g8KGDTRL/5kKlb+aH1/qIFRurxI+HMBOrzB50+THpznfPS6BHtWd 3BeuKT7osAuoqvj0LnUkIut8wEqXtvXfOPnJUunKcRMqHcnpz8UT272voQvTcVeEkl1G bOeYeO9SllQ3Ip55lQ64HJTnCUN8DchMxdzmE4zpj0rzUetFeHvwHj2wb7kgMpXl3QL4 HOlWZKog5mz04OlmLa0SgQXMEgFS6UrIyfmCH3D3HE/tTujR2gkO21KIUFDEMc1zQQlp NOGtyw6jkljaNodoMA6U9UqLiv5mrPSMYQbh2o/W8qaFAFJJy73X9t2woEOeumc6iW+7 ZrFA== 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=9S9BwHx5UyCKJX2JPPBf1rlNAUg9PfPZ0MUkcYcdubg=; b=FQcg2O2ZZfEAWhxCSNQlJfqdwHCQXRCaIDXvN29ZIlFNENk4YgoI4BvuaecGnfgial gy//ayloyx92YC2sVrLQnmbPR1CYE/nj2Iz1infq1uMDC6WnEdWGqbFm8Bhi/OG1Dp84 JO5nhOPrycXqrN2b6UrKe1hP2bX++ITDy0DetG7dDpgXjkR7yU/CNlCcEkfXacIny9Id QmremMmxcKVYzaGRvaQPU/1WXzalrDnM5+krNMraw3iHhXnZDB17mwRmm3CxQhJBDhFm NQwbvPd1gjaTJzt3j67EwN/CLniC4dQtOzSp7Z0VnqHA/hC9Eszf5hCAV+rBWGcieyiC v8Kg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mfpBpPqm; 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 y8si8393866oih.141.2020.02.03.04.06.40; Mon, 03 Feb 2020 04:06:53 -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=mfpBpPqm; 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 S1727877AbgBCKls (ORCPT + 99 others); Mon, 3 Feb 2020 05:41:48 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:33823 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727239AbgBCKlU (ORCPT ); Mon, 3 Feb 2020 05:41:20 -0500 Received: by mail-wr1-f67.google.com with SMTP id t2so17349618wrr.1 for ; Mon, 03 Feb 2020 02:41:19 -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=9S9BwHx5UyCKJX2JPPBf1rlNAUg9PfPZ0MUkcYcdubg=; b=mfpBpPqmwAcPO0e1BueHHoL83GQn+u39S5fzLWe3sm5x6q5ch5+7z+JZBr4ud9N0ka hlCWy6oQ6MXEvBvTA8Q+j+u28FVALLwfiLqQx7aIal1Ejk3ATshmevA5ZWy9nfGeA07n 6y6mFC7QPC8xUMujiRmFt0sG3zlgNQ7Gi9EReoaRy3Yshq+V4b2MZmGIJrv2/xpIMUpA xhDin3yzdFtWzB9QeaGkIcW+DKXTuvfOlUdjgia27BH37xhmkX5GBHnLVoiGQw25/Pq6 U4mfRfzrL9gTtnfZ8Cr7P8f4pVg+ugLieOD+Eb91fD8v0VQp9ph0V2zYweLoCT/0rDJi iuFQ== 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=9S9BwHx5UyCKJX2JPPBf1rlNAUg9PfPZ0MUkcYcdubg=; b=enra6teAA4ABqKWD0Ybrenn7FUROr5VPFo2KO1P9/bZSXXxLJtQ301L68Cfg1NXJEP z1yXAFpmDh5TAhaESf1uOf+kxpbsYVqw4RuVxlpWtszn5VF2dxq3gZZltRIrspXyzTxd elmkhXB6olw0vE2g/fF4EcpfNcEBdqL4hCsaQSGjYKoyEQaDxjNP4NGVJ0oGlGEk/uoK 7vynGceUR5GWmSiI/IrGYJEwfkT7w+kmVUFyNrkA04y/3Ss3PrswhiDkasZn+iGXmMin qCSNINNHgg4LoRUanEewBa+Y1fPVqWlsxYUeyZtO8T99cv7waaMeZLHWe/qC16AM6b0H B1DQ== X-Gm-Message-State: APjAAAWBnDg4nPm8bN8QlNJoWHYIgjS0uHH20ayzAVKGCOCrwYfwoh/U jw8PARc7/77pzhAN6Xh2zZl27w== X-Received: by 2002:adf:b352:: with SMTP id k18mr14456202wrd.242.1580726478647; Mon, 03 Feb 2020 02:41:18 -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.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Feb 2020 02:41:18 -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 3/7] block, bfq: get extra ref to prevent a queue from being freed during a group move Date: Mon, 3 Feb 2020 11:40:56 +0100 Message-Id: <20200203104100.16965-4-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 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 Signed-off-by: Paolo Valente --- block/bfq-cgroup.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/block/bfq-cgroup.c b/block/bfq-cgroup.c index e1419edde2ec..8ab7f18ff8cb 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