All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: xen/p2m: m2p_find_override: use list_for_each_entry_safe
@ 2012-04-20 10:51 Dan Carpenter
  2012-04-20 11:23 ` Stefano Stabellini
  0 siblings, 1 reply; 5+ messages in thread
From: Dan Carpenter @ 2012-04-20 10:51 UTC (permalink / raw)
  To: stefano.stabellini; +Cc: xen-devel, Konrad Rzeszutek Wilk

Hi Stefano,

I had a question about 8f2854c74ff4: "xen/p2m: m2p_find_override: use
list_for_each_entry_safe".

I think there is a misunderstanding about what the
list_for_each_entry_safe() macro does.  It has nothing to do with
locking, so the spinlock is still needed.  Without the lock ->next could
point to an element which has been deleted in another thread.  Probably
the patch should be reverted.

Also, it introduces a GCC warning:
arch/x86/xen/p2m.c:811:16: warning: unused variable ‘flags’
	[-Wunused-variable]

regards,
dan carpenter


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

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

* Re: xen/p2m: m2p_find_override: use list_for_each_entry_safe
  2012-04-20 10:51 xen/p2m: m2p_find_override: use list_for_each_entry_safe Dan Carpenter
@ 2012-04-20 11:23 ` Stefano Stabellini
  2012-04-20 11:35   ` Dan Carpenter
  0 siblings, 1 reply; 5+ messages in thread
From: Stefano Stabellini @ 2012-04-20 11:23 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: xen-devel, Konrad Rzeszutek Wilk, Stefano Stabellini

[-- Attachment #1: Type: text/plain, Size: 1033 bytes --]

On Fri, 20 Apr 2012, Dan Carpenter wrote:
> Hi Stefano,
> 
> I had a question about 8f2854c74ff4: "xen/p2m: m2p_find_override: use
> list_for_each_entry_safe".
> 
> I think there is a misunderstanding about what the
> list_for_each_entry_safe() macro does.  It has nothing to do with
> locking, so the spinlock is still needed.  Without the lock ->next could
> point to an element which has been deleted in another thread.  Probably
> the patch should be reverted.

I thought that list_for_each_entry_safe is safe against deletion, is it
not?
It doesn't matter whether we get up to date entries or old entries
here as long as walking through the list doesn't break if a concurrent
thread adds or removes items.


> Also, it introduces a GCC warning:
> arch/x86/xen/p2m.c:811:16: warning: unused variable ‘flags’
> 	[-Wunused-variable]

I think that Konrad didn't submit the latest version of the patch (v3),
that has a better description and also removes the flags variable:
http://marc.info/?l=linux-kernel&m=133407526406072&w=2

[-- Attachment #2: Type: text/plain, Size: 126 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

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

* Re: xen/p2m: m2p_find_override: use list_for_each_entry_safe
  2012-04-20 11:23 ` Stefano Stabellini
@ 2012-04-20 11:35   ` Dan Carpenter
  2012-04-20 13:36     ` Stefano Stabellini
  0 siblings, 1 reply; 5+ messages in thread
From: Dan Carpenter @ 2012-04-20 11:35 UTC (permalink / raw)
  To: Stefano Stabellini; +Cc: xen-devel, Konrad Rzeszutek Wilk

On Fri, Apr 20, 2012 at 12:23:21PM +0100, Stefano Stabellini wrote:
> On Fri, 20 Apr 2012, Dan Carpenter wrote:
> > Hi Stefano,
> > 
> > I had a question about 8f2854c74ff4: "xen/p2m: m2p_find_override: use
> > list_for_each_entry_safe".
> > 
> > I think there is a misunderstanding about what the
> > list_for_each_entry_safe() macro does.  It has nothing to do with
> > locking, so the spinlock is still needed.  Without the lock ->next could
> > point to an element which has been deleted in another thread.  Probably
> > the patch should be reverted.
> 
> I thought that list_for_each_entry_safe is safe against deletion, is it
> not?
> It doesn't matter whether we get up to date entries or old entries
> here as long as walking through the list doesn't break if a concurrent
> thread adds or removes items.
> 

It's safe against deletion in the same thread.  But not against
deletion from another thread.

At the beginning of the loop it stores a pointer to the next
element.  If you delete the element you are on, no problem because
you already have a pointer to the next one.  But if another thread
deletes the next element, now you have a pointer which is wrong.

regards,
dan carpenter

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

