From nobody Mon Dec 23 23:07:39 2024 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=1734809019; cv=none; d=zohomail.com; s=zohoarc; b=c+UF5rX0jB+VLD7bGolnjnVH6x3/g1U2zyK3OiA8IkOVlbTZ2BUmzaGmQXVDi7YiHqIIqZ9GCDVWxetc60oZk9tVVtC5Mtz8cGBQzaUyg2Fw9q1Y6qJae8DyciaBDKlfX8pNQTLtWm1Q8dgzuo2SpV7FI4G5S84MVoQsC533B40= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1734809019; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=7FYSczBWmZzYWP3jGZ5iez4MtKwnNlrl2iQAhPcAask=; b=VPXt7Ny6xnewNAfJFh1UZSIPQ6OHlbN5efVr1xeoik5i3AzsCh7ioRxCDWH/2hoTnUgM5o6ft2t8c5/7IEAvKhMW5PKRZkEKO8w3Q5V6qnXq6YYQzkUcdv5qwQOg6RoOoopjSYkcdLwhkIwutEjDtGNnP1Nn6Hqmf5XQGw9EqAU= 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 1734809019972541.1402339401095; Sat, 21 Dec 2024 11:23:39 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tP53Q-0002MW-IM; Sat, 21 Dec 2024 14:22:24 -0500 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 1tP53N-0002Lj-Rz for qemu-devel@nongnu.org; Sat, 21 Dec 2024 14:22:21 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tP53L-00008D-UG for qemu-devel@nongnu.org; Sat, 21 Dec 2024 14:22:21 -0500 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-306-wwwvaOLVO2OFkwId1kYa-g-1; Sat, 21 Dec 2024 14:22:17 -0500 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4361eb83f46so22515885e9.3 for ; Sat, 21 Dec 2024 11:22:17 -0800 (PST) Received: from localhost (p200300cbc7137800820d0e9f08ce52bd.dip0.t-ipconnect.de. [2003:cb:c713:7800:820d:e9f:8ce:52bd]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-38a1c89e1acsm7148542f8f.68.2024.12.21.11.22.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 21 Dec 2024 11:22:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734808939; 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=7FYSczBWmZzYWP3jGZ5iez4MtKwnNlrl2iQAhPcAask=; b=U3XRjzz4KqSZwDOzPj3Ht4/X5+j83A6vbqiGFIHQd6ZEAanwFVWDVVZxGpfpUDm/9S6PAF qkgd2YI246yIHbcpmaOQywAtyGObXmXImfqxmtNsAYSnt6yshrvOHUj3YQi7mJDC+41uP3 4ubzXKdbW2sM8XZNvqrjyCjXHjWSTw8= X-MC-Unique: wwwvaOLVO2OFkwId1kYa-g-1 X-Mimecast-MFC-AGG-ID: wwwvaOLVO2OFkwId1kYa-g X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734808936; x=1735413736; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7FYSczBWmZzYWP3jGZ5iez4MtKwnNlrl2iQAhPcAask=; b=jfyjwfY9l4OqY8XwSLfHqovUg9kyJlNepQ70l3bPuCovqDWqXaPPAMoNX9QhtCbLhQ +R/yyvO1xNIFqVOfDa2JkRHbiALesaM7Btt60cLdfZBRy+pT7v2QreYKJnCbBwlMWZ1E PR0eVUzgTrJi6u14uInaxA79g//r3wJXB2ZPUoRYFHN8+AHLSBg9nkJnL1rXedxwGfzD wHAsizkJR7JwRS53Oxez/dQ9maSt44kYQnVbUumBwC9n3Qmva8e/xc9Z9IhBlqU+db5W 5FzS5Q9Xii/lMT7XuPVJy4MHd3maEmi7adpdG0IG/+45uzhOx1mKkVvkTTt9f5TSf5h2 bdfQ== X-Gm-Message-State: AOJu0YyYtaKyShCDiHxa+b3mOikPELgevF/RxoxD1z8WgBvw+RQJe3gs z2x1shqLulZAeOzNDccdvfzVKOXPqtnQpEDyxPaqrOIYmQqMttyqTBzguX4s0uxG451ZpDiYWC+ ifKPT1EuzI7jCP5WDXAJewq66b+9MCf7M10M0NAu4zDi8AtoN7Ptgc5aroO5Ofe7k56DrBdpfAa IikFhNYpV8ZDn3z6hGwC6XfgmAIJ6rwEOB X-Gm-Gg: ASbGncvGWMzcVmqS/Y9VpNRhStB11czudRD2hzIAkhqyRTTjuisn7pivTEU001OG5M6 ILpsw+iOAd366rJ/RQx0mSrNQpXScXBjqwVaFf3F3AZzYXkTvuJRErFI7GbyS/93IW8GzMqAUFL SRWxQI45zuL2ZAxBlRYnQi99o8gVd2GuMuFCfXhNOqkKXFJeLAO62Wi4Xq6oCkX6tz3I/0342am mxhZHEMqAcZ5Xfu7GjEQD59XkUDbUeX1Ea6eQ8Opziso8ilq3P8tqpo5W2Xx678RNpKFgc88HTp ujmqVl40OgpoTNRKRsAujm2k7eGIY6I3Ah3b3Fk= X-Received: by 2002:a5d:6f15:0:b0:385:ecdf:a30a with SMTP id ffacd0b85a97d-38a221fa490mr7297733f8f.33.1734808936337; Sat, 21 Dec 2024 11:22:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IFygNBAJjA21Cc9G944Qm1sJ7ee8OFQqhaFBIHcPLgmvlnCUkwo+NmpWukajtVQXxq3Z9iC0w== X-Received: by 2002:a5d:6f15:0:b0:385:ecdf:a30a with SMTP id ffacd0b85a97d-38a221fa490mr7297711f8f.33.1734808935865; Sat, 21 Dec 2024 11:22:15 -0800 (PST) From: David Hildenbrand To: qemu-devel@nongnu.org Cc: Halil Pasic , Christian Borntraeger , Eric Farman , Thomas Huth , Richard Henderson , "Michael S . Tsirkin" , David Hildenbrand , Juraj Marcin , Peter Maydell Subject: [PULL v2 01/15] virtio-mem: unplug memory only during system resets, not device resets Date: Sat, 21 Dec 2024 20:21:55 +0100 Message-ID: <20241221192209.3979595-2-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241221192209.3979595-1-david@redhat.com> References: <20241221192209.3979595-1-david@redhat.com> MIME-Version: 1.0 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=170.10.133.124; envelope-from=dhildenb@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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=-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_H2=-1.177, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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.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: 1734809022371116600 Content-Type: text/plain; charset="utf-8" We recently converted from the LegacyReset to the new reset framework in commit c009a311e939 ("virtio-mem: Use new Resettable framework instead of LegacyReset") to be able to use the ResetType to filter out wakeup resets. However, this change had an undesired implications: as we override the Resettable interface methods in VirtIOMEMClass, the reset handler will not only get called during system resets (i.e., qemu_devices_reset()) but also during any direct or indirect device rests (e.g., device_cold_reset()). Further, we might now receive two reset callbacks during qemu_devices_reset(), first when reset by a parent and later when reset directly. The memory state of virtio-mem devices is rather special: it's supposed to be persistent/unchanged during most resets (similar to resetting a hard disk will not destroy the data), unless actually cold-resetting the whole system (different to a hard disk where a reboot will not destroy the data): ripping out system RAM is something guest OSes don't particularly enjoy, but we want to detect when rebooting to an OS that does not support virtio-mem and wouldn't be able to detect+use the memory -- and we want to force-defragment hotplugged memory to also shrink the usable device memory region. So we rally want to catch system resets to do that. On supported targets (e.g., x86), getting a cold reset on the device/parent triggers is not that easy (but looks like PCI code might trigger it), so this implication went unnoticed. However, with upcoming s390x support it is problematic: during kdump, s390x triggers a subsystem reset, ending up in s390_machine_reset() and calling only subsystem_reset() instead of qemu_devices_reset() -- because it's not a full system reset. In subsystem_reset(), s390x performs a device_cold_reset() of any TYPE_VIRTUAL_CSS_BRIDGE device, which ends up resetting all children, including the virtio-mem device. Consequently, we wrongly detect a system reset and unplug all device memory, resulting in hotplugged memory not getting included in the crash dump -- undesired. We really must not mess with hotplugged memory state during simple device resets. To fix, create+register a new reset object that will only get triggered during qemu_devices_reset() calls, but not during any other resets as it is logically not the child of any other object. Message-ID: <20241025104103.342188-1-david@redhat.com> Acked-by: Michael S. Tsirkin Cc: "Michael S. Tsirkin" Cc: Juraj Marcin Cc: Peter Maydell Signed-off-by: David Hildenbrand --- hw/virtio/virtio-mem.c | 103 +++++++++++++++++++++++---------- include/hw/virtio/virtio-mem.h | 13 ++++- 2 files changed, 84 insertions(+), 32 deletions(-) diff --git a/hw/virtio/virtio-mem.c b/hw/virtio/virtio-mem.c index 3f6f46fad7..a0dceaddec 100644 --- a/hw/virtio/virtio-mem.c +++ b/hw/virtio/virtio-mem.c @@ -956,6 +956,7 @@ static void virtio_mem_device_realize(DeviceState *dev,= Error **errp) VirtIOMEM *vmem =3D VIRTIO_MEM(dev); uint64_t page_size; RAMBlock *rb; + Object *obj; int ret; =20 if (!vmem->memdev) { @@ -1121,7 +1122,28 @@ static void virtio_mem_device_realize(DeviceState *d= ev, Error **errp) vmstate_register_any(VMSTATE_IF(vmem), &vmstate_virtio_mem_device_early, vmem); } - qemu_register_resettable(OBJECT(vmem)); + + /* + * We only want to unplug all memory to start with a clean slate when + * it is safe for the guest -- during system resets that call + * qemu_devices_reset(). + * + * We'll filter out selected qemu_devices_reset() calls used for other + * purposes, like resetting all devices during wakeup from suspend on + * x86 based on the reset type passed to qemu_devices_reset(). + * + * Unplugging all memory during simple device resets can result in the= VM + * unexpectedly losing RAM, corrupting VM state. + * + * Simple device resets (or resets triggered by getting a parent device + * reset) must not change the state of plugged memory blocks. Therefor= e, + * we need a dedicated reset object that only gets called during + * qemu_devices_reset(). + */ + obj =3D object_new(TYPE_VIRTIO_MEM_SYSTEM_RESET); + vmem->system_reset =3D VIRTIO_MEM_SYSTEM_RESET(obj); + vmem->system_reset->vmem =3D vmem; + qemu_register_resettable(obj); =20 /* * Set ourselves as RamDiscardManager before the plug handler maps the @@ -1141,7 +1163,10 @@ static void virtio_mem_device_unrealize(DeviceState = *dev) * found via an address space anymore. Unset ourselves. */ memory_region_set_ram_discard_manager(&vmem->memdev->mr, NULL); - qemu_unregister_resettable(OBJECT(vmem)); + + qemu_unregister_resettable(OBJECT(vmem->system_reset)); + object_unref(OBJECT(vmem->system_reset)); + if (vmem->early_migration) { vmstate_unregister(VMSTATE_IF(vmem), &vmstate_virtio_mem_device_ea= rly, vmem); @@ -1841,38 +1866,12 @@ static void virtio_mem_unplug_request_check(VirtIOM= EM *vmem, Error **errp) } } =20 -static ResettableState *virtio_mem_get_reset_state(Object *obj) -{ - VirtIOMEM *vmem =3D VIRTIO_MEM(obj); - return &vmem->reset_state; -} - -static void virtio_mem_system_reset_hold(Object *obj, ResetType type) -{ - VirtIOMEM *vmem =3D VIRTIO_MEM(obj); - - /* - * When waking up from standby/suspend-to-ram, do not unplug any memor= y. - */ - if (type =3D=3D RESET_TYPE_WAKEUP) { - return; - } - - /* - * During usual resets, we will unplug all memory and shrink the usable - * region size. This is, however, not possible in all scenarios. Then, - * the guest has to deal with this manually (VIRTIO_MEM_REQ_UNPLUG_ALL= ). - */ - virtio_mem_unplug_all(vmem); -} - static void virtio_mem_class_init(ObjectClass *klass, void *data) { DeviceClass *dc =3D DEVICE_CLASS(klass); VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_CLASS(klass); VirtIOMEMClass *vmc =3D VIRTIO_MEM_CLASS(klass); RamDiscardManagerClass *rdmc =3D RAM_DISCARD_MANAGER_CLASS(klass); - ResettableClass *rc =3D RESETTABLE_CLASS(klass); =20 device_class_set_props(dc, virtio_mem_properties); dc->vmsd =3D &vmstate_virtio_mem; @@ -1899,9 +1898,6 @@ static void virtio_mem_class_init(ObjectClass *klass,= void *data) rdmc->replay_discarded =3D virtio_mem_rdm_replay_discarded; rdmc->register_listener =3D virtio_mem_rdm_register_listener; rdmc->unregister_listener =3D virtio_mem_rdm_unregister_listener; - - rc->get_state =3D virtio_mem_get_reset_state; - rc->phases.hold =3D virtio_mem_system_reset_hold; } =20 static const TypeInfo virtio_mem_info =3D { @@ -1924,3 +1920,48 @@ static void virtio_register_types(void) } =20 type_init(virtio_register_types) + +OBJECT_DEFINE_SIMPLE_TYPE_WITH_INTERFACES(VirtioMemSystemReset, virtio_mem= _system_reset, VIRTIO_MEM_SYSTEM_RESET, OBJECT, { TYPE_RESETTABLE_INTERFACE= }, { }) + +static void virtio_mem_system_reset_init(Object *obj) +{ +} + +static void virtio_mem_system_reset_finalize(Object *obj) +{ +} + +static ResettableState *virtio_mem_system_reset_get_state(Object *obj) +{ + VirtioMemSystemReset *vmem_reset =3D VIRTIO_MEM_SYSTEM_RESET(obj); + + return &vmem_reset->reset_state; +} + +static void virtio_mem_system_reset_hold(Object *obj, ResetType type) +{ + VirtioMemSystemReset *vmem_reset =3D VIRTIO_MEM_SYSTEM_RESET(obj); + VirtIOMEM *vmem =3D vmem_reset->vmem; + + /* + * When waking up from standby/suspend-to-ram, do not unplug any memor= y. + */ + if (type =3D=3D RESET_TYPE_WAKEUP) { + return; + } + + /* + * During usual resets, we will unplug all memory and shrink the usable + * region size. This is, however, not possible in all scenarios. Then, + * the guest has to deal with this manually (VIRTIO_MEM_REQ_UNPLUG_ALL= ). + */ + virtio_mem_unplug_all(vmem); +} + +static void virtio_mem_system_reset_class_init(ObjectClass *klass, void *d= ata) +{ + ResettableClass *rc =3D RESETTABLE_CLASS(klass); + + rc->get_state =3D virtio_mem_system_reset_get_state; + rc->phases.hold =3D virtio_mem_system_reset_hold; +} diff --git a/include/hw/virtio/virtio-mem.h b/include/hw/virtio/virtio-mem.h index a1af144c28..550ce585b2 100644 --- a/include/hw/virtio/virtio-mem.h +++ b/include/hw/virtio/virtio-mem.h @@ -25,6 +25,10 @@ OBJECT_DECLARE_TYPE(VirtIOMEM, VirtIOMEMClass, VIRTIO_MEM) =20 +#define TYPE_VIRTIO_MEM_SYSTEM_RESET "virtio-mem-system-reset" + +OBJECT_DECLARE_SIMPLE_TYPE(VirtioMemSystemReset, VIRTIO_MEM_SYSTEM_RESET) + #define VIRTIO_MEM_MEMDEV_PROP "memdev" #define VIRTIO_MEM_NODE_PROP "node" #define VIRTIO_MEM_SIZE_PROP "size" @@ -117,8 +121,15 @@ struct VirtIOMEM { /* listeners to notify on plug/unplug activity. */ QLIST_HEAD(, RamDiscardListener) rdl_list; =20 - /* State of the resettable container */ + /* Catch system resets -> qemu_devices_reset() only. */ + VirtioMemSystemReset *system_reset; +}; + +struct VirtioMemSystemReset { + Object parent; + ResettableState reset_state; + VirtIOMEM *vmem; }; =20 struct VirtIOMEMClass { --=20 2.47.1 From nobody Mon Dec 23 23:07:39 2024 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=1734808977; cv=none; d=zohomail.com; s=zohoarc; b=QQdWfG60JB+2YyC4iheEQut/K2DZ5/PXl8terht2/uZe+8yymBLh0+K3sxBPfjZI7IYbbk6Z+6tCEgaeQQnHzxvOTjy4LWnwPSez0fU16qF1yLijK5jdvN6/9FsGcf5dY5kIvJfjRoPqmio3ico0K77NUnAJNStJf0xcqKRfOxM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1734808977; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=BOXr2Dzl9Uc55CdyQyMKaFxc2uZ6Bg9cL7pok6fw/Mk=; b=PSoeyJfVSrcBHIqwxTPv3qGnrzqlwfEv1gNoTNopiS5hmEkjwxVFkMiXycYFdjRGDMe0/Kl3/97mXOu3G1WvQZda4YHAdCWoTOP6tz8OxKNRgJQ2zMrs/UGVdJHfoUmYysqUep/5FCXTpJcyOdG2QAQf/w2Mcj9kqAL19baIfkU= 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 173480897745498.41673739597854; Sat, 21 Dec 2024 11:22:57 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tP53R-0002Mc-2l; Sat, 21 Dec 2024 14:22:25 -0500 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 1tP53Q-0002ML-0U for qemu-devel@nongnu.org; Sat, 21 Dec 2024 14:22:24 -0500 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 1tP53O-00008c-Ji for qemu-devel@nongnu.org; Sat, 21 Dec 2024 14:22:23 -0500 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-317-oltUJG4vNC2s0K3Ogq8nfQ-1; Sat, 21 Dec 2024 14:22:20 -0500 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4361a8fc3bdso16094225e9.2 for ; Sat, 21 Dec 2024 11:22:20 -0800 (PST) Received: from localhost (p200300cbc7137800820d0e9f08ce52bd.dip0.t-ipconnect.de. [2003:cb:c713:7800:820d:e9f:8ce:52bd]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-4366127c639sm82369085e9.31.2024.12.21.11.22.16 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 21 Dec 2024 11:22:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734808941; 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=BOXr2Dzl9Uc55CdyQyMKaFxc2uZ6Bg9cL7pok6fw/Mk=; b=VURB2pNNrv4M74kcKRhTolBnP99HHbMkM+knyUuWIkEAg/t2ROqvSjkZuICgtaQ9iDu76V vEbfQyn1g1nodte1EPvyC7ZKBrBim0a6t2sJ6zxO5XswfXWkMVJfSgjP96YXZlOAmKgqLb oXni4qNLOguydt7QydbkO3a04nce/nE= X-MC-Unique: oltUJG4vNC2s0K3Ogq8nfQ-1 X-Mimecast-MFC-AGG-ID: oltUJG4vNC2s0K3Ogq8nfQ X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734808939; x=1735413739; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BOXr2Dzl9Uc55CdyQyMKaFxc2uZ6Bg9cL7pok6fw/Mk=; b=V+WYOEBvHWffMXgW5zvlsxlT7MhXbz9b9kCpcYpZw6O1ANYoYtGMti9Rljoi1vD2W8 KTw0sYJ9vsVG3ZZnMT0KI8nB/GhOqAC3eiGG2F+o/qCwNtsSkMO4usQ6t0P0C/xTmW9g S3LAPuujKvHg6TMt0g87w9q9Ixwffk2EFSPC7mxdK6N1ZSEoC3LMlmfL89+O3P73g6hn ToJDroOTeJw+hyEHdF7OJf7qr8TqsNefYzXF8mhV2LEoX/E0d/fWtcxYJBs8RB65l3ED hyFoGuKnAUNQSFk+99EEPVc995kTVg242gALl7T7qkrA16lM+jGPqMHmsfIl8RRjXH2d x96Q== X-Gm-Message-State: AOJu0YyNrc2fGXNXbn+WLq77l5LdW+wQus2Ook5NUXBQ7NPxM0rycKeO 7Zi6PsmcAjE6uhjr8WB8s6L5fj8V2WgFgLa7lQW4oUVVcOsQsxWAZVLzOZrlrLDy2OpPRq34udz hfqg2S9oguO7gVmlB0e1oP8EY+N2u7Mz7qlmo/mVHeikuQNIUB9Q4Wk9T6UcUE2jX4Ggl4LZOVa 7kph7FRxgZ8UYBszjW9oPcOyTymYTcRz+r X-Gm-Gg: ASbGnctQqovNYFfytc2G7IP2VtbRD08CY1TmLbmB8/XT1B+5WbCG58e/GzNuDk5lGso hsazav4+K0TxuxCL4UIcHw1lTUwGDf8lzOsjrvUTs4JtCN6e4KBD2r8/6B0NDW12wbrmwCtmOs7 WvjxkRfUU3iKqXFCDCVG/++eVfVRzuAGmitRczfbDfkajzLfzIBPSusb94scj2/vDyDBdccGP1x vaeGTmM6urapZTokbWy707gIotA3S3EPh4Wi8+TY7Epx0HfG1+v8CnOKkqKD5+EHIXGZ6ppEaUJ 1o0lz0RQAPSv62pR9I+TVepzCrA64+9gs3LRgOY= X-Received: by 2002:a05:600c:19c6:b0:434:f2bf:1708 with SMTP id 5b1f17b1804b1-4366854740fmr55911395e9.7.1734808939146; Sat, 21 Dec 2024 11:22:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IHmhM/JDbnZdQ9xrkFvpWu/TcMWHhFRB2eCxVjCDlYSGhs9Z7LSQ8UnTkH0rDx9RLTG7X74Og== X-Received: by 2002:a05:600c:19c6:b0:434:f2bf:1708 with SMTP id 5b1f17b1804b1-4366854740fmr55911225e9.7.1734808938800; Sat, 21 Dec 2024 11:22:18 -0800 (PST) From: David Hildenbrand To: qemu-devel@nongnu.org Cc: Halil Pasic , Christian Borntraeger , Eric Farman , Thomas Huth , Richard Henderson , "Michael S . Tsirkin" , David Hildenbrand , Janosch Frank Subject: [PULL v2 02/15] s390x/s390-virtio-ccw: don't crash on weird RAM sizes Date: Sat, 21 Dec 2024 20:21:56 +0100 Message-ID: <20241221192209.3979595-3-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241221192209.3979595-1-david@redhat.com> References: <20241221192209.3979595-1-david@redhat.com> MIME-Version: 1.0 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=170.10.129.124; envelope-from=dhildenb@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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=-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_H2=-1.177, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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.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: 1734808978068116600 Content-Type: text/plain; charset="utf-8" KVM is not happy when starting a VM with weird RAM sizes: # qemu-system-s390x --enable-kvm --nographic -m 1234K qemu-system-s390x: kvm_set_user_memory_region: KVM_SET_USER_MEMORY_REGION failed, slot=3D0, start=3D0x0, size=3D0x244000: Invalid argument kvm_set_phys_mem: error registering slot: Invalid argument Aborted (core dumped) Let's handle that in a better way by rejecting such weird RAM sizes right from the start: # qemu-system-s390x --enable-kvm --nographic -m 1234K qemu-system-s390x: ram size must be multiples of 1 MiB Message-ID: <20241219144115.2820241-2-david@redhat.com> Acked-by: Michael S. Tsirkin Reviewed-by: Eric Farman Reviewed-by: Thomas Huth Acked-by: Janosch Frank Signed-off-by: David Hildenbrand --- hw/s390x/s390-virtio-ccw.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c index 67ae34aead..f2a17ecace 100644 --- a/hw/s390x/s390-virtio-ccw.c +++ b/hw/s390x/s390-virtio-ccw.c @@ -180,6 +180,17 @@ static void s390_memory_init(MemoryRegion *ram) { MemoryRegion *sysmem =3D get_system_memory(); =20 + if (!QEMU_IS_ALIGNED(memory_region_size(ram), 1 * MiB)) { + /* + * SCLP cannot possibly expose smaller granularity right now and K= VM + * cannot handle smaller granularity. As we don't support NUMA, the + * region size directly corresponds to machine->ram_size, and the = region + * is a single RAM memory region. + */ + error_report("ram size must be multiples of 1 MiB"); + exit(EXIT_FAILURE); + } + /* allocate RAM for core */ memory_region_add_subregion(sysmem, 0, ram); =20 --=20 2.47.1 From nobody Mon Dec 23 23:07:39 2024 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=1734808995; cv=none; d=zohomail.com; s=zohoarc; b=Ub/1qIqoh86EBHO62I8uUwvZacrNpcZ//pl1go2axFlp64RwRLvW8vfEtwKeahOY+B2J2IlJz4rFL+IeahPMU21XQZOJPb0RrpbYTBChm8MhbvCiItwuyAt3LKee5JjSFeP7XWukF9b2GnZ43v+W13GGjolDXnPibRq3C3jiFwE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1734808995; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Eu+UQDI4XBqUuyYo1urovuvbpp7PhrM/aJHLpvbVFXQ=; b=IgNS9KtLvKmPiYa5jeTYxRlfAqIiEFaOg3t95Fcz0mPbmUpB+QnfWVNKhpUC0PoxCipXSQnALJfpNzyazu170N6nnVtQ6jf2l5uu+l/N78dYQxiRrN9Y0apfSz0amO+cEofyVasCJ18fsNTyFE67H8ERzlustYglFSXMPnSZAJc= 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 1734808995168651.3117529266723; Sat, 21 Dec 2024 11:23:15 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tP53V-0002NQ-JZ; Sat, 21 Dec 2024 14:22:29 -0500 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 1tP53T-0002N0-Qw for qemu-devel@nongnu.org; Sat, 21 Dec 2024 14:22:27 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tP53S-00008y-1L for qemu-devel@nongnu.org; Sat, 21 Dec 2024 14:22:27 -0500 Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-50-_Pxkc9qxMguGw--aasI3ow-1; Sat, 21 Dec 2024 14:22:23 -0500 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-385e03f54d0so1409508f8f.3 for ; Sat, 21 Dec 2024 11:22:23 -0800 (PST) Received: from localhost (p200300cbc7137800820d0e9f08ce52bd.dip0.t-ipconnect.de. [2003:cb:c713:7800:820d:e9f:8ce:52bd]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-43661289e0fsm84041905e9.39.2024.12.21.11.22.19 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 21 Dec 2024 11:22:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734808945; 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=Eu+UQDI4XBqUuyYo1urovuvbpp7PhrM/aJHLpvbVFXQ=; b=d0+nKMvfR1r4jjijxd4VeH2Dgjhp7ylUuHJ0Y0p6uTN5RMMf/W6Cg2W1/yvHWZkbi7bD/g 81ltGJRXXXwH/qVV4NxzzDK97pFmmSo1xzYFj4ezZohMRqBvmQ0eIZPPWCpLHxpe4s7TYu emkr2FQSgZNda/det0Pb2jlVSBv37f4= X-MC-Unique: _Pxkc9qxMguGw--aasI3ow-1 X-Mimecast-MFC-AGG-ID: _Pxkc9qxMguGw--aasI3ow X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734808942; x=1735413742; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Eu+UQDI4XBqUuyYo1urovuvbpp7PhrM/aJHLpvbVFXQ=; b=oYwZptHT0dRZWlJAlep929DPV6ksyHTnyp+a76zAyPksFbTwlet8cmD6ry8Aaukns0 AiA4Qbe+3dRTTZ95dtVgpySmBJ5qx6s9eT9smQN86NZ+RAwvILX5FpV5m7+OLpdLb+7Z pwbBs6u+w0Kz6iGZr2bJEinTwyM1354QI2VpJu23a8El1VTLK4eD2HQHuTBaIhxVGLe7 /0cLsLRbNQoT/r+yZuwPIRQ9Zub0jmFPdYIC/LH46clZ8Av+IqH8ioQGE1ziBV/p6PQt m6iTckeMn4nVXLQw3jA048ucjhfDnpCzAnx9RT3YgKqO5jVBaUFqJsdZKw4rbbPjngs4 PxoA== X-Gm-Message-State: AOJu0Ywr3TrlwlBXY8qaVpvAl3Mh9LLSipdZY/W/U7nATWU+SsTIVe1I LdFR4QdY/1+aH6utmP4+sLuMu2nxgYKdNgv5JcKpMRLKl8J+olzlnDuQyyIkq50FnjJBGp0WZBr zqIao3qdLY93kgSB+qvz+QKqUXmnx6mrbtrPZ1oS/o99f+c9OogvyFycdNdx/uowerwP5+r6oFw RN6tfrkvK17YZTRKeD28G3QLUoW06cScIB X-Gm-Gg: ASbGncuM0YJDT6lfdI9evPnmZ2eq1+YfMQchnsfyklCmRgwl35t4eF3b38dCj+ouBhf wByuuumcyOS6x2zQht6DDTb2bgaR/pkOq8rZigNbfL5hfIhJg3+c6yiDzhmruj+L4zKezREGZu0 Qfp++nlz3jzPaq4K4Wi7lNxfVse2mOwCcArSuKaxiNqlFwipBcipfINqQgERj8dvbbwODEDstzA 8tXg1hvq/2zSCv5/P5ghOATEJCjoCXFzWk1bM3NTSf387KRF/lA/kjNUz6dduEM9o4PBvtnZUhe uyelLMJqR5zJfiXuHjhlxPXz4KG3W1qhf7lu2yA= X-Received: by 2002:a05:6000:4012:b0:385:f892:c8fe with SMTP id ffacd0b85a97d-38a221fa22cmr7202750f8f.21.1734808942166; Sat, 21 Dec 2024 11:22:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IEqebWA7jESFeSiNnHg724Vz6EPlvaC/ie8FGqhmyY/SboMdQ6hWe8lQGRuLkaMI07CfNtKLw== X-Received: by 2002:a05:6000:4012:b0:385:f892:c8fe with SMTP id ffacd0b85a97d-38a221fa22cmr7202731f8f.21.1734808941745; Sat, 21 Dec 2024 11:22:21 -0800 (PST) From: David Hildenbrand To: qemu-devel@nongnu.org Cc: Halil Pasic , Christian Borntraeger , Eric Farman , Thomas Huth , Richard Henderson , "Michael S . Tsirkin" , David Hildenbrand Subject: [PULL v2 03/15] s390x/s390-virtio-hcall: remove hypercall registration mechanism Date: Sat, 21 Dec 2024 20:21:57 +0100 Message-ID: <20241221192209.3979595-4-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241221192209.3979595-1-david@redhat.com> References: <20241221192209.3979595-1-david@redhat.com> MIME-Version: 1.0 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=170.10.133.124; envelope-from=dhildenb@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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=-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_H2=-1.177, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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.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: 1734808996212116600 Content-Type: text/plain; charset="utf-8" Nowadays, we only have a single machine type in QEMU, everything is based on virtio-ccw and the traditional virtio machine does no longer exist. No need to dynamically register diag500 handlers. Move the two existing handlers into s390-virtio-hcall.c. Message-ID: <20241219144115.2820241-3-david@redhat.com> Acked-by: Michael S. Tsirkin Reviewed-by: Thomas Huth Acked-by: Christian Borntraeger Signed-off-by: David Hildenbrand --- hw/s390x/meson.build | 6 ++-- hw/s390x/s390-virtio-ccw.c | 58 ------------------------------ hw/s390x/s390-virtio-hcall.c | 65 +++++++++++++++++++++++++--------- hw/s390x/s390-virtio-hcall.h | 2 -- target/s390x/kvm/kvm.c | 5 ++- target/s390x/tcg/misc_helper.c | 3 ++ 6 files changed, 60 insertions(+), 79 deletions(-) diff --git a/hw/s390x/meson.build b/hw/s390x/meson.build index 482fd13420..d6c8c33915 100644 --- a/hw/s390x/meson.build +++ b/hw/s390x/meson.build @@ -12,7 +12,6 @@ s390x_ss.add(files( 's390-pci-inst.c', 's390-skeys.c', 's390-stattrib.c', - 's390-virtio-hcall.c', 'sclp.c', 'sclpcpu.c', 'sclpquiesce.c', @@ -28,7 +27,10 @@ s390x_ss.add(when: 'CONFIG_KVM', if_true: files( s390x_ss.add(when: 'CONFIG_TCG', if_true: files( 'tod-tcg.c', )) -s390x_ss.add(when: 'CONFIG_S390_CCW_VIRTIO', if_true: files('s390-virtio-c= cw.c')) +s390x_ss.add(when: 'CONFIG_S390_CCW_VIRTIO', if_true: files( + 's390-virtio-ccw.c', + 's390-virtio-hcall.c', +)) s390x_ss.add(when: 'CONFIG_TERMINAL3270', if_true: files('3270-ccw.c')) s390x_ss.add(when: 'CONFIG_VFIO', if_true: files('s390-pci-vfio.c')) =20 diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c index f2a17ecace..b0edaa0872 100644 --- a/hw/s390x/s390-virtio-ccw.c +++ b/hw/s390x/s390-virtio-ccw.c @@ -16,11 +16,8 @@ #include "exec/ram_addr.h" #include "exec/confidential-guest-support.h" #include "hw/boards.h" -#include "hw/s390x/s390-virtio-hcall.h" #include "hw/s390x/sclp.h" #include "hw/s390x/s390_flic.h" -#include "hw/s390x/ioinst.h" -#include "hw/s390x/css.h" #include "virtio-ccw.h" #include "qemu/config-file.h" #include "qemu/ctype.h" @@ -124,58 +121,6 @@ static void subsystem_reset(void) } } =20 -static int virtio_ccw_hcall_notify(const uint64_t *args) -{ - uint64_t subch_id =3D args[0]; - uint64_t data =3D args[1]; - SubchDev *sch; - VirtIODevice *vdev; - int cssid, ssid, schid, m; - uint16_t vq_idx =3D data; - - if (ioinst_disassemble_sch_ident(subch_id, &m, &cssid, &ssid, &schid))= { - return -EINVAL; - } - sch =3D css_find_subch(m, cssid, ssid, schid); - if (!sch || !css_subch_visible(sch)) { - return -EINVAL; - } - - vdev =3D virtio_ccw_get_vdev(sch); - if (vq_idx >=3D VIRTIO_QUEUE_MAX || !virtio_queue_get_num(vdev, vq_idx= )) { - return -EINVAL; - } - - if (virtio_vdev_has_feature(vdev, VIRTIO_F_NOTIFICATION_DATA)) { - virtio_queue_set_shadow_avail_idx(virtio_get_queue(vdev, vq_idx), - (data >> 16) & 0xFFFF); - } - - virtio_queue_notify(vdev, vq_idx); - return 0; -} - -static int virtio_ccw_hcall_early_printk(const uint64_t *args) -{ - uint64_t mem =3D args[0]; - MachineState *ms =3D MACHINE(qdev_get_machine()); - - if (mem < ms->ram_size) { - /* Early printk */ - return 0; - } - return -EINVAL; -} - -static void virtio_ccw_register_hcalls(void) -{ - s390_register_virtio_hypercall(KVM_S390_VIRTIO_CCW_NOTIFY, - virtio_ccw_hcall_notify); - /* Tolerate early printk. */ - s390_register_virtio_hypercall(KVM_S390_VIRTIO_NOTIFY, - virtio_ccw_hcall_early_printk); -} - static void s390_memory_init(MemoryRegion *ram) { MemoryRegion *sysmem =3D get_system_memory(); @@ -296,9 +241,6 @@ static void ccw_init(MachineState *machine) OBJECT(dev)); sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); =20 - /* register hypercalls */ - virtio_ccw_register_hcalls(); - s390_enable_css_support(s390_cpu_addr2state(0)); =20 ret =3D css_create_css_image(VIRTUAL_CSSID, true); diff --git a/hw/s390x/s390-virtio-hcall.c b/hw/s390x/s390-virtio-hcall.c index ec7cf8beb3..ca49e3cd22 100644 --- a/hw/s390x/s390-virtio-hcall.c +++ b/hw/s390x/s390-virtio-hcall.c @@ -11,31 +11,64 @@ =20 #include "qemu/osdep.h" #include "cpu.h" +#include "hw/boards.h" #include "hw/s390x/s390-virtio-hcall.h" +#include "hw/s390x/ioinst.h" +#include "hw/s390x/css.h" +#include "virtio-ccw.h" =20 -#define MAX_DIAG_SUBCODES 255 +static int handle_virtio_notify(uint64_t mem) +{ + MachineState *ms =3D MACHINE(qdev_get_machine()); =20 -static s390_virtio_fn s390_diag500_table[MAX_DIAG_SUBCODES]; + if (mem < ms->ram_size) { + /* Early printk */ + return 0; + } + return -EINVAL; +} =20 -void s390_register_virtio_hypercall(uint64_t code, s390_virtio_fn fn) +static int handle_virtio_ccw_notify(uint64_t subch_id, uint64_t data) { - assert(code < MAX_DIAG_SUBCODES); - assert(!s390_diag500_table[code]); + SubchDev *sch; + VirtIODevice *vdev; + int cssid, ssid, schid, m; + uint16_t vq_idx =3D data; + + if (ioinst_disassemble_sch_ident(subch_id, &m, &cssid, &ssid, &schid))= { + return -EINVAL; + } + sch =3D css_find_subch(m, cssid, ssid, schid); + if (!sch || !css_subch_visible(sch)) { + return -EINVAL; + } =20 - s390_diag500_table[code] =3D fn; + vdev =3D virtio_ccw_get_vdev(sch); + if (vq_idx >=3D VIRTIO_QUEUE_MAX || !virtio_queue_get_num(vdev, vq_idx= )) { + return -EINVAL; + } + + if (virtio_vdev_has_feature(vdev, VIRTIO_F_NOTIFICATION_DATA)) { + virtio_queue_set_shadow_avail_idx(virtio_get_queue(vdev, vq_idx), + (data >> 16) & 0xFFFF); + } + + virtio_queue_notify(vdev, vq_idx); + return 0; } =20 int s390_virtio_hypercall(CPUS390XState *env) { - s390_virtio_fn fn; - - if (env->regs[1] < MAX_DIAG_SUBCODES) { - fn =3D s390_diag500_table[env->regs[1]]; - if (fn) { - env->regs[2] =3D fn(&env->regs[2]); - return 0; - } - } + const uint64_t subcode =3D env->regs[1]; =20 - return -EINVAL; + switch (subcode) { + case KVM_S390_VIRTIO_NOTIFY: + env->regs[2] =3D handle_virtio_notify(env->regs[2]); + return 0; + case KVM_S390_VIRTIO_CCW_NOTIFY: + env->regs[2] =3D handle_virtio_ccw_notify(env->regs[2], env->regs[= 3]); + return 0; + default: + return -EINVAL; + } } diff --git a/hw/s390x/s390-virtio-hcall.h b/hw/s390x/s390-virtio-hcall.h index 3ae6d6ae3a..3d9fe147d2 100644 --- a/hw/s390x/s390-virtio-hcall.h +++ b/hw/s390x/s390-virtio-hcall.h @@ -18,8 +18,6 @@ /* The only thing that we need from the old kvm_virtio.h file */ #define KVM_S390_VIRTIO_NOTIFY 0 =20 -typedef int (*s390_virtio_fn)(const uint64_t *args); -void s390_register_virtio_hypercall(uint64_t code, s390_virtio_fn fn); int s390_virtio_hypercall(CPUS390XState *env); =20 #endif /* HW_S390_VIRTIO_HCALL_H */ diff --git a/target/s390x/kvm/kvm.c b/target/s390x/kvm/kvm.c index dd0322c43a..32cf70bb19 100644 --- a/target/s390x/kvm/kvm.c +++ b/target/s390x/kvm/kvm.c @@ -51,6 +51,7 @@ #include "hw/s390x/s390-virtio-ccw.h" #include "hw/s390x/s390-virtio-hcall.h" #include "target/s390x/kvm/pv.h" +#include CONFIG_DEVICES =20 #define kvm_vm_check_mem_attr(s, attr) \ kvm_vm_check_attr(s, KVM_S390_VM_MEM_CTRL, attr) @@ -1494,9 +1495,11 @@ static int handle_e3(S390CPU *cpu, struct kvm_run *r= un, uint8_t ipbl) static int handle_hypercall(S390CPU *cpu, struct kvm_run *run) { CPUS390XState *env =3D &cpu->env; - int ret; + int ret =3D -EINVAL; =20 +#ifdef CONFIG_S390_CCW_VIRTIO ret =3D s390_virtio_hypercall(env); +#endif /* CONFIG_S390_CCW_VIRTIO */ if (ret =3D=3D -EINVAL) { kvm_s390_program_interrupt(cpu, PGM_SPECIFICATION); return 0; diff --git a/target/s390x/tcg/misc_helper.c b/target/s390x/tcg/misc_helper.c index 303f86d363..f44136a568 100644 --- a/target/s390x/tcg/misc_helper.c +++ b/target/s390x/tcg/misc_helper.c @@ -43,6 +43,7 @@ #include "hw/s390x/s390-pci-inst.h" #include "hw/boards.h" #include "hw/s390x/tod.h" +#include CONFIG_DEVICES #endif =20 /* #define DEBUG_HELPER */ @@ -116,12 +117,14 @@ void HELPER(diag)(CPUS390XState *env, uint32_t r1, ui= nt32_t r3, uint32_t num) uint64_t r; =20 switch (num) { +#ifdef CONFIG_S390_CCW_VIRTIO case 0x500: /* KVM hypercall */ bql_lock(); r =3D s390_virtio_hypercall(env); bql_unlock(); break; +#endif /* CONFIG_S390_CCW_VIRTIO */ case 0x44: /* yield */ r =3D 0; --=20 2.47.1 From nobody Mon Dec 23 23:07:39 2024 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=1734809042; cv=none; d=zohomail.com; s=zohoarc; b=MQIu5dJmbKgv/9WnPJ9eIQEWinC2/p6n6pRCB35+VoGzsR4MM5hPSj5K4AXun9P+FAdHGpwULdMfHfq1faqWwfI7zj0N+MK7XKag5yiI9bGZ1xZLMWpsLjvvoUdLSUxkag91coHGepEwLbsPlaQdeR7VWfEDjAliIa49hXxbkuU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1734809042; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=E4KdKj6hbbdD8TFVWl0itPd8xJR7/KfGpl+19tzA838=; b=I3vfdqLhl2hnlStDtHfwHH0iN804mW9HrUvrnF9yjyx3H9B68NMH6AvQWFAvJJ0VWrzRkaquBcqArZULF5p/cmEWiaE66RuYKB5w6JTS9gVg8O5C7fSTWDKqYuNn9I/SbnrCSUDc8t6OwEXny4Mgw/keAw6YDc/CAa3u29knW6o= 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 1734809042180685.8787815367218; Sat, 21 Dec 2024 11:24:02 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tP53a-0002ON-Ei; Sat, 21 Dec 2024 14:22:34 -0500 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 1tP53Y-0002Na-Bp for qemu-devel@nongnu.org; Sat, 21 Dec 2024 14:22:32 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tP53W-0000A5-Qa for qemu-devel@nongnu.org; Sat, 21 Dec 2024 14:22:32 -0500 Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-126-v4IDNRgrPmO9mms---R0kw-1; Sat, 21 Dec 2024 14:22:25 -0500 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-385e27c5949so1815923f8f.3 for ; Sat, 21 Dec 2024 11:22:25 -0800 (PST) Received: from localhost (p200300cbc7137800820d0e9f08ce52bd.dip0.t-ipconnect.de. [2003:cb:c713:7800:820d:e9f:8ce:52bd]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-38a1c833149sm7073049f8f.39.2024.12.21.11.22.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 21 Dec 2024 11:22:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734808950; 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=E4KdKj6hbbdD8TFVWl0itPd8xJR7/KfGpl+19tzA838=; b=NsiHHye/InGlAjaP4FrDYFFA0tBvR+WcfSmUtj/SjuqoZXx5+7AmhIG/A0i6jJsFfAbmc/ fDRDe18+9Saa4EWmiTlZJ9yXjtoG554wXVP6FwrdOegd+/RZIe/nAYWcFtnKexpgJ2zIDw bNdQILOa4UTyy3Qo4lQSMhHq5CKWO1Q= X-MC-Unique: v4IDNRgrPmO9mms---R0kw-1 X-Mimecast-MFC-AGG-ID: v4IDNRgrPmO9mms---R0kw X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734808944; x=1735413744; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=E4KdKj6hbbdD8TFVWl0itPd8xJR7/KfGpl+19tzA838=; b=BDNiTYYpmXNfkcD2ryXW0E6tGJsFr1W5MXYoEU7E8vLJQEYc2e4D2o7FNA/IqRvmql XI9ALI0fj/9kpXYsEa57JM9V8o54s7ByTYO9k1H5R2uQ3HO6ogMBv0TCWXJz0yqS44HU gDsgbC+4zurv3ZWzZGL+ndayjx20gNKPx63JA54jJYn8z7REaag6a3wlg9tKdt5NawJo hjM5bwIBz8JmQNp/Cw2DhhxPVrJQZwUQL+VUS9MxZq4KH6QoScDQoNbwpXjCpU8/3PJV qplCBc8AQKA6ndhFl/KUnTcTwiRrRTATRfKysgUxlIYefMElYb+inYKYW1hgA3UJMOyi JVwA== X-Gm-Message-State: AOJu0Yw4SCZUd1XMetuVatzzrH3hxoK8x3gk2Jn651uZAoniya+Dh2yY Pn7Lp0HT8pgEJV0mIytebQ95Um9ZNXkpUR8yISDqPLLEQnwmpf2EtC58f8f8tEqSMVH3TcSFk7C 9i5z3ODr4I0lTDxFu/5iDgXtOpLBBB3yPJHM0a4udxpuGo/Ts8JF34yut6n1LareelnEvX4vltS g8j3gp4WX3gowE3jnfqEJDQQ+GPfmnBB44 X-Gm-Gg: ASbGnctIkQiRpfs+duftFAMudD5G5YAFpZISdGWOCq9IjMH/zMZgDKIPAY5Mh5RUFxm BXLp6yrplsQkTh+1afchTGTGR8I/9mmB0fsF7Re7TKb6w5ygxY9IxcEq5xIhrJ2mnvumf0no8K5 Sfl2dDLym1QZ4CLSmsCDGek71SiZFW+QhVZXYHwH7NTCzgOxWowN8lfRZvm9R801/k6O0MU8qQi MRMpg5o7NQBSDi5f9/0yaTjIPWHagIhNy/7247t0ZtNKjIirzD7ykQusSDplSWvFAcXqx+BuYKl jewTKOpIn9gqcZZGc9CAsMx2Hqmp41rQ2m/hqrg= X-Received: by 2002:a05:6000:402c:b0:385:e9c0:c069 with SMTP id ffacd0b85a97d-38a22408f78mr6058591f8f.57.1734808944589; Sat, 21 Dec 2024 11:22:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IHKXTaedTUGvHalZ1YSe4HqBX1icZJNUv4SuMdvMlag+UD1e5QqNsrpQVZYCuKms7yOUifx3w== X-Received: by 2002:a05:6000:402c:b0:385:e9c0:c069 with SMTP id ffacd0b85a97d-38a22408f78mr6058571f8f.57.1734808944097; Sat, 21 Dec 2024 11:22:24 -0800 (PST) From: David Hildenbrand To: qemu-devel@nongnu.org Cc: Halil Pasic , Christian Borntraeger , Eric Farman , Thomas Huth , Richard Henderson , "Michael S . Tsirkin" , David Hildenbrand Subject: [PULL v2 04/15] s390x/s390-virtio-hcall: prepare for more diag500 hypercalls Date: Sat, 21 Dec 2024 20:21:58 +0100 Message-ID: <20241221192209.3979595-5-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241221192209.3979595-1-david@redhat.com> References: <20241221192209.3979595-1-david@redhat.com> MIME-Version: 1.0 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=170.10.133.124; envelope-from=dhildenb@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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=-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_H2=-1.177, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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.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: 1734809044134116600 Content-Type: text/plain; charset="utf-8" Let's generalize, abstracting the virtio bits. diag500 is now a generic hypercall to handle QEMU/KVM specific things. Explicitly specify all already defined subcodes, including legacy ones (so we know what we can use for new hypercalls). Move the PGM_SPECIFICATION injection into the renamed function handle_diag_500(), so we can turn it into a void function. We'll rename the files separately, so git properly detects the rename. Message-ID: <20241219144115.2820241-4-david@redhat.com> Acked-by: Michael S. Tsirkin Reviewed-by: Thomas Huth Signed-off-by: David Hildenbrand --- hw/s390x/s390-virtio-hcall.c | 15 ++++++++------- hw/s390x/s390-virtio-hcall.h | 11 ++++++----- target/s390x/kvm/kvm.c | 20 +++----------------- target/s390x/tcg/misc_helper.c | 5 +++-- 4 files changed, 20 insertions(+), 31 deletions(-) diff --git a/hw/s390x/s390-virtio-hcall.c b/hw/s390x/s390-virtio-hcall.c index ca49e3cd22..5fb78a719e 100644 --- a/hw/s390x/s390-virtio-hcall.c +++ b/hw/s390x/s390-virtio-hcall.c @@ -1,5 +1,5 @@ /* - * Support for virtio hypercalls on s390 + * Support for QEMU/KVM hypercalls on s390 * * Copyright 2012 IBM Corp. * Author(s): Cornelia Huck @@ -57,18 +57,19 @@ static int handle_virtio_ccw_notify(uint64_t subch_id, = uint64_t data) return 0; } =20 -int s390_virtio_hypercall(CPUS390XState *env) +void handle_diag_500(S390CPU *cpu, uintptr_t ra) { + CPUS390XState *env =3D &cpu->env; const uint64_t subcode =3D env->regs[1]; =20 switch (subcode) { - case KVM_S390_VIRTIO_NOTIFY: + case DIAG500_VIRTIO_NOTIFY: env->regs[2] =3D handle_virtio_notify(env->regs[2]); - return 0; - case KVM_S390_VIRTIO_CCW_NOTIFY: + break; + case DIAG500_VIRTIO_CCW_NOTIFY: env->regs[2] =3D handle_virtio_ccw_notify(env->regs[2], env->regs[= 3]); - return 0; + break; default: - return -EINVAL; + s390_program_interrupt(env, PGM_SPECIFICATION, ra); } } diff --git a/hw/s390x/s390-virtio-hcall.h b/hw/s390x/s390-virtio-hcall.h index 3d9fe147d2..dca456b926 100644 --- a/hw/s390x/s390-virtio-hcall.h +++ b/hw/s390x/s390-virtio-hcall.h @@ -1,5 +1,5 @@ /* - * Support for virtio hypercalls on s390x + * Support for QEMU/KVM hypercalls on s390x * * Copyright IBM Corp. 2012, 2017 * Author(s): Cornelia Huck @@ -12,12 +12,13 @@ #ifndef HW_S390_VIRTIO_HCALL_H #define HW_S390_VIRTIO_HCALL_H =20 -#include "standard-headers/asm-s390/virtio-ccw.h" #include "cpu.h" =20 -/* The only thing that we need from the old kvm_virtio.h file */ -#define KVM_S390_VIRTIO_NOTIFY 0 +#define DIAG500_VIRTIO_NOTIFY 0 /* legacy, implemented as a NOP = */ +#define DIAG500_VIRTIO_RESET 1 /* legacy */ +#define DIAG500_VIRTIO_SET_STATUS 2 /* legacy */ +#define DIAG500_VIRTIO_CCW_NOTIFY 3 /* KVM_S390_VIRTIO_CCW_NOTIFY */ =20 -int s390_virtio_hypercall(CPUS390XState *env); +void handle_diag_500(S390CPU *cpu, uintptr_t ra); =20 #endif /* HW_S390_VIRTIO_HCALL_H */ diff --git a/target/s390x/kvm/kvm.c b/target/s390x/kvm/kvm.c index 32cf70bb19..508403609f 100644 --- a/target/s390x/kvm/kvm.c +++ b/target/s390x/kvm/kvm.c @@ -1492,22 +1492,6 @@ static int handle_e3(S390CPU *cpu, struct kvm_run *r= un, uint8_t ipbl) return r; } =20 -static int handle_hypercall(S390CPU *cpu, struct kvm_run *run) -{ - CPUS390XState *env =3D &cpu->env; - int ret =3D -EINVAL; - -#ifdef CONFIG_S390_CCW_VIRTIO - ret =3D s390_virtio_hypercall(env); -#endif /* CONFIG_S390_CCW_VIRTIO */ - if (ret =3D=3D -EINVAL) { - kvm_s390_program_interrupt(cpu, PGM_SPECIFICATION); - return 0; - } - - return ret; -} - static void kvm_handle_diag_288(S390CPU *cpu, struct kvm_run *run) { uint64_t r1, r3; @@ -1603,9 +1587,11 @@ static int handle_diag(S390CPU *cpu, struct kvm_run = *run, uint32_t ipb) case DIAG_SET_CONTROL_PROGRAM_CODES: handle_diag_318(cpu, run); break; +#ifdef CONFIG_S390_CCW_VIRTIO case DIAG_KVM_HYPERCALL: - r =3D handle_hypercall(cpu, run); + handle_diag_500(cpu, RA_IGNORED); break; +#endif /* CONFIG_S390_CCW_VIRTIO */ case DIAG_KVM_BREAKPOINT: r =3D handle_sw_breakpoint(cpu, run); break; diff --git a/target/s390x/tcg/misc_helper.c b/target/s390x/tcg/misc_helper.c index f44136a568..2b4310003b 100644 --- a/target/s390x/tcg/misc_helper.c +++ b/target/s390x/tcg/misc_helper.c @@ -119,10 +119,11 @@ void HELPER(diag)(CPUS390XState *env, uint32_t r1, ui= nt32_t r3, uint32_t num) switch (num) { #ifdef CONFIG_S390_CCW_VIRTIO case 0x500: - /* KVM hypercall */ + /* QEMU/KVM hypercall */ bql_lock(); - r =3D s390_virtio_hypercall(env); + handle_diag_500(env_archcpu(env), GETPC()); bql_unlock(); + r =3D 0; break; #endif /* CONFIG_S390_CCW_VIRTIO */ case 0x44: --=20 2.47.1 From nobody Mon Dec 23 23:07:39 2024 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=1734809060; cv=none; d=zohomail.com; s=zohoarc; b=S1Z32SXOdpbjNBBDgiclQ8TVYkWs1BKqu84JxSC6492koHtWnT+sECoR7VnGM+BoDWdoSdNVyF9oo749fdM6skhjMjKBa2ko4VUCrXq5eXA4HOgTlkxAkuQldW5WnwTLzIJq8MNn9ZccEkDLIYbVsPiLkEv4BGQgwRsWUdmYDnk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1734809060; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=cAzRLGZnZVq40JVmxNUS9Db1k3+vz0e88yX7zLkG8EY=; b=OcAiStHX9OsCIoT8qHyRbKhsiJnbo4qQXi7RU934uNOR9JO0h8TzDUG7A2LiCkgEcaN0zeQ5nQoJRxmUPdmcaosSzylcElrZgziQMKOzdSdCVQHcuUQV+xZ7EfYBKeXtySK8AwJQjnHcK4A9DJ0ASZ0i7PYMiYCXASCYYyuam+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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1734809059981947.9246930979318; Sat, 21 Dec 2024 11:24:19 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tP53b-0002Oj-7n; Sat, 21 Dec 2024 14:22:35 -0500 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 1tP53Z-0002Nk-Ok for qemu-devel@nongnu.org; Sat, 21 Dec 2024 14:22:33 -0500 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 1tP53X-0000A9-St for qemu-devel@nongnu.org; Sat, 21 Dec 2024 14:22:33 -0500 Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-107-__Ogcn7YP9iowKF0NpFngQ-1; Sat, 21 Dec 2024 14:22:28 -0500 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-3862a49fbdaso1304403f8f.1 for ; Sat, 21 Dec 2024 11:22:27 -0800 (PST) Received: from localhost (p200300cbc7137800820d0e9f08ce52bd.dip0.t-ipconnect.de. [2003:cb:c713:7800:820d:e9f:8ce:52bd]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-38a1c847513sm7189727f8f.49.2024.12.21.11.22.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 21 Dec 2024 11:22:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734808950; 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=cAzRLGZnZVq40JVmxNUS9Db1k3+vz0e88yX7zLkG8EY=; b=MbtLgdv408J62w6LCqgGO8lr7DDk0XA5aAOlnCPcfpnc7IXS9q1o/T6claqtQhQk0WP6xx ZZR7GsKgEyebglptaUeC9GtBdQ1316lOrnfPsrG8vGNSMv4aomcRL5ldxBAVu1x0YIcDRI H1odkvEPG7fzs1pw3K4JOSbRP+oE918= X-MC-Unique: __Ogcn7YP9iowKF0NpFngQ-1 X-Mimecast-MFC-AGG-ID: __Ogcn7YP9iowKF0NpFngQ X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734808947; x=1735413747; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cAzRLGZnZVq40JVmxNUS9Db1k3+vz0e88yX7zLkG8EY=; b=SB0BuFicpBH9cQBW+KfMJQXgSBFo1fnArIof3GpwWc/7Dqn1nwAavY6D961c9JszP8 I/Cex8HEz6NDKFcrOKqFDYRIPTkBpEuALkLMvvAoEWa7/snzPKmYeYbNgtKPG/sl/XZk vjJHs5WX01Da6AOg0Lc2mCP5bDB/9qJlCPvbmF7w7fwvdYBxy/YIomFQTJYIv56iu4dZ eWiHbL55wAmm7wF9lRh+jHir+gs6RfUIhogigDmH6fQRdpX9+C2m8p/qMusahLAVzHcH y56fYiMKnlco05D2FJEBW6SRmifxAwzRnEsjUp24JErsqJqHWnnVoB0d8r2t4xEXKufB lKeA== X-Gm-Message-State: AOJu0YzaasRaZMWFY8VYWAYrbDL7duhCKU7leYLgZosE3LWT6ISUsMhv UAJoY0Wd039X4NcCkOAmGAMU8KPs/EAWoz3fSgc7NfxHf0XKAuI3xPEJlwfDxAoc+PoVaMj1/UL 2M2iWdj/doRJV3+JYMoNKJUkybvpXSDyJDLWBHNoJIH2y79xJegElR44zVgHknjmo1HwHNso7TD ZKlwM1QalD9nanM4t5A4CxvJTDj9W5K0pM X-Gm-Gg: ASbGncvWmQENcPkxLy1gv+GEWehInMehNYNOTFhzF4PWB3UgL6+qfFaiJySoAHyniEJ PkCIpd7tNzSSPxHdIQSsozar2L89rRwhd59MVf1RQJx7mzyblBxNoo5S1ra9uj+Vz+rUicCtfU7 46M8/bvPjuH4awHhlt1pZOq25MShNXWbVlpDk62JNxwVu3dMKf8rHrSBokEJ8PPCW3FX7u8Hu79 o7uGICoti3ay6gcCOEWOGrO/6P9/ps98BVT39EoB+S1UuW159s7gJQOfL0SLkZR4B/qDv2dCESm rS2n44KjqJ7ykPBq3ZWrcbyh93dxswS2eOg41oI= X-Received: by 2002:a05:6000:4029:b0:386:41bd:53a3 with SMTP id ffacd0b85a97d-38a224083afmr6415164f8f.50.1734808946920; Sat, 21 Dec 2024 11:22:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IF9pHyeJRXyOXYuvBQ9gKfmtxyRNZA3ycH4dbL2CYUqBYa7of+GkCkTJjGFQZbAo+/QUDDCaw== X-Received: by 2002:a05:6000:4029:b0:386:41bd:53a3 with SMTP id ffacd0b85a97d-38a224083afmr6415148f8f.50.1734808946458; Sat, 21 Dec 2024 11:22:26 -0800 (PST) From: David Hildenbrand To: qemu-devel@nongnu.org Cc: Halil Pasic , Christian Borntraeger , Eric Farman , Thomas Huth , Richard Henderson , "Michael S . Tsirkin" , David Hildenbrand Subject: [PULL v2 05/15] s390x: rename s390-virtio-hcall* to s390-hypercall* Date: Sat, 21 Dec 2024 20:21:59 +0100 Message-ID: <20241221192209.3979595-6-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241221192209.3979595-1-david@redhat.com> References: <20241221192209.3979595-1-david@redhat.com> MIME-Version: 1.0 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=170.10.129.124; envelope-from=dhildenb@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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=-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_H2=-1.177, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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.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: 1734809062368116600 Content-Type: text/plain; charset="utf-8" Let's make it clearer that we are talking about general QEMU/KVM-specific hypercalls. Message-ID: <20241219144115.2820241-5-david@redhat.com> Acked-by: Michael S. Tsirkin Reviewed-by: Thomas Huth Signed-off-by: David Hildenbrand --- hw/s390x/meson.build | 2 +- hw/s390x/{s390-virtio-hcall.c =3D> s390-hypercall.c} | 2 +- hw/s390x/{s390-virtio-hcall.h =3D> s390-hypercall.h} | 6 +++--- target/s390x/kvm/kvm.c | 2 +- target/s390x/tcg/misc_helper.c | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) rename hw/s390x/{s390-virtio-hcall.c =3D> s390-hypercall.c} (97%) rename hw/s390x/{s390-virtio-hcall.h =3D> s390-hypercall.h} (86%) diff --git a/hw/s390x/meson.build b/hw/s390x/meson.build index d6c8c33915..e344a3bd8c 100644 --- a/hw/s390x/meson.build +++ b/hw/s390x/meson.build @@ -29,7 +29,7 @@ s390x_ss.add(when: 'CONFIG_TCG', if_true: files( )) s390x_ss.add(when: 'CONFIG_S390_CCW_VIRTIO', if_true: files( 's390-virtio-ccw.c', - 's390-virtio-hcall.c', + 's390-hypercall.c', )) s390x_ss.add(when: 'CONFIG_TERMINAL3270', if_true: files('3270-ccw.c')) s390x_ss.add(when: 'CONFIG_VFIO', if_true: files('s390-pci-vfio.c')) diff --git a/hw/s390x/s390-virtio-hcall.c b/hw/s390x/s390-hypercall.c similarity index 97% rename from hw/s390x/s390-virtio-hcall.c rename to hw/s390x/s390-hypercall.c index 5fb78a719e..f816c2b1ef 100644 --- a/hw/s390x/s390-virtio-hcall.c +++ b/hw/s390x/s390-hypercall.c @@ -12,7 +12,7 @@ #include "qemu/osdep.h" #include "cpu.h" #include "hw/boards.h" -#include "hw/s390x/s390-virtio-hcall.h" +#include "hw/s390x/s390-hypercall.h" #include "hw/s390x/ioinst.h" #include "hw/s390x/css.h" #include "virtio-ccw.h" diff --git a/hw/s390x/s390-virtio-hcall.h b/hw/s390x/s390-hypercall.h similarity index 86% rename from hw/s390x/s390-virtio-hcall.h rename to hw/s390x/s390-hypercall.h index dca456b926..2fa81dbfdd 100644 --- a/hw/s390x/s390-virtio-hcall.h +++ b/hw/s390x/s390-hypercall.h @@ -9,8 +9,8 @@ * directory. */ =20 -#ifndef HW_S390_VIRTIO_HCALL_H -#define HW_S390_VIRTIO_HCALL_H +#ifndef HW_S390_HYPERCALL_H +#define HW_S390_HYPERCALL_H =20 #include "cpu.h" =20 @@ -21,4 +21,4 @@ =20 void handle_diag_500(S390CPU *cpu, uintptr_t ra); =20 -#endif /* HW_S390_VIRTIO_HCALL_H */ +#endif /* HW_S390_HYPERCALL_H */ diff --git a/target/s390x/kvm/kvm.c b/target/s390x/kvm/kvm.c index 508403609f..7a3e1a8e1e 100644 --- a/target/s390x/kvm/kvm.c +++ b/target/s390x/kvm/kvm.c @@ -49,7 +49,7 @@ #include "hw/s390x/ebcdic.h" #include "exec/memattrs.h" #include "hw/s390x/s390-virtio-ccw.h" -#include "hw/s390x/s390-virtio-hcall.h" +#include "hw/s390x/s390-hypercall.h" #include "target/s390x/kvm/pv.h" #include CONFIG_DEVICES =20 diff --git a/target/s390x/tcg/misc_helper.c b/target/s390x/tcg/misc_helper.c index 2b4310003b..b726a95352 100644 --- a/target/s390x/tcg/misc_helper.c +++ b/target/s390x/tcg/misc_helper.c @@ -36,7 +36,7 @@ #include "sysemu/cpus.h" #include "sysemu/sysemu.h" #include "hw/s390x/ebcdic.h" -#include "hw/s390x/s390-virtio-hcall.h" +#include "hw/s390x/s390-hypercall.h" #include "hw/s390x/sclp.h" #include "hw/s390x/s390_flic.h" #include "hw/s390x/ioinst.h" --=20 2.47.1 From nobody Mon Dec 23 23:07:39 2024 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=1734809090; cv=none; d=zohomail.com; s=zohoarc; b=VhzopEoVRCsEuPfA5g6dP47pExaz+lQ6CfytBQ8XgNPUDT8ujgRLCallrmLwO3rjbRUMW9xbRm1dHjGz5yUNuB/DrbyiG62lwhQDpl0OpnjdxUeZhG+YHJjb9q6eMJC6j2x9DrpbZpoaSwlW3T9h5jekqYCQfc20eh0OIEfvy5Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1734809090; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Ix5+P2+O/8/1G7e8VURHN6Qpsguw8mKubl01oxtB8Go=; b=dSJRKbUcy/TY5NE3cmmwQKsgb5udoI75sZXVp5pYRn2JxXaqUR3vneqlOcwqXeA733TFY2zQ8X65ZZicV1n+56h7I2QCzB0FRCh/hGt0Zm0fVga9RBUrXh4rQ5bb1FGhy2aJfKym59DQHSPwULIK3ftWclUktgHiIn6a5RDJe+c= 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 1734809090151163.64107971969054; Sat, 21 Dec 2024 11:24:50 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tP53d-0002PG-IC; Sat, 21 Dec 2024 14:22:37 -0500 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 1tP53c-0002P1-Fb for qemu-devel@nongnu.org; Sat, 21 Dec 2024 14:22:36 -0500 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 1tP53a-0000Ch-V4 for qemu-devel@nongnu.org; Sat, 21 Dec 2024 14:22:36 -0500 Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-371-Q0ZdrfWoORmZe3oxH_RcwQ-1; Sat, 21 Dec 2024 14:22:30 -0500 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-385df115288so1411033f8f.2 for ; Sat, 21 Dec 2024 11:22:30 -0800 (PST) Received: from localhost (p200300cbc7137800820d0e9f08ce52bd.dip0.t-ipconnect.de. [2003:cb:c713:7800:820d:e9f:8ce:52bd]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-38a1c89e375sm7247774f8f.73.2024.12.21.11.22.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 21 Dec 2024 11:22:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734808954; 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=Ix5+P2+O/8/1G7e8VURHN6Qpsguw8mKubl01oxtB8Go=; b=QKcuZI/eS+6jgVI6ZcPYRNtw5sV1F1HU1W6RC2VPmjakP196HRKFYoSO4JsVegs2GiMcEf 2ZJgw9lz3EH/eQJq22UqxnXzJml3csY80Gc1aXe90h+weqnXVFXeCJx+Zvvl90FxqNO/jf 3Ia7OepdW2hnoRSncR6PQ8pn2rWT100= X-MC-Unique: Q0ZdrfWoORmZe3oxH_RcwQ-1 X-Mimecast-MFC-AGG-ID: Q0ZdrfWoORmZe3oxH_RcwQ X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734808949; x=1735413749; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ix5+P2+O/8/1G7e8VURHN6Qpsguw8mKubl01oxtB8Go=; b=Ae5VLXeNBMyiJVhdFcWn5fxxOukvSl3q5sJRCznQOdV3ryskAwW3CfKmENiEE2i6AQ okHQ0Q7xBU1krVmZr9P82ynKWS5wjZe1SQHtPp4wTcFBWdGVgczE1nZNXVjexscXFBNR 8QzxVu1Hdv9cIl1Y1MAf6KddEFB5tHW/J1rh52PzBCfx0Z4kbgqS+hc0e7RBv7rvRuSV 1xRRMsdPZeFA+ndrU/mzPuQq3ErhTrXksM2njZiBiQkWySk/htVfu+dfSYBpqQcbwv0D 4kk3tH8dMScXV3riynZHEaJx/O9PserF3JuwsZD8TT3iANBQVbVQUthIefcdPwt3rfKe NaLQ== X-Gm-Message-State: AOJu0Yzbg4DQ701agnrpg8/WE6wSRBrEU0WQta72AHGRoRpJq9j9tPUy 1kh6YhBVAPdekfkEsJbACcFgOtp98lrzqVvY0FvyAhDteSiap4fuXlTY1jrhla3yNMdTE6h/Ecp wMxA2RTGB1SqvvhtZzV8Ha9u3oWftsESiHfTrfo3qIkJORie0xikYEAAXsSG7LlpMcPpHalRxdf psu+yr9YIHUXYkhM6LaXGCD+VsSFIETYUG X-Gm-Gg: ASbGnctgaRo4dvPcgwDWCKYpF9cqL07tHYgkz6FwsTqcduDf5PkmTpFYzfN+ONQ/ZEM GlaCSsSdv6o0u7nbG7t5dKAgGM8bv1PhD1HsIq6p1ZAnjRsMU/zqL/OjaBea2+U69QDQpAUaWfC bIQz2Bm1f/dUv94n+tI6cR7XImOzGqztafj93CpM85itxwCSntqt180z6NdXPEh9uR995V6tTRq Mq8pAZ9MWi4OXHw6GmE1GZHeEATlw6VOJ4QLkk3qyJudn0Lba5Qsxurz00QCQGvXvaVbKqHfum8 mHLlUcJbD+umin+afc0SsX2KMzqc6nMFoRpfL0o= X-Received: by 2002:a5d:5f4f:0:b0:386:391e:bc75 with SMTP id ffacd0b85a97d-38a221fa986mr5966806f8f.16.1734808949260; Sat, 21 Dec 2024 11:22:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IEl5W9lgAiXWZ6dKwCSh+jjhDP/OEEi+VRKig3aNjXEkqBHiYT2xdCpOBjqVYkPLi47AbopeA== X-Received: by 2002:a5d:5f4f:0:b0:386:391e:bc75 with SMTP id ffacd0b85a97d-38a221fa986mr5966787f8f.16.1734808948814; Sat, 21 Dec 2024 11:22:28 -0800 (PST) From: David Hildenbrand To: qemu-devel@nongnu.org Cc: Halil Pasic , Christian Borntraeger , Eric Farman , Thomas Huth , Richard Henderson , "Michael S . Tsirkin" , David Hildenbrand Subject: [PULL v2 06/15] s390x/s390-virtio-ccw: move setting the maximum guest size from sclp to machine code Date: Sat, 21 Dec 2024 20:22:00 +0100 Message-ID: <20241221192209.3979595-7-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241221192209.3979595-1-david@redhat.com> References: <20241221192209.3979595-1-david@redhat.com> MIME-Version: 1.0 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=170.10.129.124; envelope-from=dhildenb@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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=-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_H2=-1.177, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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.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: 1734809092254116600 Content-Type: text/plain; charset="utf-8" Nowadays, it feels more natural to have that code located in s390_memory_init(), where we also have direct access to the machine object. While at it, use the actual RAM size, not the maximum RAM size which cannot currently be reached without support for any memory devices. Consequently update s390_pv_vm_try_disable_async() to rely on the RAM size as well, to avoid temporary issues while we further rework that handling. set_memory_limit() is temporary, we'll merge it with s390_set_memory_limit() next. Message-ID: <20241219144115.2820241-6-david@redhat.com> Acked-by: Michael S. Tsirkin Reviewed-by: Thomas Huth Signed-off-by: David Hildenbrand --- hw/s390x/s390-virtio-ccw.c | 28 ++++++++++++++++++++++++---- hw/s390x/sclp.c | 11 ----------- target/s390x/kvm/pv.c | 2 +- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c index b0edaa0872..a28e615c5a 100644 --- a/hw/s390x/s390-virtio-ccw.c +++ b/hw/s390x/s390-virtio-ccw.c @@ -121,11 +121,29 @@ static void subsystem_reset(void) } } =20 -static void s390_memory_init(MemoryRegion *ram) +static void set_memory_limit(uint64_t new_limit) +{ + uint64_t hw_limit; + int ret; + + ret =3D s390_set_memory_limit(new_limit, &hw_limit); + if (ret =3D=3D -E2BIG) { + error_report("host supports a maximum of %" PRIu64 " GB", + hw_limit / GiB); + exit(EXIT_FAILURE); + } else if (ret) { + error_report("setting the guest size failed"); + exit(EXIT_FAILURE); + } +} + +static void s390_memory_init(MachineState *machine) { MemoryRegion *sysmem =3D get_system_memory(); + MemoryRegion *ram =3D machine->ram; + uint64_t ram_size =3D memory_region_size(ram); =20 - if (!QEMU_IS_ALIGNED(memory_region_size(ram), 1 * MiB)) { + if (!QEMU_IS_ALIGNED(ram_size, 1 * MiB)) { /* * SCLP cannot possibly expose smaller granularity right now and K= VM * cannot handle smaller granularity. As we don't support NUMA, the @@ -136,7 +154,9 @@ static void s390_memory_init(MemoryRegion *ram) exit(EXIT_FAILURE); } =20 - /* allocate RAM for core */ + set_memory_limit(ram_size); + + /* Map the initial memory. Must happen after setting the memory limit.= */ memory_region_add_subregion(sysmem, 0, ram); =20 /* @@ -211,7 +231,7 @@ static void ccw_init(MachineState *machine) qdev_realize_and_unref(DEVICE(ms->sclp), NULL, &error_fatal); =20 /* init memory + setup max page size. Required for the CPU model */ - s390_memory_init(machine->ram); + s390_memory_init(machine); =20 /* init CPUs (incl. CPU model) early so s390_has_feature() works */ s390_init_cpus(machine); diff --git a/hw/s390x/sclp.c b/hw/s390x/sclp.c index 8757626b5c..73e88ab4eb 100644 --- a/hw/s390x/sclp.c +++ b/hw/s390x/sclp.c @@ -376,10 +376,7 @@ void sclp_service_interrupt(uint32_t sccb) /* qemu object creation and initialization functions */ static void sclp_realize(DeviceState *dev, Error **errp) { - MachineState *machine =3D MACHINE(qdev_get_machine()); SCLPDevice *sclp =3D SCLP(dev); - uint64_t hw_limit; - int ret; =20 /* * qdev_device_add searches the sysbus for TYPE_SCLP_EVENTS_BUS. As lo= ng @@ -389,14 +386,6 @@ static void sclp_realize(DeviceState *dev, Error **err= p) if (!sysbus_realize(SYS_BUS_DEVICE(sclp->event_facility), errp)) { return; } - - ret =3D s390_set_memory_limit(machine->maxram_size, &hw_limit); - if (ret =3D=3D -E2BIG) { - error_setg(errp, "host supports a maximum of %" PRIu64 " GB", - hw_limit / GiB); - } else if (ret) { - error_setg(errp, "setting the guest size failed"); - } } =20 static void sclp_memory_init(SCLPDevice *sclp) diff --git a/target/s390x/kvm/pv.c b/target/s390x/kvm/pv.c index dde836d21a..424cce75ca 100644 --- a/target/s390x/kvm/pv.c +++ b/target/s390x/kvm/pv.c @@ -133,7 +133,7 @@ bool s390_pv_vm_try_disable_async(S390CcwMachineState *= ms) * If the feature is not present or if the VM is not larger than 2 GiB, * KVM_PV_ASYNC_CLEANUP_PREPARE fill fail; no point in attempting it. */ - if ((MACHINE(ms)->maxram_size <=3D 2 * GiB) || + if ((MACHINE(ms)->ram_size <=3D 2 * GiB) || !kvm_check_extension(kvm_state, KVM_CAP_S390_PROTECTED_ASYNC_DISAB= LE)) { return false; } --=20 2.47.1 From nobody Mon Dec 23 23:07:39 2024 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=1734809069; cv=none; d=zohomail.com; s=zohoarc; b=ml2TLQl5I4SI0egvoVwgrMXfui98nuPU9fPukhikDyiht2fvpiBF6jZjasKLFzFb5ULKJBCqiypcQgaqEhaTF7x8W67Iixj6jUVSgYpakFoOxi5qbt/Du3STppKVbFVkWGb7BTXpE/mrrQynUwkx1FrClgbUwZyB50uNyTpCHG0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1734809069; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=WGu+ZgEzN6rOk3pd4wJ9ZrVZQ7N/0arOChZXYIBy5JE=; b=NuLYlayP8SWO1WluhJY1MQeuIhyfzS+J29qxz1Lt/e0AbMtAhTPUct58g8DS4b1X3VlirVvK2rpaJQT+hF6ufYL5pAsla3Kpusfwj/1V4QYZa7/ezs7XDk39MQvEvYwbFVGRLYKMfkU0ds4SCNJIFtMU8dm81RU9lM0wYrugNvQ= 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 1734809069249214.37590584076054; Sat, 21 Dec 2024 11:24:29 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tP53i-0002QZ-2e; Sat, 21 Dec 2024 14:22:42 -0500 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 1tP53g-0002Po-3J for qemu-devel@nongnu.org; Sat, 21 Dec 2024 14:22:40 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tP53e-0000Fh-I2 for qemu-devel@nongnu.org; Sat, 21 Dec 2024 14:22:39 -0500 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-70-2CqSwec5PWSxhKUuhVQUmA-1; Sat, 21 Dec 2024 14:22:33 -0500 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4361d4e8359so24050805e9.3 for ; Sat, 21 Dec 2024 11:22:33 -0800 (PST) Received: from localhost (p200300cbc7137800820d0e9f08ce52bd.dip0.t-ipconnect.de. [2003:cb:c713:7800:820d:e9f:8ce:52bd]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-43656b013e1sm116101925e9.12.2024.12.21.11.22.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 21 Dec 2024 11:22:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734808958; 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=WGu+ZgEzN6rOk3pd4wJ9ZrVZQ7N/0arOChZXYIBy5JE=; b=QNWRXC8s802hZY3I+MNCIyev4J6i8LkX36AonToHunU0OOJmpj5p90PTcE6Jymzcvl+ZQ1 kzE4vkkKue+m9KETA3APX9DY6+U4pdk+PxYrUZILGduYl0czVtFyM2RJ/ovyfzuWqu0Tcu Dz279e74CI/p1oL4BTc6Q8sOXAuqWjM= X-MC-Unique: 2CqSwec5PWSxhKUuhVQUmA-1 X-Mimecast-MFC-AGG-ID: 2CqSwec5PWSxhKUuhVQUmA X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734808952; x=1735413752; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WGu+ZgEzN6rOk3pd4wJ9ZrVZQ7N/0arOChZXYIBy5JE=; b=jzuVwf4p9sRQs/VFZKnTToQ1Le04FBuVgTs4gZc9h0GxofDgNYtWClMrP8uP8fLYXg R6XTHhCHDKTmGT/GA5mlNvTYHWKGC2o2uu6NzzOZT0CMItT4yIrQWebs9lG+gaUCAJhn V1prVhqPng2X7wXEwM6SpuKZ9hTWXk8jJ2U/rDGRu3p4ifh3wbVE+xJfdPjyu0q/oHyK TDdyAe7G2yshCMCwdSDpN77e6mH+pmUqPBsoActxZWGCk2LwtGk/pQSMCo0J9ki6RBs1 6HKq9MC+Q2IYH5fhRYFYxycojxZcFAakpOjOCn7vdxm9SiST3Pu5+yitPb3SsfecymLc 604g== X-Gm-Message-State: AOJu0YyVpH4fyOXYjO6h8vEDez9Pqw3E/qFz0ljXcy05St7TgK81PAwA UxXpmgysFonExcHFdhAVIn/uOHJpJYuqZnaf7o0beJT0cU15GcaUBjMIt5baFJlLK+5odnE5Q9i X3E5LqKHCCU8TAvwWenPxnhSieC3rfM8GDNJ1ZFPAH75FV51bPzf3W+MFAbW7mTUZL1qpbKzk/7 jcXSicCnU62xDZpCZZC+vYZLuvwt2ruwOH X-Gm-Gg: ASbGnctMGZmNDPGmEP87/gCs/nvA8WPezyPz/SAw2+/hTpfbHDHnHQ7u5AoYO2+yjop 1vaghclXx6fFO+CQhGmEHqHh7BXK3frlZNwfwWPEgH07HnwsSW2v7knI6rH+bNYgDkV4HSsNlgN /ZK2KO2Y5Qy5CHjV+iVyDREMI/BPmOh4qi9OpgmoPsdv3hSB93ZdJ5Dtvf2mNXeK5sANWSLoBlv UaZfX3Wyu6PMjI80Nl9yZxWOHEO4am49bytJRaPomYm+sOPrGgpU8XT1vqomBlYIeqKJTVanUw7 ap9a1Y0EspwCEH86opHBnNnSI4uDBUrFCfkAf9o= X-Received: by 2002:a05:600c:1c9f:b0:435:32e:8270 with SMTP id 5b1f17b1804b1-43668642f9dmr64362115e9.14.1734808952329; Sat, 21 Dec 2024 11:22:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IHbcpUo2QHaH1qNNe1W6Y0nGzocSMkcNLPSdOhbQKDjoS8NwH56ptqwQBRL5iaJo6gKThICug== X-Received: by 2002:a05:600c:1c9f:b0:435:32e:8270 with SMTP id 5b1f17b1804b1-43668642f9dmr64361995e9.14.1734808951918; Sat, 21 Dec 2024 11:22:31 -0800 (PST) From: David Hildenbrand To: qemu-devel@nongnu.org Cc: Halil Pasic , Christian Borntraeger , Eric Farman , Thomas Huth , Richard Henderson , "Michael S . Tsirkin" , David Hildenbrand Subject: [PULL v2 07/15] s390x: introduce s390_get_memory_limit() Date: Sat, 21 Dec 2024 20:22:01 +0100 Message-ID: <20241221192209.3979595-8-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241221192209.3979595-1-david@redhat.com> References: <20241221192209.3979595-1-david@redhat.com> MIME-Version: 1.0 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=170.10.133.124; envelope-from=dhildenb@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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=-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_H2=-1.177, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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.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: 1734809070292116600 Content-Type: text/plain; charset="utf-8" Let's add s390_get_memory_limit(), to query what has been successfully set via s390_set_memory_limit(). Allow setting the limit only once. We'll remember the limit in the machine state. Move s390_set_memory_limit() to machine code, merging it into set_memory_limit(), because this really is a machine property. Message-ID: <20241219144115.2820241-7-david@redhat.com> Acked-by: Michael S. Tsirkin Reviewed-by: Thomas Huth Signed-off-by: David Hildenbrand --- hw/s390x/s390-virtio-ccw.c | 17 ++++++++++++----- include/hw/s390x/s390-virtio-ccw.h | 8 ++++++++ target/s390x/cpu-sysemu.c | 8 -------- target/s390x/cpu.h | 1 - 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c index a28e615c5a..1c56b70dcd 100644 --- a/hw/s390x/s390-virtio-ccw.c +++ b/hw/s390x/s390-virtio-ccw.c @@ -45,6 +45,7 @@ #include "migration/blocker.h" #include "qapi/visitor.h" #include "hw/s390x/cpu-topology.h" +#include "kvm/kvm_s390x.h" #include CONFIG_DEVICES =20 static Error *pv_mig_blocker; @@ -121,12 +122,16 @@ static void subsystem_reset(void) } } =20 -static void set_memory_limit(uint64_t new_limit) +static void s390_set_memory_limit(S390CcwMachineState *s390ms, + uint64_t new_limit) { - uint64_t hw_limit; - int ret; + uint64_t hw_limit =3D 0; + int ret =3D 0; =20 - ret =3D s390_set_memory_limit(new_limit, &hw_limit); + assert(!s390ms->memory_limit && new_limit); + if (kvm_enabled()) { + ret =3D kvm_s390_set_mem_limit(new_limit, &hw_limit); + } if (ret =3D=3D -E2BIG) { error_report("host supports a maximum of %" PRIu64 " GB", hw_limit / GiB); @@ -135,10 +140,12 @@ static void set_memory_limit(uint64_t new_limit) error_report("setting the guest size failed"); exit(EXIT_FAILURE); } + s390ms->memory_limit =3D new_limit; } =20 static void s390_memory_init(MachineState *machine) { + S390CcwMachineState *s390ms =3D S390_CCW_MACHINE(machine); MemoryRegion *sysmem =3D get_system_memory(); MemoryRegion *ram =3D machine->ram; uint64_t ram_size =3D memory_region_size(ram); @@ -154,7 +161,7 @@ static void s390_memory_init(MachineState *machine) exit(EXIT_FAILURE); } =20 - set_memory_limit(ram_size); + s390_set_memory_limit(s390ms, ram_size); =20 /* Map the initial memory. Must happen after setting the memory limit.= */ memory_region_add_subregion(sysmem, 0, ram); diff --git a/include/hw/s390x/s390-virtio-ccw.h b/include/hw/s390x/s390-vir= tio-ccw.h index 996864a34e..de04336c5a 100644 --- a/include/hw/s390x/s390-virtio-ccw.h +++ b/include/hw/s390x/s390-virtio-ccw.h @@ -29,10 +29,18 @@ struct S390CcwMachineState { bool dea_key_wrap; bool pv; uint8_t loadparm[8]; + uint64_t memory_limit; =20 SCLPDevice *sclp; }; =20 +static inline uint64_t s390_get_memory_limit(S390CcwMachineState *s390ms) +{ + /* We expect to be called only after the limit was set. */ + assert(s390ms->memory_limit); + return s390ms->memory_limit; +} + #define S390_PTF_REASON_NONE (0x00 << 8) #define S390_PTF_REASON_DONE (0x01 << 8) #define S390_PTF_REASON_BUSY (0x02 << 8) diff --git a/target/s390x/cpu-sysemu.c b/target/s390x/cpu-sysemu.c index 1cd30c1d84..3118a25fee 100644 --- a/target/s390x/cpu-sysemu.c +++ b/target/s390x/cpu-sysemu.c @@ -255,14 +255,6 @@ unsigned int s390_cpu_set_state(uint8_t cpu_state, S39= 0CPU *cpu) return s390_count_running_cpus(); } =20 -int s390_set_memory_limit(uint64_t new_limit, uint64_t *hw_limit) -{ - if (kvm_enabled()) { - return kvm_s390_set_mem_limit(new_limit, hw_limit); - } - return 0; -} - void s390_set_max_pagesize(uint64_t pagesize, Error **errp) { if (kvm_enabled()) { diff --git a/target/s390x/cpu.h b/target/s390x/cpu.h index 5ef61b1f75..b4506539f0 100644 --- a/target/s390x/cpu.h +++ b/target/s390x/cpu.h @@ -881,7 +881,6 @@ static inline void s390_do_cpu_load_normal(CPUState *cs= , run_on_cpu_data arg) =20 /* cpu.c */ void s390_crypto_reset(void); -int s390_set_memory_limit(uint64_t new_limit, uint64_t *hw_limit); void s390_set_max_pagesize(uint64_t pagesize, Error **errp); void s390_cmma_reset(void); void s390_enable_css_support(S390CPU *cpu); --=20 2.47.1 From nobody Mon Dec 23 23:07:39 2024 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=1734809029; cv=none; d=zohomail.com; s=zohoarc; b=XiglFcUEvqaZnrU5+4HD7lKsDI8heRNSxxqGe62hxaX1qiO1iHaBYnuNpmpUviZgDN0gSC1ZBneBNZof6Cmq1abWSsVA7lNzxZV859wzB/eRjJ9Wsdm4yn/ovxF9kQR3mu8r2cdRvX/3/kiDhN5O70RARGeQiEPuHLAJfnKVpdg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1734809029; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=rqKCWQR3QB2io/MyyfabdA53d/IBhffWJa6uY0wK/vs=; b=aFesG8XHgYPKJTp+2Fp+gMFAUmtPJ/989WV+j3g4husPa65bUIKaVJppQJF/MotZCDUrvgko0pyETXFClXvD0eI/ownhc3v1+VsBRw4cL8b2bxg/iXdgJ8DMJu28l/O/UYXLpxBIxTn9/Zzg+K/j0q8RuKSN+Va7Jmqday0qWUw= 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 1734809029094893.0821856982393; Sat, 21 Dec 2024 11:23:49 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tP53g-0002Pz-Dg; Sat, 21 Dec 2024 14:22:40 -0500 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 1tP53f-0002PZ-Bq for qemu-devel@nongnu.org; Sat, 21 Dec 2024 14:22:39 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tP53d-0000FP-VL for qemu-devel@nongnu.org; Sat, 21 Dec 2024 14:22:39 -0500 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-382-FtsSCamHOyaOxWv7MENjwQ-1; Sat, 21 Dec 2024 14:22:35 -0500 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-436289a570eso24136085e9.0 for ; Sat, 21 Dec 2024 11:22:35 -0800 (PST) Received: from localhost (p200300cbc7137800820d0e9f08ce52bd.dip0.t-ipconnect.de. [2003:cb:c713:7800:820d:e9f:8ce:52bd]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-4366120088esm82859165e9.13.2024.12.21.11.22.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 21 Dec 2024 11:22:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734808957; 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=rqKCWQR3QB2io/MyyfabdA53d/IBhffWJa6uY0wK/vs=; b=LQdJ2NjTNOYjppsIN3KDFrNqWZ73hJRZA6aixhfO0A9+zTHrt5QwlSKvXCxsuOvIBQ6jfg oRr79QGlq5S/MWRybqD7g9GOrWBaetaMy9BL84A2JNO0HhKL5ywoJdy5s9V1FZ3V06wp6W kCmyF9X+rO4xQZ/6ak8QW9gI14XW2tw= X-MC-Unique: FtsSCamHOyaOxWv7MENjwQ-1 X-Mimecast-MFC-AGG-ID: FtsSCamHOyaOxWv7MENjwQ X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734808954; x=1735413754; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rqKCWQR3QB2io/MyyfabdA53d/IBhffWJa6uY0wK/vs=; b=CQEkS76HkQTWz471hNZFgrHlp559nMGMEJTaXRuxFXlOHR11A+E8bliK1/ySl+65Dk QenGWZIA5GsoeUZ3ATISK/uCfV0/ESiz2U2aqEfWBazS6PiuX7OIRZRUIdPlHpYkJwYJ MRNTKaSPwUPZorE5k4tJGRVg/Zp2zFKoK1xyDTRkF1rR/NVKQib2QSOeGYVGQ+USSN2t ur4DHma0gpnMNwD0+q4qZ1d3TspY8ghJ1FoUMOob6XxelKQatfvCt2FT4XLhySrSmfGF sQ0fNGl5JAx2EkGNDhFipGopWtvhf3BA7FTT419dKpM6es8sPlpsnGF3bIH8LflAJsSG Ovgg== X-Gm-Message-State: AOJu0YxWw7OORPaiCBux+FhgrRIa8tvF2RNjBS4GGHc0BG3h4tJEw3I2 hW4IgH1FZl4MzTHroeZnsoAwuCCNtlL20dt906WaXQxTM55TQOwMhVUMfMVdFFHOHLuhqtTf3wd TAxsl8oXyQv18rp+3wri95NIJ2iId1f/qoannXlR76gPHcHq3mZ8kiV/8B/tTMAikQM1DdnWy0r sBYiRod6gXobj6hlRWHA5EDYhyeOIJYvas X-Gm-Gg: ASbGncvUMeXDxVggT+YP+EdVzLA9lZxl5oEvXRAETXDpO0P87schQhnPLTAWyKhKlbR T92ryqrXctzqoHxX09AvFPZ7m9OTXaf1EcnLpZEIqhcC2+2Ua9VcFWfFWldQKjaLg4BzU7gfsFb o00qJ4PVQkNQGhDbXwFH5SlGadTvmXWxajb8SF1yqHu19G/D73kouxucoKZpgIzhuKIzb3qTKYj DhAAwpPbIw7PLGbjTKHLdrGuDSZ6sr4RViT/2NDy7XhQczAab9SG4tljgGuS8Bq8wVBGPpyPeiE uA2g+KJiIidtJPYBHDlL8SUE/4gAB4FQ25nwqnA= X-Received: by 2002:a5d:584c:0:b0:385:d7f9:f16c with SMTP id ffacd0b85a97d-38a223f758emr6888107f8f.46.1734808954547; Sat, 21 Dec 2024 11:22:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IFkftMM59mvDXCH8p49S8A7Ny/OME7qNNogDTT/MUi6oCR3zMBAP698T0J34AXc74CpSLn6Vw== X-Received: by 2002:a5d:584c:0:b0:385:d7f9:f16c with SMTP id ffacd0b85a97d-38a223f758emr6888083f8f.46.1734808954127; Sat, 21 Dec 2024 11:22:34 -0800 (PST) From: David Hildenbrand To: qemu-devel@nongnu.org Cc: Halil Pasic , Christian Borntraeger , Eric Farman , Thomas Huth , Richard Henderson , "Michael S . Tsirkin" , David Hildenbrand Subject: [PULL v2 08/15] s390x/s390-hypercall: introduce DIAG500 STORAGE_LIMIT Date: Sat, 21 Dec 2024 20:22:02 +0100 Message-ID: <20241221192209.3979595-9-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241221192209.3979595-1-david@redhat.com> References: <20241221192209.3979595-1-david@redhat.com> MIME-Version: 1.0 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=170.10.133.124; envelope-from=dhildenb@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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=-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_H2=-1.177, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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.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: 1734809030199116600 Content-Type: text/plain; charset="utf-8" A guest OS that supports memory hotplug / memory devices must during boot be aware of the maximum possible physical memory address that it might have to handle at a later stage during its runtime. For example, the maximum possible memory address might be required to prepare the kernel virtual address space accordingly (e.g., select page table hierarchy depth). On s390x there is currently no such mechanism that is compatible with paravirtualized memory devices, because the whole SCLP interface was designed around the idea of "storage increments" and "standby memory". Paravirtualized memory devices we want to support, such as virtio-mem, have no intersection with any of that, but could co-exist with them in the future if ever needed. In particular, a guest OS must never detect and use device memory without the help of a proper device driver. Device memory must not be exposed in any firmware-provided memory map (SCLP or diag260 on s390x). For this reason, these memory devices will be places in memory *above* the "maximum storage increment" exposed via SCLP. Let's provide a new diag500 subcode to query the memory limit determined in s390_memory_init(). Message-ID: <20241219144115.2820241-8-david@redhat.com> Acked-by: Michael S. Tsirkin Reviewed-by: Thomas Huth Signed-off-by: David Hildenbrand --- hw/s390x/s390-hypercall.c | 12 +++++++++++- hw/s390x/s390-hypercall.h | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/hw/s390x/s390-hypercall.c b/hw/s390x/s390-hypercall.c index f816c2b1ef..ac1b08b2cd 100644 --- a/hw/s390x/s390-hypercall.c +++ b/hw/s390x/s390-hypercall.c @@ -11,7 +11,7 @@ =20 #include "qemu/osdep.h" #include "cpu.h" -#include "hw/boards.h" +#include "hw/s390x/s390-virtio-ccw.h" #include "hw/s390x/s390-hypercall.h" #include "hw/s390x/ioinst.h" #include "hw/s390x/css.h" @@ -57,6 +57,13 @@ static int handle_virtio_ccw_notify(uint64_t subch_id, u= int64_t data) return 0; } =20 +static uint64_t handle_storage_limit(void) +{ + S390CcwMachineState *s390ms =3D S390_CCW_MACHINE(qdev_get_machine()); + + return s390_get_memory_limit(s390ms) - 1; +} + void handle_diag_500(S390CPU *cpu, uintptr_t ra) { CPUS390XState *env =3D &cpu->env; @@ -69,6 +76,9 @@ void handle_diag_500(S390CPU *cpu, uintptr_t ra) case DIAG500_VIRTIO_CCW_NOTIFY: env->regs[2] =3D handle_virtio_ccw_notify(env->regs[2], env->regs[= 3]); break; + case DIAG500_STORAGE_LIMIT: + env->regs[2] =3D handle_storage_limit(); + break; default: s390_program_interrupt(env, PGM_SPECIFICATION, ra); } diff --git a/hw/s390x/s390-hypercall.h b/hw/s390x/s390-hypercall.h index 2fa81dbfdd..4f07209128 100644 --- a/hw/s390x/s390-hypercall.h +++ b/hw/s390x/s390-hypercall.h @@ -18,6 +18,7 @@ #define DIAG500_VIRTIO_RESET 1 /* legacy */ #define DIAG500_VIRTIO_SET_STATUS 2 /* legacy */ #define DIAG500_VIRTIO_CCW_NOTIFY 3 /* KVM_S390_VIRTIO_CCW_NOTIFY */ +#define DIAG500_STORAGE_LIMIT 4 =20 void handle_diag_500(S390CPU *cpu, uintptr_t ra); =20 --=20 2.47.1 From nobody Mon Dec 23 23:07:39 2024 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=1734809079; cv=none; d=zohomail.com; s=zohoarc; b=Jt1qNUdBIlbIFpZgnnfPwx/aDi3bA5I+Ye0qyZzU45M5e4mlVDpvAHLJtT+Fym30BdrBLI+BX5QuKtZ9WK3iuWnqLTts1W10duPNaYILLm8LSobivP8k2Gsd/jJJt3gbBYwOX61Iyv1LQG0yeye/SGh/OCHW367aNO7UDaN8QR8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1734809079; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=TyHETmSFfRkani9FLrh+iELen8TJf3jh3hXnkuxCM7M=; b=MVzBRVzPfayoCpITpIqvd9CK8GbeP4BoqkZY8hkEZGHRffuP33IIuvLJczidoCmVVDnk8aH39DQ7J9oqWbvFAJkvxxG+V2Xt70dsd7I6NODcu93JOLm0KhYtxqv7W0hXU5Nlzzp1CjdBzpuVDShDahmbTpDZ5nqmYBCkv9lCqRo= 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 1734809079667431.3459107650033; Sat, 21 Dec 2024 11:24:39 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tP53l-0002R6-JT; Sat, 21 Dec 2024 14:22:45 -0500 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 1tP53k-0002Qo-9Q for qemu-devel@nongnu.org; Sat, 21 Dec 2024 14:22:44 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tP53i-0000Kl-M6 for qemu-devel@nongnu.org; Sat, 21 Dec 2024 14:22:44 -0500 Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-534-0QYQxfZWMh20j5WO0MSz0A-1; Sat, 21 Dec 2024 14:22:38 -0500 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-385df115288so1411046f8f.2 for ; Sat, 21 Dec 2024 11:22:38 -0800 (PST) Received: from localhost (p200300cbc7137800820d0e9f08ce52bd.dip0.t-ipconnect.de. [2003:cb:c713:7800:820d:e9f:8ce:52bd]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-38a1c8474a9sm7072492f8f.52.2024.12.21.11.22.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 21 Dec 2024 11:22:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734808962; 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=TyHETmSFfRkani9FLrh+iELen8TJf3jh3hXnkuxCM7M=; b=B/7mzEOsSvc5vMSmRHTPrVk00yPnvKixGjp3bW1gf1MjnDl8tsZ5URMj8f3jz3NmLPnw35 XxZx1i6mpSVCAkrWNfHncrBj/PCBLj2uQkPrX6rwfVghUp+ysbwqfEuAy3DUQ19B8m6iqL J4LMu+E9n1VgNZ/HKJX4dVtpIlQyoto= X-MC-Unique: 0QYQxfZWMh20j5WO0MSz0A-1 X-Mimecast-MFC-AGG-ID: 0QYQxfZWMh20j5WO0MSz0A X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734808957; x=1735413757; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TyHETmSFfRkani9FLrh+iELen8TJf3jh3hXnkuxCM7M=; b=hYAe+42ESsrhu/wRddFc9mH3l72qZdse9+6YN4KyrANGfRE+Sknd+kClG/0YYKLU3Q huTQY99Q+KhveooQtVQxKHCe6SU11GZRZYPHQNS7RXh2BIypMO78E7LRn4AoCdGs60s5 aSXm8YA9xyM+SHnpDAtbsvq8K3S6zyD+0X7KzX4TqDMKQSw8f870qn6RKUYMFksjb1cA Vwvn5C639eZAuEk6ceqeP1AMae66wYlb+lrPWf7BNlqh+9SypZzgF+26+sTjSdfzPT74 bxpSDVFImVAeHYNoUABKCnAWW59SbRoD8ywZkbe4EYIN3+T+R8/CHgsK7r+fGEAPBbdv iD4w== X-Gm-Message-State: AOJu0YxiNXMm58BQQ1zsnzParZQx7NBI+/OSgnXgYy6L/0h52pxAvEql Y74JVAWPTrgU99Wns9LYwD7tdg1pNUFBaxejoxzfXQJHwsnlM31tmiY+0R/9FYXNGLk0heE72VP WY3oFWUojH1XXViS4u06RfSI9eWNvFyL8Rk50P+IUo5UAH0OTdWk1SvvxiufYyqsvf9KGUWMspZ Pf72uMT1A0xSfAKxtTwh3NiMCz5cKVzYAn X-Gm-Gg: ASbGnctMcTc/9zAC0XhhCAnBS6KLOOyvcydNOxZAzmJeqxk7nq6P2CrOcAhDGtdLac+ RcB9Bfr4HmIfyxSz5bx078TLp/QI6+v6BtbMvrBJZeXy77FNa1zuJi7NFcRdE+uKrdf/z14mP2F j/soehlncPYdjV/RPLEnBlmh3nz7ktkA4FV5opf+3FdQKp8CmXTXT2gboDtbo22tl4aPtfYyg42 jD4XQuM0oT42YMXcgeIMdwfD7gD8Gper1sX2YlC8wmSoXmJcMomBHQAB5DOxrlbx544Daz7zPRU ChbF1gmVgdM7lPJmD2y/BQwe+IpbZ1jYIci2pyo= X-Received: by 2002:a05:6000:71b:b0:385:fab3:c56d with SMTP id ffacd0b85a97d-38a221685c4mr7121846f8f.0.1734808957402; Sat, 21 Dec 2024 11:22:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IF1gaHU8eFWPAQqJ2ZbDNX9RSfGulkjNHaH8H6K5MjIqXuyLemJBQJ2UnH1RR6jGFO6+Swrrg== X-Received: by 2002:a05:6000:71b:b0:385:fab3:c56d with SMTP id ffacd0b85a97d-38a221685c4mr7121830f8f.0.1734808957060; Sat, 21 Dec 2024 11:22:37 -0800 (PST) From: David Hildenbrand To: qemu-devel@nongnu.org Cc: Halil Pasic , Christian Borntraeger , Eric Farman , Thomas Huth , Richard Henderson , "Michael S . Tsirkin" , David Hildenbrand Subject: [PULL v2 09/15] s390x/s390-stattrib-kvm: prepare for memory devices and sparse memory layouts Date: Sat, 21 Dec 2024 20:22:03 +0100 Message-ID: <20241221192209.3979595-10-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241221192209.3979595-1-david@redhat.com> References: <20241221192209.3979595-1-david@redhat.com> MIME-Version: 1.0 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=170.10.133.124; envelope-from=dhildenb@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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=-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_H2=-1.177, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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.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: 1734809080230116600 Content-Type: text/plain; charset="utf-8" With memory devices, we will have storage attributes for memory that exceeds the initial ram size. Further, we can easily have memory holes, for which there (currently) are no storage attributes. In particular, with memory holes, KVM_S390_SET_CMMA_BITS will fail to set some storage attributes. So let's do it like we handle storage keys migration, relying on guest_phys_blocks_append(). However, in contrast to storage key migration, we will handle it on the migration destination. This is a preparation for virtio-mem support. Note that ever since the "early migration" feature was added (x-early-migration), the state of device blocks (plugged/unplugged) is migrated early such that guest_phys_blocks_append() will properly consider all currently plugged memory blocks and skip any unplugged ones. In the future, we should try getting rid of the large temporary buffer and also not send any attributes for any memory holes, just so they get ignored on the destination. Message-ID: <20241219144115.2820241-9-david@redhat.com> Acked-by: Michael S. Tsirkin Reviewed-by: Thomas Huth Signed-off-by: David Hildenbrand --- hw/s390x/s390-stattrib-kvm.c | 67 +++++++++++++++++++++++------------- 1 file changed, 43 insertions(+), 24 deletions(-) diff --git a/hw/s390x/s390-stattrib-kvm.c b/hw/s390x/s390-stattrib-kvm.c index eeaa811098..33ec91422a 100644 --- a/hw/s390x/s390-stattrib-kvm.c +++ b/hw/s390x/s390-stattrib-kvm.c @@ -10,11 +10,12 @@ */ =20 #include "qemu/osdep.h" -#include "hw/boards.h" +#include "hw/s390x/s390-virtio-ccw.h" #include "migration/qemu-file.h" #include "hw/s390x/storage-attributes.h" #include "qemu/error-report.h" #include "sysemu/kvm.h" +#include "sysemu/memory_mapping.h" #include "exec/ram_addr.h" #include "kvm/kvm_s390x.h" #include "qapi/error.h" @@ -84,8 +85,8 @@ static int kvm_s390_stattrib_set_stattr(S390StAttribState= *sa, uint8_t *values) { KVMS390StAttribState *sas =3D KVM_S390_STATTRIB(sa); - MachineState *machine =3D MACHINE(qdev_get_machine()); - unsigned long max =3D machine->ram_size / TARGET_PAGE_SIZE; + S390CcwMachineState *s390ms =3D S390_CCW_MACHINE(qdev_get_machine()); + unsigned long max =3D s390_get_memory_limit(s390ms) / TARGET_PAGE_SIZE; =20 if (start_gfn + count > max) { error_report("Out of memory bounds when setting storage attributes= "); @@ -103,39 +104,57 @@ static int kvm_s390_stattrib_set_stattr(S390StAttribS= tate *sa, static void kvm_s390_stattrib_synchronize(S390StAttribState *sa) { KVMS390StAttribState *sas =3D KVM_S390_STATTRIB(sa); - MachineState *machine =3D MACHINE(qdev_get_machine()); - unsigned long max =3D machine->ram_size / TARGET_PAGE_SIZE; - /* We do not need to reach the maximum buffer size allowed */ - unsigned long cx, len =3D KVM_S390_SKEYS_MAX / 2; + S390CcwMachineState *s390ms =3D S390_CCW_MACHINE(qdev_get_machine()); + unsigned long max =3D s390_get_memory_limit(s390ms) / TARGET_PAGE_SIZE; + unsigned long start_gfn, end_gfn, pages; + GuestPhysBlockList guest_phys_blocks; + GuestPhysBlock *block; int r; struct kvm_s390_cmma_log clog =3D { .flags =3D 0, .mask =3D ~0ULL, }; =20 - if (sas->incoming_buffer) { - for (cx =3D 0; cx + len <=3D max; cx +=3D len) { - clog.start_gfn =3D cx; - clog.count =3D len; - clog.values =3D (uint64_t)(sas->incoming_buffer + cx); - r =3D kvm_vm_ioctl(kvm_state, KVM_S390_SET_CMMA_BITS, &clog); - if (r) { - error_report("KVM_S390_SET_CMMA_BITS failed: %s", strerror= (-r)); - return; - } - } - if (cx < max) { - clog.start_gfn =3D cx; - clog.count =3D max - cx; - clog.values =3D (uint64_t)(sas->incoming_buffer + cx); + if (!sas->incoming_buffer) { + return; + } + guest_phys_blocks_init(&guest_phys_blocks); + guest_phys_blocks_append(&guest_phys_blocks); + + QTAILQ_FOREACH(block, &guest_phys_blocks.head, next) { + assert(QEMU_IS_ALIGNED(block->target_start, TARGET_PAGE_SIZE)); + assert(QEMU_IS_ALIGNED(block->target_end, TARGET_PAGE_SIZE)); + + start_gfn =3D block->target_start / TARGET_PAGE_SIZE; + end_gfn =3D block->target_end / TARGET_PAGE_SIZE; + + while (start_gfn < end_gfn) { + /* Don't exceed the maximum buffer size. */ + pages =3D MIN(end_gfn - start_gfn, KVM_S390_SKEYS_MAX / 2); + + /* + * If we ever get guest physical memory beyond the configured + * memory limit, something went very wrong. + */ + assert(start_gfn + pages <=3D max); + + clog.start_gfn =3D start_gfn; + clog.count =3D pages; + clog.values =3D (uint64_t)(sas->incoming_buffer + start_gfn); r =3D kvm_vm_ioctl(kvm_state, KVM_S390_SET_CMMA_BITS, &clog); if (r) { error_report("KVM_S390_SET_CMMA_BITS failed: %s", strerror= (-r)); + goto out; } + + start_gfn +=3D pages; } - g_free(sas->incoming_buffer); - sas->incoming_buffer =3D NULL; } + +out: + guest_phys_blocks_free(&guest_phys_blocks); + g_free(sas->incoming_buffer); + sas->incoming_buffer =3D NULL; } =20 static int kvm_s390_stattrib_set_migrationmode(S390StAttribState *sa, bool= val, --=20 2.47.1 From nobody Mon Dec 23 23:07:39 2024 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=1734809066; cv=none; d=zohomail.com; s=zohoarc; b=Z7E0bPYvColuGoEMt6Uv55GcFPuAzHd+rbF32/InP77+ArP95jMFGVNY3kXJyDLxYVI52S+d4mamzIOhvULzcKEpAGag/Kvlzh+hBKXOWPXDt6UotPxcRXH5MEvxHO5QOzaqkONg31nTBb2I5O3oKXMqbaM5R+I1mR8IyI8KGDY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1734809066; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=u6rrgRHxwZkzjvI/Y0EExDevggaj96UfW/Jubye9t9k=; b=hEZbege/2bD622Z9J2ONcJHe0LkYX3wfYPAWqaIF84QOvddXYIzKNoMlVKBfV50KpJXkkRFi7TfzmU5L0c8G9agWxfX9Lkvw3yEdw0ZJWBWu95nDo4tIH7XcGYfxXMbbeo4mwsC6O4gqtr0KZ17+iX2QBWXWHQsH6FiQlosYR5c= 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 1734809066058873.5301046232834; Sat, 21 Dec 2024 11:24:26 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tP53n-0002Rg-3F; Sat, 21 Dec 2024 14:22:47 -0500 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 1tP53l-0002RI-PY for qemu-devel@nongnu.org; Sat, 21 Dec 2024 14:22:45 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tP53k-0000Ms-B8 for qemu-devel@nongnu.org; Sat, 21 Dec 2024 14:22:45 -0500 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-298-OChuXYVpOYu11dhIyosEpA-1; Sat, 21 Dec 2024 14:22:41 -0500 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4361f371908so22496825e9.0 for ; Sat, 21 Dec 2024 11:22:41 -0800 (PST) Received: from localhost (p200300cbc7137800820d0e9f08ce52bd.dip0.t-ipconnect.de. [2003:cb:c713:7800:820d:e9f:8ce:52bd]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-4364b0566f1sm108795275e9.2.2024.12.21.11.22.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 21 Dec 2024 11:22:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734808963; 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=u6rrgRHxwZkzjvI/Y0EExDevggaj96UfW/Jubye9t9k=; b=CoqbjmIDn0Ccu32sxJItjdt2YH6aF8tad1unJP7GNtaUTAUnImnXBNGEPq15vCejQtclEF yu+cE4vMfUknhIwf95RwQrVTKFMoM3oaRVWLOkxNyg1wbdxcuIvP8DmtbkiHRa/SwJZz2y v+FgIK0wfxqqq/OaETKBhNSaXhTWcUY= X-MC-Unique: OChuXYVpOYu11dhIyosEpA-1 X-Mimecast-MFC-AGG-ID: OChuXYVpOYu11dhIyosEpA X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734808960; x=1735413760; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=u6rrgRHxwZkzjvI/Y0EExDevggaj96UfW/Jubye9t9k=; b=YMB9G/sZnGgjqqF3kwQwTGEgpXFTsIWbk+jOyZ6P+/CP6M7DKs2gdXGL1+L6seH5RL h7bW/KFtNYAabfjsey4kwSj4+cOEyaJvBP5sVjDia8E0oCM/H/lNwzn0AmVBgIqdBrsY 9X0+Ia82/Wl8roZg24KN82GzcS49njUVjJXO/cSjK7LK4DbE1nAru/v6VXvIT2rVs389 uSnHiztGMi3JIkZ2uWTdqTc/KG4TzuCZWbE1kbte3hZOFVKF6TspBGaQt3Rmx5DfJtWO HSKfAv5zEIq7zjV1IjtwCsiu6jkCLWIMq0RHgWvjkDHAmsYZGI9aEW/3Jx1O8T3Om5tJ cuCw== X-Gm-Message-State: AOJu0YyZgxPBVGFXt/o4WfG4vZ9lmZHy+eHCBWuiO53BqaMi30bCaJYE CXlzDJGwJEFwCwMV7f4zG6ksmh/1ZGWGkUhYuwJFPwcw2bYMZroTuHcTY8vz+w0vSyRvMCLdd2B yANMz6pxunKPs2uDaAH8J+L2jqWsCdWteZHNwjALRb7v3zMOxsbAlSI6W++w1q/CwW2e+u3MIfz zqTJdEuVsBqgHxk71Rc8F2maMfc72IENtq X-Gm-Gg: ASbGncuiDWvLPJvVW89lrLj8OrhJfgPqO+VoUHosgKdqrJe7RCA12OSVj3S3qjFsHsC JUBJyuZUAfg489KWpJuPhMUFSFZhRfYvLLzNdbVTtE6i4eFOiUoTrsddHmVCNi3OzrOxI4n+dQF fx7v/i8EIlhgFPxVZRSXXtRTCeocop/WmiQyELVQYLaJXCOtmcDCkYVcGprTyxDwShaNl8xplB1 lNB0BsxtUY0myI/9WKRK2iqeDJKDqyM59OlHTxNdzZiSw7vYmGG3cEMp51TaZQ4dazAyRft11IU Uv9+qFxpXqspfpBpjbdQ9T2Vt7pKiM4spwhMIiE= X-Received: by 2002:a05:6000:1fab:b0:385:e30a:394e with SMTP id ffacd0b85a97d-38a221e2066mr7861463f8f.3.1734808960365; Sat, 21 Dec 2024 11:22:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IEmSpL9UWbBBDCBUCB8hkorKZlp78VrUrwmqJfQKpsOAOh28AyZLh5KVQatADM8CjDNaqq1Tw== X-Received: by 2002:a05:6000:1fab:b0:385:e30a:394e with SMTP id ffacd0b85a97d-38a221e2066mr7861449f8f.3.1734808959976; Sat, 21 Dec 2024 11:22:39 -0800 (PST) From: David Hildenbrand To: qemu-devel@nongnu.org Cc: Halil Pasic , Christian Borntraeger , Eric Farman , Thomas Huth , Richard Henderson , "Michael S . Tsirkin" , David Hildenbrand Subject: [PULL v2 10/15] s390x/s390-skeys: prepare for memory devices Date: Sat, 21 Dec 2024 20:22:04 +0100 Message-ID: <20241221192209.3979595-11-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241221192209.3979595-1-david@redhat.com> References: <20241221192209.3979595-1-david@redhat.com> MIME-Version: 1.0 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=170.10.133.124; envelope-from=dhildenb@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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=-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_H2=-1.177, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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.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: 1734809068083116600 Content-Type: text/plain; charset="utf-8" With memory devices, we will have storage keys for memory that exceeds the initial ram size. The TODO already states that current handling is subopimal, but we won't worry about improving that (TCG-only) thing for now. Message-ID: <20241219144115.2820241-10-david@redhat.com> Acked-by: Michael S. Tsirkin Reviewed-by: Thomas Huth Signed-off-by: David Hildenbrand --- hw/s390x/s390-skeys.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hw/s390x/s390-skeys.c b/hw/s390x/s390-skeys.c index 6d0a47ed73..6ea4d8c20e 100644 --- a/hw/s390x/s390-skeys.c +++ b/hw/s390x/s390-skeys.c @@ -11,7 +11,7 @@ =20 #include "qemu/osdep.h" #include "qemu/units.h" -#include "hw/boards.h" +#include "hw/s390x/s390-virtio-ccw.h" #include "hw/qdev-properties.h" #include "hw/s390x/storage-keys.h" #include "qapi/error.h" @@ -251,9 +251,9 @@ static bool qemu_s390_enable_skeys(S390SKeysState *ss) * g_once_init_enter() is good enough. */ if (g_once_init_enter(&initialized)) { - MachineState *machine =3D MACHINE(qdev_get_machine()); + S390CcwMachineState *s390ms =3D S390_CCW_MACHINE(qdev_get_machine(= )); =20 - skeys->key_count =3D machine->ram_size / TARGET_PAGE_SIZE; + skeys->key_count =3D s390_get_memory_limit(s390ms) / TARGET_PAGE_S= IZE; skeys->keydata =3D g_malloc0(skeys->key_count); g_once_init_leave(&initialized, 1); } --=20 2.47.1 From nobody Mon Dec 23 23:07:39 2024 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=1734809023; cv=none; d=zohomail.com; s=zohoarc; b=JXz8hZfADJrFr581aA3ouvduSY630KeYYZ6S43EFHsp02BJhxg8A65JSY0Z9NIx3vmg9yy/zW3HS2vxYO3mBaePCjh+R2B7xu+pAqT8GN7d0BNjeUQZEBWEQOpz0gncFayq+Vkg61WHgwngssdsCyKYpjAzmWIUTb1kwS9kYeXA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1734809023; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=+SCHZt+7eq0EguUklsx9a7gyRDzfGwtz5P0zLbQ+Xi8=; b=klL+MeMKCPW+mDKX3WovLenZPs6+dmGOECUPP8Yvln+Ev9q4DQx3VJaax0UBfxBa/HSz6qSCwNJE9SkQDnLnlOkmUNtVNutYSOVXBv7+V/pgtb4DfbvMUjBd3pnUuwg/4m/mA4L4YyLaJQ59WcW1hl8w6mkjEeQl8S0cSyRpciA= 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 1734809023320447.7648912237828; Sat, 21 Dec 2024 11:23:43 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tP53r-0002Tz-CZ; Sat, 21 Dec 2024 14:22:51 -0500 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 1tP53p-0002Rz-VD for qemu-devel@nongnu.org; Sat, 21 Dec 2024 14:22:49 -0500 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 1tP53o-0000NM-4N for qemu-devel@nongnu.org; Sat, 21 Dec 2024 14:22:49 -0500 Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-655-WITFYY1hNZKNS23rrFRRyQ-1; Sat, 21 Dec 2024 14:22:44 -0500 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-38639b4f19cso2016649f8f.0 for ; Sat, 21 Dec 2024 11:22:44 -0800 (PST) Received: from localhost (p200300cbc7137800820d0e9f08ce52bd.dip0.t-ipconnect.de. [2003:cb:c713:7800:820d:e9f:8ce:52bd]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-38a1c89e2eesm7226385f8f.80.2024.12.21.11.22.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 21 Dec 2024 11:22:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734808967; 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=+SCHZt+7eq0EguUklsx9a7gyRDzfGwtz5P0zLbQ+Xi8=; b=e04Zq6/fgXa0Edj1QbfncAvLtTVrSscA/1YFaUJ6jGiUjBekn5U55XxmaREJzzQFEpPvRh c2f68LETc8d7EFq56Rkm3zZvSMr8AuI85SQqiNb0ydXkxnfnlFrLf6kolH7Dal6JZx5eaQ VT5s/UsCe/bJfuaQ9pPPqg4+t+F8bjI= X-MC-Unique: WITFYY1hNZKNS23rrFRRyQ-1 X-Mimecast-MFC-AGG-ID: WITFYY1hNZKNS23rrFRRyQ X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734808963; x=1735413763; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+SCHZt+7eq0EguUklsx9a7gyRDzfGwtz5P0zLbQ+Xi8=; b=YhaJ5wPPMWhZa7gfhdFejcV3eND3IcRdG1SrjntCEtg7BBej6j/cJNKL3RCBIqnfcF 1P0nateUM7uly8nKFltS3LZmTMS1sTTYcOcuZqaRrOMzbW/kGDJLzdt1LmRj9JkU0kYH 7FwJWKqjCDX7iDwlYCH9LoE0S3ctqKbWfAT1YrdBrfaVj2LOP6rSMQ4YHPOH/6e5nqz8 R+kqEMvN16vrSdQQRwczwTW7/C7aI/qEjSdLD1fxsSoAKzVE+Z0bsfhslIAGv/5YqlzC y0lYRNFnaI0hs4lTCkq7krQZWcmH/hXAEUDKgkDzIiDjNpxn+nz23Xl+v65kcrXbjIic YTFQ== X-Gm-Message-State: AOJu0Yy9h074Idr4K7EHdf2Dkvz/oIiZorsKZBgz8MZX4pw58fBykgoX fUHNflaJrSCeHkA6AoqrMftUdgGxB/oROsm6e9K084B3+3SmT+uilYR/5iS1gn9tcI1hPYkA7eC VJgNzy3sDV2eRikTIJxodLHoRVS0MrPKp29GkiDWNbVriDWftHHI+q96xpR45o3299vviKzUdTl fjG9HLJEjSHV+KrDd7QZboKseaE2LLVqti X-Gm-Gg: ASbGncs7/AYqXj0+LlHSGPUIPui4LCPFhTHXhAzIRGVpNHU7QL1FhMSImI6k958PCpx gCWIuBdkYjSzir17qBf1lVxFuMCggO9GyUJh3Bwba+i2dAVmeP7lXQ8piwJkw+yzdnXJ6+qrYqU k3DBOnz2WpapzEcH1HU6AzlCsTZbew8h0fONGX51WUEQ31tWPQKRD5xhDWT0JN74b6GAn0MkoLI RA6MedxGffC2RNcDfC7kSRDLkli7qKXu1CetIfLDXROMRmOwouzjMs3iDzzBnGiNFF2gSK5mOwW WrkHTl3UWJip8RcihCH9hRM9ri+IjGJYj+hEljA= X-Received: by 2002:a05:6000:186b:b0:385:e877:c037 with SMTP id ffacd0b85a97d-38a223f82f4mr6157296f8f.42.1734808963207; Sat, 21 Dec 2024 11:22:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IEwsiHDn5FIHVUD7quSHAYiTuUOjdmR05qX+N/bzOz3QbzsjL51U3seaZfr4uo5KTiTOuuXKQ== X-Received: by 2002:a05:6000:186b:b0:385:e877:c037 with SMTP id ffacd0b85a97d-38a223f82f4mr6157282f8f.42.1734808962788; Sat, 21 Dec 2024 11:22:42 -0800 (PST) From: David Hildenbrand To: qemu-devel@nongnu.org Cc: Halil Pasic , Christian Borntraeger , Eric Farman , Thomas Huth , Richard Henderson , "Michael S . Tsirkin" , David Hildenbrand Subject: [PULL v2 11/15] s390x/s390-virtio-ccw: prepare for memory devices Date: Sat, 21 Dec 2024 20:22:05 +0100 Message-ID: <20241221192209.3979595-12-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241221192209.3979595-1-david@redhat.com> References: <20241221192209.3979595-1-david@redhat.com> MIME-Version: 1.0 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=170.10.129.124; envelope-from=dhildenb@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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=-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_H2=-1.177, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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.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: 1734809023983116600 Content-Type: text/plain; charset="utf-8" Let's prepare our address space for memory devices if enabled via "maxmem" and if we have CONFIG_MEM_DEVICE enabled at all. Note that CONFIG_MEM_DEVICE will be selected automatically once we add support for devices. Just like on other architectures, the region container for memory devices is placed directly above our initial memory. For now, we only align the start address of the region up to 1 GiB, but we won't add any additional space to the region for internal alignment purposes; this can be done in the future if really required. The RAM size returned via SCLP is not modified, as this only covers initial RAM (and standby memory we don't implement) and not memory devices; clarify that in the docs of read_SCP_info(). Existing OSes without support for memory devices will keep working as is, even when memory devices would be attached the VM. Guest OSs which support memory devices, such as virtio-mem, will consult diag500(), to find out the maximum possible pfn. Guest OSes that don't support memory devices, don't have to be changed and will continue relying on information provided by SCLP. There are no remaining maxram_size users in s390x code, and the remaining ram_size users only care about initial RAM: * hw/s390x/ipl.c * hw/s390x/s390-hypercall.c * hw/s390x/sclp.c * target/s390x/kvm/pv.c Message-ID: <20241219144115.2820241-11-david@redhat.com> Acked-by: Michael S. Tsirkin Reviewed-by: Thomas Huth Signed-off-by: David Hildenbrand --- hw/s390x/s390-virtio-ccw.c | 23 ++++++++++++++++++++++- hw/s390x/sclp.c | 6 +++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c index 1c56b70dcd..2ba66be018 100644 --- a/hw/s390x/s390-virtio-ccw.c +++ b/hw/s390x/s390-virtio-ccw.c @@ -149,6 +149,7 @@ static void s390_memory_init(MachineState *machine) MemoryRegion *sysmem =3D get_system_memory(); MemoryRegion *ram =3D machine->ram; uint64_t ram_size =3D memory_region_size(ram); + uint64_t devmem_base, devmem_size; =20 if (!QEMU_IS_ALIGNED(ram_size, 1 * MiB)) { /* @@ -161,11 +162,31 @@ static void s390_memory_init(MachineState *machine) exit(EXIT_FAILURE); } =20 - s390_set_memory_limit(s390ms, ram_size); + devmem_size =3D 0; + devmem_base =3D ram_size; +#ifdef CONFIG_MEM_DEVICE + if (machine->ram_size < machine->maxram_size) { + + /* + * Make sure memory devices have a sane default alignment, even + * when weird initial memory sizes are specified. + */ + devmem_base =3D QEMU_ALIGN_UP(devmem_base, 1 * GiB); + devmem_size =3D machine->maxram_size - machine->ram_size; + } +#endif + s390_set_memory_limit(s390ms, devmem_base + devmem_size); =20 /* Map the initial memory. Must happen after setting the memory limit.= */ memory_region_add_subregion(sysmem, 0, ram); =20 + /* Initialize address space for memory devices. */ +#ifdef CONFIG_MEM_DEVICE + if (devmem_size) { + machine_memory_devices_init(machine, devmem_base, devmem_size); + } +#endif /* CONFIG_MEM_DEVICE */ + /* * Configure the maximum page size. As no memory devices were created * yet, this is the page size of initial memory only. diff --git a/hw/s390x/sclp.c b/hw/s390x/sclp.c index 73e88ab4eb..5945c9b1d8 100644 --- a/hw/s390x/sclp.c +++ b/hw/s390x/sclp.c @@ -161,7 +161,11 @@ static void read_SCP_info(SCLPDevice *sclp, SCCB *sccb) read_info->rnsize2 =3D cpu_to_be32(rnsize); } =20 - /* we don't support standby memory, maxram_size is never exposed */ + /* + * We don't support standby memory. maxram_size is used for sizing the + * memory device region, which is not exposed through SCLP but through + * diag500. + */ rnmax =3D machine->ram_size >> sclp->increment_size; if (rnmax < 0x10000) { read_info->rnmax =3D cpu_to_be16(rnmax); --=20 2.47.1 From nobody Mon Dec 23 23:07:39 2024 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=1734809068; cv=none; d=zohomail.com; s=zohoarc; b=Xn+7M9YZAewz1okvN5NeT7WVcMkEt65U1kMrwgmUjY31jivbYa30WhQ+daM/MHtctJ0gK2X0n/ch1Xy7cXNJSV5gUzdAw7ASs7h9cVX4kBve+wMeock/KzE/c+4rWBsz3Nbv/cXL9g4AiIpXVEn1bn+kxWhNiLNMSB1BtUV9bU8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1734809068; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=wtsh1Lk6xlukF3B5MU4Com6s9MZP8UnYV3hnvMy+hsA=; b=fmfqDJ57geKB+aXl+9Uk8zy+3rHt3o5jZd0+2cUN8F+q+Ery6Fzt2+W3Bo5AM0iRxxm4ps1PEPneUhQZ60XA4Tn8Va81f1QEJpYPycVL1cJCA1LDjuU37fla0dmo8trCeJJgWQTYU20FcpH+3BCX1gRahlawU3AEg6DeblOQuyM= 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 1734809068588508.45781555258907; Sat, 21 Dec 2024 11:24:28 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tP53s-0002UX-KB; Sat, 21 Dec 2024 14:22:52 -0500 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 1tP53q-0002S8-IW for qemu-devel@nongnu.org; Sat, 21 Dec 2024 14:22:50 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tP53p-0000NR-93 for qemu-devel@nongnu.org; Sat, 21 Dec 2024 14:22:50 -0500 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-490-i48WpF3wMzqKxLbjz589Ew-1; Sat, 21 Dec 2024 14:22:47 -0500 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-43631d8d9c7so15640075e9.1 for ; Sat, 21 Dec 2024 11:22:47 -0800 (PST) Received: from localhost (p200300cbc7137800820d0e9f08ce52bd.dip0.t-ipconnect.de. [2003:cb:c713:7800:820d:e9f:8ce:52bd]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-4364b053e91sm151842665e9.1.2024.12.21.11.22.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 21 Dec 2024 11:22:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734808968; 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=wtsh1Lk6xlukF3B5MU4Com6s9MZP8UnYV3hnvMy+hsA=; b=DtxnKXvkc8GivXtPOK0o0hlsOX2cBzf24GCwjOP5OIehvY0Mvj1hHtB2eaou5mcaXkTMRV 2/pvRr+zjuPGZioO1z/jTq+jZmo5+uJ/CukIfCh6Z+aSLzuZFykMcux7mWpwx1DNcoT81N 83V+IfsbPIE20DWIMqcmHOxobaM+OsM= X-MC-Unique: i48WpF3wMzqKxLbjz589Ew-1 X-Mimecast-MFC-AGG-ID: i48WpF3wMzqKxLbjz589Ew X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734808966; x=1735413766; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wtsh1Lk6xlukF3B5MU4Com6s9MZP8UnYV3hnvMy+hsA=; b=dEfjCaMmXB69pEAxgv9OVQ311jotFvXJgRjBGaj4H28QrYnqeGAs4X2nRdevlRs5GW +BprGjgjEuJA1wF8DclY1xXWaELKZksk52KtfcVW/jcJdeuCpmIKX7u+EcvPQXNsBFJ4 FZODDzSpDVIH8g3Yo/wAURumEE5BgZLNnB9Cg0Lxgbd24wG5SU1u8Newgk711JEMHAQL lS4DYBd8J/b6HHZ90FaieqwRNubc+Rdq5Wmtw+dcAjcjzTFE0IZ7xajnL4j83hhOB36m j1IOP+Osz5B+4dvg6Fi9KyR1dFQG1OBxVZzIDgWI8qr5VebOP/tx9HeXKP6RWnpljjId He+w== X-Gm-Message-State: AOJu0YzO54WU21Esk8WyZpKwXVK8dnd2tXXx4A0iaVky1WGyrkIt15uU jANLL8gwhVlGojuGT66VcCN152JcVTwHf7bLr1yVciGFN6bVAE/BpTu3iwln3R/fYfh/XLl50qY UrU6hGdW1O8tJy9LiXXgRmbM5OC1Zs49+V2hKz7c3xBMMzmvqfVz9uhQMaT+ecAkOiX1x5KAa2C njunNU5K+AdX63nHYHwirVaioYaGqD2qRF X-Gm-Gg: ASbGnctmTx7ga2FETQlQd26LhOFHGsaJxu+kJBom4Kmnuwk9TWM5RFQl6yCFF/beEuk yFk9jJuT20wZbTT/S0aMZLC7uzDACFAgb+9X7uHOwsx3Td97/MwFlqTmAsji8B2jpjKN8tPhsrA inpOWARJMAYZci2ncYt8lGuDphFpGV+aHKGWZdYFezg1R82SfxKWSaNSKb1t1wf5PYp+u5zYwle oSxtu1A/QFmGqxRif97eb33fj40JqH795ZB/Cuj0mLjCMZ4pqzXVCpkkXkYqPYO2v37hXek2Zl2 zNHKCjtxIGv8pP3uFCek6W0HgmeanFPyDXvS8H0= X-Received: by 2002:a05:600c:511d:b0:434:fddf:5c06 with SMTP id 5b1f17b1804b1-436696fec16mr60719385e9.1.1734808966061; Sat, 21 Dec 2024 11:22:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IHsXV0vVQZtpcEDflA6tQt3C+bMLIGzpWK2kwajZvSGvGtjAKxNP+I6szI3oWIzdbLU3iH3cA== X-Received: by 2002:a05:600c:511d:b0:434:fddf:5c06 with SMTP id 5b1f17b1804b1-436696fec16mr60719235e9.1.1734808965746; Sat, 21 Dec 2024 11:22:45 -0800 (PST) From: David Hildenbrand To: qemu-devel@nongnu.org Cc: Halil Pasic , Christian Borntraeger , Eric Farman , Thomas Huth , Richard Henderson , "Michael S . Tsirkin" , David Hildenbrand , Nina Schoetterl-Glausch Subject: [PULL v2 12/15] s390x/pv: prepare for memory devices Date: Sat, 21 Dec 2024 20:22:06 +0100 Message-ID: <20241221192209.3979595-13-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241221192209.3979595-1-david@redhat.com> References: <20241221192209.3979595-1-david@redhat.com> MIME-Version: 1.0 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=170.10.133.124; envelope-from=dhildenb@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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=-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_H2=-1.177, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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.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: 1734809070177116600 Content-Type: text/plain; charset="utf-8" Let's avoid checking for the maxram_size, and instead rely on the memory limit determined in s390_memory_init(), that might be larger than maxram_size, for example due to alignment purposes. This check now correctly mimics what the kernel will check in kvm_s390_pv_set_aside(), whereby a VM <=3D 2 GiB VM would end up using a segment type ASCE. Message-ID: <20241219144115.2820241-12-david@redhat.com> Acked-by: Michael S. Tsirkin Reviewed-by: Nina Schoetterl-Glausch Signed-off-by: David Hildenbrand --- target/s390x/kvm/pv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/s390x/kvm/pv.c b/target/s390x/kvm/pv.c index 424cce75ca..fa66607e7b 100644 --- a/target/s390x/kvm/pv.c +++ b/target/s390x/kvm/pv.c @@ -133,7 +133,7 @@ bool s390_pv_vm_try_disable_async(S390CcwMachineState *= ms) * If the feature is not present or if the VM is not larger than 2 GiB, * KVM_PV_ASYNC_CLEANUP_PREPARE fill fail; no point in attempting it. */ - if ((MACHINE(ms)->ram_size <=3D 2 * GiB) || + if (s390_get_memory_limit(ms) <=3D 2 * GiB || !kvm_check_extension(kvm_state, KVM_CAP_S390_PROTECTED_ASYNC_DISAB= LE)) { return false; } --=20 2.47.1 From nobody Mon Dec 23 23:07:39 2024 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=1734809071; cv=none; d=zohomail.com; s=zohoarc; b=YOf1Aq2rP537V4Z64uW4DWJVgUH3QJNhXUGV6PN7rl/IRsFCd7AvNc/+Q/Cs9e5PWKqkUfXpQwcB6fFJjX2HN+fIed8VnRDHGpAD4ws8+NI6axZ4+/+JX0IqXPV7souRpUGa6Pxn4YXyLwH96q6xIkaTgXNr24VJFwkkCHrCA00= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1734809071; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=cPykELzZWYychb/XmGLesydXjeUkKpSsqMmT/tkVBhQ=; b=ISp6ju4VQjYKpSx8mM8KEizGJ0HpWVYxkcrEb1y5LkWCKyFsbOurr/51TXd6ukqOorPKSyAq5Q3noDVQr2UpzP/9ViHLVFILtvCyXOuh9X1uOvZPfku8VIzCeHTPD5D+IXkn+VmtuKbnf8VSqVVKHrG4IPGxsBKAy4SBSJbDN2w= 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 1734809071943197.4670862424755; Sat, 21 Dec 2024 11:24:31 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tP53v-0002VY-FJ; Sat, 21 Dec 2024 14:22:55 -0500 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 1tP53t-0002Ur-R5 for qemu-devel@nongnu.org; Sat, 21 Dec 2024 14:22:53 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tP53s-0000Ny-BJ for qemu-devel@nongnu.org; Sat, 21 Dec 2024 14:22:53 -0500 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-544-mtpNn1LNMnCRHwNsdOZ54g-1; Sat, 21 Dec 2024 14:22:50 -0500 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-43631d8d9c7so15640125e9.1 for ; Sat, 21 Dec 2024 11:22:49 -0800 (PST) Received: from localhost (p200300cbc7137800820d0e9f08ce52bd.dip0.t-ipconnect.de. [2003:cb:c713:7800:820d:e9f:8ce:52bd]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-43661289995sm82665035e9.36.2024.12.21.11.22.46 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 21 Dec 2024 11:22:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734808971; 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=cPykELzZWYychb/XmGLesydXjeUkKpSsqMmT/tkVBhQ=; b=Z0ovhALwcVqS4p7dWxKSC48Z5l1Ho4do04lnNbuAstfzYRG05GrecGDQlWPB/NAnG4Fpww r5au7mIssbAK3esRb0HVpQ+X9owaml+vM0isgnGLZybU4jIgB36UKLQNWgBszrWHnLGvyS ze1XP8R4K43uHJvZV+u1yWclhXxxsDs= X-MC-Unique: mtpNn1LNMnCRHwNsdOZ54g-1 X-Mimecast-MFC-AGG-ID: mtpNn1LNMnCRHwNsdOZ54g X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734808969; x=1735413769; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cPykELzZWYychb/XmGLesydXjeUkKpSsqMmT/tkVBhQ=; b=sFArEcb5U7D7XZq57NZ0nz9bzQ3mMm7k7ut6fDdrXFS3Usep3O0FD0Y+VN1qH6mSU7 ZsOKR9wL6jarTfn9fI2bZmRnx1zznyX9RjDDQU2QGL9N7I89tnAoj21oAYXD1AeqkVt7 W9KKAq/5UTK2GkbHJ9hfrR59ryRMhdLjTnDpzd4UdBIG5JrNYkiZIBrLtXqYeSXnKCfT Yyal27S2bEXteuCVn6sCIf92oBiS9B8HdAAeAPdrvXvYBL0vhT9t5dq7H4XYJKTFpJ5a w0fO4lWlnalj0atoGC5EDUW3G93RNFPdBWdH2S3d1hmD+jmwPndt8I6CJplatzOk/xlh bwuA== X-Gm-Message-State: AOJu0YyxJSG3pEGndwSjbN+k7AvVWK5h9BPYsnhjby0rAjdY6iQeOEi2 tiZSiGny6s3WTK8M/dNcMaFZqzhBo2dBodtbN2zbeAI4HmVsY3U8v97v8Pk7dVA+ZUU2pd5yqKo BHjL71HCtG3EVnTnbbR4nQcHPz02hXmOs7b9W7eNxOAYrBvNSTcIcMdEuCzQs9hRudAKLattqoR cu6LfV+IHO5+iSzool0DcWDc9+r7TQnCdl X-Gm-Gg: ASbGncuuXaF0kCLcxoQRWuhlfAJRr2/2q6KWq07i96iEOZU97rIjCZs6apYTE+EptZF 8ePCFCNR8hByuBx5lPSEQpBLrMv++xwY4r69FlHP/Qdzwqr4KsejY0nTsnIS6q1bzGW4Xd/ep0d yuk0H6MEOxBzw43fEamXalR5mtzU8PqmMPsx/xD2VsSeqDNplcieOyoBum7e6WJGLciMeabZVD0 BSYyvBFmG5nwV/Y1zdDpaV1N/np3ChoC0qPaaypeMTXAuM0ZeQRKCclOj13NrqM2oAg6w7/ZBNT Kg0kNhaOVZNV2PzqFcwulqNOHR/ahrTvUckCQuI= X-Received: by 2002:a05:600c:3b26:b0:434:fa73:a906 with SMTP id 5b1f17b1804b1-436697f8e14mr50764315e9.4.1734808968979; Sat, 21 Dec 2024 11:22:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IFUmYIDasQqLW83KjYjIwHmHo+TQe37j3c6gLScQ7YhFIY1d1M1qlAOF32NhTrAPBYK9eLaJA== X-Received: by 2002:a05:600c:3b26:b0:434:fa73:a906 with SMTP id 5b1f17b1804b1-436697f8e14mr50764155e9.4.1734808968605; Sat, 21 Dec 2024 11:22:48 -0800 (PST) From: David Hildenbrand To: qemu-devel@nongnu.org Cc: Halil Pasic , Christian Borntraeger , Eric Farman , Thomas Huth , Richard Henderson , "Michael S . Tsirkin" , David Hildenbrand Subject: [PULL v2 13/15] s390x: remember the maximum page size Date: Sat, 21 Dec 2024 20:22:07 +0100 Message-ID: <20241221192209.3979595-14-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241221192209.3979595-1-david@redhat.com> References: <20241221192209.3979595-1-david@redhat.com> MIME-Version: 1.0 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=170.10.133.124; envelope-from=dhildenb@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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=-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_H2=-1.177, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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.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: 1734809074177116600 Content-Type: text/plain; charset="utf-8" Let's remember the value (successfully) set via s390_set_max_pagesize(). This will be helpful to reject hotplugged memory devices that would exceed this initially set page size. Handle it just like how we handle s390_get_memory_limit(), storing it in the machine, and moving the handling to machine code. Message-ID: <20241219144115.2820241-13-david@redhat.com> Acked-by: Michael S. Tsirkin Reviewed-by: Thomas Huth Signed-off-by: David Hildenbrand --- hw/s390x/s390-virtio-ccw.c | 12 +++++++++++- include/hw/s390x/s390-virtio-ccw.h | 1 + target/s390x/cpu-sysemu.c | 7 ------- target/s390x/cpu.h | 1 - 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c index 2ba66be018..9f8d830798 100644 --- a/hw/s390x/s390-virtio-ccw.c +++ b/hw/s390x/s390-virtio-ccw.c @@ -143,6 +143,16 @@ static void s390_set_memory_limit(S390CcwMachineState = *s390ms, s390ms->memory_limit =3D new_limit; } =20 +static void s390_set_max_pagesize(S390CcwMachineState *s390ms, + uint64_t pagesize) +{ + assert(!s390ms->max_pagesize && pagesize); + if (kvm_enabled()) { + kvm_s390_set_max_pagesize(pagesize, &error_fatal); + } + s390ms->max_pagesize =3D pagesize; +} + static void s390_memory_init(MachineState *machine) { S390CcwMachineState *s390ms =3D S390_CCW_MACHINE(machine); @@ -191,7 +201,7 @@ static void s390_memory_init(MachineState *machine) * Configure the maximum page size. As no memory devices were created * yet, this is the page size of initial memory only. */ - s390_set_max_pagesize(qemu_maxrampagesize(), &error_fatal); + s390_set_max_pagesize(s390ms, qemu_maxrampagesize()); /* Initialize storage key device */ s390_skeys_init(); /* Initialize storage attributes device */ diff --git a/include/hw/s390x/s390-virtio-ccw.h b/include/hw/s390x/s390-vir= tio-ccw.h index de04336c5a..599740a998 100644 --- a/include/hw/s390x/s390-virtio-ccw.h +++ b/include/hw/s390x/s390-virtio-ccw.h @@ -30,6 +30,7 @@ struct S390CcwMachineState { bool pv; uint8_t loadparm[8]; uint64_t memory_limit; + uint64_t max_pagesize; =20 SCLPDevice *sclp; }; diff --git a/target/s390x/cpu-sysemu.c b/target/s390x/cpu-sysemu.c index 3118a25fee..706a5c53e2 100644 --- a/target/s390x/cpu-sysemu.c +++ b/target/s390x/cpu-sysemu.c @@ -255,13 +255,6 @@ unsigned int s390_cpu_set_state(uint8_t cpu_state, S39= 0CPU *cpu) return s390_count_running_cpus(); } =20 -void s390_set_max_pagesize(uint64_t pagesize, Error **errp) -{ - if (kvm_enabled()) { - kvm_s390_set_max_pagesize(pagesize, errp); - } -} - void s390_cmma_reset(void) { if (kvm_enabled()) { diff --git a/target/s390x/cpu.h b/target/s390x/cpu.h index b4506539f0..5b7992deda 100644 --- a/target/s390x/cpu.h +++ b/target/s390x/cpu.h @@ -881,7 +881,6 @@ static inline void s390_do_cpu_load_normal(CPUState *cs= , run_on_cpu_data arg) =20 /* cpu.c */ void s390_crypto_reset(void); -void s390_set_max_pagesize(uint64_t pagesize, Error **errp); void s390_cmma_reset(void); void s390_enable_css_support(S390CPU *cpu); void s390_do_cpu_set_diag318(CPUState *cs, run_on_cpu_data arg); --=20 2.47.1 From nobody Mon Dec 23 23:07:39 2024 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=1734809010; cv=none; d=zohomail.com; s=zohoarc; b=R5h/X8VBaSgvxvGhsJvadFjUuAt6cgiN453PK85ijxNv3lSbchHsqcfkT2bEoirtlZbT+l+li86Bq+d54ZKwY0c6yAMYrRsyl/TA2WVlgYtwnFexPMvBLsb/Fj183GqxgctqXb9RU8F/iNmaiJlQbIM6NMyKasnCfCQLFI7MTpw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1734809010; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=2UuusRwxG1yeSE1VQLGzrmkmK/nH8y6mAI7q7Cr7/tQ=; b=aX/SASwXTJzXGY0Fzd8ROFmdYK8FPrycNtZlSM4G3JMEuGCq0UvW/xXIOQ0A98H7a0ptnN7npadNmtpciIxk7O6bPsLOu0Mdpi2k37O128SaZXYZMFI/dmNfwkJwZJsrTLzNJH0lgldFvik8203BSay/nZJkEImphN1Ubz8f56Q= 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 1734809010274848.8182949765761; Sat, 21 Dec 2024 11:23:30 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tP53z-0002cr-1v; Sat, 21 Dec 2024 14:22:59 -0500 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 1tP53x-0002Zv-5T for qemu-devel@nongnu.org; Sat, 21 Dec 2024 14:22:57 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tP53u-0000OY-Vh for qemu-devel@nongnu.org; Sat, 21 Dec 2024 14:22:56 -0500 Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-552-REX7JcllPlaBX9wZE0n5KA-1; Sat, 21 Dec 2024 14:22:52 -0500 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-385df115300so1364820f8f.2 for ; Sat, 21 Dec 2024 11:22:52 -0800 (PST) Received: from localhost (p200300cbc7137800820d0e9f08ce52bd.dip0.t-ipconnect.de. [2003:cb:c713:7800:820d:e9f:8ce:52bd]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-38a1c8475cesm7127626f8f.57.2024.12.21.11.22.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 21 Dec 2024 11:22:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734808974; 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=2UuusRwxG1yeSE1VQLGzrmkmK/nH8y6mAI7q7Cr7/tQ=; b=NAYnI4cIJk4JDYwLMV0GeYoLq3qDCXo7UuiF3Ce6WrgciYRxjnqyZ4qQkGOB9v8GdYwDot lpS2hCLrejoHPBUMqsEMPz5VcGeUxwLfBqC9hqmqPZmDl/uo0lW/tGu9ZCX2FB6uEWC6BO GOmGiIFj0oHW3y9qXkOXdHKFg3hmLdM= X-MC-Unique: REX7JcllPlaBX9wZE0n5KA-1 X-Mimecast-MFC-AGG-ID: REX7JcllPlaBX9wZE0n5KA X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734808971; x=1735413771; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2UuusRwxG1yeSE1VQLGzrmkmK/nH8y6mAI7q7Cr7/tQ=; b=szadQiw/GB1UWNLtxwcm0FWYyxJP2BFHv//bS7JkVk7YjfoXcOZjCtpjcYmJ4dgxTO moXr7FURmQgtOWNp9uUvSifVrw94IcMzv/ysk1IZHLwEFJ2vCdJDFknnTZkbtsfhk0d6 qVlWFGvwsxCVdT/zQmP+mc1c6hreydgvogiOk5GHHf/xT1Rvwb1eF9MLMbw89c0FDjeI 2oP5o19CNbPJsFDCWp0l6kJm6o0K21fGROFq+2sfAE0cKhl4pKwz5/D76FpRqGNe6TWj NVLtCr/tRZbp9vq7/QDMi8XGSEzsWY5sMLVMyQTtYU9bJ8X0U8bGU0kc4GvSXtV06EWU R9Pw== X-Gm-Message-State: AOJu0YziM/tFv+h73qGE8TZCiodxLyW9RAp1T+9nyOFXPlpV49HSMdXc C638+qhY4s/OzCVijGYzU9hl0f+t1XWeb9x0mwrbbqaHakkZSeBQGC0GJilkSDVuyDzFMa/koDn O+glWkoOQdYRB/zGuhNmmLVSIOWFEdfRhsrXNcLEClgv3jOI2sFgc8Jhxb7tyYwTKQE639i8TJN /5u/Yqm6+sflyl9CiLcKpU1XxP+UwxUIGe X-Gm-Gg: ASbGncvwX4f92n9AARQ+ddifYN+NgL6VlT81uMeR+ozPzTgRYaugLFxum0QfM3oLGqR x56fOWdSP8al8RbVu+IxeG+sQPwgnRZdMHaOKY4Oh1mP7K4ObG7VdUNPIXzrsCgHCSCzF9kBVUJ h7FU9uRJbJMe9C0ggB57WoaXBQiRJvU1H5aFKKqPtYsGKJUg3qzmGPpvVbsK4lWHq+Y9xmH69HQ RDdeU/4G0tSY1Fx/jTzF/lJGJOK2VYYJou62JikiEdptnO/p9m9rDI6blQ9fCbgTwgWxyfcpUA+ 91KTvHsWpzOVVvbTG46eNjsNikeUOxEgjgThhag= X-Received: by 2002:a05:6000:1544:b0:386:3cfa:62ad with SMTP id ffacd0b85a97d-38a221e2eb3mr7223978f8f.1.1734808971453; Sat, 21 Dec 2024 11:22:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IFzNxqAV5ao1UpeUaGjUn9A0nTevPizecd+wrFtIdDWWyUmfO8/Ha4Do1E6D9RrvTXqzXsZ7g== X-Received: by 2002:a05:6000:1544:b0:386:3cfa:62ad with SMTP id ffacd0b85a97d-38a221e2eb3mr7223956f8f.1.1734808971004; Sat, 21 Dec 2024 11:22:51 -0800 (PST) From: David Hildenbrand To: qemu-devel@nongnu.org Cc: Halil Pasic , Christian Borntraeger , Eric Farman , Thomas Huth , Richard Henderson , "Michael S . Tsirkin" , David Hildenbrand Subject: [PULL v2 14/15] s390x/virtio-ccw: add support for virtio based memory devices Date: Sat, 21 Dec 2024 20:22:08 +0100 Message-ID: <20241221192209.3979595-15-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241221192209.3979595-1-david@redhat.com> References: <20241221192209.3979595-1-david@redhat.com> MIME-Version: 1.0 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=170.10.133.124; envelope-from=dhildenb@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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=-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_H2=-1.177, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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.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: 1734809012120116600 Content-Type: text/plain; charset="utf-8" Let's implement support for abstract virtio based memory devices, using the virtio-pci implementation as an orientation. Wire them up in the machine hotplug handler, taking care of s390x page size limitations. As we neither support virtio-mem or virtio-pmem yet, the code is effectively unused. We'll implement support for virtio-mem based on this next. Note that we won't wire up the virtio-pci variant (should currently be impossible due to lack of support for MSI-X), but we'll add a safety net to reject plugging them in the pre-plug handler. Message-ID: <20241219144115.2820241-14-david@redhat.com> Acked-by: Michael S. Tsirkin Signed-off-by: David Hildenbrand --- MAINTAINERS | 3 + hw/s390x/meson.build | 3 + hw/s390x/s390-virtio-ccw.c | 47 +++++++++- hw/s390x/virtio-ccw-md-stubs.c | 24 ++++++ hw/s390x/virtio-ccw-md.c | 153 +++++++++++++++++++++++++++++++++ hw/s390x/virtio-ccw-md.h | 44 ++++++++++ hw/virtio/Kconfig | 1 + 7 files changed, 274 insertions(+), 1 deletion(-) create mode 100644 hw/s390x/virtio-ccw-md-stubs.c create mode 100644 hw/s390x/virtio-ccw-md.c create mode 100644 hw/s390x/virtio-ccw-md.h diff --git a/MAINTAINERS b/MAINTAINERS index 430a0f4f8c..afb1203597 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2376,6 +2376,9 @@ F: include/hw/virtio/virtio-crypto.h virtio based memory device M: David Hildenbrand S: Supported +F: hw/s390x/virtio-ccw-md.c +F: hw/s390x/virtio-ccw-md.h +F: hw/s390x/virtio-ccw-md-stubs.c F: hw/virtio/virtio-md-pci.c F: include/hw/virtio/virtio-md-pci.h F: stubs/virtio-md-pci.c diff --git a/hw/s390x/meson.build b/hw/s390x/meson.build index e344a3bd8c..4431868408 100644 --- a/hw/s390x/meson.build +++ b/hw/s390x/meson.build @@ -50,8 +50,11 @@ endif virtio_ss.add(when: 'CONFIG_VHOST_SCSI', if_true: files('vhost-scsi-ccw.c'= )) virtio_ss.add(when: 'CONFIG_VHOST_VSOCK', if_true: files('vhost-vsock-ccw.= c')) virtio_ss.add(when: 'CONFIG_VHOST_USER_FS', if_true: files('vhost-user-fs-= ccw.c')) +virtio_ss.add(when: 'CONFIG_VIRTIO_MD', if_true: files('virtio-ccw-md.c')) s390x_ss.add_all(when: 'CONFIG_VIRTIO_CCW', if_true: virtio_ss) =20 +s390x_ss.add(when: 'CONFIG_VIRTIO_MD', if_false: files('virtio-ccw-md-stub= s.c')) + hw_arch +=3D {'s390x': s390x_ss} =20 hw_s390x_modules =3D {} diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c index 9f8d830798..097ec78826 100644 --- a/hw/s390x/s390-virtio-ccw.c +++ b/hw/s390x/s390-virtio-ccw.c @@ -46,6 +46,8 @@ #include "qapi/visitor.h" #include "hw/s390x/cpu-topology.h" #include "kvm/kvm_s390x.h" +#include "hw/virtio/virtio-md-pci.h" +#include "hw/s390x/virtio-ccw-md.h" #include CONFIG_DEVICES =20 static Error *pv_mig_blocker; @@ -546,11 +548,39 @@ static void s390_machine_reset(MachineState *machine,= ResetType type) s390_ipl_clear_reset_request(); } =20 +static void s390_machine_device_pre_plug(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **errp) +{ + if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MD_CCW)) { + virtio_ccw_md_pre_plug(VIRTIO_MD_CCW(dev), MACHINE(hotplug_dev), e= rrp); + } else if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MD_PCI)) { + error_setg(errp, + "PCI-attached virtio based memory devices not supported= "); + } +} + static void s390_machine_device_plug(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) { + S390CcwMachineState *s390ms =3D S390_CCW_MACHINE(hotplug_dev); + if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) { s390_cpu_plug(hotplug_dev, dev, errp); + } else if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MD_CCW)) { + /* + * At this point, the device is realized and set all memdevs mappe= d, so + * qemu_maxrampagesize() will pick up the page sizes of these memd= evs + * as well. Before we plug the device and expose any RAM memory re= gions + * to the system, make sure we don't exceed the previously set max= page + * size. While only relevant for KVM, there is not really any use = case + * for this with TCG, so we'll unconditionally reject it. + */ + if (qemu_maxrampagesize() !=3D s390ms->max_pagesize) { + error_setg(errp, "Memory device uses a bigger page size than" + " initial memory"); + return; + } + virtio_ccw_md_plug(VIRTIO_MD_CCW(dev), MACHINE(hotplug_dev), errp); } } =20 @@ -560,9 +590,20 @@ static void s390_machine_device_unplug_request(Hotplug= Handler *hotplug_dev, if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) { error_setg(errp, "CPU hot unplug not supported on this machine"); return; + } else if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MD_CCW)) { + virtio_ccw_md_unplug_request(VIRTIO_MD_CCW(dev), MACHINE(hotplug_d= ev), + errp); } } =20 +static void s390_machine_device_unplug(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **errp) +{ + if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MD_CCW)) { + virtio_ccw_md_unplug(VIRTIO_MD_CCW(dev), MACHINE(hotplug_dev), err= p); + } + } + static CpuInstanceProperties s390_cpu_index_to_props(MachineState *ms, unsigned cpu_index) { @@ -609,7 +650,9 @@ static const CPUArchIdList *s390_possible_cpu_arch_ids(= MachineState *ms) static HotplugHandler *s390_get_hotplug_handler(MachineState *machine, DeviceState *dev) { - if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) { + if (object_dynamic_cast(OBJECT(dev), TYPE_CPU) || + object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MD_CCW) || + object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MD_PCI)) { return HOTPLUG_HANDLER(machine); } return NULL; @@ -769,8 +812,10 @@ static void ccw_machine_class_init(ObjectClass *oc, vo= id *data) mc->possible_cpu_arch_ids =3D s390_possible_cpu_arch_ids; /* it is overridden with 'host' cpu *in kvm_arch_init* */ mc->default_cpu_type =3D S390_CPU_TYPE_NAME("qemu"); + hc->pre_plug =3D s390_machine_device_pre_plug; hc->plug =3D s390_machine_device_plug; hc->unplug_request =3D s390_machine_device_unplug_request; + hc->unplug =3D s390_machine_device_unplug; nc->nmi_monitor_handler =3D s390_nmi; mc->default_ram_id =3D "s390.ram"; mc->default_nic =3D "virtio-net-ccw"; diff --git a/hw/s390x/virtio-ccw-md-stubs.c b/hw/s390x/virtio-ccw-md-stubs.c new file mode 100644 index 0000000000..e937865550 --- /dev/null +++ b/hw/s390x/virtio-ccw-md-stubs.c @@ -0,0 +1,24 @@ +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "hw/s390x/virtio-ccw-md.h" + +void virtio_ccw_md_pre_plug(VirtIOMDCcw *vmd, MachineState *ms, Error **er= rp) +{ + error_setg(errp, "virtio based memory devices not supported"); +} + +void virtio_ccw_md_plug(VirtIOMDCcw *vmd, MachineState *ms, Error **errp) +{ + error_setg(errp, "virtio based memory devices not supported"); +} + +void virtio_ccw_md_unplug_request(VirtIOMDCcw *vmd, MachineState *ms, + Error **errp) +{ + error_setg(errp, "virtio based memory devices not supported"); +} + +void virtio_ccw_md_unplug(VirtIOMDCcw *vmd, MachineState *ms, Error **errp) +{ + error_setg(errp, "virtio based memory devices not supported"); +} diff --git a/hw/s390x/virtio-ccw-md.c b/hw/s390x/virtio-ccw-md.c new file mode 100644 index 0000000000..de333282df --- /dev/null +++ b/hw/s390x/virtio-ccw-md.c @@ -0,0 +1,153 @@ +/* + * Virtio CCW support for abstract virtio based memory device + * + * Copyright (C) 2024 Red Hat, Inc. + * + * Authors: + * David Hildenbrand + * + * This work is licensed under the terms of the GNU GPL, version 2. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "hw/s390x/virtio-ccw-md.h" +#include "hw/mem/memory-device.h" +#include "qapi/error.h" +#include "qemu/error-report.h" + +void virtio_ccw_md_pre_plug(VirtIOMDCcw *vmd, MachineState *ms, Error **er= rp) +{ + DeviceState *dev =3D DEVICE(vmd); + HotplugHandler *bus_handler =3D qdev_get_bus_hotplug_handler(dev); + MemoryDeviceState *md =3D MEMORY_DEVICE(vmd); + Error *local_err =3D NULL; + + if (!bus_handler && dev->hotplugged) { + /* + * Without a bus hotplug handler, we cannot control the plug/unplug + * order. We should never reach this point when hotplugging, but + * better add a safety net. + */ + error_setg(errp, "hotplug of virtio based memory devices not suppo= rted" + " on this bus."); + return; + } + + /* + * First, see if we can plug this memory device at all. If that + * succeeds, branch of to the actual hotplug handler. + */ + memory_device_pre_plug(md, ms, &local_err); + if (!local_err && bus_handler) { + hotplug_handler_pre_plug(bus_handler, dev, &local_err); + } + error_propagate(errp, local_err); +} + +void virtio_ccw_md_plug(VirtIOMDCcw *vmd, MachineState *ms, Error **errp) +{ + DeviceState *dev =3D DEVICE(vmd); + HotplugHandler *bus_handler =3D qdev_get_bus_hotplug_handler(dev); + MemoryDeviceState *md =3D MEMORY_DEVICE(vmd); + Error *local_err =3D NULL; + + /* + * Plug the memory device first and then branch off to the actual + * hotplug handler. If that one fails, we can easily undo the memory + * device bits. + */ + memory_device_plug(md, ms); + if (bus_handler) { + hotplug_handler_plug(bus_handler, dev, &local_err); + if (local_err) { + memory_device_unplug(md, ms); + } + } + error_propagate(errp, local_err); +} + +void virtio_ccw_md_unplug_request(VirtIOMDCcw *vmd, MachineState *ms, + Error **errp) +{ + VirtIOMDCcwClass *vmdc =3D VIRTIO_MD_CCW_GET_CLASS(vmd); + DeviceState *dev =3D DEVICE(vmd); + HotplugHandler *bus_handler =3D qdev_get_bus_hotplug_handler(dev); + HotplugHandlerClass *hdc; + Error *local_err =3D NULL; + + if (!vmdc->unplug_request_check) { + error_setg(errp, + "this virtio based memory devices cannot be unplugged"); + return; + } + + if (!bus_handler) { + error_setg(errp, "hotunplug of virtio based memory devices not" + "supported on this bus"); + return; + } + + vmdc->unplug_request_check(vmd, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } + + /* + * Forward the async request or turn it into a sync request (handling = it + * like qdev_unplug()). + */ + hdc =3D HOTPLUG_HANDLER_GET_CLASS(bus_handler); + if (hdc->unplug_request) { + hotplug_handler_unplug_request(bus_handler, dev, &local_err); + } else { + virtio_ccw_md_unplug(vmd, ms, &local_err); + if (!local_err) { + object_unparent(OBJECT(dev)); + } + } +} + +void virtio_ccw_md_unplug(VirtIOMDCcw *vmd, MachineState *ms, Error **errp) +{ + DeviceState *dev =3D DEVICE(vmd); + HotplugHandler *bus_handler =3D qdev_get_bus_hotplug_handler(dev); + MemoryDeviceState *md =3D MEMORY_DEVICE(vmd); + Error *local_err =3D NULL; + + /* Unplug the memory device while it is still realized. */ + memory_device_unplug(md, ms); + + if (bus_handler) { + hotplug_handler_unplug(bus_handler, dev, &local_err); + if (local_err) { + /* Not expected to fail ... but still try to recover. */ + memory_device_plug(md, ms); + error_propagate(errp, local_err); + return; + } + } else { + /* Very unexpected, but let's just try to do the right thing. */ + warn_report("Unexpected unplug of virtio based memory device"); + qdev_unrealize(dev); + } +} + +static const TypeInfo virtio_ccw_md_info =3D { + .name =3D TYPE_VIRTIO_MD_CCW, + .parent =3D TYPE_VIRTIO_CCW_DEVICE, + .instance_size =3D sizeof(VirtIOMDCcw), + .class_size =3D sizeof(VirtIOMDCcwClass), + .abstract =3D true, + .interfaces =3D (InterfaceInfo[]) { + { TYPE_MEMORY_DEVICE }, + { } + }, +}; + +static void virtio_ccw_md_register(void) +{ + type_register_static(&virtio_ccw_md_info); +} +type_init(virtio_ccw_md_register) diff --git a/hw/s390x/virtio-ccw-md.h b/hw/s390x/virtio-ccw-md.h new file mode 100644 index 0000000000..39ba864c92 --- /dev/null +++ b/hw/s390x/virtio-ccw-md.h @@ -0,0 +1,44 @@ +/* + * Virtio CCW support for abstract virtio based memory device + * + * Copyright (C) 2024 Red Hat, Inc. + * + * Authors: + * David Hildenbrand + * + * This work is licensed under the terms of the GNU GPL, version 2. + * See the COPYING file in the top-level directory. + */ + +#ifndef HW_S390X_VIRTIO_CCW_MD_H +#define HW_S390X_VIRTIO_CCW_MD_H + +#include "virtio-ccw.h" +#include "qom/object.h" + +/* + * virtio-md-ccw: This extends VirtioCcwDevice. + */ +#define TYPE_VIRTIO_MD_CCW "virtio-md-ccw" + +OBJECT_DECLARE_TYPE(VirtIOMDCcw, VirtIOMDCcwClass, VIRTIO_MD_CCW) + +struct VirtIOMDCcwClass { + /* private */ + VirtIOCCWDeviceClass parent; + + /* public */ + void (*unplug_request_check)(VirtIOMDCcw *vmd, Error **errp); +}; + +struct VirtIOMDCcw { + VirtioCcwDevice parent_obj; +}; + +void virtio_ccw_md_pre_plug(VirtIOMDCcw *vmd, MachineState *ms, Error **er= rp); +void virtio_ccw_md_plug(VirtIOMDCcw *vmd, MachineState *ms, Error **errp); +void virtio_ccw_md_unplug_request(VirtIOMDCcw *vmd, MachineState *ms, + Error **errp); +void virtio_ccw_md_unplug(VirtIOMDCcw *vmd, MachineState *ms, Error **errp= ); + +#endif /* HW_S390X_VIRTIO_CCW_MD_H */ diff --git a/hw/virtio/Kconfig b/hw/virtio/Kconfig index 70c77e183d..7648a2d68d 100644 --- a/hw/virtio/Kconfig +++ b/hw/virtio/Kconfig @@ -29,6 +29,7 @@ config VIRTIO_MMIO config VIRTIO_CCW bool select VIRTIO + select VIRTIO_MD_SUPPORTED =20 config VIRTIO_BALLOON bool --=20 2.47.1 From nobody Mon Dec 23 23:07:39 2024 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=1734809085; cv=none; d=zohomail.com; s=zohoarc; b=ANpW8MCcpHsQSByXnoU8hejVFl6LExI2L3U4lY7zmwCjZ6BhwvDf/c6Beh/rpWEKjrVgUaPBPJlpJ0rpS7JWGyYrcqCssJ0YxmD2kesFUXUbD9b4HMLA28kb4LI7gfgzVQZXmBRqpLI7YU1taW1ZtQAqiIcuE+tw3Re575i8584= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1734809085; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=pAsPaUKTuMa4Ous85d3PJEPNZrveVDpSgA8xfhYPloI=; b=KxkwOF+t1rKqvG7hQRfWyPMJNbjwg+rTeFA03UnxKlzJxFcSSE7BTgk54WjoTRAoXiWvw4CajZybue9ERpVLOfbuqZeLlJdneVGUSKJ1CeMhft/VCqtxriGHD2T2dhUlg6fFQ9cuDiDT6LKGLKMC2T8+DvlrIKeaF/2t93+/eto= 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 1734809085056737.2215679331802; Sat, 21 Dec 2024 11:24:45 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tP541-0002e6-FP; Sat, 21 Dec 2024 14:23:01 -0500 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 1tP53z-0002dC-LU for qemu-devel@nongnu.org; Sat, 21 Dec 2024 14:22:59 -0500 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 1tP53x-0000Od-6F for qemu-devel@nongnu.org; Sat, 21 Dec 2024 14:22:59 -0500 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-675-4AE0iMQNNgO5c8BB0jvnhQ-1; Sat, 21 Dec 2024 14:22:54 -0500 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-436328fcfeeso22567795e9.1 for ; Sat, 21 Dec 2024 11:22:54 -0800 (PST) Received: from localhost (p200300cbc7137800820d0e9f08ce52bd.dip0.t-ipconnect.de. [2003:cb:c713:7800:820d:e9f:8ce:52bd]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-436611ea42esm84219575e9.9.2024.12.21.11.22.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 21 Dec 2024 11:22:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734808976; 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=pAsPaUKTuMa4Ous85d3PJEPNZrveVDpSgA8xfhYPloI=; b=eulano7CCac5QMdfWSTsTclg7jYXZVahKETfuQrW00CkoALry4XBzjulcAWWWT0rKUA41T lqjdsQvvIZ9izAyrydXk7lYNNDyHhcRnAzIRPuhfKzHbnz/eI1xV3GatMsAj6kmKabvnLE 1wmZ3U6jV+2iSRhxsbXgM+DVFEJ4f9Y= X-MC-Unique: 4AE0iMQNNgO5c8BB0jvnhQ-1 X-Mimecast-MFC-AGG-ID: 4AE0iMQNNgO5c8BB0jvnhQ X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734808973; x=1735413773; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pAsPaUKTuMa4Ous85d3PJEPNZrveVDpSgA8xfhYPloI=; b=bQGjtKqTyJgY5BG3YjGhrARaNAMoSpO7F68sYG347JlhFM5uczAetUyJ3RuO9UY65L ZX9FXsAaOVsBlAMHEw/xJebOlUPDlDJWehfYD11Xxr0i/g1AIvWrAqpiqKD64KSbNrE/ P0by1opL6hdEUFVo/cKhyJYKkTHrKuzSLxtaqIdLeLeHfT3VvFcUCk73rmaKAdztcQ6y Yy6n1XB+tMriVQ3I9mBeZOoP08QbbX95VqWVw1VLJ4IXC8O8LmP1Ct+7q+NiwZ8ZDdxW PBvMoAKgQ7+k2juajLw15UTCu3mD39TSAhdK/dNZUdKEKAcQeMP5UQfTl/xA3HA/TmVM 1h3A== X-Gm-Message-State: AOJu0Yxdc3QvhozftyCphbZ9vPeQJJD2tQMPhkEFzYUyDO6hYPo7nKxh /DMG+Djlv4mU9XfxQDGPM8S0Aa9A725In9IsUIU1UAqgCdhEVcEKBOe9wRp+tN3tYp5JG9X/UJs wP4du3egQgFcbvwZZar5sO3PM3RY4P8VsFfJQGgbk0WLwyVQDQeel/xOqDNSCTgwCOhlCiKW98T mmxRCHPChSSO7IzGwbITk07uKrthgEpsEy X-Gm-Gg: ASbGncvCXReT312q5xaMD0o5nme8Zo3LOtZNj47ZTzwVMOZjuFqsVliwSbt/Q9RGBWi BNUCVHVnclEPbpq9/CRWfNyYE8S0bAqkPU9vtXVQh8E8TvhmEhrraHLNT1IJ6B9HX90wPPjCsdi 8i3kCZ6zGjc1Ycb1JTBet3qqmc2TZsGAn+MTyBPZP55+j373HJZ4hJoT0BpCCuFATUKeowUwjT2 i/VUlgHfI+eRQucwxJ/7Xn+/4Sxf/3r/eo3CI75qvNecVgfBDwPTvWIAwseCmy+fQYV6eWbibJI PEHclBK1LofuL6Hw3MFmWnQLqvy4OV6pCqIT4M8= X-Received: by 2002:a05:600c:1c22:b0:434:a10f:9b with SMTP id 5b1f17b1804b1-43668643b44mr64934785e9.14.1734808973580; Sat, 21 Dec 2024 11:22:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IFV0hK22k68c0SUkBR4bxMXvKu75fKLsoZD877KAtnkJkfdbOg+r76VlyvdDyDPdF0uPX/0jQ== X-Received: by 2002:a05:600c:1c22:b0:434:a10f:9b with SMTP id 5b1f17b1804b1-43668643b44mr64934585e9.14.1734808973031; Sat, 21 Dec 2024 11:22:53 -0800 (PST) From: David Hildenbrand To: qemu-devel@nongnu.org Cc: Halil Pasic , Christian Borntraeger , Eric Farman , Thomas Huth , Richard Henderson , "Michael S . Tsirkin" , David Hildenbrand Subject: [PULL v2 15/15] s390x: virtio-mem support Date: Sat, 21 Dec 2024 20:22:09 +0100 Message-ID: <20241221192209.3979595-16-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241221192209.3979595-1-david@redhat.com> References: <20241221192209.3979595-1-david@redhat.com> MIME-Version: 1.0 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=170.10.129.124; envelope-from=dhildenb@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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=-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_H2=-1.177, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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.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: 1734809086402116600 Content-Type: text/plain; charset="utf-8" Let's add our virtio-mem-ccw proxy device and wire it up. We should be supporting everything (e.g., device unplug, "dynamic-memslots") that we already support for the virtio-pci variant. With a Linux guest that supports virtio-mem (and has automatic memory onlining properly configured) the following example will work: 1. Start a VM with 4G initial memory and a virtio-mem device with a maximum capacity of 16GB: qemu/build/qemu-system-s390x \ --enable-kvm \ -m 4G,maxmem=3D20G \ -nographic \ -smp 8 \ -hda Fedora-Server-KVM-40-1.14.s390x.qcow2 \ -chardev socket,id=3Dmonitor,path=3D/var/tmp/monitor,server,nowait \ -mon chardev=3Dmonitor,mode=3Dreadline \ -object memory-backend-ram,id=3Dmem0,size=3D16G,reserve=3Doff \ -device virtio-mem-ccw,id=3Dvmem0,memdev=3Dmem0,dynamic-memslots=3Don 2. Query the current size of virtio-mem device: (qemu) info memory-devices Memory device [virtio-mem]: "vmem0" memaddr: 0x100000000 node: 0 requested-size: 0 size: 0 max-size: 17179869184 block-size: 1048576 memdev: /objects/mem0 3. Request to grow it to 8GB (hotplug 8GB): (qemu) qom-set vmem0 requested-size 8G (qemu) info memory-devices Memory device [virtio-mem]: "vmem0" memaddr: 0x100000000 node: 0 requested-size: 8589934592 size: 8589934592 max-size: 17179869184 block-size: 1048576 memdev: /objects/mem0 4. Request to grow to 16GB (hotplug another 8GB): (qemu) qom-set vmem0 requested-size 16G (qemu) info memory-devices Memory device [virtio-mem]: "vmem0" memaddr: 0x100000000 node: 0 requested-size: 17179869184 size: 17179869184 max-size: 17179869184 block-size: 1048576 memdev: /objects/mem0 5. Try to hotunplug all memory again, shrinking to 0GB: (qemu) qom-set vmem0 requested-size 0G (qemu) info memory-devices Memory device [virtio-mem]: "vmem0" memaddr: 0x100000000 node: 0 requested-size: 0 size: 0 max-size: 17179869184 block-size: 1048576 memdev: /objects/mem0 6. If it worked, unplug the device (qemu) device_del vmem0 (qemu) info memory-devices (qemu) object_del mem0 7. Hotplug a new device with a smaller capacity and directly size it to 1GB (qemu) object_add memory-backend-ram,id=3Dmem0,size=3D8G,reserve=3Doff (qemu) device_add virtio-mem-ccw,id=3Dvmem0,memdev=3Dmem0,\ dynamic-memslots=3Don,requested-size=3D1G (qemu) info memory-devices Memory device [virtio-mem]: "vmem0" memaddr: 0x100000000 node: 0 requested-size: 1073741824 size: 1073741824 max-size: 8589934592 block-size: 1048576 memdev: /objects/mem0 Trying to use a virtio-mem device backed by hugetlb into a !hugetlb VM correctly results in the error: ... Memory device uses a bigger page size than initial memory Note that the virtio-mem driver in Linux will supports 1 MiB (pageblock) granularity. Message-ID: <20241219144115.2820241-15-david@redhat.com> Acked-by: Michael S. Tsirkin Signed-off-by: David Hildenbrand --- MAINTAINERS | 2 + hw/s390x/Kconfig | 1 + hw/s390x/meson.build | 1 + hw/s390x/virtio-ccw-mem.c | 226 ++++++++++++++++++++++++++++++++++++++ hw/s390x/virtio-ccw-mem.h | 34 ++++++ hw/virtio/virtio-mem.c | 4 +- 6 files changed, 267 insertions(+), 1 deletion(-) create mode 100644 hw/s390x/virtio-ccw-mem.c create mode 100644 hw/s390x/virtio-ccw-mem.h diff --git a/MAINTAINERS b/MAINTAINERS index afb1203597..0b7605fbeb 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2390,6 +2390,8 @@ W: https://virtio-mem.gitlab.io/ F: hw/virtio/virtio-mem.c F: hw/virtio/virtio-mem-pci.h F: hw/virtio/virtio-mem-pci.c +F: hw/s390x/virtio-ccw-mem.c +F: hw/s390x/virtio-ccw-mem.h F: include/hw/virtio/virtio-mem.h =20 virtio-snd diff --git a/hw/s390x/Kconfig b/hw/s390x/Kconfig index 82afdaa9dc..02ea199701 100644 --- a/hw/s390x/Kconfig +++ b/hw/s390x/Kconfig @@ -16,3 +16,4 @@ config S390_CCW_VIRTIO select SCLPCONSOLE select VIRTIO_CCW select MSI_NONBROKEN + select VIRTIO_MEM_SUPPORTED diff --git a/hw/s390x/meson.build b/hw/s390x/meson.build index 4431868408..3bbebfd817 100644 --- a/hw/s390x/meson.build +++ b/hw/s390x/meson.build @@ -51,6 +51,7 @@ virtio_ss.add(when: 'CONFIG_VHOST_SCSI', if_true: files('= vhost-scsi-ccw.c')) virtio_ss.add(when: 'CONFIG_VHOST_VSOCK', if_true: files('vhost-vsock-ccw.= c')) virtio_ss.add(when: 'CONFIG_VHOST_USER_FS', if_true: files('vhost-user-fs-= ccw.c')) virtio_ss.add(when: 'CONFIG_VIRTIO_MD', if_true: files('virtio-ccw-md.c')) +virtio_ss.add(when: 'CONFIG_VIRTIO_MEM', if_true: files('virtio-ccw-mem.c'= )) s390x_ss.add_all(when: 'CONFIG_VIRTIO_CCW', if_true: virtio_ss) =20 s390x_ss.add(when: 'CONFIG_VIRTIO_MD', if_false: files('virtio-ccw-md-stub= s.c')) diff --git a/hw/s390x/virtio-ccw-mem.c b/hw/s390x/virtio-ccw-mem.c new file mode 100644 index 0000000000..bee0d560cb --- /dev/null +++ b/hw/s390x/virtio-ccw-mem.c @@ -0,0 +1,226 @@ +/* + * virtio-mem CCW implementation + * + * Copyright (C) 2024 Red Hat, Inc. + * + * Authors: + * David Hildenbrand + * + * This work is licensed under the terms of the GNU GPL, version 2. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "hw/qdev-properties.h" +#include "qapi/error.h" +#include "qemu/module.h" +#include "virtio-ccw-mem.h" +#include "hw/mem/memory-device.h" +#include "qapi/qapi-events-machine.h" +#include "qapi/qapi-events-misc.h" + +static void virtio_ccw_mem_realize(VirtioCcwDevice *ccw_dev, Error **errp) +{ + VirtIOMEMCcw *dev =3D VIRTIO_MEM_CCW(ccw_dev); + DeviceState *vdev =3D DEVICE(&dev->vdev); + + qdev_realize(vdev, BUS(&ccw_dev->bus), errp); +} + +static void virtio_ccw_mem_set_addr(MemoryDeviceState *md, uint64_t addr, + Error **errp) +{ + object_property_set_uint(OBJECT(md), VIRTIO_MEM_ADDR_PROP, addr, errp); +} + +static uint64_t virtio_ccw_mem_get_addr(const MemoryDeviceState *md) +{ + return object_property_get_uint(OBJECT(md), VIRTIO_MEM_ADDR_PROP, + &error_abort); +} + +static MemoryRegion *virtio_ccw_mem_get_memory_region(MemoryDeviceState *m= d, + Error **errp) +{ + VirtIOMEMCcw *dev =3D VIRTIO_MEM_CCW(md); + VirtIOMEM *vmem =3D &dev->vdev; + VirtIOMEMClass *vmc =3D VIRTIO_MEM_GET_CLASS(vmem); + + return vmc->get_memory_region(vmem, errp); +} + +static void virtio_ccw_mem_decide_memslots(MemoryDeviceState *md, + unsigned int limit) +{ + VirtIOMEMCcw *dev =3D VIRTIO_MEM_CCW(md); + VirtIOMEM *vmem =3D VIRTIO_MEM(&dev->vdev); + VirtIOMEMClass *vmc =3D VIRTIO_MEM_GET_CLASS(vmem); + + vmc->decide_memslots(vmem, limit); +} + +static unsigned int virtio_ccw_mem_get_memslots(MemoryDeviceState *md) +{ + VirtIOMEMCcw *dev =3D VIRTIO_MEM_CCW(md); + VirtIOMEM *vmem =3D VIRTIO_MEM(&dev->vdev); + VirtIOMEMClass *vmc =3D VIRTIO_MEM_GET_CLASS(vmem); + + return vmc->get_memslots(vmem); +} + +static uint64_t virtio_ccw_mem_get_plugged_size(const MemoryDeviceState *m= d, + Error **errp) +{ + return object_property_get_uint(OBJECT(md), VIRTIO_MEM_SIZE_PROP, + errp); +} + +static void virtio_ccw_mem_fill_device_info(const MemoryDeviceState *md, + MemoryDeviceInfo *info) +{ + VirtioMEMDeviceInfo *vi =3D g_new0(VirtioMEMDeviceInfo, 1); + VirtIOMEMCcw *dev =3D VIRTIO_MEM_CCW(md); + VirtIOMEM *vmem =3D &dev->vdev; + VirtIOMEMClass *vpc =3D VIRTIO_MEM_GET_CLASS(vmem); + DeviceState *vdev =3D DEVICE(md); + + if (vdev->id) { + vi->id =3D g_strdup(vdev->id); + } + + /* let the real device handle everything else */ + vpc->fill_device_info(vmem, vi); + + info->u.virtio_mem.data =3D vi; + info->type =3D MEMORY_DEVICE_INFO_KIND_VIRTIO_MEM; +} + +static uint64_t virtio_ccw_mem_get_min_alignment(const MemoryDeviceState *= md) +{ + return object_property_get_uint(OBJECT(md), VIRTIO_MEM_BLOCK_SIZE_PROP, + &error_abort); +} + +static void virtio_ccw_mem_size_change_notify(Notifier *notifier, void *da= ta) +{ + VirtIOMEMCcw *dev =3D container_of(notifier, VirtIOMEMCcw, + size_change_notifier); + DeviceState *vdev =3D DEVICE(dev); + char *qom_path =3D object_get_canonical_path(OBJECT(dev)); + const uint64_t * const size_p =3D data; + + qapi_event_send_memory_device_size_change(vdev->id, *size_p, qom_path); + g_free(qom_path); +} + +static void virtio_ccw_mem_unplug_request_check(VirtIOMDCcw *vmd, Error **= errp) +{ + VirtIOMEMCcw *dev =3D VIRTIO_MEM_CCW(vmd); + VirtIOMEM *vmem =3D &dev->vdev; + VirtIOMEMClass *vpc =3D VIRTIO_MEM_GET_CLASS(vmem); + + vpc->unplug_request_check(vmem, errp); +} + +static void virtio_ccw_mem_get_requested_size(Object *obj, Visitor *v, + const char *name, void *opaq= ue, + Error **errp) +{ + VirtIOMEMCcw *dev =3D VIRTIO_MEM_CCW(obj); + + object_property_get(OBJECT(&dev->vdev), name, v, errp); +} + +static void virtio_ccw_mem_set_requested_size(Object *obj, Visitor *v, + const char *name, void *opaq= ue, + Error **errp) +{ + VirtIOMEMCcw *dev =3D VIRTIO_MEM_CCW(obj); + DeviceState *vdev =3D DEVICE(obj); + + /* + * If we passed virtio_ccw_mem_unplug_request_check(), making sure that + * the requested size is 0, don't allow modifying the requested size + * anymore, otherwise the VM might end up hotplugging memory before + * handling the unplug request. + */ + if (vdev->pending_deleted_event) { + error_setg(errp, "'%s' cannot be changed if the device is in the" + " process of unplug", name); + return; + } + + object_property_set(OBJECT(&dev->vdev), name, v, errp); +} + +static Property virtio_ccw_mem_properties[] =3D { + DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags, + VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true), + DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice, max_rev, + VIRTIO_CCW_MAX_REV), + DEFINE_PROP_END_OF_LIST(), +}; + +static void virtio_ccw_mem_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + VirtIOCCWDeviceClass *k =3D VIRTIO_CCW_DEVICE_CLASS(klass); + MemoryDeviceClass *mdc =3D MEMORY_DEVICE_CLASS(klass); + VirtIOMDCcwClass *vmdc =3D VIRTIO_MD_CCW_CLASS(klass); + + k->realize =3D virtio_ccw_mem_realize; + set_bit(DEVICE_CATEGORY_MISC, dc->categories); + device_class_set_props(dc, virtio_ccw_mem_properties); + + mdc->get_addr =3D virtio_ccw_mem_get_addr; + mdc->set_addr =3D virtio_ccw_mem_set_addr; + mdc->get_plugged_size =3D virtio_ccw_mem_get_plugged_size; + mdc->get_memory_region =3D virtio_ccw_mem_get_memory_region; + mdc->decide_memslots =3D virtio_ccw_mem_decide_memslots; + mdc->get_memslots =3D virtio_ccw_mem_get_memslots; + mdc->fill_device_info =3D virtio_ccw_mem_fill_device_info; + mdc->get_min_alignment =3D virtio_ccw_mem_get_min_alignment; + + vmdc->unplug_request_check =3D virtio_ccw_mem_unplug_request_check; +} + +static void virtio_ccw_mem_instance_init(Object *obj) +{ + VirtIOMEMCcw *dev =3D VIRTIO_MEM_CCW(obj); + VirtIOMEMClass *vmc; + VirtIOMEM *vmem; + + virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), + TYPE_VIRTIO_MEM); + + dev->size_change_notifier.notify =3D virtio_ccw_mem_size_change_notify; + vmem =3D &dev->vdev; + vmc =3D VIRTIO_MEM_GET_CLASS(vmem); + /* + * We never remove the notifier again, as we expect both devices to + * disappear at the same time. + */ + vmc->add_size_change_notifier(vmem, &dev->size_change_notifier); + + object_property_add_alias(obj, VIRTIO_MEM_BLOCK_SIZE_PROP, + OBJECT(&dev->vdev), VIRTIO_MEM_BLOCK_SIZE_PR= OP); + object_property_add_alias(obj, VIRTIO_MEM_SIZE_PROP, OBJECT(&dev->vdev= ), + VIRTIO_MEM_SIZE_PROP); + object_property_add(obj, VIRTIO_MEM_REQUESTED_SIZE_PROP, "size", + virtio_ccw_mem_get_requested_size, + virtio_ccw_mem_set_requested_size, NULL, NULL); +} + +static const TypeInfo virtio_ccw_mem =3D { + .name =3D TYPE_VIRTIO_MEM_CCW, + .parent =3D TYPE_VIRTIO_MD_CCW, + .instance_size =3D sizeof(VirtIOMEMCcw), + .instance_init =3D virtio_ccw_mem_instance_init, + .class_init =3D virtio_ccw_mem_class_init, +}; + +static void virtio_ccw_mem_register_types(void) +{ + type_register_static(&virtio_ccw_mem); +} +type_init(virtio_ccw_mem_register_types) diff --git a/hw/s390x/virtio-ccw-mem.h b/hw/s390x/virtio-ccw-mem.h new file mode 100644 index 0000000000..738ab2c744 --- /dev/null +++ b/hw/s390x/virtio-ccw-mem.h @@ -0,0 +1,34 @@ +/* + * Virtio MEM CCW device + * + * Copyright (C) 2024 Red Hat, Inc. + * + * Authors: + * David Hildenbrand + * + * This work is licensed under the terms of the GNU GPL, version 2. + * See the COPYING file in the top-level directory. + */ + +#ifndef HW_S390X_VIRTIO_CCW_MEM_H +#define HW_S390X_VIRTIO_CCW_MEM_H + +#include "virtio-ccw-md.h" +#include "hw/virtio/virtio-mem.h" +#include "qom/object.h" + +typedef struct VirtIOMEMCcw VirtIOMEMCcw; + +/* + * virtio-mem-ccw: This extends VirtIOMDCcw + */ +#define TYPE_VIRTIO_MEM_CCW "virtio-mem-ccw" +DECLARE_INSTANCE_CHECKER(VirtIOMEMCcw, VIRTIO_MEM_CCW, TYPE_VIRTIO_MEM_CCW) + +struct VirtIOMEMCcw { + VirtIOMDCcw parent_obj; + VirtIOMEM vdev; + Notifier size_change_notifier; +}; + +#endif /* HW_S390X_VIRTIO_CCW_MEM_H */ diff --git a/hw/virtio/virtio-mem.c b/hw/virtio/virtio-mem.c index a0dceaddec..48e4a58239 100644 --- a/hw/virtio/virtio-mem.c +++ b/hw/virtio/virtio-mem.c @@ -61,6 +61,8 @@ static uint32_t virtio_mem_default_thp_size(void) } else if (qemu_real_host_page_size() =3D=3D 64 * KiB) { default_thp_size =3D 512 * MiB; } +#elif defined(__s390x__) + default_thp_size =3D 1 * MiB; #endif =20 return default_thp_size; @@ -168,7 +170,7 @@ static bool virtio_mem_has_shared_zeropage(RAMBlock *rb) * necessary (as the section size can change). But it's more likely that t= he * section size will rather get smaller and not bigger over time. */ -#if defined(TARGET_X86_64) || defined(TARGET_I386) +#if defined(TARGET_X86_64) || defined(TARGET_I386) || defined(TARGET_S390X) #define VIRTIO_MEM_USABLE_EXTENT (2 * (128 * MiB)) #elif defined(TARGET_ARM) #define VIRTIO_MEM_USABLE_EXTENT (2 * (512 * MiB)) --=20 2.47.1