Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp302872ybi; Thu, 1 Aug 2019 19:26:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqyb/lNFnYAPzdQKV993bm9FHSGv8AHn+0iK6VU79A5jsDyj+NqdBoRX7sPhwh39H582Izkt X-Received: by 2002:ae9:edc1:: with SMTP id c184mr84469912qkg.418.1564712786163; Thu, 01 Aug 2019 19:26:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564712786; cv=none; d=google.com; s=arc-20160816; b=HTtfSZZI11uI5pue663kgvGBAFpPdwXl4hAKEbfY8TAJARINZ3+RXBedhamyQBSTqG e3AAToF/3l51V5047Qyz8uhTckediFJcjzRLWRvYBgO/4al0r+1RqQsNOOpm7r/9m3Vr f878WTBbVBFjwvIZIuZNZ8kTU2c39rINUzDkY8GmqW0IbD5Xgeda+TP2pFafwGoRV+rz FYCkJdAY5HQwuPl9RHyjP/fmU1bZOQM0zSB7XlE8qbOsJMwsgX/ULKRvQ04t+EKD3UxV /OZQvCjA/cLmOH5pLGmVlakS8S3huFhuU3fvXk5rA25KrhNT0Vvdem4RgAxmA7RaBwfB B0fA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:dkim-signature; bh=a/jqoVnZMS4gCQHlsNMs0Wm0i9/bhDBfzuCMndLKGiI=; b=M18eoq6zS89NaI0wTT90z48AxiULTIq7JOdb16Ozpn22YRRs56AAQFPVDfRFoSS8tw HW9FCEw9SitN40o+rIfIgWc8LG1oxI0sOCxHAehenB3IqgleH+WoEZGKU5ezYN2/JLdx l6vzdzgLVy900S4NDjidD/i3CWXqXON9SL0kEX3lmK0OLcdoPxjPqCIjOwdf/r66xyPK LmXGYoSuXeDIi0R2GgjbCFCu31Em8iLZU3RScFXhYEJwuWYj9kpDqJVnPKf9abO3C8T2 JS7eUdWyGrKUF81TGQkgPLM6pvLkTYph4MEG1nbaJIXvmkLzkW/A5UFo4hCn7nekxfvi /5/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=NZxJbecw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v35si42946786qtj.81.2019.08.01.19.26.12; Thu, 01 Aug 2019 19:26:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=NZxJbecw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389931AbfHAWnS (ORCPT + 99 others); Thu, 1 Aug 2019 18:43:18 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:35307 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389922AbfHAWnR (ORCPT ); Thu, 1 Aug 2019 18:43:17 -0400 Received: by mail-pf1-f194.google.com with SMTP id u14so34904425pfn.2; Thu, 01 Aug 2019 15:43:16 -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=a/jqoVnZMS4gCQHlsNMs0Wm0i9/bhDBfzuCMndLKGiI=; b=NZxJbecwhsIRKAn7eTc+DEWg5Y73G1yfBpYfTgoTLj8uI430qQIWPf10i2RoOhFOEM K8s8te0tZX6GiAk7J6xt9n53Vx8l2tHByIvKeFp1u6mjdP6+CETi9j1HazLfHNtMc6eH VBQBrLk1u4q/6cvecxbda6RZqN85ILzhHl2209VVRYknXehPkppSaaPPWFvMCqW/ytZ5 ByPdU2snob67LZhf3oPJywHM6b1TJsX9O1t5FRK8sTKgA9nY37Z9fjisjPcfI0O2xEZT pD/i7OGIux0iSaaqYyOJyGgm4y2fH9QVmE0oMxOJhFwZEcJztwOGUuwZtFVjwWKf2tEX Yf6w== 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=a/jqoVnZMS4gCQHlsNMs0Wm0i9/bhDBfzuCMndLKGiI=; b=uO+WmyhQhVSjoHthW3NYIfmvMN6rCSaFRYbH8OK/PT6QXRueiJ+rPXZgb3SoY8g9TW 0fVQ/FfxSAhSCaN6oYSSPb5+08YR/OK66hEshCD3BlLE1v57zF2r3OrbZkQGiP2kbZ8I nN5EkdyXMiNeTtx20dmk5CV6BzhRzLRUeK/r7ZW0cQUjP6AHskK1G1DLYZhRl7cpiEuY 1FLEqAO4zCNn3MhpjH4g13mqdWJoOUbXTOOhNctS5ILnIPLYBjbBUpK7HZFaEgfP00ZZ WDRBF1Ae96FOjXOcfobUzSLwMZzDzo+iK7TtTsLU1gKrMYwVc6TdKaGWv3IF0t7wPwd7 +2TA== X-Gm-Message-State: APjAAAWFtUlHgx7hNMWPK11eXnJ2+QUgfIxHUCFw7+Bcbu6A8Q4lS10c tzUvBPLZ8CR/YqdNCI4r/TU= X-Received: by 2002:a62:ae02:: with SMTP id q2mr54784607pff.1.1564699395583; Thu, 01 Aug 2019 15:43:15 -0700 (PDT) Received: from localhost.localdomain (50-39-177-61.bvtn.or.frontiernet.net. [50.39.177.61]) by smtp.gmail.com with ESMTPSA id b6sm63677178pgq.26.2019.08.01.15.43.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Aug 2019 15:43:15 -0700 (PDT) Subject: [PATCH v3 QEMU 1/2] virtio-ballon: Implement support for page poison tracking feature From: Alexander Duyck To: nitesh@redhat.com, kvm@vger.kernel.org, david@redhat.com, mst@redhat.com, dave.hansen@intel.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, akpm@linux-foundation.org Cc: yang.zhang.wz@gmail.com, pagupta@redhat.com, riel@surriel.com, konrad.wilk@oracle.com, willy@infradead.org, lcapitulino@redhat.com, wei.w.wang@intel.com, aarcange@redhat.com, pbonzini@redhat.com, dan.j.williams@intel.com, alexander.h.duyck@linux.intel.com Date: Thu, 01 Aug 2019 15:41:04 -0700 Message-ID: <20190801224104.24744.18563.stgit@localhost.localdomain> In-Reply-To: <20190801222158.22190.96964.stgit@localhost.localdomain> References: <20190801222158.22190.96964.stgit@localhost.localdomain> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 25de15430710..003b3ebcfdfb 100644 --- a/hw/virtio/virtio-balloon.c +++ b/hw/virtio/virtio-balloon.c @@ -530,6 +530,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; @@ -617,12 +626,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); } @@ -633,6 +640,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 = @@ -696,6 +704,8 @@ 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); } @@ -705,6 +715,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; } @@ -846,6 +859,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) @@ -908,6 +923,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