mm/balloon_compaction: avoid duplicate page removal
Subsystems (2)
PATCH 1/1 mm/balloon_compaction: avoid duplicate page removal
A #GP is reported in the guest when requesting balloon inflation via virtio-balloon. The reason is that the virtio-balloon driver has removed the page from its internal page list (via balloon_page_pop), but balloon_page_enqueue_one also calls "list_del" to do the removal. So remove the list_del in balloon_page_enqueue_one, and have the callers do the page removal from their own page lists.
--- mm/balloon_compaction.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
mm/balloon_compaction.c +2 -1
@@ -11,6 +11,7 @@#include <linux/export.h> #include <linux/balloon_compaction.h> +/* Callers ensure that @page has been removed from its original list. */ static void balloon_page_enqueue_one (struct balloon_dev_info *b_dev_info,struct page *page) {
@@ -21,7 +22,6 @@ static void balloon_page_enqueue_one(struct balloon_dev_info *b_dev_info,* memory corruption is possible and we should stop execution. */ BUG_ON (!trylock_page (page)); -list_del (&page->lru);balloon_page_insert (b_dev_info, page);unlock_page (page);__count_vm_event (BALLOON_INFLATE );
@@ -47,6 +47,7 @@ size_t balloon_page_list_enqueue(struct balloon_dev_info *b_dev_info,spin_lock_irqsave (&b_dev_info->pages_lock, flags);list_for_each_entry_safe (page, tmp, pages, lru) { +list_del (&page->lru);balloon_page_enqueue_one (b_dev_info, page); n_pages++; }
Signature · 1 line
2.7.4
Quoted 6 lines · Wei Wang
Fixes 418a3ab1e778 (mm/balloon_compaction: List interfaces)A #GP is reported in the guest when requesting balloon inflation via virtio-balloon. The reason is that the virtio-balloon driver has removed the page from its internal page list (via
balloon_page_pop), butballoon_page_enqueue_onealso calls "list_del" to do the removal.
I would add here "this is necessary when it's used from balloon_page_enqueue_list but not when it's called from balloon_page_enqueue".
Quoted 4 lines
So remove the
list_delinballoon_page_enqueue_one, and have the callers do the page removal from their own page lists.Signed-off-by Wei Wang <[email protected]>
Patch is good but comments need some work.
mm/balloon_compaction.c line 14
Quoted 13 lines
--- mm/balloon_compaction.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)mm/balloon_compaction.c +1
-0@@ -11,6 +11,7 @@#include <linux/export.h> #include <linux/balloon_compaction.h> +/* Callers ensure that @page has been removed from its original list. */
This comment does not make sense. E.g. balloon_page_enqueue does nothing to ensure this. And drivers are not supposed to care how the page lists are managed. Pls drop.
Instead please add the following to balloon_page_enqueue:
Note: drivers must not call balloon_page_list_enqueue on pages that have been pushed to a list with balloon_page_push before removing them with balloon_page_pop.
To all pages on a list, use balloon_page_list_enqueue instead.
Quoted 21 lines
mm/balloon_compaction.c +1
-1static void balloon_page_enqueue_one (struct balloon_dev_info *b_dev_info,struct page *page) {@@ -21,7 +22,6 @@ static void balloon_page_enqueue_one(struct balloon_dev_info *b_dev_info,* memory corruption is possible and we should stop execution. */ BUG_ON (!trylock_page (page)); -list_del (&page->lru);balloon_page_insert (b_dev_info, page);unlock_page (page);__count_vm_event (BALLOON_INFLATE );@@ -47,6 +47,7 @@ size_t balloon_page_list_enqueue(struct balloon_dev_info *b_dev_info,spin_lock_irqsave (&b_dev_info->pages_lock, flags);list_for_each_entry_safe (page, tmp, pages, lru) { +list_del (&page->lru);balloon_page_enqueue_one (b_dev_info, page); n_pages++; }Signature · 1 line
2.7.4
Quoted 34 lines · Michael S. Tsirkin
Quoted 6 lines · Wei Wang
Fixes 418a3ab1e778 (mm/balloon_compaction: List interfaces)A #GP is reported in the guest when requesting balloon inflation via virtio-balloon. The reason is that the virtio-balloon driver has removed the page from its internal page list (via
balloon_page_pop), butballoon_page_enqueue_onealso calls "list_del" to do the removal.I would add here "this is necessary when it's used from
balloon_page_enqueue_listbut not when it's called fromballoon_page_enqueue".Quoted 4 lines
So remove the
list_delinballoon_page_enqueue_one, and have the callers do the page removal from their own page lists.Signed-off-by Wei Wang <[email protected]>Patch is good but comments need some work.
mm/balloon_compaction.c line 14
Quoted 13 lines
--- mm/balloon_compaction.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)mm/balloon_compaction.c +1
-0@@ -11,6 +11,7 @@#include <linux/export.h> #include <linux/balloon_compaction.h> +/* Callers ensure that @page has been removed from its original list. */ This comment does not make sense. E.g.
balloon_page_enqueuedoes nothing to ensure this. And drivers are not supposed to care how the page lists are managed. Pls drop.
Quoted 4 lines
Instead please add the following to
balloon_page_enqueue:Note: drivers must not call
balloon_page_list_enqueueon
Probably, you meant balloon_page_enqueue here.
The description for balloon_page_enqueue also seems incorrect:
"allocates a new page and inserts it into the balloon page list." This function doesn't do any allocation itself.
Plan to reword it: inserts a new page into the balloon page list."
Best,
Wei
Quoted 34 lines · Wei Wang
Quoted 33 lines · Michael S. Tsirkin
Quoted 6 lines · Wei Wang
Fixes 418a3ab1e778 (mm/balloon_compaction: List interfaces)A #GP is reported in the guest when requesting balloon inflation via virtio-balloon. The reason is that the virtio-balloon driver has removed the page from its internal page list (via
balloon_page_pop), butballoon_page_enqueue_onealso calls "list_del" to do the removal.I would add here "this is necessary when it's used from
balloon_page_enqueue_listbut not when it's called fromballoon_page_enqueue".Quoted 4 lines
So remove the
list_delinballoon_page_enqueue_one, and have the callers do the page removal from their own page lists.Signed-off-by Wei Wang <[email protected]>Patch is good but comments need some work.
mm/balloon_compaction.c line 13
Quoted 12 lines
--- mm/balloon_compaction.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)mm/balloon_compaction.c +1
-0@@ -11,6 +11,7 @@#include <linux/export.h> #include <linux/balloon_compaction.h> +/* Callers ensure that @page has been removed from its original list. */ This comment does not make sense. E.g.
balloon_page_enqueuedoes nothing to ensure this. And drivers are not supposed to care how the page lists are managed. Pls drop.
Quoted 6 lines
Quoted 4 lines
Instead please add the following to
balloon_page_enqueue:Note: drivers must not call
balloon_page_list_enqueueonProbably, you meant
balloon_page_enqueuehere.
yes
Quoted 4 lines
The description for
balloon_page_enqueuealso seems incorrect:
"allocates a new page and inserts it into the balloon page list." This function doesn't do any allocation itself.
Plan to reword it: inserts a new page into the balloon page list."
And maybe
" Page must have been allocated with balloon_page_alloc.".
Also
* Driver must call it to properly enqueue a balloon pages before definitively
should be
* Driver must call it to properly enqueue balloon pages before definitively
Quoted 3 lines
Best,
Wei