From nobody Fri Dec 19 13:21:57 2025 Delivered-To: importer@patchew.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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1689149999; cv=none; d=zohomail.com; s=zohoarc; b=gGa8my4t+aRGzJszhstI5UZrsTWRD0dNu73rgYrjtNRrfcn5h9rt+M1Q4yP2Beo0Te/Wnw0JZXzBwb0B6MqpW74PLIx9Z8ZksJTImkNanNOIfDiQUFUoRh8HkRFbOPDTCXDRaRvAe9X6f8HtbTBo785L519ECdzBMXY8iT3ICno= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689149999; h=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=g6uoS7ZPa3YUwd1+lSLiowZTMzcG2d1EDZG2tGOQdck=; b=CPAk0AoAl6+OwCLuPUWA8RaLgm/M2iecXW47Qu+w4LrAMd3zvoI5kUe7G8WuAoQ/wE701Sspiavy70CxR/RWXcM4h0bTmjkAhcE/2ORh2F+RTveGgaDZ/ApSb/jC/xI550vYWDFkNROTUX+wpp4wKXHodbaQdA+y2YFiTgOQFY8= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1689149999777150.72580351200247; Wed, 12 Jul 2023 01:19:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qJV3Y-0004GV-Lk; Wed, 12 Jul 2023 04:18:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qJV3W-0004E3-Uu for qemu-devel@nongnu.org; Wed, 12 Jul 2023 04:18:38 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qJV3V-0000aB-6w for qemu-devel@nongnu.org; Wed, 12 Jul 2023 04:18:38 -0400 Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-511-KtdlGue5PWKYBy21TMsSTw-1; Wed, 12 Jul 2023 04:18:33 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 252871C08968; Wed, 12 Jul 2023 08:18:33 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.39.193.77]) by smtp.corp.redhat.com (Postfix) with ESMTP id 85386492C13; Wed, 12 Jul 2023 08:18:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689149916; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=g6uoS7ZPa3YUwd1+lSLiowZTMzcG2d1EDZG2tGOQdck=; b=UfWoc8wV5F6PdLie4bNa3bkvGu/QsTUFcZGg1KLpwqORPk937pwflHtNrExgFb0wT/7psC 0h4FDPIzUHjrWtuX13fWcIlOxSgLGdaZlvupU/kKe8dJlj+hGSs2poemzHycbFO4E8N3gC RV9wrxuYnMAoTrc1A3mpxrcSyIGD45E= X-MC-Unique: KtdlGue5PWKYBy21TMsSTw-1 From: David Hildenbrand To: qemu-devel@nongnu.org Cc: Peter Maydell , Richard Henderson , "Michael S . Tsirkin" , Paolo Bonzini , David Hildenbrand , Mario Casquero Subject: [GIT PULL 20/21] virtio-mem: Prepare for device unplug support Date: Wed, 12 Jul 2023 10:17:49 +0200 Message-ID: <20230712081750.80852-21-david@redhat.com> In-Reply-To: <20230712081750.80852-1-david@redhat.com> References: <20230712081750.80852-1-david@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 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=170.10.129.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, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1689150001530100001 Content-Type: text/plain; charset="utf-8" In many cases, blindly unplugging a virtio-mem device is problematic. We can only safely remove a device once: * The guest is not expecting to be able to read unplugged memory (unplugged-inaccessible =3D=3D on) * The virtio-mem device does not have memory plugged (size =3D=3D 0) * The virtio-mem device does not have outstanding requests to the VM to plug memory (requested-size =3D=3D 0) So let's add a callback to the virtio-mem device class to check for that. We'll wire-up virtio-mem-pci next. Message-ID: <20230711153445.514112-7-david@redhat.com> Tested-by: Mario Casquero Reviewed-by: Michael S. Tsirkin Signed-off-by: David Hildenbrand --- hw/virtio/virtio-mem.c | 25 +++++++++++++++++++++++++ include/hw/virtio/virtio-mem.h | 1 + 2 files changed, 26 insertions(+) diff --git a/hw/virtio/virtio-mem.c b/hw/virtio/virtio-mem.c index 3f41e00e74..b6e781741e 100644 --- a/hw/virtio/virtio-mem.c +++ b/hw/virtio/virtio-mem.c @@ -1512,6 +1512,30 @@ static void virtio_mem_rdm_unregister_listener(RamDi= scardManager *rdm, QLIST_REMOVE(rdl, next); } =20 +static void virtio_mem_unplug_request_check(VirtIOMEM *vmem, Error **errp) +{ + if (vmem->unplugged_inaccessible =3D=3D ON_OFF_AUTO_OFF) { + /* + * We could allow it with a usable region size of 0, but let's just + * not care about that legacy setting. + */ + error_setg(errp, "virtio-mem device cannot get unplugged while" + " '" VIRTIO_MEM_UNPLUGGED_INACCESSIBLE_PROP "' !=3D 'on= '"); + return; + } + + if (vmem->size) { + error_setg(errp, "virtio-mem device cannot get unplugged while" + " '" VIRTIO_MEM_SIZE_PROP "' !=3D '0'"); + return; + } + if (vmem->requested_size) { + error_setg(errp, "virtio-mem device cannot get unplugged while" + " '" VIRTIO_MEM_REQUESTED_SIZE_PROP "' !=3D '0'"); + return; + } +} + static void virtio_mem_class_init(ObjectClass *klass, void *data) { DeviceClass *dc =3D DEVICE_CLASS(klass); @@ -1534,6 +1558,7 @@ static void virtio_mem_class_init(ObjectClass *klass,= void *data) vmc->get_memory_region =3D virtio_mem_get_memory_region; vmc->add_size_change_notifier =3D virtio_mem_add_size_change_notifier; vmc->remove_size_change_notifier =3D virtio_mem_remove_size_change_not= ifier; + vmc->unplug_request_check =3D virtio_mem_unplug_request_check; =20 rdmc->get_min_granularity =3D virtio_mem_rdm_get_min_granularity; rdmc->is_populated =3D virtio_mem_rdm_is_populated; diff --git a/include/hw/virtio/virtio-mem.h b/include/hw/virtio/virtio-mem.h index f15e561785..ab0fe2b4f2 100644 --- a/include/hw/virtio/virtio-mem.h +++ b/include/hw/virtio/virtio-mem.h @@ -98,6 +98,7 @@ struct VirtIOMEMClass { MemoryRegion *(*get_memory_region)(VirtIOMEM *vmem, Error **errp); void (*add_size_change_notifier)(VirtIOMEM *vmem, Notifier *notifier); void (*remove_size_change_notifier)(VirtIOMEM *vmem, Notifier *notifie= r); + void (*unplug_request_check)(VirtIOMEM *vmem, Error **errp); }; =20 #endif --=20 2.41.0