From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 05464C282CE for ; Tue, 4 Jun 2019 11:32:12 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 83CDC24BDC for ; Tue, 4 Jun 2019 11:32:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 83CDC24BDC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id E71B56B0008; Tue, 4 Jun 2019 07:32:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E223A6B026B; Tue, 4 Jun 2019 07:32:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CC2746B026C; Tue, 4 Jun 2019 07:32:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from mail-oi1-f200.google.com (mail-oi1-f200.google.com [209.85.167.200]) by kanga.kvack.org (Postfix) with ESMTP id 908D66B0008 for ; Tue, 4 Jun 2019 07:32:10 -0400 (EDT) Received: by mail-oi1-f200.google.com with SMTP id t198so3139433oih.20 for ; Tue, 04 Jun 2019 04:32:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:subject:to:cc :references:from:openpgp:autocrypt:organization:message-id:date :user-agent:mime-version:in-reply-to; bh=89nyAs1osOnuiitnydoH40PYd9QXxNcum2Oy+IP+CJY=; b=YIw22HLVKQO9B6jQqF3z1QUk48x8bIToOsYFlfolbzFQTsDkzOlwnytswwnEtK80ZR OgBoLGmYiKrgQHR6I3wrLUQ1SbKBex76JpxNgpCrMN1e9aT8pK8I+CVq4YOQDNBBOPqX E6Sa7LZzndSdr8FUsPGPRmXursirCdz9UHj0tlsIGTf97/i4JUJL6IPDs+i3AvSam/OY OUrZfYl/7rVooU8yDBrqvT+CVLje31atA7ZfrSAC/EB0iushM8dRScxxKf+/9ZT6Iz/X nHwCmkRje/jZnE9psPIorcZZQXGaZeTULlkd4Wuep9Bzel03m17891DsgjD9riLyXUiR 9WcQ== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of nitesh@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=nitesh@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: APjAAAX3kbup6GgHidJybeMWCYDWgAVPKqnYKyZxSBpa3rlUaXjySVEe oERoAhsgox67pAitN5meDTEk2RrpfXQIpUfe50Fd1ztbO4HZREYjcxH6WO0Mj4D7pRvIejD3jtM sf+0OVUhalaiqJMHJ/NOLxweb29jdiqZbfhUiF1QPg0GSXwEX8QSMWFMhj8z5dNiWMA== X-Received: by 2002:aca:fc8d:: with SMTP id a135mr2116196oii.145.1559647930230; Tue, 04 Jun 2019 04:32:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqzehdpR0OmxLcaQ1SN1b6k0JbpmyexNhHEDtYeYc1EZnHh+kQg/8WEOCz0eSoAsPZ/Jtlqi X-Received: by 2002:aca:fc8d:: with SMTP id a135mr2116110oii.145.1559647928500; Tue, 04 Jun 2019 04:32:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559647928; cv=none; d=google.com; s=arc-20160816; b=xAMEw/SrxLi78n62UnSE/wA4skKYRrhKZsJKggfExiUXcIEUAwKD4KosBh6k818sBw crr0lTI+Nv1Ud5WhNrfUAM8wrUTx5Ztote662nrz5dOa0l47+vK8ioKShZAbnG6n8cbY QkrE2CFdW1MC81p4BGhuBi/abGHxJHHb9/vatZtQ3SGc5xo8tSug+QMyDrQtAp3pIK8e 5bEQFpRbw8WE+SEKsMmtUKcUha98VjNcySDGhuxs+gR0R6umGtZTX8SAKZNo/mwB/5Zt dI4yZgHi0e9blHNIK1izK84wqngV8gfE6FQaQQwrgAeagRaVWYEJY/Eetag3uTL+B1Kb mkjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:mime-version:user-agent:date:message-id:organization :autocrypt:openpgp:from:references:cc:to:subject; bh=89nyAs1osOnuiitnydoH40PYd9QXxNcum2Oy+IP+CJY=; b=ONPG4iLA/u2qXcJXPyCmN288/Y3hntaLF4y0EUbksYcx4cbfvtGG/EOITZJzc8mdkL 2dal1f+Ntxz65VjaBDR/hCgi3Sc7GPWYOL8xySWTcWAls120L5BfV2egZCGCuuWap+73 lFlaqpiOTo2KZan3+1GT91NoXlgebGubBQUjcXAZyk+yzQn6JnCL6nATOao/B8PzkdnQ MyHVQTjx1WBcGqSkV6GtMG1KWOPTuwvGnz3r9N9tHl0p8WmtfzldGiyKLizr0keec+vz E+WaCzNAWdzQP+R0C/EjSisY2Q/iG/yEtOp69HVmOJszqm8qr0CCzY9FSjV3kpmVAv1f 2V/g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of nitesh@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=nitesh@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id 1si3397441otr.299.2019.06.04.04.32.08 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Jun 2019 04:32:08 -0700 (PDT) Received-SPF: pass (google.com: domain of nitesh@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of nitesh@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=nitesh@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0D28A3107B35; Tue, 4 Jun 2019 11:31:47 +0000 (UTC) Received: from [10.40.205.182] (unknown [10.40.205.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 819FB5B683; Tue, 4 Jun 2019 11:31:28 +0000 (UTC) Subject: Re: [RFC][Patch v10 2/2] virtio-balloon: page_hinting: reporting to the host To: Alexander Duyck Cc: kvm list , LKML , linux-mm , Paolo Bonzini , lcapitulino@redhat.com, pagupta@redhat.com, wei.w.wang@intel.com, Yang Zhang , Rik van Riel , David Hildenbrand , "Michael S. Tsirkin" , dodgen@google.com, Konrad Rzeszutek Wilk , dhildenb@redhat.com, Andrea Arcangeli References: <20190603170306.49099-1-nitesh@redhat.com> <20190603170306.49099-3-nitesh@redhat.com> From: Nitesh Narayan Lal Openpgp: preference=signencrypt Autocrypt: addr=nitesh@redhat.com; prefer-encrypt=mutual; keydata= mQINBFl4pQoBEADT/nXR2JOfsCjDgYmE2qonSGjkM1g8S6p9UWD+bf7YEAYYYzZsLtbilFTe z4nL4AV6VJmC7dBIlTi3Mj2eymD/2dkKP6UXlliWkq67feVg1KG+4UIp89lFW7v5Y8Muw3Fm uQbFvxyhN8n3tmhRe+ScWsndSBDxYOZgkbCSIfNPdZrHcnOLfA7xMJZeRCjqUpwhIjxQdFA7 n0s0KZ2cHIsemtBM8b2WXSQG9CjqAJHVkDhrBWKThDR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TPKwpulMSUaJE8ZH9n8A/+sdC3CAD4QafVBcCcbFe1jifHmQRdDrvHV9Es14QVAOTZhnJ vweENyHEIxkpLsyUUDuVypIo6y/Cws+EBCWt27BJi9GH/EOTB0wb+2ghCs/i3h8a+bi+bS7L FCCm/AxIqxRurh2UySn0P/2+2eZvneJ1/uTgfxnjeSlwQJ1BWzMAdAHQO1/lnbyZgEZEtUZJ x9d9ASekTtJjBMKJXAw7GbB2dAA/QmbA+Q+Xuamzm/1imigz6L6sOt2n/X/SSc33w8RJUyor SvAIoG/zU2Y76pKTgbpQqMDmkmNYFMLcAukpvC4ki3Sf086TdMgkjqtnpTkEElMSFJC8npXv 3QnGGOIfFug/qs8z03DLPBz9VYS26jiiN7QIJVpeeEdN/LKnaz5LO+h5kNAyj44qdF2T2AiF HxnZnxO5JNP5uISQH3FjxxGxJkdJ8jKzZV7aT37sC+Rp0o3KNc+GXTR+GSVq87Xfuhx0LRST NK9ZhT0+qkiN7npFLtNtbzwqaqceq3XhafmCiw8xrtzCnlB/C4SiBr/93Ip4kihXJ0EuHSLn VujM7c/b4pps Organization: Red Hat Inc, Message-ID: <22265a8a-98bf-26b9-87b8-c3fde0884240@redhat.com> Date: Tue, 4 Jun 2019 07:31:22 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="niRRzAuGhcqDPj9hnL5YvC8u2zDOPQ0E3" X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Tue, 04 Jun 2019 11:32:02 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --niRRzAuGhcqDPj9hnL5YvC8u2zDOPQ0E3 Content-Type: multipart/mixed; boundary="WlwgUakvqZiOH4w8bPdhVBo09cA0GQVco"; protected-headers="v1" From: Nitesh Narayan Lal To: Alexander Duyck Cc: kvm list , LKML , linux-mm , Paolo Bonzini , lcapitulino@redhat.com, pagupta@redhat.com, wei.w.wang@intel.com, Yang Zhang , Rik van Riel , David Hildenbrand , "Michael S. Tsirkin" , dodgen@google.com, Konrad Rzeszutek Wilk , dhildenb@redhat.com, Andrea Arcangeli Message-ID: <22265a8a-98bf-26b9-87b8-c3fde0884240@redhat.com> Subject: Re: [RFC][Patch v10 2/2] virtio-balloon: page_hinting: reporting to the host References: <20190603170306.49099-1-nitesh@redhat.com> <20190603170306.49099-3-nitesh@redhat.com> In-Reply-To: --WlwgUakvqZiOH4w8bPdhVBo09cA0GQVco Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Content-Language: en-US On 6/3/19 6:38 PM, Alexander Duyck wrote: > On Mon, Jun 3, 2019 at 10:04 AM Nitesh Narayan Lal = wrote: >> Enables the kernel to negotiate VIRTIO_BALLOON_F_HINTING feature with = the >> host. If it is available and page_hinting_flag is set to true, page_hi= nting >> is enabled and its callbacks are configured along with the max_pages c= ount >> which indicates the maximum number of pages that can be isolated and h= inted >> at a time. Currently, only free pages of order >=3D (MAX_ORDER - 2) ar= e >> reported. To prevent any false OOM max_pages count is set to 16. >> >> By default page_hinting feature is enabled and gets loaded as soon >> as the virtio-balloon driver is loaded. However, it could be disabled >> by writing the page_hinting_flag which is a virtio-balloon parameter. >> >> Signed-off-by: Nitesh Narayan Lal >> --- >> drivers/virtio/virtio_balloon.c | 112 +++++++++++++++++++++++++++= - >> include/uapi/linux/virtio_balloon.h | 14 ++++ >> 2 files changed, 125 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_b= alloon.c >> index f19061b585a4..40f09ea31643 100644 >> --- a/drivers/virtio/virtio_balloon.c >> +++ b/drivers/virtio/virtio_balloon.c >> @@ -31,6 +31,7 @@ >> #include >> #include >> #include >> +#include >> >> /* >> * Balloon device works in 4K page units. So each page is pointed to= by >> @@ -48,6 +49,7 @@ >> /* The size of a free page block in bytes */ >> #define VIRTIO_BALLOON_FREE_PAGE_SIZE \ >> (1 << (VIRTIO_BALLOON_FREE_PAGE_ORDER + PAGE_SHIFT)) >> +#define VIRTIO_BALLOON_PAGE_HINTING_MAX_PAGES 16 >> >> #ifdef CONFIG_BALLOON_COMPACTION >> static struct vfsmount *balloon_mnt; >> @@ -58,6 +60,7 @@ enum virtio_balloon_vq { >> VIRTIO_BALLOON_VQ_DEFLATE, >> VIRTIO_BALLOON_VQ_STATS, >> VIRTIO_BALLOON_VQ_FREE_PAGE, >> + VIRTIO_BALLOON_VQ_HINTING, >> VIRTIO_BALLOON_VQ_MAX >> }; >> >> @@ -67,7 +70,8 @@ enum virtio_balloon_config_read { >> >> struct virtio_balloon { >> struct virtio_device *vdev; >> - struct virtqueue *inflate_vq, *deflate_vq, *stats_vq, *free_pa= ge_vq; >> + struct virtqueue *inflate_vq, *deflate_vq, *stats_vq, *free_pa= ge_vq, >> + *hinting_vq; >> >> /* Balloon's own wq for cpu-intensive work items */ >> struct workqueue_struct *balloon_wq; >> @@ -125,6 +129,9 @@ struct virtio_balloon { >> >> /* To register a shrinker to shrink memory upon memory pressur= e */ >> struct shrinker shrinker; >> + >> + /* object pointing at the array of isolated pages ready for hi= nting */ >> + struct hinting_data *hinting_arr; > Just make this an array of size VIRTIO_BALLOON_PAGE_HINTING_MAX_PAGES. > It will save a bunch of complexity later. Make sense. >> }; >> >> static struct virtio_device_id id_table[] =3D { >> @@ -132,6 +139,85 @@ static struct virtio_device_id id_table[] =3D { >> { 0 }, >> }; >> >> +#ifdef CONFIG_PAGE_HINTING > Instead of having CONFIG_PAGE_HINTING enable this, maybe we should > have virtio-balloon enable CONFIG_PAGE_HINTING. > >> +struct virtio_balloon *hvb; >> +bool page_hinting_flag =3D true; >> +module_param(page_hinting_flag, bool, 0444); >> +MODULE_PARM_DESC(page_hinting_flag, "Enable page hinting"); >> + >> +static bool virtqueue_kick_sync(struct virtqueue *vq) >> +{ >> + u32 len; >> + >> + if (likely(virtqueue_kick(vq))) { >> + while (!virtqueue_get_buf(vq, &len) && >> + !virtqueue_is_broken(vq)) >> + cpu_relax(); >> + return true; > Is this a synchronous setup?=20 Yes. > It seems kind of wasteful to have a > thread busy waiting here like this. It might make more sense to just > make this work like the other balloon queues and have a wait event > with a wake up in the interrupt handler for the queue. I can do that. I may have to use a flag or something else to page_hinting.c as well to ensure that no other bitmap scanning is initiated until then. > >> + } >> + return false; >> +} >> + >> +static void page_hinting_report(int entries) >> +{ >> + struct scatterlist sg; >> + struct virtqueue *vq =3D hvb->hinting_vq; >> + int err =3D 0; >> + struct hinting_data *hint_req; >> + u64 gpaddr; >> + >> + hint_req =3D kmalloc(sizeof(*hint_req), GFP_KERNEL); >> + if (!hint_req) >> + return; > Why do we need another allocation here? Couldn't you just allocate > hint_req on the stack and then use that? I think we might be doing too > much here. All this really needs to look like is something along the > lines of tell_host() minus the wait_event. > >> + gpaddr =3D virt_to_phys(hvb->hinting_arr); >> + hint_req->phys_addr =3D cpu_to_virtio64(hvb->vdev, gpaddr); >> + hint_req->size =3D cpu_to_virtio32(hvb->vdev, entries); >> + sg_init_one(&sg, hint_req, sizeof(*hint_req)); >> + err =3D virtqueue_add_outbuf(vq, &sg, 1, hint_req, GFP_KERNEL)= ; >> + if (!err) >> + virtqueue_kick_sync(hvb->hinting_vq); >> + >> + kfree(hint_req); >> +} >> + >> +int page_hinting_prepare(void) >> +{ >> + hvb->hinting_arr =3D kmalloc_array(VIRTIO_BALLOON_PAGE_HINTING= _MAX_PAGES, >> + sizeof(*hvb->hinting_arr), GF= P_KERNEL); >> + if (!hvb->hinting_arr) >> + return -ENOMEM; >> + return 0; >> +} >> + > Why make the hinting_arr a dynamic allocation? You should probably > just make it a static array within the virtio_balloon structure. Then > you don't have the risk of an allocation failing and messing up the > hints. I agree. >> +void hint_pages(struct list_head *pages) >> +{ >> + struct page *page, *next; >> + unsigned long pfn; >> + int idx =3D 0, order; >> + >> + list_for_each_entry_safe(page, next, pages, lru) { >> + pfn =3D page_to_pfn(page); >> + order =3D page_private(page); >> + hvb->hinting_arr[idx].phys_addr =3D pfn << PAGE_SHIFT;= >> + hvb->hinting_arr[idx].size =3D (1 << order) * PAGE_SIZ= E; >> + idx++; >> + } >> + page_hinting_report(idx); >> +} >> + > Getting back to my suggestion from earlier today. It might make sense > to not bother with the PAGE_SHIFT or PAGE_SIZE multiplication if you > just record everything in VIRTIO_BALLOON_PAGES intead of using the > actual address and size. > >> +void page_hinting_cleanup(void) >> +{ >> + kfree(hvb->hinting_arr); >> +} >> + > Same comment here. Make this array a part of virtio_balloon and you > don't have to free it. +1 > >> +static const struct page_hinting_cb hcb =3D { >> + .prepare =3D page_hinting_prepare, >> + .hint_pages =3D hint_pages, >> + .cleanup =3D page_hinting_cleanup, >> + .max_pages =3D VIRTIO_BALLOON_PAGE_HINTING_MAX_PAGES, >> +}; > With the above changes prepare and cleanup can be dropped. > >> +#endif >> + >> static u32 page_to_balloon_pfn(struct page *page) >> { >> unsigned long pfn =3D page_to_pfn(page); >> @@ -488,6 +574,7 @@ static int init_vqs(struct virtio_balloon *vb) >> names[VIRTIO_BALLOON_VQ_DEFLATE] =3D "deflate"; >> names[VIRTIO_BALLOON_VQ_STATS] =3D NULL; >> names[VIRTIO_BALLOON_VQ_FREE_PAGE] =3D NULL; >> + names[VIRTIO_BALLOON_VQ_HINTING] =3D NULL; >> >> if (virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_STATS_VQ)) {= >> names[VIRTIO_BALLOON_VQ_STATS] =3D "stats"; >> @@ -499,11 +586,18 @@ static int init_vqs(struct virtio_balloon *vb) >> callbacks[VIRTIO_BALLOON_VQ_FREE_PAGE] =3D NULL; >> } >> >> + if (virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_HINTING)) { >> + names[VIRTIO_BALLOON_VQ_HINTING] =3D "hinting_vq"; >> + callbacks[VIRTIO_BALLOON_VQ_HINTING] =3D NULL; >> + } >> err =3D 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 =3D vqs[VIRTIO_BALLOON_VQ_HINTING]; >> + >> vb->inflate_vq =3D vqs[VIRTIO_BALLOON_VQ_INFLATE]; >> vb->deflate_vq =3D vqs[VIRTIO_BALLOON_VQ_DEFLATE]; >> if (virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_STATS_VQ)) {= >> @@ -942,6 +1036,14 @@ static int virtballoon_probe(struct virtio_devic= e *vdev) >> if (err) >> goto out_del_balloon_wq; >> } >> + >> +#ifdef CONFIG_PAGE_HINTING >> + if (virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_HINTING) && >> + page_hinting_flag) { >> + hvb =3D vb; >> + page_hinting_enable(&hcb); >> + } >> +#endif >> virtio_device_ready(vdev); >> >> if (towards_target(vb)) >> @@ -989,6 +1091,12 @@ static void virtballoon_remove(struct virtio_dev= ice *vdev) >> destroy_workqueue(vb->balloon_wq); >> } >> >> +#ifdef CONFIG_PAGE_HINTING >> + if (virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_HINTING)) { >> + hvb =3D NULL; >> + page_hinting_disable(); >> + } >> +#endif >> remove_common(vb); >> #ifdef CONFIG_BALLOON_COMPACTION >> if (vb->vb_dev_info.inode) >> @@ -1043,8 +1151,10 @@ static unsigned int features[] =3D { >> 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, >> + VIRTIO_BALLOON_F_HINTING, >> }; >> >> static struct virtio_driver virtio_balloon_driver =3D { >> diff --git a/include/uapi/linux/virtio_balloon.h b/include/uapi/linux/= virtio_balloon.h >> index a1966cd7b677..25e4f817c660 100644 >> --- a/include/uapi/linux/virtio_balloon.h >> +++ b/include/uapi/linux/virtio_balloon.h >> @@ -29,6 +29,7 @@ >> #include >> #include >> #include >> +#include >> >> /* The feature bitmap for virtio balloon */ >> #define VIRTIO_BALLOON_F_MUST_TELL_HOST 0 /* Tell before recla= iming pages */ >> @@ -36,6 +37,7 @@ >> #define VIRTIO_BALLOON_F_DEFLATE_ON_OOM 2 /* Deflate balloon o= n 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 poiso= ning */ >> +#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,16 @@ struct virtio_balloon_stat { >> __virtio64 val; >> } __attribute__((packed)); >> >> +#ifdef CONFIG_PAGE_HINTING >> +/* >> + * struct hinting_data- holds the information associated with hinting= =2E >> + * @phys_add: physical address associated with a page or the array h= olding >> + * the array of isolated pages. >> + * @size: total size associated with the phys_addr. >> + */ >> +struct hinting_data { >> + __virtio64 phys_addr; >> + __virtio32 size; >> +}; > So in order to avoid errors this should either have > "__attribute__((packed))" added or it should be changed to a pair of > u32 or u64 values so that it will always be the same size regardless > of what platform it is built on. I will take a look at this. Thanks. >> +#endif >> #endif /* _LINUX_VIRTIO_BALLOON_H */ >> -- >> 2.21.0 >> --=20 Regards Nitesh --WlwgUakvqZiOH4w8bPdhVBo09cA0GQVco-- --niRRzAuGhcqDPj9hnL5YvC8u2zDOPQ0E3 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEkXcoRVGaqvbHPuAGo4ZA3AYyozkFAlz2VosACgkQo4ZA3AYy ozm6mg/9EUX7lXpCTVLYRs29Wzyi+3IJbMJJ6awT1jtuZaZb/H4h0AL3MjZ+i17N wOdHkFKgoOJMZIMSebhDW2gi0sGerZq9BpJ3UETSJwDi8fTw9aEQskpBId/w2mUo brWnAgtQdcFaoRLn9RRcahScxOeOFC11I/YTi2f/NN5juZ/5C+l+aidzeMMZM80Q OHXjH03hKO8ZHiVgMhSEjHdpNLgjgiY7OF+bpfjAb7+lXY8MEuG+uJYY0mRL6Esc MxLFR91k3UaiSHwA8B20mkhypwNnV3w7P0l7GN1X8fv6a1EJKPZgzhfFZXhadRoA 49KigFb/H3t7iBQtBHMXeeT0Cb+ZCJ0+/xKTaRlgtkv4QErAhEbhxhM0/qb010pk jjdJcakk77lRvdGEu1uZAOgNK9OVDw89NT79DWBogx8zBTl4irtuS/CaKCsP2ynR eMaRPNm8Lf1vTFgIXKDg9gseiQC9zyGDEX4O2osB4w2v4XOhH4/HYhYZyoeCjdTi qDV648O3t0nWhuVIM+eXleqsPGZz5bM5/Nmi5vEnvBdc1O6y1caMS7q5zkhrBFau dEpkC/EJ3us8Kf616XIb/QL5DstYMfdV1ZeLnRGXKSV52kp0mdwZ/oDCeypWTv7h +bijwwoJa2HK+JTSm783nKfWw98jIcXZN2XvtQ1brL/ghadDj0M= =4lOZ -----END PGP SIGNATURE----- --niRRzAuGhcqDPj9hnL5YvC8u2zDOPQ0E3--