From nobody Mon Feb 9 01:16:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600964857; cv=none; d=zohomail.com; s=zohoarc; b=F78uMTgYjGN+tJdKwzepKMQck0U+RtTAlSAcQqXsvx7ylsVJvyc0514X0NkEenfxcyCzryLmW4MIaubC035izXOQy0nAgIaHpEizdn1hOnZRN9bxNIdK5bZAzY54wwaPSBZPFI1mwC20uzXWEdXD1nnexsq2P8ZpZifJxF1juDA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600964857; 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=AH8IYQbb3ay9Cjv/MkGhbM86WcU24pssD37+05te6Zg=; b=XCdPTfSAfOzTEgzBccDzEnujH/gkbBm3Kop33txDJBLxhrhYKrsn51mD/7ogFDRPmcVIs5PPbsB9N5DjSSkZsgjp9qWRlLNi2lRE2VhGlAe/ypmajSTU7BQrCP1SUxeUBmtcMAHrt8/t5jUAIQzrLtelomwzEbz/Gu8BJHojInI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail 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 1600964857574813.8884696530283; Thu, 24 Sep 2020 09:27:37 -0700 (PDT) Received: from localhost ([::1]:55516 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kLU5o-0004s7-Az for importer@patchew.org; Thu, 24 Sep 2020 12:27:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57664) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kLTlB-0003PY-8Y for qemu-devel@nongnu.org; Thu, 24 Sep 2020 12:06:17 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:36699) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kLTl1-00046t-RK for qemu-devel@nongnu.org; Thu, 24 Sep 2020 12:06:16 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-21-ydXYsntHOt-q1VhWHPH5Kw-1; Thu, 24 Sep 2020 12:06:00 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1C7DB801E53; Thu, 24 Sep 2020 16:05:59 +0000 (UTC) Received: from t480s.redhat.com (ovpn-114-4.ams2.redhat.com [10.36.114.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 70EF61A4D7; Thu, 24 Sep 2020 16:05:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600963567; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AH8IYQbb3ay9Cjv/MkGhbM86WcU24pssD37+05te6Zg=; b=axxWIf89I2Z2dPI+ZoAtfNdjckBFPfHntBJdqVI2Oio+D+KeNcIQi/0wV5R80E+++3/Bw5 m9tKkDHpXog+/tm/wjGMopGJJ2JU5V6Zy7Ekk31u3QKIYUeUnpcfnuOB1B9ERW7s6iqqEu cPyFgb2c5UlI5eAfxb0UBifNrGSG3ok= X-MC-Unique: ydXYsntHOt-q1VhWHPH5Kw-1 From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH PROTOTYPE 6/6] vfio: Disable only RAM_BLOCK_DISCARD_T_UNCOORDINATED discards Date: Thu, 24 Sep 2020 18:04:23 +0200 Message-Id: <20200924160423.106747-7-david@redhat.com> In-Reply-To: <20200924160423.106747-1-david@redhat.com> References: <20200924160423.106747-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=david@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=216.205.24.124; envelope-from=david@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 23:02:20 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -32 X-Spam_score: -3.3 X-Spam_bar: --- X-Spam_report: (-3.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.199, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: Pankaj Gupta , David Hildenbrand , "Michael S. Tsirkin" , "Dr . David Alan Gilbert" , Peter Xu , Luiz Capitulino , Auger Eric , Alex Williamson , Wei Yang , Igor Mammedov , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This unlocks virtio-mem with vfio. A virtio-mem device properly notifies about all accessible/mapped blocks inside a managed memory region - whenever blocks become accessible and whenever blocks become inaccessible. Note: The block size of a virtio-mem device has to be set to sane sizes, depending on the maximum hotplug size - to not run out of vfio mappings. The default virtio-mem block size is usually in the range of a couple of MBs. Linux kernels (x86-64) don't support block sizes > 128MB with an initial memory size of < 64 MB - and above that only in some cases 2GB. The larger the blocks, the less likely that a lot of memory can get unplugged again. The smaller the blocks, the slower memory hot(un)plug will be. Assume you want to hotplug 256GB - the block size would have to be at least 8 MB (resulting in 32768 distinct mappings). It's expected that the block size will be comparatively large when virtio-mem is used with vfio in the future (e.g., 128MB, 1G, 2G) - something Linux guests will have to be optimized for. Cc: Paolo Bonzini Cc: "Michael S. Tsirkin" Cc: Alex Williamson Cc: Wei Yang Cc: Dr. David Alan Gilbert Cc: Igor Mammedov Cc: Pankaj Gupta Cc: Peter Xu Signed-off-by: David Hildenbrand --- hw/vfio/common.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index a3aaf70dd8..4d82296967 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -1392,8 +1392,12 @@ static int vfio_connect_container(VFIOGroup *group, = AddressSpace *as, * new memory, it will not yet set ram_block_discard_set_required() and * therefore, neither stops us here or deals with the sudden memory * consumption of inflated memory. + * + * We do support discarding for memory regions where accessible pieces + * are coordinated via the SparseRAMNotifier. */ - ret =3D ram_block_discard_disable(true); + ret =3D ram_block_discard_type_disable(RAM_BLOCK_DISCARD_T_UNCOORDINAT= ED, + true); if (ret) { error_setg_errno(errp, -ret, "Cannot set discarding of RAM broken"= ); return ret; @@ -1564,7 +1568,7 @@ close_fd_exit: close(fd); =20 put_space_exit: - ram_block_discard_disable(false); + ram_block_discard_type_disable(RAM_BLOCK_DISCARD_T_UNCOORDINATED, fals= e); vfio_put_address_space(space); =20 return ret; @@ -1686,7 +1690,8 @@ void vfio_put_group(VFIOGroup *group) } =20 if (!group->ram_block_discard_allowed) { - ram_block_discard_disable(false); + ram_block_discard_type_disable(RAM_BLOCK_DISCARD_T_UNCOORDINATED, + false); } vfio_kvm_device_del_group(group); vfio_disconnect_container(group); @@ -1740,7 +1745,8 @@ int vfio_get_device(VFIOGroup *group, const char *nam= e, =20 if (!group->ram_block_discard_allowed) { group->ram_block_discard_allowed =3D true; - ram_block_discard_disable(false); + ram_block_discard_type_disable(RAM_BLOCK_DISCARD_T_UNCOORDINAT= ED, + false); } } =20 --=20 2.26.2