From nobody Sun May 19 09:42:11 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1586490309; cv=none; d=zohomail.com; s=zohoarc; b=iEnhr/E2qt9mO1gVC1rZUF2RRZFvwAhk3dXwqE3CBToOrl4gOLGENTX4dGLeeMxyBVLV4OlPvcohlkWVJB6pKY4TNPotSdeWWB3vydMEy4xwG97gJ5oN2aGZyLBPWaXc1Y1oJmr6ZMDzuSxDYoaCxtuIGz63lL9PnQ8wcN25/o0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1586490309; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=IZT5rQBEFmVBhwL98g+uKrEBfh0eqMpZVWez4s0eHKU=; b=a+SytPg7vfXQdsOkDTcxLwholHeXT2TIK7ZN8rsDuGoH0hTeLscHa488IcoPl5mlDSB5zbNrcm8Mfih0UnxVmKoZs3SJAkm+wC4DejPUltlBZ0Pxkl66xkV5eJH8qRZZ9/UW62Yfto/0GPB9LhhEEuo1ETXcTf9WiAczRoS8N+o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1586490309945138.6833550016246; Thu, 9 Apr 2020 20:45:09 -0700 (PDT) Received: from localhost ([::1]:58216 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jMkbM-00071c-Nk for importer@patchew.org; Thu, 09 Apr 2020 23:45:08 -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) 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) 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) 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) 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(VirtIOBallo= on *s) return; } =20 + /* + * 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 =3D=3D UINT_MAX) { s->free_page_report_cmd_id =3D VIRTIO_BALLOON_FREE_PAGE_REPORT_CMD_ID_MIN; @@ -618,12 +627,10 @@ static size_t virtio_balloon_config_size(VirtIOBalloo= n *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); } =20 @@ -634,6 +641,7 @@ static void virtio_balloon_get_config(VirtIODevice *vde= v, uint8_t *config_data) =20 config.num_pages =3D cpu_to_le32(dev->num_pages); config.actual =3D cpu_to_le32(dev->actual); + config.poison_val =3D cpu_to_le32(dev->poison_val); =20 if (dev->free_page_report_status =3D=3D FREE_PAGE_REPORT_S_REQUESTED) { config.free_page_report_cmd_id =3D @@ -697,6 +705,9 @@ static void virtio_balloon_set_config(VirtIODevice *vde= v, qapi_event_send_balloon_change(vm_ram_size - ((ram_addr_t) dev->actual << VIRTIO_BALLOON_PFN_SH= IFT)); } + dev->poison_val =3D 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); } =20 @@ -706,6 +717,9 @@ static uint64_t virtio_balloon_get_features(VirtIODevic= e *vdev, uint64_t f, VirtIOBalloon *dev =3D VIRTIO_BALLOON(vdev); f |=3D 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); + } =20 return f; } @@ -854,6 +868,8 @@ static void virtio_balloon_device_reset(VirtIODevice *v= dev) g_free(s->stats_vq_elem); s->stats_vq_elem =3D NULL; } + + s->poison_val =3D 0; } =20 static void virtio_balloon_set_status(VirtIODevice *vdev, uint8_t status) @@ -916,6 +932,8 @@ static Property virtio_balloon_properties[] =3D { 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-h= int * 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; =20 bool qemu_4_0_config_size; + uint32_t poison_val; } VirtIOBalloon; =20 #endif From nobody Sun May 19 09:42:11 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1586490168; cv=none; d=zohomail.com; s=zohoarc; b=Rf8AhkEXTx8E3Pw1DMXbCD4ahDseoXqHwNXOCuNEIAOkyg2Jtf//QsWRKXBPbnTWZyG687d/5u+up3gpoRWiJdnnj0t5yJQU8nbhbDWLnOGPIawpjcuzwdNfWaIDQe3TyqY4r0IENyJX5UFFyqRFDF72XVQUs8eyVK3skUDWJqg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1586490168; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=lZ1k9L4/vo7grjJ1SStQcHrbDBEPT6Fdb+m3NWYJLWQ=; b=G2/fARS71MUU6wzY4/9n0805B8J2WUncmnY/Ynbk6zhq24xNbGRsgTKTR6Ue6KJ+c268AOnOtsp9nalg9Tnz635ECX1QcUZPn4ao6Y4+t/KQr2iz6tsUdE0NDRm4xD6IxWDqeiiJFQmubnZs8qGnwmswV2I5t+Vgnoe0dCUXIEY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1586490168049514.3147494549853; Thu, 9 Apr 2020 20:42:48 -0700 (PDT) Received: from localhost ([::1]:58176 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jMkZ4-0002lN-ER for importer@patchew.org; Thu, 09 Apr 2020 23:42:46 -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) 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) 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) 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) 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/stan= dard-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 */ =20 /* Size of a PFN in the balloon interface. */ #define VIRTIO_BALLOON_PFN_SHIFT 12 From nobody Sun May 19 09:42:11 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1586490179; cv=none; d=zohomail.com; s=zohoarc; b=PiPRxDOQJSJCcGJkj6+BBX9PrT5ga69XclLOaevUPyfXJ7cVZG8lfCKrN5HE8S2D4+Ksr3hHX9N538DdAGNqycHsR/ZkHzIu/j75ep0KWs1i8dKHJlIMpziKGf6y0IDc+7DCzDsl2wnBXiXqw9NW1nbQ8iECtDOIzaW+aOmijOw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1586490179; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=VkROvCgm5mN7+wKVn1WvkxoHIcp7705QcSzcumM/77U=; b=lrfgD+OWzVqm9U5w26KPeXx4saSbhLe0xGbm8xhlFwkKlYUOAkRK8l9mTUTLGW7Q7Gfj/Xbw9dvXmiG0Ptb9vmfb4C1QRmZOOj6+hogtA2STcLbPtTarU7sGaUQqRs9OrWFms2B96YnhD2F8pAb2fcSdoUibxpg0zlR8HROi0Wo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1586490179201670.513539394448; Thu, 9 Apr 2020 20:42:59 -0700 (PDT) Received: from localhost ([::1]:58182 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jMkZF-0003Dx-UH for importer@patchew.org; Thu, 09 Apr 2020 23:42:57 -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) 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) 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) 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) 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 *ob= j, Visitor *v, balloon_stats_change_timer(s, 0); } =20 +static void virtio_balloon_handle_report(VirtIODevice *vdev, VirtQueue *vq) +{ + VirtIOBalloon *dev =3D VIRTIO_BALLOON(vdev); + VirtQueueElement *elem; + + while ((elem =3D virtqueue_pop(vq, sizeof(VirtQueueElement)))) { + unsigned int i; + + for (i =3D 0; i < elem->in_num; i++) { + void *addr =3D elem->in_sg[i].iov_base; + size_t size =3D 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 =3D 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 =3D 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 =3D 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(VirtIODevic= e *vdev, uint64_t f, VirtIOBalloon *dev =3D VIRTIO_BALLOON(vdev); f |=3D 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); } =20 @@ -807,6 +860,10 @@ static void virtio_balloon_device_realize(DeviceState = *dev, Error **errp) s->dvq =3D virtio_add_queue(vdev, 128, virtio_balloon_handle_output); s->svq =3D virtio_add_queue(vdev, 128, virtio_balloon_receive_stats); =20 + if (virtio_has_feature(s->host_features, VIRTIO_BALLOON_F_REPORTING)) { + s->rvq =3D 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 =3D virtio_add_queue(vdev, VIRTQUEUE_MAX_SIZE, @@ -940,6 +997,8 @@ static Property virtio_balloon_properties[] =3D { */ 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 { =20 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 nobody Sun May 19 09:42:11 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1586490177; cv=none; d=zohomail.com; s=zohoarc; b=QZ5ua4lBhVAbE5nl53h3aZFiZ1GaRaj0+QjeNYiae1N8rbJDHOtI2XlrKKjKhlBRa7hhr/siQzn0kh0oktdhWmScci/y+M6tWjLts3h0Y5tttTlM2aGiLy/tKdTOGcElk2WMDZpeENTq8Rp05b4IwdNUtVIo9mNc9Q3SqH41Cps= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1586490177; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=F6qfRA9Zsk5PQPX5NBdmVChOrunOXGYYK7OugFpAebY=; b=PEKSDZkccxbGB7/eJicF4u2gWfqpN/5YST/GP170D4kSxSsWL5gkR3wvXv4YlAbf2n1NPCYqBWc8S0SPJ+EAF4ZS3xv9AhayDgFFZlfJ3qKBxnH3dzlqVw2TT1TAfGr7JmiAPm/FOc/L8WGt0q8zd1uYhkQh4slnx5BkS7OJhg0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1586490177774918.4103818627799; Thu, 9 Apr 2020 20:42:57 -0700 (PDT) Received: from localhost ([::1]:58180 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jMkZE-0003D9-9F for importer@patchew.org; Thu, 09 Apr 2020 23:42:56 -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) 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) 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) 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) 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(MemoryRegionCach= e *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(m= r)) || memory_region_is_romd(mr);