linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Qian Cai <cai@lca.pw>
To: rafael@kernel.org
Cc: elver@google.com, linux-pm@vger.kernel.org,
	linux-kernel@vger.kernel.org, Qian Cai <cai@lca.pw>
Subject: [PATCH -next v2] power/qos: annotate data races in pm_qos_*_value
Date: Tue, 25 Feb 2020 20:58:13 -0500	[thread overview]
Message-ID: <20200226015813.987-1-cai@lca.pw> (raw)

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 <cai@lca.pw>
---

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)


             reply	other threads:[~2020-02-26  1:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-26  1:58 Qian Cai [this message]
2020-03-03 22:37 ` [PATCH -next v2] power/qos: annotate data races in pm_qos_*_value Rafael J. Wysocki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200226015813.987-1-cai@lca.pw \
    --to=cai@lca.pw \
    --cc=elver@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=rafael@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).