From nobody Tue Nov 18 07:20:16 2025 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=1608158980; cv=none; d=zohomail.com; s=zohoarc; b=Sr09Tj8oS/3nhTvxZBJukJqN690CE8PB6pS2isl13OObi+REtSasP/mrsvjZE5Q/V6FkJkHJrAZ4qDjPlPz+pIwaMwZLcMZef6nU0LKwbKorF+5nibs3EwzkXvJUbFIi2nq5iJo1ReX9RdsqOrXQMA2U3RCJ+xuu5AiCjJLF0VM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608158980; 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=Vcu+ud6Jx88YTX9bP9X6wUv3DhVLS/+Y302WetMxVDk=; b=U+HPJvuTSKcDs9z+jRJFIG7ebeE7qVaI0u2ye+onEJnKLavUOCe2VUS0JkbquVVtQVkqTw5frSOftZq+4sBVr6CsOM9RDp5DOIfEQC7PTkvsCCoAlWl4YLe5+IgmYkAYMltPPxXPdCDel9rBGCMvt33ZxWTKBsG4bUGD0fJc+mU= 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 1608158980236168.14197438529789; Wed, 16 Dec 2020 14:49:40 -0800 (PST) Received: from localhost ([::1]:51910 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kpXwW-0004SU-BO for importer@patchew.org; Wed, 16 Dec 2020 09:38:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:46204) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kpXZ5-0002rq-Ui for qemu-devel@nongnu.org; Wed, 16 Dec 2020 09:14:03 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:35423) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kpXZ3-000777-4I for qemu-devel@nongnu.org; Wed, 16 Dec 2020 09:14:03 -0500 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-588-B5hs7VbqMCG_clmvo5X--Q-1; Wed, 16 Dec 2020 09:13:59 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9BCC11927801; Wed, 16 Dec 2020 14:13:57 +0000 (UTC) Received: from t480s.redhat.com (ovpn-115-49.ams2.redhat.com [10.36.115.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id BFDF160C15; Wed, 16 Dec 2020 14:13:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608128040; 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=Vcu+ud6Jx88YTX9bP9X6wUv3DhVLS/+Y302WetMxVDk=; b=VXyTzp5EZSqFHYzu2XW624GyQKS6oZUzMTVd9yI8gzG/YddYL83eHsGCGCeJOl0hZCasSF r1PmXWA2wEfrqKAzd1g6D5Tk/WizZC/7zSlUVDRsytTOjiDu1bUEcWzBNPPD5fylWM7AjU oaCGvzf4SV2KvCcWSIazCvHESlK8BuU= X-MC-Unique: B5hs7VbqMCG_clmvo5X--Q-1 From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH v3 10/10] vfio: Disable only uncoordinated discards Date: Wed, 16 Dec 2020 15:12:00 +0100 Message-Id: <20201216141200.118742-11-david@redhat.com> In-Reply-To: <20201216141200.118742-1-david@redhat.com> References: <20201216141200.118742-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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=63.128.21.124; envelope-from=david@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H4=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: Marek Kedzierski , Pankaj Gupta , Wei Yang , David Hildenbrand , "Michael S. Tsirkin" , Alex Williamson , Peter Xu , "Dr . David Alan Gilbert" , Auger Eric , Pankaj Gupta , teawater , Jonathan Cameron , Paolo Bonzini , Igor Mammedov 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" We support coordinated discarding of RAM using the RamDiscardMgr. Let's unlock support for coordinated discards, keeping uncoordinated discards (e.g., via virtio-balloon) disabled. This unlocks virtio-mem + vfio. Note that vfio used via "nvme://" by the block layer has to be implemented/unlocked separately. For now, virtio-mem only supports x86-64 - spapr IOMMUs are not tested/affected. 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. The maximum number of mapping is 64k, shared with other users. Assume you want to hotplug 256GB using virtio-mem - the block size would have to be set to at least 8 MiB (resulting in 32768 separate mappings). Reviewed-by: Pankaj Gupta Cc: Paolo Bonzini Cc: "Michael S. Tsirkin" Cc: Alex Williamson Cc: Dr. David Alan Gilbert Cc: Igor Mammedov Cc: Pankaj Gupta Cc: Peter Xu Cc: Auger Eric Cc: Wei Yang Cc: teawater Cc: Marek Kedzierski Signed-off-by: David Hildenbrand --- hw/vfio/common.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 57c83a2f14..3ce5e26bab 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -1974,8 +1974,10 @@ 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 of memory coordinated via the RamDiscardMg= r. */ - ret =3D ram_block_discard_disable(true); + ret =3D ram_block_uncoordinated_discard_disable(true); if (ret) { error_setg_errno(errp, -ret, "Cannot set discarding of RAM broken"= ); return ret; @@ -2155,7 +2157,7 @@ close_fd_exit: close(fd); =20 put_space_exit: - ram_block_discard_disable(false); + ram_block_uncoordinated_discard_disable(false); vfio_put_address_space(space); =20 return ret; @@ -2277,7 +2279,7 @@ void vfio_put_group(VFIOGroup *group) } =20 if (!group->ram_block_discard_allowed) { - ram_block_discard_disable(false); + ram_block_uncoordinated_discard_disable(false); } vfio_kvm_device_del_group(group); vfio_disconnect_container(group); @@ -2331,7 +2333,7 @@ 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_uncoordinated_discard_disable(false); } } =20 --=20 2.29.2