From: Rafael Aquini <aquini@redhat.com>
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
virtualization@lists.linux-foundation.org,
Rusty Russell <rusty@rustcorp.com.au>,
Rik van Riel <riel@redhat.com>, Mel Gorman <mel@csn.ul.ie>,
Andi Kleen <andi@firstfloor.org>,
Andrew Morton <akpm@linux-foundation.org>,
Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>,
Minchan Kim <minchan@kernel.org>
Subject: Re: [PATCH v7 2/4] virtio_balloon: introduce migration primitives to balloon pages
Date: Tue, 14 Aug 2012 15:22:45 -0300 [thread overview]
Message-ID: <20120814182244.GB13338@t510.redhat.com> (raw)
In-Reply-To: <20120813084123.GF14081@redhat.com>
On Mon, Aug 13, 2012 at 11:41:23AM +0300, Michael S. Tsirkin wrote:
> > @@ -141,7 +151,10 @@ static void fill_balloon(struct virtio_balloon *vb, size_t num)
> > set_page_pfns(vb->pfns + vb->num_pfns, page);
> > vb->num_pages += VIRTIO_BALLOON_PAGES_PER_PAGE;
> > totalram_pages--;
> > + spin_lock(&pages_lock);
> > list_add(&page->lru, &vb->pages);
>
> If list_add above is reordered with mapping assignment below,
> then nothing bad happens because balloon_mapping takes
> pages_lock.
>
> > + page->mapping = balloon_mapping;
> > + spin_unlock(&pages_lock);
> > }
> >
> > /* Didn't get any? Oh well. */
> > @@ -149,6 +162,7 @@ static void fill_balloon(struct virtio_balloon *vb, size_t num)
> > return;
> >
> > tell_host(vb, vb->inflate_vq);
> > + mutex_unlock(&balloon_lock);
> > }
> >
> > static void release_pages_by_pfn(const u32 pfns[], unsigned int num)
> > @@ -169,10 +183,22 @@ static void leak_balloon(struct virtio_balloon *vb, size_t num)
> > /* We can only do one array worth at a time. */
> > num = min(num, ARRAY_SIZE(vb->pfns));
> >
> > + mutex_lock(&balloon_lock);
> > for (vb->num_pfns = 0; vb->num_pfns < num;
> > vb->num_pfns += VIRTIO_BALLOON_PAGES_PER_PAGE) {
> > + /*
> > + * We can race against virtballoon_isolatepage() and end up
> > + * stumbling across a _temporarily_ empty 'pages' list.
> > + */
> > + spin_lock(&pages_lock);
> > + if (unlikely(list_empty(&vb->pages))) {
> > + spin_unlock(&pages_lock);
> > + break;
> > + }
> > page = list_first_entry(&vb->pages, struct page, lru);
> > + page->mapping = NULL;
>
> Unlike the case above, here
> if = NULL write above is reordered with list_del below,
> then isolate_page can run on a page that is not
> on lru.
>
> So I think this needs a wmb().
> And maybe a comment above explaining why it is safe?
Good point. Presumably, this nit has potential to explain your guessing on the
read barrier stuff at movable_balloon_page() on the other patch.
> > list_del(&page->lru);
>
> I wonder why changing page->lru here is safe against
> races with unmap_and_move in the previous patch.
leak_balloon() doesn't race against unmap_and_move() because the later works on
an isolated page set. So, theoretically, pages being dequeued from balloon page
list here are either migrated (already) or they were not isolated yet.
> > +/*
> > + * '*vb_ptr' allows virtballoon_migratepage() & virtballoon_putbackpage() to
> > + * access pertinent elements from struct virtio_balloon
> > + */
>
> What if there is more than one balloon device?
Is it possible to load this driver twice, or are you foreseeing a future case
where this driver will be able to manage several distinct memory balloons for
the same guest?
> > + /* Init the ballooned page->mapping special balloon_mapping */
> > + balloon_mapping = kmalloc(sizeof(*balloon_mapping), GFP_KERNEL);
> > + if (!balloon_mapping) {
> > + err = -ENOMEM;
> > + goto out_free_vb;
> > + }
>
> Can balloon_mapping be dereferenced at this point?
> Then what happens?
Since there's no balloon page enqueued for this balloon driver yet, there's no
chance of balloon_mapping being dereferenced at this point.
> > +
> > + INIT_RADIX_TREE(&balloon_mapping->page_tree, GFP_ATOMIC | __GFP_NOWARN);
> > + INIT_LIST_HEAD(&balloon_mapping->i_mmap_nonlinear);
> > + spin_lock_init(&balloon_mapping->tree_lock);
> > + balloon_mapping->a_ops = &virtio_balloon_aops;
> >
> > err = init_vqs(vb);
> > if (err)
> > @@ -373,6 +493,7 @@ out_del_vqs:
> > vdev->config->del_vqs(vdev);
> > out_free_vb:
> > kfree(vb);
> > + kfree(balloon_mapping);
>
> No need to set it to NULL? It seems if someone else allocates a mapping
> and gets this chunk of memory by chance, the logic in mm will get
> confused.
Good point. It surely doesn't hurt be asured of this sort of safety.
> > out:
> > return err;
> > }
> > @@ -397,6 +518,7 @@ static void __devexit virtballoon_remove(struct virtio_device *vdev)
> > kthread_stop(vb->thread);
> > remove_common(vb);
> > kfree(vb);
> > + kfree(balloon_mapping);
>
> Neither here?
ditto.
> > }
> >
> > #ifdef CONFIG_PM
> > diff --git a/include/linux/virtio_balloon.h b/include/linux/virtio_balloon.h
> > index 652dc8b..930f1b7 100644
> > --- a/include/linux/virtio_balloon.h
> > +++ b/include/linux/virtio_balloon.h
> > @@ -56,4 +56,8 @@ struct virtio_balloon_stat {
> > u64 val;
> > } __attribute__((packed));
> >
> > +#if !defined(CONFIG_COMPACTION)
> > +struct address_space *balloon_mapping;
> > +#endif
> > +
>
> Anyone including this header will get a different copy of
> balloon_mapping. Besides, need to be ifdef KERNEL.
Good point. I'll move this hunk to the balloon driver itself.
--
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>
next prev parent reply other threads:[~2012-08-14 18:23 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-10 17:55 [PATCH v7 0/4] make balloon pages movable by compaction Rafael Aquini
2012-08-10 17:55 ` [PATCH v7 1/4] mm: introduce compaction and migration for virtio ballooned pages Rafael Aquini
2012-08-12 23:14 ` Minchan Kim
2012-08-13 8:26 ` Michael S. Tsirkin
2012-08-14 17:44 ` Rafael Aquini
2012-08-14 19:35 ` Michael S. Tsirkin
2012-08-14 19:48 ` Michael S. Tsirkin
2012-08-14 20:03 ` Rafael Aquini
2012-08-14 20:00 ` Rafael Aquini
2012-08-14 20:23 ` Michael S. Tsirkin
2012-08-15 8:52 ` Mel Gorman
2012-08-14 19:52 ` Michael S. Tsirkin
2012-08-10 17:55 ` [PATCH v7 2/4] virtio_balloon: introduce migration primitives to balloon pages Rafael Aquini
2012-08-13 8:41 ` Michael S. Tsirkin
2012-08-13 23:59 ` Rusty Russell
2012-08-14 8:33 ` Michael S. Tsirkin
2012-08-14 18:44 ` Rafael Aquini
2012-08-14 19:31 ` Michael S. Tsirkin
2012-08-15 12:34 ` Rafael Aquini
2012-08-15 14:40 ` Michael S. Tsirkin
2012-08-20 2:29 ` Rusty Russell
2012-08-20 5:12 ` Michael S. Tsirkin
2012-08-15 3:13 ` Rusty Russell
2012-08-14 18:22 ` Rafael Aquini [this message]
2012-08-14 19:51 ` Michael S. Tsirkin
2012-08-14 19:59 ` Michael S. Tsirkin
2012-08-14 20:08 ` Rafael Aquini
2012-08-14 20:24 ` Michael S. Tsirkin
2012-08-14 20:29 ` Rafael Aquini
2012-08-14 20:49 ` Michael S. Tsirkin
2012-08-14 20:54 ` Michael S. Tsirkin
2012-08-14 20:56 ` Rik van Riel
2012-08-14 21:38 ` Michael S. Tsirkin
2012-08-15 15:30 ` Rik van Riel
2012-08-14 21:34 ` Rafael Aquini
2012-08-14 22:48 ` Michael S. Tsirkin
2012-08-14 20:11 ` Rafael Aquini
2012-08-14 20:31 ` Michael S. Tsirkin
2012-08-15 9:05 ` Mel Gorman
2012-08-15 9:25 ` Michael S. Tsirkin
2012-08-15 9:48 ` Mel Gorman
2012-08-15 10:01 ` Michael S. Tsirkin
2012-08-15 11:16 ` Mel Gorman
2012-08-15 11:28 ` Michael S. Tsirkin
2012-08-21 5:31 ` Rusty Russell
2012-08-22 0:37 ` Michael S. Tsirkin
2012-08-10 17:55 ` [PATCH v7 3/4] mm: introduce putback_movable_pages() Rafael Aquini
2012-08-12 23:26 ` Minchan Kim
2012-08-10 17:55 ` [PATCH v7 4/4] mm: add vm event counters for balloon pages compaction Rafael Aquini
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=20120814182244.GB13338@t510.redhat.com \
--to=aquini@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=andi@firstfloor.org \
--cc=konrad.wilk@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mel@csn.ul.ie \
--cc=minchan@kernel.org \
--cc=mst@redhat.com \
--cc=riel@redhat.com \
--cc=rusty@rustcorp.com.au \
--cc=virtualization@lists.linux-foundation.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox