Skip to contentSkip to conversation

xen/p2m: m2p_find_override: use list_for_each_entry_safe

DISCUSSION Dan Carpenter 3 participants 5 messages Apr 20, 2012

lore
Share & tools
lore
#0 lore raw

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
[email protected]
http://lists.xen.org/xen-devel

#1 lore raw
Quoted 10 lines · Dan Carpenter

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.

Quoted 3 lines

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

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#2 lore raw
Quoted 12 lines · Stefano Stabellini
Quoted 10 lines · Dan Carpenter

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.

Quoted 6 lines

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

#3 lore raw
Quoted 20 lines · Dan Carpenter
Quoted 12 lines · Stefano Stabellini
Quoted 10 lines · Dan Carpenter

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.

Quoted 6 lines

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.

Quoted 7 lines

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.

#4 lore raw
Quoted 29 lines · Stefano Stabellini
Quoted 20 lines · Dan Carpenter
Quoted 12 lines · Stefano Stabellini
Quoted 10 lines · Dan Carpenter

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.

Quoted 6 lines

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.

Quoted 7 lines

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.

Quoted 7 lines

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.