From patchwork Fri Jul 28 19:41:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Valente X-Patchwork-Id: 108907 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp776816qge; Fri, 28 Jul 2017 12:41:54 -0700 (PDT) X-Received: by 10.98.204.10 with SMTP id a10mr8558903pfg.332.1501270913944; Fri, 28 Jul 2017 12:41:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501270913; cv=none; d=google.com; s=arc-20160816; b=pW57u6uBmEGoUDcnDcqCqB9iDuQswaaiQGbN3SS6kmm/136ntMrj603fOAaBDwj5BR LWFgwNUU4rNe0xhycSq+C0Ra6z2xoGLKlJ8QyREMMOVCVGY0ble1JyFENmao26snaD6V 292InoaorDMh5jlOjRWsa5GCJxlZrnQjx9b5BNCDeUrSX21eR0dnXHL2D3uTIcwq2Lb1 wivPcXVVvIlGjpLfJWwOTPHUdUhHQX7pTxUP4Rfq1/6DgtUVbBjyBxHh79k0bLHout4I /hOcCKkAWVY9bLcoP7D+V+3uvGPYmw3O01inbyLifIudnQdZ8Fv3rRPbVmHriUrTM8Oj vkGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=xGPvalquzxVvUhzB9xHS8EkSO6lzEnJIgfZjTxf0OvU=; b=kqcTrAEYhpObWUj+e409if62UtBg7oICO/wPDOuAdSARGAuNb2KRgzDd/TByW3L2X3 E1fEZF/2nRKw6O2O1Kpex8arMr8NAwMsOPzR1fbEALEZOp+VviEFYSdpxRQWv6Rojxiv kAQeBwL/K36XLqmlpJqwqu0bqg1sw+z8fl8c1UgGxDC23J6ajJe8EVCMVOKpyj7+POOO kxs9pgVU02Gbi2M07TQap3b8TkERAmb05KXQzU5nRVIdMJEssR8tREqXtkHbY3ztazio aHu+wtNI38I1o929ZEKtvF5D/8Z5Cs4hxsjsThXsCD1BEyYYmlPteisEgZ+hx1kTtKEK f9hA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=f/AG9NqX; 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 h9si12786508pgc.48.2017.07.28.12.41.53; Fri, 28 Jul 2017 12:41:53 -0700 (PDT) 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.b=f/AG9NqX; 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 S1752729AbdG1Tlv (ORCPT + 26 others); Fri, 28 Jul 2017 15:41:51 -0400 Received: from mail-wr0-f182.google.com ([209.85.128.182]:38739 "EHLO mail-wr0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752710AbdG1Tlt (ORCPT ); Fri, 28 Jul 2017 15:41:49 -0400 Received: by mail-wr0-f182.google.com with SMTP id f21so102187149wrf.5 for ; Fri, 28 Jul 2017 12:41:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=xGPvalquzxVvUhzB9xHS8EkSO6lzEnJIgfZjTxf0OvU=; b=f/AG9NqXbY0VjMxdDQxpYnYgwU5wV0Wuxcpi7lfAOJ18i1iogy5M5H3u07G3n78zXT 6x0Ba8bZNAvkLFiRy4FJIm8bjuO36652xVhmsFHXDArgsaaN2uo8PO9VLbBwtgLvnWTO sL/VeX9PG55Nycp4F1iy4EIW29+G15sKyTTEE= 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; bh=xGPvalquzxVvUhzB9xHS8EkSO6lzEnJIgfZjTxf0OvU=; b=Fw3vyvXVYxxz0779VUfh+CmJVRDh469aEu1dk/9TPqdvtB63bSNJNkwOQwftdpyKGN edxj+Pxvmej7TgA9C4u4r/pBl3i+sb/FC+s/M+o7H2rLJySfu6VsRvrrlga2/lXppb+7 8m3Z2YI3XdyArF9jWpki8XZmH3zhY6vIj0uhJ8sdNqGCT6Z6D8VuUrz519uJsGPGY5g4 A6X83sGxMgmv48pwtzhPdJUSDnrh1vJK98fZYYJ63CDPG3yX0JA8CXc58FYocSQ1ro4C 3d4iz5XCx/Yei5VBYJLiP+kqqJwBtGwxi03G8PyTeFn32TOeUaRcgWfzOP4cEKRWePAY urGQ== X-Gm-Message-State: AIVw113NHKyeu4Bif4x1kwDaoRCK8qA7i8Ylmoyc0itwAWQBtj+rnKhD D+Tn9bvkGq6L25sZ X-Received: by 10.223.154.7 with SMTP id z7mr6596638wrb.136.1501270908290; Fri, 28 Jul 2017 12:41:48 -0700 (PDT) Received: from localhost.localdomain ([185.14.11.247]) by smtp.gmail.com with ESMTPSA id 77sm5071797wmk.8.2017.07.28.12.41.46 (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 28 Jul 2017 12:41:47 -0700 (PDT) From: Paolo Valente To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, ulf.hansson@linaro.org, broonie@kernel.org, lnicola@dend.ro, Paolo Valente Subject: [PATCH BUGFIX] block, bfq: reset in_service_entity if it becomes idle Date: Fri, 28 Jul 2017 21:41:18 +0200 Message-Id: <20170728194118.8249-1-paolo.valente@linaro.org> X-Mailer: git-send-email 2.10.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org BFQ implements hierarchical scheduling by representing each group of queues with a generic parent entity. For each parent entity, BFQ maintains an in_service_entity pointer: if one of the child entities happens to be in service, in_service_entity points to it. The resetting of these pointers happens only on queue expirations: when the in-service queue is expired, i.e., stops to be the queue in service, BFQ resets all in_service_entity pointers along the parent-entity path from this queue to the root entity. Functions handling the scheduling of entities assume, naturally, that in-service entities are active, i.e., have pending I/O requests (or, as a special case, even if they have no pending requests, they are expected to receive a new request very soon, with the scheduler idling the storage device while waiting for such an event). Unfortunately, the above resetting scheme of the in_service_entity pointers may cause this assumption to be violated. For example, the in-service queue may happen to remain without requests because of a request merge. In this case the queue does become idle, and all related data structures are updated accordingly. But in_service_entity still points to the queue in the parent entity. This inconsistency may even propagate to higher-level parent entities, if they happen to become idle as well, as a consequence of the leaf queue becoming idle. For this queue and parent entities, scheduling functions have an undefined behaviour, and, as reported, may easily lead to kernel crashes or hangs. This commit addresses this issue by simply resetting the in_service_entity field also when it is detected to point to an entity becoming idle (regardless of why the entity becomes idle). Reported-by: Laurentiu Nicola Signed-off-by: Paolo Valente Tested-by: Laurentiu Nicola --- block/bfq-wf2q.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) -- 2.10.0 diff --git a/block/bfq-wf2q.c b/block/bfq-wf2q.c index 979f8f2..881bbe5 100644 --- a/block/bfq-wf2q.c +++ b/block/bfq-wf2q.c @@ -1158,8 +1158,10 @@ bool __bfq_deactivate_entity(struct bfq_entity *entity, bool ins_into_idle_tree) st = bfq_entity_service_tree(entity); is_in_service = entity == sd->in_service_entity; - if (is_in_service) + if (is_in_service) { bfq_calc_finish(entity, entity->service); + sd->in_service_entity = NULL; + } if (entity->tree == &st->active) bfq_active_extract(st, entity);