Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp491307ybl; Fri, 31 Jan 2020 02:42:32 -0800 (PST) X-Google-Smtp-Source: APXvYqzYmO1wC/rgnMflIdOHPGeUwwMmx3G+ZzoaJoR+Pli1GTe63X6sXrBUbmGc+7LKPVyMtrlF X-Received: by 2002:aca:1708:: with SMTP id j8mr5888696oii.166.1580467352785; Fri, 31 Jan 2020 02:42:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580467352; cv=none; d=google.com; s=arc-20160816; b=yq34b4fo+3vX1bPW7Y92SPesFfEGahi/hMIjz3GC2sUS21P7uCjeomOR1ci5qraAfH vo6WlWvX22k5vg5kIsEU2g315oj5tWdpUK1FWayD5PsmTBT1Jy/6ShBQn0902oCJLTE6 X7TwjYXR2eqgDoMXAS/ARuYymQM43c2pB91ttVBefHWvoh9gjyw00iVSO1CWZfD8dh/P grAavjoA3OTBriBRpf2Y0wc7npzXW0Ez5gg3/WlTry4CtuTp9YQF5dgEGDCe69b/FKFE cxIzomaDWB3o49edJcCqc6jbGSwMmwGb4U1s2xCi6YHk8Dxhnou2jIGRITOgEM+UFAJA W0Ag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version:dkim-signature; bh=WZop4bdwwGLO+EHfABQjAxDwhkz6UEFKkDSsUCMxnGI=; b=iH41kZ9KK5JtGTSWSOEOZDeFNiSaBJUG/+UdHgQwmr9F80HoOFJVg/9tZRqw3Llxed jTGflXH9eEZVb0FJtmR4EMuT/42R1yjCs36wOwq8coG37O5LFlB4VEeTWB3Gf5MmpIiz om7rT6iOHXS+ai8Php+DHRGkc5wBPwHp5vI8QLi3IIyVmIUFTz7j5mbcka3Fc2uO7w+k wSEWu/F/7Vrx+rWEvdJFh/KtrWG9cRkMnF+BtwdNlU0/2v6xp65IkRh7J4qMGHtGaF7i xorTAjNocYkLIykcGBpJ6laWn6b02w6jbJSX43Ag5sjbCnPpGTHcGv2laKeIsvlQSm4O ngrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=x3C9KHV3; 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 k4si4646368otp.186.2020.01.31.02.42.21; Fri, 31 Jan 2020 02:42:32 -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=x3C9KHV3; 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 S1728344AbgAaKl3 (ORCPT + 99 others); Fri, 31 Jan 2020 05:41:29 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:38382 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728301AbgAaKl2 (ORCPT ); Fri, 31 Jan 2020 05:41:28 -0500 Received: by mail-wm1-f65.google.com with SMTP id a9so8093493wmj.3 for ; Fri, 31 Jan 2020 02:41:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=WZop4bdwwGLO+EHfABQjAxDwhkz6UEFKkDSsUCMxnGI=; b=x3C9KHV3dsuebpyTMEa658xzfgYeOafa4rxar9/uPB6IHwukAWRbBfChhel6mE2liX VueNN7HDIkRtL7UYhcG/OL1s5wMYFgSrxjZMIchbpqNkDQxsoLVZDJVUzzwP57NyKGyN G0hjEhz9uuaj7H2WwBYs0pj7+QnbxYwwh/qjBoVSSQIyEx+IJNay8ZMjyk0kfoG6ruea onTQXickJmwVdIQwkDygb0uu9Sb7hh0Hj1SSYNL6XIfgMdJC4de38xu47E9DzbLYpVAV FfMbfvZ1dtVDVT+EJnLpDovbJ3wmntmjwB91Ebr3veuJrHcQmzb2ryN2fS8I6fpGIixW jlWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=WZop4bdwwGLO+EHfABQjAxDwhkz6UEFKkDSsUCMxnGI=; b=h5TqBeZoAfFqE8LAIzfjWC5K51LwKej+qCJ9Z72L967wl/dI1KMdgPCRZ0qH/yS7LT R6U1yYB2+cLYBLLaJWho7LASB2H1ZDZFgLxfOkH0S6/YuIbCMACOvUepQ2RZjN4dlxz4 uTB7GFK/oHgZmr/jH+KGbiW1or1/qFmm1ZXOfX6XM/pgZqnA328ydjdy55F3WRgH1+ez emvkICAGSFzKeM277Tmu0S2VsV6EVlGou46XBgiK8jrflZtwTBOojAL3ZlOBr6zXQPUH 3qv1slFnpOhkZ9FD68hs9/hFHvnWVr2jzLEw7c6ImRkPrtb+T0N37hDurbfrYXemtMxr rELA== X-Gm-Message-State: APjAAAWiBepXptNKWKupNqQL25Wh6tSAMqUw5YGd0zLAtgaS3kjliJ3o v9Rtg/oxbV5l9d9SwU4XR/arKQ== X-Received: by 2002:a1c:9849:: with SMTP id a70mr11079056wme.76.1580467286817; Fri, 31 Jan 2020 02:41:26 -0800 (PST) Received: from [192.168.0.103] (88-147-73-186.dyn.eolo.it. [88.147.73.186]) by smtp.gmail.com with ESMTPSA id m7sm10871957wrr.40.2020.01.31.02.41.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 31 Jan 2020 02:41:26 -0800 (PST) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Subject: Re: [PATCH BUGFIX 3/6] block, bfq: get extra ref to prevent a queue from being freed during a group move From: Paolo Valente In-Reply-To: <784c55c0f37a1a448c31e73e28bef6f8@natalenko.name> Date: Fri, 31 Jan 2020 11:41:24 +0100 Cc: Jens Axboe , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, bfq-iosched@googlegroups.com, patdung100@gmail.com, cevich@redhat.com Content-Transfer-Encoding: quoted-printable Message-Id: <4D4E431C-D4B7-43DD-AB66-67ED5EA807DE@linaro.org> References: <20200131092409.10867-1-paolo.valente@linaro.org> <20200131092409.10867-4-paolo.valente@linaro.org> <784c55c0f37a1a448c31e73e28bef6f8@natalenko.name> To: Oleksandr Natalenko X-Mailer: Apple Mail (2.3445.104.11) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [RESENDING, BECAUSE BOUNCED OFF] > Il giorno 31 gen 2020, alle ore 11:20, Oleksandr Natalenko = ha scritto: >=20 > Hello. >=20 > On 31.01.2020 10:24, Paolo Valente wrote: >> 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++; >=20 > Shouldn't this be hidden under some macro (bfq_get_queue_ref(), for = instance) and also converted from int into refcount_t? >=20 Yeah, that's in my (long) todo list. Unfortunately, all BFQ code handles that ref increment in that rustic way (inherited from CFQ). It would take a little time to fix and check all occurrences. This fix is probably more critical, as this bug is crashing machines in some configurations. But I promise I won't forget your right suggestion. Thanks, Paolo >> + >> 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); >> } >> /** >=20 > --=20 > Oleksandr Natalenko (post-factum)