* Re: xen/p2m: m2p_find_override: use list_for_each_entry_safe
  2012-04-20 11:35   ` Dan Carpenter
@ 2012-04-20 13:36     ` Stefano Stabellini
  2012-04-20 16:01       ` Konrad Rzeszutek Wilk
  0 siblings, 1 reply; 5+ messages in thread
From: Stefano Stabellini @ 2012-04-20 13:36 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: xen-devel, Konrad Rzeszutek Wilk, Stefano Stabellini

On Fri, 20 Apr 2012, Dan Carpenter wrote:
> On Fri, Apr 20, 2012 at 12:23:21PM +0100, Stefano Stabellini wrote:
> > On Fri, 20 Apr 2012, Dan Carpenter wrote:
> > > Hi Stefano,
> > > 
> > > I had a question about 8f2854c74ff4: "xen/p2m: m2p_find_override: use
> > > list_for_each_entry_safe".
> > > 
> > > I think there is a misunderstanding about what the
> > > list_for_each_entry_safe() macro does.  It has nothing to do with
> > > locking, so the spinlock is still needed.  Without the lock ->next could
> > > point to an element which has been deleted in another thread.  Probably
> > > the patch should be reverted.
> > 
> > I thought that list_for_each_entry_safe is safe against deletion, is it
> > not?
> > It doesn't matter whether we get up to date entries or old entries
> > here as long as walking through the list doesn't break if a concurrent
> > thread adds or removes items.
> > 
> 
> It's safe against deletion in the same thread.  But not against
> deletion from another thread.
> 
> At the beginning of the loop it stores a pointer to the next
> element.  If you delete the element you are on, no problem because
> you already have a pointer to the next one.  But if another thread
> deletes the next element, now you have a pointer which is wrong.

The problem is not that the next element is wrong because we should be
able to cope with that.
The problem is that the next->next pointer would be set LIST_POISON1.

Maybe replacing our call to list_del with __list_del would be sufficient
to solve the problem?
Probably it is best to revert the patch at this stage.

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

* Re: xen/p2m: m2p_find_override: use list_for_each_entry_safe
  2012-04-20 13:36     ` Stefano Stabellini
@ 2012-04-20 16:01       ` Konrad Rzeszutek Wilk
  0 siblings, 0 replies; 5+ messages in thread
From: Konrad Rzeszutek Wilk @ 2012-04-20 16:01 UTC (permalink / raw)
  To: Stefano Stabellini; +Cc: xen-devel, Dan Carpenter

On Fri, Apr 20, 2012 at 02:36:59PM +0100, Stefano Stabellini wrote:
> On Fri, 20 Apr 2012, Dan Carpenter wrote:
> > On Fri, Apr 20, 2012 at 12:23:21PM +0100, Stefano Stabellini wrote:
> > > On Fri, 20 Apr 2012, Dan Carpenter wrote:
> > > > Hi Stefano,
> > > > 
> > > > I had a question about 8f2854c74ff4: "xen/p2m: m2p_find_override: use
> > > > list_for_each_entry_safe".
> > > > 
> > > > I think there is a misunderstanding about what the
> > > > list_for_each_entry_safe() macro does.  It has nothing to do with
> > > > locking, so the spinlock is still needed.  Without the lock ->next could
> > > > point to an element which has been deleted in another thread.  Probably
> > > > the patch should be reverted.
> > > 
> > > I thought that list_for_each_entry_safe is safe against deletion, is it
> > > not?
> > > It doesn't matter whether we get up to date entries or old entries
> > > here as long as walking through the list doesn't break if a concurrent
> > > thread adds or removes items.
> > > 
> > 
> > It's safe against deletion in the same thread.  But not against
> > deletion from another thread.
> > 
> > At the beginning of the loop it stores a pointer to the next
> > element.  If you delete the element you are on, no problem because
> > you already have a pointer to the next one.  But if another thread
> > deletes the next element, now you have a pointer which is wrong.
> 
> The problem is not that the next element is wrong because we should be
> able to cope with that.
> The problem is that the next->next pointer would be set LIST_POISON1.
> 
> Maybe replacing our call to list_del with __list_del would be sufficient
> to solve the problem?
> Probably it is best to revert the patch at this stage.

ok, reverted.

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

end of thread, other threads:[~2012-04-20 16:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-20 10:51 xen/p2m: m2p_find_override: use list_for_each_entry_safe Dan Carpenter
2012-04-20 11:23 ` Stefano Stabellini
2012-04-20 11:35   ` Dan Carpenter
2012-04-20 13:36     ` Stefano Stabellini
2012-04-20 16:01       ` Konrad Rzeszutek Wilk

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.