All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm: memcontrol: correct the comment in mem_cgroup_swapout()
@ 2015-06-19 16:34 Sebastian Andrzej Siewior
  2015-06-19 17:11 ` Johannes Weiner
  0 siblings, 1 reply; 6+ messages in thread
From: Sebastian Andrzej Siewior @ 2015-06-19 16:34 UTC (permalink / raw
  To: hannes, akpm; +Cc: linux-mm, tglx, rostedt, williams

Clark stumbled over a VM_BUG_ON() in -RT which was then was removed by
Johannes in commit f371763a79d ("mm: memcontrol: fix false-positive
VM_BUG_ON() on -rt"). The comment before that patch was a tiny bit
better than it is now. While the patch claimed to fix a false-postive on
-RT this was not the case. None of the -RT folks ACKed it and it was not a
false positive report. That was a *real* problem.

This patch updates the comment that is improper because it refers to
"disabled preemption" as a consequence of that lock being taken. A
spin_lock() disables preemption, true, but in this case the code relies on
the fact that the lock _also_ disables interrupts once it is acquired. And
this is the important detail (which was checked the VM_BUG_ON()) which needs
to be pointed out. This is the hint one needs while looking at the code. It
was explained by Johannes on the list that the per-CPU variables are protected
by local_irq_save(). The BUG_ON() was helpful. This code has been workarounded
in -RT in the meantime. I wouldn't mind running into more of those if the code
in question uses *special* kind of locking since now there is no no
verification (in terms of lockdep or BUG_ON()).

The two functions after the comment could also have a "local_irq_save()"
dance around them in order to serialize access to the per-CPU variables.
This has been avoided because the interrupts should be off.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 mm/memcontrol.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index a04225d372ba..6e90cf68ff7c 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -5835,7 +5835,12 @@ void mem_cgroup_swapout(struct page *page, swp_entry_t entry)
 	if (!mem_cgroup_is_root(memcg))
 		page_counter_uncharge(&memcg->memory, 1);
 
-	/* Caller disabled preemption with mapping->tree_lock */
+	/*
+	 * Interrupts should be disabled here because the caller holds the
+	 * mapping->tree_lock lock which is taken with interrupts-off. It is
+	 * important here to have the interrupts disabled because it is the
+	 * only synchronisation we have for udpating the per-CPU variables.
+	 */
 	mem_cgroup_charge_statistics(memcg, page, -1);
 	memcg_check_events(memcg, page);
 }
-- 
2.1.4

--
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>

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] mm: memcontrol: correct the comment in mem_cgroup_swapout()
  2015-06-19 16:34 [PATCH] mm: memcontrol: correct the comment in mem_cgroup_swapout() Sebastian Andrzej Siewior
@ 2015-06-19 17:11 ` Johannes Weiner
  2015-06-19 17:18   ` Sebastian Andrzej Siewior
  0 siblings, 1 reply; 6+ messages in thread
From: Johannes Weiner @ 2015-06-19 17:11 UTC (permalink / raw
  To: Sebastian Andrzej Siewior; +Cc: akpm, linux-mm, tglx, rostedt, williams

On Fri, Jun 19, 2015 at 06:34:18PM +0200, Sebastian Andrzej Siewior wrote:
> Clark stumbled over a VM_BUG_ON() in -RT which was then was removed by
> Johannes in commit f371763a79d ("mm: memcontrol: fix false-positive
> VM_BUG_ON() on -rt"). The comment before that patch was a tiny bit
> better than it is now. While the patch claimed to fix a false-postive on
> -RT this was not the case. None of the -RT folks ACKed it and it was not a
> false positive report. That was a *real* problem.

The real problem is that irqs_disabled() on -rt is returning false
negatives.  Having it return false within a spin_lock_irq() section is
broken.

> This patch updates the comment that is improper because it refers to
> "disabled preemption" as a consequence of that lock being taken. A
> spin_lock() disables preemption, true, but in this case the code relies on
> the fact that the lock _also_ disables interrupts once it is acquired. And
> this is the important detail (which was checked the VM_BUG_ON()) which needs
> to be pointed out. This is the hint one needs while looking at the code. It
> was explained by Johannes on the list that the per-CPU variables are protected
> by local_irq_save(). The BUG_ON() was helpful. This code has been workarounded
> in -RT in the meantime. I wouldn't mind running into more of those if the code
> in question uses *special* kind of locking since now there is no no
> verification (in terms of lockdep or BUG_ON()).

I'd be happy to re-instate the VM_BUG_ON that checks for disabled
interrupts as before, that was the most obvious documentation.

--
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>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] mm: memcontrol: correct the comment in mem_cgroup_swapout()
  2015-06-19 17:11 ` Johannes Weiner
@ 2015-06-19 17:18   ` Sebastian Andrzej Siewior
  2015-06-19 17:28     ` Johannes Weiner
  0 siblings, 1 reply; 6+ messages in thread
