Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp4330139ybv; Tue, 25 Feb 2020 17:59:09 -0800 (PST) X-Google-Smtp-Source: APXvYqwWbDNLOESi/SDVXIxdnLm35vOqbVqEezXiF2+EFahsOdBTUJEHuRvqKfKYhC3ym9BpMq8j X-Received: by 2002:a54:4805:: with SMTP id j5mr1364574oij.29.1582682349561; Tue, 25 Feb 2020 17:59:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582682349; cv=none; d=google.com; s=arc-20160816; b=MQlJ7lNNimxnaZlTL9z2MnrW9CtURIh1mS9zG+vAjXOIA/OWykGYhpTXHlNNAVsv3A 6v9UYc22Kef4R/KPhW76Se55QhQtxCuzNz8lwYgxY+ugtRE1IRp8lgMLiTZ0jxxOx6Pg LvkZRRDMY0eZwYHRDesuVBHEob5lImJ5X0HnsUj4oo7mXEsdG1coBhrSrjGSs41gpG6h Df7cD/xh9+eJAgYg0IcW3/++BnS9bqg6CdPy187fo3x6txg8zpKCiR9UtOf/KHC01dnR 7E1J6CAgv6+g9H39WNz6EaSZISRg21OvSGrs1mCm4BLrn11UexiWqu1lRPh148iP/WX/ ojJg== 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=3W6dUjneFw3Iq5j0LRHddz/04ra8gT9SV1GqromcUcA=; b=e4VXTfIYg5A0AIYNdXhXopNVU2dsH2Nburq7iBugt4QVhrazVSrgE7KMZw0P81Ku59 uNleH/R+z3JBGDXLVLBUxF5oi1LRjpgXGlg1AEe30Cc93i/aSne53CqpcC/4ykhYqXlK s5OFEUkwCfMRPu1Xam0EsJnroSInDNkWscxs7wTPRJavBeYMKWYbPF12HohYD9CQDeCQ SNfPaKxKPj5daLPt7GtM7kjtjek7ejOrWrrYVybhT+yEceNRY3FYrLyvCn/n6r+Bvd8v stMphJE7AmGvVMsNqM8I8nf7VyFbz7eDVObPwn8emjg41jjf8MKqHECY92rJkZY12txX US/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lca.pw header.s=google header.b="p1b6DIB/"; 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 l10si385079oth.243.2020.02.25.17.58.57; Tue, 25 Feb 2020 17:59:09 -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="p1b6DIB/"; 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 S1729989AbgBZB6Z (ORCPT + 99 others); Tue, 25 Feb 2020 20:58:25 -0500 Received: from mail-qt1-f194.google.com ([209.85.160.194]:38763 "EHLO mail-qt1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727809AbgBZB6Z (ORCPT ); Tue, 25 Feb 2020 20:58:25 -0500 Received: by mail-qt1-f194.google.com with SMTP id i23so1164591qtr.5 for ; Tue, 25 Feb 2020 17:58:24 -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:mime-version :content-transfer-encoding; bh=3W6dUjneFw3Iq5j0LRHddz/04ra8gT9SV1GqromcUcA=; b=p1b6DIB/zaPCoKDbRHx56Ttn3E//aAfWWDn5ysoYfvW9M17pCbsmV09+Z/c1eYrgYT RLTBR6fyj9srVTEglPmT6kRF5IjSO/9MH40LH7aL2K5L0ywykQNdGuGmcBoh7+g20L/S 4Hz0X55LGUiN8wlKC5ak0ibUvEkrv71+M1Ue6SrYDgJEVxuPB10/Dvy3waU+0NZTGszW afkV03q05woG9KXAuYUXZPHO9kcMr2Wf0wussfbM34enqv7vS26F6o//x03jcLx9zOXc QpBHg9A0nAt62FEphlR4ouYHAs0nsgfx0P/SuHe5AWaKE/CuSIpB55fBGtOCmOfS7LCj ha0A== 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=3W6dUjneFw3Iq5j0LRHddz/04ra8gT9SV1GqromcUcA=; b=X3DJ4pJT0fuxT7d/vF6tQta75cHHRY6hfxKeUSBBO6XZs91qt2Qw4pKsf5VtfyNsqV V97rIddOB8UzqSzRx66L3LAheS8H6aEP5QdYNYHhwu5DW+B4FwRO27e7kHRjWa4IsVWe lFZkE3TLwWiuNQcmvFEIu0hXu37xVMCKOrApqsZJfr9BrF5PEGLbKT4Xs49m2TUT0bKg zCg3e1ZJfRcVQF7Mch+W+5qLCGx28dzNNLKOVoz5UH81Y/0IuB/W+lq8EX5SKS9PUKfL FIZMxPt1w4KfL8W5XkAP8Lh/POcrX52KhEjvM16aWZgp0xKDc4Ubw0DhvETpbFnQ5NVB g8Fg== X-Gm-Message-State: APjAAAV6SS0X1KWH7pmHjWyUULlnAaPMU5ESlS+XGdgYEEfOOKgVOPL4 LZpj4VMp4SLC0pytGxE5JTn03A== X-Received: by 2002:ac8:1b18:: with SMTP id y24mr2071113qtj.158.1582682304323; Tue, 25 Feb 2020 17:58:24 -0800 (PST) Received: from ovpn-121-122.rdu2.redhat.com (pool-71-184-117-43.bstnma.fios.verizon.net. [71.184.117.43]) by smtp.gmail.com with ESMTPSA id v80sm283450qka.15.2020.02.25.17.58.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 25 Feb 2020 17:58:23 -0800 (PST) From: Qian Cai To: rafael@kernel.org Cc: elver@google.com, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Qian Cai Subject: [PATCH -next v2] power/qos: annotate data races in pm_qos_*_value Date: Tue, 25 Feb 2020 20:58:13 -0500 Message-Id: <20200226015813.987-1-cai@lca.pw> X-Mailer: git-send-email 2.21.0 (Apple Git-122.2) 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 target_value field in struct pm_qos_constraints is used for lockless access to the effective constraint value of a given QoS list, so the readers of it cannot expect it to always reflect the most recent effective constraint value. However, they can and do expect it to be equal to a valid effective constraint value computed at a certain time in the past (event though it may not be the most recent one), so add READ|WRITE_ONCE() annotations around the target_value accesses to prevent the compiler from possibly causing that expectation to be unmet by generating code in an exceptionally convoluted way. Signed-off-by: Qian Cai --- v2: borrow the commit log from Rafael. 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 @@ static DEFINE_SPINLOCK(pm_qos_lock); */ 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); } /** -- 2.21.0 (Apple Git-122.2)