From patchwork Thu Apr 16 20:00: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: 11493701 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 C669A92C for ; Thu, 16 Apr 2020 20:01:29 +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 9C98321744 for ; Thu, 16 Apr 2020 20:01:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="goWnYVxh" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9C98321744 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]:38766 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jPAhU-000611-JA for patchwork-qemu-devel@patchwork.kernel.org; Thu, 16 Apr 2020 16:01:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56128) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jPAgb-0004dV-A3 for qemu-devel@nongnu.org; Thu, 16 Apr 2020 16:00:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jPAga-0000Lo-Bh for qemu-devel@nongnu.org; Thu, 16 Apr 2020 16:00:33 -0400 Received: from mail-pl1-x641.google.com ([2607:f8b0:4864:20::641]:43604) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jPAga-0000LV-5A for qemu-devel@nongnu.org; Thu, 16 Apr 2020 16:00:32 -0400 Received: by mail-pl1-x641.google.com with SMTP id z6so14972plk.10 for ; Thu, 16 Apr 2020 13:00:32 -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=XWQH+WqkRfp4wJIRuWJ29KttjuuuSpzbvrw8QWn/fPk=; b=goWnYVxhjX5vHde8S++Gnuxwje6qW154GE0dmSzDliq6YxGxVQ9RpyFHJkPXpG4abj NJ2kWUkxLCdoNOLdCqZfneVhJkzww7lOKlL/o5o1Sqak4/X+CkbY1TUKi5X+9b6IxZYb jq2CHT3sRjya2WIBXyD1+P9YSgoyMqVurMGWuzDNg9SgViieAV7b+D9K2drevedDLLGl hXO+FHN+v0dF+q9TtETUMAWj09M2ZOspWYCN7YpA4/aoG5KmaAOYjNBeAJTqE8gEUrV3 9N+/xw/6mWDiT6JlxBeXyFmClh8RCmAF55zidTM8uo7RJVq2+ivC4j0vaaFpPTZPocJ7 JAow== 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=XWQH+WqkRfp4wJIRuWJ29KttjuuuSpzbvrw8QWn/fPk=; b=JcE0iJgpZblt/Mvu+uyqGsl4wbpRPGO0HwkgZQp2Oc7KdSM6l2RbQzhPuaRBKWYodH wZ2rrqsD8bYWeqsCYahNts6ON4jiftkYL3CbZ0+2pEUdjVoUUE54G2LVpnCyTsoMdeRO evW6wDvilM4Rl6brvJ873vFeSRjkLd/79s+QFD+bt+4LwLv6o8I4O1bb+nRYfmoHQTAL mGrA+IbBwKb+wKNwUawEtbvSiKXMAgU9YyP+2Ts1wT90MnItl+3e3swYOmCmf10ihE3q jiUWmBinZcMMQGGN5zIsME1M4YkrV2d2a6KJxk3AgYaLUnmVuX2E5YAs7gl0SVGwVS0V oz5A== X-Gm-Message-State: AGi0PuYkB+9bInejWi7pvPlHovr+0qKYVcBS6v1ImWXfUwsbRfB13rqn OZl45tr4qRHNEyi4tLsi7U8= X-Google-Smtp-Source: APiQypIMQmN6sXFtDrPrUQmCQBmH/xUeksrL0cfeLaWTFOv9duU4Oc6XQnkGvpuX/LhPozMEAm9nqQ== X-Received: by 2002:a17:902:8d86:: with SMTP id v6mr11689175plo.57.1587067230717; Thu, 16 Apr 2020 13:00:30 -0700 (PDT) Received: from localhost.localdomain ([2001:470:b:9c3:9e5c:8eff:fe4f:f2d0]) by smtp.gmail.com with ESMTPSA id v202sm1210185pgb.46.2020.04.16.13.00.29 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Apr 2020 13:00:29 -0700 (PDT) Subject: [PATCH v20 QEMU 1/5] linux-headers: Update to allow renaming of free_page_report_cmd_id From: Alexander Duyck To: david@redhat.com, mst@redhat.com Date: Thu, 16 Apr 2020 13:00:29 -0700 Message-ID: <20200416200029.13144.8957.stgit@localhost.localdomain> In-Reply-To: <20200416195641.13144.16955.stgit@localhost.localdomain> References: <20200416195641.13144.16955.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::641 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 Sync to the latest upstream changes for free page hinting. To be replaced by a full linux header sync. Signed-off-by: Alexander Duyck --- include/standard-headers/linux/virtio_balloon.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/include/standard-headers/linux/virtio_balloon.h b/include/standard-headers/linux/virtio_balloon.h index 9375ca2a70de..af0a6b59dab2 100644 --- a/include/standard-headers/linux/virtio_balloon.h +++ b/include/standard-headers/linux/virtio_balloon.h @@ -47,8 +47,15 @@ struct virtio_balloon_config { uint32_t num_pages; /* Number of pages we've actually got in balloon. */ uint32_t actual; - /* Free page report command id, readonly by guest */ - uint32_t free_page_report_cmd_id; + /* + * Free page hint command id, readonly by guest. + * Was previously name free_page_report_cmd_id so we + * need to carry that name for legacy support. + */ + union { + uint32_t free_page_hint_cmd_id; + uint32_t free_page_report_cmd_id; /* deprecated */ + }; /* Stores PAGE_POISON if page poisoning is in use */ uint32_t poison_val; }; From patchwork Thu Apr 16 20:00:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Duyck X-Patchwork-Id: 11493703 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 82CF6112C for ; Thu, 16 Apr 2020 20:01:48 +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 4626A21744 for ; Thu, 16 Apr 2020 20:01:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="G0K6/2E3" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4626A21744 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]:38768 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jPAhn-0006UA-5u for patchwork-qemu-devel@patchwork.kernel.org; Thu, 16 Apr 2020 16:01:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56145) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jPAgi-0004pM-U1 for qemu-devel@nongnu.org; Thu, 16 Apr 2020 16:00:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jPAgh-0000PC-4y for qemu-devel@nongnu.org; Thu, 16 Apr 2020 16:00:40 -0400 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]:40832) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jPAgg-0000Ot-UH for qemu-devel@nongnu.org; Thu, 16 Apr 2020 16:00:39 -0400 Received: by mail-pf1-x441.google.com with SMTP id x3so2153867pfp.7 for ; Thu, 16 Apr 2020 13:00:38 -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=YJd/5+rwmU7jV4Cc2a5A8ynsedgtcoLuxNlkQDArthc=; b=G0K6/2E3sDX5uKbs2Kj+vJeUlIPke9cKwEvNEdSHwCBAGyCdNW/EGw/VQ/lvsZ+GBc CQWKgX07HBEsIu2BnLoS+arxiQ6EITSVHLAqxds/Hmb8GS7qji6J+gF7oiOJdKWpHN4r XRxApemMV+NYaupuaehEjJBqHCENlK1Mar9gA3JI1/KYOBa/hmSi/RAmscdidiCqSCGk WaK8eVNkmA2SI49OJHCMM0QYup2doCAPHTpLvfqKId8GokhZZwNUHRC6Nwm2vRGJ6FcF KT1hMz2VUFwj6xIeugTIMRflx2KWTaCficiQ01ToO1u3xarhSlR12NMWRqakv4tlIc4d uKBQ== 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=YJd/5+rwmU7jV4Cc2a5A8ynsedgtcoLuxNlkQDArthc=; b=DpfAqabnivtxju9UVpYI9byQWOsjZsK69oUjWcItdbeKmK6c/bQ5AaeMpqgjyEfOA1 0yw6e9ZXsO6yMHRwC+J/LhHk4IX/oITQo7d/Rd2eg4ZD9Dn4Dhx9pZhb5vbiaGe1uJXK g1CxXjGDPRxEtaLQMZbarb6NLcXuTe/tbiSF9JvCmRXkscUMrNEKFQeCqhQt/BJb5Hy4 ZjufBgWc0OnQN9Ht/++WAaH3b2lFOqs0HuLm8izjTsSuHYvSQqq4ycPv01Um7mrgqV40 /0d8Zv5ubxg54+zRFXI1rSHYy6Mw6lJo4ObbVGMz9wAQgvkr+xvsFoDGHhFCsqt9PcFn j0yA== X-Gm-Message-State: AGi0PuZnmyrHja2BnqE1+45E2WTTFu831xrTR4eh3VjGjo9cQCnLakux YhBJbSk0eY9FhrXBCbnM65M= X-Google-Smtp-Source: APiQypKf96mBco0aaw69jYXfUm4wt9YM2SALdKOQkr+H4lQJN7BGEvmwk9zc4MnP2Ud0sSsLh4OYZw== X-Received: by 2002:a62:7c86:: with SMTP id x128mr2802328pfc.295.1587067237617; Thu, 16 Apr 2020 13:00:37 -0700 (PDT) Received: from localhost.localdomain ([2001:470:b:9c3:9e5c:8eff:fe4f:f2d0]) by smtp.gmail.com with ESMTPSA id b186sm17662684pfg.77.2020.04.16.13.00.36 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Apr 2020 13:00:36 -0700 (PDT) Subject: [PATCH v20 QEMU 2/5] virtio-balloon: Replace free page hinting references to 'report' with 'hint' From: Alexander Duyck To: david@redhat.com, mst@redhat.com Date: Thu, 16 Apr 2020 13:00:35 -0700 Message-ID: <20200416200035.13144.57468.stgit@localhost.localdomain> In-Reply-To: <20200416195641.13144.16955.stgit@localhost.localdomain> References: <20200416195641.13144.16955.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::441 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 In an upcoming patch a feature named Free Page Reporting is about to be added. In order to avoid any confusion we should drop the use of the word 'report' when referring to Free Page Hinting. So what this patch does is go through and replace all instances of 'report' with 'hint" when we are referring to free page hinting. Signed-off-by: Alexander Duyck --- hw/virtio/virtio-balloon.c | 74 ++++++++++++++++++------------------ include/hw/virtio/virtio-balloon.h | 20 +++++----- 2 files changed, 47 insertions(+), 47 deletions(-) diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c index a4729f7fc930..a1d6fb52c876 100644 --- a/hw/virtio/virtio-balloon.c +++ b/hw/virtio/virtio-balloon.c @@ -466,21 +466,21 @@ static bool get_free_page_hints(VirtIOBalloon *dev) ret = false; goto out; } - if (id == dev->free_page_report_cmd_id) { - dev->free_page_report_status = FREE_PAGE_REPORT_S_START; + if (id == dev->free_page_hint_cmd_id) { + dev->free_page_hint_status = FREE_PAGE_HINT_S_START; } else { /* * Stop the optimization only when it has started. This * avoids a stale stop sign for the previous command. */ - if (dev->free_page_report_status == FREE_PAGE_REPORT_S_START) { - dev->free_page_report_status = FREE_PAGE_REPORT_S_STOP; + if (dev->free_page_hint_status == FREE_PAGE_HINT_S_START) { + dev->free_page_hint_status = FREE_PAGE_HINT_S_STOP; } } } if (elem->in_num) { - if (dev->free_page_report_status == FREE_PAGE_REPORT_S_START) { + if (dev->free_page_hint_status == FREE_PAGE_HINT_S_START) { qemu_guest_free_page_hint(elem->in_sg[0].iov_base, elem->in_sg[0].iov_len); } @@ -506,11 +506,11 @@ static void virtio_ballloon_get_free_page_hints(void *opaque) qemu_mutex_unlock(&dev->free_page_lock); virtio_notify(vdev, vq); /* - * Start to poll the vq once the reporting started. Otherwise, continue + * Start to poll the vq once the hinting started. Otherwise, continue * only when there are entries on the vq, which need to be given back. */ } while (continue_to_get_hints || - dev->free_page_report_status == FREE_PAGE_REPORT_S_START); + dev->free_page_hint_status == FREE_PAGE_HINT_S_START); virtio_queue_set_notification(vq, 1); } @@ -531,14 +531,14 @@ static void virtio_balloon_free_page_start(VirtIOBalloon *s) return; } - if (s->free_page_report_cmd_id == UINT_MAX) { - s->free_page_report_cmd_id = - VIRTIO_BALLOON_FREE_PAGE_REPORT_CMD_ID_MIN; + if (s->free_page_hint_cmd_id == UINT_MAX) { + s->free_page_hint_cmd_id = + VIRTIO_BALLOON_FREE_PAGE_HINT_CMD_ID_MIN; } else { - s->free_page_report_cmd_id++; + s->free_page_hint_cmd_id++; } - s->free_page_report_status = FREE_PAGE_REPORT_S_REQUESTED; + s->free_page_hint_status = FREE_PAGE_HINT_S_REQUESTED; virtio_notify_config(vdev); } @@ -546,18 +546,18 @@ static void virtio_balloon_free_page_stop(VirtIOBalloon *s) { VirtIODevice *vdev = VIRTIO_DEVICE(s); - if (s->free_page_report_status != FREE_PAGE_REPORT_S_STOP) { + if (s->free_page_hint_status != FREE_PAGE_HINT_S_STOP) { /* * The lock also guarantees us that the * virtio_ballloon_get_free_page_hints exits after the - * free_page_report_status is set to S_STOP. + * free_page_hint_status is set to S_STOP. */ qemu_mutex_lock(&s->free_page_lock); /* * The guest hasn't done the reporting, so host sends a notification * to the guest to actively stop the reporting. */ - s->free_page_report_status = FREE_PAGE_REPORT_S_STOP; + s->free_page_hint_status = FREE_PAGE_HINT_S_STOP; qemu_mutex_unlock(&s->free_page_lock); virtio_notify_config(vdev); } @@ -567,15 +567,15 @@ static void virtio_balloon_free_page_done(VirtIOBalloon *s) { VirtIODevice *vdev = VIRTIO_DEVICE(s); - s->free_page_report_status = FREE_PAGE_REPORT_S_DONE; + s->free_page_hint_status = FREE_PAGE_HINT_S_DONE; virtio_notify_config(vdev); } static int -virtio_balloon_free_page_report_notify(NotifierWithReturn *n, void *data) +virtio_balloon_free_page_hint_notify(NotifierWithReturn *n, void *data) { VirtIOBalloon *dev = container_of(n, VirtIOBalloon, - free_page_report_notify); + free_page_hint_notify); VirtIODevice *vdev = VIRTIO_DEVICE(dev); PrecopyNotifyData *pnd = data; @@ -624,7 +624,7 @@ static size_t virtio_balloon_config_size(VirtIOBalloon *s) 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); + return offsetof(struct virtio_balloon_config, free_page_hint_cmd_id); } static void virtio_balloon_get_config(VirtIODevice *vdev, uint8_t *config_data) @@ -635,14 +635,14 @@ 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); - if (dev->free_page_report_status == FREE_PAGE_REPORT_S_REQUESTED) { - config.free_page_report_cmd_id = - cpu_to_le32(dev->free_page_report_cmd_id); - } else if (dev->free_page_report_status == FREE_PAGE_REPORT_S_STOP) { - config.free_page_report_cmd_id = + if (dev->free_page_hint_status == FREE_PAGE_HINT_S_REQUESTED) { + config.free_page_hint_cmd_id = + cpu_to_le32(dev->free_page_hint_cmd_id); + } else if (dev->free_page_hint_status == FREE_PAGE_HINT_S_STOP) { + config.free_page_hint_cmd_id = cpu_to_le32(VIRTIO_BALLOON_CMD_ID_STOP); - } else if (dev->free_page_report_status == FREE_PAGE_REPORT_S_DONE) { - config.free_page_report_cmd_id = + } else if (dev->free_page_hint_status == FREE_PAGE_HINT_S_DONE) { + config.free_page_hint_cmd_id = cpu_to_le32(VIRTIO_BALLOON_CMD_ID_DONE); } @@ -743,14 +743,14 @@ static int virtio_balloon_post_load_device(void *opaque, int version_id) return 0; } -static const VMStateDescription vmstate_virtio_balloon_free_page_report = { +static const VMStateDescription vmstate_virtio_balloon_free_page_hint = { .name = "virtio-balloon-device/free-page-report", .version_id = 1, .minimum_version_id = 1, .needed = virtio_balloon_free_page_support, .fields = (VMStateField[]) { - VMSTATE_UINT32(free_page_report_cmd_id, VirtIOBalloon), - VMSTATE_UINT32(free_page_report_status, VirtIOBalloon), + VMSTATE_UINT32(free_page_hint_cmd_id, VirtIOBalloon), + VMSTATE_UINT32(free_page_hint_status, VirtIOBalloon), VMSTATE_END_OF_LIST() } }; @@ -766,7 +766,7 @@ static const VMStateDescription vmstate_virtio_balloon_device = { VMSTATE_END_OF_LIST() }, .subsections = (const VMStateDescription * []) { - &vmstate_virtio_balloon_free_page_report, + &vmstate_virtio_balloon_free_page_hint, NULL } }; @@ -797,12 +797,12 @@ static void virtio_balloon_device_realize(DeviceState *dev, Error **errp) VIRTIO_BALLOON_F_FREE_PAGE_HINT)) { s->free_page_vq = virtio_add_queue(vdev, VIRTQUEUE_MAX_SIZE, virtio_balloon_handle_free_page_vq); - s->free_page_report_status = FREE_PAGE_REPORT_S_STOP; - s->free_page_report_cmd_id = - VIRTIO_BALLOON_FREE_PAGE_REPORT_CMD_ID_MIN; - s->free_page_report_notify.notify = - virtio_balloon_free_page_report_notify; - precopy_add_notifier(&s->free_page_report_notify); + s->free_page_hint_status = FREE_PAGE_HINT_S_STOP; + s->free_page_hint_cmd_id = + VIRTIO_BALLOON_FREE_PAGE_HINT_CMD_ID_MIN; + s->free_page_hint_notify.notify = + virtio_balloon_free_page_hint_notify; + precopy_add_notifier(&s->free_page_hint_notify); if (s->iothread) { object_ref(OBJECT(s->iothread)); s->free_page_bh = aio_bh_new(iothread_get_aio_context(s->iothread), @@ -827,7 +827,7 @@ static void virtio_balloon_device_unrealize(DeviceState *dev, Error **errp) if (virtio_balloon_free_page_support(s)) { qemu_bh_delete(s->free_page_bh); virtio_balloon_free_page_stop(s); - precopy_remove_notifier(&s->free_page_report_notify); + precopy_remove_notifier(&s->free_page_hint_notify); } balloon_stats_destroy_timer(s); qemu_remove_balloon_handler(s); diff --git a/include/hw/virtio/virtio-balloon.h b/include/hw/virtio/virtio-balloon.h index d1c968d2376e..108cff97e71a 100644 --- a/include/hw/virtio/virtio-balloon.h +++ b/include/hw/virtio/virtio-balloon.h @@ -23,7 +23,7 @@ #define VIRTIO_BALLOON(obj) \ OBJECT_CHECK(VirtIOBalloon, (obj), TYPE_VIRTIO_BALLOON) -#define VIRTIO_BALLOON_FREE_PAGE_REPORT_CMD_ID_MIN 0x80000000 +#define VIRTIO_BALLOON_FREE_PAGE_HINT_CMD_ID_MIN 0x80000000 typedef struct virtio_balloon_stat VirtIOBalloonStat; @@ -33,20 +33,20 @@ typedef struct virtio_balloon_stat_modern { uint64_t val; } VirtIOBalloonStatModern; -enum virtio_balloon_free_page_report_status { - FREE_PAGE_REPORT_S_STOP = 0, - FREE_PAGE_REPORT_S_REQUESTED = 1, - FREE_PAGE_REPORT_S_START = 2, - FREE_PAGE_REPORT_S_DONE = 3, +enum virtio_balloon_free_page_hint_status { + FREE_PAGE_HINT_S_STOP = 0, + FREE_PAGE_HINT_S_REQUESTED = 1, + FREE_PAGE_HINT_S_START = 2, + FREE_PAGE_HINT_S_DONE = 3, }; typedef struct VirtIOBalloon { VirtIODevice parent_obj; VirtQueue *ivq, *dvq, *svq, *free_page_vq; - uint32_t free_page_report_status; + uint32_t free_page_hint_status; uint32_t num_pages; uint32_t actual; - uint32_t free_page_report_cmd_id; + uint32_t free_page_hint_cmd_id; uint64_t stats[VIRTIO_BALLOON_S_NR]; VirtQueueElement *stats_vq_elem; size_t stats_vq_offset; @@ -55,7 +55,7 @@ typedef struct VirtIOBalloon { QEMUBH *free_page_bh; /* * Lock to synchronize threads to access the free page reporting related - * fields (e.g. free_page_report_status). + * fields (e.g. free_page_hint_status). */ QemuMutex free_page_lock; QemuCond free_page_cond; @@ -64,7 +64,7 @@ typedef struct VirtIOBalloon { * stopped. */ bool block_iothread; - NotifierWithReturn free_page_report_notify; + NotifierWithReturn free_page_hint_notify; int64_t stats_last_update; int64_t stats_poll_interval; uint32_t host_features; From patchwork Thu Apr 16 20:00:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Duyck X-Patchwork-Id: 11493705 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 A3ACF112C for ; Thu, 16 Apr 2020 20:02:06 +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 79C1021744 for ; Thu, 16 Apr 2020 20:02:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="G492WGL1" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 79C1021744 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]:38776 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jPAi5-0006na-HI for patchwork-qemu-devel@patchwork.kernel.org; Thu, 16 Apr 2020 16:02:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56171) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jPAgr-000526-1n for qemu-devel@nongnu.org; Thu, 16 Apr 2020 16:00:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jPAgo-0000U4-SA for qemu-devel@nongnu.org; Thu, 16 Apr 2020 16:00:48 -0400 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]:38294) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jPAgo-0000Tm-Lj for qemu-devel@nongnu.org; Thu, 16 Apr 2020 16:00:46 -0400 Received: by mail-pl1-x644.google.com with SMTP id w3so25945plz.5 for ; Thu, 16 Apr 2020 13:00:46 -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=wvk7nigxCNm3PB+AvD69Criz9Bq5lWke+Bvc71+/U/E=; b=G492WGL1cz1eCnfFjL3KlDJye+n7mj0KjCq8Nzpu6Qb1oLWeFtPrRWAIOp7SfXwDb8 GrwQC6K+Utk8gi8jQ0MQxePLGjL0l4JN4EdJpot9knqFAgSElITcELsqkUMzxSo/XUy6 VjA2PCZ+fw3t3Zkdvy1tAJwz7JBliK+yBpXQzE3o39rNf5E0cmc386HmQhww6O5Z3jvl yoR9Hcb30TKpJZihO+ZOr2JtBd85V6xmhyOKlhe6ieMppjWEcb0vKynUxDvGoyXzH8R/ XLWdcFzfwTlX2/76iOtm+2FuZnjCLQoeE+knN901KFaTPBoq7ifrOnQcUDzvV8xZubN1 VBZw== 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=wvk7nigxCNm3PB+AvD69Criz9Bq5lWke+Bvc71+/U/E=; b=tn+xkaldNd40Q52Ehj/JsrO+Yv1EZBA5EkEr0c2F4KoCkbgI1nZPbEMM8677kqFc0g TCpJZq2WiHWhhFUcUEciTPjbQ7ilMXyDEPMtMxYybmCSo9OLkKuGbYgaZxI08yUH5+rR 4zbuHwFd++eO37qKBYxTV5MJ/QMxXWi2SAkHaLGD3ODkfKgcAkFpC3KSdEuPxYqANxqg fAo6jSlVEr5oLdrW7pEQs7xUBzif5DyfgdfnVzgzIC4oO4F7NqoLTe+ULrxXYV0qXIif I8lLVm9pI1Trv7JGF0i26AJob3/6s92RItkPFudzBUJugOTDjgffPWCmDbpmWTzMPvPL MWqA== X-Gm-Message-State: AGi0PuaLIJCMC4fHhcK97aRVm/vEL++T5OAUZIR+XOO0ZIYflY/rm4Q4 gI/H1hy2jwhlMPLW9SZNeQA= X-Google-Smtp-Source: APiQypKJLAm0D1gjhTifvaKp99X2/3SU6AyhBgMF+2kUC0JERsXYS1f3IaI10COM6csIAQdV0BbQvA== X-Received: by 2002:a17:902:fe90:: with SMTP id x16mr11549082plm.295.1587067245627; Thu, 16 Apr 2020 13:00:45 -0700 (PDT) Received: from localhost.localdomain ([2001:470:b:9c3:9e5c:8eff:fe4f:f2d0]) by smtp.gmail.com with ESMTPSA id a13sm3322899pjq.0.2020.04.16.13.00.43 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Apr 2020 13:00:43 -0700 (PDT) Subject: [PATCH v20 QEMU 3/5] virtio-balloon: Implement support for page poison tracking feature From: Alexander Duyck To: david@redhat.com, mst@redhat.com Date: Thu, 16 Apr 2020 13:00:42 -0700 Message-ID: <20200416200042.13144.65487.stgit@localhost.localdomain> In-Reply-To: <20200416195641.13144.16955.stgit@localhost.localdomain> References: <20200416195641.13144.16955.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::644 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 | 27 +++++++++++++++++++++++++++ include/hw/virtio/virtio-balloon.h | 1 + 2 files changed, 28 insertions(+) diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c index a1d6fb52c876..19d587fd05cb 100644 --- a/hw/virtio/virtio-balloon.c +++ b/hw/virtio/virtio-balloon.c @@ -531,6 +531,23 @@ 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 at some point in the future the implementation is changed in the + * guest we would still have issues as the poison would need to be + * applied to the last state of the page on the remote end. + * + * To do that we could improve upon this current implementation by + * migrating a poison/zero page if the page is flagged as dirty instead + * of simply skipping it. + */ + if (virtio_vdev_has_feature(vdev, VIRTIO_BALLOON_F_PAGE_POISON)) { + return; + } + if (s->free_page_hint_cmd_id == UINT_MAX) { s->free_page_hint_cmd_id = VIRTIO_BALLOON_FREE_PAGE_HINT_CMD_ID_MIN; @@ -634,6 +651,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_hint_status == FREE_PAGE_HINT_S_REQUESTED) { config.free_page_hint_cmd_id = @@ -697,6 +715,10 @@ 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 = 0; + if (virtio_vdev_has_feature(vdev, VIRTIO_BALLOON_F_PAGE_POISON)) { + dev->poison_val = le32_to_cpu(config.poison_val); + } trace_virtio_balloon_set_config(dev->actual, oldactual); } @@ -706,6 +728,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 +879,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) diff --git a/include/hw/virtio/virtio-balloon.h b/include/hw/virtio/virtio-balloon.h index 108cff97e71a..3ca2a78e1aca 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 Thu Apr 16 20:00:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Duyck X-Patchwork-Id: 11493707 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 85310112C for ; Thu, 16 Apr 2020 20:03: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 5ABEF21744 for ; Thu, 16 Apr 2020 20:03:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Wcmo2bGD" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5ABEF21744 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]:38802 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jPAjG-0000Vw-IV for patchwork-qemu-devel@patchwork.kernel.org; Thu, 16 Apr 2020 16:03:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56198) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jPAgw-0005Dw-PR for qemu-devel@nongnu.org; Thu, 16 Apr 2020 16:00:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jPAgv-0000Xf-PL for qemu-devel@nongnu.org; Thu, 16 Apr 2020 16:00:54 -0400 Received: from mail-pj1-x1043.google.com ([2607:f8b0:4864:20::1043]:38760) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jPAgv-0000XC-K5 for qemu-devel@nongnu.org; Thu, 16 Apr 2020 16:00:53 -0400 Received: by mail-pj1-x1043.google.com with SMTP id t40so16301pjb.3 for ; Thu, 16 Apr 2020 13:00:53 -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=r3DmuhsjF9XmFz6gfXOOjELEtTu/H+9BPOkgH77BTws=; b=Wcmo2bGDRfYyuyx3/biHMzNBTnu/PnaHkxYNbXZoICZCvWykxFP/K+yBYlVu9MtCB/ sLkM6KCEz3PL2Zg1O4znelGyb+OO97Cl+6fqP09ZWwFXzKdx+Hs2tq6GX7o888IlTY8X 5v66EWCuhaKUhYkRHflW2kgmnIQsBAestGiHCxO+vnWtg3QRHnLl0yv09pQ7Rh7yXEYV 45tzdqNVAcczLJ8OoytIbFqKnbYDsrDeqc256OUav8UDjmMLD6Nw9ehV7RmDymRdhdh/ UP5jjru2CJV2rWWz90NC5mBIDtVcGxbQKEoXPzGc+az2IioMMPsuh8BamLIC7vddrTUR Rs1Q== 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=r3DmuhsjF9XmFz6gfXOOjELEtTu/H+9BPOkgH77BTws=; b=TT0dEK8YfpMw4EgPgepXoJ0YlWiRTSXmRlCA0FAnLaGAjGrHuP/Yi4hpN3D1i0Weyg J+dqVu+rfK0DIiHfXxAEylG+f3Frk9+QlAMtyHzeFt/IYXFtP1hYf8YIzsh8UwuU5iRm XVtCgLacpTd0HQdLjpzqloHJnM6h/ErY5eGGKEOQb7pvu/DesakzvY4aKqQc+iOrqV+w NUbdJWBxpJfTW+Bgrpx96bG31QlnOmJxqAYviXB+7vn/IGbnCTxC8GXy6gVbmuhJ7IRw 4nmC2N+eCyVWtcCWXPbMfomJsZozpxFTxUe3mNiM/waHBcVTZYBZ2S5/XYeUBKcSKCb8 UArA== X-Gm-Message-State: AGi0Pub2z86lWoUWaUe7Xvi1GWjg3sU7kGMvRC8+/nvxkJdIMoX7jHpp ucTFoD92tmR1XIlrlTOx/1I= X-Google-Smtp-Source: APiQypKvu/3yOwqBwVnNGv02T768Dk7ssWCngb0wDVNPDVqntE1FdSwg67MCXhysGAP4J9k+UXBSwg== X-Received: by 2002:a17:902:5999:: with SMTP id p25mr11795750pli.189.1587067252412; Thu, 16 Apr 2020 13:00:52 -0700 (PDT) Received: from localhost.localdomain ([2001:470:b:9c3:9e5c:8eff:fe4f:f2d0]) by smtp.gmail.com with ESMTPSA id q9sm14044947pgt.32.2020.04.16.13.00.51 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Apr 2020 13:00:51 -0700 (PDT) Subject: [PATCH v20 QEMU 4/5] linux-headers: update to contain virito-balloon free page reporting From: Alexander Duyck To: david@redhat.com, mst@redhat.com Date: Thu, 16 Apr 2020 13:00:50 -0700 Message-ID: <20200416200050.13144.98116.stgit@localhost.localdomain> In-Reply-To: <20200416195641.13144.16955.stgit@localhost.localdomain> References: <20200416195641.13144.16955.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::1043 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 Sync the latest upstream changes for free page reporting. To be replaced by a full linux header sync. 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 af0a6b59dab2..af3b7a1fa263 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 Thu Apr 16 20:00:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Duyck X-Patchwork-Id: 11493709 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 C125892C for ; Thu, 16 Apr 2020 20:05:16 +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 96A0E21744 for ; Thu, 16 Apr 2020 20:05:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lWWqMMA1" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 96A0E21744 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]:38822 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jPAl9-0002O8-JY for patchwork-qemu-devel@patchwork.kernel.org; Thu, 16 Apr 2020 16:05:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56244) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jPAh5-0005N4-6o for qemu-devel@nongnu.org; Thu, 16 Apr 2020 16:01:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jPAh2-0000cH-US for qemu-devel@nongnu.org; Thu, 16 Apr 2020 16:01:03 -0400 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]:43030) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jPAh2-0000br-OK for qemu-devel@nongnu.org; Thu, 16 Apr 2020 16:01:00 -0400 Received: by mail-pg1-x541.google.com with SMTP id x26so2137581pgc.10 for ; Thu, 16 Apr 2020 13:00:59 -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=s+fZu2aO6tRXGmFNo6N7uZIK/R7mB4CPuTQRSWKo/zg=; b=lWWqMMA1I7Mjqpa+uTjluq+QbpupvV8b7x1rcPg9DPRlCLdvz7DsMFlsd17EGsuhtf 7bE7GaCodnWbKgW+H5SDz6tuqtYglU13xboPWTxqM5lHiVYA6iVdvw5eKp6bAx1Er6MD 8WiZRcmPaEhSARKbCaLFbIbT+L7aSw0ZsoM++P1KxiznEyhBy/SK+c6ZoEQx0kxTfJLW 99JHN6LKcHi83eNv4cHJc6ySYd2XsgwSm8bjYDBNit3rvrc+6UtpFyyjuRQdOi2sGh1C dGDqYgOweXHdubnPa55XE5uGpiAiFoEeBAgA6xV1bw3FuZwkhedmbJ+VvEZ+6NSMAPgG JJkg== 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=s+fZu2aO6tRXGmFNo6N7uZIK/R7mB4CPuTQRSWKo/zg=; b=RgLYVWSYZrBe8c9xBUOrpxHj1xyCoQ5pqSgryjq3wxilo5axxe03YDVUqQx0LXTsl0 MTQGid8dp/wTK33dK2t/FGtnkDfFlFoxyADR2LoYHsRdvzAsizWcX0snC/dSQjIOchZl 2u2LckVlvSbzfjsVzD80JjsM7Rw0AbmoBNG+wqqFMUKzyGwuVrgPH1/u7XrmzNErHJ3g dw4S9UG63eYMB7/j9S5DBpuUBc0cbZa6okkfjed71ZX769tN5N5XwTxCX3IZAQnZ3GPC N3owRkMNWMZiIe44vaJXNPybqK0eQGGg1TGL1xU/szgIiovbq06VlnUpLXu1NvX92d+J Rt2A== X-Gm-Message-State: AGi0PuY5ZdVhSMCV60ZUuVBimEcnwyOIYGGlSOTCxKb+WQVMlQXDE4ec 0i+g/4nQmNS+LNLachlfYKw= X-Google-Smtp-Source: APiQypKp80LJqYRtWhN9gvIHqT4UZ7J2TAp+fDrnH0c7x/W1TSwHeNuKzA09cTFOWP7QbBA55VZzzg== X-Received: by 2002:a65:530b:: with SMTP id m11mr12882427pgq.338.1587067258819; Thu, 16 Apr 2020 13:00:58 -0700 (PDT) Received: from localhost.localdomain ([2001:470:b:9c3:9e5c:8eff:fe4f:f2d0]) by smtp.gmail.com with ESMTPSA id x16sm3834761pfc.61.2020.04.16.13.00.58 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Apr 2020 13:00:58 -0700 (PDT) Subject: [PATCH v20 QEMU 5/5] virtio-balloon: Provide an interface for free page reporting From: Alexander Duyck To: david@redhat.com, mst@redhat.com Date: Thu, 16 Apr 2020 13:00:57 -0700 Message-ID: <20200416200057.13144.75507.stgit@localhost.localdomain> In-Reply-To: <20200416195641.13144.16955.stgit@localhost.localdomain> References: <20200416195641.13144.16955.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 free page reporting. 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 provides a new way of letting the guest proactively report free pages to the hypervisor, so the hypervisor can reuse them. In contrast to inflate/deflate that is triggered via the hypervisor explicitly. Signed-off-by: Alexander Duyck --- hw/virtio/virtio-balloon.c | 62 +++++++++++++++++++++++++++++++++++- include/hw/virtio/virtio-balloon.h | 2 + 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c index 19d587fd05cb..e5c9317921a1 100644 --- a/hw/virtio/virtio-balloon.c +++ b/hw/virtio/virtio-balloon.c @@ -321,6 +321,59 @@ 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; + + if (qemu_balloon_is_inhibited() || dev->poison_val) { + continue; + } + + 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; + RAMBlock *rb; + + /* + * There is no need to check the memory section to see if + * it is ram/readonly/romd like there is for handle_output + * below. If the region is not meant to be written to then + * address_space_map will have allocated a bounce buffer + * and it will be freed in address_space_unmap and trigger + * and unassigned_mem_write before failing to copy over the + * buffer. If more than one bad descriptor is provided it + * will return NULL after the first bounce buffer and fail + * to map any resources. + */ + rb = qemu_ram_block_from_host(addr, false, &ram_offset); + if (!rb) { + trace_virtio_balloon_bad_addr(elem->in_addr[i]); + continue; + } + + /* + * For now we will simply ignore unaligned memory regions, or + * regions that overrun the end of the RAMBlock. + */ + if (!QEMU_IS_ALIGNED(ram_offset | size, qemu_ram_pagesize(rb)) || + (ram_offset + size) > qemu_ram_get_used_length(rb)) { + 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); @@ -728,7 +781,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); } @@ -818,6 +872,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, @@ -949,6 +1007,8 @@ static Property virtio_balloon_properties[] = { */ DEFINE_PROP_BOOL("qemu-4-0-config-size", VirtIOBalloon, qemu_4_0_config_size, false), + DEFINE_PROP_BIT("free-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 3ca2a78e1aca..ac4013d51010 100644 --- a/include/hw/virtio/virtio-balloon.h +++ b/include/hw/virtio/virtio-balloon.h @@ -42,7 +42,7 @@ enum virtio_balloon_free_page_hint_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_hint_status; uint32_t num_pages; uint32_t actual;