Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp5067941ybv; Tue, 11 Feb 2020 08:35:38 -0800 (PST) X-Google-Smtp-Source: APXvYqxIl790q0dBeo1E3bbdoEq3LTzTVgwIeL3e++cKOCkBYw+614QubI4z9i3XfPIicfpsKKF5 X-Received: by 2002:aca:4309:: with SMTP id q9mr3426230oia.158.1581438937941; Tue, 11 Feb 2020 08:35:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581438937; cv=none; d=google.com; s=arc-20160816; b=a+wyRBY1MGmraluXPOeNI58F9BwzRdRrDrm447fp49mWCCtZGPlGszdVoQqB2bWJ9d Fz+mwgDDULywrxdiTZl/Pf4ZB28iZ93ivfhCR2jMdoSnrb5A2wLHcMSxQmKGy1hcoOmM W74/JSY7iazTgo982mlUE2im0+KiHfxlin0N41Zgewb/4K/hzTgJX5W2gbazuGAyEqO3 c+2Zx5/26rhCciAWyHAlugqu0WFnaI0zGv8sGmC3k+X9Nks+FQ6nmrYUmGe0WFG4lqSp vEiflle07UenxN9rSk8SImCgOIbBcml52hBlAYiNhy01UzbWg1UlG5+ENSRXVmvKvLZn 3jCw== 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; bh=r5ROJ/iKzEgxbwFmuTvJ5Vl3fQN8IuLjb5C2ZZ/Fdzc=; b=G7Au5SCeZMEWKniyZ9ADpMz7kvgQ6hmvYTR88O7FdnbBFLJwyP4eS1MbeM65MF7AW+ eEwRSdKnRGreoh2+Jx/Wkpb8vyhrHloZ3y/a71YQJu4RiwsmOW9L+F1oY/NIdrElOAbs 9KYJJwl3ajxW8wiu58MRhwxeN/+qHOZnvUFQ3EhY+BL4U+uiFCvYQJkYzG5B9tp5deex HQmJKwP44jjNZYI06nAUEnegXzu2wgpfpMPn6qYLB2ze9dP47bLR5tWlzJQ74erx39NU JFAdC/4ClyEXLJyVa+zcrMWl0aYjwiT6QYXGKc42graRebZGDoQFgA0PT1ibYnSW15ci k8+g== ARC-Authentication-Results: i=1; mx.google.com; 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 n11si2272980otf.36.2020.02.11.08.35.25; Tue, 11 Feb 2020 08:35:37 -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; 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 S1729658AbgBKOP7 (ORCPT + 99 others); Tue, 11 Feb 2020 09:15:59 -0500 Received: from foss.arm.com ([217.140.110.172]:46942 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728495AbgBKOP7 (ORCPT ); Tue, 11 Feb 2020 09:15:59 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 76F3D30E; Tue, 11 Feb 2020 06:15:58 -0800 (PST) Received: from e107158-lin.cambridge.arm.com (e107158-lin.cambridge.arm.com [10.1.195.21]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 9163E3F68F; Tue, 11 Feb 2020 06:15:57 -0800 (PST) From: Qais Yousef To: Li Zefan , Tejun Heo , Johannes Weiner Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Qais Yousef Subject: [PATCH] cgroup/cpuset: Fix a race condition when reading cpuset.* Date: Tue, 11 Feb 2020 14:15:54 +0000 Message-Id: <20200211141554.24181-1-qais.yousef@arm.com> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org LTP cpuset_hotplug_test.sh was failing with the following error message cpuset_hotplug 1 TFAIL: root group's cpus isn't expected(Result: 0-5, Expect: 0,2-5). Which is due to a race condition between cpu hotplug operation and reading cpuset.cpus file. When a cpu is onlined/offlined, cpuset schedules a workqueue to sync its internal data structures with the new values. If a read happens during this window, the user will read a stale value, hence triggering the failure above. To fix the issue make sure cpuset_wait_for_hotplug() is called before allowing any value to be read, hence forcing the synchronization to happen before the read. I ran 500 iterations with this fix applied with no failure triggered. Signed-off-by: Qais Yousef --- I think it's okay to flush the workqueue from the read context? We do it on the write, so I assumed it's okay on the read too. But it'd be good to confirm it doesn't break any rule I'm not aware of. kernel/cgroup/cpuset.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 58f5073acff7..593055522626 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -2405,6 +2405,9 @@ static int cpuset_common_seq_show(struct seq_file *sf, void *v) cpuset_filetype_t type = seq_cft(sf)->private; int ret = 0; + /* Ensure all hotplug ops were done before reading any value */ + cpuset_wait_for_hotplug(); + spin_lock_irq(&callback_lock); switch (type) { -- 2.17.1