From patchwork Thu Dec 19 14:41: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: 13915239 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 330F4E7718B for ; Thu, 19 Dec 2024 16:28:08 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tOJGx-0004jb-SJ; Thu, 19 Dec 2024 11:21:11 -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 1tOHiW-000395-3s for qemu-devel@nongnu.org; Thu, 19 Dec 2024 09:41:32 -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 1tOHiU-0002MA-Ia for qemu-devel@nongnu.org; Thu, 19 Dec 2024 09:41:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734619289; 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=fboTz2aKOBPFD893G/856eT/1ehnF9yoXSpVF6Vzslw0WY/pzm1nxRNUitTbr0qAG3qNRI vtmilJ6tSr/waVA7L7Z7TqcVnjKPV6+viQxWlixurICeBu/Pye+jsM4kDkIc1Ii4EyKe7Y cemAfJDL3YhEIpVRVv+euieLggqpJNI= 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-219-Q3qhqaLkP5-8ywzxRwBnwg-1; Thu, 19 Dec 2024 09:41:23 -0500 X-MC-Unique: Q3qhqaLkP5-8ywzxRwBnwg-1 X-Mimecast-MFC-AGG-ID: Q3qhqaLkP5-8ywzxRwBnwg Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4361c040ba8so5411305e9.1 for ; Thu, 19 Dec 2024 06:41:22 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734619282; x=1735224082; 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=CuG7UfZHmA/LdYlQOAStksFpmCSdCZYY7HM1w/N6gNYf+Aa6puJfj6KLIXxvCZjElG AwvPusoJo6QoIGqLbaUlUvKX0nyasI2aU8fFEwtMeTplKwXSxIq6TozoYjHGQ9TU6IVJ rcroDvh9I10p+uyv8X6iTa9qA0+eGVUxnMJE+D2CWa/gE+n9B9nBOIPVRWIIgVrxqYIO wwKYzOYUskZshpUegPOelvsA6R5Ny2c/lTuDJB4ikFNU4BPq58gi2yqvRngmCU38z7gq JflTlhfEg1stCTAr5UTfU4aZT2AVTbNZo0VHKn5IE9ppC+92qKq3Gcx8EqsusEf5Gga3 AhyA== X-Gm-Message-State: AOJu0YyqOCz0cA2ZE+GruLLJQ9hw0fMxMMPzokig0zWDEFMoY7S1TCGC e/xn1erD6xQVcmyyHzcLuIKfp866LjPS9/hEg58+utx3THpKdHthpuvmeU8IPnHbTDWVbQ2r3cp 0dej5gNBXiGSQ9O3Quh/F9iM4lTZ3RCSEqlQ9+c5jJBP429/x9o4GWyS0cOTKQz+Fj/+a47pHjA /afixStJL//+mKI9WDNh2TCSnhy0813KARf+Q= X-Gm-Gg: ASbGnctlpgxoAcFvyBvdCCZBWaThr0dvZhwVJGtxJsu6G1GMagBr6JMSys5iMOg+o1L SXBk9OZLkXFKJmAgiQEZPtkzLQiZ3afIpBT6R2sRYygTk7PQtIwkvbbG8Su6LbIqszzxaMQltYV u7Emxd6Qu+Wbt32/id8g1YSvx7BNB+g1RKOAuFS0xjCNLbgqhdjhqUmwG+Ikkb1+RnFYCB0sfls 3xlTiLy3hlAxMFfrDEoMci+ENgnh6W4RNny1aQjoiHDt8e/PNbaN8K9ojdorTo4W2RCMsTYgCx3 DtXHvkdI+3n41QwFRRQaMvyyhBenPbpT2vcLNoRz X-Received: by 2002:a05:6000:154c:b0:385:decf:52bc with SMTP id ffacd0b85a97d-38a19b1680cmr3294883f8f.32.1734619281825; Thu, 19 Dec 2024 06:41:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IH6aZO+nDAEA5YjakspU6Sj9NKtxSKEoLpfxqN6jXjYOygAUX94hJOesqUsED3r3p+eGw93Og== X-Received: by 2002:a05:6000:154c:b0:385:decf:52bc with SMTP id ffacd0b85a97d-38a19b1680cmr3294845f8f.32.1734619281426; Thu, 19 Dec 2024 06:41:21 -0800 (PST) Received: from localhost (p200300cbc7496600b73a466ce6100686.dip0.t-ipconnect.de. [2003:cb:c749:6600:b73a:466c:e610:686]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-43656b11aecsm53403925e9.23.2024.12.19.06.41.19 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 19 Dec 2024 06:41:20 -0800 (PST) From: David Hildenbrand To: qemu-devel@nongnu.org Cc: David Hildenbrand , Paolo Bonzini , Thomas Huth , Halil Pasic , Christian Borntraeger , Eric Farman , Richard Henderson , Nina Schoetterl-Glausch , Heiko Carstens , Ilya Leoshkevich , Janosch Frank , "Michael S. Tsirkin" , Cornelia Huck , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v3 01/14] s390x/s390-virtio-ccw: don't crash on weird RAM sizes Date: Thu, 19 Dec 2024 15:41:02 +0100 Message-ID: <20241219144115.2820241-2-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241219144115.2820241-1-david@redhat.com> References: <20241219144115.2820241-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 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 Thu Dec 19 14:41: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: 13915261 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 AEA00E7718B for ; Thu, 19 Dec 2024 16:35:14 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tOJGw-0004Zy-0R; Thu, 19 Dec 2024 11:21:10 -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 1tOHiU-00038w-TC for qemu-devel@nongnu.org; Thu, 19 Dec 2024 09:41: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 1tOHiR-0002Lf-8B for qemu-devel@nongnu.org; Thu, 19 Dec 2024 09:41:28 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734619286; 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=CfUMyzBxkenPRXVObBB8fXXXKSaqPam0WqFh0G56Vy0=; b=RhPn7rXK6496eeGX5s9GBzjMNfnQpXyQ6RFHh1/dTwTkpRlqzCE7/WpUyfuEX+i6CMoVjg POxVhKx7UrsK/ijiqvM4wTlHG8V11BCSoo1/gy4yeYlYHWdh9U0vZrpsRSnx6NuFmD5xiL N8raYasI91MudL5bX95qFMC71R1IMwY= 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-264-E3e2hNHrPZeNPBrzQritSA-1; Thu, 19 Dec 2024 09:41:25 -0500 X-MC-Unique: E3e2hNHrPZeNPBrzQritSA-1 X-Mimecast-MFC-AGG-ID: E3e2hNHrPZeNPBrzQritSA Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-43624b08181so5260835e9.0 for ; Thu, 19 Dec 2024 06:41:25 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734619284; x=1735224084; 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=CfUMyzBxkenPRXVObBB8fXXXKSaqPam0WqFh0G56Vy0=; b=szNLgN61yO/MW/jmMBiDebKw6+yPRfyYapgr8Y3g8wLHTWPl3eCDHgaBKMf9v9qxVY oHbjJcGyhWbM+6QR37bL5j2L3X6mOlimrNaCo9wuEr5HLMA21kbPvX3ZXGtAU2Aa70mA bcvq+CsIoYVHWvyHbKS9DNLxDJQTJLHZCMJ8t5NXWCp5yYV1yIA7OZs1lO7KL9sRvqAs O9lD87Jf665ehplfmY8/NwauiXLn1IRQMwP8sv1WRobHkUfljEMeG8E/jtGh8iqvMNmO sPuMKzy8JNumogbrl3zaoHuoO9L+LHIDjzpwQ1qzUVUBgNOQAGsfbQnFTMkZL9BMSyA1 CRIQ== X-Gm-Message-State: AOJu0YyfCevDnHXYn9aBrL8/1R4gpTpc7WK5Wu6b175ZcR+gVwyDamA+ l8Itdrs9HhCp4HPrLLkISZdKuxA8SxWp4ULGWc9zltWZXNBiyIk3QhUPvTgLHk99zZFUOgO+fz4 cnqVrcPEJLjOUAtxZRhBlZGV5Us658llT6pu7cz9gTfBGeJmhkCDa8vceF6pZ/1qpKHqPju2h7Y YmqNC5wmpFPcpYIOggjwaCZkdB0v8UTFPzYoE= X-Gm-Gg: ASbGncv7qrNd5obd2REtZHUrac0Zk3JFCWLHLK5TssNJ3Cv9GYw6tRhMNrjONQHYBrm JWJ2GoQYXMnb/BfM0MjHz6FfjxlCxDW3tPpoL9uMR9YhcJMpgSMw0BGqo/jqt/6nA2Y90OSfnFe Muhz5yK+gMRGv6I3PTHvUXNdxSBZ7tmKS7ssBKL98b/7NNh0BQaSidDSK4xCvC3Moks9lIYT4dW wUEm0KHwyg0VPsYxgV3dwXLF8sab2QsaHfmkaA2fWBc/IZ1EZC047uisslafFAQjYAcqIJHbUUB h1+gllDn/Lfjm/zyYCRp1Mho5lGAlBJy/TG4JlV1 X-Received: by 2002:a05:600c:3b98:b0:434:e69c:d338 with SMTP id 5b1f17b1804b1-4365c775994mr29757395e9.5.1734619283909; Thu, 19 Dec 2024 06:41:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IFwW+mEvolI/hBMEH/VMiivF08wHGLY3GmEDRdNEgw3Gd3twnsX+9fAxYHplsxuAe36Lw4IIw== X-Received: by 2002:a05:600c:3b98:b0:434:e69c:d338 with SMTP id 5b1f17b1804b1-4365c775994mr29756945e9.5.1734619283231; Thu, 19 Dec 2024 06:41:23 -0800 (PST) Received: from localhost (p200300cbc7496600b73a466ce6100686.dip0.t-ipconnect.de. [2003:cb:c749:6600:b73a:466c:e610:686]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-436611ea3e0sm20239125e9.7.2024.12.19.06.41.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 19 Dec 2024 06:41:22 -0800 (PST) From: David Hildenbrand To: qemu-devel@nongnu.org Cc: David Hildenbrand , Paolo Bonzini , Thomas Huth , Halil Pasic , Christian Borntraeger , Eric Farman , Richard Henderson , Nina Schoetterl-Glausch , Heiko Carstens , Ilya Leoshkevich , Janosch Frank , "Michael S. Tsirkin" , Cornelia Huck , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v3 02/14] s390x/s390-virtio-hcall: remove hypercall registration mechanism Date: Thu, 19 Dec 2024 15:41:03 +0100 Message-ID: <20241219144115.2820241-3-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241219144115.2820241-1-david@redhat.com> References: <20241219144115.2820241-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, 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/meson.build | 6 ++-- hw/s390x/s390-virtio-ccw.c | 58 ------------------------------ hw/s390x/s390-virtio-hcall.c | 65 +++++++++++++++++++++++++--------- hw/s390x/s390-virtio-hcall.h | 2 -- target/s390x/kvm/kvm.c | 5 ++- target/s390x/tcg/misc_helper.c | 3 ++ 6 files changed, 60 insertions(+), 79 deletions(-) diff --git a/hw/s390x/meson.build b/hw/s390x/meson.build index 482fd13420..d6c8c33915 100644 --- a/hw/s390x/meson.build +++ b/hw/s390x/meson.build @@ -12,7 +12,6 @@ s390x_ss.add(files( 's390-pci-inst.c', 's390-skeys.c', 's390-stattrib.c', - 's390-virtio-hcall.c', 'sclp.c', 'sclpcpu.c', 'sclpquiesce.c', @@ -28,7 +27,10 @@ s390x_ss.add(when: 'CONFIG_KVM', if_true: files( s390x_ss.add(when: 'CONFIG_TCG', if_true: files( 'tod-tcg.c', )) -s390x_ss.add(when: 'CONFIG_S390_CCW_VIRTIO', if_true: files('s390-virtio-ccw.c')) +s390x_ss.add(when: 'CONFIG_S390_CCW_VIRTIO', if_true: files( + 's390-virtio-ccw.c', + 's390-virtio-hcall.c', +)) s390x_ss.add(when: 'CONFIG_TERMINAL3270', if_true: files('3270-ccw.c')) s390x_ss.add(when: 'CONFIG_VFIO', if_true: files('s390-pci-vfio.c')) 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 */ diff --git a/target/s390x/kvm/kvm.c b/target/s390x/kvm/kvm.c index dd0322c43a..32cf70bb19 100644 --- a/target/s390x/kvm/kvm.c +++ b/target/s390x/kvm/kvm.c @@ -51,6 +51,7 @@ #include "hw/s390x/s390-virtio-ccw.h" #include "hw/s390x/s390-virtio-hcall.h" #include "target/s390x/kvm/pv.h" +#include CONFIG_DEVICES #define kvm_vm_check_mem_attr(s, attr) \ kvm_vm_check_attr(s, KVM_S390_VM_MEM_CTRL, attr) @@ -1494,9 +1495,11 @@ static int handle_e3(S390CPU *cpu, struct kvm_run *run, uint8_t ipbl) static int handle_hypercall(S390CPU *cpu, struct kvm_run *run) { CPUS390XState *env = &cpu->env; - int ret; + int ret = -EINVAL; +#ifdef CONFIG_S390_CCW_VIRTIO ret = s390_virtio_hypercall(env); +#endif /* CONFIG_S390_CCW_VIRTIO */ if (ret == -EINVAL) { kvm_s390_program_interrupt(cpu, PGM_SPECIFICATION); return 0; diff --git a/target/s390x/tcg/misc_helper.c b/target/s390x/tcg/misc_helper.c index 303f86d363..f44136a568 100644 --- a/target/s390x/tcg/misc_helper.c +++ b/target/s390x/tcg/misc_helper.c @@ -43,6 +43,7 @@ #include "hw/s390x/s390-pci-inst.h" #include "hw/boards.h" #include "hw/s390x/tod.h" +#include CONFIG_DEVICES #endif /* #define DEBUG_HELPER */ @@ -116,12 +117,14 @@ void HELPER(diag)(CPUS390XState *env, uint32_t r1, uint32_t r3, uint32_t num) uint64_t r; switch (num) { +#ifdef CONFIG_S390_CCW_VIRTIO case 0x500: /* KVM hypercall */ bql_lock(); r = s390_virtio_hypercall(env); bql_unlock(); break; +#endif /* CONFIG_S390_CCW_VIRTIO */ case 0x44: /* yield */ r = 0; From patchwork Thu Dec 19 14:41:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13915228 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 9A054E77184 for ; Thu, 19 Dec 2024 16:23:39 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tOJGG-0002IP-Vw; Thu, 19 Dec 2024 11:20:29 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tOHiW-000399-9I for qemu-devel@nongnu.org; Thu, 19 Dec 2024 09:41:32 -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 1tOHiU-0002MD-N2 for qemu-devel@nongnu.org; Thu, 19 Dec 2024 09:41:32 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734619289; 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=3VQaKwg1D2Qf4PHe4EtWcKabR8++ETW6oPSveqgKZuc=; b=huNjhLGwNOoWo9XFYsVbrkfmNoGJlZKUvHtYR2azOa5VNtBVGhWU6zXKxX7fYOhaAlw/Hz QAbqMNewzoQ/8yZz/MaQP4KA1GmPg2dNVMXM6IT8GPBR2VoxdfAhM8uXweI44uQpc98mnX xH5mih59mqV1cp7WSg9e308AeaFCHes= 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-149-euvJhC7OPw-O7cBDgdzhEw-1; Thu, 19 Dec 2024 09:41:27 -0500 X-MC-Unique: euvJhC7OPw-O7cBDgdzhEw-1 X-Mimecast-MFC-AGG-ID: euvJhC7OPw-O7cBDgdzhEw Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-3862be3bfc9so597313f8f.3 for ; Thu, 19 Dec 2024 06:41:27 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734619286; x=1735224086; 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=3VQaKwg1D2Qf4PHe4EtWcKabR8++ETW6oPSveqgKZuc=; b=ojzSstP7gcOeLE0DxdjBRKCFUwqTgh6yV+2NmlBSYSshoFKY8eJX9QiC5SfHQj/yWI 4MiHtKEEAE0HuZ3KNVq32mUvoCfw/VPZr6msi3XEVnKxMtl2hT6H0n9Soe2xr13AAB3k dCWy64s+Duh+VgToaLdLp6DSXlhZq45A66sXN44SJtcW4Hr5Qvut/yxBF+hTwVULkAzr BMtB+/UVTHNLcm5dliA8dnxXzULh7LkhRV0HKbQWvxqgxTNZnsthS6rJk2+OiMkgzDDd uBAWtUQX/c2jREUqLHolzMPY64qUTJ1VrAWryt6hMJ+z5uqlMm3A5x1vAcvK8j1lZg8u ByAA== X-Gm-Message-State: AOJu0Yyr+CQXlhsepRyn0DbIANF+i3lL/eb/OFgWZiq69CCfNhvhdKc4 auVpJceSGZY8N7Hf1pFUB6EvTO1sAqsongIqXqVGYv7kCUm5hYqM4pUQYUAh51Z0Is+PHjGh0uI IlmD8zOmuPjGCZ4rIWwrzrFvBawswkhstRJq/7Uh/5TIifBYe+b9IMXKHTJ/xnj/TR+fvQD6JK1 YTSjut54ALWMgzyhUAlkQsaoil6ky1wQudSs8= X-Gm-Gg: ASbGncvV8j/mhl2dTu1e8APlboqxx2FeFKv4FQJM7IC8+pPvSFSgsbCQ8VEPKnGBgpl znU4/aJ4rpQREML4H4eqhnFi1ZxOUyt+V7WAbeHFyfcA0UGqHsXbVPgRRbEdqRQd+85NHAX+jHZ 1tpCJOV77Yn439Fuwk2VieaO6RtNOASR1Tl4/3Bvj/veDCpex2aj8MH0gMYILCJ6n0nr1qQHAW6 NuEfLNm8hD/rzYGhikyr33moMFfcDY/K5C/Dyp6EP0Basbl3SLF5gwU1u/tZzTju1GEtzxOFhRR iDCZ+ao2aWjr1rak2X0zL3SNqc7mIeQnTA5YP++O X-Received: by 2002:a5d:64a2:0:b0:385:ec8d:8ca9 with SMTP id ffacd0b85a97d-388e4d8df0dmr4694176f8f.42.1734619286180; Thu, 19 Dec 2024 06:41:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IHIEgkc+OWymXfFtvw7wa43e2Ok9cgC15n/X7Sias5HbodnR2vSsXI6yd3ff9qoB4yE0t+j5A== X-Received: by 2002:a5d:64a2:0:b0:385:ec8d:8ca9 with SMTP id ffacd0b85a97d-388e4d8df0dmr4694139f8f.42.1734619285680; Thu, 19 Dec 2024 06:41:25 -0800 (PST) Received: from localhost (p200300cbc7496600b73a466ce6100686.dip0.t-ipconnect.de. [2003:cb:c749:6600:b73a:466c:e610:686]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-38a1c84840asm1700557f8f.61.2024.12.19.06.41.23 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 19 Dec 2024 06:41:24 -0800 (PST) From: David Hildenbrand To: qemu-devel@nongnu.org Cc: David Hildenbrand , Paolo Bonzini , Thomas Huth , Halil Pasic , Christian Borntraeger , Eric Farman , Richard Henderson , Nina Schoetterl-Glausch , Heiko Carstens , Ilya Leoshkevich , Janosch Frank , "Michael S. Tsirkin" , Cornelia Huck , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v3 03/14] s390x/s390-virtio-hcall: prepare for more diag500 hypercalls Date: Thu, 19 Dec 2024 15:41:04 +0100 Message-ID: <20241219144115.2820241-4-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241219144115.2820241-1-david@redhat.com> References: <20241219144115.2820241-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 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 | 20 +++----------------- target/s390x/tcg/misc_helper.c | 5 +++-- 4 files changed, 20 insertions(+), 31 deletions(-) diff --git a/hw/s390x/s390-virtio-hcall.c b/hw/s390x/s390-virtio-hcall.c index ca49e3cd22..5fb78a719e 100644 --- a/hw/s390x/s390-virtio-hcall.c +++ b/hw/s390x/s390-virtio-hcall.c @@ -1,5 +1,5 @@ /* - * Support for virtio hypercalls on s390 + * Support for QEMU/KVM hypercalls on s390 * * Copyright 2012 IBM Corp. * Author(s): Cornelia Huck @@ -57,18 +57,19 @@ static int handle_virtio_ccw_notify(uint64_t subch_id, uint64_t data) return 0; } -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 32cf70bb19..508403609f 100644 --- a/target/s390x/kvm/kvm.c +++ b/target/s390x/kvm/kvm.c @@ -1492,22 +1492,6 @@ static int handle_e3(S390CPU *cpu, struct kvm_run *run, uint8_t ipbl) return r; } -static int handle_hypercall(S390CPU *cpu, struct kvm_run *run) -{ - CPUS390XState *env = &cpu->env; - int ret = -EINVAL; - -#ifdef CONFIG_S390_CCW_VIRTIO - ret = s390_virtio_hypercall(env); -#endif /* CONFIG_S390_CCW_VIRTIO */ - 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; @@ -1603,9 +1587,11 @@ static int handle_diag(S390CPU *cpu, struct kvm_run *run, uint32_t ipb) case DIAG_SET_CONTROL_PROGRAM_CODES: handle_diag_318(cpu, run); break; +#ifdef CONFIG_S390_CCW_VIRTIO case DIAG_KVM_HYPERCALL: - r = handle_hypercall(cpu, run); + handle_diag_500(cpu, RA_IGNORED); break; +#endif /* CONFIG_S390_CCW_VIRTIO */ case DIAG_KVM_BREAKPOINT: r = handle_sw_breakpoint(cpu, run); break; diff --git a/target/s390x/tcg/misc_helper.c b/target/s390x/tcg/misc_helper.c index f44136a568..2b4310003b 100644 --- a/target/s390x/tcg/misc_helper.c +++ b/target/s390x/tcg/misc_helper.c @@ -119,10 +119,11 @@ void HELPER(diag)(CPUS390XState *env, uint32_t r1, uint32_t r3, uint32_t num) switch (num) { #ifdef CONFIG_S390_CCW_VIRTIO 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; #endif /* CONFIG_S390_CCW_VIRTIO */ case 0x44: From patchwork Thu Dec 19 14:41:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13915253 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 1AA2EE77184 for ; Thu, 19 Dec 2024 16:32:54 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tOJIy-00039z-Nr; Thu, 19 Dec 2024 11:23:17 -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 1tOHiX-00039N-FB for qemu-devel@nongnu.org; Thu, 19 Dec 2024 09:41:34 -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 1tOHiV-0002MU-Oj for qemu-devel@nongnu.org; Thu, 19 Dec 2024 09:41:33 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734619291; 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=tqf6k3q8q/B0Mm1igt69ERgmFOVdeWHaULQ4Xn6JpyI=; b=NEs4p9zxMMltA1QLhVYk3OtDj+mQZwYED6e60QtucBFyjY54QJ47Ngzx4tSsBxmcjTJbiA U7gYsXCekDxJPdNkXJO6Xr7EqUuIp8EQ+WOVwxbej9D3qopFDv3Y2D/1snCZGpGdxAnMb9 qv7hkwGx31YH1W8EOx3mDa7tCL4B0j0= 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-593-yNVKgkm1ORSzGcXJr0k1pQ-1; Thu, 19 Dec 2024 09:41:29 -0500 X-MC-Unique: yNVKgkm1ORSzGcXJr0k1pQ-1 X-Mimecast-MFC-AGG-ID: yNVKgkm1ORSzGcXJr0k1pQ Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-386321c8f4bso527216f8f.0 for ; Thu, 19 Dec 2024 06:41:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734619288; x=1735224088; 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=tqf6k3q8q/B0Mm1igt69ERgmFOVdeWHaULQ4Xn6JpyI=; b=FQnWZwgbr5oWo41c5BMkGyNUiSWHMFlxE1BCtXVsgLH935KjknBVTlUWIv2mD0+qYE Y2xx1nY+eGZBcoX1ucOsASgfs3hWZ9I9lltt66hdTjQeiafEgWF6aWQH0JpVw8bse+EJ X+hftZISTCiH1LRaCpAitf/JeZjqe1s6AWK70fPcxXd8IdeEdCfjaLqt/Mdfyc7YslOU 6PDQTCXzjGaQjuUA9TcRtQ5K5IlQ5Dvxta6ESGc+2IddjKMD3zkQyADZwqTo2H6ofXjv d+VAJ6V9yzGhRsJO3AftHfyCRVedYdPo96AZ3u/JxSYi507ePREfhjHAy0B8pxAcIG09 wtYA== X-Gm-Message-State: AOJu0YyaMsbJmcf3mhM9yzfldkBx+JYHOJXy60KbUBDR1emkkWdtrByK kiefLbnGq5XkVndfNpaRVuruea1bazRnYX8rViTmhq8Rz39cxLiZvmgRfLpxGzlCoae1gZu+gR9 Ze8yRi1TKSgyKWVacs80EovY5vhAcVASekZR1yKBvXDuYQY4EcFYoWJo5Y4QvdT/PCpTyM0em8i Qni4ioziL2bjDpb8aJsiZb1IV6pSqywvSUtaw= X-Gm-Gg: ASbGncssUvppoyevct1Qm36ukPqQs3xWuTeK9O+s0g8DKwQQyA09S58/JHMFlErVpfJ yw1Mw8cwFeZ+mI6sgOBz36Uo9BPFd6i0G3kA2acQCkBolViih3xvJrCdNUdb6E8W66tw5Vu9CiV VQmAQ7pXR6D1dWgbCzrDvsRg1cShjac+aMElQ1u4rY8fFYXpA+FX2g3kG4H/weyD6fTprTd1f4p foVjp+V9Y9FmpYpTyqv30GhWgUB2QGGgyuW8iEWG2x5gSJbyPqANGKqyO6UcyDZLUlv/mAgm10r HmAaI1cBcu8xCXJVNcR8WzCRGBPyeYM14wffAIyu X-Received: by 2002:a05:6000:1562:b0:385:f840:e630 with SMTP id ffacd0b85a97d-388e4d8fd68mr6787335f8f.37.1734619288626; Thu, 19 Dec 2024 06:41:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IE1pFzKjK+Z3mlcpD9cWIgAME8vSq/yi4VXzTxd+oWhVs8nWtj31upZLqkHDQHyZm4jIP/5sg== X-Received: by 2002:a05:6000:1562:b0:385:f840:e630 with SMTP id ffacd0b85a97d-388e4d8fd68mr6787297f8f.37.1734619288219; Thu, 19 Dec 2024 06:41:28 -0800 (PST) Received: from localhost (p200300cbc7496600b73a466ce6100686.dip0.t-ipconnect.de. [2003:cb:c749:6600:b73a:466c:e610:686]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-4366128a44fsm19546165e9.43.2024.12.19.06.41.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 19 Dec 2024 06:41:27 -0800 (PST) From: David Hildenbrand To: qemu-devel@nongnu.org Cc: David Hildenbrand , Paolo Bonzini , Thomas Huth , Halil Pasic , Christian Borntraeger , Eric Farman , Richard Henderson , Nina Schoetterl-Glausch , Heiko Carstens , Ilya Leoshkevich , Janosch Frank , "Michael S. Tsirkin" , Cornelia Huck , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v3 04/14] s390x: rename s390-virtio-hcall* to s390-hypercall* Date: Thu, 19 Dec 2024 15:41:05 +0100 Message-ID: <20241219144115.2820241-5-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241219144115.2820241-1-david@redhat.com> References: <20241219144115.2820241-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 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 d6c8c33915..e344a3bd8c 100644 --- a/hw/s390x/meson.build +++ b/hw/s390x/meson.build @@ -29,7 +29,7 @@ s390x_ss.add(when: 'CONFIG_TCG', if_true: files( )) s390x_ss.add(when: 'CONFIG_S390_CCW_VIRTIO', if_true: files( 's390-virtio-ccw.c', - 's390-virtio-hcall.c', + 's390-hypercall.c', )) s390x_ss.add(when: 'CONFIG_TERMINAL3270', if_true: files('3270-ccw.c')) s390x_ss.add(when: 'CONFIG_VFIO', if_true: files('s390-pci-vfio.c')) diff --git a/hw/s390x/s390-virtio-hcall.c b/hw/s390x/s390-hypercall.c similarity index 97% rename from hw/s390x/s390-virtio-hcall.c rename to hw/s390x/s390-hypercall.c index 5fb78a719e..f816c2b1ef 100644 --- a/hw/s390x/s390-virtio-hcall.c +++ b/hw/s390x/s390-hypercall.c @@ -12,7 +12,7 @@ #include "qemu/osdep.h" #include "cpu.h" #include "hw/boards.h" -#include "hw/s390x/s390-virtio-hcall.h" +#include "hw/s390x/s390-hypercall.h" #include "hw/s390x/ioinst.h" #include "hw/s390x/css.h" #include "virtio-ccw.h" diff --git a/hw/s390x/s390-virtio-hcall.h b/hw/s390x/s390-hypercall.h similarity index 86% rename from hw/s390x/s390-virtio-hcall.h rename to hw/s390x/s390-hypercall.h index dca456b926..2fa81dbfdd 100644 --- a/hw/s390x/s390-virtio-hcall.h +++ b/hw/s390x/s390-hypercall.h @@ -9,8 +9,8 @@ * directory. */ -#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 508403609f..7a3e1a8e1e 100644 --- a/target/s390x/kvm/kvm.c +++ b/target/s390x/kvm/kvm.c @@ -49,7 +49,7 @@ #include "hw/s390x/ebcdic.h" #include "exec/memattrs.h" #include "hw/s390x/s390-virtio-ccw.h" -#include "hw/s390x/s390-virtio-hcall.h" +#include "hw/s390x/s390-hypercall.h" #include "target/s390x/kvm/pv.h" #include CONFIG_DEVICES diff --git a/target/s390x/tcg/misc_helper.c b/target/s390x/tcg/misc_helper.c index 2b4310003b..b726a95352 100644 --- a/target/s390x/tcg/misc_helper.c +++ b/target/s390x/tcg/misc_helper.c @@ -36,7 +36,7 @@ #include "sysemu/cpus.h" #include "sysemu/sysemu.h" #include "hw/s390x/ebcdic.h" -#include "hw/s390x/s390-virtio-hcall.h" +#include "hw/s390x/s390-hypercall.h" #include "hw/s390x/sclp.h" #include "hw/s390x/s390_flic.h" #include "hw/s390x/ioinst.h" From patchwork Thu Dec 19 14:41:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13915267 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 12051E7718C for ; Thu, 19 Dec 2024 16:37:06 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tOJH5-00054K-9J; Thu, 19 Dec 2024 11:21:24 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tOHia-00039d-0W for qemu-devel@nongnu.org; Thu, 19 Dec 2024 09:41:36 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tOHiY-0002Ms-Dj for qemu-devel@nongnu.org; Thu, 19 Dec 2024 09:41:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734619292; 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=VyQDOEnzApisWwBYedaksydakNeNwdudcL2ngF1b7lxlaQnc0kj/pg6Aix1LFZWB04vp19 CR4R/IdTqUy9gJV4DKaf7VZ31RKNmrH9117O22a+cwftn8O2r0hMlrJioEZKeYvwcphaHn 63/Pg7jwQHzmYeQR2CSo1OpjG6Z2F4g= 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-659-x2Zd82l5MhmZ3mVoiYZwYA-1; Thu, 19 Dec 2024 09:41:31 -0500 X-MC-Unique: x2Zd82l5MhmZ3mVoiYZwYA-1 X-Mimecast-MFC-AGG-ID: x2Zd82l5MhmZ3mVoiYZwYA Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4362b9c15d8so5186025e9.3 for ; Thu, 19 Dec 2024 06:41:31 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734619290; x=1735224090; 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=W67IpZBR2zZnHN5flQqRrNpH5f1Eui3Ud8sUCODN+XJ+I7XA8LmtBJ6mxa4hLseK92 XbzusKNzETshHSgrirxzq5ItM7UusiX6y8Pq7qt9n8d65N9nF2s34hIgLEenCVqNu5fi bYB0Ki6jVY2042JB+sx/ql486Chu2ewm0V2nkdp3n3g+vQiIrfaALYBrBuAs5HxSGw/Q BwOIUe72E9Wqbs1D9UxWFbHgAyZBi5mgG1sfTYKplVGIA4qpAl0UhTn4521VeMy9bWfs KNlFv6ZMgJLR44TLZfJU21Urt01XzbD44c1Ee6sxPZz3sriwE+ToNZZDifJN49JMAH5S OQ+A== X-Gm-Message-State: AOJu0Yyy+04zpSFoLKk7BNMKDXhr2F+T4Ajx5h3meGoXboVOO369nnsJ a6NYPp03yok8FEjXoSHCWRlaN55d/f2BX5zWJwk8ya+2a4VHNxq1gUgbApsKzfCrp541PtDfBFK Ac4AqvjyypDO2cEzEhP4eCWWehAwGyGElGpudgaEuv7oUVcS1ruurkqJNsVAzRRE++XgoXFNO8W qGL0A0YSd8v/PlH8wP4hg+t901uZs5AnHgvDQ= X-Gm-Gg: ASbGncvu1SuiXiqVh0MLF4DVJ+b2hVOXIACC2INAm9j74zTUmhCbcDFINtO2qyiyJxR nIsd1pzESjZ+P+u7MhlJ1RG6dmCw187jhPdYM44pKpKr0BWw6zv2vJ+y1yhX2mzNfAj1GOcBoux r7y5rS5Pkbk0ktOD3gzisnGXdiLM09Fzjbe8MDVA5w2qVQS3yyObc0ItkN+bAmwTwrz8fPBownI knSFo0UK5xKHofurcLu8AJdfY0VfyIA4765aOjjlbDDzHeLvpMTbA832COINvcXbLfs3ypiYd0y 0LdGyOv6AQwlQi7iFjk72RypK/univPb83POotzQ X-Received: by 2002:a05:600c:3548:b0:434:a1d3:a30f with SMTP id 5b1f17b1804b1-43655345212mr63790865e9.6.1734619290197; Thu, 19 Dec 2024 06:41:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IFtHMVOBeAxDz6ruff6h7b+APMm7L2hbahpzHmL/60QT5pmnzXrF4aVaL4FomTTosyQOJAwHg== X-Received: by 2002:a05:600c:3548:b0:434:a1d3:a30f with SMTP id 5b1f17b1804b1-43655345212mr63790515e9.6.1734619289785; Thu, 19 Dec 2024 06:41:29 -0800 (PST) Received: from localhost (p200300cbc7496600b73a466ce6100686.dip0.t-ipconnect.de. [2003:cb:c749:6600:b73a:466c:e610:686]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-436612008bcsm19613395e9.16.2024.12.19.06.41.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 19 Dec 2024 06:41:29 -0800 (PST) From: David Hildenbrand To: qemu-devel@nongnu.org Cc: David Hildenbrand , Paolo Bonzini , Thomas Huth , Halil Pasic , Christian Borntraeger , Eric Farman , Richard Henderson , Nina Schoetterl-Glausch , Heiko Carstens , Ilya Leoshkevich , Janosch Frank , "Michael S. Tsirkin" , Cornelia Huck , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v3 05/14] s390x/s390-virtio-ccw: move setting the maximum guest size from sclp to machine code Date: Thu, 19 Dec 2024 15:41:06 +0100 Message-ID: <20241219144115.2820241-6-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241219144115.2820241-1-david@redhat.com> References: <20241219144115.2820241-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, 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 Thu Dec 19 14:41:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13915249 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 21412E77184 for ; Thu, 19 Dec 2024 16:30:46 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tOJIF-0007Xv-Uy; Thu, 19 Dec 2024 11:22:32 -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 1tOHic-00039s-H5 for qemu-devel@nongnu.org; Thu, 19 Dec 2024 09:41: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 1tOHia-0002NO-UU for qemu-devel@nongnu.org; Thu, 19 Dec 2024 09:41:38 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734619296; 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=MYii7dt2+ZtXvGWzQ4vYeXf89uLkAK1FjQNWVHIzMe4=; b=Fg253PuIYJPMvge0N7WgjuE1XTEdb4hoflnuInryA34OBX46B6xRCP3OZy4/NZINbcfyaj I4Kc28Kf5t48iuLudse7acdNVCbePM5IMbvOtyv3Yj+ejVYAPGQ408uHqQGwMm/7UwFDSR kSpVk3Nrz549L44+V2BbDQJmIKKAwe4= 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-10-OxvOduDzOoii13xu81HQCw-1; Thu, 19 Dec 2024 09:41:33 -0500 X-MC-Unique: OxvOduDzOoii13xu81HQCw-1 X-Mimecast-MFC-AGG-ID: OxvOduDzOoii13xu81HQCw Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4362b9c1641so5081505e9.3 for ; Thu, 19 Dec 2024 06:41:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734619292; x=1735224092; 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=MYii7dt2+ZtXvGWzQ4vYeXf89uLkAK1FjQNWVHIzMe4=; b=fL2g7GXL3Hnh6guPiWfcj38eQXDO7ii/uqATeU5shQCkOR1de1DlhCtgyFup4jZ4At zGGV5xEELFe4oq+16NWRYXujnrmdd9htmy3XOY4mUChZUapJezxvYyOcJ0vD9zEX3MFN RfKfQPTm4y0QwnSDHUEFfmTMYJ2QvRwJvXdUpYNkZjkQhYEhLRJRMwyfEkWCBf03pzjt swiIKsn4kfCNgWMAfobGvuzI/wdChpM29rMzX3xtDpGsDjqoZRCtRcfh/4AJkFHHQEOD 8Zhyi9zJpi+Zvj3LPMvbRjh7VJtcaKhBvmyl64GjBo7IEUXOCQYyD9WKomksTdpPBNqM R4xA== X-Gm-Message-State: AOJu0YzJTkjfhHhjtYoBcqZCT+jy/lzEoEqY8Iz0PgRWXccVMfcMn4Ll O5IqMeWcwlUGFo4v+5wLQvB4YSVqP6daxMBpLvkG/gMA3qsPPqkNEtNMwNr7NUpzjVeoz8fOFKR VJzWBdatmVBhjW+mffluYJSw9XmTr4rBlEDNbgcynhcFGZOumkv/RbEHkTSt1xX6H0dCjUDihcx 0T7yZdRoIc+XCCU+okaTFkmXomvERuJ1Gf5mk= X-Gm-Gg: ASbGnctbPmDEQBzTW8Bl3QAdQQU8tA2IGrkMbrc35lnfZ6ZKS1wObGSTG2Ps7mJ9/XF o6Z5rvaT2A4lT8flwi60koafLRy3jnB30xoNXg0tzqnN8eJ5cy7VxkIREzWHUlfMqouWDx2cIsm QMXRV7tX4vDbNBRK7GwoQT4WEkYTZq9xeCkGz0kCYhjrrtAsjuSsLsKIdORseFuR0mUBrZydKlK /2wlAq1gKdhyWiSe00lpvqv4Y7/Ka82L5ABBaq60203uXahu1Wzb9d3hXLwoVhG6LL+5u8ABpZO +4g+hiEzAlLlM/AeWskwIhECcw/y6qTvpZqElWlh X-Received: by 2002:a05:600c:3b84:b0:436:1b7a:c0b4 with SMTP id 5b1f17b1804b1-43655347f09mr59357195e9.1.1734619291945; Thu, 19 Dec 2024 06:41:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IGOvTcX2DH0l98NnpQo6d96dOrXG0tSWcFdWBJR/og7Qc5DYgKbKa2w1ExcQkSOC3v3XuriAg== X-Received: by 2002:a05:600c:3b84:b0:436:1b7a:c0b4 with SMTP id 5b1f17b1804b1-43655347f09mr59356825e9.1.1734619291576; Thu, 19 Dec 2024 06:41:31 -0800 (PST) Received: from localhost (p200300cbc7496600b73a466ce6100686.dip0.t-ipconnect.de. [2003:cb:c749:6600:b73a:466c:e610:686]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-38a1c8b830csm1704090f8f.108.2024.12.19.06.41.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 19 Dec 2024 06:41:31 -0800 (PST) From: David Hildenbrand To: qemu-devel@nongnu.org Cc: David Hildenbrand , Paolo Bonzini , Thomas Huth , Halil Pasic , Christian Borntraeger , Eric Farman , Richard Henderson , Nina Schoetterl-Glausch , Heiko Carstens , Ilya Leoshkevich , Janosch Frank , "Michael S. Tsirkin" , Cornelia Huck , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v3 06/14] s390x: introduce s390_get_memory_limit() Date: Thu, 19 Dec 2024 15:41:07 +0100 Message-ID: <20241219144115.2820241-7-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241219144115.2820241-1-david@redhat.com> References: <20241219144115.2820241-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 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 | 17 ++++++++++++----- include/hw/s390x/s390-virtio-ccw.h | 8 ++++++++ target/s390x/cpu-sysemu.c | 8 -------- target/s390x/cpu.h | 1 - 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c index a28e615c5a..1c56b70dcd 100644 --- a/hw/s390x/s390-virtio-ccw.c +++ b/hw/s390x/s390-virtio-ccw.c @@ -45,6 +45,7 @@ #include "migration/blocker.h" #include "qapi/visitor.h" #include "hw/s390x/cpu-topology.h" +#include "kvm/kvm_s390x.h" #include CONFIG_DEVICES 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; + uint64_t hw_limit = 0; + 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,12 @@ static void set_memory_limit(uint64_t new_limit) error_report("setting the guest size failed"); exit(EXIT_FAILURE); } + s390ms->memory_limit = new_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 +161,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..de04336c5a 100644 --- a/include/hw/s390x/s390-virtio-ccw.h +++ b/include/hw/s390x/s390-virtio-ccw.h @@ -29,10 +29,18 @@ struct S390CcwMachineState { bool dea_key_wrap; bool pv; uint8_t loadparm[8]; + uint64_t memory_limit; SCLPDevice *sclp; }; +static inline uint64_t s390_get_memory_limit(S390CcwMachineState *s390ms) +{ + /* We expect to be called only after the limit was set. */ + assert(s390ms->memory_limit); + return s390ms->memory_limit; +} + #define S390_PTF_REASON_NONE (0x00 << 8) #define S390_PTF_REASON_DONE (0x01 << 8) #define S390_PTF_REASON_BUSY (0x02 << 8) diff --git a/target/s390x/cpu-sysemu.c b/target/s390x/cpu-sysemu.c index 1cd30c1d84..3118a25fee 100644 --- a/target/s390x/cpu-sysemu.c +++ b/target/s390x/cpu-sysemu.c @@ -255,14 +255,6 @@ unsigned int s390_cpu_set_state(uint8_t cpu_state, 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 Thu Dec 19 14:41:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13915238 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 4DE6DE77184 for ; Thu, 19 Dec 2024 16:27:57 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tOJHc-0005sq-2m; Thu, 19 Dec 2024 11:21:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tOHie-0003A1-7M for qemu-devel@nongnu.org; Thu, 19 Dec 2024 09:41:40 -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 1tOHib-0002NT-Ox for qemu-devel@nongnu.org; Thu, 19 Dec 2024 09:41:39 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734619296; 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=bcYK7CJzsXVAeOZsKg3lULCA4lr2aRbPIXQfbOPRz8AMBN2moRJvYPputAdqk1H2e1HIW3 mxCkFx+Zc6XYrxZJNykGabf2CVtgIz6MEXe1olRLfrDaqsvjxktNT80WiyoJ8/3JMLUr13 bvNtqnVMsRapPBvv6Lqwa1UwGaeVP1k= 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-625-t0QnZrSoOGGsRegygGGVbA-1; Thu, 19 Dec 2024 09:41:35 -0500 X-MC-Unique: t0QnZrSoOGGsRegygGGVbA-1 X-Mimecast-MFC-AGG-ID: t0QnZrSoOGGsRegygGGVbA Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-43626224274so5477415e9.0 for ; Thu, 19 Dec 2024 06:41:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734619294; x=1735224094; 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=NK9iQ/PlSfOeTEY4nKRe002v1y5Pkz7O4EjfIWwERcnJ2Xz8+ykLZXPiKepvvolU3i gHgcikH6/M38MgHcBJu+auosGxrqvrSGI/Y2lKY/3Uwa9DUGK9siVDNyZwX/tHMiUuqC +kHjUqTgQm0E8I3cEfxOmyDA5g/ERE5g75hoK2yNM+iIJv09xOS7HePuVQ9ev0dFiX/q SjlUlwOanhVsB6e39BsriFsrp6FGzTzl4EosJLiTNHRhssnV0CPusgrdQ2s+f915MoC6 l7hFNTLsdmwYvOEDxRUS/0BEugSo48gPIEb2b908T357nL5mhAeoBtjveH7r4gk9GFNw ncbg== X-Gm-Message-State: AOJu0YykYICanwTSKBV+RsvGQ4ayMS7kAHpg/GkpikhSwozU17dxWGhW JKZQV3zJVa2iqJzml/wSH9hOu7pLDvX6xGAtx2ebyEIIAA3TsxxGiPipF/B8iS5FoAESe9fUhNe zRGbAdv0ZM/fvOolGDHJqFVhBGw4G0HsJMft4vCYTuHDwh9I06W3Z5PAey71u+l5Na/Wl960UW3 qwiW/9BrAh9HbI70etYj+4zLa4OPNLJeT8emc= X-Gm-Gg: ASbGncsYDbpTj8pmRZxJX3d43YCtLXqCYGp6ir3nlNagxIsIMTPLMvle3zj8fny6JNP 2nKYTDPnXspATp7h8c0a2AqnIsh6dqd0/PZ1c+FHwktb+iZJ621QJLCY+NISMgEa9awjlZM2Qxg ByvUo7fhxYPTDceqmKmhXCSXsPXSVYiJemXQER7/5UaHLscJ+YXpqvmdCGf/WxvK1irF4QdoJq3 PDwH3gqbbxM3vmIOc8/zJizcehOTQr4cybEZhrM3EjkZQ8yFwiu3Kes2q47Oo/qNr1cTtfgDPbh UQPtq9B8wgRgDE/HXqDbsgeWMPYXawBxUiIArqZ3 X-Received: by 2002:a05:600c:46c7:b0:434:f219:6b28 with SMTP id 5b1f17b1804b1-4365c7c971emr29834815e9.24.1734619294457; Thu, 19 Dec 2024 06:41:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IHztFy0IccXcInyFfCAOjcoAf7Brbxy3wqIIv0V8v9Yq/BFpdH3gxZqLrVcIRngnwr5m1N0bg== X-Received: by 2002:a05:600c:46c7:b0:434:f219:6b28 with SMTP id 5b1f17b1804b1-4365c7c971emr29834475e9.24.1734619294016; Thu, 19 Dec 2024 06:41:34 -0800 (PST) Received: from localhost (p200300cbc7496600b73a466ce6100686.dip0.t-ipconnect.de. [2003:cb:c749:6600:b73a:466c:e610:686]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-436611ea47asm19692745e9.4.2024.12.19.06.41.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 19 Dec 2024 06:41:33 -0800 (PST) From: David Hildenbrand To: qemu-devel@nongnu.org Cc: David Hildenbrand , Paolo Bonzini , Thomas Huth , Halil Pasic , Christian Borntraeger , Eric Farman , Richard Henderson , Nina Schoetterl-Glausch , Heiko Carstens , Ilya Leoshkevich , Janosch Frank , "Michael S. Tsirkin" , Cornelia Huck , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v3 07/14] s390x/s390-hypercall: introduce DIAG500 STORAGE_LIMIT Date: Thu, 19 Dec 2024 15:41:08 +0100 Message-ID: <20241219144115.2820241-8-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241219144115.2820241-1-david@redhat.com> References: <20241219144115.2820241-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 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 Thu Dec 19 14:41:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13915246 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 5A2CFE7718A for ; Thu, 19 Dec 2024 16:29:05 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tOJHd-00061N-Dp; Thu, 19 Dec 2024 11:21:53 -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 1tOHih-0003AI-BE for qemu-devel@nongnu.org; Thu, 19 Dec 2024 09:41:43 -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 1tOHif-0002O0-8o for qemu-devel@nongnu.org; Thu, 19 Dec 2024 09:41:42 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734619300; 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=g8QzR9caDIwZh28IkI4gZxV7O54NEpB7h3VLaqcMYfJSsxvG6tNlM+UQYGrHPsmgD1qsFs pV1a51WI4By3CCOswMIG8emEIQVSkIK49EJE0oB6sI2mPZJGp12S6m/wuIerOaDSQf9piz GRwZJ/gyBm6l8k7WvtQYrkj5PQ5ZXDo= 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-567-fdMWavGkP12vxcYMK8NpqA-1; Thu, 19 Dec 2024 09:41:38 -0500 X-MC-Unique: fdMWavGkP12vxcYMK8NpqA-1 X-Mimecast-MFC-AGG-ID: fdMWavGkP12vxcYMK8NpqA Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4361efc9d23so7272785e9.3 for ; Thu, 19 Dec 2024 06:41:38 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734619297; x=1735224097; 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=PMWVqkz0ZyKY4Cc+AVJSEu+sTIaqtwEkTo2kgqxOi/mQ/3gsSIYqKH5lEhFD2JEC1V DjTDkSmBwkSzNRuAqW/qGJsRXjwFuy8IOCxxId+zOLTRt9WE+T47/5oTtmfUnXFrZvNm nJem7k1o7dRO1n4X67vOLOO3Z2u9dyNunlYI+zQWY4rAe9zeAz9l6Unw5iWw3xwoCpw2 zFz/wbXEteOwZWdB6maymbbgumJXBkB93ungLvIBqOQVZg1IN8LPgkWPiQ/4oZYvyhTz AeDiDHN0Ye9Ch30h5iH0Fsp3ZvneJyFavHJWeXnGKPcp6Fle6iwG6XKEthRcI34Tm3/r A89g== X-Gm-Message-State: AOJu0Yxfjov3bpfe98dUTSxYSnYEJbg6vaP1xRLn3kh/9UEnI91c7bH7 mWvRdTC1GIVc5p1NXuYIXtpjkEYLYLIAqqkDYQZzJthoNsHhe459kwHAuOV32ShDrbqfiiVFbZU y01xUdeWm4l6HLHdTiQ9sOTBHqokQaQxMf/BERsA0ha0T1RmVqHBdSg8Usrnm+EhETiAe5AnvI7 2sKUEVRwLeCvP0LAUN2C/g8InU8RNy4tMzEAQ= X-Gm-Gg: ASbGncs576cYB/gX0c4kBhZF5//FHk+QeIKZoAXThKCoM9VKd4W29EiUOQaHaQHzKi0 +goet3T6qf2FAze88Zl1XOKrbSlqoM0dEsnI7JLH3dve2EQdKploEIIhDYOmFiDTHIVWZ1z4ZiE yBY6s+iWpZYtlr9UdcwU2Vaowh0UYkZWuUoxbjZ/KT2FzFrr1JLAoYhNLBLV/7qDQUwE2u8zbKn oOkJEP/NulfEWiPfydWkpi8KnmdJCM6wYVy/RVldqfCa6nH0gY8zA292UfoeCj9uPbUcTLHPqFE X8ogfgzXcdyUyL7OF6psNZjDVksWEnX1Mji+WSOw X-Received: by 2002:a05:600c:3511:b0:431:557e:b40c with SMTP id 5b1f17b1804b1-4365c9ca659mr31322265e9.27.1734619297665; Thu, 19 Dec 2024 06:41:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IHBHv0x2cGBRQlvqikuvgr/lcZ8/J/1BVJtjA5CBTOcv8QNv58HWKjkf4nZTQ93E/63qb90bQ== X-Received: by 2002:a05:600c:3511:b0:431:557e:b40c with SMTP id 5b1f17b1804b1-4365c9ca659mr31321905e9.27.1734619297250; Thu, 19 Dec 2024 06:41:37 -0800 (PST) Received: from localhost (p200300cbc7496600b73a466ce6100686.dip0.t-ipconnect.de. [2003:cb:c749:6600:b73a:466c:e610:686]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-43656b442dasm53476785e9.42.2024.12.19.06.41.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 19 Dec 2024 06:41:35 -0800 (PST) From: David Hildenbrand To: qemu-devel@nongnu.org Cc: David Hildenbrand , Paolo Bonzini , Thomas Huth , Halil Pasic , Christian Borntraeger , Eric Farman , Richard Henderson , Nina Schoetterl-Glausch , Heiko Carstens , Ilya Leoshkevich , Janosch Frank , "Michael S. Tsirkin" , Cornelia Huck , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v3 08/14] s390x/s390-stattrib-kvm: prepare for memory devices and sparse memory layouts Date: Thu, 19 Dec 2024 15:41:09 +0100 Message-ID: <20241219144115.2820241-9-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241219144115.2820241-1-david@redhat.com> References: <20241219144115.2820241-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 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 Thu Dec 19 14:41:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13915231 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 8DC84E77184 for ; Thu, 19 Dec 2024 16:25:00 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tOJIG-0007bP-Rv; Thu, 19 Dec 2024 11:22: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 1tOHii-0003Aa-F0 for qemu-devel@nongnu.org; Thu, 19 Dec 2024 09:41:44 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tOHih-0002O5-4b for qemu-devel@nongnu.org; Thu, 19 Dec 2024 09:41:44 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734619301; 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=XWmOV9wUwyPje4Vsu/KP4BYWBfv2DOxk5DjZrlLHQo+myGqqXcnlVsCYm0+2GskYFvRb8m +det+ogPsXSzjk/znJrjEpF05dqo283T6SB9uKvNYMAUPo3Ei+IPhqphKm+Mnpy0tRRAyq aXG3LZ/4sNEEbTbgcnuNou1hm+mCO44= 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-536-V39AOP5YN_K4uAX--bvcUw-1; Thu, 19 Dec 2024 09:41:40 -0500 X-MC-Unique: V39AOP5YN_K4uAX--bvcUw-1 X-Mimecast-MFC-AGG-ID: V39AOP5YN_K4uAX--bvcUw Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-436219070b4so5115175e9.1 for ; Thu, 19 Dec 2024 06:41:40 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734619299; x=1735224099; 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=gg8NHc7kvw1WNOMbJKuWET0Azl2juFmVrBd9VKZlh93exuWYFRfw61SQR3uofrFQxZ 0344x8Si7866Zkq92ArvMqc7+rH0L4hz/Goy+fN0aPVJ/rLIfP40DVuCEi8y53i/uMtO v/cqeW0RfA0wglumvVfHpVKqWfSAgIN2vLOWEHr2JIET+edeYzsx5+PEQDe7csSNOcsc YHXit283nOdXjzp8y7MdbK9G/k4brXAVjiLCKpZOgp3u5vpteOeGtOGpuRutc3z+aiXw g2GuBKbWdOLJTRqJ2nG+sbvfrh1WwvqzBQw+cIwLDkx1htTVmjmqgVTnZRuVndy+lEvY ngpw== X-Gm-Message-State: AOJu0YxYNxTROByO5VSsn5kDwyVCkpV2SQYjMc8O25PNC8BW3b2IyYGu LP5wVI0WV1f/UAVTfCbWqtsqkcGG/NQB5oU32Dy1POsSTHbtoezy6KM/uW0j6r+NoVrnvNHkfaT Kjiw0jA2oB89atKBivNlYkV4OkFv/7mbTeIifJRNJEe8y+Jiz9CGWAcIJYiv+n/y52Dj/10fVWw EoBvY+aWNisuSQ9H08mmMh/4J/tO09iJFVjuw= X-Gm-Gg: ASbGncu+J81v+GhzGqxL3CZiSKQZrRvyRRUZYRGC1Y+MrIkmR+9hHwQFnwtZn9zLd+m gYczmKq1q9kTnNkgtQILnGZEjwfMhPD1ciZ5lKjppzIUzywv7Cbe5zvvrNnIxr64DmoSVtcaUsd n6Sjow8EErBfPsQUIOpnX28s+cX5/iEih5zkUZs7rMH+w1syrNkvhMBizoA8QfBFZPTy5naZiOI y6LF7Q1xZxAvHck4CyjK374hyXzoOilQjC23WhKLVqiuFEgta+GlcFnaPzXShSb5bpYbLHWm7Xy zuj1qkStbPNc9gxVtQcMtrE/wPje2PrFpfVnCEfH X-Received: by 2002:a05:6000:186d:b0:385:f677:8594 with SMTP id ffacd0b85a97d-388e4dae534mr6569882f8f.43.1734619299434; Thu, 19 Dec 2024 06:41:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IEFQKY2hGjqemM6rtrThUOVEhVLFMaAF+U6FklQxfKRNp1OyH97jHfYFfU2gMBiPflYIVnk9Q== X-Received: by 2002:a05:6000:186d:b0:385:f677:8594 with SMTP id ffacd0b85a97d-388e4dae534mr6569844f8f.43.1734619298986; Thu, 19 Dec 2024 06:41:38 -0800 (PST) Received: from localhost (p200300cbc7496600b73a466ce6100686.dip0.t-ipconnect.de. [2003:cb:c749:6600:b73a:466c:e610:686]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-38a1c84705esm1709900f8f.44.2024.12.19.06.41.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 19 Dec 2024 06:41:38 -0800 (PST) From: David Hildenbrand To: qemu-devel@nongnu.org Cc: David Hildenbrand , Paolo Bonzini , Thomas Huth , Halil Pasic , Christian Borntraeger , Eric Farman , Richard Henderson , Nina Schoetterl-Glausch , Heiko Carstens , Ilya Leoshkevich , Janosch Frank , "Michael S. Tsirkin" , Cornelia Huck , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v3 09/14] s390x/s390-skeys: prepare for memory devices Date: Thu, 19 Dec 2024 15:41:10 +0100 Message-ID: <20241219144115.2820241-10-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241219144115.2820241-1-david@redhat.com> References: <20241219144115.2820241-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 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 Thu Dec 19 14:41:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13915229 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 B0DC2E7718B for ; Thu, 19 Dec 2024 16:24:13 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tOJJG-0003m0-8g; Thu, 19 Dec 2024 11:23:34 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tOHil-0003Aj-Ul for qemu-devel@nongnu.org; Thu, 19 Dec 2024 09:41:47 -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 1tOHik-0002Os-6U for qemu-devel@nongnu.org; Thu, 19 Dec 2024 09:41:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734619305; 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=32Fg/9MsvAhaDZv2tz2CNpS6C7gzvxZjQEqSc8NsMDE=; b=aAjdlmI1wrmGgFVudnp1ZzoSZlTyhqSP8PiHkLff4qpj3PBOhG7OIne0+9hlD3rde7RfH0 T/G40WaRO2pilbtW3RQiyQrDVV2w1WFhR7NEkELvTPVI0G+4hH9p913QsVQLSGGkXE3izN NdWMDmVjhynJu7ZhHNRf7Weoe+dO/n8= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-584-wIqI_LQ1PR68T48-rSNmew-1; Thu, 19 Dec 2024 09:41:43 -0500 X-MC-Unique: wIqI_LQ1PR68T48-rSNmew-1 X-Mimecast-MFC-AGG-ID: wIqI_LQ1PR68T48-rSNmew Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-385ed79291eso1054285f8f.0 for ; Thu, 19 Dec 2024 06:41:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734619302; x=1735224102; 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=32Fg/9MsvAhaDZv2tz2CNpS6C7gzvxZjQEqSc8NsMDE=; b=V4cn085xYzOc+ca3KdzCvHPHcWHslPRsUgxc0PO3+6SnyJzINBNtQ471RHZS52tURu gKj5HBlcYChF5VqCx1CjAaDbGl30NYi7x93BcbZJoeQY1AOKhN+OTEHx1jKjkCm8QgFp 12bb8BBzKSqnza4wFMZ+fPnt3kt1RZE1LZOao82l+nkp185FbwzBsvE8khMGfXgQsSqV 4xZzXZ7Aimn+VNHt6IZXdbipZsL2DYdVPrMUInSdF2bRyatcgz+tm5AgnQulzZUvSLZM dA777l0lPWMFVof6rmiBD0Nmx7Z4mq5qivoSyDCF1vzQPHXupKImUl98T+HVsMgbc7cC /Dgg== X-Gm-Message-State: AOJu0YzL4cukNvNJvtt+pJrFa1rAclFsRN3n9LuuJJDpM1mZuBuCUSRY SXMLrC8bDzZXvzZx67jQngYw+3bdzG4774ogzlzdkAScGlVChlvTwP2R4SNjuT5BIE+UA96NyuH 2q3AUpezHfQdYvsE49gWH+aCUAQmR2KzaztLw7Vku6ZJ+IUy62vy1x2+fJ9x8bJoPYC1B2lj4jM wPqJsBajUo4iMxOyHGLKkmPYL1Rv8MkP6a1Ds= X-Gm-Gg: ASbGnctmOn5pX1XDt5dx3mLIHNseyPsyaAOybQiEaHgDxm59U3Wh75SbukyQygkLvkX Q/IKEiSPp+5a7P3WnEUptocNgZJ/6idlLv1rXYFJ4qU7RQO4YmiuSvYbvEF3wpmfY3rF2dtw2dp eQo8Sxp9DrlWOb5I20kT+qM2bteQ/EzWbm0mzudVTiJi4+enZZWbZeUPLvEjMiGDxnS3WOZ+gtI 0bX85YIP53sma1if5S6wBPsp1fr0rUHQrsrZRuPXVgBsrq0FhjGRiVjP8QsKjp3aZ6iYg49O9OF AaJnM/Ay9li4qpRqEXroATZHtAvchAmgc9o4f5E6 X-Received: by 2002:a5d:5f4d:0:b0:386:34af:9bae with SMTP id ffacd0b85a97d-38a1a1f7219mr3532273f8f.4.1734619302127; Thu, 19 Dec 2024 06:41:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IH7Rzj8wVSJzmZXEYgZk+H6CTeb0rLWMlJyMFUs4EsRfwWka9nmax80bCaoeqCswpdyOxH5EA== X-Received: by 2002:a5d:5f4d:0:b0:386:34af:9bae with SMTP id ffacd0b85a97d-38a1a1f7219mr3532234f8f.4.1734619301704; Thu, 19 Dec 2024 06:41:41 -0800 (PST) Received: from localhost (p200300cbc7496600b73a466ce6100686.dip0.t-ipconnect.de. [2003:cb:c749:6600:b73a:466c:e610:686]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-43656b0145csm53826055e9.15.2024.12.19.06.41.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 19 Dec 2024 06:41:41 -0800 (PST) From: David Hildenbrand To: qemu-devel@nongnu.org Cc: David Hildenbrand , Paolo Bonzini , Thomas Huth , Halil Pasic , Christian Borntraeger , Eric Farman , Richard Henderson , Nina Schoetterl-Glausch , Heiko Carstens , Ilya Leoshkevich , Janosch Frank , "Michael S. Tsirkin" , Cornelia Huck , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v3 10/14] s390x/s390-virtio-ccw: prepare for memory devices Date: Thu, 19 Dec 2024 15:41:11 +0100 Message-ID: <20241219144115.2820241-11-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241219144115.2820241-1-david@redhat.com> References: <20241219144115.2820241-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 1c56b70dcd..2ba66be018 100644 --- a/hw/s390x/s390-virtio-ccw.c +++ b/hw/s390x/s390-virtio-ccw.c @@ -149,6 +149,7 @@ static void s390_memory_init(MachineState *machine) MemoryRegion *sysmem = 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)) { /* @@ -161,11 +162,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 Thu Dec 19 14:41:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13915223 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 67F6DE7718B for ; Thu, 19 Dec 2024 16:20:44 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tOJFU-0001nL-CQ; Thu, 19 Dec 2024 11:19:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tOHim-0003Ar-O4 for qemu-devel@nongnu.org; Thu, 19 Dec 2024 09:41:48 -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 1tOHik-0002Ow-SJ for qemu-devel@nongnu.org; Thu, 19 Dec 2024 09:41:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734619306; 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=YXYNCvXI4YLcTBJGvRZBBlTqyFUqKX5/Cqmb4oEk4SS0I2TRDhet1vs9xvMN/SjnRDPdJr UpSwCWTphJZAcujj+nFdn8//RJd1XFBUFMQA+rrTawDd8Wk/XEoyntYVIBjxftB/HkivkA iDC4CwBVNPOCgdQE5vWQNW29vL4CjME= 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-418-VYzOtU9oPBiUodDkYeoUOg-1; Thu, 19 Dec 2024 09:41:45 -0500 X-MC-Unique: VYzOtU9oPBiUodDkYeoUOg-1 X-Mimecast-MFC-AGG-ID: VYzOtU9oPBiUodDkYeoUOg Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4362552ce62so5285265e9.0 for ; Thu, 19 Dec 2024 06:41:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734619304; x=1735224104; 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=tq3jSL+vqG7RNzXWpwBjd1I+2VbGMhTgPckPmVOmldbGWqrgQyaF8ROyIQlySXkrt5 ZQ1lZSi/wA7ElVLf7Afp5KdLjQ5Ok01CEzm0l9zaz0XflQ9XlZLXPdgJV8U1q/jfmfqz 22Xb0PDWb4HAQpLWQ6UsmuInTLsrexnOrY0hNWy/oRpXzMUTpt0EamgoEMyhhr79gao9 EDk6Y3qgWhrE4Jrq6TAeg2+JJivi6y6hyaB0hQAQ2peiuTEeN2OhkVpCtBjoWe/BrZbL t7pVCOsevHu+WI3rIAno6asZsOykgG9nhnC12veJn8mxyaZWDJIJIeTQrozoDpGFZqsx I1Ig== X-Gm-Message-State: AOJu0YzKKBmRm1wgN/golsjWRkCNztTpC6P19gdDvn7ALnJ4mPfdBkqn OjzwK+KT98A7w9endLDBjuHZP/OY290wX7f1yVm2uN5O+Ooq36+v0pTz53IzSxRH67MYD7374y2 mfqG32u6Xn6Timj4tkoabByZzzUBKqkhtEpKnpYa3mIveDuwZSkgXuaLqLwMUc7/bYvRmDPG/zN gdcD0tt2v8Y8w2jibVgtyT/9wVlDQ/k73MeKE= X-Gm-Gg: ASbGncsXbne8P3dSohasSKdre1Vp80FT3AJ5gZ91X2HJ7tDlN5jmY7mVhtL9z1yAl2Y h0HKzCOLhP66AXrsyCvpk5csxQ+oQwJq42HZx4Zyu/zsaY7OHr0jntrFZCoWBssVegBJ2n9lObr nB+zSKIHpGEPADv/bGIxRXknp4XeUpFTJDhks9FsGzaTwmWyeKwlvEkGk0hwYMN1vaQC30Y02t6 tAhMpZxew/H8fX9j7ai8akjqIbMihVSmoDXPNK5ANP2z9V+NloM8YRmG3COEiJPTAy5hQ0fFELE PFmCPnpT0Iqb4U9N06aNCHVZ2cfV7pgdoGW1IPKD X-Received: by 2002:a05:6000:4609:b0:382:31a1:8dc3 with SMTP id ffacd0b85a97d-388e4d6430dmr6378027f8f.35.1734619303839; Thu, 19 Dec 2024 06:41:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IFdK5LxQEuU02Z9U+hkMcgnnmY4R64sLf1X0U+pBmoZ2k2Zw/0TsBk3kR2RqwGWkpI7pxlsNg== X-Received: by 2002:a05:6000:4609:b0:382:31a1:8dc3 with SMTP id ffacd0b85a97d-388e4d6430dmr6377993f8f.35.1734619303439; Thu, 19 Dec 2024 06:41:43 -0800 (PST) Received: from localhost (p200300cbc7496600b73a466ce6100686.dip0.t-ipconnect.de. [2003:cb:c749:6600:b73a:466c:e610:686]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-38a1c8471dcsm1708604f8f.48.2024.12.19.06.41.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 19 Dec 2024 06:41:43 -0800 (PST) From: David Hildenbrand To: qemu-devel@nongnu.org Cc: David Hildenbrand , Paolo Bonzini , Thomas Huth , Halil Pasic , Christian Borntraeger , Eric Farman , Richard Henderson , Nina Schoetterl-Glausch , Heiko Carstens , Ilya Leoshkevich , Janosch Frank , "Michael S. Tsirkin" , Cornelia Huck , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v3 11/14] s390x/pv: prepare for memory devices Date: Thu, 19 Dec 2024 15:41:12 +0100 Message-ID: <20241219144115.2820241-12-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241219144115.2820241-1-david@redhat.com> References: <20241219144115.2820241-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 Thu Dec 19 14:41:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13915242 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 A0893E77184 for ; Thu, 19 Dec 2024 16:28:46 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tOJFS-0001n7-Qt; Thu, 19 Dec 2024 11:19:38 -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 1tOHiu-0003BJ-4C for qemu-devel@nongnu.org; Thu, 19 Dec 2024 09:41:56 -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 1tOHin-0002PT-Lu for qemu-devel@nongnu.org; Thu, 19 Dec 2024 09:41:55 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734619308; 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=df6CjF6Td41AMvjiwZAUJBUmD4molRWafGhHQVx7OQA=; b=RlNcwyq47BQ+9Ihi9N/uQp+doB1kHlMh4fhGx3SQzeyBO+3NJihbcqKzJ8e+stHGaXBsaw 1lshir+xHgATB7sJVqwUaalquuW+SBlGB0E+4SkwCQcscIYtnA/lpPswzo2kQ922LBNqeJ lwwldLvvWx+an0F0JMKnsQkIUcPZHUw= 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-417-4GR8vVUPOmecpHdCBGcwCg-1; Thu, 19 Dec 2024 09:41:46 -0500 X-MC-Unique: 4GR8vVUPOmecpHdCBGcwCg-1 X-Mimecast-MFC-AGG-ID: 4GR8vVUPOmecpHdCBGcwCg Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-385d51ba2f5so437652f8f.2 for ; Thu, 19 Dec 2024 06:41:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734619305; x=1735224105; 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=df6CjF6Td41AMvjiwZAUJBUmD4molRWafGhHQVx7OQA=; b=an8Cl+JrH+MP1VX7oj40oNaQFFTnfZVz26WNqTB2KIfnXtOSawfbsrKUrzByvbhKA1 qIpCuQUzqq1FifRwbbzRHQMVm/YRGdCCpyiq45qXbG+eDnkwbEGxIZJJseyZsHC5N3A/ d3wg0McWW1bAczsVwUts3Kz/LKzBK5DX3vPPpij2cXUJFxgKpVbuM1R9nJDFhAK0qlYK Lfq3HfE4fbSM0sL3rZGCFKmmf/6mj8+Wj2iYnAuTRndSJ/q6jk4/cDu4u1oym0IzwVsO +t0hM02iCbNlNRwb9ta1SN3+QqeTieGmgKlr5MJykVw9CFwuV8zc3NFgwd//8Z6nNaVK Ewlg== X-Gm-Message-State: AOJu0YxDphl1PHvlNr0PW0lxhM90EmHM3jf4xTHae4jywJ9QjMZz99zc QSmDjh+1Yme+jrWoyVfKRCnKFHR3joVp78AsF/bLhdttud+rSK28xRJSHHVaz4/FBNzWC18Cjqu 0ZPblIeWo1gu7nKupiwfNfcc9J52MeawkUYvWI0G3Jstsimv8LTx3zFsKXLF3U6+73r43wVYLVu YoVANpaAp+RkDj5h8ll+t/yyiTE35/Jcfo/Rc= X-Gm-Gg: ASbGncteULAwg6FnSLvYgjASzVNjvbA46YoLLfi8YQ/f+sTZQ9yoEj/jGHULX+YFDB/ A7uFRbPy3u1tPX2Ne63xHneZGkzz2dG0qKbcjjtVEdm285PzWnH1+GINezzGJSWeZDEkl2NMruV 9X7qcGkiUKXl3B5lPjFo1aOQ+HF5b2xS5zYBhiCFeYrQm+WNk1poO6sg8Zib9OaTTbwAWlHDgz4 GOIOqQrgBH4aFXoWcZigB2YrCBxxVeM0pYx4ZduoJ4kQYFMFjx2XBz6OkRGp0LTA5lSXIb2e25w wOvTe9Te0iTOWmKJ1zwKKByw/iz1qoTsKs7AmIYW X-Received: by 2002:a05:6000:156b:b0:385:f892:c8fe with SMTP id ffacd0b85a97d-388e4d43a62mr7283606f8f.21.1734619305567; Thu, 19 Dec 2024 06:41:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IEnbgS8QXfgDi/2wFabwK+V4asQjZyvjUrkQalZxbn1dBHR2sy2bkd9kITBj9Xd7DU3nCABYw== X-Received: by 2002:a05:6000:156b:b0:385:f892:c8fe with SMTP id ffacd0b85a97d-388e4d43a62mr7283563f8f.21.1734619305129; Thu, 19 Dec 2024 06:41:45 -0800 (PST) Received: from localhost (p200300cbc7496600b73a466ce6100686.dip0.t-ipconnect.de. [2003:cb:c749:6600:b73a:466c:e610:686]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-38a1c8acc02sm1681600f8f.104.2024.12.19.06.41.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 19 Dec 2024 06:41:44 -0800 (PST) From: David Hildenbrand To: qemu-devel@nongnu.org Cc: David Hildenbrand , Paolo Bonzini , Thomas Huth , Halil Pasic , Christian Borntraeger , Eric Farman , Richard Henderson , Nina Schoetterl-Glausch , Heiko Carstens , Ilya Leoshkevich , Janosch Frank , "Michael S. Tsirkin" , Cornelia Huck , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v3 12/14] s390x: remember the maximum page size Date: Thu, 19 Dec 2024 15:41:13 +0100 Message-ID: <20241219144115.2820241-13-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241219144115.2820241-1-david@redhat.com> References: <20241219144115.2820241-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 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 2ba66be018..9f8d830798 100644 --- a/hw/s390x/s390-virtio-ccw.c +++ b/hw/s390x/s390-virtio-ccw.c @@ -143,6 +143,16 @@ static void s390_set_memory_limit(S390CcwMachineState *s390ms, s390ms->memory_limit = new_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); @@ -191,7 +201,7 @@ static void s390_memory_init(MachineState *machine) * Configure the maximum page size. As no memory devices were created * yet, this is the page size of initial memory only. */ - s390_set_max_pagesize(qemu_maxrampagesize(), &error_fatal); + s390_set_max_pagesize(s390ms, qemu_maxrampagesize()); /* Initialize storage key device */ s390_skeys_init(); /* Initialize storage attributes device */ diff --git a/include/hw/s390x/s390-virtio-ccw.h b/include/hw/s390x/s390-virtio-ccw.h index de04336c5a..599740a998 100644 --- a/include/hw/s390x/s390-virtio-ccw.h +++ b/include/hw/s390x/s390-virtio-ccw.h @@ -30,6 +30,7 @@ struct S390CcwMachineState { bool pv; uint8_t loadparm[8]; uint64_t memory_limit; + uint64_t max_pagesize; 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 Thu Dec 19 14:41:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13915272 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 71290E7718A for ; Thu, 19 Dec 2024 16:39:11 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tOJGI-0002QO-4W; Thu, 19 Dec 2024 11:20:30 -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 1tOHiw-0003BT-5b for qemu-devel@nongnu.org; Thu, 19 Dec 2024 09:41:58 -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 1tOHit-0002Qq-3u for qemu-devel@nongnu.org; Thu, 19 Dec 2024 09:41:57 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734619313; 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=m9dvAqzRzytQceAkLtdosU9ptt2OLUMmqsTVeyr1HNM=; b=eMxMtrh+hZYa8ztjZpkqXuj0DPxwOE+ADeLjVqu/W8pFm0s6fkm379yApyLwk8EOJA+g0v a2dPE3k2QDXfwzG/bZPXLGwMf7y+EQrgUprV6Z3+MAMAoOkTU86oN8Tp3fRCE1qw8V4T7k a9Xq1L/s7QLLs8MumgxMc8g1/d/eSbQ= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-186--Ob2EKhmNT-qN1vdyANL9w-1; Thu, 19 Dec 2024 09:41:50 -0500 X-MC-Unique: -Ob2EKhmNT-qN1vdyANL9w-1 X-Mimecast-MFC-AGG-ID: -Ob2EKhmNT-qN1vdyANL9w Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-385e27c5949so609802f8f.3 for ; Thu, 19 Dec 2024 06:41:50 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734619309; x=1735224109; 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=m9dvAqzRzytQceAkLtdosU9ptt2OLUMmqsTVeyr1HNM=; b=oyvqGiS6gHIxpPu1QFX+M46ccFKmkpf73ZM0GGkaFN/hzjyrbVnyH/kd4n+t0T6ufA Dg13+fEXnBNMwVC5/PI1RnBduTM5CpVW8BxzTmnZSD8i+rmYflIyVKHrad4yNJoePD+T qbIXgaEIDdtbrPfAj/hF0t0moHP7pdrL5gXTUaof4DqRKzTe4SET6E6e42DGefpeT//9 58SKpBNqpZ0ru6hbmVRxjku6raKC8JiBroG45/z/oWb8vOIL60al78NYTLO7dh2cz4b9 1eI8OSoH7lb2pxmiBEKWSBW7tPLKIjHCZHTrgwpAzYaKJIDaqAhL85OuUygBKKjgX6ye 2jGA== X-Gm-Message-State: AOJu0YwieZU24rZrv8OELUWin2SKcPEUhTVI/0L09N4DNczhjNtLOSMb M3g4igkTv5d+FQlXW7NU4aQeJTh+aGVt+Rb2IeVXiawtI55TeNS0XpdFMxfAT7+SR4LogMN30As lrZXGx/ciJ1yvZZqrNMj6/1025UGv18wCLY0hYn4y2hbHeZQitlOL6KhSD3uAz8ZULhaLrCJRSW IL1CjZwwn1/O2xDAsgKwqdkzZVMyTs9gYspM4= X-Gm-Gg: ASbGnct/xa7aYQxS91VD+o7i2yzS/tiujh/uB9ZHeR0V07JeHiZ2IGWcCzjLDdv0iGp o4KS1rMVk+yJCrV3/903wAHASc/VbRPO0Dzi3GAqW5s6bzj32dYAPFcRdup8PWjGPtZL9wVscyG kARLekOqDap+mzDO0UifUr1gG5CE5D5SzXpi/KKd38N1r9ZRjc/vctsbLHQfwdorbJV0UHMUxnO vlAH3EEa4z+AIvtyrKOEWlAh2W+k9boOEGeCUuV2789CcCjgUvFggWadN/LLn8fivX3frSDg8Ye ur6XdD5/+1M3fhpYi7J9t28wes7a0La+/qEWuD3P X-Received: by 2002:a05:6000:4012:b0:385:f89a:402e with SMTP id ffacd0b85a97d-388e4d42b9dmr7860042f8f.14.1734619309283; Thu, 19 Dec 2024 06:41:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IFhwiSGwNXtGs0GzyYt0Ey7NrskyzJIHasc0YUzyahqeMn68+dEy3ZofdJkoqkv8mx3YIJsPw== X-Received: by 2002:a05:6000:4012:b0:385:f89a:402e with SMTP id ffacd0b85a97d-388e4d42b9dmr7859995f8f.14.1734619308727; Thu, 19 Dec 2024 06:41:48 -0800 (PST) Received: from localhost (p200300cbc7496600b73a466ce6100686.dip0.t-ipconnect.de. [2003:cb:c749:6600:b73a:466c:e610:686]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-4366127c515sm19900905e9.30.2024.12.19.06.41.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 19 Dec 2024 06:41:47 -0800 (PST) From: David Hildenbrand To: qemu-devel@nongnu.org Cc: David Hildenbrand , Paolo Bonzini , Thomas Huth , Halil Pasic , Christian Borntraeger , Eric Farman , Richard Henderson , Nina Schoetterl-Glausch , Heiko Carstens , Ilya Leoshkevich , Janosch Frank , "Michael S. Tsirkin" , Cornelia Huck , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v3 13/14] s390x/virtio-ccw: add support for virtio based memory devices Date: Thu, 19 Dec 2024 15:41:14 +0100 Message-ID: <20241219144115.2820241-14-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241219144115.2820241-1-david@redhat.com> References: <20241219144115.2820241-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 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 430a0f4f8c..afb1203597 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2376,6 +2376,9 @@ F: include/hw/virtio/virtio-crypto.h virtio based memory device M: David Hildenbrand S: Supported +F: hw/s390x/virtio-ccw-md.c +F: hw/s390x/virtio-ccw-md.h +F: hw/s390x/virtio-ccw-md-stubs.c F: hw/virtio/virtio-md-pci.c F: include/hw/virtio/virtio-md-pci.h F: stubs/virtio-md-pci.c diff --git a/hw/s390x/meson.build b/hw/s390x/meson.build index e344a3bd8c..4431868408 100644 --- a/hw/s390x/meson.build +++ b/hw/s390x/meson.build @@ -50,8 +50,11 @@ endif virtio_ss.add(when: 'CONFIG_VHOST_SCSI', if_true: files('vhost-scsi-ccw.c')) virtio_ss.add(when: 'CONFIG_VHOST_VSOCK', if_true: files('vhost-vsock-ccw.c')) virtio_ss.add(when: 'CONFIG_VHOST_USER_FS', if_true: files('vhost-user-fs-ccw.c')) +virtio_ss.add(when: 'CONFIG_VIRTIO_MD', if_true: files('virtio-ccw-md.c')) s390x_ss.add_all(when: 'CONFIG_VIRTIO_CCW', if_true: virtio_ss) +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 9f8d830798..097ec78826 100644 --- a/hw/s390x/s390-virtio-ccw.c +++ b/hw/s390x/s390-virtio-ccw.c @@ -46,6 +46,8 @@ #include "qapi/visitor.h" #include "hw/s390x/cpu-topology.h" #include "kvm/kvm_s390x.h" +#include "hw/virtio/virtio-md-pci.h" +#include "hw/s390x/virtio-ccw-md.h" #include CONFIG_DEVICES static Error *pv_mig_blocker; @@ -546,11 +548,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); } } @@ -560,9 +590,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) { @@ -609,7 +650,9 @@ static const CPUArchIdList *s390_possible_cpu_arch_ids(MachineState *ms) static HotplugHandler *s390_get_hotplug_handler(MachineState *machine, DeviceState *dev) { - if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) { + if (object_dynamic_cast(OBJECT(dev), TYPE_CPU) || + object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MD_CCW) || + object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MD_PCI)) { return HOTPLUG_HANDLER(machine); } return NULL; @@ -769,8 +812,10 @@ static void ccw_machine_class_init(ObjectClass *oc, 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 Thu Dec 19 14:41:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13915264 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 E5818E7718A for ; Thu, 19 Dec 2024 16:36:27 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tOJJj-0004Ou-Be; Thu, 19 Dec 2024 11:24:03 -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 1tOHix-0003Bh-Uq for qemu-devel@nongnu.org; Thu, 19 Dec 2024 09:42:00 -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 1tOHit-0002Qt-SF for qemu-devel@nongnu.org; Thu, 19 Dec 2024 09:41:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734619313; 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=0VpCBpco2/YBncqJ9NedwCNhvtTWVtYBreOca/WrjlI=; b=cSmixNEyrQyU19zZL6ba5at/2nN+Jta7Ki9+DiJcip+gw85XvpzENKBZqBZYftQt4cpoBD XjlyDXdf60QhlsYgXDulcrbqMyXfmP5HVuLWkGjwkcBjiKW2ErCXLh9dj2ncCq48T4Zoae HDyCcXbH6M2nkDuKBqHzOollr8Igw1I= 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-403-cioYOOLdM0uMc6T6ZDBzEQ-1; Thu, 19 Dec 2024 09:41:52 -0500 X-MC-Unique: cioYOOLdM0uMc6T6ZDBzEQ-1 X-Mimecast-MFC-AGG-ID: cioYOOLdM0uMc6T6ZDBzEQ Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-43651b1ba8aso7162925e9.1 for ; Thu, 19 Dec 2024 06:41:52 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734619311; x=1735224111; 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=0VpCBpco2/YBncqJ9NedwCNhvtTWVtYBreOca/WrjlI=; b=YxeCQCFc4E/Kg2oTrlHW9r9f2yEdNE2KCr+8y411vCw3XH13CKnReurLPjii9YV3Y4 vQ3TlA6Ns7tAxiQxZrbKvB7AIhUGTqRqZKdO1DXsM/OqWC3CV1sFgyNgwETym5ebpL7V x+Ru7nX2ZDutp9jSysLggI/ho7kwCWqlP/8uwaXuoIt8XgIMffIiKJNYKQb/J5FRJ9+9 7L8G5/LMyu1oSA+53GpMxaXDSF+tFYZ0hKDnpwgybM/O+ddpeVG06PvCBn4kGEqXuN3T cIF++E36JjdxISoN7Otwd9370jFfFjSSSoRiuhBkWsQqbgohyg7lY0wNQIkj+hat5HXC zoeQ== X-Gm-Message-State: AOJu0Ywd1nboi3Fcrv4uKJLNoofftwh7lf2HUSqi0m1wAfYjCEHdT9YU Q+Pv+JhXJUPaJjAKc7JeLTJp2jmJSKjSnjRuoAppUJZAFp/cfMKviwLja/K1nfKV6kd8ZDh8LTp jXpPXbUlYNcg5nMsk4oRMaxETGmA07FQYGp05UdIY7GaxCkZ3VBNxVYMdWht9YyOjdeTZ4wb3jc vJNXGXqiTzjLrVmiIkYjM02BwLhoNza7XTr2k= X-Gm-Gg: ASbGncsvVG89VFLsT/hZqUwXEkCWUxtITZi4uOWuzF2Q1elD3f3Om33Ww6O1gW0Li7W dLGqHjmfiByJ3ly9efx9ZZywCIJ4b3XLmK1wNszhe6tAZqWdrcyqJNSK5MD31Krpiy3mDg7gbXW geIaG3xlDg1zcG68lw+Uq5/bls65+ZQz2fI6EsRrSv7YHgHuB1GBW43xxQtxQ1RHb28ef00OCRL dvQXJllSfpSVdLN3zTuZk/9lp03tWNytR2JIMhrYKxWvAV5pYhiBFAXe4yjDPrH5SeSylorkcCu wNCJsxfWCQsgF/OqCSe8Y6Ca9vtA4C1zq/x+31z6 X-Received: by 2002:a05:600c:444b:b0:434:f9e1:5cf8 with SMTP id 5b1f17b1804b1-436553f64aamr76563095e9.31.1734619311212; Thu, 19 Dec 2024 06:41:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IFIXDcRIyEW6zNgkcdV8zzgRZlU540U4piszmWR8Wr54TrM91QEK1+HPTAuE63p5wX7szR1sw== X-Received: by 2002:a05:600c:444b:b0:434:f9e1:5cf8 with SMTP id 5b1f17b1804b1-436553f64aamr76562595e9.31.1734619310614; Thu, 19 Dec 2024 06:41:50 -0800 (PST) Received: from localhost (p200300cbc7496600b73a466ce6100686.dip0.t-ipconnect.de. [2003:cb:c749:6600:b73a:466c:e610:686]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-43661289d3dsm19732765e9.41.2024.12.19.06.41.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 19 Dec 2024 06:41:50 -0800 (PST) From: David Hildenbrand To: qemu-devel@nongnu.org Cc: David Hildenbrand , Paolo Bonzini , Thomas Huth , Halil Pasic , Christian Borntraeger , Eric Farman , Richard Henderson , Nina Schoetterl-Glausch , Heiko Carstens , Ilya Leoshkevich , Janosch Frank , "Michael S. Tsirkin" , Cornelia Huck , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v3 14/14] s390x: virtio-mem support Date: Thu, 19 Dec 2024 15:41:15 +0100 Message-ID: <20241219144115.2820241-15-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241219144115.2820241-1-david@redhat.com> References: <20241219144115.2820241-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 afb1203597..0b7605fbeb 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2390,6 +2390,8 @@ W: https://virtio-mem.gitlab.io/ F: hw/virtio/virtio-mem.c F: hw/virtio/virtio-mem-pci.h F: hw/virtio/virtio-mem-pci.c +F: hw/s390x/virtio-ccw-mem.c +F: hw/s390x/virtio-ccw-mem.h F: include/hw/virtio/virtio-mem.h virtio-snd diff --git a/hw/s390x/Kconfig b/hw/s390x/Kconfig index 82afdaa9dc..02ea199701 100644 --- a/hw/s390x/Kconfig +++ b/hw/s390x/Kconfig @@ -16,3 +16,4 @@ config S390_CCW_VIRTIO select SCLPCONSOLE select VIRTIO_CCW select MSI_NONBROKEN + select VIRTIO_MEM_SUPPORTED diff --git a/hw/s390x/meson.build b/hw/s390x/meson.build index 4431868408..3bbebfd817 100644 --- a/hw/s390x/meson.build +++ b/hw/s390x/meson.build @@ -51,6 +51,7 @@ virtio_ss.add(when: 'CONFIG_VHOST_SCSI', if_true: files('vhost-scsi-ccw.c')) virtio_ss.add(when: 'CONFIG_VHOST_VSOCK', if_true: files('vhost-vsock-ccw.c')) virtio_ss.add(when: 'CONFIG_VHOST_USER_FS', if_true: files('vhost-user-fs-ccw.c')) virtio_ss.add(when: 'CONFIG_VIRTIO_MD', if_true: files('virtio-ccw-md.c')) +virtio_ss.add(when: 'CONFIG_VIRTIO_MEM', if_true: files('virtio-ccw-mem.c')) s390x_ss.add_all(when: 'CONFIG_VIRTIO_CCW', if_true: virtio_ss) 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))