Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp1821256ybc; Wed, 13 Nov 2019 04:59:02 -0800 (PST) X-Google-Smtp-Source: APXvYqwESKevvrMXZGw/Bqt+wkFVpZ9eHhIi5NP0asZg+QX5xqnD9nfAmkYtjfAWbJ0pNXWHB2nL X-Received: by 2002:a05:6402:547:: with SMTP id i7mr3468751edx.55.1573649942643; Wed, 13 Nov 2019 04:59:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573649942; cv=none; d=google.com; s=arc-20160816; b=X0Pi67CPbtUNvUKPGLwXFL8wCKqqWO0CWQCVsHpkqwiauPDmssdRQFCfstusp05xrx EXSbvnvAcRpwl9i8sjvxEuTyw+POX/t91J3ptMPy0V0I07eRZgbB5pLLhxASVl4MYD87 iARzcIkHgKcSxj+PIrDJfpNyHmWF1YsZ8IO4uWVhLsuSbwKTQ+7KERHUUe3CRH4WU9qF g9P0VzgFRBl2ntPQuF+paI17pvKWuR4GsF4VXks4B6GhfzeVuabarALgajsOOr2bHKZL XZLDw2fuS1/1ovhoBarvZnCbsuJJ4+mfo7VyiskoUMGqA5S7wDRamLtnuwrNnIyRD+PE KJPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:user-agent:references :in-reply-to:subject:cc:to:from:date:content-transfer-encoding :mime-version:dkim-signature; bh=5lJHmk092HI/n/t3HGbtqhY5NJJ/zYeiYOZoPfSWoV8=; b=pOUTWD/ua4cnbv7q+Wr6+f7xc/WuIb5tS0rW4G8C8wMlamdUcAqensmOIFgf956eEl +A+sBapDR0eyenjbElr2b5ctitcy3VQYQV2sjWk2iYZ7U/PXR7HcJYHvloL75GUAcKkj Q/z3A77dyXf9+IoiT5KF3GNpuK/e/bKWNkXsGZ4F+FBEXXcmywOlitNpnhNIX/cZJDvH cx1gSPv1hMp+GgTWWBCedKhJWXqMydnjlHwI4TYwKrC1TGcm3ULMJd2FuzCeM1lqMW2e ocMNWWvxjgezAeSGmD8fViuSmtbvMvshIlqucji8yY2JLnyialbK9cPjLzWnknq9aIRB ZhxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@natalenko.name header.s=dkim-20170712 header.b=KflpJlhU; 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=REJECT sp=REJECT dis=NONE) header.from=natalenko.name Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f2si1084623ejf.231.2019.11.13.04.58.38; Wed, 13 Nov 2019 04:59:02 -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=@natalenko.name header.s=dkim-20170712 header.b=KflpJlhU; 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=REJECT sp=REJECT dis=NONE) header.from=natalenko.name Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727113AbfKMM5Y (ORCPT + 99 others); Wed, 13 Nov 2019 07:57:24 -0500 Received: from vulcan.natalenko.name ([104.207.131.136]:39432 "EHLO vulcan.natalenko.name" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726326AbfKMM5Y (ORCPT ); Wed, 13 Nov 2019 07:57:24 -0500 Received: from mail.natalenko.name (vulcan.natalenko.name [IPv6:fe80::5400:ff:fe0c:dfa0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by vulcan.natalenko.name (Postfix) with ESMTPSA id 3DA9F628C1D; Wed, 13 Nov 2019 13:57:19 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=natalenko.name; s=dkim-20170712; t=1573649839; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5lJHmk092HI/n/t3HGbtqhY5NJJ/zYeiYOZoPfSWoV8=; b=KflpJlhUhEVlin+lNNHQWX1kTlF4c1gNrPhtrV2UqmrK1UcmXVlG2RYGtHWbje5+kkNlwy h/aTjcodHZEpUULAbfWhbcb/TBRdAB35NNB66MvZQDpCIAufvyGAcweYUFPWk68ULOSyXU oCWqgAA4vFV0FXjE4ISYmMmPPrWmbg0= MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Wed, 13 Nov 2019 13:57:19 +0100 From: Oleksandr Natalenko To: Paolo Valente Cc: Jens Axboe , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, ulf.hansson@linaro.org, linus.walleij@linaro.org, bfq-iosched@googlegroups.com, Chris Evich , Patrick Dung , Thorsten Schubert Subject: Re: [PATCH BUGFIX] block, bfq: deschedule empty bfq_queues not referred by any process In-Reply-To: <20191112074856.40433-1-paolo.valente@linaro.org> References: <20191112074856.40433-1-paolo.valente@linaro.org> User-Agent: Roundcube Webmail/1.4.0 Message-ID: X-Sender: oleksandr@natalenko.name Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi. On 12.11.2019 08:48, Paolo Valente wrote: > Since commit 3726112ec731 ("block, bfq: re-schedule empty queues if > they deserve I/O plugging"), to prevent the service guarantees of a > bfq_queue from being violated, the bfq_queue may be left busy, i.e., > scheduled for service, even if empty (see comments in > __bfq_bfqq_expire() for details). But, if no process will send > requests to the bfq_queue any longer, then there is no point in > keeping the bfq_queue scheduled for service. > > In addition, keeping the bfq_queue scheduled for service, but with no > process reference any longer, may cause the bfq_queue to be freed when > descheduled from service. But this is assumed to never happen, and > causes a UAF if it happens. This, in turn, caused crashes [1, 2]. > > This commit fixes this issue by descheduling an empty bfq_queue when > it remains with not process reference. > > [1] https://bugzilla.redhat.com/show_bug.cgi?id=1767539 > [2] https://bugzilla.kernel.org/show_bug.cgi?id=205447 > > Fixes: 3726112ec731 ("block, bfq: re-schedule empty queues if they > deserve I/O plugging") > Reported-by: Chris Evich > Reported-by: Patrick Dung > Reported-by: Thorsten Schubert > Signed-off-by: Paolo Valente > --- > block/bfq-iosched.c | 31 +++++++++++++++++++++++++------ > 1 file changed, 25 insertions(+), 6 deletions(-) > > diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c > index 0319d6339822..ba68627f7740 100644 > --- a/block/bfq-iosched.c > +++ b/block/bfq-iosched.c > @@ -2713,6 +2713,27 @@ static void bfq_bfqq_save_state(struct bfq_queue > *bfqq) > } > } > > + > +static > +void bfq_release_process_ref(struct bfq_data *bfqd, struct bfq_queue > *bfqq) > +{ > + /* > + * To prevent bfqq's service guarantees from being violated, > + * bfqq may be left busy, i.e., queued for service, even if > + * empty (see comments in __bfq_bfqq_expire() for > + * details). But, if no process will send requests to bfqq any > + * longer, then there is no point in keeping bfqq queued for > + * service. In addition, keeping bfqq queued for service, but > + * with no process ref any longer, may have caused bfqq to be > + * freed when dequeued from service. But this is assumed to > + * never happen. > + */ > + if (bfq_bfqq_busy(bfqq) && RB_EMPTY_ROOT(&bfqq->sort_list)) > + bfq_del_bfqq_busy(bfqd, bfqq, false); > + > + bfq_put_queue(bfqq); > +} > + > static void > bfq_merge_bfqqs(struct bfq_data *bfqd, struct bfq_io_cq *bic, > struct bfq_queue *bfqq, struct bfq_queue *new_bfqq) > @@ -2783,8 +2804,7 @@ bfq_merge_bfqqs(struct bfq_data *bfqd, struct > bfq_io_cq *bic, > */ > new_bfqq->pid = -1; > bfqq->bic = NULL; > - /* release process reference to bfqq */ > - bfq_put_queue(bfqq); > + bfq_release_process_ref(bfqd, bfqq); > } > > static bool bfq_allow_bio_merge(struct request_queue *q, struct > request *rq, > @@ -4899,7 +4919,7 @@ static void bfq_exit_bfqq(struct bfq_data *bfqd, > struct bfq_queue *bfqq) > > bfq_put_cooperator(bfqq); > > - bfq_put_queue(bfqq); /* release process reference */ > + bfq_release_process_ref(bfqd, bfqq); > } > > static void bfq_exit_icq_bfqq(struct bfq_io_cq *bic, bool is_sync) > @@ -5001,8 +5021,7 @@ static void bfq_check_ioprio_change(struct > bfq_io_cq *bic, struct bio *bio) > > bfqq = bic_to_bfqq(bic, false); > if (bfqq) { > - /* release process reference on this queue */ > - bfq_put_queue(bfqq); > + bfq_release_process_ref(bfqd, bfqq); > bfqq = bfq_get_queue(bfqd, bio, BLK_RW_ASYNC, bic); > bic_set_bfqq(bic, bfqq, false); > } > @@ -5963,7 +5982,7 @@ bfq_split_bfqq(struct bfq_io_cq *bic, struct > bfq_queue *bfqq) > > bfq_put_cooperator(bfqq); > > - bfq_put_queue(bfqq); > + bfq_release_process_ref(bfqq->bfqd, bfqq); > return NULL; > } I'm not sure if I see things right, but this commit along with v5.3.11 kernel causes almost all boots to hang (for instance, on mounting the FS). Once the scheduler is changed to something else than BFQ (I set the I/O scheduler early via udev rule), multiple reboots go just fine. Is this commit also applicable to 5.3 kernels? Or I'm testing a dumb thing? Thanks. -- Oleksandr Natalenko (post-factum)