From patchwork Wed Dec 18 10:52:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13913442 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9E088E7718A for ; Wed, 18 Dec 2024 10:56:09 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tNrhy-0000ys-9N; Wed, 18 Dec 2024 05:55:14 -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 1tNrhp-0000mP-OW for qemu-devel@nongnu.org; Wed, 18 Dec 2024 05:55:05 -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 1tNrhn-0006sC-B8 for qemu-devel@nongnu.org; Wed, 18 Dec 2024 05:55:05 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734519302; 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=AhVrh3Q3z4Bfk8jUFJBhDnddlEzyQULJelziI+3XsoJjrYw99bePWMQBGjLuwf7TIUp3OY nluvIBzp3UhVl+V6Wkp93aksb+5FMKorjcq9nOwB+5els2DpKaBLh3+V/wgZSlMbRODYYE 8B0s8kV4y1X94m6mgYoRWgrYKBIw3Gw= 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-322-Ki4VnQz5Ma6pkDrB89Q-oQ-1; Wed, 18 Dec 2024 05:53:11 -0500 X-MC-Unique: Ki4VnQz5Ma6pkDrB89Q-oQ-1 X-Mimecast-MFC-AGG-ID: Ki4VnQz5Ma6pkDrB89Q-oQ Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-43627bb20b5so49863365e9.1 for ; Wed, 18 Dec 2024 02:53:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734519190; x=1735123990; 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=mdGY3Yf3AQgcRNSmpYACC2nU511J/TVfiHu9tMWqm9jwxKuaDLMf/8yqJeKD2yvBQN vr7KfFEnGTE9HCaP4fMt/T3hhaJkKtRuK09NwLJ3ksPw1+Bz39ri+5b8zQqnSugE1R6Q MqO8lAa8+3erByWgSNYibu3LmH5foSrGjfIKVrnOjOGQfpMUAguT46+9jEbjX+FzLmY2 kk+7SgUCQTI+XO5bgZQdseY+nXjt6OUDVPny4aKroCUAazWykbUlbPVjS2xCjjX/IaNF ERAi1gwKPEB8IA8wgPq2exlwQSAvAuJkfve1e2o1eWcFYKcdac7nQm/Q7IpeP9gZPTLS 9iwg== X-Gm-Message-State: AOJu0YyukCdzk+9Hmt/O/wIzoli9TWahrz4BF6xJFrs41y2tlcdBF94z 6HYouTx12QE4GAVtUPJD5jRVOWoRmCnN1b6Qy3Z9yNWMQxAQrFOZ09EQqn4cTKHsGE278JeqK9B 0zR/knYzn48KNqsJgXaFtC7Z6hYZTmPVd7rg9EEKaF7fzXbNLGY66haVSWKr3BVipR2TbwL+X5f DVgu+Gw63JycuUvMJipwjo1iZMBHVg1ITz6yw= X-Gm-Gg: ASbGnctVYWXlc2pbJGTkyb23luJyU3CdlYAaTdLvq+CnQpAsQOKvZTP5tnVTWpbi5SN z8q7/LyhL2dkaI6bq2j/XPjOJuIotgva3b3GcMZYmH/XH2QP9m7b3tP1jetBAB0ct3Ov1v2T3uz LHJNrQl7+NicYQq3HgWsshZ/GClwPPQv+sZLc8ILWP8bn14PHjuwRLL2sZop/J3OLswJN6B0mvy wjgGZ8Ws53aInlYMAPPr7IXMQ4jjLHWnlPCc9s2f19zKk5E8+4i7Jgktvwn5q85LJUmcSxcZn4a a0jCzKPfhL2UDp1ZYYRL1XcpIRDofwITPpLnrE1c4w== X-Received: by 2002:a05:600c:3ba8:b0:42c:bb10:7292 with SMTP id 5b1f17b1804b1-43655341f14mr17282755e9.1.1734519190008; Wed, 18 Dec 2024 02:53:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IHJdZsBZakKgxs096l2IqY1hOhqzw+dNo4w+a7zPwLN3zcl1j8auOY5+RpIUU8NGa6BAyWuNQ== X-Received: by 2002:a05:600c:3ba8:b0:42c:bb10:7292 with SMTP id 5b1f17b1804b1-43655341f14mr17282465e9.1.1734519189505; Wed, 18 Dec 2024 02:53:09 -0800 (PST) Received: from localhost (p200300cbc73f8300a5d5c21badd3cf50.dip0.t-ipconnect.de. [2003:cb:c73f:8300:a5d5:c21b:add3:cf50]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-43656b1248dsm16289575e9.24.2024.12.18.02.53.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 18 Dec 2024 02:53:08 -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 01/15] virtio-mem: unplug memory only during system resets, not device resets Date: Wed, 18 Dec 2024 11:52:49 +0100 Message-ID: <20241218105303.1966303-2-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241218105303.1966303-1-david@redhat.com> References: <20241218105303.1966303-1-david@redhat.com> MIME-Version: 1.0 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: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 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.116, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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 = VIRTIO_MEM(dev); uint64_t page_size; RAMBlock *rb; + Object *obj; int ret; if (!vmem->memdev) { @@ -1121,7 +1122,28 @@ static void virtio_mem_device_realize(DeviceState *dev, 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. Therefore, + * we need a dedicated reset object that only gets called during + * qemu_devices_reset(). + */ + obj = object_new(TYPE_VIRTIO_MEM_SYSTEM_RESET); + vmem->system_reset = VIRTIO_MEM_SYSTEM_RESET(obj); + vmem->system_reset->vmem = vmem; + qemu_register_resettable(obj); /* * 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_early, vmem); @@ -1841,38 +1866,12 @@ static void virtio_mem_unplug_request_check(VirtIOMEM *vmem, Error **errp) } } -static ResettableState *virtio_mem_get_reset_state(Object *obj) -{ - VirtIOMEM *vmem = VIRTIO_MEM(obj); - return &vmem->reset_state; -} - -static void virtio_mem_system_reset_hold(Object *obj, ResetType type) -{ - VirtIOMEM *vmem = VIRTIO_MEM(obj); - - /* - * When waking up from standby/suspend-to-ram, do not unplug any memory. - */ - if (type == 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 = DEVICE_CLASS(klass); VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass); VirtIOMEMClass *vmc = VIRTIO_MEM_CLASS(klass); RamDiscardManagerClass *rdmc = RAM_DISCARD_MANAGER_CLASS(klass); - ResettableClass *rc = RESETTABLE_CLASS(klass); device_class_set_props(dc, virtio_mem_properties); dc->vmsd = &vmstate_virtio_mem; @@ -1899,9 +1898,6 @@ static void virtio_mem_class_init(ObjectClass *klass, void *data) rdmc->replay_discarded = virtio_mem_rdm_replay_discarded; rdmc->register_listener = virtio_mem_rdm_register_listener; rdmc->unregister_listener = virtio_mem_rdm_unregister_listener; - - rc->get_state = virtio_mem_get_reset_state; - rc->phases.hold = virtio_mem_system_reset_hold; } static const TypeInfo virtio_mem_info = { @@ -1924,3 +1920,48 @@ static void virtio_register_types(void) } 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 = VIRTIO_MEM_SYSTEM_RESET(obj); + + return &vmem_reset->reset_state; +} + +static void virtio_mem_system_reset_hold(Object *obj, ResetType type) +{ + VirtioMemSystemReset *vmem_reset = VIRTIO_MEM_SYSTEM_RESET(obj); + VirtIOMEM *vmem = vmem_reset->vmem; + + /* + * When waking up from standby/suspend-to-ram, do not unplug any memory. + */ + if (type == 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 *data) +{ + ResettableClass *rc = RESETTABLE_CLASS(klass); + + rc->get_state = virtio_mem_system_reset_get_state; + rc->phases.hold = 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) +#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; - /* State of the resettable container */ + /* Catch system resets -> qemu_devices_reset() only. */ + VirtioMemSystemReset *system_reset; +}; + +struct VirtioMemSystemReset { + Object parent; + ResettableState reset_state; + VirtIOMEM *vmem; }; struct VirtIOMEMClass { From patchwork Wed Dec 18 10:52:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13913435 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4E41CE7718A for ; Wed, 18 Dec 2024 10:55:31 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tNrhB-0000c5-7K; Wed, 18 Dec 2024 05:54: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 1tNrh9-0000bd-Fh for qemu-devel@nongnu.org; Wed, 18 Dec 2024 05:54:23 -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 1tNrh7-0006mB-Lz for qemu-devel@nongnu.org; Wed, 18 Dec 2024 05:54:23 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734519258; 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=QndkQAdv+aZOEQr2b2o41BTTLOjnawhbhJJcyyz1yzo=; b=QfG24xi7jqTAq2SG8L5rSTkrTmBQD+aIdBUljBVQFDtawR4yXzn+H1wGyBnCxR8/IktRDe +LVEDb1Bpg5ePAyezohC8im446g1DBkoeuXLzdLc9tUJbH0ZacCYlgExfk+yWZhQs0oGOv 9Wa/QJSJg0JwvfgMLWjzrkV/WGgtknw= 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-133-654OZlAmPouDCk7lUTMWxQ-1; Wed, 18 Dec 2024 05:53:12 -0500 X-MC-Unique: 654OZlAmPouDCk7lUTMWxQ-1 X-Mimecast-MFC-AGG-ID: 654OZlAmPouDCk7lUTMWxQ Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-43610eba55bso21948595e9.3 for ; Wed, 18 Dec 2024 02:53:12 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734519191; x=1735123991; 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=QndkQAdv+aZOEQr2b2o41BTTLOjnawhbhJJcyyz1yzo=; b=qDPQGIHhYaoWfDygj+tcusmtcKnrEfWKsfenIjA0NQkVSIDXESaoTPmyyDs224BP7y rmXQ4EzDCaRAT7DAaNfVZf+UGOenm3zF73lOq94kT3Q+16eIZ3tv0UZ21q5un+hiI/2H q6MBSIw1UKXQ0hVRe8ddpUwfjGPU19EFTmGt6vsdYenqONopvCSztMiljq/ibOxaVNRc cD+RoIgBoyveaN9FZ2YKaV3tUj6/E3kr0KYAFC9UAAToatJ8LNlg/kkVOwNmLrbcpN68 kytdbMYRP/zG1ZncvdY6Pjilp/gBKLj0pHDTXApSqa00sfnV1jBGfa0y7YEe/JasEdeG l8zQ== X-Gm-Message-State: AOJu0Yz29rAHiRk4VlQT8oiaBN7NMiiA1XWFy7Kwoj9RP3ZANpC0tLsq LAccoKESK4nLli8pZS3kr10SJG7QglK0XUVAP+QH0JthcE3uoNZe9QswZMYadX3gGMC6tFEVggv vucUAgH0CvZwjA3XtrD12NLPzeeHqVxuEUYOHjp+zPES3tmGMV/8oDw3mqAFliIEoPxDX49xPsZ qTqH0I+DZXhtAEu7SgL7DFFpT6nVvfc4sC6jc= X-Gm-Gg: ASbGncvzhjYq+7fXbsqx5KMV5fGjxv4uK9taMw6Uzy5IRg/7Lw3eZKMsGIphrY6ksUi yoMogSuY/W+jqc7Mxl5DyTB3KBLPw8HDsQaH2xJRYxhUZf21XUgKJ0AcAt2bOTiWvyShDy0TtvF y8RilMlBt4iIlCrbFbBmdLLYNnNekvA8s9KxYM+Elxi/CPs5LPUxwIRMSVL4/dCGdTU2jeOc/x4 wgqJBC+ddb7ORMxzNd8xT1pKgy8ZHc7nmmEbNLLYFkWJdRew/d3qvzJTVPLdzf9rYhAoA456bC1 lnRj9W6dcg6Iwd59KOUBaxiJ5Nogl0LNMEHiVE8BnA== X-Received: by 2002:a05:600c:45cd:b0:434:fddf:5bfa with SMTP id 5b1f17b1804b1-43655341465mr21064715e9.2.1734519191588; Wed, 18 Dec 2024 02:53:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IHR0GhsNJkR9YG52+yzP7+HPVmEa2YqTJ+dNd52NFn3823753NX0Tgszl+whEt1epgFq1rrhQ== X-Received: by 2002:a05:600c:45cd:b0:434:fddf:5bfa with SMTP id 5b1f17b1804b1-43655341465mr21064355e9.2.1734519191118; Wed, 18 Dec 2024 02:53:11 -0800 (PST) Received: from localhost (p200300cbc73f8300a5d5c21badd3cf50.dip0.t-ipconnect.de. [2003:cb:c73f:8300:a5d5:c21b:add3:cf50]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-43656b1143dsm16214115e9.18.2024.12.18.02.53.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 18 Dec 2024 02:53:10 -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 02/15] s390x/s390-virtio-ccw: don't crash on weird RAM sizes Date: Wed, 18 Dec 2024 11:52:50 +0100 Message-ID: <20241218105303.1966303-3-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241218105303.1966303-1-david@redhat.com> References: <20241218105303.1966303-1-david@redhat.com> MIME-Version: 1.0 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: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 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.116, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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=0, start=0x0, size=0x244000: 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: <20241008105455.2302628-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 = get_system_memory(); + if (!QEMU_IS_ALIGNED(memory_region_size(ram), 1 * MiB)) { + /* + * SCLP cannot possibly expose smaller granularity right now and KVM + * 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); From patchwork Wed Dec 18 10:52:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13913436 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 13431E77188 for ; Wed, 18 Dec 2024 10:55:41 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tNriF-0001OF-BF; Wed, 18 Dec 2024 05:55:31 -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 1tNrht-0000nh-3T for qemu-devel@nongnu.org; Wed, 18 Dec 2024 05:55:13 -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 1tNrho-0006zD-63 for qemu-devel@nongnu.org; Wed, 18 Dec 2024 05:55:08 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734519303; 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=AxxchDNQC4SAcVGoK+vji+3LCeK2icJzmCxE+kApb18=; b=NCp82HLom1mMUSgCSKc1JP0dzYBAwBU1wgrQSF6Ms4HCotDvhY5HMKx03QwxuzEonv+1v3 WUxf/sbDCbZASvJMEO48r7/hO8MNVKHNuFTFGfNJbdo5JF3AhA8zHmcZPG3BTp+6Igxwjo TDPd0Z8Z+iidgFz8W5hqGQdU5vE5u4o= 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-515-dAxi-L4OPB6Xxtjqy8Tq1g-1; Wed, 18 Dec 2024 05:53:15 -0500 X-MC-Unique: dAxi-L4OPB6Xxtjqy8Tq1g-1 X-Mimecast-MFC-AGG-ID: dAxi-L4OPB6Xxtjqy8Tq1g Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-3860bc1d4f1so4224999f8f.2 for ; Wed, 18 Dec 2024 02:53:14 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734519194; x=1735123994; 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=AxxchDNQC4SAcVGoK+vji+3LCeK2icJzmCxE+kApb18=; b=tkX62usuIdb6HydA3pPGdDfwc7MehzgsTn8G+Uu6BYlxK8DvclnKB5c2GX3G+YjrQy IpquWpWiQXnmKz8FgDs+ODpUC4nC4Aer7oPozSf46GqQcWrtMxIyfC63vQma6+j4c0M2 DmRJyEpQo/tekY62kO+EetKLDUaRFXLGc/YsUMHsnyVB8ErpUji+gjjqYOMGkQE/wKiK CHXazOoZzOiIlUD0EH5vgB5x4f/I6frFD7eOwRgyl7uWZqIoNXYeNoi3bESh66kWRb8q crqIWVmv+yIGwYNAoibtqPC+bfkgqFZbxsn/Zgq/rjIdVH3HxYG0uG+6TIoIc99cHZBF Qdew== X-Gm-Message-State: AOJu0YwXv0e1C0VWc1sjtMuwYSHNCNcQ74YpK+aTTJQcrbAlBDKlnAxy 3JlmDms9aFflADUfPuAJThKZTNhIUApZKrob7Gb4tQwTPeHdCbchDaGRuZYMw93p2A2iB4fRWUw mPdQJs986oYrlOdLWI7nohoO1ZmC18ykEnB/9dJH2KwLzGTcAoVbv8qkEAqbVJNUZRN+3vzOdOp m9irB9XR9pCuHtK4B8Of+7AQc/6H0HLEbzYUs= X-Gm-Gg: ASbGncvtC3FFOlX6fZG+SYQ0+Cr+5jKP7Ytfm6mw1DzoJ2yuyhfFyv9SjfufAqJwOLd DK2PvTd1kmRNZyqersJDnkrFdXW8W5xoRg8U1Ylo2ML/3ndWQqkAh+Blsi5H7oshqo7+V2gMSzQ che/2mkYyxLZjkFvMxB+Fegg17BojFMcWWQOhCJE0bUIWt1ITU8ritjm5SJtG6Z7oHAwfQW1Nw9 Xr/yCEAIp2Njg0zdgfGeQUDLtTR02UO8fSjlOsfisRLN5gVdGX1iRrCJH8ZMcG5IKfKt5JGcr4l irAUgH7f5M7IMk60ZLx24iINYB/25SBpoOunThn+Sg== X-Received: by 2002:a05:6000:1f89:b0:386:1cd3:8a07 with SMTP id ffacd0b85a97d-388e4d3125amr2397197f8f.7.1734519193926; Wed, 18 Dec 2024 02:53:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IGfibFWX5cTe42xxKTjQo5HD8qlI7NE464blGE5LJrNukJzxxjJvaOKpyjbJ8dTZKbgPpGqEA== X-Received: by 2002:a05:6000:1f89:b0:386:1cd3:8a07 with SMTP id ffacd0b85a97d-388e4d3125amr2397156f8f.7.1734519193465; Wed, 18 Dec 2024 02:53:13 -0800 (PST) Received: from localhost (p200300cbc73f8300a5d5c21badd3cf50.dip0.t-ipconnect.de. [2003:cb:c73f:8300:a5d5:c21b:add3:cf50]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-4364b0532a6sm47177535e9.1.2024.12.18.02.53.11 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 18 Dec 2024 02:53:12 -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 03/15] s390x/s390-virtio-hcall: remove hypercall registration mechanism Date: Wed, 18 Dec 2024 11:52:51 +0100 Message-ID: <20241218105303.1966303-4-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241218105303.1966303-1-david@redhat.com> References: <20241218105303.1966303-1-david@redhat.com> MIME-Version: 1.0 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: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 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.116, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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: <20241008105455.2302628-3-david@redhat.com> Acked-by: Michael S. Tsirkin Reviewed-by: Thomas Huth Acked-by: Christian Borntraeger Signed-off-by: David Hildenbrand --- hw/s390x/s390-virtio-ccw.c | 58 -------------------------------- hw/s390x/s390-virtio-hcall.c | 65 +++++++++++++++++++++++++++--------- hw/s390x/s390-virtio-hcall.h | 2 -- 3 files changed, 49 insertions(+), 76 deletions(-) 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) } } -static int virtio_ccw_hcall_notify(const uint64_t *args) -{ - uint64_t subch_id = args[0]; - uint64_t data = args[1]; - SubchDev *sch; - VirtIODevice *vdev; - int cssid, ssid, schid, m; - uint16_t vq_idx = data; - - if (ioinst_disassemble_sch_ident(subch_id, &m, &cssid, &ssid, &schid)) { - return -EINVAL; - } - sch = css_find_subch(m, cssid, ssid, schid); - if (!sch || !css_subch_visible(sch)) { - return -EINVAL; - } - - vdev = virtio_ccw_get_vdev(sch); - if (vq_idx >= 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 = args[0]; - MachineState *ms = 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 = 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); - /* register hypercalls */ - virtio_ccw_register_hcalls(); - s390_enable_css_support(s390_cpu_addr2state(0)); ret = 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 @@ #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" -#define MAX_DIAG_SUBCODES 255 +static int handle_virtio_notify(uint64_t mem) +{ + MachineState *ms = MACHINE(qdev_get_machine()); -static s390_virtio_fn s390_diag500_table[MAX_DIAG_SUBCODES]; + if (mem < ms->ram_size) { + /* Early printk */ + return 0; + } + return -EINVAL; +} -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 = data; + + if (ioinst_disassemble_sch_ident(subch_id, &m, &cssid, &ssid, &schid)) { + return -EINVAL; + } + sch = css_find_subch(m, cssid, ssid, schid); + if (!sch || !css_subch_visible(sch)) { + return -EINVAL; + } - s390_diag500_table[code] = fn; + vdev = virtio_ccw_get_vdev(sch); + if (vq_idx >= 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; } int s390_virtio_hypercall(CPUS390XState *env) { - s390_virtio_fn fn; - - if (env->regs[1] < MAX_DIAG_SUBCODES) { - fn = s390_diag500_table[env->regs[1]]; - if (fn) { - env->regs[2] = fn(&env->regs[2]); - return 0; - } - } + const uint64_t subcode = env->regs[1]; - return -EINVAL; + switch (subcode) { + case KVM_S390_VIRTIO_NOTIFY: + env->regs[2] = handle_virtio_notify(env->regs[2]); + return 0; + case KVM_S390_VIRTIO_CCW_NOTIFY: + env->regs[2] = 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 -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); #endif /* HW_S390_VIRTIO_HCALL_H */ From patchwork Wed Dec 18 10:52:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13913438 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 069E6E77187 for ; Wed, 18 Dec 2024 10:55:51 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tNriJ-0001kS-CG; Wed, 18 Dec 2024 05:55: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 1tNrhs-0000nG-Uo for qemu-devel@nongnu.org; Wed, 18 Dec 2024 05:55:13 -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 1tNrho-0006zg-5y for qemu-devel@nongnu.org; Wed, 18 Dec 2024 05:55:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734519303; 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=7uM+FWljAFEQKRezuys6B3I8zqsZ9FHnISAqVX/2eZI=; b=Y9+58KlfYcugPgy6DW3gP8ygF362rn+5tykTj/0/AZFltF6FVQp3ucMsNJBaFZc9NRoZPZ OP3gwClGmYwLdZkLfAvCv5lGdNloasOCf2lbntCEYLX5loKHTkwv0fqn2xYFqEhw0DVhvr MebUbJCVt2PGdsfzel3Cp+rYvSvmmMw= 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-226-6acG3tf4MYq-6N3JVdz1MQ-1; Wed, 18 Dec 2024 05:53:17 -0500 X-MC-Unique: 6acG3tf4MYq-6N3JVdz1MQ-1 X-Mimecast-MFC-AGG-ID: 6acG3tf4MYq-6N3JVdz1MQ Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-38629a685fdso2004056f8f.2 for ; Wed, 18 Dec 2024 02:53:17 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734519196; x=1735123996; 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=7uM+FWljAFEQKRezuys6B3I8zqsZ9FHnISAqVX/2eZI=; b=bbMBUQoDz+o9kINMSg+2uhaK99RklPHxGv9vHUZWiestqbxfBgcH9k9oNzX6FBNrTR HVO5AwaZZLOt4/nr+T0dBzZXqA5JxboyuraDOfnae0ZRy2PYxsW59JMqkKSsenlkvJt/ e3/R3aomLIHD7FCSzZw3VZl9nGOkdeWNn9CFJrlHXS77lKGqjd1TcRmNJOu6KzymxRNd kr538dzsFDyBeW1y6JgAZ2r8RdyfDabJyUYePpxiozgn7Wsb2QuRxkvUFEfwA3NHNPjQ TH3Qa04gZLACGeGuE/6LzJpBizKfsvMiIGQ2C1NjU06STnYERI9cb02zoUwSBmMlOk46 mwlA== X-Gm-Message-State: AOJu0Yxa7wigh8HF4pSRypasu4iQcpAVRyyEbuawkmE2WVwFD25Gl7ye X26TYgdiZgK0x/FiekusiLX63l9v7xdV0jqx4x8Z/nDtuONU6D8viU6YLsGc6sd2Ot24Y/vokVy folf99/+KAKabeG5GEJEtg9eq/8zpDbTm3Pqu6vddWHT9ra8e57B1bll5iZgjVChL5mXWSR2hUp ZdPy6oQM8iQbya6nk2DOTkvjb/ulZqmQ7iGHs= X-Gm-Gg: ASbGncvISHgaQzsAk5kkjyxUDBKVCcBKpVXbw2pEt0bv9/gp2JGnplYKQ/BcJl0HJqO gwS10OqPrc0JPYRb24MMejSguBhEzCTuGYEr2ElTRfdjZa+CHFF0vXL6EdRoklHStM/TVYNjwAj jG3xnPlllQ4g9E/9DznRWrsWzoeDO//OKGvSkacIodGTD0Na/618VNzrlsdYY5iK3vigK7YF/0M K9gAT7DmBTYiY3QFv/8eFiixkSV73g8gryRr+V94KXNggl4+ncrO6doqmTmp/joWGghEMEGRsVh Z1bWPOj3tdz1AA4HMhH4zq9WqP8/+ucYlGr0npFD7w== X-Received: by 2002:a5d:47a3:0:b0:386:34cb:37b with SMTP id ffacd0b85a97d-388e4d96d2fmr1534625f8f.56.1734519196326; Wed, 18 Dec 2024 02:53:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IF/sWSUM6eFz9e0Fj2ehZix+pCZAtX4z9ddKA37lVSDdVWFlMJSod4Dayo4sxctiSlixawauw== X-Received: by 2002:a5d:47a3:0:b0:386:34cb:37b with SMTP id ffacd0b85a97d-388e4d96d2fmr1534598f8f.56.1734519195851; Wed, 18 Dec 2024 02:53:15 -0800 (PST) Received: from localhost (p200300cbc73f8300a5d5c21badd3cf50.dip0.t-ipconnect.de. [2003:cb:c73f:8300:a5d5:c21b:add3:cf50]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-388c8046ca6sm13922120f8f.83.2024.12.18.02.53.14 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 18 Dec 2024 02:53: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 Subject: [PULL 04/15] s390x/s390-virtio-hcall: prepare for more diag500 hypercalls Date: Wed, 18 Dec 2024 11:52:52 +0100 Message-ID: <20241218105303.1966303-5-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241218105303.1966303-1-david@redhat.com> References: <20241218105303.1966303-1-david@redhat.com> MIME-Version: 1.0 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: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 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.116, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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: <20241008105455.2302628-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 | 16 +--------------- target/s390x/tcg/misc_helper.c | 5 +++-- 4 files changed, 18 insertions(+), 29 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; } -int s390_virtio_hypercall(CPUS390XState *env) +void handle_diag_500(S390CPU *cpu, uintptr_t ra) { + CPUS390XState *env = &cpu->env; const uint64_t subcode = env->regs[1]; switch (subcode) { - case KVM_S390_VIRTIO_NOTIFY: + case DIAG500_VIRTIO_NOTIFY: env->regs[2] = handle_virtio_notify(env->regs[2]); - return 0; - case KVM_S390_VIRTIO_CCW_NOTIFY: + break; + case DIAG500_VIRTIO_CCW_NOTIFY: env->regs[2] = 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 -#include "standard-headers/asm-s390/virtio-ccw.h" #include "cpu.h" -/* 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 */ -int s390_virtio_hypercall(CPUS390XState *env); +void handle_diag_500(S390CPU *cpu, uintptr_t ra); #endif /* HW_S390_VIRTIO_HCALL_H */ diff --git a/target/s390x/kvm/kvm.c b/target/s390x/kvm/kvm.c index dd0322c43a..9fbb7db163 100644 --- a/target/s390x/kvm/kvm.c +++ b/target/s390x/kvm/kvm.c @@ -1491,20 +1491,6 @@ static int handle_e3(S390CPU *cpu, struct kvm_run *run, uint8_t ipbl) return r; } -static int handle_hypercall(S390CPU *cpu, struct kvm_run *run) -{ - CPUS390XState *env = &cpu->env; - int ret; - - ret = s390_virtio_hypercall(env); - if (ret == -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; @@ -1601,7 +1587,7 @@ static int handle_diag(S390CPU *cpu, struct kvm_run *run, uint32_t ipb) handle_diag_318(cpu, run); break; case DIAG_KVM_HYPERCALL: - r = handle_hypercall(cpu, run); + handle_diag_500(cpu, RA_IGNORED); break; case DIAG_KVM_BREAKPOINT: r = handle_sw_breakpoint(cpu, run); diff --git a/target/s390x/tcg/misc_helper.c b/target/s390x/tcg/misc_helper.c index 303f86d363..0ab2bf36cf 100644 --- a/target/s390x/tcg/misc_helper.c +++ b/target/s390x/tcg/misc_helper.c @@ -117,10 +117,11 @@ void HELPER(diag)(CPUS390XState *env, uint32_t r1, uint32_t r3, uint32_t num) switch (num) { case 0x500: - /* KVM hypercall */ + /* QEMU/KVM hypercall */ bql_lock(); - r = s390_virtio_hypercall(env); + handle_diag_500(env_archcpu(env), GETPC()); bql_unlock(); + r = 0; break; case 0x44: /* yield */ From patchwork Wed Dec 18 10:52:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13913447 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5D5F3E77188 for ; Wed, 18 Dec 2024 10:57:18 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tNrhI-0000dr-Ca; Wed, 18 Dec 2024 05:54:33 -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 1tNrhF-0000dd-W4 for qemu-devel@nongnu.org; Wed, 18 Dec 2024 05:54:30 -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 1tNrhE-0006n2-6j for qemu-devel@nongnu.org; Wed, 18 Dec 2024 05:54:29 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734519267; 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=Zvokl2JFZjrf2TkNRlzgYIlGm36Z91ZjxT6UTdHIqvs=; b=QCKeEICib9Fdroke1YGnFp53+yKTF6Ec86sbgUCVn2OlHtRtVntfB7vzqxLpjysX+JTpBA AZc4wwdLeT4H3/KCMNtSGvlIbN49KSmHtfm/qzm9g9hgrZKJDlOW0O9UP7rC96TMaXq1q9 3+rLld0wRHenzaex+oPygK0ReaZUBR8= 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-657-HabVR3UzPQq-p0f9FJb9vQ-1; Wed, 18 Dec 2024 05:53:20 -0500 X-MC-Unique: HabVR3UzPQq-p0f9FJb9vQ-1 X-Mimecast-MFC-AGG-ID: HabVR3UzPQq-p0f9FJb9vQ Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-385e9c698e7so362679f8f.0 for ; Wed, 18 Dec 2024 02:53:20 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734519199; x=1735123999; 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=Zvokl2JFZjrf2TkNRlzgYIlGm36Z91ZjxT6UTdHIqvs=; b=BRSArODTVQQywPL/FldAG7UWpCzaBpAnsUgmmT/YjTwRPRPW6exj9Hj6IIbOMW4cB1 7P35JZv3dJqL9nhROvtSAwZuMTKfiCMr+tXDnarmfolBOrh70uXRBmpPxUzoa47RlMZy DM8Yi0+H8hX+Eq5gMEGvbYa9Hc30i247Ce3pQD67qQhW98lnA25g8uAaDrhrAZTgY3rq JZsLLmNnDxzzPB/wyzkj/XZKiuJwrsqb7be7xz7/hjJlntVP/Q4JXezetW6PckMtXIfy U9KZ7b8jn0+OGhQeNJZBnrW/a7dT6S/OyM3IhZPIN4CnKO91zw1nc+Y88tGsK2ebgaB/ +pag== X-Gm-Message-State: AOJu0Yy4ZjUGALV96N1aKGPT5lMr32IBqN/6CtWVm8hFSA5EWUw572W4 eUO0rA2TzDInw+tfNpe2t0/eEouBl6VKz9L7LPKhkyFwDqtLJcDtWh6dC562fMxYyWY86cr7Phy OelBFMzfRfiarsFBTLW/n+S6qyD/LWYbG8uNQuhibgtgPzVBnHdZnu/8ZDsEi5vZZiRbbQQFubu FNt9dBpS4jzeErUNsN4dbJbLork31t0nTje3I= X-Gm-Gg: ASbGncvlUGVCRWC+XRoeyFo9gCu2Jdx63RQU+Nh6TeQR4eXKH85PrdoUOiba4HQBMhy 0RqVof3C405qGEhKpO1htcnFsvo5J9SUPvA5WTY+pKY/yhGTBNb9pv0gaikmh3Xd9l40Lz1O7B8 m5UctyGyRiW8cXXMNoaOYOdW08VT1nSOM1y+FVaWmjff9PX319eN97Bw/zrIODoVe+PsuzLE+kX 0NzvxrTQ+hYDfBHuOeKoWCJo+rph0Lonb+KbdraOMkUZBXLeWxBpcxbT4bESMZYjxyWiXSk8kMD SJ66oaA0duSwJux1lVk0/I4A/3Iy0G+QmSVkzt33GQ== X-Received: by 2002:a05:6000:1ac8:b0:385:e95b:bb46 with SMTP id ffacd0b85a97d-388e4e79255mr1488520f8f.22.1734519199113; Wed, 18 Dec 2024 02:53:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IEEngxYrOZ9O8x5obWISSGDHmBHNXG7U1bKMTOcXzBMprW2ys74s+PRO4w+pQACLPWt8wRpVA== X-Received: by 2002:a05:6000:1ac8:b0:385:e95b:bb46 with SMTP id ffacd0b85a97d-388e4e79255mr1488495f8f.22.1734519198770; Wed, 18 Dec 2024 02:53:18 -0800 (PST) Received: from localhost (p200300cbc73f8300a5d5c21badd3cf50.dip0.t-ipconnect.de. [2003:cb:c73f:8300:a5d5:c21b:add3:cf50]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-388c80473c6sm13910919f8f.80.2024.12.18.02.53.16 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 18 Dec 2024 02:53:17 -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 05/15] s390x: rename s390-virtio-hcall* to s390-hypercall* Date: Wed, 18 Dec 2024 11:52:53 +0100 Message-ID: <20241218105303.1966303-6-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241218105303.1966303-1-david@redhat.com> References: <20241218105303.1966303-1-david@redhat.com> MIME-Version: 1.0 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: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 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.116, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Let's make it clearer that we are talking about general QEMU/KVM-specific hypercalls. Message-ID: <20241008105455.2302628-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 => s390-hypercall.c} | 2 +- hw/s390x/{s390-virtio-hcall.h => 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 => s390-hypercall.c} (97%) rename hw/s390x/{s390-virtio-hcall.h => s390-hypercall.h} (86%) diff --git a/hw/s390x/meson.build b/hw/s390x/meson.build index 482fd13420..71ec747f4c 100644 --- a/hw/s390x/meson.build +++ b/hw/s390x/meson.build @@ -12,7 +12,7 @@ s390x_ss.add(files( 's390-pci-inst.c', 's390-skeys.c', 's390-stattrib.c', - 's390-virtio-hcall.c', + 's390-hypercall.c', 'sclp.c', 'sclpcpu.c', 'sclpquiesce.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. */ -#ifndef HW_S390_VIRTIO_HCALL_H -#define HW_S390_VIRTIO_HCALL_H +#ifndef HW_S390_HYPERCALL_H +#define HW_S390_HYPERCALL_H #include "cpu.h" @@ -21,4 +21,4 @@ void handle_diag_500(S390CPU *cpu, uintptr_t ra); -#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 9fbb7db163..7e4bce5337 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" #define kvm_vm_check_mem_attr(s, attr) \ diff --git a/target/s390x/tcg/misc_helper.c b/target/s390x/tcg/misc_helper.c index 0ab2bf36cf..3732d79185 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" From patchwork Wed Dec 18 10:52:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13913437 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1F3B0E7718B for ; Wed, 18 Dec 2024 10:55:51 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tNri9-0001Ba-Du; Wed, 18 Dec 2024 05:55:26 -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 1tNrht-0000o4-D6 for qemu-devel@nongnu.org; Wed, 18 Dec 2024 05:55:13 -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 1tNrho-00072X-W8 for qemu-devel@nongnu.org; Wed, 18 Dec 2024 05:55:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734519304; 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=96QA+3QUnhA5HLSyZnMcgqoHbzkb3vZ+SomK19wOjd8=; b=U1xD9eW0zmqbu/V/S402/DcLhDsAFG5tOkvo5o/hxgvHTgBVfCoSTwr4SepGL6R+jrSWNN CGdWzQYKve0aUU1Hc8ZksSbTQfoJl/sghheUZi7FIy4hPzlfXshwxP7iYbJzwZ+318h8N6 amtk5VCMinimFc9ObgxRfBdNDi/yYyo= 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-638-G-JOUg3LMBOu4H46irXEXw-1; Wed, 18 Dec 2024 05:53:24 -0500 X-MC-Unique: G-JOUg3LMBOu4H46irXEXw-1 X-Mimecast-MFC-AGG-ID: G-JOUg3LMBOu4H46irXEXw Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4361ecebc5bso18777415e9.1 for ; Wed, 18 Dec 2024 02:53:23 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734519203; x=1735124003; 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=96QA+3QUnhA5HLSyZnMcgqoHbzkb3vZ+SomK19wOjd8=; b=D6iSCUWRmpuUvOvKBCLXUODMDOuyarhDEQ4q25HTt6ScVLSxDm6BHN34Thcf7IWksd 5h2jFGBcHZyiOBmeyYPI3VApshgw2+Q7V/VePS7ODfy8DnzIQQgkyXDmwopsd2g03ftj hYt3MWTUuVXLaEL24I7xcEOTHg7DzMB+8gDfm+qY2hG8cITyNEJoB/ue+DCHR/lWMZjN uNeQVbJyYBB9Wu9fPPwymJdZ8AtDNGxiDbj93tmLAPuXhScfOuqSr3khdakJL35mA+j/ gPp98Bvrhh7kD3dtI9s5LsbhTYbkielHC142E64o+30UuyghHIdj1g8fQ+aNPuXbAcTz vgzw== X-Gm-Message-State: AOJu0YySZtN9naQLeyDBg1grYdH9Uka5Am06MiCylSA2ngy7ByraB4iK xG6EhfGNh7gk8UIau1mV9aAl6uc2NMDyX5qFRY9IcgnbWYGdpQemYqsHiFjLlZAhag0rXDf5mIX iwF48kXeWtGN8D7zlQ/xiP5fc3tBUghW52N/3Ysrn/Sg4zL8KL2c3laDs4atwMo/ks+RfpOjzLC lXSmVZztV0lSKuZB4gr//98lCvXW7ucpivps4= X-Gm-Gg: ASbGncsChXmnBs4l9dEpAiJL/68qXw/Z8HqLuYIRw2PeGj/y4XMmRHeZrmM59uHg4yo zxzuJ0s3otr9bygCq/abwWd7b6mn8Fpkmw3R0f0aLqUqrgzYIJ2LJ9tluOlmPcBmu8ZoL7TV0kR lawC5391mcysQWKcJOvplzaKpvY3olDEDbTD8ZseTVNbSySVzTqFkN7gYC0TdH37Dlqf0WRfH4h bm5ISyeFU3mXjX1mXYrheK8EXE5v/aVEDo+gSy9eUdR0GgGzppNlRtFrbSJ1vo+RbuqpYFNXC9N txDdyMR8JpKjvvFTN31av8ewwpA/f5E2kWw3zyIfOw== X-Received: by 2002:a05:600c:4709:b0:434:a1d3:a331 with SMTP id 5b1f17b1804b1-436553f69d3mr16509605e9.22.1734519202783; Wed, 18 Dec 2024 02:53:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IGvbcNQmU26ZX9roj7iZeQAQiydNF4z8Xv3VrfnSeTBvb+C6hkuHhZFIn6257i3zaR4zD8HCQ== X-Received: by 2002:a05:600c:4709:b0:434:a1d3:a331 with SMTP id 5b1f17b1804b1-436553f69d3mr16509325e9.22.1734519202304; Wed, 18 Dec 2024 02:53:22 -0800 (PST) Received: from localhost (p200300cbc73f8300a5d5c21badd3cf50.dip0.t-ipconnect.de. [2003:cb:c73f:8300:a5d5:c21b:add3:cf50]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-43656af6d02sm16987005e9.1.2024.12.18.02.53.19 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 18 Dec 2024 02:53: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 06/15] s390x/s390-virtio-ccw: move setting the maximum guest size from sclp to machine code Date: Wed, 18 Dec 2024 11:52:54 +0100 Message-ID: <20241218105303.1966303-7-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241218105303.1966303-1-david@redhat.com> References: <20241218105303.1966303-1-david@redhat.com> MIME-Version: 1.0 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: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 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.116, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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: <20241008105455.2302628-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) } } -static void s390_memory_init(MemoryRegion *ram) +static void set_memory_limit(uint64_t new_limit) +{ + uint64_t hw_limit; + int ret; + + ret = s390_set_memory_limit(new_limit, &hw_limit); + if (ret == -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 = get_system_memory(); + MemoryRegion *ram = machine->ram; + uint64_t ram_size = memory_region_size(ram); - 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 KVM * 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); } - /* 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); /* @@ -211,7 +231,7 @@ static void ccw_init(MachineState *machine) qdev_realize_and_unref(DEVICE(ms->sclp), NULL, &error_fatal); /* init memory + setup max page size. Required for the CPU model */ - s390_memory_init(machine->ram); + s390_memory_init(machine); /* 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 = MACHINE(qdev_get_machine()); SCLPDevice *sclp = SCLP(dev); - uint64_t hw_limit; - int ret; /* * qdev_device_add searches the sysbus for TYPE_SCLP_EVENTS_BUS. As long @@ -389,14 +386,6 @@ static void sclp_realize(DeviceState *dev, Error **errp) if (!sysbus_realize(SYS_BUS_DEVICE(sclp->event_facility), errp)) { return; } - - ret = s390_set_memory_limit(machine->maxram_size, &hw_limit); - if (ret == -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"); - } } 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 <= 2 * GiB) || + if ((MACHINE(ms)->ram_size <= 2 * GiB) || !kvm_check_extension(kvm_state, KVM_CAP_S390_PROTECTED_ASYNC_DISABLE)) { return false; } From patchwork Wed Dec 18 10:52:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13913446 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6DAD4E7718A for ; Wed, 18 Dec 2024 10:57:16 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tNriI-0001iN-Mn; Wed, 18 Dec 2024 05:55: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 1tNrht-0000ot-EK for qemu-devel@nongnu.org; Wed, 18 Dec 2024 05:55:13 -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 1tNrhn-0006sF-Bj for qemu-devel@nongnu.org; Wed, 18 Dec 2024 05:55:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734519302; 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=fNn4jmZMJMsNyzffi2yRwWE0r3jKftHosPoyBPI8w34=; b=I2g6lo5K6eZZ40iTzTo7dWcWQrV7AfBybB9dtqsMCAiI5kn6AeDO7ckxqrFJaa3gjdkGDN 7wRLmJPxaa/XJURnic+3Br0+S7z0dgHdqDd7zNcUeN5dPeLcXzq7Jz/vrGiMV4rs8BO1Ll v5ZBvAUW8RIzx2kzSd3meRPr89LVKuQ= 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-212-H7E0aACdNVi1z04EyX_jTw-1; Wed, 18 Dec 2024 05:53:26 -0500 X-MC-Unique: H7E0aACdNVi1z04EyX_jTw-1 X-Mimecast-MFC-AGG-ID: H7E0aACdNVi1z04EyX_jTw Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-3862b364578so316356f8f.1 for ; Wed, 18 Dec 2024 02:53:25 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734519204; x=1735124004; 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=fNn4jmZMJMsNyzffi2yRwWE0r3jKftHosPoyBPI8w34=; b=V0ku3J7y6a4N2jNnRzeodKFANbRTBqMqESzIS8/LMLW6rIq1pQtJ1rMa8rvI1RI8OP ua42M/B5Sftv9wZdBbnrbCMFE+uHHqDt9iy1wOGKVgf/gskUmw0JT0ZCfF8IplnJ+9Ci 0nSjrQXr0fyMcpK5H3BiQ2da1LT0zAEU4zwmUca9Bq4ganGr5eK/7zVo5bqn12e9cTqt N8QmRnSQMy1eDDcETumXwmCfzXArnOev84LJSUkTtde7pGNwvZIaoqergbgNshgRC78f jpOE8i7bJQ017zSTOUITd1hqy0sFpzDje/+9AqoF2sdyY6WJP8Bd655gWkuQC1sLvCe5 kyoQ== X-Gm-Message-State: AOJu0Yxm5uYQ72EW8Z3abXItvEY6bGwhotYTMufcInK7MVaaYzq+Yils fyu+J4QmRILF6q3c6j34HAhXB1ZNCwhNVcTVmpnWwIt0k6+kbZh0n569DekrbW+w55YlgJBm/vC y9DVnWdtk0Z2xRfh69kxnzwD0ep45IBt7sxmMnAYI0jabk7FgWxH4PzxQm6Do/BwmqXWfzY+y9a OIxrRmPk3t991uP2kzukJvqs0iT+HIUiiARjA= X-Gm-Gg: ASbGncttB00VipGbCOwNrgiuD+o46ZLJqu8529SMiBWzt/+TgwJzjBAiNY4mceyTbkF HngKpMHQOavPRyHI+Z3wxwaUoj+ihxCa3tHQ2mmgk3d6zmJvz8GIgYC4pm7tSnBw6C7c6+5WYnQ 2b5KGxZQUeey4gPWpSy6ZIqNDG0plmNdI2+W8M8xW2jJLrTYqq/4DFq2l5tA1VtzVBOMM6O4mLi 9tIkaKhPrj7pzoIgVfFpFgpNZA4rWfi+riU1+wwBp78FdjHeFXRvqGzJpXWw4r3ODd4x51gMh4h M6wN/yKayRJaUyLgzKYMnoeb61S29xaKpNINA1fOjg== X-Received: by 2002:a05:600c:450a:b0:434:fc5d:179c with SMTP id 5b1f17b1804b1-436553b6e3cmr19611275e9.13.1734519204382; Wed, 18 Dec 2024 02:53:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IHvENqeBNlec5X1ks1+P7MEYQQLUvfc2KID3UehvJteQwbyHz4ImLZlYFoSoj1vYUQ1WL8sCQ== X-Received: by 2002:a05:600c:450a:b0:434:fc5d:179c with SMTP id 5b1f17b1804b1-436553b6e3cmr19610975e9.13.1734519203908; Wed, 18 Dec 2024 02:53:23 -0800 (PST) Received: from localhost (p200300cbc73f8300a5d5c21badd3cf50.dip0.t-ipconnect.de. [2003:cb:c73f:8300:a5d5:c21b:add3:cf50]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-43656b11d1dsm16493355e9.25.2024.12.18.02.53.23 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 18 Dec 2024 02:53:23 -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 07/15] s390x: introduce s390_get_memory_limit() Date: Wed, 18 Dec 2024 11:52:55 +0100 Message-ID: <20241218105303.1966303-8-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241218105303.1966303-1-david@redhat.com> References: <20241218105303.1966303-1-david@redhat.com> MIME-Version: 1.0 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: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 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.116, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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: <20241008105455.2302628-7-david@redhat.com> Acked-by: Michael S. Tsirkin Reviewed-by: Thomas Huth Signed-off-by: David Hildenbrand --- hw/s390x/s390-virtio-ccw.c | 22 ++++++++++++++++++---- include/hw/s390x/s390-virtio-ccw.h | 3 +++ target/s390x/cpu-sysemu.c | 8 -------- target/s390x/cpu.h | 1 - 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c index a28e615c5a..5a91e334f3 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 static Error *pv_mig_blocker; @@ -121,12 +122,16 @@ static void subsystem_reset(void) } } -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; + int ret = 0; - ret = s390_set_memory_limit(new_limit, &hw_limit); + assert(!s390ms->memory_limit && new_limit); + if (kvm_enabled()) { + ret = kvm_s390_set_mem_limit(new_limit, &hw_limit); + } if (ret == -E2BIG) { error_report("host supports a maximum of %" PRIu64 " GB", hw_limit / GiB); @@ -135,10 +140,19 @@ static void set_memory_limit(uint64_t new_limit) error_report("setting the guest size failed"); exit(EXIT_FAILURE); } + s390ms->memory_limit = new_limit; +} + +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; } static void s390_memory_init(MachineState *machine) { + S390CcwMachineState *s390ms = S390_CCW_MACHINE(machine); MemoryRegion *sysmem = get_system_memory(); MemoryRegion *ram = machine->ram; uint64_t ram_size = memory_region_size(ram); @@ -154,7 +168,7 @@ static void s390_memory_init(MachineState *machine) exit(EXIT_FAILURE); } - set_memory_limit(ram_size); + s390_set_memory_limit(s390ms, ram_size); /* 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-virtio-ccw.h index 996864a34e..eb04542979 100644 --- a/include/hw/s390x/s390-virtio-ccw.h +++ b/include/hw/s390x/s390-virtio-ccw.h @@ -29,10 +29,13 @@ struct S390CcwMachineState { bool dea_key_wrap; bool pv; uint8_t loadparm[8]; + uint64_t memory_limit; SCLPDevice *sclp; }; +uint64_t s390_get_memory_limit(S390CcwMachineState *s390ms); + #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, S390CPU *cpu) return s390_count_running_cpus(); } -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) /* 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); From patchwork Wed Dec 18 10:52:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13913445 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9BAC1E77188 for ; Wed, 18 Dec 2024 10:57:13 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tNrhW-0000ho-9L; Wed, 18 Dec 2024 05:54:46 -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 1tNrhO-0000fQ-Uu for qemu-devel@nongnu.org; Wed, 18 Dec 2024 05:54: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 1tNrhN-0006nw-8G for qemu-devel@nongnu.org; Wed, 18 Dec 2024 05:54:38 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734519276; 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=EfkChPr+ra7P61re5axqyhrcegwzNh2gqwFHHmftqG0=; b=VC7pE+7h8JQjNgUCtHEwrjJXbvFtNNLGlF5PP+35fV1J/o+Ah/sKCJ553MdZ9toRie5Lqn GwrK1mQ4pOdY6yNgGfBal/L8yqYDlcmBxc9z+SED3kAF1N8gZe3Mv4HA0KD6qV/q4HDHfX f0/h5Ri1zMp4XVCn6OJjsi6ig1nzWts= 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-601-vlcJU-2PPRGJKetxQWvDOg-1; Wed, 18 Dec 2024 05:53:27 -0500 X-MC-Unique: vlcJU-2PPRGJKetxQWvDOg-1 X-Mimecast-MFC-AGG-ID: vlcJU-2PPRGJKetxQWvDOg Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-43626224274so30055115e9.0 for ; Wed, 18 Dec 2024 02:53:26 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734519206; x=1735124006; 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=EfkChPr+ra7P61re5axqyhrcegwzNh2gqwFHHmftqG0=; b=jdZwOzLDmGT3epeC+0G4G4eMqxBz0CDVorKILlrVff3RQ1ugfMOLubzyF9OFuZHWzd 7ApLDNsPUE3tj8pGtpR002rUcD8hdIol7CwBRu0V1F/dTCqTaifspYB+Zcgp7AQ3iEUx fOqJRfZ/yIslOR2lNncW1lfvZmdWvyjnheN2hNMjp7xOnvTs/AH9ipPC/UYKem08kHyf /+B2ziH2B4e13RduwhdcNxTh9ufJq3IwbUwmiTn9TMFPpEdImDD5op/KHZOV7LNycW8Q yr5hrj6oe+AkXFIxzLqvzhXgfdvPoGCjHOiHlFnrmfqUbEyS/4Jeshy/ecYVhw+q00dW 5Myw== X-Gm-Message-State: AOJu0YzmE26BC/5GUge1qWika00Kwl6fPVZO/ErOhn6P4AMY/jfSKZU3 ak2LXybs4HXlyAQZvwdQOhwoXtB9ETaJm+X8FCkZJQ++v3ZWQ9eJH/p1pTdDSh9Cx4B0ZmGQKG7 XBmgWgb1lcd3yN54jIgSK647nExilDXTpcmB0WMofp7sAtwsMfhIhBMfS8wzCdhJFfqW6QM38yX jTwA+iTgB6baFVcFSSzHGuQrnfj9A9DCNWekY= X-Gm-Gg: ASbGncubGLA3+t89J+FdKwzbtJ2+eztQTKdj4izY3cjVJZbU+h+K4lGvs1+8MVYIoSv hzaQswTEYWG4DnuPO96IZQzJkeMTJNtfgW2YK5WHE7SwGL8P4vxCj+9wagd3s5GJ8RZOHuBLiYM VyYP0j0sEJtsHRjhyFMpbJIXZq+fEIUMoA0zQVX7y9TNtxKC1XvRtXXdeS5UkZiyhvwDAb083Km CaFnC4ykM096PmQ3X0jYlHEz6dJW3mwcH8F0hMzl7F4iLGAmRcJQ2RUqfqtrQNszhRQrZmNkQdy zNo2zj5FZSkzQpEtx5TbGd8vtwYXfko0Kiag6GXCFQ== X-Received: by 2002:a05:600c:1f94:b0:434:a734:d268 with SMTP id 5b1f17b1804b1-4365535e846mr19927305e9.14.1734519205824; Wed, 18 Dec 2024 02:53:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IHSUhBLgWM5bVGNdLsPpmeKl/5hCAanDdAfVEFcyV7cNYMKaEOASE/oGKT56FKYHG1P3wmLqw== X-Received: by 2002:a05:600c:1f94:b0:434:a734:d268 with SMTP id 5b1f17b1804b1-4365535e846mr19926935e9.14.1734519205341; Wed, 18 Dec 2024 02:53:25 -0800 (PST) Received: from localhost (p200300cbc73f8300a5d5c21badd3cf50.dip0.t-ipconnect.de. [2003:cb:c73f:8300:a5d5:c21b:add3:cf50]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-43656b00cf6sm16763155e9.10.2024.12.18.02.53.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 18 Dec 2024 02:53: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 08/15] s390x/s390-hypercall: introduce DIAG500 STORAGE_LIMIT Date: Wed, 18 Dec 2024 11:52:56 +0100 Message-ID: <20241218105303.1966303-9-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241218105303.1966303-1-david@redhat.com> References: <20241218105303.1966303-1-david@redhat.com> MIME-Version: 1.0 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: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 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.116, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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: <20241008105455.2302628-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 @@ #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, uint64_t data) return 0; } +static uint64_t handle_storage_limit(void) +{ + S390CcwMachineState *s390ms = S390_CCW_MACHINE(qdev_get_machine()); + + return s390_get_memory_limit(s390ms) - 1; +} + void handle_diag_500(S390CPU *cpu, uintptr_t ra) { CPUS390XState *env = &cpu->env; @@ -69,6 +76,9 @@ void handle_diag_500(S390CPU *cpu, uintptr_t ra) case DIAG500_VIRTIO_CCW_NOTIFY: env->regs[2] = handle_virtio_ccw_notify(env->regs[2], env->regs[3]); break; + case DIAG500_STORAGE_LIMIT: + env->regs[2] = 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 void handle_diag_500(S390CPU *cpu, uintptr_t ra); From patchwork Wed Dec 18 10:52:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13913443 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 23116E77187 for ; Wed, 18 Dec 2024 10:56:17 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tNriK-0001wN-VD; Wed, 18 Dec 2024 05:55: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 1tNrhs-0000nd-JF for qemu-devel@nongnu.org; Wed, 18 Dec 2024 05:55:13 -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 1tNrhm-0006qd-TN for qemu-devel@nongnu.org; Wed, 18 Dec 2024 05:55:08 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734519302; 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=l0gBfmC/71g11Jbf0onG2UBI9DIVGHNXDaOgDh8tn80=; b=SRDCKNRxnpxpNtOty7+2TVtfN6CHw9r6Nd90jBjz8UGxixgqFBiTi5yb587P7oSRQRDW9o E2tJe8TLNYow5NUJfEv4H45tULRUmj24+I15kY974JnVkf0xqN6PWp62S1MH10hKBJPp7i fxMjVy2dOMvTGPnuExJPBX7D+JWIxoA= 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-372-r6R2KEj3NseZ9Nq1gVkwhw-1; Wed, 18 Dec 2024 05:53:30 -0500 X-MC-Unique: r6R2KEj3NseZ9Nq1gVkwhw-1 X-Mimecast-MFC-AGG-ID: r6R2KEj3NseZ9Nq1gVkwhw Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-43635895374so3142675e9.0 for ; Wed, 18 Dec 2024 02:53:30 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734519209; x=1735124009; 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=l0gBfmC/71g11Jbf0onG2UBI9DIVGHNXDaOgDh8tn80=; b=lOfO+TRYM94JIUt6lmbEz86ULsMqsTD7Vm7J4eXwEv2L5XRP02wbjXnzsiB1vym/4D BmoT02tOMIKjPASBAE65hMGwApXxxte4KrOe8rlOoTiBh32PlzvknP9WH8vZLM56KIbY qcaSYKphUqKtliAl+UGv+ORTKX73S0ykQLWc7Lynxk5JrLBIt6KoisSa6eosafGYeClU ZOBVb84WBYgIJfiwVhD0jooywiUev16uYnr/jMkkyE64Os8vA/AUdJu667uKlNjYcS8m b7ByqWVoUbDirZ64+Dn5J8LzsbOnpGV61aLfWUpYLX+8P7KbzO0BxfsBQlC4iTlhwoc+ OMKA== X-Gm-Message-State: AOJu0Yw0Eqh1EwbZ57uuRVljpHkMzdoxWN/C4o+yCKXrhFsomNVeMFLn ylOGOjJlaxxjecUaCgXPHO+vs51dOptcNEkExtqTySQBI+m/FZWMouBlFwAYEmws23aXDYGmmsq jieIKkRC2O2ktvP/ATAOKePuClNpu1MbLZiweYWcFSG6lE4h+AfujaMNeyJHgKc5EZ5ZNMYpgex dd9m/FM3xOoFAp7TIpkyIls751bq1BDODaPyo= X-Gm-Gg: ASbGncsGgULKwcEJ442B2B5Q833BT9/5kMU0ZrWdhDdH9annxVH2aVQ93rmmgK+F15Z +8/6sohafZrK8CJiPQ42564epuWfHYa24zeyM+wmSUZOrWHiMrPAt2HiMTD8semqXbBpunzO4+H 8tHamLxDgq2mVy4Z78NlLF5EDLoUlUkgYqCUYHCdX6T5KhxChfhncoVYGRQ7UaF8nDfXLkRDU/C OCX7pdJB544KPenCIrbOfq5mNioujkwhX5VxSdfqaGU+/sLPj4TltDwbaD3Rv1wX/IeH6m1o2xj EjgR8Cm3Bhv7Fvbl/plAq5MxdteIzBZjtF+8Wghg7w== X-Received: by 2002:a05:600c:1d19:b0:434:fb8b:deee with SMTP id 5b1f17b1804b1-436553f2d16mr18279715e9.16.1734519209030; Wed, 18 Dec 2024 02:53:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IEY1h8hO0hLiRa2NcpJKgUPQl3PlEPEYdtJ50FtCnI6VQUOcNTr4E99dVOKspMmAk02wEBBnQ== X-Received: by 2002:a05:600c:1d19:b0:434:fb8b:deee with SMTP id 5b1f17b1804b1-436553f2d16mr18279505e9.16.1734519208578; Wed, 18 Dec 2024 02:53:28 -0800 (PST) Received: from localhost (p200300cbc73f8300a5d5c21badd3cf50.dip0.t-ipconnect.de. [2003:cb:c73f:8300:a5d5:c21b:add3:cf50]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-4364b053e91sm50545215e9.1.2024.12.18.02.53.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 18 Dec 2024 02:53:27 -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 09/15] s390x/s390-stattrib-kvm: prepare for memory devices and sparse memory layouts Date: Wed, 18 Dec 2024 11:52:57 +0100 Message-ID: <20241218105303.1966303-10-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241218105303.1966303-1-david@redhat.com> References: <20241218105303.1966303-1-david@redhat.com> MIME-Version: 1.0 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: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 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.116, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_PASS=-0.001, T_SPF_HELO_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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: <20241008105455.2302628-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 @@ */ #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 = KVM_S390_STATTRIB(sa); - MachineState *machine = MACHINE(qdev_get_machine()); - unsigned long max = machine->ram_size / TARGET_PAGE_SIZE; + S390CcwMachineState *s390ms = S390_CCW_MACHINE(qdev_get_machine()); + unsigned long max = s390_get_memory_limit(s390ms) / TARGET_PAGE_SIZE; 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(S390StAttribState *sa, static void kvm_s390_stattrib_synchronize(S390StAttribState *sa) { KVMS390StAttribState *sas = KVM_S390_STATTRIB(sa); - MachineState *machine = MACHINE(qdev_get_machine()); - unsigned long max = machine->ram_size / TARGET_PAGE_SIZE; - /* We do not need to reach the maximum buffer size allowed */ - unsigned long cx, len = KVM_S390_SKEYS_MAX / 2; + S390CcwMachineState *s390ms = S390_CCW_MACHINE(qdev_get_machine()); + unsigned long max = 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 = { .flags = 0, .mask = ~0ULL, }; - if (sas->incoming_buffer) { - for (cx = 0; cx + len <= max; cx += len) { - clog.start_gfn = cx; - clog.count = len; - clog.values = (uint64_t)(sas->incoming_buffer + cx); - r = 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 = cx; - clog.count = max - cx; - clog.values = (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 = block->target_start / TARGET_PAGE_SIZE; + end_gfn = block->target_end / TARGET_PAGE_SIZE; + + while (start_gfn < end_gfn) { + /* Don't exceed the maximum buffer size. */ + pages = 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 <= max); + + clog.start_gfn = start_gfn; + clog.count = pages; + clog.values = (uint64_t)(sas->incoming_buffer + start_gfn); r = 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 += pages; } - g_free(sas->incoming_buffer); - sas->incoming_buffer = NULL; } + +out: + guest_phys_blocks_free(&guest_phys_blocks); + g_free(sas->incoming_buffer); + sas->incoming_buffer = NULL; } static int kvm_s390_stattrib_set_migrationmode(S390StAttribState *sa, bool val, From patchwork Wed Dec 18 10:52:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13913444 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 97DFEE77188 for ; Wed, 18 Dec 2024 10:56:46 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tNrhy-0000ni-1M; Wed, 18 Dec 2024 05:55:14 -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 1tNrhq-0000mc-C0 for qemu-devel@nongnu.org; Wed, 18 Dec 2024 05:55:06 -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 1tNrhn-0006tQ-IP for qemu-devel@nongnu.org; Wed, 18 Dec 2024 05:55:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734519302; 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=oIdN8k8UxbFd6pPRixbwE/O/YwzOJXLRbaptlMiUIjU=; b=NbyIgxAVjLEF/wQ4Zz9LDxOqnGPTJu3Z4ucqzWsokVcXuPLr1cAHzjXMMGu7poGOZ6c21w ux4Ni+7wO+zuGCtrsNg3W9V6F5CKRmnB8hiaSK5NsSWlXb54ktwV5SEn9KWh4J/Yr7XjMN WIB0FMvTxh08J/kw8WMmaE3+VWgZv7E= 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-670-d7gGxEt9M_e9Uyu4uj30mw-1; Wed, 18 Dec 2024 05:53:32 -0500 X-MC-Unique: d7gGxEt9M_e9Uyu4uj30mw-1 X-Mimecast-MFC-AGG-ID: d7gGxEt9M_e9Uyu4uj30mw Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-385e1339790so3726881f8f.2 for ; Wed, 18 Dec 2024 02:53:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734519211; x=1735124011; 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=oIdN8k8UxbFd6pPRixbwE/O/YwzOJXLRbaptlMiUIjU=; b=V/alYQzWgbMKD3NLVFQ6SPyCsZylCLGVTEcs1tO1m1UPWfobisOVapl0FhM0TXrbJu guk/Nc07nXB+kbA/5iaDP7cNMrbkYX+1yKMiMX7MyChTQ/qnow40F/4LEPfz+Q7/tqEq V5RC9xmvbaupnBGbohZRBEDdHeoxRjXAd1Sx0pH1Ni8ck5BosjYQojHYGgQRHfkBnGv2 5/y1pn5uYUoybtexW+K/dsL0uAkMiUgs92O/eoyQUXIRAmyL9NdKgVz9+H1ScPcvWYcc +Oe9tUVCr8P/iBQmAp9ZUTsEddpzKqA/cN85ojjBpLTIu38P+XnwS5on42DT75mdph15 4SDg== X-Gm-Message-State: AOJu0YweWY/BzElI5CGxJ+bF6aQZa4mpI5vwHmY7z65T7j6iZ0wVFH00 qz+zyi9EfAXWaIUWojfrG1iXi7LwMnSkPmoZZpJCYK6ENKinzW+H/kwLOATLcjfCoj8VgBCWNdx 9ebXBMhuJtSoZcsBn6Cn0pLrU2Bp8J7klaln6kJaWpFWsYBLuq68/XRhTYlx5I4o2yU2SZlqtCe fo5IaaN3qQsp2vU7p/C29eNF4BeFcTwyfkeBI= X-Gm-Gg: ASbGncvPfRiW2kwtPvW7ZTq0w6xNf8OymhNpkR97s1v7ohbrMBWoxosGt662OabFuWl u9Tpm4kgJTWydSfJPnr/NiJCEzsktgPjsYE2m+dc1dG2+gBMpFbBqV5dg5iAcKWblnIfluZNncD hQMdpJ9KAvEk6AVP/9CuY8IMhtBQUcgq3M4xg+HSB95WAfS9ACeLo50CHnH3RfS+yNacYB/FMNU yQxEFnNGhIaGUFrUR4lYbuq/X0tPRLsE68mjsjLtvlTJbqtmYP7GXTtLyRinfiSfe3WORriTaW0 z48XnjraOVcD3MJM2GS6oCnQdAjxbkFd6PUQ/YVxBQ== X-Received: by 2002:a5d:64a1:0:b0:385:faad:bfb8 with SMTP id ffacd0b85a97d-388e4db3356mr1872856f8f.41.1734519211406; Wed, 18 Dec 2024 02:53:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IG1dSZfRX78xrsNdb851rzl34E5+6rxY+MGtW07yZ+u01+FUx2aLwMvlk6ZmJHgVIANK8v3Fw== X-Received: by 2002:a5d:64a1:0:b0:385:faad:bfb8 with SMTP id ffacd0b85a97d-388e4db3356mr1872813f8f.41.1734519210871; Wed, 18 Dec 2024 02:53:30 -0800 (PST) Received: from localhost (p200300cbc73f8300a5d5c21badd3cf50.dip0.t-ipconnect.de. [2003:cb:c73f:8300:a5d5:c21b:add3:cf50]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-388c806b84esm13652312f8f.108.2024.12.18.02.53.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 18 Dec 2024 02:53:30 -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 10/15] s390x/s390-skeys: prepare for memory devices Date: Wed, 18 Dec 2024 11:52:58 +0100 Message-ID: <20241218105303.1966303-11-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241218105303.1966303-1-david@redhat.com> References: <20241218105303.1966303-1-david@redhat.com> MIME-Version: 1.0 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: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 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.116, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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: <20241008105455.2302628-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 @@ #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 = MACHINE(qdev_get_machine()); + S390CcwMachineState *s390ms = S390_CCW_MACHINE(qdev_get_machine()); - skeys->key_count = machine->ram_size / TARGET_PAGE_SIZE; + skeys->key_count = s390_get_memory_limit(s390ms) / TARGET_PAGE_SIZE; skeys->keydata = g_malloc0(skeys->key_count); g_once_init_leave(&initialized, 1); } From patchwork Wed Dec 18 10:52:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13913441 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 65EB4E77188 for ; Wed, 18 Dec 2024 10:56:01 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tNrhp-0000m4-La; Wed, 18 Dec 2024 05:55:05 -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 1tNrhn-0000lD-Q6 for qemu-devel@nongnu.org; Wed, 18 Dec 2024 05:55:03 -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 1tNrhl-0006qI-Rt for qemu-devel@nongnu.org; Wed, 18 Dec 2024 05:55:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734519301; 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=ae4dyIyqNtWDwadcWWfv4WjE9ofwvL0jMgrctB+jsJA=; b=fDOgy/2aDIKxzt/1asmEFHeSZC4TQT+Ct15Hn6HeJu7y3VmLfkv9UsnKlh9wOStf1KKoJ7 5kne12b0IpAWHtQrGweIYBW9C6Fk1m4nWPCfuy5J16mJ61usiiyC+Rj2cAM660LSnlusor HunvgId0pwNzxj75j43E7Bj7JM9OLVE= 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-554-SWAtKcE9N3yMk_7jG-NfSA-1; Wed, 18 Dec 2024 05:53:34 -0500 X-MC-Unique: SWAtKcE9N3yMk_7jG-NfSA-1 X-Mimecast-MFC-AGG-ID: SWAtKcE9N3yMk_7jG-NfSA Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-43627bb20b5so49866365e9.1 for ; Wed, 18 Dec 2024 02:53:34 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734519213; x=1735124013; 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=ae4dyIyqNtWDwadcWWfv4WjE9ofwvL0jMgrctB+jsJA=; b=M+iEmp/PUxhfPr8b7Vgc9VEL5uQ9FRm+XpB8PusNQTWcOfiEXJzrjEr/v/n1lsUbQg rh3f1vYH8qK83n+Tina9l1IguVuS43j73ATMDagQtxYIlG3YNQqEFCsBGIRQgSHPEpfb JX56r4n2ipT4+7F+7BNu10n34XPVtCVJyx95WRl8Tr+lPpZT1/NsveJSZ3A0aMBVdXKz K/GNdPJ86Ub5rGSkiUbCnOd34Ail5pJ3MLWzLHCci3TYalc75qAhaKfbl/CKfSnsVnsA oAhLtoMU796/uySz0ElY4Nu0Nmll8mjYeU91MI7cXy3biLNEr4sIdE0xaiaJh+B40oTb C9zQ== X-Gm-Message-State: AOJu0YxX3l0GsNe8bq1NuvqPgjbOHyv62AYmtS1JAaNonoorb8sJIuPK 0PwhG/UgZ8h2JpXMNRtDVkDy3v68UQrYLQKipYNBLGjd9Aqk91xO8CxBYi41V+C7Jol4Pn0SE2l 4GMkVuuQ/L3pa11D8I8rMw+ZoHMu+rMyiG2MKfst859OXDps5d89wU+Z448MVqb1eHMZVvQrRnU RXu50SEwHEa2UgbJQFf8oL5SpEJTrTEvGenVQ= X-Gm-Gg: ASbGncsYcEfe8Sr/Scje0uumwfw8TjfwJI0/vBKo8I29lSBVHzoG+6YdQ1XIt9vQ00j xq+LzoBUco/YTTBjFiCmPLbKcIe7oevoSiaYag/7ZUSk+JPk2I6YeBOY+oZ1bN65K/F1l9tfd50 MOZoqKAQuxpak/tYSpQopnLlxf+7IcyP5rL5kk3lfRHafWciWngnAzSNS08ikWHjADRPpaiVEvm OLY6H+7TpdHGxD6SO2NVyz91uVB0gBBuMHeBZnsp4rfTyUa+c0WhFLIGaqekSXmhQSMYew2ruUB UR/q84QjyNLndS/IvX65PmJHXEMw+FQ+vT2PH91N9w== X-Received: by 2002:a05:600c:1d1c:b0:435:1b:65ee with SMTP id 5b1f17b1804b1-436553ea72dmr18205295e9.24.1734519213551; Wed, 18 Dec 2024 02:53:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IEXF3ehh0uNXJY4O2vHXQ6p2VO9ez8cXbOSHA6rzJxx/P9i+77iuAsRKWUxmtHhUi5tHuT0rA== X-Received: by 2002:a05:600c:1d1c:b0:435:1b:65ee with SMTP id 5b1f17b1804b1-436553ea72dmr18204955e9.24.1734519213075; Wed, 18 Dec 2024 02:53:33 -0800 (PST) Received: from localhost (p200300cbc73f8300a5d5c21badd3cf50.dip0.t-ipconnect.de. [2003:cb:c73f:8300:a5d5:c21b:add3:cf50]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-43656b18f5bsm16882195e9.31.2024.12.18.02.53.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 18 Dec 2024 02:53: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 11/15] s390x/s390-virtio-ccw: prepare for memory devices Date: Wed, 18 Dec 2024 11:52:59 +0100 Message-ID: <20241218105303.1966303-12-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241218105303.1966303-1-david@redhat.com> References: <20241218105303.1966303-1-david@redhat.com> MIME-Version: 1.0 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: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 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.116, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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: <20241008105455.2302628-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 5a91e334f3..aa06d07835 100644 --- a/hw/s390x/s390-virtio-ccw.c +++ b/hw/s390x/s390-virtio-ccw.c @@ -156,6 +156,7 @@ static void s390_memory_init(MachineState *machine) MemoryRegion *sysmem = get_system_memory(); MemoryRegion *ram = machine->ram; uint64_t ram_size = memory_region_size(ram); + uint64_t devmem_base, devmem_size; if (!QEMU_IS_ALIGNED(ram_size, 1 * MiB)) { /* @@ -168,11 +169,31 @@ static void s390_memory_init(MachineState *machine) exit(EXIT_FAILURE); } - s390_set_memory_limit(s390ms, ram_size); + devmem_size = 0; + devmem_base = 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 = QEMU_ALIGN_UP(devmem_base, 1 * GiB); + devmem_size = machine->maxram_size - machine->ram_size; + } +#endif + s390_set_memory_limit(s390ms, devmem_base + devmem_size); /* Map the initial memory. Must happen after setting the memory limit. */ memory_region_add_subregion(sysmem, 0, ram); + /* 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 = cpu_to_be32(rnsize); } - /* 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 = machine->ram_size >> sclp->increment_size; if (rnmax < 0x10000) { read_info->rnmax = cpu_to_be16(rnmax); From patchwork Wed Dec 18 10:53:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13913434 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CDF6BE77187 for ; Wed, 18 Dec 2024 10:55:29 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tNrhr-0000mq-5c; Wed, 18 Dec 2024 05:55:07 -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 1tNrhp-0000lh-5Q for qemu-devel@nongnu.org; Wed, 18 Dec 2024 05:55:05 -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 1tNrhn-0006qq-7C for qemu-devel@nongnu.org; Wed, 18 Dec 2024 05:55:04 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734519302; 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=6jzX2pyO/iqHI0cjENwYLEKZ3ZU6j0kw5XT1+VOMzPg=; b=BWtEpBBewq98msbsny2AYNjC3Sflz6Rpg50fpq8ii5KJKdy9jOMsYZe4HpBKxWc9oVfuGk mNsM3W3AphNorGcvDiTcdqGOhOZKIjYAsL/kpwQuFl1LIUDdyoNuTuURzqUdUUnx1D2glm NB6fx/Jt9F0Egt6SeD1gwLOxZ9ICYSY= 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-694-_4-4_-v-Piu2l-r7D0tT5A-1; Wed, 18 Dec 2024 05:53:36 -0500 X-MC-Unique: _4-4_-v-Piu2l-r7D0tT5A-1 X-Mimecast-MFC-AGG-ID: _4-4_-v-Piu2l-r7D0tT5A Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4362b9c1641so27884155e9.3 for ; Wed, 18 Dec 2024 02:53:36 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734519216; x=1735124016; 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=6jzX2pyO/iqHI0cjENwYLEKZ3ZU6j0kw5XT1+VOMzPg=; b=sm7kb9OelrL+8HkA+wrl96N3V8J+rlNRZhGwowG4TmJ/EV1tseE5mwSz/PV1Q3HhkM arOCPEyRWsVjeM4zyYgFkpoAPTq0Gtr2S72Xheahy89NOg5b2I02MjqL1tTsfMwYb6Qh nQEiQa7YP6f41TAJj+yDMz388sxEFaO5i1oKt/A5LsPidYxikpElxHYejmtL3ePbCJ11 xM4k3QOifzVdoXtVEBOJTyqp+sio6mG6MgSgj23RUO/kk0A+nISUWEpfV2fnSJ+ynjnA 10iFiHt6xmC9/4Ztf0Tjl8ZTCT415oDCudNqZPNFYGzNuTjOZYd5tICr1zH0ern1lzjf 5Bjg== X-Gm-Message-State: AOJu0YxScXJPK1fa1hJSIZm252dVmOaqcgGa/+YTtzFRbbN1iBedfZnS qemAG/h24rvO7xY8MlbNvzWj9Q/zUr8Yi3i97pm2QU40hUZP1xXtrXTALCPB4JG68Tn7mK1V6if sI8mxCzCp+zp8vWjIDmrWTEF/iIO3BN47YVScI3Vi+oED0PhEmNqIqlPukpoo9i3b8LxLMpUjP6 +jl2/2UfUz+jXeyW6WaOrlnjt0aJyjrvWNk2M= X-Gm-Gg: ASbGncszFuG5ccEiu3apw4saAxrZxpvE2aRzT1/xRWypum4uy1o0woifWzt1YyZx45U 4oJsV4OrMF/FMwhxmpfztOl5cQS+m+NniNyA2mxEfz+QyBUMn5OKKLxZsFoXMRWDvwAc8S2lU6T c+9marESBjTeiHXVbpzxVJ23P5lsM+E/U4jzzWTzi1GZxzZypS3RsCZXkrty0DjKXd+fn+nxzch xFA4KhCN+5mQHVb2wTmsprdXxX0Mx3C7XxQF5epx02N+sBMHyKTUDcOeIOK7Se3DAKUzbQN00uP rtvZtdwPiaS3jxv65Dj6pcQ6p02SnjFReNgU0Q5wdQ== X-Received: by 2002:a05:600c:4f14:b0:434:a10f:c3 with SMTP id 5b1f17b1804b1-4365535fe63mr20045045e9.9.1734519215758; Wed, 18 Dec 2024 02:53:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IHlycrOknbfAPHpV3mL2rVWzzSXJoEXGLBTlnTJeXlmduzWviJD86gsYpPZfSZJtT41UWv8uA== X-Received: by 2002:a05:600c:4f14:b0:434:a10f:c3 with SMTP id 5b1f17b1804b1-4365535fe63mr20044745e9.9.1734519215384; Wed, 18 Dec 2024 02:53:35 -0800 (PST) Received: from localhost (p200300cbc73f8300a5d5c21badd3cf50.dip0.t-ipconnect.de. [2003:cb:c73f:8300:a5d5:c21b:add3:cf50]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-388c8060fb3sm13556545f8f.94.2024.12.18.02.53.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 18 Dec 2024 02:53: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 , Nina Schoetterl-Glausch Subject: [PULL 12/15] s390x/pv: prepare for memory devices Date: Wed, 18 Dec 2024 11:53:00 +0100 Message-ID: <20241218105303.1966303-13-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241218105303.1966303-1-david@redhat.com> References: <20241218105303.1966303-1-david@redhat.com> MIME-Version: 1.0 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: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 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.116, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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 <= 2 GiB VM would end up using a segment type ASCE. Message-ID: <20241008105455.2302628-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 <= 2 * GiB) || + if (s390_get_memory_limit(ms) <= 2 * GiB || !kvm_check_extension(kvm_state, KVM_CAP_S390_PROTECTED_ASYNC_DISABLE)) { return false; } From patchwork Wed Dec 18 10:53:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13913433 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D32DBE77188 for ; Wed, 18 Dec 2024 10:55:29 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tNrho-0000lc-Si; Wed, 18 Dec 2024 05:55:05 -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 1tNrhn-0000lG-SK for qemu-devel@nongnu.org; Wed, 18 Dec 2024 05:55:03 -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 1tNrhm-0006qX-42 for qemu-devel@nongnu.org; Wed, 18 Dec 2024 05:55:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734519301; 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=/QBJrTf6g4Vqln67IUOCc7Xr8xeF+lIWKbSulfpvbBM=; b=Ln8v3H+TYV+P/KE3vaVBRM7KDnHEdra7WhHr9ODiKn8Ag1hdea4qwxS9OH2Pspod6XlfAU QIIU35Lxr3htDshqCU8A96rO49Ywb1e0naByEL6t69Pb+alFxEUK7U+ouMxKAMVPBnf9ix G5KR1O+SE1AIJDQbzCkYOyAhPDNT5Ic= 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-22-eerHLl4cO7ijPjarwApByA-1; Wed, 18 Dec 2024 05:53:38 -0500 X-MC-Unique: eerHLl4cO7ijPjarwApByA-1 X-Mimecast-MFC-AGG-ID: eerHLl4cO7ijPjarwApByA Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-436289a570eso50744405e9.0 for ; Wed, 18 Dec 2024 02:53:38 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734519217; x=1735124017; 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=/QBJrTf6g4Vqln67IUOCc7Xr8xeF+lIWKbSulfpvbBM=; b=R7J/QK+0u6yx9fHcBFo8JzTP8Sr5AdCCBay///f7/oqcECjvBSqiOpT9ivyjnTyhXo oozYXwV2jyhSK4rHK7yN+FeUugapuqOP69daR1gPO8HsN2OQQfSabAIqO7zM7wP+up0d dJwh7l2qHjL3ALsIZolu0HB91YWrNkPYinb5W7ttsXA/e9RSv07wxqvIZ3OtKDrF28uQ 2wnnYT5dETEBQuNK1vhqtZAVfgMRI4FW5cUOyIgkhZnN++MUwY2He0zFaBPdXXLbzJyh 1d4KzVaxF7ECL5yCOkMmGUJFqG9h2pLikTujL8hmKzIgMDyHMagS1WGzoupQirfWOSMq bpgQ== X-Gm-Message-State: AOJu0YyCKRTRRSPWWYQtVcrDSqTgjHQEaoxODNDcAnK1XDZKBpN+gqNy gQ2r+CjKUsB3PT+kS+qwAWiAJtGj07RWFUyHxTzaX1U4b59lS5FF1mumKqThZxkxq/2PduFSf1R 0MUOipUFCkFgKbAioCsXROiSooXC+ot6CcPQrwSS1dsh3bnXJ5wjPCmAQpcZ6PLdBiJWO2P4tjK pzabwyHG3t3hHMK/ezYLOPzM5v28arc9qIMaQ= X-Gm-Gg: ASbGncsEUBBZlo7oygdmWqEmYC79MtOd+rTPji5NM2R26XTe7cUWNwmudBbfd5Tsy6H /wrbqzaeAdP/99Le54ossZhuDpDGuyMhm79klUnOC3zLCE40MsXSDfQFVmenOFOkyLp61+4z39C xmViUsfnqRkbaVOTdS9e9jTT4onCnl9aMHpKLv9hXJI1ArnoWZzXXQdb4AlffBfadR972vZZ/4D +TY5EJtKfV2L87pWx2CEub7OzUyQJvNOEbGLhs1T93JCvwbsdg8h459MaXy67cgxXOSOGgqUt9e W5sFDIuDM9r21HEHpJ2qORuVn1NvLWDH44qmSeefEQ== X-Received: by 2002:a05:6000:18a5:b0:386:3a8e:64bd with SMTP id ffacd0b85a97d-388e4d8b7c1mr1886343f8f.22.1734519217512; Wed, 18 Dec 2024 02:53:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IHGxtoL89ebJ7m7B7KkyshTksdkcAMmk1gEf7e125/rlETHyOKlqVT/HvkA0HnoJZacLw7wpg== X-Received: by 2002:a05:6000:18a5:b0:386:3a8e:64bd with SMTP id ffacd0b85a97d-388e4d8b7c1mr1886308f8f.22.1734519217017; Wed, 18 Dec 2024 02:53:37 -0800 (PST) Received: from localhost (p200300cbc73f8300a5d5c21badd3cf50.dip0.t-ipconnect.de. [2003:cb:c73f:8300:a5d5:c21b:add3:cf50]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-388c804a297sm13607480f8f.67.2024.12.18.02.53.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 18 Dec 2024 02:53:36 -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 13/15] s390x: remember the maximum page size Date: Wed, 18 Dec 2024 11:53:01 +0100 Message-ID: <20241218105303.1966303-14-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241218105303.1966303-1-david@redhat.com> References: <20241218105303.1966303-1-david@redhat.com> MIME-Version: 1.0 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: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 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.116, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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: <20241008105455.2302628-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 aa06d07835..ef1bf32770 100644 --- a/hw/s390x/s390-virtio-ccw.c +++ b/hw/s390x/s390-virtio-ccw.c @@ -150,6 +150,16 @@ uint64_t s390_get_memory_limit(S390CcwMachineState *s390ms) return s390ms->memory_limit; } +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 = pagesize; +} + static void s390_memory_init(MachineState *machine) { S390CcwMachineState *s390ms = S390_CCW_MACHINE(machine); @@ -198,7 +208,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-virtio-ccw.h index eb04542979..5a730f5d07 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; 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, S390CPU *cpu) return s390_count_running_cpus(); } -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) /* 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); From patchwork Wed Dec 18 10:53:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13913439 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CF9A5E77187 for ; Wed, 18 Dec 2024 10:55:59 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tNriJ-0001lM-Se; Wed, 18 Dec 2024 05:55: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 1tNrhr-0000nF-Su for qemu-devel@nongnu.org; Wed, 18 Dec 2024 05:55:08 -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 1tNrhn-0006tM-IW for qemu-devel@nongnu.org; Wed, 18 Dec 2024 05:55:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734519302; 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=u2lZB1XkpAVLKJUOPtItdy8lM7FE26x15ARtSf++WDA=; b=VksJlwsvH6T5mCe3iIlKAcq4c1ZCRAwlDlaYdHlyPzLNkfreSB57QUd8wBBFn1xyUl6w/P sOLZe10awFZh2EsJWZ1H4y++8f5FbgO84nitCqcqNWkaRR/noJI/4VhSKX2+6mUp2LnJCz Uk00MKa4ohk9PzcHvtTfOGSWHl2GxMU= 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-540-kgqvJI9uNG-_gtwACmg8WA-1; Wed, 18 Dec 2024 05:53:41 -0500 X-MC-Unique: kgqvJI9uNG-_gtwACmg8WA-1 X-Mimecast-MFC-AGG-ID: kgqvJI9uNG-_gtwACmg8WA Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4362f893bfaso28615875e9.1 for ; Wed, 18 Dec 2024 02:53:41 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734519220; x=1735124020; 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=u2lZB1XkpAVLKJUOPtItdy8lM7FE26x15ARtSf++WDA=; b=kAF1ZGy8d5RMxFYPajEKrzw0E0+Boq+aEVySK7uod0Y53YiGtSHTXUcGHv/t1B5YUS NukL+WjhlOLrFyCCCHrQ1AeBx28fRrAFOGcmJutJHR4voU1S7hdHs2Sc0Iu6eY2ZxtCQ aJi4QHNbKw66h9kQZch/0rVOP64nKwhKaNH3mIQ5Kqk5C1OkNHNhGMiusN8+nDbV+3T6 YOxBy0vz8YH6/EZ20jgzlF0XGoHSpC9h/lmASGDJmvQIJzpFF3r9Y8wPW0oz6tawVWjN 1Ph3qHZ3E+hs1OinM5wMVNo9AxmPXvp8uu3V+3xehMhEsrK57olay6+nd7I3HdDnndVL uNOQ== X-Gm-Message-State: AOJu0Yyr7YkwKCrGdVGe6VMH7lemkxMGBOgh1wihyF9YKYReRu6WtdQo lndC/a8QVrAb2dRPFqL7MjkC/r8xRlMEoMpwvOuG3MhrOUjIID4SrJL4L+QeC6u4nEMB9Xl6ATb 3ZFbnUKtFezYd46q2zOuIJ2QfuXIgYgpwCOxLIGuIHrDPLbN4eGcveULwzXUtniY78EDII++zH0 krSrY2taeI8ylQofKJ6qEYRL4Q9TS+FIAt9+A= X-Gm-Gg: ASbGnct+GSGVF1pYA8ihKOHnEYqRlF2CYxoMvi8FzrNtpNc+SAe8kuO0d6jKW1JC2cc NgHyiao837DQqvHAATavhJBl7Eubh7FWn/u+PYYSNoRlSCYtmqSPEhZm0Gulr3vEZewbVH+79Q7 CWXF7rnscUPlLZvfGdm2Y62E8OjOFVf+4WoWTAOpYCB/qaOH8nDOGVY0nGa6NVBUmwuGhKUqJoU WGBUMLjSQUoWXMWE/fdqyW5UmLUHZNAwDELBaROuabyGEKtH6e76r6VAYBTQ/fS7o/XZV/BeX+l hzkEfTzrKUKDPWA578Kxqpxz+A/kAqlTxsgxgqBXTA== X-Received: by 2002:a05:600c:3106:b0:434:fb65:ebbb with SMTP id 5b1f17b1804b1-436553689fcmr21731115e9.17.1734519219913; Wed, 18 Dec 2024 02:53:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IFmIhjLinM3crpf0K0rV+idg8w3FsmILpfmys68mkDY8K5XDbpkjHPFp2ce6wOQqkgnPLid3A== X-Received: by 2002:a05:600c:3106:b0:434:fb65:ebbb with SMTP id 5b1f17b1804b1-436553689fcmr21730735e9.17.1734519219377; Wed, 18 Dec 2024 02:53:39 -0800 (PST) Received: from localhost (p200300cbc73f8300a5d5c21badd3cf50.dip0.t-ipconnect.de. [2003:cb:c73f:8300:a5d5:c21b:add3:cf50]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-43656b3b1f6sm16668375e9.31.2024.12.18.02.53.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 18 Dec 2024 02:53:38 -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 14/15] s390x/virtio-ccw: add support for virtio based memory devices Date: Wed, 18 Dec 2024 11:53:02 +0100 Message-ID: <20241218105303.1966303-15-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241218105303.1966303-1-david@redhat.com> References: <20241218105303.1966303-1-david@redhat.com> MIME-Version: 1.0 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: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 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.116, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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: <20241008105455.2302628-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 822f34344b..f47fce0362 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2375,6 +2375,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 71ec747f4c..28bbe4b06c 100644 --- a/hw/s390x/meson.build +++ b/hw/s390x/meson.build @@ -48,8 +48,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) +s390x_ss.add(when: 'CONFIG_VIRTIO_MD', if_false: files('virtio-ccw-md-stubs.c')) + hw_arch += {'s390x': s390x_ss} hw_s390x_modules = {} diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c index ef1bf32770..248566f8dc 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 static Error *pv_mig_blocker; @@ -553,11 +555,39 @@ static void s390_machine_reset(MachineState *machine, ResetType type) s390_ipl_clear_reset_request(); } +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), errp); + } 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 = 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 mapped, so + * qemu_maxrampagesize() will pick up the page sizes of these memdevs + * as well. Before we plug the device and expose any RAM memory regions + * 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() != 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); } } @@ -567,9 +597,20 @@ static void s390_machine_device_unplug_request(HotplugHandler *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_dev), + errp); } } +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), errp); + } + } + static CpuInstanceProperties s390_cpu_index_to_props(MachineState *ms, unsigned cpu_index) { @@ -616,7 +657,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; @@ -776,8 +819,10 @@ static void ccw_machine_class_init(ObjectClass *oc, void *data) mc->possible_cpu_arch_ids = s390_possible_cpu_arch_ids; /* it is overridden with 'host' cpu *in kvm_arch_init* */ mc->default_cpu_type = S390_CPU_TYPE_NAME("qemu"); + hc->pre_plug = s390_machine_device_pre_plug; hc->plug = s390_machine_device_plug; hc->unplug_request = s390_machine_device_unplug_request; + hc->unplug = s390_machine_device_unplug; nc->nmi_monitor_handler = s390_nmi; mc->default_ram_id = "s390.ram"; mc->default_nic = "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 **errp) +{ + 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 **errp) +{ + DeviceState *dev = DEVICE(vmd); + HotplugHandler *bus_handler = qdev_get_bus_hotplug_handler(dev); + MemoryDeviceState *md = MEMORY_DEVICE(vmd); + Error *local_err = 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 supported" + " 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 = DEVICE(vmd); + HotplugHandler *bus_handler = qdev_get_bus_hotplug_handler(dev); + MemoryDeviceState *md = MEMORY_DEVICE(vmd); + Error *local_err = 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 = VIRTIO_MD_CCW_GET_CLASS(vmd); + DeviceState *dev = DEVICE(vmd); + HotplugHandler *bus_handler = qdev_get_bus_hotplug_handler(dev); + HotplugHandlerClass *hdc; + Error *local_err = 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 = 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 = DEVICE(vmd); + HotplugHandler *bus_handler = qdev_get_bus_hotplug_handler(dev); + MemoryDeviceState *md = MEMORY_DEVICE(vmd); + Error *local_err = 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 = { + .name = TYPE_VIRTIO_MD_CCW, + .parent = TYPE_VIRTIO_CCW_DEVICE, + .instance_size = sizeof(VirtIOMDCcw), + .class_size = sizeof(VirtIOMDCcwClass), + .abstract = true, + .interfaces = (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 **errp); +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 config VIRTIO_BALLOON bool From patchwork Wed Dec 18 10:53:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13913440 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 06F07E7718A for ; Wed, 18 Dec 2024 10:56:01 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tNriH-0001ZT-BL; Wed, 18 Dec 2024 05:55:33 -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 1tNrhr-0000n9-JI for qemu-devel@nongnu.org; Wed, 18 Dec 2024 05:55:08 -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 1tNrhn-0006rS-9M for qemu-devel@nongnu.org; Wed, 18 Dec 2024 05:55:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734519302; 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=C6mjoxWpzKzpHFaajNu3b5e8yQfielrard7GssXS/50=; b=iKtTlJsTqL35xhM+ZE7bgBzYt9IcNP/8cvEf6PPU+S/6ljgugBypdnblmXs19bJ+9yf0AN F4vozki4aBXCcLZ2Vvuo3zvXqOyWCQSTYMhBU3UhOJ9PZqgrsGmHLooP+0kEZGOn+Ol/LF XBP0m1c4yZZFMi/tpv0x/0g2XBERV0s= 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-163-ng5jvswBOhqPowTDEzPJBw-1; Wed, 18 Dec 2024 05:53:44 -0500 X-MC-Unique: ng5jvswBOhqPowTDEzPJBw-1 X-Mimecast-MFC-AGG-ID: ng5jvswBOhqPowTDEzPJBw Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-385dc37cb3eso3543826f8f.0 for ; Wed, 18 Dec 2024 02:53:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734519223; x=1735124023; 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=C6mjoxWpzKzpHFaajNu3b5e8yQfielrard7GssXS/50=; b=pimIxeG6lF2FJH/R1qTaBe/ZVd6gl7RqcImmpELwOdhihqpwHcEkGyL+o7OxoOiBTd ELexm0Q075KRjG11wSjH5LlS/kkMbiq2hnsTog4YX5qdJY5BxpfPLzjQdZCfHQwm2V60 5sAtnLfhdLvbHtd4CNpb+5SFLr+XcMWp12oyOsflfHPyrrCapRyrWog2IGPFhYGk/C0O uLp4we1W8rfPuYYlKat1k5UHnyjqZBZEGr+nMV6ARf38fttczkHN8dwj2AxCkFdTG7qy btSDwtXZfnSifPhLKrTaSR0efNXCYF+JMcWhVmRiIn2FbGBGI1HS7lrgkcmExzZ1eJD8 erdg== X-Gm-Message-State: AOJu0YxvZNZ2rlfqhV67Wp575XpR2c93hYg7lDCj2fPd5sc8/BLZu2I5 XkvPvc9HDxihZh3hGpn0kf/8nrb20rwaVYVI6mOIcjofXuY8dZnph1TsUegRHhf08cv52XKKIAE cz2kSEoyK0h6PFt0xWT+P5obYhef0QoC42KHM2vXRz3oIDoc62rkNNqRswWH2BiFBKZNe7DFOor vvGL2xaolXMY94GYDUq6zlc3ld30jp+HCt5Bc= X-Gm-Gg: ASbGnctXGIoibBwhP9+tvs3kIt7YakppWs4FjcUYV5dT8Qu5wXPh9uJeqEU+qigTaBf Oi7qP0ufn6+ZNsDSNxK1/ZijneMjz3/IYeU4dyNKWJoV6FPoGMXWL1231x3r8IDr/tsvoR1Q3SU O2c9eOjVRYGRsBBdaJrnKjvrcrTG1RMFNUirlMaS85TgVrmLeEfnEjr7W6Iezgy+AWTruKglGY9 STDkBTjNcwEyf9in5Tz3/cUMEkt6SyLezvLfrGa9sdz9ZTluq8TSRY+gauSpQA/Zh/hVH1feTEX LFnKvuelqMPIds77Pk2X4wR2goLYb0nEvI//VyoArA== X-Received: by 2002:a05:6000:18a4:b0:385:e013:b842 with SMTP id ffacd0b85a97d-388e4d42b6emr2488309f8f.14.1734519223037; Wed, 18 Dec 2024 02:53:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IGYVz8NEUhgNLAOUuw0/YdgEiL/tew/5Q8u+Ue1UJsUwbVDzvc+cAMNt5Q2o6Z9skplnQeaIg== X-Received: by 2002:a05:6000:18a4:b0:385:e013:b842 with SMTP id ffacd0b85a97d-388e4d42b6emr2488263f8f.14.1734519222467; Wed, 18 Dec 2024 02:53:42 -0800 (PST) Received: from localhost (p200300cbc73f8300a5d5c21badd3cf50.dip0.t-ipconnect.de. [2003:cb:c73f:8300:a5d5:c21b:add3:cf50]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-43656b01b73sm16725645e9.14.2024.12.18.02.53.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 18 Dec 2024 02:53:41 -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 15/15] s390x: virtio-mem support Date: Wed, 18 Dec 2024 11:53:03 +0100 Message-ID: <20241218105303.1966303-16-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241218105303.1966303-1-david@redhat.com> References: <20241218105303.1966303-1-david@redhat.com> MIME-Version: 1.0 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: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 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.116, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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=20G \ -nographic \ -smp 8 \ -hda Fedora-Server-KVM-40-1.14.s390x.qcow2 \ -chardev socket,id=monitor,path=/var/tmp/monitor,server,nowait \ -mon chardev=monitor,mode=readline \ -object memory-backend-ram,id=mem0,size=16G,reserve=off \ -device virtio-mem-ccw,id=vmem0,memdev=mem0,dynamic-memslots=on 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=mem0,size=8G,reserve=off (qemu) device_add virtio-mem-ccw,id=vmem0,memdev=mem0,\ dynamic-memslots=on,requested-size=1G (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: <20241008105455.2302628-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 f47fce0362..898097593e 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2389,6 +2389,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 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 28bbe4b06c..094435cd3b 100644 --- a/hw/s390x/meson.build +++ b/hw/s390x/meson.build @@ -49,6 +49,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) s390x_ss.add(when: 'CONFIG_VIRTIO_MD', if_false: files('virtio-ccw-md-stubs.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 = VIRTIO_MEM_CCW(ccw_dev); + DeviceState *vdev = 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 *md, + Error **errp) +{ + VirtIOMEMCcw *dev = VIRTIO_MEM_CCW(md); + VirtIOMEM *vmem = &dev->vdev; + VirtIOMEMClass *vmc = 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 = VIRTIO_MEM_CCW(md); + VirtIOMEM *vmem = VIRTIO_MEM(&dev->vdev); + VirtIOMEMClass *vmc = VIRTIO_MEM_GET_CLASS(vmem); + + vmc->decide_memslots(vmem, limit); +} + +static unsigned int virtio_ccw_mem_get_memslots(MemoryDeviceState *md) +{ + VirtIOMEMCcw *dev = VIRTIO_MEM_CCW(md); + VirtIOMEM *vmem = VIRTIO_MEM(&dev->vdev); + VirtIOMEMClass *vmc = VIRTIO_MEM_GET_CLASS(vmem); + + return vmc->get_memslots(vmem); +} + +static uint64_t virtio_ccw_mem_get_plugged_size(const MemoryDeviceState *md, + 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 = g_new0(VirtioMEMDeviceInfo, 1); + VirtIOMEMCcw *dev = VIRTIO_MEM_CCW(md); + VirtIOMEM *vmem = &dev->vdev; + VirtIOMEMClass *vpc = VIRTIO_MEM_GET_CLASS(vmem); + DeviceState *vdev = DEVICE(md); + + if (vdev->id) { + vi->id = g_strdup(vdev->id); + } + + /* let the real device handle everything else */ + vpc->fill_device_info(vmem, vi); + + info->u.virtio_mem.data = vi; + info->type = 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 *data) +{ + VirtIOMEMCcw *dev = container_of(notifier, VirtIOMEMCcw, + size_change_notifier); + DeviceState *vdev = DEVICE(dev); + char *qom_path = object_get_canonical_path(OBJECT(dev)); + const uint64_t * const size_p = 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 = VIRTIO_MEM_CCW(vmd); + VirtIOMEM *vmem = &dev->vdev; + VirtIOMEMClass *vpc = 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 *opaque, + Error **errp) +{ + VirtIOMEMCcw *dev = 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 *opaque, + Error **errp) +{ + VirtIOMEMCcw *dev = VIRTIO_MEM_CCW(obj); + DeviceState *vdev = 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[] = { + 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 = DEVICE_CLASS(klass); + VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass); + MemoryDeviceClass *mdc = MEMORY_DEVICE_CLASS(klass); + VirtIOMDCcwClass *vmdc = VIRTIO_MD_CCW_CLASS(klass); + + k->realize = virtio_ccw_mem_realize; + set_bit(DEVICE_CATEGORY_MISC, dc->categories); + device_class_set_props(dc, virtio_ccw_mem_properties); + + mdc->get_addr = virtio_ccw_mem_get_addr; + mdc->set_addr = virtio_ccw_mem_set_addr; + mdc->get_plugged_size = virtio_ccw_mem_get_plugged_size; + mdc->get_memory_region = virtio_ccw_mem_get_memory_region; + mdc->decide_memslots = virtio_ccw_mem_decide_memslots; + mdc->get_memslots = virtio_ccw_mem_get_memslots; + mdc->fill_device_info = virtio_ccw_mem_fill_device_info; + mdc->get_min_alignment = virtio_ccw_mem_get_min_alignment; + + vmdc->unplug_request_check = virtio_ccw_mem_unplug_request_check; +} + +static void virtio_ccw_mem_instance_init(Object *obj) +{ + VirtIOMEMCcw *dev = 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 = virtio_ccw_mem_size_change_notify; + vmem = &dev->vdev; + vmc = 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_PROP); + 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 = { + .name = TYPE_VIRTIO_MEM_CCW, + .parent = TYPE_VIRTIO_MD_CCW, + .instance_size = sizeof(VirtIOMEMCcw), + .instance_init = virtio_ccw_mem_instance_init, + .class_init = 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() == 64 * KiB) { default_thp_size = 512 * MiB; } +#elif defined(__s390x__) + default_thp_size = 1 * MiB; #endif 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 the * 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))