Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2708157pxv; Sun, 11 Jul 2021 23:23:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx/6aPZAl1F1us2avy1LjuzhA4BUM/9U9WNRh0QSo0n36fLmJarQsbIB+JjDa3gPufNa0eV X-Received: by 2002:a17:907:170c:: with SMTP id le12mr430274ejc.288.1626071003966; Sun, 11 Jul 2021 23:23:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626071003; cv=none; d=google.com; s=arc-20160816; b=uUY+IC90lWq0tmz2fBvtuFn2lB/5hPh4giVZEnRqas20tA/lwCFmNRVscSmSILQ/6C l4iOY6q8uuaHTK4WKvRlUFPj1zr4YHh/Gk5XFgSxMh4o9h4KribGhUKlQeWUEpl7TKvy wlhlb3tauDxdBZsf/AAsagS1GSVOcoOR65n3IsetPGnXeDc8XlTYjP6AzEcSKuPdeLol Z/Kk1LeN0UDT7pJXlkmQ11YomSD1vouE5wYrHUkkzvz4VvXfer9MEf5iFebWzl5NuKhh N1glPc4F4b/qkiIoBz6n5PT50ix5rkmN1rWNIF41z+DnKPSMc9cRA3jFISwUJRzVvxYL KaSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Qyx+MWQCoCMZPcc84CV/IfcpN3hRv6B/6S3eEf+9l8c=; b=OrUWRjwa4ZQf00arzcoRa0b2pfhtucZUo0ElIifbFis65kg3KHJ3MnCYDDNNC/2zee xgJrL3EvKXPWp6WmtDM6Legbcd+SDO2PBPkCVSU9Xl+lPNbj4DUIwbh5XMHeZJlfdi99 2RnXHJaZgoUBLNV4ifAs6aiUW0xyh8a43N09GHFkbaoHQ3IiVx60m1/3JGrgyAltLx4o TedUY3OJAyG8DuLBu27nsWsI4WRrJ+/2xSX+gBZ8U82lvWQAjHdrVvdFQ3zEAKHMpQCO 8F1RW6l6MVVqebLnsxzbZH2nVN+UbrkQJeHHTxrNm6bcAKIydpAmxf8kOGgbrleyi2oB +tvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ulqaclRX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ba10si16451598edb.363.2021.07.11.23.23.01; Sun, 11 Jul 2021 23:23:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ulqaclRX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234695AbhGLGYw (ORCPT + 99 others); Mon, 12 Jul 2021 02:24:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:39792 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234632AbhGLGXZ (ORCPT ); Mon, 12 Jul 2021 02:23:25 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2F01E61156; Mon, 12 Jul 2021 06:20:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626070801; bh=LMBdObpsKduGXwb8191KmlvMJGz4aoBvilCCGyX/9dE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ulqaclRXC5tjaB79l2UtxpJxZ2OtuQ0PQtesbuQi58cZ4oer/x1QoT5Yd6zuhiFc6 Tj3Q3uLssX5QCa+5HFTClmhxDhIzNYVT/UUsfz2oaksUoyQKu75Fz76nlEQ14mSWsB qzoI+WvDYp+RaODh76f5ErYSPRZwGuyqaBQZx35g= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Quentin Perret , Qais Yousef , "Peter Zijlstra (Intel)" , Sasha Levin Subject: [PATCH 5.4 145/348] sched/uclamp: Fix locking around cpu_util_update_eff() Date: Mon, 12 Jul 2021 08:08:49 +0200 Message-Id: <20210712060720.335658324@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210712060659.886176320@linuxfoundation.org> References: <20210712060659.886176320@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Qais Yousef [ Upstream commit 93b73858701fd01de26a4a874eb95f9b7156fd4b ] cpu_cgroup_css_online() calls cpu_util_update_eff() without holding the uclamp_mutex or rcu_read_lock() like other call sites, which is a mistake. The uclamp_mutex is required to protect against concurrent reads and writes that could update the cgroup hierarchy. The rcu_read_lock() is required to traverse the cgroup data structures in cpu_util_update_eff(). Surround the caller with the required locks and add some asserts to better document the dependency in cpu_util_update_eff(). Fixes: 7226017ad37a ("sched/uclamp: Fix a bug in propagating uclamp value in new cgroups") Reported-by: Quentin Perret Signed-off-by: Qais Yousef Signed-off-by: Peter Zijlstra (Intel) Link: https://lkml.kernel.org/r/20210510145032.1934078-3-qais.yousef@arm.com Signed-off-by: Sasha Levin --- kernel/sched/core.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 9a01e51b25f4..b23e70db3b6e 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -7199,7 +7199,11 @@ static int cpu_cgroup_css_online(struct cgroup_subsys_state *css) #ifdef CONFIG_UCLAMP_TASK_GROUP /* Propagate the effective uclamp value for the new group */ + mutex_lock(&uclamp_mutex); + rcu_read_lock(); cpu_util_update_eff(css); + rcu_read_unlock(); + mutex_unlock(&uclamp_mutex); #endif return 0; @@ -7289,6 +7293,9 @@ static void cpu_util_update_eff(struct cgroup_subsys_state *css) enum uclamp_id clamp_id; unsigned int clamps; + lockdep_assert_held(&uclamp_mutex); + SCHED_WARN_ON(!rcu_read_lock_held()); + css_for_each_descendant_pre(css, top_css) { uc_parent = css_tg(css)->parent ? css_tg(css)->parent->uclamp : NULL; -- 2.30.2