All of lore.kernel.org
 help / color / mirror / Atom feed
From: Xishi Qiu <qiuxishi@huawei.com>
To: Christian Borntraeger <borntraeger@de.ibm.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Mel Gorman <mgorman@techsingularity.net>,
	Yaowei Bai <baiyaowei@cmss.chinamobile.com>
Cc: Linux MM <linux-mm@kvack.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Yisheng Xie <xieyisheng1@huawei.com>
Subject: [RFC PATCH v2] mm: use ACCESS_ONCE in page_cpupid_xchg_last()
Date: Mon, 5 Dec 2016 17:26:55 +0800	[thread overview]
Message-ID: <584532DF.7080805@huawei.com> (raw)
In-Reply-To: <0cc3c2bb-e292-2d7b-8d44-16c8e6c19899@de.ibm.com>

A compiler could re-read "old_flags" from the memory location after reading
and calculation "flags" and passes a newer value into the cmpxchg making 
the comparison succeed while it should actually fail.

Signed-off-by: Xishi Qiu <qiuxishi@huawei.com>
Suggested-by: Christian Borntraeger <borntraeger@de.ibm.com>
---
 mm/mmzone.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/mmzone.c b/mm/mmzone.c
index 5652be8..e0b698e 100644
--- a/mm/mmzone.c
+++ b/mm/mmzone.c
@@ -102,7 +102,7 @@ int page_cpupid_xchg_last(struct page *page, int cpupid)
 	int last_cpupid;
 
 	do {
-		old_flags = flags = page->flags;
+		old_flags = flags = ACCESS_ONCE(page->flags);
 		last_cpupid = page_cpupid_last(page);
 
 		flags &= ~(LAST_CPUPID_MASK << LAST_CPUPID_PGSHIFT);
-- 
1.8.3.1



--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

WARNING: multiple messages have this Message-ID (diff)
From: Xishi Qiu <qiuxishi@huawei.com>
To: Christian Borntraeger <borntraeger@de.ibm.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Mel Gorman <mgorman@techsingularity.net>,
	"Yaowei Bai" <baiyaowei@cmss.chinamobile.com>
Cc: Linux MM <linux-mm@kvack.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Yisheng Xie <xieyisheng1@huawei.com>
Subject: [RFC PATCH v2] mm: use ACCESS_ONCE in page_cpupid_xchg_last()
Date: Mon, 5 Dec 2016 17:26:55 +0800	[thread overview]
Message-ID: <584532DF.7080805@huawei.com> (raw)
In-Reply-To: <0cc3c2bb-e292-2d7b-8d44-16c8e6c19899@de.ibm.com>

A compiler could re-read "old_flags" from the memory location after reading
and calculation "flags" and passes a newer value into the cmpxchg making 
the comparison succeed while it should actually fail.

Signed-off-by: Xishi Qiu <qiuxishi@huawei.com>
Suggested-by: Christian Borntraeger <borntraeger@de.ibm.com>
---
 mm/mmzone.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/mmzone.c b/mm/mmzone.c
index 5652be8..e0b698e 100644
--- a/mm/mmzone.c
+++ b/mm/mmzone.c
@@ -102,7 +102,7 @@ int page_cpupid_xchg_last(struct page *page, int cpupid)
 	int last_cpupid;
 
 	do {
-		old_flags = flags = page->flags;
+		old_flags = flags = ACCESS_ONCE(page->flags);
 		last_cpupid = page_cpupid_last(page);
 
 		flags &= ~(LAST_CPUPID_MASK << LAST_CPUPID_PGSHIFT);
-- 
1.8.3.1

  parent reply	other threads:[~2016-12-05  9:39 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-05  8:23 [RFC PATCH] mm: use ACCESS_ONCE in page_cpupid_xchg_last() Xishi Qiu
2016-12-05  8:23 ` Xishi Qiu
2016-12-05  8:31 ` Christian Borntraeger
2016-12-05  8:31   ` Christian Borntraeger
2016-12-05  8:50   ` Christian Borntraeger
2016-12-05  8:50     ` Christian Borntraeger
2016-12-05  9:22     ` Xishi Qiu
2016-12-05  9:22       ` Xishi Qiu
2016-12-05  9:26     ` Xishi Qiu [this message]
2016-12-05  9:26       ` [RFC PATCH v2] " Xishi Qiu
2016-12-05  9:44       ` Christian Borntraeger
2016-12-05  9:44         ` Christian Borntraeger
2016-12-06  1:53 ` [RFC PATCH v3] mm: use READ_ONCE " Xishi Qiu
2016-12-06  1:53   ` Xishi Qiu
2016-12-07  8:39   ` Vlastimil Babka
2016-12-07  8:39     ` Vlastimil Babka
2016-12-07  8:43   ` Michal Hocko
2016-12-07  8:43     ` Michal Hocko
2016-12-07  8:48     ` Vlastimil Babka
2016-12-07  8:48       ` Vlastimil Babka
2016-12-07  8:58       ` Michal Hocko
2016-12-07  8:58         ` Michal Hocko
2016-12-07  9:29         ` Vlastimil Babka
2016-12-07  9:29           ` Vlastimil Babka
2016-12-07  9:40           ` Christian Borntraeger
2016-12-07  9:40             ` Christian Borntraeger
2016-12-07  9:59             ` Michal Hocko
2016-12-07  9:59               ` Michal Hocko
2016-12-07 10:03               ` Christian Borntraeger
2016-12-07 10:03                 ` Christian Borntraeger
2016-12-07 22:16                 ` Rasmus Villemoes
2016-12-07 22:16                   ` Rasmus Villemoes

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=584532DF.7080805@huawei.com \
    --to=qiuxishi@huawei.com \
    --cc=akpm@linux-foundation.org \
    --cc=baiyaowei@cmss.chinamobile.com \
    --cc=borntraeger@de.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mgorman@techsingularity.net \
    --cc=xieyisheng1@huawei.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.