Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp4232664ybh; Tue, 6 Aug 2019 08:19:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqycbUTx/fKvsVabKmmQc97c6SE46/GIriqVfTGxm+zYTTCIPpm8jsIVtIHXOjPDQpExuylE X-Received: by 2002:a17:902:1004:: with SMTP id b4mr3760133pla.325.1565104781677; Tue, 06 Aug 2019 08:19:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565104781; cv=none; d=google.com; s=arc-20160816; b=BeYdJ/0o3fhze80hUT7/99e6EtgTWemCvtbDTgIfJ3yKO6JeEHKGUv13N+Ys3mEjUQ 42yDc8gau5mwzO7DS63/6ewOp+4kwaeb5vOqXWztr2rlwTlHUKxOupkpYK2gR0lpvFah y2AqXunN2NqwXj6huFeju+7qZBlQS6DztJXubCPoou+vZcPTAdUbMfWDE/zOjilP3Wg2 tXd/xzf+QC98ppdXl/XrfmGjKplCzdNPaFI0hosCYToi6so+0itRQClZyOFt0/f3Svur DZrYRpoCG/ljss+aL8Dc1pbqx7o5j/Av+87BAMKegXYyk4mBiAoVdjvhfrucydBR4uZT fGXA== 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=t5utYjK2IgovkZjkelguTsCtsgYZG52HIH6Pxqs1L48=; b=tI1Sh6RCTm9LlFHtoPDLJBWDLlcoFjpGNV+6sMVtwatA1PjA/tzwIi22SyoR8rXPnB RtC7VdL1AZBccf2NYkUvPeAkDjkdsduDvmnbPff7planPt2uXUmfBaXfHwgM/HIzPtNo Kkpf3l7ssqUVEZzInFWuDRnEaQM59WUx5ST5zeSslFvFTsMcI4CKBnNSlgDbIqbdcaf2 Scjn1OBGV61KJfZwxHW8Ba6IKUVv078lwieFYv3WlqmwDP9zvkI0wCqwr5iaFUgpBtHU qWP5NI7vERz9IFD4q+QzBTfwml2M5OPzc5139mjI/RATmFyuvSJgUvYPwOGJdxU47Cez wN4w== 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 c8si42063525pls.436.2019.08.06.08.19.25; Tue, 06 Aug 2019 08:19:41 -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 S1732913AbfHFPSK (ORCPT + 99 others); Tue, 6 Aug 2019 11:18:10 -0400 Received: from mga06.intel.com ([134.134.136.31]:22167 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726713AbfHFPSJ (ORCPT ); Tue, 6 Aug 2019 11:18:09 -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 orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Aug 2019 08:16:37 -0700 X-IronPort-AV: E=Sophos;i="5.64,353,1559545200"; d="scan'208";a="185676339" 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; 06 Aug 2019 08:16:36 -0700 Message-ID: Subject: Re: [PATCH v3 6/6] virtio-balloon: Add support for providing unused page reports to host From: Alexander Duyck To: "Michael S. Tsirkin" Cc: Nitesh Narayan Lal , Alexander Duyck , kvm@vger.kernel.org, david@redhat.com, dave.hansen@intel.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, akpm@linux-foundation.org, 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: Tue, 06 Aug 2019 08:16:36 -0700 In-Reply-To: <20190806073047-mutt-send-email-mst@kernel.org> References: <20190801222158.22190.96964.stgit@localhost.localdomain> <20190801223829.22190.36831.stgit@localhost.localdomain> <1cff09a4-d302-639c-ab08-9d82e5fc1383@redhat.com> <20190806073047-mutt-send-email-mst@kernel.org> 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 Tue, 2019-08-06 at 07:31 -0400, Michael S. Tsirkin wrote: > On Mon, Aug 05, 2019 at 09:27:16AM -0700, Alexander Duyck wrote: > > 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. > > I agree. But it can't hurt to BUG_ON for good measure. > I wouldn't use a BUG_ON as that seems overkill. No need to panic the kernel just because we couldn't report some idle pages. I can probably do something like: if (WARN_ON(err)) return; That way the unused page reporting can run to completion still and the fact that we aren't really hinting on the pages would effectively be no different then if we had a direct assigned device or shared memory in the hypervisor.