From patchwork Wed Apr 8 22:55:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Duyck X-Patchwork-Id: 11481049 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B4A84112C for ; Wed, 8 Apr 2020 22:56:10 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8777420730 for ; Wed, 8 Apr 2020 22:56:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Ch/bGjzo" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8777420730 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:41270 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jMJc9-0001kN-LL for patchwork-qemu-devel@patchwork.kernel.org; Wed, 08 Apr 2020 18:56:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53468) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jMJbN-0000Rj-BH for qemu-devel@nongnu.org; Wed, 08 Apr 2020 18:55:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jMJbM-0001HM-46 for qemu-devel@nongnu.org; Wed, 08 Apr 2020 18:55:21 -0400 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]:36463) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jMJbL-0001H2-Os for qemu-devel@nongnu.org; Wed, 08 Apr 2020 18:55:20 -0400 Received: by mail-pf1-x42c.google.com with SMTP id n10so3160954pff.3 for ; Wed, 08 Apr 2020 15:55:19 -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=IZT5rQBEFmVBhwL98g+uKrEBfh0eqMpZVWez4s0eHKU=; b=Ch/bGjzo6QpTua1xE9LqyGqhbk4xBbhn1o6vsDomoBsjF+Hm85mbQHCND6bLnKs1z+ gWkr52aUbMce5ogqWa+zs1iJW/gfgU2OwR8NpgMO/4igISjy20YErCcm+0lfATh9a61J 1Y6jt7rpsRHFShOyND3j+drTgnR9fnh+y9tTyeflXbUJZ7G9EIyeG+H7Fi+FP9NY9ilW 8Dq/moUbieY0uzxvFQSCBf8U99B0BoJJuBsspIUOboiVcXKJl6S4tVXTkFJOmrpYL7hm FLAyYJOwoLn18TkcXnnoHD53bZzydxkOT6pP2jyaHGqd+8I7rRSV7Sol5JR+jd1fvJQL Z8fQ== 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=IZT5rQBEFmVBhwL98g+uKrEBfh0eqMpZVWez4s0eHKU=; b=rqEWzxWaQPgIOMfdt61HLyrHdnJY77ScG4mra/PUJ61DubR0oT6RRbYEqBU7+o/AV7 vIzcR2dNSsHxlTz0O8+0rHilmkUYRxDKasPF9JzQ+vZ1LNIYlihOWfax3scOUdSadacL SUJ2b4DT14FMq4VrxqaxdwtC5F1eepBpPu8rDIZ4ZWgY/ZnlZq9RDGpQ98b3fbjYCJdQ jiEjD06Jg09SEEJwleShMIhMr47wFtTVMNttHtphs8/2zvEoyoLEl75VBjRbMyXgsfHO 2ruSvFGWjRX7dbUM+QcclvpG/f3arIvt27AKXvs8x5gWrm2fCcAIY+ReeLAbm4ton0Kn AC/Q== X-Gm-Message-State: AGi0PuYjoz58vX/ZD1kPVZ214V/z993qintPRLIv3wSqu5T9PpgtlkbB y+dxC6FRBsiUy75x+x78zb8= X-Google-Smtp-Source: APiQypJtO2bs9VSB0hukHeaMCh3PjhON22S7rUEGEXkkmhyIdGvj0qMv29ILOmnc8jK3m8z110IHrQ== X-Received: by 2002:aa7:9708:: with SMTP id a8mr9561837pfg.66.1586386518332; Wed, 08 Apr 2020 15:55:18 -0700 (PDT) Received: from localhost.localdomain ([2001:470:b:9c3:9e5c:8eff:fe4f:f2d0]) by smtp.gmail.com with ESMTPSA id l190sm17415252pfl.212.2020.04.08.15.55.17 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Apr 2020 15:55:17 -0700 (PDT) Subject: [PATCH v18 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 15:55:17 -0700 Message-ID: <20200408225517.18764.99675.stgit@localhost.localdomain> In-Reply-To: <20200408225302.18764.209.stgit@localhost.localdomain> References: <20200408225302.18764.209.stgit@localhost.localdomain> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::42c 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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 | 26 ++++++++++++++++++++++---- include/hw/virtio/virtio-balloon.h | 1 + 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c index a4729f7fc930..1c6d36a29a04 100644 --- a/hw/virtio/virtio-balloon.c +++ b/hw/virtio/virtio-balloon.c @@ -531,6 +531,15 @@ static void virtio_balloon_free_page_start(VirtIOBalloon *s) return; } + /* + * 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 == UINT_MAX) { s->free_page_report_cmd_id = VIRTIO_BALLOON_FREE_PAGE_REPORT_CMD_ID_MIN; @@ -618,12 +627,10 @@ static size_t virtio_balloon_config_size(VirtIOBalloon *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); } @@ -634,6 +641,7 @@ static void virtio_balloon_get_config(VirtIODevice *vdev, uint8_t *config_data) config.num_pages = cpu_to_le32(dev->num_pages); config.actual = cpu_to_le32(dev->actual); + config.poison_val = cpu_to_le32(dev->poison_val); if (dev->free_page_report_status == FREE_PAGE_REPORT_S_REQUESTED) { config.free_page_report_cmd_id = @@ -697,6 +705,9 @@ static void virtio_balloon_set_config(VirtIODevice *vdev, qapi_event_send_balloon_change(vm_ram_size - ((ram_addr_t) dev->actual << VIRTIO_BALLOON_PFN_SHIFT)); } + dev->poison_val = virtio_vdev_has_feature(vdev, + VIRTIO_BALLOON_F_PAGE_POISON) ? + le32_to_cpu(config.poison_val) : 0; trace_virtio_balloon_set_config(dev->actual, oldactual); } @@ -706,6 +717,9 @@ static uint64_t virtio_balloon_get_features(VirtIODevice *vdev, uint64_t f, VirtIOBalloon *dev = VIRTIO_BALLOON(vdev); f |= 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); + } return f; } @@ -854,6 +868,8 @@ static void virtio_balloon_device_reset(VirtIODevice *vdev) g_free(s->stats_vq_elem); s->stats_vq_elem = NULL; } + + s->poison_val = 0; } static void virtio_balloon_set_status(VirtIODevice *vdev, uint8_t status) @@ -916,6 +932,8 @@ static Property virtio_balloon_properties[] = { 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-hint * 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; bool qemu_4_0_config_size; + uint32_t poison_val; } VirtIOBalloon; #endif From patchwork Wed Apr 8 22:55:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Duyck X-Patchwork-Id: 11481053 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CC95E17D4 for ; Wed, 8 Apr 2020 22:57:19 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9EA7820730 for ; Wed, 8 Apr 2020 22:57:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LhAFwM4a" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9EA7820730 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:41282 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jMJdG-0003gW-Qb for patchwork-qemu-devel@patchwork.kernel.org; Wed, 08 Apr 2020 18:57:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53493) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jMJbT-0000YW-BA for qemu-devel@nongnu.org; Wed, 08 Apr 2020 18:55:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jMJbS-0001Jj-35 for qemu-devel@nongnu.org; Wed, 08 Apr 2020 18:55:27 -0400 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]:38972) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jMJbR-0001JL-T5 for qemu-devel@nongnu.org; Wed, 08 Apr 2020 18:55:26 -0400 Received: by mail-pf1-x442.google.com with SMTP id k15so3150817pfh.6 for ; Wed, 08 Apr 2020 15:55:25 -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=LhAFwM4aCGpSxxCshU7Zfg64BFB9F27L0JucH8w+dt9Uwb0uE+X9qJH98HrrqfvKgG CKpEtypwUeAsuQAgTlDoy2NWi2LwUHmAl5kUgnYgTuSXdYAD/rmCBNXcUasSVHlGKz3t ie/fi7pYrywW/dsrpPTiTMBhwVCT3ijasqKqX651aTQb9IWhDcdJz2IqasWfjZDP2zwh Gpb9RGD2SDnWB+Mkf8uHvQclkqp/NUCbAED55mVhqmQwwNPiOsM56G9XgrmZcsqiZDJ7 nWuKQZXotUaa1D73SaJPlzaQ7YQ8iwXDVLoJho1hPsmXR7WzYQIfz9rPJwWtsKS+28pV kqaQ== 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=k8KblQb7NcDAm2WirHUBRyVWCIjW35jh2sbZdYbQviEe4ofO0yqAqM98VACe9wk5CG nzMW0AGLx5Bp2/Q66jMVpTqsBjChCNyy4pFp/KiIhUSaEHYyoS+tL3vHeeVaL15MUJlg qLculI2TDebp41lCwrUXf5313NqaP0UZ+OhVtBf0NJV/Ei5COGNeo80OD4oM0EsCqDLV uzNp35DW14kQEXTAkByCWrtBicELjfEZsvUcZ8ur+TQup/UX08W3+4uj3v4So5towqLr j2G8BEh+ZaOqjUyD7wri0Z0BePq+nm/rGsmQDFEuIMfI/FyDAgs7w7EGdL1pftH/QB1N L3hQ== X-Gm-Message-State: AGi0PuYSKnvB0Ot370tbTwDLVjwfKhV4YGe1YhI+CEjGPKn3Q3Fr97zR PLFgUrZzYb18Vk5594QY2VU= X-Google-Smtp-Source: APiQypKrZ2uyBWMmsCGQE0B+HyeVZ6Jmpcf6wKIvD1X/N1KgcpxuDhA9d6fFi1oB63V3/9t1r5ibew== X-Received: by 2002:a63:4850:: with SMTP id x16mr9170021pgk.317.1586386524582; Wed, 08 Apr 2020 15:55:24 -0700 (PDT) Received: from localhost.localdomain ([2001:470:b:9c3:9e5c:8eff:fe4f:f2d0]) by smtp.gmail.com with ESMTPSA id z7sm516712pju.37.2020.04.08.15.55.24 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Apr 2020 15:55:24 -0700 (PDT) Subject: [PATCH v18 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 15:55:23 -0700 Message-ID: <20200408225523.18764.86514.stgit@localhost.localdomain> In-Reply-To: <20200408225302.18764.209.stgit@localhost.localdomain> References: <20200408225302.18764.209.stgit@localhost.localdomain> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::442 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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.localdomain/ Signed-off-by: Alexander Duyck 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/standard-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 */ /* Size of a PFN in the balloon interface. */ #define VIRTIO_BALLOON_PFN_SHIFT 12 From patchwork Wed Apr 8 22:55:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Duyck X-Patchwork-Id: 11481051 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 52DBF112C for ; Wed, 8 Apr 2020 22:56:18 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2422A2078E for ; Wed, 8 Apr 2020 22:56:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BQ1de24/" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2422A2078E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:41272 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jMJcH-0001vC-A8 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 08 Apr 2020 18:56:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53520) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jMJba-0000cy-CB for qemu-devel@nongnu.org; Wed, 08 Apr 2020 18:55:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jMJbY-0001Q5-Vw for qemu-devel@nongnu.org; Wed, 08 Apr 2020 18:55:34 -0400 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]:35064) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jMJbY-0001Os-BE for qemu-devel@nongnu.org; Wed, 08 Apr 2020 18:55:32 -0400 Received: by mail-pg1-x541.google.com with SMTP id k5so4035570pga.2 for ; Wed, 08 Apr 2020 15:55:31 -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=QbFPTJ8PrOkL5KW33hQUGbiq9WhS0luRbBZRC56AG18=; b=BQ1de24/AEstFg+DyJgjenWMHK9k+WF1qAfAQPhJS/WnNJTXg245v/1hFgVlQLiXy5 Qv2qtuqOsUQ/rd9mUi4d1KQUKY6K+FC7NCEARgJkwuI+pO7JD+QmhnmTmNgpkrYAsucU L3nDh4turo752xeDvRPbZXnc5UHCZrmJXRL2RaE5vVHtMCSawJnln1g8+goydlnYPw9v r+xg+jzKONBXECGJ9L7lyCnsG+tNXgLqbv7J5d673gqOYXxyBiyfinIhjYZ0on7FJgDY kCkdzy7vh0uBikfqH0uBfVTO5lWGl2R/xhfPT2Iai4yG5FAO/qMf1RfH+GNyPAMw7S9s V0NA== 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=QbFPTJ8PrOkL5KW33hQUGbiq9WhS0luRbBZRC56AG18=; b=nQtg7AjUeKGynjAomL0lvNOUFdsIB8o14sX3nktVR7p337CI5FP1akqedYJ2CzSuRw gmOE/GtehB826fJgzC6xZx5e+wisqJJwSgBJm0K8C1ald4pD54xh81QDyLeAZyjxH3JI n82Z1t8TVEMttj+wfzQ6t4O1b3aKpMnuxbRlz1cZVBT5/HOAsaCuLjcDEqmON3l00aDe DBrC6c1CvYFV41sNaoQOW7GszjEwYjhuSIYvL1iS99Sv7XhwsROujc9IDd7ky1l8RgNh lw7zOkp/mRfxKvvFZImULD9ZC23X09cOqLinruh70Kp2XNByRceIfNs4js+yzbaDKUvk m9EQ== X-Gm-Message-State: AGi0PubAhPROIBoZDpT0MdyYO9neVrcpz9WY1UDq+iMQr4RW0uX5NqDU csz0KiPPNuw/9eshJAAH4l4= X-Google-Smtp-Source: APiQypL1CAdbCD7EYmaUHpQ/VthBhJ1skS91TE/SBVEBg0ys4mFzgPpQUJhezQUJMCHwwJXAx4aFMA== X-Received: by 2002:a62:ae05:: with SMTP id q5mr10160634pff.307.1586386530703; Wed, 08 Apr 2020 15:55:30 -0700 (PDT) Received: from localhost.localdomain ([2001:470:b:9c3:9e5c:8eff:fe4f:f2d0]) by smtp.gmail.com with ESMTPSA id x13sm16624418pfj.185.2020.04.08.15.55.30 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Apr 2020 15:55:30 -0700 (PDT) Subject: [PATCH v18 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 15:55:29 -0700 Message-ID: <20200408225529.18764.44086.stgit@localhost.localdomain> In-Reply-To: <20200408225302.18764.209.stgit@localhost.localdomain> References: <20200408225302.18764.209.stgit@localhost.localdomain> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::541 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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 | 48 +++++++++++++++++++++++++++++++++++- include/hw/virtio/virtio-balloon.h | 2 +- 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c index 1c6d36a29a04..297b267198ac 100644 --- a/hw/virtio/virtio-balloon.c +++ b/hw/virtio/virtio-balloon.c @@ -321,6 +321,42 @@ static void balloon_stats_set_poll_interval(Object *obj, Visitor *v, balloon_stats_change_timer(s, 0); } +static void virtio_balloon_handle_report(VirtIODevice *vdev, VirtQueue *vq) +{ + VirtIOBalloon *dev = VIRTIO_BALLOON(vdev); + VirtQueueElement *elem; + + while ((elem = virtqueue_pop(vq, sizeof(VirtQueueElement)))) { + unsigned int i; + + for (i = 0; i < elem->in_num; i++) { + void *addr = elem->in_sg[i].iov_base; + size_t size = 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 = qemu_ram_block_from_host(addr, false, &ram_offset); + rb_page_size = 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 = VIRTIO_BALLOON(vdev); @@ -628,7 +664,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); @@ -717,7 +754,8 @@ static uint64_t virtio_balloon_get_features(VirtIODevice *vdev, uint64_t f, VirtIOBalloon *dev = VIRTIO_BALLOON(vdev); f |= 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); } @@ -807,6 +845,10 @@ static void virtio_balloon_device_realize(DeviceState *dev, Error **errp) s->dvq = virtio_add_queue(vdev, 128, virtio_balloon_handle_output); s->svq = virtio_add_queue(vdev, 128, virtio_balloon_receive_stats); + if (virtio_has_feature(s->host_features, VIRTIO_BALLOON_F_REPORTING)) { + s->rvq = 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 = virtio_add_queue(vdev, VIRTQUEUE_MAX_SIZE, @@ -940,6 +982,8 @@ static Property virtio_balloon_properties[] = { */ 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 { 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;