From: Nitesh Narayan Lal <nitesh@redhat.com>
To: Alexander Duyck <alexander.duyck@gmail.com>
Cc: kvm list <kvm@vger.kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
linux-mm <linux-mm@kvack.org>,
Paolo Bonzini <pbonzini@redhat.com>,
lcapitulino@redhat.com, pagupta@redhat.com, wei.w.wang@intel.com,
Yang Zhang <yang.zhang.wz@gmail.com>,
Rik van Riel <riel@surriel.com>,
David Hildenbrand <david@redhat.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
dodgen@google.com, Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>,
dhildenb@redhat.com, Andrea Arcangeli <aarcange@redhat.com>
Subject: Re: [RFC][Patch v9 3/6] KVM: Enables the kernel to report isolated pages
Date: Thu, 7 Mar 2019 08:23:11 -0500 [thread overview]
Message-ID: <7e1d0731-46e8-443e-7c37-62999fcb5642@redhat.com> (raw)
In-Reply-To: <CAKgT0Udrzo4Ddx4UsJr+x-kgEVJpzQf_PhtAmoShSU8PPDOZEQ@mail.gmail.com>
[-- Attachment #1.1: Type: text/plain, Size: 10580 bytes --]
On 3/6/19 4:30 PM, Alexander Duyck wrote:
> On Wed, Mar 6, 2019 at 7:51 AM Nitesh Narayan Lal <nitesh@redhat.com> wrote:
>> This patch enables the kernel to report the isolated pages
>> to the host via virtio balloon driver.
>> In order to do so a new virtuqeue (hinting_vq) is added to the
>> virtio balloon driver. As the host responds back after freeing
>> the pages, all the isolated pages are returned back to the buddy
>> via __free_one_page().
>>
>> Signed-off-by: Nitesh Narayan Lal <nitesh@redhat.com>
> I ran into a few build issues due to this patch. Comments below.
>
>> ---
>> drivers/virtio/virtio_balloon.c | 72 ++++++++++++++++++++++++++++-
>> include/linux/page_hinting.h | 4 ++
>> include/uapi/linux/virtio_balloon.h | 8 ++++
>> virt/kvm/page_hinting.c | 18 ++++++--
>> 4 files changed, 98 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
>> index 728ecd1eea30..cfe7574b5204 100644
>> --- a/drivers/virtio/virtio_balloon.c
>> +++ b/drivers/virtio/virtio_balloon.c
>> @@ -57,13 +57,15 @@ enum virtio_balloon_vq {
>> VIRTIO_BALLOON_VQ_INFLATE,
>> VIRTIO_BALLOON_VQ_DEFLATE,
>> VIRTIO_BALLOON_VQ_STATS,
>> + VIRTIO_BALLOON_VQ_HINTING,
>> VIRTIO_BALLOON_VQ_FREE_PAGE,
>> VIRTIO_BALLOON_VQ_MAX
>> };
>>
>> struct virtio_balloon {
>> struct virtio_device *vdev;
>> - struct virtqueue *inflate_vq, *deflate_vq, *stats_vq, *free_page_vq;
>> + struct virtqueue *inflate_vq, *deflate_vq, *stats_vq, *free_page_vq,
>> + *hinting_vq;
>>
>> /* Balloon's own wq for cpu-intensive work items */
>> struct workqueue_struct *balloon_wq;
>> @@ -122,6 +124,56 @@ static struct virtio_device_id id_table[] = {
>> { 0 },
>> };
>>
>> +#ifdef CONFIG_KVM_FREE_PAGE_HINTING
>> +int virtballoon_page_hinting(struct virtio_balloon *vb,
>> + void *hinting_req,
>> + int entries)
>> +{
>> + struct scatterlist sg;
>> + struct virtqueue *vq = vb->hinting_vq;
>> + int err;
>> + int unused;
>> + struct virtio_balloon_hint_req *hint_req;
>> + u64 gpaddr;
>> +
>> + hint_req = kmalloc(sizeof(struct virtio_balloon_hint_req), GFP_KERNEL);
>> + while (virtqueue_get_buf(vq, &unused))
>> + ;
>> +
>> + gpaddr = virt_to_phys(hinting_req);
>> + hint_req->phys_addr = cpu_to_virtio64(vb->vdev, gpaddr);
>> + hint_req->count = cpu_to_virtio32(vb->vdev, entries);
>> + sg_init_one(&sg, hint_req, sizeof(struct virtio_balloon_hint_req));
>> + err = virtqueue_add_outbuf(vq, &sg, 1, hint_req, GFP_KERNEL);
>> + if (!err)
>> + virtqueue_kick(vb->hinting_vq);
>> + else
>> + kfree(hint_req);
>> + return err;
>> +}
>> +
>> +static void hinting_ack(struct virtqueue *vq)
>> +{
>> + int len = sizeof(struct virtio_balloon_hint_req);
>> + struct virtio_balloon_hint_req *hint_req = virtqueue_get_buf(vq, &len);
>> + void *v_addr = phys_to_virt(hint_req->phys_addr);
>> +
>> + release_buddy_pages(v_addr, hint_req->count);
>> + kfree(hint_req);
>> +}
>> +
> You use release_buddy_pages here, but never exported it in the call
> down below. Since this can be built as a module and I believe the page
> hinting can be built either into the kernel or as a seperate module
> shouldn't you be exporting it?
Thanks for pointing this out.
>
>> +static void enable_hinting(struct virtio_balloon *vb)
>> +{
>> + request_hypercall = (void *)&virtballoon_page_hinting;
>> + balloon_ptr = vb;
>> +}
>> +
>> +static void disable_hinting(void)
>> +{
>> + balloon_ptr = NULL;
>> +}
>> +#endif
>> +
>> static u32 page_to_balloon_pfn(struct page *page)
>> {
>> unsigned long pfn = page_to_pfn(page);
>> @@ -481,6 +533,7 @@ static int init_vqs(struct virtio_balloon *vb)
>> names[VIRTIO_BALLOON_VQ_DEFLATE] = "deflate";
>> names[VIRTIO_BALLOON_VQ_STATS] = NULL;
>> names[VIRTIO_BALLOON_VQ_FREE_PAGE] = NULL;
>> + names[VIRTIO_BALLOON_VQ_HINTING] = NULL;
>>
>> if (virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_STATS_VQ)) {
>> names[VIRTIO_BALLOON_VQ_STATS] = "stats";
>> @@ -492,11 +545,18 @@ static int init_vqs(struct virtio_balloon *vb)
>> callbacks[VIRTIO_BALLOON_VQ_FREE_PAGE] = NULL;
>> }
>>
>> + if (virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_HINTING)) {
>> + names[VIRTIO_BALLOON_VQ_HINTING] = "hinting_vq";
>> + callbacks[VIRTIO_BALLOON_VQ_HINTING] = hinting_ack;
>> + }
>> err = vb->vdev->config->find_vqs(vb->vdev, VIRTIO_BALLOON_VQ_MAX,
>> vqs, callbacks, names, NULL, NULL);
>> if (err)
>> return err;
>>
>> + if (virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_HINTING))
>> + vb->hinting_vq = vqs[VIRTIO_BALLOON_VQ_HINTING];
>> +
>> vb->inflate_vq = vqs[VIRTIO_BALLOON_VQ_INFLATE];
>> vb->deflate_vq = vqs[VIRTIO_BALLOON_VQ_DEFLATE];
>> if (virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_STATS_VQ)) {
>> @@ -908,6 +968,11 @@ static int virtballoon_probe(struct virtio_device *vdev)
>> if (err)
>> goto out_del_balloon_wq;
>> }
>> +
>> +#ifdef CONFIG_KVM_FREE_PAGE_HINTING
>> + if (virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_HINTING))
>> + enable_hinting(vb);
>> +#endif
>> virtio_device_ready(vdev);
>>
>> if (towards_target(vb))
>> @@ -950,6 +1015,10 @@ static void virtballoon_remove(struct virtio_device *vdev)
>> cancel_work_sync(&vb->update_balloon_size_work);
>> cancel_work_sync(&vb->update_balloon_stats_work);
>>
>> +#ifdef CONFIG_KVM_FREE_PAGE_HINTING
>> + if (virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_HINTING))
>> + disable_hinting();
>> +#endif
>> if (virtio_has_feature(vdev, VIRTIO_BALLOON_F_FREE_PAGE_HINT)) {
>> cancel_work_sync(&vb->report_free_page_work);
>> destroy_workqueue(vb->balloon_wq);
>> @@ -1009,6 +1078,7 @@ static unsigned int features[] = {
>> VIRTIO_BALLOON_F_MUST_TELL_HOST,
>> VIRTIO_BALLOON_F_STATS_VQ,
>> VIRTIO_BALLOON_F_DEFLATE_ON_OOM,
>> + VIRTIO_BALLOON_F_HINTING,
>> VIRTIO_BALLOON_F_FREE_PAGE_HINT,
>> VIRTIO_BALLOON_F_PAGE_POISON,
>> };
>> diff --git a/include/linux/page_hinting.h b/include/linux/page_hinting.h
>> index d554a2581826..a32af8851081 100644
>> --- a/include/linux/page_hinting.h
>> +++ b/include/linux/page_hinting.h
>> @@ -11,6 +11,8 @@
>> #define HINTING_THRESHOLD 128
>> #define FREE_PAGE_HINTING_MIN_ORDER (MAX_ORDER - 1)
>>
>> +extern void *balloon_ptr;
>> +
>> void guest_free_page_enqueue(struct page *page, int order);
>> void guest_free_page_try_hinting(void);
>> extern int __isolate_free_page(struct page *page, unsigned int order);
>> @@ -18,3 +20,5 @@ extern void __free_one_page(struct page *page, unsigned long pfn,
>> struct zone *zone, unsigned int order,
>> int migratetype);
>> void release_buddy_pages(void *obj_to_free, int entries);
>> +extern int (*request_hypercall)(void *balloon_ptr,
>> + void *hinting_req, int entries);
>> diff --git a/include/uapi/linux/virtio_balloon.h b/include/uapi/linux/virtio_balloon.h
>> index a1966cd7b677..a7e909d77447 100644
>> --- a/include/uapi/linux/virtio_balloon.h
>> +++ b/include/uapi/linux/virtio_balloon.h
>> @@ -29,6 +29,7 @@
>> #include <linux/virtio_types.h>
>> #include <linux/virtio_ids.h>
>> #include <linux/virtio_config.h>
>> +#include <linux/page_hinting.h>
>>
>> /* The feature bitmap for virtio balloon */
>> #define VIRTIO_BALLOON_F_MUST_TELL_HOST 0 /* Tell before reclaiming pages */
> So I am pretty sure that this isn't valid. You have a file in
> include/uapi/linux referencing one in include/linux. As such when the
> userspace headers are built off of this they cannot access the kernel
> include file.
>
>> @@ -36,6 +37,7 @@
>> #define VIRTIO_BALLOON_F_DEFLATE_ON_OOM 2 /* Deflate balloon on OOM */
>> #define VIRTIO_BALLOON_F_FREE_PAGE_HINT 3 /* VQ to report free pages */
>> #define VIRTIO_BALLOON_F_PAGE_POISON 4 /* Guest is using page poisoning */
>> +#define VIRTIO_BALLOON_F_HINTING 5 /* Page hinting virtqueue */
>>
>> /* Size of a PFN in the balloon interface. */
>> #define VIRTIO_BALLOON_PFN_SHIFT 12
>> @@ -108,4 +110,10 @@ struct virtio_balloon_stat {
>> __virtio64 val;
>> } __attribute__((packed));
>>
>> +#ifdef CONFIG_KVM_FREE_PAGE_HINTING
>> +struct virtio_balloon_hint_req {
>> + __virtio64 phys_addr;
>> + __virtio64 count;
>> +};
>> +#endif
>> #endif /* _LINUX_VIRTIO_BALLOON_H */
>> diff --git a/virt/kvm/page_hinting.c b/virt/kvm/page_hinting.c
>> index 9885b372b5a9..eb0c0ddfe990 100644
>> --- a/virt/kvm/page_hinting.c
>> +++ b/virt/kvm/page_hinting.c
>> @@ -31,11 +31,16 @@ struct guest_isolated_pages {
>> unsigned int order;
>> };
>>
>> -void release_buddy_pages(void *obj_to_free, int entries)
>> +int (*request_hypercall)(void *balloon_ptr, void *hinting_req, int entries);
>> +EXPORT_SYMBOL(request_hypercall);
>> +void *balloon_ptr;
>> +EXPORT_SYMBOL(balloon_ptr);
>> +
> Why are you using a standard EXPORT_SYMBOL here instead of
> EXPORT_SYMBOL_GPL? It seems like these are core functions that can
> impact the memory allocator. It might make more sense to use
> EXPORT_SYMBOL_GPL.
>
>> +void release_buddy_pages(void *hinting_req, int entries)
>> {
>> int i = 0;
>> int mt = 0;
>> - struct guest_isolated_pages *isolated_pages_obj = obj_to_free;
>> + struct guest_isolated_pages *isolated_pages_obj = hinting_req;
>>
>> while (i < entries) {
>> struct page *page = pfn_to_page(isolated_pages_obj[i].pfn);
> See my comment above, I am pretty sure you need to be exporting this.
> I had to change this in order to be able to build.
Thanks, I will take note and correct it in the next version.
--
Regards
Nitesh
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2019-03-07 13:23 UTC|newest]
Thread overview: 77+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-06 15:50 [RFC][Patch v9 0/6] KVM: Guest Free Page Hinting Nitesh Narayan Lal
2019-03-06 15:50 ` [RFC][Patch v9 1/6] KVM: Guest free page hinting support Nitesh Narayan Lal
2019-03-06 23:43 ` Alexander Duyck
2019-03-07 19:32 ` Nitesh Narayan Lal
2019-03-06 15:50 ` [RFC][Patch v9 2/6] KVM: Enables the kernel to isolate guest free pages Nitesh Narayan Lal
2019-03-07 18:30 ` Alexander Duyck
2019-03-07 19:23 ` Nitesh Narayan Lal
2019-03-07 19:30 ` David Hildenbrand
2019-03-07 21:32 ` Alexander Duyck
2019-03-07 21:40 ` David Hildenbrand
2019-03-07 22:35 ` Alexander Duyck
2019-03-08 2:28 ` Michael S. Tsirkin
2019-03-08 2:32 ` Michael S. Tsirkin
2019-03-08 18:06 ` Alexander Duyck
2019-03-08 18:59 ` Michael S. Tsirkin
2019-03-08 19:10 ` Nitesh Narayan Lal
2019-03-08 19:25 ` Alexander Duyck
2019-03-08 19:38 ` Nitesh Narayan Lal
2019-03-08 21:39 ` Alexander Duyck
2019-03-12 19:46 ` Nitesh Narayan Lal
2019-03-12 21:13 ` Alexander Duyck
2019-03-12 21:53 ` David Hildenbrand
2019-03-12 22:56 ` Alexander Duyck
2019-03-13 11:54 ` Nitesh Narayan Lal
2019-03-13 12:17 ` David Hildenbrand
2019-03-13 13:08 ` Nitesh Narayan Lal
2019-03-13 16:37 ` Alexander Duyck
2019-03-13 16:39 ` David Hildenbrand
2019-03-13 22:54 ` Alexander Duyck
2019-03-13 23:18 ` David Hildenbrand
2019-03-06 15:50 ` [RFC][Patch v9 3/6] KVM: Enables the kernel to report isolated pages Nitesh Narayan Lal
2019-03-06 21:30 ` Alexander Duyck
2019-03-07 13:23 ` Nitesh Narayan Lal [this message]
2019-03-06 15:50 ` [RFC][Patch v9 4/6] KVM: Reporting page poisoning value to the host Nitesh Narayan Lal
2019-03-06 15:50 ` [RFC][Patch v9 5/6] KVM: Enabling guest free page hinting via static key Nitesh Narayan Lal
2019-03-06 15:50 ` [RFC][Patch v9 6/6] KVM: Adding tracepoints for guest free page hinting Nitesh Narayan Lal
2019-03-06 15:52 ` [RFC][QEMU Patch] KVM: Enable QEMU to free the pages hinted by the guest Nitesh Narayan Lal
[not found] ` <20190306110501-mutt-send-email-mst@kernel.org>
2019-03-06 18:07 ` [RFC][Patch v9 0/6] KVM: Guest Free Page Hinting Nitesh Narayan Lal
[not found] ` <20190306130955-mutt-send-email-mst@kernel.org>
2019-03-06 18:30 ` Nitesh Narayan Lal
2019-03-06 18:38 ` Michael S. Tsirkin
2019-03-06 18:40 ` Nitesh Narayan Lal
2019-03-06 18:43 ` Alexander Duyck
2019-03-06 18:43 ` Michael S. Tsirkin
2019-03-06 18:59 ` David Hildenbrand
2019-03-06 19:08 ` Alexander Duyck
2019-03-06 19:18 ` David Hildenbrand
2019-03-06 19:24 ` Alexander Duyck
2019-03-06 20:31 ` Nitesh Narayan Lal
2019-03-06 20:32 ` Michael S. Tsirkin
2019-03-06 21:40 ` David Hildenbrand
2019-03-06 22:18 ` Michael S. Tsirkin
2019-03-06 23:12 ` Alexander Duyck
2019-03-14 16:42 ` Nitesh Narayan Lal
2019-03-14 16:58 ` Alexander Duyck
2019-03-18 15:57 ` Nitesh Narayan Lal
2019-03-19 13:33 ` David Hildenbrand
2019-03-19 16:04 ` Nitesh Narayan Lal
[not found] ` <CAKgT0UcBDKr0ACHQWUCvmm8atxM6wSu7aCRFJkFvfjT_W_femQ@mail.gmail.com>
2019-03-19 17:59 ` Nitesh Narayan Lal
2019-03-20 13:18 ` Nitesh Narayan Lal
2019-03-25 14:27 ` Nitesh Narayan Lal
2019-03-25 15:37 ` Michael S. Tsirkin
2019-03-25 15:42 ` Nitesh Narayan Lal
[not found] ` <CAKgT0Ud35pmmfAabYJijWo8qpucUWS8-OzBW=gsotfxZFuS9PQ@mail.gmail.com>
2019-03-06 19:07 ` Nitesh Narayan Lal
2019-03-06 22:05 ` Alexander Duyck
2019-03-07 13:09 ` Nitesh Narayan Lal
2019-03-07 18:45 ` Alexander Duyck
2019-03-07 18:53 ` Michael S. Tsirkin
2019-03-07 19:27 ` David Hildenbrand
2019-03-08 2:24 ` Michael S. Tsirkin
2019-03-08 11:53 ` David Hildenbrand
2019-03-07 21:14 ` Alexander Duyck
2019-03-07 21:28 ` David Hildenbrand
2019-03-07 22:19 ` Alexander Duyck
2019-03-07 19:45 ` Nitesh Narayan Lal
2019-03-07 19:49 ` David Hildenbrand
2019-03-07 18:46 ` Michael S. Tsirkin
2019-03-12 19:58 ` David Hildenbrand
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=7e1d0731-46e8-443e-7c37-62999fcb5642@redhat.com \
--to=nitesh@redhat.com \
--cc=aarcange@redhat.com \
--cc=alexander.duyck@gmail.com \
--cc=david@redhat.com \
--cc=dhildenb@redhat.com \
--cc=dodgen@google.com \
--cc=konrad.wilk@oracle.com \
--cc=kvm@vger.kernel.org \
--cc=lcapitulino@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mst@redhat.com \
--cc=pagupta@redhat.com \
--cc=pbonzini@redhat.com \
--cc=riel@surriel.com \
--cc=wei.w.wang@intel.com \
--cc=yang.zhang.wz@gmail.com \
/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