From patchwork Fri Apr 10 03:41: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: 11482717 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 DFE8D913 for ; Fri, 10 Apr 2020 03:44:58 +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 B468320936 for ; Fri, 10 Apr 2020 03:44:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VTX47Ykc" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B468320936 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]:58216 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jMkbB-00071c-Uv for patchwork-qemu-devel@patchwork.kernel.org; Thu, 09 Apr 2020 23:44:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47714) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jMkXt-0001Ec-Si for qemu-devel@nongnu.org; Thu, 09 Apr 2020 23:41:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jMkXs-0007lU-NL for qemu-devel@nongnu.org; Thu, 09 Apr 2020 23:41:33 -0400 Received: from mail-qk1-x742.google.com ([2607:f8b0:4864:20::742]:41735) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jMkXs-0007ke-HM for qemu-devel@nongnu.org; Thu, 09 Apr 2020 23:41:32 -0400 Received: by mail-qk1-x742.google.com with SMTP id y3so1023802qky.8 for ; Thu, 09 Apr 2020 20:41: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=IZT5rQBEFmVBhwL98g+uKrEBfh0eqMpZVWez4s0eHKU=; b=VTX47Ykcrok+3feVdmvHYEHy8ay0S/Rs4i8qGeK+J1z9ha4RXX5/a8Wzykj9K/JSci KEcGJfoRyQf77TKGoYLXmjqGWZuV4cz7h+zz25oRJ38G5c2YP/oLnog2znL08o4wBfWn rJDdFMoY60L4E2IdZH2Td2fjk6vKHE5Ae7GNRJ1r6baaFgM+V/nxDB+hjMqRHzSnkqdu 7Ojk+f4HcYFUODQdvX7KClU6yiRnFE9MNF4ol6uKmFQE1B8hfv68wvVqWCXar6KQrz1C 3osg8mv42TZZolETnRbRkEFlk1YxWYyBo+zC4yLyEq+JUVd+6HEZkXuhzw3wCpgEf9Tj 8Xqg== 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=V9KUJAUVMsVqgL8wptKYr5XE8mYibLQS7XkbXW86tNMGZgoXM4/e/tQvTE+w28JLJ5 I+tNGi8StxL+tF9MPGD8+tag6949bfVG3KpqL03zhPqIdzd8ju6TT57TZNFL+ipAYzdK xC9/O1YCt8KScgsrtz9ZQhdnso879fYC3Lm66bh7BqHqNjl/0d7WRzQZBacy/zUV0kFi i+1VQim4w8hiRuqDOVis+EpVlSKyr6LTJLGEK6XwISCMwWyn3iSC6tTZ9yrjRvDVADRP FkUVVbNQNfSUGCdNgjh/MrhenuA1Tj4MksjZzcWgBrjhkKT/0J4Hi4bytKIRIcwjAyCS n4iw== X-Gm-Message-State: AGi0PuZxbXm9+cX5Cis7Ookz+xZzZF9XD69pz4bk8hKnw1CXiFp/N0hX A4+P+HOYGafNpKq+y1Nk7lDnZqniY54= X-Google-Smtp-Source: APiQypJbKhJxFUGefJZxWFDkQo7thGRq2yoFtNOTDl213jp8Nff/rfJ6q4XTW6QZRDEWPdx95jN1CA== X-Received: by 2002:a37:4117:: with SMTP id o23mr2176105qka.295.1586490091219; Thu, 09 Apr 2020 20:41:31 -0700 (PDT) Received: from localhost.localdomain ([2001:470:b:9c3:9e5c:8eff:fe4f:f2d0]) by smtp.gmail.com with ESMTPSA id o18sm708422qkk.52.2020.04.09.20.41.30 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Apr 2020 20:41:30 -0700 (PDT) Subject: [PATCH v19 QEMU 1/4] virtio-balloon: Implement support for page poison tracking feature From: Alexander Duyck To: pbonzini@redhat.com, david@redhat.com, mst@redhat.com Date: Thu, 09 Apr 2020 20:41:29 -0700 Message-ID: <20200410034129.24738.36022.stgit@localhost.localdomain> In-Reply-To: <20200410033729.24738.22879.stgit@localhost.localdomain> References: <20200410033729.24738.22879.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::742 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