Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp2317317ybv; Fri, 21 Feb 2020 13:09:39 -0800 (PST) X-Google-Smtp-Source: APXvYqzWVH7fWcazZLLzHERLqgmTBiP+sIACo6Sgi/+803tzAee+uV09sM/orwbkVOJALw1P21kl X-Received: by 2002:aca:54cc:: with SMTP id i195mr3668169oib.126.1582319379601; Fri, 21 Feb 2020 13:09:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582319379; cv=none; d=google.com; s=arc-20160816; b=zDCq9PD7ugxVYKJX9y95un0aIgu0EzsZzxegy1t/+s4CNgW3HaTYYqVNDR8Uss5Z3N orXJ8WwhqWrmtesymJz8uQLwmo4w08Ja/CAmF1Z3rwFjJlo/EZP/4wG3b/iuX0aa193I rv7ssEmZpz9K7W9/DMq/P65kOmQ9gyuvAA00xOyf4vkzfIv84tj/Zg0mHTvxrTihXGR9 egSyf0jkjrkIMdP2sSD4cUwh5cfh5wnXkJ3wDHQ1FEzeDWM24e88KJXJfHA6/AAO5NHd gixg1lCY3iC3rRVnVkf7y18+1/kk2bwDA4jxDU2Vy392FgOdeE6LFOQe0jWF/o6wslbm W01Q== 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; bh=ENPq/7GL2LdhwWd45tusEGIXiUDzJQV+38GbQQfDu9Y=; b=xu7lYeO5VK7RoZZ3pMfYrl87A99hEY2p2RoT5e7eKhRAhNrMsx9t53aMhI5hMv9OPT TG/8iwF2YD0c6f1lpTb+2GgFhw+Wg4mN1COhRWzICE2T43rEBAPnNYJ7GaWHbIYEkn0f +W5QsITODWqu5a1WLMLnn9zKIV+YbZ82PmZleqiYOB6GIz86zKy2I2MsznD0S+YCbZX9 Po3t8guNFS9t0A5dR9ROkPy+QB9xnfQGFMMGBImbAZTJAqVstf/YGuOMpp5e4J+qevuJ hg2OCXxmG3j2W6YXYYYfunwK6rSYimC/puZr1YECldGd71uQ/QXhHl70in6I5B9arUuQ W8fA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lca.pw header.s=google header.b=VeesGLC8; 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 d2si2009379oth.267.2020.02.21.13.09.26; Fri, 21 Feb 2020 13:09:39 -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=@lca.pw header.s=google header.b=VeesGLC8; 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 S1729514AbgBUVJU (ORCPT + 99 others); Fri, 21 Feb 2020 16:09:20 -0500 Received: from mail-qk1-f194.google.com ([209.85.222.194]:43305 "EHLO mail-qk1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727362AbgBUVJU (ORCPT ); Fri, 21 Feb 2020 16:09:20 -0500 Received: by mail-qk1-f194.google.com with SMTP id p7so3162057qkh.10 for ; Fri, 21 Feb 2020 13:09:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lca.pw; s=google; h=from:to:cc:subject:date:message-id; bh=ENPq/7GL2LdhwWd45tusEGIXiUDzJQV+38GbQQfDu9Y=; b=VeesGLC8L7IzrzUN89qTRkqVXcW8jd53cLBfKygxcqlUrbJxcGc7bp+qUu5jCyDADH EFzyxAyXvvYYmGIdXrocupJmYKEvrPvx8NDyBs2hFpLJmOBlvlBRikDqJjxCbgQJirlg cnpRslIQxdm/MIQI51Ie35aGcmCU+FF6haH2N+J1IT0hqSkWeq0bJsT6zeiU2NWtk8gw KniHr/MXtAVag3o4PU5+oWGTg5uEij0ZObOHno5LKAr5XeMyQcigiQ7kLrCewHgvYtU+ XeUbjFE/aV8iI2Tq3bFTinhkLWG4Rpg57qRpEOpaz9t/jboqevP8L581oOPP/DWH2ggA hqRA== 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=ENPq/7GL2LdhwWd45tusEGIXiUDzJQV+38GbQQfDu9Y=; b=HyNcYrdTfWtS2GnyH4iE1yai4I4JheqE4u13ucHriIhCjTU4KQU27oI3yLJrHN2GWX 9kYsKoYCGM41nGRzp6PksNkYgPNeWikdESZHpUcj3D9dZDsZbiGq0GhL18hbKBNb0BtI nX2wqMy/B0e7hnHLSG+g17kmJpl6T/KGfCy6z8SNBwIpjwmo5eHWfXjm7bG8t+BFqAi5 l4oVumh0V773lO+pUWxDh7e3x5E19z87i8Rz0tXN3eYBdOorwAXdSrPUlRi7ltYgWJ3o Vy1bemxUj8kf1kpe3G6RFjMyHzo8//3fF9erotLZB1RVsPguKns1JshTWua0M1Amt2Uy Gmfg== X-Gm-Message-State: APjAAAXnIPqXrSQWLpCQmTprWELhwmSbT15qCwufQaSQXPakikOQm8Ae ukIHovrReLoA0E8e0xBIgLv85g== X-Received: by 2002:a37:a84f:: with SMTP id r76mr35023486qke.115.1582319358843; Fri, 21 Feb 2020 13:09:18 -0800 (PST) Received: from qcai.nay.com (nat-pool-bos-t.redhat.com. [66.187.233.206]) by smtp.gmail.com with ESMTPSA id n191sm2120818qkn.6.2020.02.21.13.09.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Feb 2020 13:09:18 -0800 (PST) From: Qian Cai To: rjw@rjwysocki.net Cc: elver@google.com, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Qian Cai Subject: [PATCH -next] power/qos: fix a data race in pm_qos_*_value Date: Fri, 21 Feb 2020 16:09:10 -0500 Message-Id: <1582319350-23515-1-git-send-email-cai@lca.pw> X-Mailer: git-send-email 1.8.3.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org cpu_latency_constraints.target_value could be accessed concurrently as noticed by KCSAN, LTP: starting ppoll01 BUG: KCSAN: data-race in cpu_latency_qos_limit / pm_qos_update_target write to 0xffffffff99081470 of 4 bytes by task 27532 on cpu 2: pm_qos_update_target+0xa4/0x370 pm_qos_set_value at kernel/power/qos.c:78 cpu_latency_qos_apply+0x3b/0x50 cpu_latency_qos_remove_request+0xea/0x270 cpu_latency_qos_release+0x4b/0x70 __fput+0x187/0x3d0 ____fput+0x1e/0x30 task_work_run+0xbf/0x130 do_exit+0xa78/0xfd0 do_group_exit+0x8b/0x180 __x64_sys_exit_group+0x2e/0x30 do_syscall_64+0x91/0xb05 entry_SYSCALL_64_after_hwframe+0x49/0xbe read to 0xffffffff99081470 of 4 bytes by task 0 on cpu 41: cpu_latency_qos_limit+0x1f/0x30 pm_qos_read_value at kernel/power/qos.c:55 cpuidle_governor_latency_req+0x4f/0x80 cpuidle_governor_latency_req at drivers/cpuidle/governor.c:114 menu_select+0x6b/0xc29 cpuidle_select+0x50/0x70 do_idle+0x214/0x280 cpu_startup_entry+0x1d/0x1f start_secondary+0x1b2/0x230 secondary_startup_64+0xb6/0xc0 Reported by Kernel Concurrency Sanitizer on: CPU: 41 PID: 0 Comm: swapper/41 Tainted: G L 5.6.0-rc2-next-20200221+ #7 Hardware name: HPE ProLiant DL385 Gen10/ProLiant DL385 Gen10, BIOS A40 07/10/2019 The read is outside pm_qos_lock critical section which results in a data race. Fix it by adding a pair of READ|WRITE_ONCE(). Signed-off-by: Qian Cai --- kernel/power/qos.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/power/qos.c b/kernel/power/qos.c index 32927682bcc4..db0bed2cae26 100644 --- a/kernel/power/qos.c +++ b/kernel/power/qos.c @@ -52,7 +52,7 @@ */ s32 pm_qos_read_value(struct pm_qos_constraints *c) { - return c->target_value; + return READ_ONCE(c->target_value); } static int pm_qos_get_value(struct pm_qos_constraints *c) @@ -75,7 +75,7 @@ static int pm_qos_get_value(struct pm_qos_constraints *c) static void pm_qos_set_value(struct pm_qos_constraints *c, s32 value) { - c->target_value = value; + WRITE_ONCE(c->target_value, value); } /** -- 1.8.3.1