Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp6780087ybf; Fri, 6 Mar 2020 04:28:55 -0800 (PST) X-Google-Smtp-Source: ADFU+vuMix+444D4fw3dXAKTqUtwlu6QPuqWxP4xvlfzjF9iJbycskczYnGw3bspvutuw2dTcgGF X-Received: by 2002:a54:4181:: with SMTP id 1mr2411771oiy.158.1583497735321; Fri, 06 Mar 2020 04:28:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583497735; cv=none; d=google.com; s=arc-20160816; b=BUqjiJqdZgjgGQKkuyADViOYO3lGJJnGJ6g4Olx1BXYfOEaM476VuOauIUz7Von9IS aMhmzQD0uQ3tmqn69NecysqstmjDEqJi27VEYmLiWJQUrMKC+b/KUN24usQyVdw2/nOl 7/N+5Q/ZiW+EN51EBkvth7A+Ij3sBK/Icwsa6YBqRK14qddge24crLUtmffsUzkWmQ/E P3xLU3MXt5N8vVLOTo8ql1aTJQ27PZLUxPHeM6c8AcUgFsrICEE31wdZc2j82DsGvivC PLqgjpqLDFnIiuoiyRcPm/jR+7hAgJBA7dgcgM90ep1FeLN0EYJf/HwqiA8cyQloplcl XtrA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=Rf+ut+vZ0rkmAH/Rce7x5xKiOiWUHGb8d9Igi14P9Lw=; b=Iu3dijQKrCMGZGMJvxxjSVyr3DzSGIR1jtHH/h4Qw5xI9d7kdUjrgTaY9bp2qx7D/n smlfSJ+P/8akI5DTTcno8l2eC6m7Sok427S/icRahQTmThKcoTCmoECdFx5y/aGbYI/9 Msx+cwvW0/o7NE+w8OgQXI4bKFmEAdVdapGE+/ptoULTis31eU7k+3LWURvvuR6pIdza TNt99vmGtQ3WOoQLRrcqUPRlVpHNUQSUI39CNUtkGfd25f07rin/QulfD1P0QzH9QBH3 aG/MMPeAdodUDVkO5zmBtDznwZbLKd94p5apgs4oVTkeUy2DYjDYWJ3Dlr3gHBdkEVpj w78A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ShIPKgee; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o18si1308477otk.80.2020.03.06.04.28.42; Fri, 06 Mar 2020 04:28:55 -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=@gmail.com header.s=20161025 header.b=ShIPKgee; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726579AbgCFM2T (ORCPT + 99 others); Fri, 6 Mar 2020 07:28:19 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:51753 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726307AbgCFM2S (ORCPT ); Fri, 6 Mar 2020 07:28:18 -0500 Received: by mail-wm1-f65.google.com with SMTP id a132so2204283wme.1; Fri, 06 Mar 2020 04:28:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Rf+ut+vZ0rkmAH/Rce7x5xKiOiWUHGb8d9Igi14P9Lw=; b=ShIPKgeeGOieT6zOaPe7N1NG1+rDBuRiuiFsuB2sNIxLmjxU9SVQI4d5nMsN1AbIVS Vj77ogg71rIo51YRkAdwbdDOmP+FWH2OvCvPbbjly0b3JNScZFUdVpvifLABRMIdHsRs AgeuXspkx0YFf8DeEY1JgjOBFXWe7GMl40w1X8BDvK2HSZLkny2GA3w3vuyzqUkd+Acl qy8fbSC3OlK/xw2XRYiwMGLBrHkXzEskdV9DOmDB9m8LnoE+rSzCce4SWfMg3xyBhGCM 2O5fFRiPd6QYwyZxzPzqx5VRlefFdTggo6oGEdf3kX9uMaNFbEJTuc2VeWshTgWVn4y2 dbZQ== 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:mime-version :content-transfer-encoding; bh=Rf+ut+vZ0rkmAH/Rce7x5xKiOiWUHGb8d9Igi14P9Lw=; b=X1pPTR/F/Zek1c1eO/Z95iAWMUmeT1HLoCQ+8lfI9MKqZisVW7l1G6AfPs29TDdkof ObXZ1fkaJ6+HwiPbLh6Wyk9D7rcOSmhT4AF5IglnERZVc929ZgjVN5tecfTmtLPqW/Yl oHKp1AfiJ12hYmT2EX4zlkBwPZg8p16fzW2ZeUjyrjrdCOJA2URMNpnBv+u+NsQzkp+8 y4juGsJ2qU7ZkpLJNruhG6dcpUTpmZfOVrYJSmGONp7KdDH5vBQv3hTFzN6scXBlEm3E UQYRhFcycvBo2B8X8fJ6z3ERYP27ItGRzo7wN2U5Fguuq8PF8iIpUgopqoycQ7QAIVkE WJuQ== X-Gm-Message-State: ANhLgQ1YJLBNnMQz59ABNee1wkQSmyVzItYXQzd+Cy39Oe4nFI4e15es kpUnSgFydPNdC5K/57Ou+xw= X-Received: by 2002:a7b:cc6a:: with SMTP id n10mr3829347wmj.170.1583497696717; Fri, 06 Mar 2020 04:28:16 -0800 (PST) Received: from carlo-arch.lan ([2001:b07:6469:6bad:29c8:57ea:bea1:b9b1]) by smtp.gmail.com with ESMTPSA id c62sm13763876wmd.7.2020.03.06.04.28.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Mar 2020 04:28:16 -0800 (PST) From: Carlo Nonato To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, bfq-iosched@googlegroups.com, oleksandr@natalenko.name, Kwon Je Oh Subject: [PATCH BUGFIX] block, bfq: fix overwrite of bfq_group pointer in bfq_find_set_group() Date: Fri, 6 Mar 2020 13:27:31 +0100 Message-Id: <20200306122731.5945-1-carlo.nonato95@gmail.com> X-Mailer: git-send-email 2.25.1 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 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 --- 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 09b69a3ed..f0ff6654a 100644 --- a/block/bfq-cgroup.c +++ b/block/bfq-cgroup.c @@ -610,12 +610,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.25.1