Received: by 2002:a17:90a:1609:0:0:0:0 with SMTP id n9csp852120pja; Wed, 1 Apr 2020 09:51:19 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsMPpbyWbllbc4KHoY821MCFoga/RZn5/vD2k4H2u9wz/DVBOz9ElI2ywlhqJOku4BtYo3P X-Received: by 2002:a4a:cb02:: with SMTP id r2mr7595195ooq.28.1585759879363; Wed, 01 Apr 2020 09:51:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585759879; cv=none; d=google.com; s=arc-20160816; b=Iic/C0Ron2NG/EvAUoUCLH6b3mWeG4H24Bck7MNGPWrRJd82IMGjx3OYJPKqI7sxPS 3EABFw1+dD34aKu+mE9Rc4QTyWHpwNuWd6sY3+Z7TwSY495topfZ4VKs5+AMw3oR15Us BcKZ1HdgyYUFfsqKVlGHm6U7Rm8IQjYYbL6IgMm0jVjlZTPepIBnUS1g2Su2b85imLqz HmE/oU7+hIY0eRltdidUg4a2fPA9LC78xs3o6pzWninWlyDZU+aGfXcHt1LoHgMb48B4 qdmABsSApxJYxxGZ5kQlngdSy0BBAH3pXDqZJukKRmAg8+BXf32zt7A8+gqHFgDkMv0O KXYg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=x7ubyu3GbbePUMlWvFtbaIcY2NGOI7Gm/iSPryq4J2s=; b=CTueDq2YEA3XMguDdZZ34LgiDDWs/MUYVlKDeFNmSKNGZuWUBHG8Ue6goDKNuRBpmy g7fER0b6A6pWBJ1apuanJx/i7YLVcI3bdcnut4qFt6FHJuCrWP6HYl1a+Prxy2y1xKMI ImSW6WHhAnH/+csXH053+L0WjqP1dnnvMjj83YAjiGXJ+fQl1/6POqOWZknfsQOTY0zg eJdEoxuJ0OsQUGcMqNaJ6nMoH2lSXyCXDDJb6PJLcW0tJ7cTGOs3DYksu0rHfHL/4MR5 KCj2Dwn5KFwTpqXl14Ldc3HVRAx9PXRyV9vhu4ifbBlbUQQz6SpgTmxevE6ZFdJgRJ2m IGYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=N2KLh9oz; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w17si951120ooc.23.2020.04.01.09.51.07; Wed, 01 Apr 2020 09:51:19 -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=@kernel.org header.s=default header.b=N2KLh9oz; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389317AbgDAQk1 (ORCPT + 99 others); Wed, 1 Apr 2020 12:40:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:40560 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389289AbgDAQkX (ORCPT ); Wed, 1 Apr 2020 12:40:23 -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 1972920719; Wed, 1 Apr 2020 16:40:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1585759221; bh=dmhLfHVWp2qxWaMfTfJhVl2xwkEquJBqtbaqRq3rT9Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=N2KLh9oz8IpezgrM4eUYJdbhIqC4JQCUa9S88+hyk4K6Yg6I8ie9nS2Loz7EQI5LD 6HZ6qLTcqPOzdkZfnL+F2fxQGkL0//RYIII9phP9X8ToBDfylX7e8WG2hqASwed3Uu Ts7lLWAFZcPo7XNQJiUNG7+98vRIL15P9xdeWkA4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kwon Je Oh , Carlo Nonato , Paolo Valente , Jens Axboe , Sasha Levin Subject: [PATCH 4.14 013/148] block, bfq: fix overwrite of bfq_group pointer in bfq_find_set_group() Date: Wed, 1 Apr 2020 18:16:45 +0200 Message-Id: <20200401161553.506542958@linuxfoundation.org> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200401161552.245876366@linuxfoundation.org> References: <20200401161552.245876366@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Carlo Nonato [ Upstream commit 14afc59361976c0ba39e3a9589c3eaa43ebc7e1d ] The bfq_find_set_group() function takes as input a blkcg (which represents a cgroup) and retrieves the corresponding bfq_group, then it updates the bfq internal group hierarchy (see comments inside the function for why this is needed) and finally it returns the bfq_group. In the hierarchy update cycle, the pointer holding the correct bfq_group that has to be returned is mistakenly used to traverse the hierarchy bottom to top, meaning that in each iteration it gets overwritten with the parent of the current group. Since the update cycle stops at root's children (depth = 2), the overwrite becomes a problem only if the blkcg describes a cgroup at a hierarchy level deeper than that (depth > 2). In this case the root's child that happens to be also an ancestor of the correct bfq_group is returned. The main consequence is that processes contained in a cgroup at depth greater than 2 are wrongly placed in the group described above by BFQ. This commits fixes this problem by using a different bfq_group pointer in the update cycle in order to avoid the overwrite of the variable holding the original group reference. Reported-by: Kwon Je Oh Signed-off-by: Carlo Nonato Signed-off-by: Paolo Valente Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- block/bfq-cgroup.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/block/bfq-cgroup.c b/block/bfq-cgroup.c index afbbe5750a1f8..7d7aee024ece2 100644 --- a/block/bfq-cgroup.c +++ b/block/bfq-cgroup.c @@ -499,12 +499,13 @@ struct bfq_group *bfq_find_set_group(struct bfq_data *bfqd, */ entity = &bfqg->entity; for_each_entity(entity) { - bfqg = container_of(entity, struct bfq_group, entity); - if (bfqg != bfqd->root_group) { - parent = bfqg_parent(bfqg); + struct bfq_group *curr_bfqg = container_of(entity, + struct bfq_group, entity); + if (curr_bfqg != bfqd->root_group) { + parent = bfqg_parent(curr_bfqg); if (!parent) parent = bfqd->root_group; - bfq_group_set_parent(bfqg, parent); + bfq_group_set_parent(curr_bfqg, parent); } } -- 2.20.1