From: Sebastian Andrzej Siewior @ 2015-06-19 17:18 UTC (permalink / raw
  To: Johannes Weiner; +Cc: akpm, linux-mm, tglx, rostedt, williams

On 06/19/2015 07:11 PM, Johannes Weiner wrote:
> On Fri, Jun 19, 2015 at 06:34:18PM +0200, Sebastian Andrzej Siewior wrote:
>> Clark stumbled over a VM_BUG_ON() in -RT which was then was removed by
>> Johannes in commit f371763a79d ("mm: memcontrol: fix false-positive
>> VM_BUG_ON() on -rt"). The comment before that patch was a tiny bit
>> better than it is now. While the patch claimed to fix a false-postive on
>> -RT this was not the case. None of the -RT folks ACKed it and it was not a
>> false positive report. That was a *real* problem.
> 
> The real problem is that irqs_disabled() on -rt is returning false
> negatives.  Having it return false within a spin_lock_irq() section is
> broken.

As I explained it in
	http://www.spinics.net/lists/linux-rt-users/msg13499.html
it is not.

>> This patch updates the comment that is improper because it refers to
>> "disabled preemption" as a consequence of that lock being taken. A
>> spin_lock() disables preemption, true, but in this case the code relies on
>> the fact that the lock _also_ disables interrupts once it is acquired. And
>> this is the important detail (which was checked the VM_BUG_ON()) which needs
>> to be pointed out. This is the hint one needs while looking at the code. It
>> was explained by Johannes on the list that the per-CPU variables are protected
>> by local_irq_save(). The BUG_ON() was helpful. This code has been workarounded
>> in -RT in the meantime. I wouldn't mind running into more of those if the code
>> in question uses *special* kind of locking since now there is no no
>> verification (in terms of lockdep or BUG_ON()).
> 
> I'd be happy to re-instate the VM_BUG_ON that checks for disabled
> interrupts as before, that was the most obvious documentation.

sure thing, patch follows in a jiffy or two.

Sebastian

--
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>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] mm: memcontrol: correct the comment in mem_cgroup_swapout()
  2015-06-19 17:18   ` Sebastian Andrzej Siewior
@ 2015-06-19 17:28     ` Johannes Weiner
  2015-06-19 17:36       ` [PATCH v2] mm: memcontrol: bring back the VM_BUG_ON() " Sebastian Andrzej Siewior
  0 siblings, 1 reply; 6+ messages in thread
From: Johannes Weiner @ 2015-06-19 17:28 UTC (permalink / raw
  To: Sebastian Andrzej Siewior; +Cc: akpm, linux-mm, tglx, rostedt, williams

On Fri, Jun 19, 2015 at 07:18:31PM +0200, Sebastian Andrzej Siewior wrote:
> On 06/19/2015 07:11 PM, Johannes Weiner wrote:
> > On Fri, Jun 19, 2015 at 06:34:18PM +0200, Sebastian Andrzej Siewior wrote:
> >> Clark stumbled over a VM_BUG_ON() in -RT which was then was removed by
> >> Johannes in commit f371763a79d ("mm: memcontrol: fix false-positive
> >> VM_BUG_ON() on -rt"). The comment before that patch was a tiny bit
> >> better than it is now. While the patch claimed to fix a false-postive on
> >> -RT this was not the case. None of the -RT folks ACKed it and it was not a
> >> false positive report. That was a *real* problem.
> > 
> > The real problem is that irqs_disabled() on -rt is returning false
> > negatives.  Having it return false within a spin_lock_irq() section is
> > broken.
> 
> As I explained it in
> 	http://www.spinics.net/lists/linux-rt-users/msg13499.html
> it is not.

I missed this email, sorry about that.

> >> This patch updates the comment that is improper because it refers to
> >> "disabled preemption" as a consequence of that lock being taken. A
> >> spin_lock() disables preemption, true, but in this case the code relies on
> >> the fact that the lock _also_ disables interrupts once it is acquired. And
> >> this is the important detail (which was checked the VM_BUG_ON()) which needs
> >> to be pointed out. This is the hint one needs while looking at the code. It
> >> was explained by Johannes on the list that the per-CPU variables are protected
> >> by local_irq_save(). The BUG_ON() was helpful. This code has been workarounded
> >> in -RT in the meantime. I wouldn't mind running into more of those if the code
> >> in question uses *special* kind of locking since now there is no no
> >> verification (in terms of lockdep or BUG_ON()).
> > 
> > I'd be happy to re-instate the VM_BUG_ON that checks for disabled
> > interrupts as before, that was the most obvious documentation.
> 
> sure thing, patch follows in a jiffy or two.

Thanks.

--
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>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2] mm: memcontrol: bring back the VM_BUG_ON() in mem_cgroup_swapout()
  2015-06-19 17:28     ` Johannes Weiner
@ 2015-06-19 17:36       ` Sebastian Andrzej Siewior
  2015-06-19 18:02         ` Johannes Weiner
  0 siblings, 1 reply; 6+ messages in thread
From: Sebastian Andrzej Siewior @ 2015-06-19 17:36 UTC (permalink / raw
  To: Johannes Weiner; +Cc: akpm, linux-mm, tglx, rostedt, williams

Clark stumbled over a VM_BUG_ON() in -RT which was then was removed by
Johannes in commit f371763a79d ("mm: memcontrol: fix false-positive
VM_BUG_ON() on -rt"). The comment before that patch was a tiny bit
better than it is now. While the patch claimed to fix a false-postive on
-RT this was not the case. None of the -RT folks ACKed it and it was not a
false positive report. That was a *real* problem.

This patch updates the comment that is improper because it refers to
"disabled preemption" as a consequence of that lock being taken. A
spin_lock() disables preemption, true, but in this case the code relies on
the fact that the lock _also_ disables interrupts once it is acquired. And
this is the important detail (which was checked the VM_BUG_ON()) which needs
to be pointed out. This is the hint one needs while looking at the code. It
was explained by Johannes on the list that the per-CPU variables are protected
by local_irq_save(). The BUG_ON() was helpful. This code has been workarounded
in -RT in the meantime. I wouldn't mind running into more of those if the code
in question uses *special* kind of locking since now there is no
verification (in terms of lockdep or BUG_ON()) and therefore I bring the
VM_BUG_ON() check back in.

The two functions after the comment could also have a "local_irq_save()"
dance around them in order to serialize access to the per-CPU variables.
This has been avoided because the interrupts should be off.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
v1…v2: bring back VM_BUG_ON()

 mm/memcontrol.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index a04225d372ba..fefbb37e5bad 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -5835,7 +5835,13 @@ void mem_cgroup_swapout(struct page *page, swp_entry_t entry)
 	if (!mem_cgroup_is_root(memcg))
 		page_counter_uncharge(&memcg->memory, 1);
 
-	/* Caller disabled preemption with mapping->tree_lock */
+	/*
+	 * Interrupts should be disabled here because the caller holds the
+	 * mapping->tree_lock lock which is taken with interrupts-off. It is
+	 * important here to have the interrupts disabled because it is the
+	 * only synchronisation we have for udpating the per-CPU variables.
+	 */
+	VM_BUG_ON(!irqs_disabled());
 	mem_cgroup_charge_statistics(memcg, page, -1);
 	memcg_check_events(memcg, page);
 }
-- 
2.1.4

--
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>

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] mm: memcontrol: bring back the VM_BUG_ON() in mem_cgroup_swapout()
  2015-06-19 17:36       ` [PATCH v2] mm: memcontrol: bring back the VM_BUG_ON() " Sebastian Andrzej Siewior
@ 2015-06-19 18:02         ` Johannes Weiner
  0 siblings, 0 replies; 6+ messages in thread
From: Johannes Weiner @ 2015-06-19 18:02 UTC (permalink / raw
  To: Sebastian Andrzej Siewior; +Cc: akpm, linux-mm, tglx, rostedt, williams

On Fri, Jun 19, 2015 at 07:36:12PM +0200, Sebastian Andrzej Siewior wrote:
> Clark stumbled over a VM_BUG_ON() in -RT which was then was removed by
> Johannes in commit f371763a79d ("mm: memcontrol: fix false-positive
> VM_BUG_ON() on -rt"). The comment before that patch was a tiny bit
> better than it is now. While the patch claimed to fix a false-postive on
> -RT this was not the case. None of the -RT folks ACKed it and it was not a
> false positive report. That was a *real* problem.
> 
> This patch updates the comment that is improper because it refers to
> "disabled preemption" as a consequence of that lock being taken. A
> spin_lock() disables preemption, true, but in this case the code relies on
> the fact that the lock _also_ disables interrupts once it is acquired. And
> this is the important detail (which was checked the VM_BUG_ON()) which needs
> to be pointed out. This is the hint one needs while looking at the code. It
> was explained by Johannes on the list that the per-CPU variables are protected
> by local_irq_save(). The BUG_ON() was helpful. This code has been workarounded
> in -RT in the meantime. I wouldn't mind running into more of those if the code
> in question uses *special* kind of locking since now there is no
> verification (in terms of lockdep or BUG_ON()) and therefore I bring the
> VM_BUG_ON() check back in.
> 
> The two functions after the comment could also have a "local_irq_save()"
> dance around them in order to serialize access to the per-CPU variables.
> This has been avoided because the interrupts should be off.
> 
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>

Much better, thanks.

Acked-by: Johannes Weiner <hannes@cmpxchg.org>

--
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>

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-06-19 18:03 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-19 16:34 [PATCH] mm: memcontrol: correct the comment in mem_cgroup_swapout() Sebastian Andrzej Siewior
2015-06-19 17:11 ` Johannes Weiner
2015-06-19 17:18   ` Sebastian Andrzej Siewior
2015-06-19 17:28     ` Johannes Weiner
2015-06-19 17:36       ` [PATCH v2] mm: memcontrol: bring back the VM_BUG_ON() " Sebastian Andrzej Siewior
2015-06-19 18:02         ` Johannes Weiner

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.