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 From patchwork Fri Apr 10 03:41:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Duyck X-Patchwork-Id: 11482709 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 23C126CA for ; Fri, 10 Apr 2020 03:42:27 +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 DCD13206DD for ; Fri, 10 Apr 2020 03:42:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bMPmkYeD" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DCD13206DD 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]:58176 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jMkYj-0002lN-W0 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 09 Apr 2020 23:42:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47738) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jMkY1-0001Jh-6W for qemu-devel@nongnu.org; Thu, 09 Apr 2020 23:41:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jMkY0-0007pi-8t for qemu-devel@nongnu.org; Thu, 09 Apr 2020 23:41:41 -0400 Received: from mail-qk1-x743.google.com ([2607:f8b0:4864:20::743]:44473) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jMkY0-0007pJ-4a for qemu-devel@nongnu.org; Thu, 09 Apr 2020 23:41:40 -0400 Received: by mail-qk1-x743.google.com with SMTP id j4so999777qkc.11 for ; Thu, 09 Apr 2020 20:41:39 -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=lZ1k9L4/vo7grjJ1SStQcHrbDBEPT6Fdb+m3NWYJLWQ=; b=bMPmkYeDfxI/O53Y15m08QwjUaGEnfQxFnmDS6/11jflvv6ko9TRsbG58rEMoB6+BA UEZslL0ssQ/WaEuS3p+b4y1o2Hv8LmYiW/fqKe4FyYk0qUXsI22dpGfR/5uwgqgLrWNo oKdA7vbzLejvrYMvGfwfP8bZHMTBhxGov1fuDuPXX9FHubZlo4Cbzz0jQNmjTXTuTcQZ wCnq/MKfZpZS/ORZ3OQuOBQpH2+0b7VIPpNepbu8acF1D7XBK+4X8tDlZzNlfabeQw7h eFVH7r2k3WBUIoSP0gV+FHx4tTqyy5SG1scPs4YPSs/Rj/fTJ5whLRdHakcByNusrfAb jhzQ== 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=lZ1k9L4/vo7grjJ1SStQcHrbDBEPT6Fdb+m3NWYJLWQ=; b=h9nQHHj5QnjeK8Z86zJMxWAnGgtNgx6hJ9gHIxrsrzr04Ea5Ad+BkIzWg0jEbaJCGk N+cSIVE0FlSmBm2Yn1F2Q9negyN0efv/wfUP80kEPUINIvLs3zWfzOPss5yIWfBj57mv QHd12hSdym+8dYAmTrIXVx5R0UpLZ0dtDhJwZFUXwyUgF6oDIJmnTOZ/7kmx+Y8t/fxj V7e6iahIl6rXflJ+rkUELQGSIiUUcV3NDjsrZyct7V2IW6hX9a4GRv/59Db/9NOcULIV 4F1a9CQ1wAA/2pdHryGwzRWfaO2TzULoGDuxekoqzbxqDSCI3KEGHrTN3IyoVXe4L1bs F5VQ== X-Gm-Message-State: AGi0PuaoDsMD7TQoNz0MhxSkdN5dmoamJcjoBpClpmURtDkd1gXuxmXv oucogyrz5IA0G/eP/C3p7s4b3sq60os= X-Google-Smtp-Source: APiQypIXPuhGMK4aU6UJW6jMUHSDHyM1J592zRULTpFxhR6Pwof3dIgfINnJ4+WwOhNeZijhhnR/HQ== X-Received: by 2002:a37:62d7:: with SMTP id w206mr2077384qkb.406.1586490098342; Thu, 09 Apr 2020 20:41:38 -0700 (PDT) Received: from localhost.localdomain ([2001:470:b:9c3:9e5c:8eff:fe4f:f2d0]) by smtp.gmail.com with ESMTPSA id h11sm709573qtr.38.2020.04.09.20.41.37 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Apr 2020 20:41:37 -0700 (PDT) Subject: [PATCH v19 QEMU 2/4] linux-headers: update to contain virito-balloon free page reporting From: Alexander Duyck To: pbonzini@redhat.com, david@redhat.com, mst@redhat.com Date: Thu, 09 Apr 2020 20:41:36 -0700 Message-ID: <20200410034136.24738.52188.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::743 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 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 Fri Apr 10 03:41:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Duyck X-Patchwork-Id: 11482711 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 D656692C for ; Fri, 10 Apr 2020 03:42:37 +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 AA6092082D for ; Fri, 10 Apr 2020 03:42:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ISc143uM" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AA6092082D 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]:58182 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jMkYu-0003Dx-Q0 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 09 Apr 2020 23:42:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47816) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jMkY7-0001Qd-Gm for qemu-devel@nongnu.org; Thu, 09 Apr 2020 23:41:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jMkY6-0007tH-6r for qemu-devel@nongnu.org; Thu, 09 Apr 2020 23:41:47 -0400 Received: from mail-qv1-xf42.google.com ([2607:f8b0:4864:20::f42]:43740) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jMkY6-0007tA-2C for qemu-devel@nongnu.org; Thu, 09 Apr 2020 23:41:46 -0400 Received: by mail-qv1-xf42.google.com with SMTP id w26so418161qvd.10 for ; Thu, 09 Apr 2020 20:41: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=VkROvCgm5mN7+wKVn1WvkxoHIcp7705QcSzcumM/77U=; b=ISc143uM/ga32qp3ovR6UzCUshCKaA0mBjjDNdkCju7rwK1K2fZbDJjOWIgD8/rV7J gvO52e7W/kr7xAeTDUCRErYaJlrZTnMZIFxYptnbdWvB+MDXWvXDd12DTBhSo4OE0flX xq97WlnkTn1wboUDHgpjCGP/zd7q1ZfHn3UCMejt1DHdPMPUl3iRx2k+6t/TIueATse6 j5JhCx+LK1a2GupiCVuF80p+nTi0hALTttvkwjFDA7fM9rr2PBfJJTz9RnnGHWLXeGZw YKejpMXsoPgV1gug5pAiPNmTGNUd3OUXihsctQpJ6hivhF0yo+0RGiQnb8IetHwVSnXW syvA== 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=VkROvCgm5mN7+wKVn1WvkxoHIcp7705QcSzcumM/77U=; b=ifVLc8I9fCFP8AwyjF5Tf53/XwUyYv5PrNduSYzteMPQ4UKdQRNrOxTYXQ2s3xcite oNmoDqAHMHUtLLDeOQre+Ztewh69C+PF5uy5vaB6tfkh5zE/AkMmjIHtRVx8ZBgdzr5N lLRu8UlM7NzGX6QCkh1tUnEymDnDdlVLF2SBxqDhkCHCWQlWnyWVheXszZtftaICoCT3 IXWkH6nhJ0dPRRWScEXPWrVRM9C2STDA+1qZ18NELUXQpW4wflpxBYqXgCp73C7bgti5 c7xknOXWn3r4SnH5MYRbwAuT+ilcsSBfCS1IuNNcKXBNkKz7n4dMkAjkBVCbVQnJla2t FPNA== X-Gm-Message-State: AGi0Pua53y3W6sMwxEC+G758Mv8zwMZYkLpSJfgj7BpGMRtMtCcCXraE lKJp6ysCFBAtsL18kChQ8ancZr7e3/k= X-Google-Smtp-Source: APiQypJacHOkOh+e3nkYmp7fHoEVrchfHBgzoPPxyKoplIYyKnOSI6c9Nl9xYdo7Y/L03J2R2hRrsg== X-Received: by 2002:ad4:4e6a:: with SMTP id ec10mr3465375qvb.204.1586490105160; Thu, 09 Apr 2020 20:41:45 -0700 (PDT) Received: from localhost.localdomain ([2001:470:b:9c3:9e5c:8eff:fe4f:f2d0]) by smtp.gmail.com with ESMTPSA id f68sm695131qtb.19.2020.04.09.20.41.44 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Apr 2020 20:41:44 -0700 (PDT) Subject: [PATCH v19 QEMU 3/4] virtio-balloon: Provide an interface for free page reporting From: Alexander Duyck To: pbonzini@redhat.com, david@redhat.com, mst@redhat.com Date: Thu, 09 Apr 2020 20:41:43 -0700 Message-ID: <20200410034143.24738.78852.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::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+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 | 63 +++++++++++++++++++++++++++++++++++- include/hw/virtio/virtio-balloon.h | 2 + 2 files changed, 62 insertions(+), 3 deletions(-) diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c index 1c6d36a29a04..86d8b48a8e3a 100644 --- a/hw/virtio/virtio-balloon.c +++ b/hw/virtio/virtio-balloon.c @@ -321,6 +321,57 @@ 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; + } + + /* + * 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 */ + rb_page_size = qemu_ram_pagesize(rb); + if (!QEMU_IS_ALIGNED(ram_offset | size, rb_page_size)) { + 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 +679,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 +769,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 +860,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 +997,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 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; From patchwork Fri Apr 10 03:41: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: 11482713 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 D97121392 for ; Fri, 10 Apr 2020 03:42:37 +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 A9A11206DD for ; Fri, 10 Apr 2020 03:42:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aa7zJ2Fi" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A9A11206DD 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]:58180 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jMkYu-0003D9-GZ for patchwork-qemu-devel@patchwork.kernel.org; Thu, 09 Apr 2020 23:42:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47836) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jMkYE-0001dD-1Y for qemu-devel@nongnu.org; Thu, 09 Apr 2020 23:41:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jMkYD-0007w0-04 for qemu-devel@nongnu.org; Thu, 09 Apr 2020 23:41:53 -0400 Received: from mail-qv1-xf42.google.com ([2607:f8b0:4864:20::f42]:35059) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jMkYC-0007vn-S3 for qemu-devel@nongnu.org; Thu, 09 Apr 2020 23:41:52 -0400 Received: by mail-qv1-xf42.google.com with SMTP id q73so444197qvq.2 for ; Thu, 09 Apr 2020 20:41:52 -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=F6qfRA9Zsk5PQPX5NBdmVChOrunOXGYYK7OugFpAebY=; b=aa7zJ2Fi2mXZEEyWeiG4y/CMjIJpfclxqnDw7qWm39zDwF/tTHNWb9Fm4/otfsrc9c uxOvomv4FK7udCvyXkSgOkrV5HLko1JnScSTPmb72EGXf0NIkpRSbxedBGlpkjPvV9Jk tWAssqihOWAgUyFKSxxmXOCRJgPoWlRpFZUiIHT0oAeQz8XEeKedcze57KwGyDPvI0kU LB+EdD81vCDF15WHQwzaSsneWXSIS71F1vWx9ldyN/K42NNFRAMVceFXX5aAsLOyyd5R 5qal+auYiFvNr5gs2+QbT146DX2TD0uyF2TGHKUs3BJhKjV3/0KxKnkgSSjQwbSQkDoi 8ZqA== 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=F6qfRA9Zsk5PQPX5NBdmVChOrunOXGYYK7OugFpAebY=; b=Uv2LCyOYMtzOEys4G/aJLRtTSbgkwqOm9FHaMF9V2Js7sDPFQF+eIm+8ZmvcEy3Bc2 fu+WXz1a7EV9mKzow1iIxwcUU7mdWPw+EMpjgJt0SK0omd1wqUxhEeeUt1E0VoYZoHhI lSmj/7c5OUsBubu/Lxh/b8q+Z9m+bCQEum5od0Ps/4eOzGLq7e7M4+GP2PndVafDmioa ll0XFsds4XB8Ftb3iZXQsT5sYGys7HxEce7Ny+GaMybuXifjyzNJfldd9PGLrgOs42rW RXVTY/zecTgGnxOP90NQNASPQghI8sDdfvTC6xFSW+KDn+EHn3n+4GPa2HEGyYEb0LeG d78g== X-Gm-Message-State: AGi0PubG72/H29GvTGWRkZZblR0CXP1Ke0//s06jTgMQtBjQ//UaIzYq ByQIIVRxOiCo9dOyP96pPSVoqh9NEzg= X-Google-Smtp-Source: APiQypJDNebDsH2LEr2FtkHUpVTrN3oiMCRvfOsIv4OdflsPtWQdM3kt64IWOp2jn4uTUTL7/rnQ1w== X-Received: by 2002:a0c:f4ca:: with SMTP id o10mr3310777qvm.18.1586490112178; Thu, 09 Apr 2020 20:41:52 -0700 (PDT) Received: from localhost.localdomain ([2001:470:b:9c3:9e5c:8eff:fe4f:f2d0]) by smtp.gmail.com with ESMTPSA id l9sm725784qth.60.2020.04.09.20.41.51 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Apr 2020 20:41:51 -0700 (PDT) Subject: [PATCH v19 QEMU 4/4] memory: Do not allow direct write access to rom_device regions From: Alexander Duyck To: pbonzini@redhat.com, david@redhat.com, mst@redhat.com Date: Thu, 09 Apr 2020 20:41:50 -0700 Message-ID: <20200410034150.24738.98143.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::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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Alexander Duyck According to the documentation in memory.h a ROM memory region will be backed by RAM for reads, but is supposed to go through a callback for writes. Currently we were not checking for the existence of the rom_device flag when determining if we could perform a direct write or not. To correct that add a check to memory_region_is_direct so that if the memory region has the rom_device flag set we will return false for all checks where is_write is set. Signed-off-by: Alexander Duyck --- include/exec/memory.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index 1614d9a02c0c..e000bd2f97b2 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -2351,8 +2351,8 @@ void address_space_write_cached_slow(MemoryRegionCache *cache, static inline bool memory_access_is_direct(MemoryRegion *mr, bool is_write) { if (is_write) { - return memory_region_is_ram(mr) && - !mr->readonly && !memory_region_is_ram_device(mr); + return memory_region_is_ram(mr) && !mr->readonly && + !mr->rom_device && !memory_region_is_ram_device(mr); } else { return (memory_region_is_ram(mr) && !memory_region_is_ram_device(mr)) || memory_region_is_romd(mr);