From nobody Sun May 19 01:26:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1586375407; cv=none; d=zohomail.com; s=zohoarc; b=Z0Eq/7GmuJaPJIw/LyxJR53mqR4NsOS5RHi4W6LTjeeR6xXgJ7/PYJGJNsg9VuXLVe4jc5G4M8C/V5Zdq+Yy8Wt5You6gaoxr2YxLKgI4MPXmapeYUGIzmM1FbpWWL5bMwfH8Rgv0W31hd/rKSY0Hgu2evNPSOjoLyvEBF9w44U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1586375407; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=V78oNbusAm5S3e7SX3vKPs7Z58CB44qhuhwypR7BDJE=; b=kkjnhnWg+MkHlu4TkI+4Gy9cDIpzkYbv751bjo1TMe5i/KnUJpsB1eaBxxnrLVFCkREEfIrsaaJuuClLocDb4YIInX3SXNmtI2BgUr+IjfBRqqWwAT3JhlPC/rIAki+p5MA8TNVg/reqFtbTqyJ1shSq6sUlL0EPB/enWY/7a5g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 158637540798040.485076417878076; Wed, 8 Apr 2020 12:50:07 -0700 (PDT) Received: from localhost ([::1]:40034 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jMGi6-0003F4-NO for importer@patchew.org; Wed, 08 Apr 2020 15:50:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37207) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jMGgt-0001pc-O4 for qemu-devel@nongnu.org; Wed, 08 Apr 2020 15:48:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jMGgs-0002ta-Ai for qemu-devel@nongnu.org; Wed, 08 Apr 2020 15:48:51 -0400 Received: from mail-qt1-x834.google.com ([2607:f8b0:4864:20::834]:38385) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jMGgs-0002tI-5K for qemu-devel@nongnu.org; Wed, 08 Apr 2020 15:48:50 -0400 Received: by mail-qt1-x834.google.com with SMTP id 13so915928qtt.5 for ; Wed, 08 Apr 2020 12:48:50 -0700 (PDT) Received: from localhost.localdomain ([2001:470:b:9c3:9e5c:8eff:fe4f:f2d0]) by smtp.gmail.com with ESMTPSA id g187sm19413251qkf.115.2020.04.08.12.48.48 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Apr 2020 12:48:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=V78oNbusAm5S3e7SX3vKPs7Z58CB44qhuhwypR7BDJE=; b=jcfhmoW9bkjhL7qdUeaFbBuwrAjEdNZwBij6kRQsZk447P9yvAqF+VPAxIQ9RTnv2f 2RGYzU7B8nOZtBW6/+OZbmBS+Pil6ytrNkvkCNzMBnjZRHgucylMj7kzZkRUZWkfnlTM tV2Xx+jmsQXrwOUC4+ptXTKWbJ20IGXpvK2FubMVrJUq5lEhSAkEKpSLKknp4q9LvU/s aZ963fMCsbWEH0BgYFWkuE7Z6mkvbFnvlNv3fIkAqOqz4uo+YwNwWxlQsccaib8YfqKi vDjFOUdKiZ1vylKCXUrC4e9kPbgXUe1z3/7LwXzXFSg3g1Qn304A9LtfkeGuuxvmNfxE sCDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:date:message-id:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=V78oNbusAm5S3e7SX3vKPs7Z58CB44qhuhwypR7BDJE=; b=f41KauZDYu97qLNxMe1IIY4J3nmgZatK81Q+HbihcmQSZnCcaXN3Tyi9IkxhEtKcP0 C4WAhzgKaZBStHZNe5cMVGDe/kNoaCYSGJeXCQfghKymipD9/TbqXEbDBhyaeAenp+eO 0zC+Bfw4iCZpu1MBPBPJbFk7hQB60RVusKa2tVy/HbciDpHoV/x9hGXZen3WxgWXL6kW qtbuEmbv/Ud3g+PblujyrzAI/TMwTgKRj8GvUktIz0KexrLDZG0fmOB2ZA7XKmLbmaSt elv1zMm0t0HHi/Q00btrD3TIEHmCCS1K53I/IU47+f1jrke5nTU15fFEgPFuME08dzQZ iwCw== X-Gm-Message-State: AGi0PuZFkKCgy4ADiCJsp7tvq+PtXagcFeKgEO8cvS5nczMTnE1xqvQ7 WryfvkOQ7AwYAN8BmBoioLQ= X-Google-Smtp-Source: APiQypK0j0AbyZ9uZMx6YtbYcZZpm6duOkXi5D/eh2ypm9IW5lE2Qx2a4HsrC7fib7wGjII2HUGjMg== X-Received: by 2002:aed:21b0:: with SMTP id l45mr8944433qtc.47.1586375329394; Wed, 08 Apr 2020 12:48:49 -0700 (PDT) Subject: [PATCH v17 RESUBMIT QEMU 1/3] virtio-balloon: Implement support for page poison tracking feature From: Alexander Duyck To: david@redhat.com, mst@redhat.com Date: Wed, 08 Apr 2020 12:48:47 -0700 Message-ID: <20200408194847.24143.91542.stgit@localhost.localdomain> In-Reply-To: <20200408194628.24143.51644.stgit@localhost.localdomain> References: <20200408194628.24143.51644.stgit@localhost.localdomain> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::834 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: virtio-dev@lists.oasis-open.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) From: Alexander Duyck We need to make certain to advertise support for page poison tracking if we want to actually get data on if the guest will be poisoning pages. So if free page hinting is active we should add page poisoning support and let the guest disable it if it isn't using it. Page poisoning will result in a page being dirtied on free. As such we cannot really avoid having to copy the page at least one more time since we will need to write the poison value to the destination. As such we can just ignore free page hinting if page poisoning is enabled as it will actually reduce the work we have to do. Signed-off-by: Alexander Duyck --- hw/virtio/virtio-balloon.c | 25 +++++++++++++++++++++---- include/hw/virtio/virtio-balloon.h | 1 + 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c index a4729f7fc930..455d85b7082f 100644 --- a/hw/virtio/virtio-balloon.c +++ b/hw/virtio/virtio-balloon.c @@ -531,6 +531,15 @@ static void virtio_balloon_free_page_start(VirtIOBallo= on *s) return; } =20 + /* + * If page poisoning is enabled then we probably shouldn't bother with + * the hinting since the poisoning will dirty the page and invalidate + * the work we are doing anyway. + */ + if (virtio_vdev_has_feature(vdev, VIRTIO_BALLOON_F_PAGE_POISON)) { + return; + } + if (s->free_page_report_cmd_id =3D=3D UINT_MAX) { s->free_page_report_cmd_id =3D VIRTIO_BALLOON_FREE_PAGE_REPORT_CMD_ID_MIN; @@ -618,12 +627,10 @@ static size_t virtio_balloon_config_size(VirtIOBalloo= n *s) if (s->qemu_4_0_config_size) { return sizeof(struct virtio_balloon_config); } - if (virtio_has_feature(features, VIRTIO_BALLOON_F_PAGE_POISON)) { + if (virtio_has_feature(features, VIRTIO_BALLOON_F_PAGE_POISON) || + virtio_has_feature(features, VIRTIO_BALLOON_F_FREE_PAGE_HINT)) { return sizeof(struct virtio_balloon_config); } - if (virtio_has_feature(features, VIRTIO_BALLOON_F_FREE_PAGE_HINT)) { - return offsetof(struct virtio_balloon_config, poison_val); - } return offsetof(struct virtio_balloon_config, free_page_report_cmd_id); } =20 @@ -634,6 +641,7 @@ static void virtio_balloon_get_config(VirtIODevice *vde= v, uint8_t *config_data) =20 config.num_pages =3D cpu_to_le32(dev->num_pages); config.actual =3D cpu_to_le32(dev->actual); + config.poison_val =3D cpu_to_le32(dev->poison_val); =20 if (dev->free_page_report_status =3D=3D FREE_PAGE_REPORT_S_REQUESTED) { config.free_page_report_cmd_id =3D @@ -697,6 +705,8 @@ static void virtio_balloon_set_config(VirtIODevice *vde= v, qapi_event_send_balloon_change(vm_ram_size - ((ram_addr_t) dev->actual << VIRTIO_BALLOON_PFN_SH= IFT)); } + dev->poison_val =3D virtio_vdev_has_feature(vdev, VIRTIO_BALLOON_F_PAG= E_POISON) ?=20 + le32_to_cpu(config.poison_val) : 0; trace_virtio_balloon_set_config(dev->actual, oldactual); } =20 @@ -706,6 +716,9 @@ static uint64_t virtio_balloon_get_features(VirtIODevic= e *vdev, uint64_t f, VirtIOBalloon *dev =3D VIRTIO_BALLOON(vdev); f |=3D dev->host_features; virtio_add_feature(&f, VIRTIO_BALLOON_F_STATS_VQ); + if (virtio_has_feature(f, VIRTIO_BALLOON_F_FREE_PAGE_HINT)) { + virtio_add_feature(&f, VIRTIO_BALLOON_F_PAGE_POISON); + } =20 return f; } @@ -854,6 +867,8 @@ static void virtio_balloon_device_reset(VirtIODevice *v= dev) g_free(s->stats_vq_elem); s->stats_vq_elem =3D NULL; } + + s->poison_val =3D 0; } =20 static void virtio_balloon_set_status(VirtIODevice *vdev, uint8_t status) @@ -916,6 +931,8 @@ static Property virtio_balloon_properties[] =3D { VIRTIO_BALLOON_F_DEFLATE_ON_OOM, false), DEFINE_PROP_BIT("free-page-hint", VirtIOBalloon, host_features, VIRTIO_BALLOON_F_FREE_PAGE_HINT, false), + DEFINE_PROP_BIT("x-page-poison", VirtIOBalloon, host_features, + VIRTIO_BALLOON_F_PAGE_POISON, false), /* QEMU 4.0 accidentally changed the config size even when free-page-h= int * is disabled, resulting in QEMU 3.1 migration incompatibility. This * property retains this quirk for QEMU 4.1 machine types. diff --git a/include/hw/virtio/virtio-balloon.h b/include/hw/virtio/virtio-= balloon.h index d1c968d2376e..7fe78e5c14d7 100644 --- a/include/hw/virtio/virtio-balloon.h +++ b/include/hw/virtio/virtio-balloon.h @@ -70,6 +70,7 @@ typedef struct VirtIOBalloon { uint32_t host_features; =20 bool qemu_4_0_config_size; + uint32_t poison_val; } VirtIOBalloon; =20 #endif From nobody Sun May 19 01:26:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1586375405; cv=none; d=zohomail.com; s=zohoarc; b=aqqZmFRA9xTriETZM7WEXhzkGfU5Xgv9livQDhxAgeKCBDDVIKZ0ELteH/6mnjrlEeFjeTfNFW+R2OdB+bXVRX+1Ie6n9e1Ha5DLl8xWUC2VMvDEbWm6h/R9Q2xzXTRtmoeSpVPg5Q3jA/TqYeibsapADZOqgiSgFv7CQQz2hZw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1586375405; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=IOMlbjfXWuE+0u1ners+vpffTKgzzJDssD1Ouo69X0c=; b=gBFp2TF/sDvjrPh+kzz/6QnYoZT64IRrrmOkdGGYGfe/R1rSqZMRyZIkgVac7KF8wXWTpDI38lSU04BD8Q8ePzxKMVB39TQqwJ5xwSQCOfzIyXwom5JJA6M6hndEezcOmI09d9MAad/bb980TKSeVX5uPqZJxmEzbbhAm2KOyMo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1586375405133309.16019388080133; Wed, 8 Apr 2020 12:50:05 -0700 (PDT) Received: from localhost ([::1]:40032 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jMGi3-0003C9-Mj for importer@patchew.org; Wed, 08 Apr 2020 15:50:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37218) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jMGh2-0001t2-Ng for qemu-devel@nongnu.org; Wed, 08 Apr 2020 15:49:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jMGh0-0002ze-Ir for qemu-devel@nongnu.org; Wed, 08 Apr 2020 15:49:00 -0400 Received: from mail-qv1-xf42.google.com ([2607:f8b0:4864:20::f42]:42717) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jMGgz-0002xd-EC for qemu-devel@nongnu.org; Wed, 08 Apr 2020 15:48:58 -0400 Received: by mail-qv1-xf42.google.com with SMTP id ca9so4314389qvb.9 for ; Wed, 08 Apr 2020 12:48:57 -0700 (PDT) Received: from localhost.localdomain ([2001:470:b:9c3:9e5c:8eff:fe4f:f2d0]) by smtp.gmail.com with ESMTPSA id t24sm5019928qkj.23.2020.04.08.12.48.55 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Apr 2020 12:48:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=IOMlbjfXWuE+0u1ners+vpffTKgzzJDssD1Ouo69X0c=; b=FSHTEzfDUkxuEf+1W+sAmhhANtyGhE2YTFAJ7s6ItmMRQBRjeLfpNek7JbCxKqBOGl pZIBzW7H+HoqeC9ZRVanOA3vQZ/JwZ8gdTDutljLbjhbdpHkL0jNSLVNV+VXVnch+DlS VfxSLQDQFpL3+bgRMTao3XGBA4vPV9Zkfa8ASsf290XcKcc/EqNmUbJr7yCtkgVXtME5 RydLmrTqQIAG4+lc92eRht/UdPyrvHjB0PlN9Keg3B2Q+X/mhoqJCWrs9Gl/jnS5jh/h lG+4XcqwNqm+O6+ZsWzaLmzytGnz1F7XFwOouWvo3+kZjlVAlWU9/6LSI7rUSvHluM2H 4kuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:date:message-id:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=IOMlbjfXWuE+0u1ners+vpffTKgzzJDssD1Ouo69X0c=; b=N0fV1a6Pu/SS/0DCZw7ONG0Pxi8w/35MpREiSk4zbCtI8EEts+pCpPwseIJE53q5nb 76Kltq7xAaJsk9HVU5ghUMUJDebC8qONFeBX6B1uBLou/6dm4KwZKXELbItcUUqIaBqn lHKWkvx+jw3MNMaefhhGLZ8ugH2HLNyLGANZjjhQZSa8YkkyKtuRiz+RFRmydocBoNQE 7psVhURiT2yiJLxFpU3ITsRq9/uPIVuKenvrU0RgpRrZRylgFzkhJ1xsYK+4djEkEPJk u0YM/Q2uyM25laz+LkCtiMPcOr4kVesFOBkt6MrKC/PoWa7nYPNfJjR1SPRBYaI39bk+ yWbQ== X-Gm-Message-State: AGi0PuayjMSxStUvYjbNX9H5rvVjDx2IlWt5BpegOYm1qp0cv/No64EN L6RCtM+oyOgkGTa8e5N7Z5E= X-Google-Smtp-Source: APiQypLxqlqQbYr9Q/QLFHhDDdEyvKmib9sd99MAtR/9zYg8l14bZSWItjNRYdlySyIZEFfG0vRP+w== X-Received: by 2002:ad4:41c2:: with SMTP id a2mr8916779qvq.112.1586375336732; Wed, 08 Apr 2020 12:48:56 -0700 (PDT) Subject: [PATCH v17 RESUBMIT QEMU 2/3] virtio-balloon: Add support for providing free page reports to host From: Alexander Duyck To: david@redhat.com, mst@redhat.com Date: Wed, 08 Apr 2020 12:48:54 -0700 Message-ID: <20200408194854.24143.51548.stgit@localhost.localdomain> In-Reply-To: <20200408194628.24143.51644.stgit@localhost.localdomain> References: <20200408194628.24143.51644.stgit@localhost.localdomain> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::f42 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: virtio-dev@lists.oasis-open.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) 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. Unlike a standard balloon we don't inflate and deflate the pages. Instead we perform the reporting, and once the reporting is completed it is assumed that the page has been dropped from the guest and will be faulted back in the next time the page is accessed. This patch is a subset of the UAPI patch that was submitted for the Linux kernel. The original patch can be found at: https://lore.kernel.org/lkml/20200211224657.29318.68624.stgit@localhost.loc= aldomain/ Signed-off-by: Alexander Duyck --- include/standard-headers/linux/virtio_balloon.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/standard-headers/linux/virtio_balloon.h b/include/stan= dard-headers/linux/virtio_balloon.h index 9375ca2a70de..1c5f6d6f2de6 100644 --- a/include/standard-headers/linux/virtio_balloon.h +++ b/include/standard-headers/linux/virtio_balloon.h @@ -36,6 +36,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_REPORTING 5 /* Page reporting virtqueue */ =20 /* Size of a PFN in the balloon interface. */ #define VIRTIO_BALLOON_PFN_SHIFT 12 From nobody Sun May 19 01:26:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1586375471; cv=none; d=zohomail.com; s=zohoarc; b=foqpqXuIW9XXEkEEwVYpf1eIm/WMQCl08qP5bS0PAm/8I4Uj09DssoqKXW4l4ovyJS6byYJC5ngn6lnSRWknvHx8gSVgSbRTx8bqbpBHYt31muS2IiH8xxYEpaJFmu/YnAikIl2aZz7gPD6cpfhqWaXwGxnkXDlHOxJk6u7uRgY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1586375471; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=gbRBokZUeADxG1Js0n3CcSXLvNNKI4dY2r2GfqE2RsE=; b=YlGWEgNhLci1CaPg82lRyDkosH5DN9GlxbL1uUELHOf8onP4n7BFwv42AdLVI6YGiTGWMsMAxpe9vhD9cSwuFCwIFjL7mporqffALTsvdN/Xj5HLAHGWP1UYai2Zgkmj8mKoBfVONmAkDg4ST6xyPSFkDIqRa1e7GlnQZ1zhkkQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1586375471976826.4139705290297; Wed, 8 Apr 2020 12:51:11 -0700 (PDT) Received: from localhost ([::1]:40058 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jMGj8-00055F-Rq for importer@patchew.org; Wed, 08 Apr 2020 15:51:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37243) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jMGh8-00021J-TS for qemu-devel@nongnu.org; Wed, 08 Apr 2020 15:49:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jMGh6-00036O-JK for qemu-devel@nongnu.org; Wed, 08 Apr 2020 15:49:06 -0400 Received: from mail-qk1-x744.google.com ([2607:f8b0:4864:20::744]:46011) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jMGh6-00035C-9r for qemu-devel@nongnu.org; Wed, 08 Apr 2020 15:49:04 -0400 Received: by mail-qk1-x744.google.com with SMTP id m67so1525288qke.12 for ; Wed, 08 Apr 2020 12:49:04 -0700 (PDT) Received: from localhost.localdomain ([2001:470:b:9c3:9e5c:8eff:fe4f:f2d0]) by smtp.gmail.com with ESMTPSA id y24sm6362658qtn.87.2020.04.08.12.49.02 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Apr 2020 12:49:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=gbRBokZUeADxG1Js0n3CcSXLvNNKI4dY2r2GfqE2RsE=; b=MgqpimCt0H1OWTla793dPDrS3KHHa360iRORSuhXbeVPJFS8obt1JfELdDdPlEnJbR gHBXkVZJ9nRoiqyO7HzVU0A3UsrhcnRCAywDHJWWhTFDPjeEseBzCyhvnnbO6cI+rpNA hYwyHR6i0hS3Ox/Zgc3PxPczF6rw4BPdpU8R9QRoIRC89Xjc+RPxcLOg+BzVIRIyojmQ UaofJvfRbYPbEbSVyO6R2VQcbFOqG+wX473EUq1SmrQ4VcPcMdQxA2OecxOGwc9G5daQ +YfqKB4qd9swYoOAavUXvisL/dQvAnRQQ9MNLDMlkwfEa3Eosq7iCoJoiSA82kRt/m4d O+Ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:date:message-id:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=gbRBokZUeADxG1Js0n3CcSXLvNNKI4dY2r2GfqE2RsE=; b=GuU5b9Sg8idZP/+35T233BB4pXpEf3E8gX19w1dHRJcqVtyuB2gFuwC3AgHIg2+pT3 Ax1QyY7j5i19O/msE8ugWoNimFF43PUmZa0J7oe24TrJpBf2MFxGlifgXMY1h+cSt4Ge ZaKhV8V9lRyeCur+/rNbjkZNzLVkwxbHH+f6lRiP4FeuQ7+j1lUrVB3g9EdBH25t1lSI yoLfNyyIiLRejLS3I5towKVpfySuT1G08StPoH6bTnEsM+63j9RPtxnXBFbqYfHi+sK2 ifEqXzRnmMGMXwrh/i8nHqTh/DeD8brGj0PXN0PBOc+EC/pwDPpH28PG/hSi/biYYn/6 6Ttg== X-Gm-Message-State: AGi0PuZeBO75AC+zP71238RMnqneJoNvSF5AGAo2Pi9EUAy/UIEpjEi3 GkuQFT9VET4yU2bfL2B9BBtZu4vkLP8= X-Google-Smtp-Source: APiQypIQjGcgYg4WGbE7iWiimwp+tk8wjLK2fiN3pCooM7NfGBh4VE0u1+jO3zi1Imto1CLMi9XUCw== X-Received: by 2002:a05:620a:2016:: with SMTP id c22mr8992091qka.334.1586375343649; Wed, 08 Apr 2020 12:49:03 -0700 (PDT) Subject: [PATCH v17 RESUBMIT QEMU 3/3] virtio-balloon: Provide a interface for free page reporting From: Alexander Duyck To: david@redhat.com, mst@redhat.com Date: Wed, 08 Apr 2020 12:49:01 -0700 Message-ID: <20200408194901.24143.34991.stgit@localhost.localdomain> In-Reply-To: <20200408194628.24143.51644.stgit@localhost.localdomain> References: <20200408194628.24143.51644.stgit@localhost.localdomain> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::744 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: virtio-dev@lists.oasis-open.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) From: Alexander Duyck Add support for what I am referring to as "free page reporting". Basically the idea is to function very similar to how the balloon works in that we basically end up madvising the page as not being used. However we don't really need to bother with any deflate type logic since the page will be faulted back into the guest when it is read or written to. This is meant to be a simplification of the existing balloon interface to use for providing hints to what memory needs to be freed. I am assuming this is safe to do as the deflate logic does not actually appear to do very much other than tracking what subpages have been released and which ones haven't. Signed-off-by: Alexander Duyck --- hw/virtio/virtio-balloon.c | 46 ++++++++++++++++++++++++++++++++= ++-- include/hw/virtio/virtio-balloon.h | 2 +- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c index 455d85b7082f..5faafd2f62ac 100644 --- a/hw/virtio/virtio-balloon.c +++ b/hw/virtio/virtio-balloon.c @@ -321,6 +321,40 @@ static void balloon_stats_set_poll_interval(Object *ob= j, Visitor *v, balloon_stats_change_timer(s, 0); } =20 +static void virtio_balloon_handle_report(VirtIODevice *vdev, VirtQueue *vq) +{ + VirtIOBalloon *dev =3D VIRTIO_BALLOON(vdev); + VirtQueueElement *elem; + + while ((elem =3D virtqueue_pop(vq, sizeof(VirtQueueElement)))) { + unsigned int i; + + for (i =3D 0; i < elem->in_num; i++) { + void *addr =3D elem->in_sg[i].iov_base; + size_t size =3D elem->in_sg[i].iov_len; + ram_addr_t ram_offset; + size_t rb_page_size; + RAMBlock *rb; + + if (qemu_balloon_is_inhibited() || dev->poison_val) + continue; + + rb =3D qemu_ram_block_from_host(addr, false, &ram_offset); + rb_page_size =3D qemu_ram_pagesize(rb); + + /* For now we will simply ignore unaligned memory regions */ + if ((ram_offset | size) & (rb_page_size - 1)) + continue; + + ram_block_discard_range(rb, ram_offset, size); + } + + virtqueue_push(vq, elem, 0); + virtio_notify(vdev, vq); + g_free(elem); + } +} + static void virtio_balloon_handle_output(VirtIODevice *vdev, VirtQueue *vq) { VirtIOBalloon *s =3D VIRTIO_BALLOON(vdev); @@ -628,7 +662,8 @@ static size_t virtio_balloon_config_size(VirtIOBalloon = *s) return sizeof(struct virtio_balloon_config); } if (virtio_has_feature(features, VIRTIO_BALLOON_F_PAGE_POISON) || - virtio_has_feature(features, VIRTIO_BALLOON_F_FREE_PAGE_HINT)) { + virtio_has_feature(features, VIRTIO_BALLOON_F_FREE_PAGE_HINT) || + virtio_has_feature(features, VIRTIO_BALLOON_F_REPORTING)) { return sizeof(struct virtio_balloon_config); } return offsetof(struct virtio_balloon_config, free_page_report_cmd_id); @@ -716,7 +751,8 @@ static uint64_t virtio_balloon_get_features(VirtIODevic= e *vdev, uint64_t f, VirtIOBalloon *dev =3D VIRTIO_BALLOON(vdev); f |=3D dev->host_features; virtio_add_feature(&f, VIRTIO_BALLOON_F_STATS_VQ); - if (virtio_has_feature(f, VIRTIO_BALLOON_F_FREE_PAGE_HINT)) { + if (virtio_has_feature(f, VIRTIO_BALLOON_F_FREE_PAGE_HINT) || + virtio_has_feature(f, VIRTIO_BALLOON_F_REPORTING)) { virtio_add_feature(&f, VIRTIO_BALLOON_F_PAGE_POISON); } =20 @@ -806,6 +842,10 @@ static void virtio_balloon_device_realize(DeviceState = *dev, Error **errp) s->dvq =3D virtio_add_queue(vdev, 128, virtio_balloon_handle_output); s->svq =3D virtio_add_queue(vdev, 128, virtio_balloon_receive_stats); =20 + if (virtio_has_feature(s->host_features, VIRTIO_BALLOON_F_REPORTING)) { + s->rvq =3D virtio_add_queue(vdev, 32, virtio_balloon_handle_report= ); + } + if (virtio_has_feature(s->host_features, VIRTIO_BALLOON_F_FREE_PAGE_HINT)) { s->free_page_vq =3D virtio_add_queue(vdev, VIRTQUEUE_MAX_SIZE, @@ -939,6 +979,8 @@ static Property virtio_balloon_properties[] =3D { */ DEFINE_PROP_BOOL("qemu-4-0-config-size", VirtIOBalloon, qemu_4_0_config_size, false), + DEFINE_PROP_BIT("unused-page-reporting", VirtIOBalloon, host_features, + VIRTIO_BALLOON_F_REPORTING, true), DEFINE_PROP_LINK("iothread", VirtIOBalloon, iothread, TYPE_IOTHREAD, IOThread *), DEFINE_PROP_END_OF_LIST(), diff --git a/include/hw/virtio/virtio-balloon.h b/include/hw/virtio/virtio-= balloon.h index 7fe78e5c14d7..db5bf7127112 100644 --- a/include/hw/virtio/virtio-balloon.h +++ b/include/hw/virtio/virtio-balloon.h @@ -42,7 +42,7 @@ enum virtio_balloon_free_page_report_status { =20 typedef struct VirtIOBalloon { VirtIODevice parent_obj; - VirtQueue *ivq, *dvq, *svq, *free_page_vq; + VirtQueue *ivq, *dvq, *svq, *free_page_vq, *rvq; uint32_t free_page_report_status; uint32_t num_pages; uint32_t actual;