Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp2951667ybh; Mon, 5 Aug 2019 09:28:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqzLaxHqSkpMTsTy2FcYo671LdbJiu5ccXRURGkB5Vpz8oWnFwj2bpTTNfjyt/iWSnNI3/5v X-Received: by 2002:a17:90a:9a83:: with SMTP id e3mr18574350pjp.105.1565022489841; Mon, 05 Aug 2019 09:28:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565022489; cv=none; d=google.com; s=arc-20160816; b=kgApGdXC+xOvLr67BD/qE5WF7KKP7O3NOYNs1PclacDCT7RUqIK2sfkyyw9dLc0GXr jlmXmCZ3zK4YBh73HvbP1BTxlxuwRJn7olBZLV39W8dcAEoZzx/4mZh02Y1AgVnlrV+0 8jpn3P+u5xpR7a8dR59wRa39vqzVnB/mASynjK18CDKyaT6iKKSH1jnGzxWaDNhcEdN9 xb3t5xBtOwmoOnqol9TzU1qKtrmLH0n1Bp4v5WFpy5PjOZuMQwqW3PdXNLVHd9ShoKPE zjt7sV11Gi+qEg00XhpHLERHzj6XzgTr50IBEMF6YzL05iovEdU59+HFrqtdM41OW8X5 Qx4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id; bh=GLF3xAIayfgXT+v4rLYxKNTX/C/b+0YPxmm68b2cQBA=; b=HXa+hYMisTtCL01i5XUhN0Gy2s2iwJHAsF7k2CDPsDBYHHopgx3D0fJ/TNhYdxbxu7 Iz7ifaqSu5N/rn6pzcyndqLCWsUdKTkRiz/fmrmd7jO/nFZa9oUxPXAV3s57MKlC/YXY ansA7TC03E9hd4KM8gWYSi1qUlUO1pAbR9AC3zK2I6lzwcPoYXf/0K7wIi+GCQ3d1UJU vIeTDvOWHO7Dhg0ql4rvezmyo/DfwsutTgaeHxQ0QX974oPZO5LHz5XmU6rRCPqWtGyb /2765cSDB1NMqcookziHaHiVi4RG7qfKHnjtqJl/zNB6xwHNa2e01l0G1noZz1nqi5cP +vrA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a2si12913499pjs.16.2019.08.05.09.27.53; Mon, 05 Aug 2019 09:28:09 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729198AbfHEQ1S (ORCPT + 99 others); Mon, 5 Aug 2019 12:27:18 -0400 Received: from mga17.intel.com ([192.55.52.151]:35190 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726620AbfHEQ1R (ORCPT ); Mon, 5 Aug 2019 12:27:17 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Aug 2019 09:27:17 -0700 X-IronPort-AV: E=Sophos;i="5.64,350,1559545200"; d="scan'208";a="185363930" Received: from ahduyck-desk1.jf.intel.com ([10.7.198.76]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Aug 2019 09:27:17 -0700 Message-ID: Subject: Re: [PATCH v3 6/6] virtio-balloon: Add support for providing unused page reports to host From: Alexander Duyck To: Nitesh Narayan Lal , Alexander Duyck , kvm@vger.kernel.org, david@redhat.com, mst@redhat.com, dave.hansen@intel.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, akpm@linux-foundation.org Cc: yang.zhang.wz@gmail.com, pagupta@redhat.com, riel@surriel.com, konrad.wilk@oracle.com, willy@infradead.org, lcapitulino@redhat.com, wei.w.wang@intel.com, aarcange@redhat.com, pbonzini@redhat.com, dan.j.williams@intel.com Date: Mon, 05 Aug 2019 09:27:16 -0700 In-Reply-To: <1cff09a4-d302-639c-ab08-9d82e5fc1383@redhat.com> References: <20190801222158.22190.96964.stgit@localhost.localdomain> <20190801223829.22190.36831.stgit@localhost.localdomain> <1cff09a4-d302-639c-ab08-9d82e5fc1383@redhat.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.30.5 (3.30.5-1.fc29) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 2019-08-05 at 12:00 -0400, Nitesh Narayan Lal wrote: > On 8/1/19 6:38 PM, Alexander Duyck wrote: > > From: Alexander Duyck > > > > Add support for the page reporting feature provided by virtio-balloon. > > Reporting differs from the regular balloon functionality in that is is > > much less durable than a standard memory balloon. Instead of creating a > > list of pages that cannot be accessed the pages are only inaccessible > > while they are being indicated to the virtio interface. Once the > > interface has acknowledged them they are placed back into their respective > > free lists and are once again accessible by the guest system. > > > > Signed-off-by: Alexander Duyck > > --- > > drivers/virtio/Kconfig | 1 + > > drivers/virtio/virtio_balloon.c | 56 +++++++++++++++++++++++++++++++++++ > > include/uapi/linux/virtio_balloon.h | 1 + > > 3 files changed, 58 insertions(+) > > > > diff --git a/drivers/virtio/Kconfig b/drivers/virtio/Kconfig > > index 078615cf2afc..4b2dd8259ff5 100644 > > --- a/drivers/virtio/Kconfig > > +++ b/drivers/virtio/Kconfig > > @@ -58,6 +58,7 @@ config VIRTIO_BALLOON > > tristate "Virtio balloon driver" > > depends on VIRTIO > > select MEMORY_BALLOON > > + select PAGE_REPORTING > > ---help--- > > This driver supports increasing and decreasing the amount > > of memory within a KVM guest. > > diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c > > index 2c19457ab573..971fe924e34f 100644 > > --- a/drivers/virtio/virtio_balloon.c > > +++ b/drivers/virtio/virtio_balloon.c > > @@ -19,6 +19,7 @@ > > #include > > #include > > #include > > +#include > > > > /* > > * Balloon device works in 4K page units. So each page is pointed to by > > @@ -37,6 +38,9 @@ > > #define VIRTIO_BALLOON_FREE_PAGE_SIZE \ > > (1 << (VIRTIO_BALLOON_FREE_PAGE_ORDER + PAGE_SHIFT)) > > > > +/* limit on the number of pages that can be on the reporting vq */ > > +#define VIRTIO_BALLOON_VRING_HINTS_MAX 16 > > + > > #ifdef CONFIG_BALLOON_COMPACTION > > static struct vfsmount *balloon_mnt; > > #endif > > @@ -46,6 +50,7 @@ enum virtio_balloon_vq { > > VIRTIO_BALLOON_VQ_DEFLATE, > > VIRTIO_BALLOON_VQ_STATS, > > VIRTIO_BALLOON_VQ_FREE_PAGE, > > + VIRTIO_BALLOON_VQ_REPORTING, > > VIRTIO_BALLOON_VQ_MAX > > }; > > > > @@ -113,6 +118,10 @@ struct virtio_balloon { > > > > /* To register a shrinker to shrink memory upon memory pressure */ > > struct shrinker shrinker; > > + > > + /* Unused page reporting device */ > > + struct virtqueue *reporting_vq; > > + struct page_reporting_dev_info ph_dev_info; > > }; > > > > static struct virtio_device_id id_table[] = { > > @@ -152,6 +161,23 @@ static void tell_host(struct virtio_balloon *vb, struct virtqueue *vq) > > > > } > > > > +void virtballoon_unused_page_report(struct page_reporting_dev_info *ph_dev_info, > > + unsigned int nents) > > +{ > > + struct virtio_balloon *vb = > > + container_of(ph_dev_info, struct virtio_balloon, ph_dev_info); > > + struct virtqueue *vq = vb->reporting_vq; > > + unsigned int unused; > > + > > + /* We should always be able to add these buffers to an empty queue. */ > > + virtqueue_add_inbuf(vq, ph_dev_info->sg, nents, vb, > > + GFP_NOWAIT | __GFP_NOWARN); > > I think you should handle allocation failure here. It is a possibility, isn't? > Maybe return an error or even disable page hinting/reporting? > I don't think it is an issue I have to worry about. Specifically I am limiting the size of the scatterlist based on the size of the vq. As such I will never exceed the size and should be able to use it to store the scatterlist directly.