From nobody Sat Nov 23 21:40:13 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1728384955; cv=none; d=zohomail.com; s=zohoarc; b=FfgmNOyb8EZpBfUt37mESNaSy4TX7hkKwFpcYzOb2xRacgyWZIThb4PfSIMDzy2KF8In8BzSbMWKc6cVECuc2DLR4c9J5xMGtPEbM9oOphJOH9DjuiPTbdthRO6aurzwRNYgAqCebGDdh8TeC7PPBm9xUW5iAN/UyRSNMgbEOwI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728384955; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=UwCj+hgqyB9x40oN682O/EprONvoL/7W9oor1YYT55A=; b=KVy9XKCsrpCyl0cWP+9mlHvWdvTuGJO79YYnICJqaq/iDP7zXjsLEMXcBm7weVq9rK9oE/C+ndrAwj9zKfobFXHbmZKXVKkYjLQknfj+TpGfHL8z01c6wTxwXV6j+vrta0/gslNGqjRJ4Uqh7AudmulsOp651owrU4qN1ffm7wg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1728384955234382.1947658586562; Tue, 8 Oct 2024 03:55:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sy7s9-0001IZ-F6; Tue, 08 Oct 2024 06:55:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sy7s4-0001HV-9r for qemu-devel@nongnu.org; Tue, 08 Oct 2024 06:55:19 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sy7s2-0001d3-VL for qemu-devel@nongnu.org; Tue, 08 Oct 2024 06:55:16 -0400 Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-413-5wXBN5JRMy2_3UUA9sZW0w-1; Tue, 08 Oct 2024 06:55:10 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3EBC51955EAD; Tue, 8 Oct 2024 10:55:09 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.22.16.102]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7861619560A3; Tue, 8 Oct 2024 10:55:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728384913; 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=UwCj+hgqyB9x40oN682O/EprONvoL/7W9oor1YYT55A=; b=ZKTkPP+BK7JZX2+0I2KDtMoi/pdAQu5b5zn+wB0Azzhh1HX8VqVS8Jt688CLUIFIS2okkW +x0kUCVpVeNQHzfMLPy4bv+9Usus7kvuOG/GMKiqJ+J8mjIU5GTA4sbXorsTAcyLY1Rzv6 D/Zf7jeBzBbYYsG4y6iv38bs9sUtgB0= X-MC-Unique: 5wXBN5JRMy2_3UUA9sZW0w-1 From: David Hildenbrand To: qemu-devel@nongnu.org Cc: qemu-s390x@nongnu.org, 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 Subject: [PATCH v2 01/14] s390x/s390-virtio-ccw: don't crash on weird RAM sizes Date: Tue, 8 Oct 2024 12:54:42 +0200 Message-ID: <20241008105455.2302628-2-david@redhat.com> In-Reply-To: <20241008105455.2302628-1-david@redhat.com> References: <20241008105455.2302628-1-david@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=david@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.153, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1728384956523116600 Content-Type: text/plain; charset="utf-8" KVM is not happy when starting a VM with weird RAM sizes: # qemu-system-s390x --enable-kvm --nographic -m 1234K qemu-system-s390x: kvm_set_user_memory_region: KVM_SET_USER_MEMORY_REGION failed, slot=3D0, start=3D0x0, size=3D0x244000: Invalid argument kvm_set_phys_mem: error registering slot: Invalid argument Aborted (core dumped) Let's handle that in a better way by rejecting such weird RAM sizes right from the start: # qemu-system-s390x --enable-kvm --nographic -m 1234K qemu-system-s390x: ram size must be multiples of 1 MiB Acked-by: Michael S. Tsirkin Reviewed-by: Eric Farman Reviewed-by: Thomas Huth Acked-by: Janosch Frank Signed-off-by: David Hildenbrand Tested-by: Mario Casquero --- 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 5aa8d207a3..b88ec8e78a 100644 --- a/hw/s390x/s390-virtio-ccw.c +++ b/hw/s390x/s390-virtio-ccw.c @@ -180,6 +180,17 @@ static void s390_memory_init(MemoryRegion *ram) { MemoryRegion *sysmem =3D get_system_memory(); =20 + if (!QEMU_IS_ALIGNED(memory_region_size(ram), 1 * MiB)) { + /* + * SCLP cannot possibly expose smaller granularity right now and K= VM + * cannot handle smaller granularity. As we don't support NUMA, the + * region size directly corresponds to machine->ram_size, and the = region + * is a single RAM memory region. + */ + error_report("ram size must be multiples of 1 MiB"); + exit(EXIT_FAILURE); + } + /* allocate RAM for core */ memory_region_add_subregion(sysmem, 0, ram); =20 --=20 2.46.1 From nobody Sat Nov 23 21:40:13 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1728385058; cv=none; d=zohomail.com; s=zohoarc; b=EA89spyybXyrYMTsh1keZwd+wBMweY5wYqss4UUmXyO4JWDng5/Oong4YgzvwFzVXPU7IhuP1B3o+GBwKHnhB0loc0B5cdE96XaX8Tp9Ds1wOTU5Ax1JjLnSo22EGSU3s28IKnWC1JaCsuxJF2XZye/5XVSUGaIUqVlb5Ap8bFc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728385058; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=o/pTY+vlAFooYtwZrRszeFc2DO2xGGlWM/JfrMyYqlg=; b=P/4oUxShUF/u/EnyQgVsiNnac0FfGxw6IjY1cm+iAicY4D934Cd28p5SoOXZLOHENp48PWN3cz34QrLlS4Wdj6kNxY4gDuU6MruEmtH97VibcmUqjvzJPg9aEqJ/0SsJFHyErjmItSUqfT4TNcFaW+2mAYxxLMYtUPs9HLB7xDA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1728385058663494.812065875356; Tue, 8 Oct 2024 03:57:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sy7sD-0001Jc-JV; Tue, 08 Oct 2024 06:55:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sy7sB-0001Iq-71 for qemu-devel@nongnu.org; Tue, 08 Oct 2024 06:55:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sy7s8-0001du-B0 for qemu-devel@nongnu.org; Tue, 08 Oct 2024 06:55:22 -0400 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-49-ZPaKzdWqPN2u11M9uxyQrw-1; Tue, 08 Oct 2024 06:55:16 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 73B921955F43; Tue, 8 Oct 2024 10:55:14 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.22.16.102]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id BD3F719560A3; Tue, 8 Oct 2024 10:55:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728384919; 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=o/pTY+vlAFooYtwZrRszeFc2DO2xGGlWM/JfrMyYqlg=; b=FFLtxhsU58GQbLOTR96kpK96zhyQWCuB+BS83+5MowpxV91dNa4txp+1JkbSmkwMh9wV8Q uWw/lSAtwpxJR5RwEJVkk+OcUfsFu6EDScGR0HV/iKFBgFdWH/T4eXw5QawKBozzEqtuF4 h4+v0Uebxv9fV+/onzhMqnk2ptH9eJk= X-MC-Unique: ZPaKzdWqPN2u11M9uxyQrw-1 From: David Hildenbrand To: qemu-devel@nongnu.org Cc: qemu-s390x@nongnu.org, 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 Subject: [PATCH v2 02/14] s390x/s390-virtio-hcall: remove hypercall registration mechanism Date: Tue, 8 Oct 2024 12:54:43 +0200 Message-ID: <20241008105455.2302628-3-david@redhat.com> In-Reply-To: <20241008105455.2302628-1-david@redhat.com> References: <20241008105455.2302628-1-david@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=david@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.153, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1728385060792116600 Content-Type: text/plain; charset="utf-8" Nowadays, we only have a single machine type in QEMU, everything is based on virtio-ccw and the traditional virtio machine does no longer exist. No need to dynamically register diag500 handlers. Move the two existing handlers into s390-virtio-hcall.c. Acked-by: Michael S. Tsirkin Reviewed-by: Thomas Huth Acked-by: Christian Borntraeger Signed-off-by: David Hildenbrand Tested-by: Mario Casquero --- hw/s390x/s390-virtio-ccw.c | 58 -------------------------------- hw/s390x/s390-virtio-hcall.c | 65 +++++++++++++++++++++++++++--------- hw/s390x/s390-virtio-hcall.h | 2 -- 3 files changed, 49 insertions(+), 76 deletions(-) diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c index b88ec8e78a..77f5d22203 100644 --- a/hw/s390x/s390-virtio-ccw.c +++ b/hw/s390x/s390-virtio-ccw.c @@ -16,11 +16,8 @@ #include "exec/ram_addr.h" #include "exec/confidential-guest-support.h" #include "hw/boards.h" -#include "hw/s390x/s390-virtio-hcall.h" #include "hw/s390x/sclp.h" #include "hw/s390x/s390_flic.h" -#include "hw/s390x/ioinst.h" -#include "hw/s390x/css.h" #include "virtio-ccw.h" #include "qemu/config-file.h" #include "qemu/ctype.h" @@ -124,58 +121,6 @@ static void subsystem_reset(void) } } =20 -static int virtio_ccw_hcall_notify(const uint64_t *args) -{ - uint64_t subch_id =3D args[0]; - uint64_t data =3D args[1]; - SubchDev *sch; - VirtIODevice *vdev; - int cssid, ssid, schid, m; - uint16_t vq_idx =3D data; - - if (ioinst_disassemble_sch_ident(subch_id, &m, &cssid, &ssid, &schid))= { - return -EINVAL; - } - sch =3D css_find_subch(m, cssid, ssid, schid); - if (!sch || !css_subch_visible(sch)) { - return -EINVAL; - } - - vdev =3D virtio_ccw_get_vdev(sch); - if (vq_idx >=3D VIRTIO_QUEUE_MAX || !virtio_queue_get_num(vdev, vq_idx= )) { - return -EINVAL; - } - - if (virtio_vdev_has_feature(vdev, VIRTIO_F_NOTIFICATION_DATA)) { - virtio_queue_set_shadow_avail_idx(virtio_get_queue(vdev, vq_idx), - (data >> 16) & 0xFFFF); - } - - virtio_queue_notify(vdev, vq_idx); - return 0; -} - -static int virtio_ccw_hcall_early_printk(const uint64_t *args) -{ - uint64_t mem =3D args[0]; - MachineState *ms =3D MACHINE(qdev_get_machine()); - - if (mem < ms->ram_size) { - /* Early printk */ - return 0; - } - return -EINVAL; -} - -static void virtio_ccw_register_hcalls(void) -{ - s390_register_virtio_hypercall(KVM_S390_VIRTIO_CCW_NOTIFY, - virtio_ccw_hcall_notify); - /* Tolerate early printk. */ - s390_register_virtio_hypercall(KVM_S390_VIRTIO_NOTIFY, - virtio_ccw_hcall_early_printk); -} - static void s390_memory_init(MemoryRegion *ram) { MemoryRegion *sysmem =3D get_system_memory(); @@ -302,9 +247,6 @@ static void ccw_init(MachineState *machine) OBJECT(dev)); sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); =20 - /* register hypercalls */ - virtio_ccw_register_hcalls(); - s390_enable_css_support(s390_cpu_addr2state(0)); =20 ret =3D css_create_css_image(VIRTUAL_CSSID, true); diff --git a/hw/s390x/s390-virtio-hcall.c b/hw/s390x/s390-virtio-hcall.c index ec7cf8beb3..ca49e3cd22 100644 --- a/hw/s390x/s390-virtio-hcall.c +++ b/hw/s390x/s390-virtio-hcall.c @@ -11,31 +11,64 @@ =20 #include "qemu/osdep.h" #include "cpu.h" +#include "hw/boards.h" #include "hw/s390x/s390-virtio-hcall.h" +#include "hw/s390x/ioinst.h" +#include "hw/s390x/css.h" +#include "virtio-ccw.h" =20 -#define MAX_DIAG_SUBCODES 255 +static int handle_virtio_notify(uint64_t mem) +{ + MachineState *ms =3D MACHINE(qdev_get_machine()); =20 -static s390_virtio_fn s390_diag500_table[MAX_DIAG_SUBCODES]; + if (mem < ms->ram_size) { + /* Early printk */ + return 0; + } + return -EINVAL; +} =20 -void s390_register_virtio_hypercall(uint64_t code, s390_virtio_fn fn) +static int handle_virtio_ccw_notify(uint64_t subch_id, uint64_t data) { - assert(code < MAX_DIAG_SUBCODES); - assert(!s390_diag500_table[code]); + SubchDev *sch; + VirtIODevice *vdev; + int cssid, ssid, schid, m; + uint16_t vq_idx =3D data; + + if (ioinst_disassemble_sch_ident(subch_id, &m, &cssid, &ssid, &schid))= { + return -EINVAL; + } + sch =3D css_find_subch(m, cssid, ssid, schid); + if (!sch || !css_subch_visible(sch)) { + return -EINVAL; + } =20 - s390_diag500_table[code] =3D fn; + vdev =3D virtio_ccw_get_vdev(sch); + if (vq_idx >=3D VIRTIO_QUEUE_MAX || !virtio_queue_get_num(vdev, vq_idx= )) { + return -EINVAL; + } + + if (virtio_vdev_has_feature(vdev, VIRTIO_F_NOTIFICATION_DATA)) { + virtio_queue_set_shadow_avail_idx(virtio_get_queue(vdev, vq_idx), + (data >> 16) & 0xFFFF); + } + + virtio_queue_notify(vdev, vq_idx); + return 0; } =20 int s390_virtio_hypercall(CPUS390XState *env) { - s390_virtio_fn fn; - - if (env->regs[1] < MAX_DIAG_SUBCODES) { - fn =3D s390_diag500_table[env->regs[1]]; - if (fn) { - env->regs[2] =3D fn(&env->regs[2]); - return 0; - } - } + const uint64_t subcode =3D env->regs[1]; =20 - return -EINVAL; + switch (subcode) { + case KVM_S390_VIRTIO_NOTIFY: + env->regs[2] =3D handle_virtio_notify(env->regs[2]); + return 0; + case KVM_S390_VIRTIO_CCW_NOTIFY: + env->regs[2] =3D handle_virtio_ccw_notify(env->regs[2], env->regs[= 3]); + return 0; + default: + return -EINVAL; + } } diff --git a/hw/s390x/s390-virtio-hcall.h b/hw/s390x/s390-virtio-hcall.h index 3ae6d6ae3a..3d9fe147d2 100644 --- a/hw/s390x/s390-virtio-hcall.h +++ b/hw/s390x/s390-virtio-hcall.h @@ -18,8 +18,6 @@ /* The only thing that we need from the old kvm_virtio.h file */ #define KVM_S390_VIRTIO_NOTIFY 0 =20 -typedef int (*s390_virtio_fn)(const uint64_t *args); -void s390_register_virtio_hypercall(uint64_t code, s390_virtio_fn fn); int s390_virtio_hypercall(CPUS390XState *env); =20 #endif /* HW_S390_VIRTIO_HCALL_H */ --=20 2.46.1 From nobody Sat Nov 23 21:40:13 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1728384986; cv=none; d=zohomail.com; s=zohoarc; b=T5xX5v/tAOzMFTXjnThu14jy/kvy+Y0716Q3u5zlwZFn5LKZOwTr17hRul8HZ7+xUNyqGTisNl4tNhioTn1XS32tb7bA20X4F+caepeWD4xzj/MuuVDOduQ7yINder4CAzD+uYSVmtEvAqtLR7wA5d2oGgTwsm65+9cVImGcD8w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728384986; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=bGLHZLJ0QeoA7f+QassN2W0pfX21pfZ8EKxhyJsshKQ=; b=OWujn44QATLuzz3AGBxOtSjdhFvZP0T6uhqir403oN/iqArbl1wJSABlIwQ6Q1JSqQRpRxwXzJxvAxH6AYSD9M8Jps1kEwMwqXXmDlHrxzIXkebZ6MH8Orshme/jUKtcO2/isl17I4xKjZ4tD/yJW9wro9YC7Mq/zHlM430bvE4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1728384986170637.874029870283; Tue, 8 Oct 2024 03:56:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sy7sG-0001LA-Uh; Tue, 08 Oct 2024 06:55:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sy7sF-0001KL-7i for qemu-devel@nongnu.org; Tue, 08 Oct 2024 06:55:27 -0400 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 1sy7sD-0001eZ-Lo for qemu-devel@nongnu.org; Tue, 08 Oct 2024 06:55:26 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-590-1bK25XIcMiygiwXEnpfAMw-1; Tue, 08 Oct 2024 06:55:21 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1C2E81955F29; Tue, 8 Oct 2024 10:55:20 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.22.16.102]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0F11B19560A3; Tue, 8 Oct 2024 10:55:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728384925; 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=bGLHZLJ0QeoA7f+QassN2W0pfX21pfZ8EKxhyJsshKQ=; b=RZWOhGDjI808jXliSO93qH0aLW6oEbUQ8UXSZNN7xcZOYyISng9HiyqaWcw9MVmAGK+3km r2BkCZZLtZe07jCVTrPbgzOUvYlt7tEx//AiLOs8SSrPWqM3YRhq2pW3+1OnIDjiIAfWgL ZisqUcC/EMNoBNFzEEz/OplNfYMw70c= X-MC-Unique: 1bK25XIcMiygiwXEnpfAMw-1 From: David Hildenbrand To: qemu-devel@nongnu.org Cc: qemu-s390x@nongnu.org, 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 Subject: [PATCH v2 03/14] s390x/s390-virtio-hcall: prepare for more diag500 hypercalls Date: Tue, 8 Oct 2024 12:54:44 +0200 Message-ID: <20241008105455.2302628-4-david@redhat.com> In-Reply-To: <20241008105455.2302628-1-david@redhat.com> References: <20241008105455.2302628-1-david@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=david@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.153, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1728384986455116600 Content-Type: text/plain; charset="utf-8" Let's generalize, abstracting the virtio bits. diag500 is now a generic hypercall to handle QEMU/KVM specific things. Explicitly specify all already defined subcodes, including legacy ones (so we know what we can use for new hypercalls). Move the PGM_SPECIFICATION injection into the renamed function handle_diag_500(), so we can turn it into a void function. We'll rename the files separately, so git properly detects the rename. Acked-by: Michael S. Tsirkin Reviewed-by: Thomas Huth Signed-off-by: David Hildenbrand Tested-by: Mario Casquero --- hw/s390x/s390-virtio-hcall.c | 15 ++++++++------- hw/s390x/s390-virtio-hcall.h | 11 ++++++----- target/s390x/kvm/kvm.c | 16 +--------------- target/s390x/tcg/misc_helper.c | 5 +++-- 4 files changed, 18 insertions(+), 29 deletions(-) diff --git a/hw/s390x/s390-virtio-hcall.c b/hw/s390x/s390-virtio-hcall.c index ca49e3cd22..5fb78a719e 100644 --- a/hw/s390x/s390-virtio-hcall.c +++ b/hw/s390x/s390-virtio-hcall.c @@ -1,5 +1,5 @@ /* - * Support for virtio hypercalls on s390 + * Support for QEMU/KVM hypercalls on s390 * * Copyright 2012 IBM Corp. * Author(s): Cornelia Huck @@ -57,18 +57,19 @@ static int handle_virtio_ccw_notify(uint64_t subch_id, = uint64_t data) return 0; } =20 -int s390_virtio_hypercall(CPUS390XState *env) +void handle_diag_500(S390CPU *cpu, uintptr_t ra) { + CPUS390XState *env =3D &cpu->env; const uint64_t subcode =3D env->regs[1]; =20 switch (subcode) { - case KVM_S390_VIRTIO_NOTIFY: + case DIAG500_VIRTIO_NOTIFY: env->regs[2] =3D handle_virtio_notify(env->regs[2]); - return 0; - case KVM_S390_VIRTIO_CCW_NOTIFY: + break; + case DIAG500_VIRTIO_CCW_NOTIFY: env->regs[2] =3D handle_virtio_ccw_notify(env->regs[2], env->regs[= 3]); - return 0; + break; default: - return -EINVAL; + s390_program_interrupt(env, PGM_SPECIFICATION, ra); } } diff --git a/hw/s390x/s390-virtio-hcall.h b/hw/s390x/s390-virtio-hcall.h index 3d9fe147d2..dca456b926 100644 --- a/hw/s390x/s390-virtio-hcall.h +++ b/hw/s390x/s390-virtio-hcall.h @@ -1,5 +1,5 @@ /* - * Support for virtio hypercalls on s390x + * Support for QEMU/KVM hypercalls on s390x * * Copyright IBM Corp. 2012, 2017 * Author(s): Cornelia Huck @@ -12,12 +12,13 @@ #ifndef HW_S390_VIRTIO_HCALL_H #define HW_S390_VIRTIO_HCALL_H =20 -#include "standard-headers/asm-s390/virtio-ccw.h" #include "cpu.h" =20 -/* The only thing that we need from the old kvm_virtio.h file */ -#define KVM_S390_VIRTIO_NOTIFY 0 +#define DIAG500_VIRTIO_NOTIFY 0 /* legacy, implemented as a NOP = */ +#define DIAG500_VIRTIO_RESET 1 /* legacy */ +#define DIAG500_VIRTIO_SET_STATUS 2 /* legacy */ +#define DIAG500_VIRTIO_CCW_NOTIFY 3 /* KVM_S390_VIRTIO_CCW_NOTIFY */ =20 -int s390_virtio_hypercall(CPUS390XState *env); +void handle_diag_500(S390CPU *cpu, uintptr_t ra); =20 #endif /* HW_S390_VIRTIO_HCALL_H */ diff --git a/target/s390x/kvm/kvm.c b/target/s390x/kvm/kvm.c index 8ffe0159d8..a8cbc0e2eb 100644 --- a/target/s390x/kvm/kvm.c +++ b/target/s390x/kvm/kvm.c @@ -1491,20 +1491,6 @@ static int handle_e3(S390CPU *cpu, struct kvm_run *r= un, uint8_t ipbl) return r; } =20 -static int handle_hypercall(S390CPU *cpu, struct kvm_run *run) -{ - CPUS390XState *env =3D &cpu->env; - int ret; - - ret =3D s390_virtio_hypercall(env); - if (ret =3D=3D -EINVAL) { - kvm_s390_program_interrupt(cpu, PGM_SPECIFICATION); - return 0; - } - - return ret; -} - static void kvm_handle_diag_288(S390CPU *cpu, struct kvm_run *run) { uint64_t r1, r3; @@ -1601,7 +1587,7 @@ static int handle_diag(S390CPU *cpu, struct kvm_run *= run, uint32_t ipb) handle_diag_318(cpu, run); break; case DIAG_KVM_HYPERCALL: - r =3D handle_hypercall(cpu, run); + handle_diag_500(cpu, RA_IGNORED); break; case DIAG_KVM_BREAKPOINT: r =3D handle_sw_breakpoint(cpu, run); diff --git a/target/s390x/tcg/misc_helper.c b/target/s390x/tcg/misc_helper.c index 303f86d363..0ab2bf36cf 100644 --- a/target/s390x/tcg/misc_helper.c +++ b/target/s390x/tcg/misc_helper.c @@ -117,10 +117,11 @@ void HELPER(diag)(CPUS390XState *env, uint32_t r1, ui= nt32_t r3, uint32_t num) =20 switch (num) { case 0x500: - /* KVM hypercall */ + /* QEMU/KVM hypercall */ bql_lock(); - r =3D s390_virtio_hypercall(env); + handle_diag_500(env_archcpu(env), GETPC()); bql_unlock(); + r =3D 0; break; case 0x44: /* yield */ --=20 2.46.1 From nobody Sat Nov 23 21:40:13 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1728384982; cv=none; d=zohomail.com; s=zohoarc; b=V+DfKPxtAzCmu0mlYq7SBg+wrw1EEwtVSuZ/owx600Fzi9p0vH6kOl0UEI2hysnz3rX7wvEGaPKOuI4Ds7yNWjggtizQffLHi8vkYzdHd5oWVfviAB9qZD92Z4js9OGHS9TFOt4SjZ0rZPuj1c42TbUqmWGcT0GwmzKignF1J98= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728384982; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=jtLJqklyQa2GF3ENhOHyU716km6/Ea5m6EVGzUWX/BE=; b=R4038M3aBeL6yboy58VTU5mJBx6ErFeb1IGIcAv79IOnvLzsIaJ3TV61ysNVwDl/aS5flEXpRzdu4I0kaDsqEYp04gJDVQ+PFu7ti/F+X/PcowFkKluUHLNTiF2zIFEPCU3gR0ieQArrRLbMdRbYAozoF3LdYCwZGT17nHrvLRw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1728384982862760.839214231544; Tue, 8 Oct 2024 03:56:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sy7sM-0001OT-HI; Tue, 08 Oct 2024 06:55:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sy7sL-0001NB-6r for qemu-devel@nongnu.org; Tue, 08 Oct 2024 06:55:33 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sy7sJ-0001fA-G5 for qemu-devel@nongnu.org; Tue, 08 Oct 2024 06:55:32 -0400 Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-551-2NI1YwAoOqWNWgK11Rp3Lg-1; Tue, 08 Oct 2024 06:55:27 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id CD7191955E80; Tue, 8 Oct 2024 10:55:25 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.22.16.102]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id AAB6F19560A3; Tue, 8 Oct 2024 10:55:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728384930; 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=jtLJqklyQa2GF3ENhOHyU716km6/Ea5m6EVGzUWX/BE=; b=b7t2J+2dRfof9s+CnNqaS2Iyyp6fQt7s/aQY2WiwiBmRTePYI35KhdnIFEn/IQ26Pkz09d xrO3gnkXDGVmor6aO1v4kKXOD86HmpQKd2PcwgrQoAwsdJa5+aNMqapX3v+VEIELgMrit/ Wn9WPIQmtAc3inpN5VXKoVGIj4kPcWM= X-MC-Unique: 2NI1YwAoOqWNWgK11Rp3Lg-1 From: David Hildenbrand To: qemu-devel@nongnu.org Cc: qemu-s390x@nongnu.org, 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 Subject: [PATCH v2 04/14] s390x: rename s390-virtio-hcall* to s390-hypercall* Date: Tue, 8 Oct 2024 12:54:45 +0200 Message-ID: <20241008105455.2302628-5-david@redhat.com> In-Reply-To: <20241008105455.2302628-1-david@redhat.com> References: <20241008105455.2302628-1-david@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=david@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.153, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1728384984449116600 Content-Type: text/plain; charset="utf-8" Let's make it clearer that we are talking about general QEMU/KVM-specific hypercalls. Acked-by: Michael S. Tsirkin Reviewed-by: Thomas Huth Signed-off-by: David Hildenbrand Tested-by: Mario Casquero --- hw/s390x/meson.build | 2 +- hw/s390x/{s390-virtio-hcall.c =3D> s390-hypercall.c} | 2 +- hw/s390x/{s390-virtio-hcall.h =3D> s390-hypercall.h} | 6 +++--- target/s390x/kvm/kvm.c | 2 +- target/s390x/tcg/misc_helper.c | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) rename hw/s390x/{s390-virtio-hcall.c =3D> s390-hypercall.c} (97%) rename hw/s390x/{s390-virtio-hcall.h =3D> s390-hypercall.h} (86%) diff --git a/hw/s390x/meson.build b/hw/s390x/meson.build index 482fd13420..71ec747f4c 100644 --- a/hw/s390x/meson.build +++ b/hw/s390x/meson.build @@ -12,7 +12,7 @@ s390x_ss.add(files( 's390-pci-inst.c', 's390-skeys.c', 's390-stattrib.c', - 's390-virtio-hcall.c', + 's390-hypercall.c', 'sclp.c', 'sclpcpu.c', 'sclpquiesce.c', diff --git a/hw/s390x/s390-virtio-hcall.c b/hw/s390x/s390-hypercall.c similarity index 97% rename from hw/s390x/s390-virtio-hcall.c rename to hw/s390x/s390-hypercall.c index 5fb78a719e..f816c2b1ef 100644 --- a/hw/s390x/s390-virtio-hcall.c +++ b/hw/s390x/s390-hypercall.c @@ -12,7 +12,7 @@ #include "qemu/osdep.h" #include "cpu.h" #include "hw/boards.h" -#include "hw/s390x/s390-virtio-hcall.h" +#include "hw/s390x/s390-hypercall.h" #include "hw/s390x/ioinst.h" #include "hw/s390x/css.h" #include "virtio-ccw.h" diff --git a/hw/s390x/s390-virtio-hcall.h b/hw/s390x/s390-hypercall.h similarity index 86% rename from hw/s390x/s390-virtio-hcall.h rename to hw/s390x/s390-hypercall.h index dca456b926..2fa81dbfdd 100644 --- a/hw/s390x/s390-virtio-hcall.h +++ b/hw/s390x/s390-hypercall.h @@ -9,8 +9,8 @@ * directory. */ =20 -#ifndef HW_S390_VIRTIO_HCALL_H -#define HW_S390_VIRTIO_HCALL_H +#ifndef HW_S390_HYPERCALL_H +#define HW_S390_HYPERCALL_H =20 #include "cpu.h" =20 @@ -21,4 +21,4 @@ =20 void handle_diag_500(S390CPU *cpu, uintptr_t ra); =20 -#endif /* HW_S390_VIRTIO_HCALL_H */ +#endif /* HW_S390_HYPERCALL_H */ diff --git a/target/s390x/kvm/kvm.c b/target/s390x/kvm/kvm.c index a8cbc0e2eb..734d2b9b78 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" =20 #define kvm_vm_check_mem_attr(s, attr) \ diff --git a/target/s390x/tcg/misc_helper.c b/target/s390x/tcg/misc_helper.c index 0ab2bf36cf..3732d79185 100644 --- a/target/s390x/tcg/misc_helper.c +++ b/target/s390x/tcg/misc_helper.c @@ -36,7 +36,7 @@ #include "sysemu/cpus.h" #include "sysemu/sysemu.h" #include "hw/s390x/ebcdic.h" -#include "hw/s390x/s390-virtio-hcall.h" +#include "hw/s390x/s390-hypercall.h" #include "hw/s390x/sclp.h" #include "hw/s390x/s390_flic.h" #include "hw/s390x/ioinst.h" --=20 2.46.1 From nobody Sat Nov 23 21:40:13 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1728384998; cv=none; d=zohomail.com; s=zohoarc; b=GoRVs4fEkvhIIxaNDIwTFC9bbmxQR83ZuOvGRh+7ru3uS5B8BowimUQtrd4IPxzbUqsY3T+5fj9UB7GJ53WnGho+03SxQNgT4OLle1qIDGi1bVychcHlG+n420bPusZXi1BE/uC4bZvm8ziGw6Q9NsrZEocgLTl2hSwFjBupJOU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728384998; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=7nbvv/EzKjF6TygpGepePY6Bd6hGXC8yUwfGazr6G6c=; b=FSpcMysUT3HNd1xhp/iyhx7u3Xt5CPuvcPXPz5DwQaD19nDLW6L1PbpCcEe1SDBXjrJMaFhcM7n+uyEbM5sdjX16AboDUdeFpHjJpwMJd2oJLoI74ovfRzpSQ/mXz6Ix3IKfNDYU0XKjGgEFe1MJxNM6aLXBa9uXr6TdFDM2Smk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1728384998086702.4221547311072; Tue, 8 Oct 2024 03:56:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sy7ss-0001WZ-Ky; Tue, 08 Oct 2024 06:56:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sy7sT-0001Qa-Os for qemu-devel@nongnu.org; Tue, 08 Oct 2024 06:55:42 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sy7sM-0001fZ-9o for qemu-devel@nongnu.org; Tue, 08 Oct 2024 06:55:39 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-173-by4KUbElNHyN5e_QT2IEWw-1; Tue, 08 Oct 2024 06:55:32 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D105A1956064; Tue, 8 Oct 2024 10:55:30 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.22.16.102]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4860F19560A3; Tue, 8 Oct 2024 10:55:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728384933; 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=7nbvv/EzKjF6TygpGepePY6Bd6hGXC8yUwfGazr6G6c=; b=cvQ+W6haue1y5sTwpeRm5mOgzjayEJLEwEBeVMHPIuphe1kenK2Ha4D3yO3FRf2kHf2Rt+ Hg4W6vgEUx4Y1Jp/qQK/watVYNyL4YfYPu4QJLF5wtl8UyzgEzjE53MGv+cbxxfu3V/tHS IQ3fcDIIo8ADmJayOn4JWcJ4hvz/e8E= X-MC-Unique: by4KUbElNHyN5e_QT2IEWw-1 From: David Hildenbrand To: qemu-devel@nongnu.org Cc: qemu-s390x@nongnu.org, 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 Subject: [PATCH v2 05/14] s390x/s390-virtio-ccw: move setting the maximum guest size from sclp to machine code Date: Tue, 8 Oct 2024 12:54:46 +0200 Message-ID: <20241008105455.2302628-6-david@redhat.com> In-Reply-To: <20241008105455.2302628-1-david@redhat.com> References: <20241008105455.2302628-1-david@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=david@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.153, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1728384998936116600 Content-Type: text/plain; charset="utf-8" Nowadays, it feels more natural to have that code located in s390_memory_init(), where we also have direct access to the machine object. While at it, use the actual RAM size, not the maximum RAM size which cannot currently be reached without support for any memory devices. Consequently update s390_pv_vm_try_disable_async() to rely on the RAM size as well, to avoid temporary issues while we further rework that handling. set_memory_limit() is temporary, we'll merge it with s390_set_memory_limit() next. Acked-by: Michael S. Tsirkin Reviewed-by: Thomas Huth Signed-off-by: David Hildenbrand Tested-by: Mario Casquero --- 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 77f5d22203..f4c4433b23 100644 --- a/hw/s390x/s390-virtio-ccw.c +++ b/hw/s390x/s390-virtio-ccw.c @@ -121,11 +121,29 @@ static void subsystem_reset(void) } } =20 -static void s390_memory_init(MemoryRegion *ram) +static void set_memory_limit(uint64_t new_limit) +{ + uint64_t hw_limit; + int ret; + + ret =3D s390_set_memory_limit(new_limit, &hw_limit); + if (ret =3D=3D -E2BIG) { + error_report("host supports a maximum of %" PRIu64 " GB", + hw_limit / GiB); + exit(EXIT_FAILURE); + } else if (ret) { + error_report("setting the guest size failed"); + exit(EXIT_FAILURE); + } +} + +static void s390_memory_init(MachineState *machine) { MemoryRegion *sysmem =3D get_system_memory(); + MemoryRegion *ram =3D machine->ram; + uint64_t ram_size =3D memory_region_size(ram); =20 - if (!QEMU_IS_ALIGNED(memory_region_size(ram), 1 * MiB)) { + if (!QEMU_IS_ALIGNED(ram_size, 1 * MiB)) { /* * SCLP cannot possibly expose smaller granularity right now and K= VM * cannot handle smaller granularity. As we don't support NUMA, the @@ -136,7 +154,9 @@ static void s390_memory_init(MemoryRegion *ram) exit(EXIT_FAILURE); } =20 - /* allocate RAM for core */ + set_memory_limit(ram_size); + + /* Map the initial memory. Must happen after setting the memory limit.= */ memory_region_add_subregion(sysmem, 0, ram); =20 /* @@ -217,7 +237,7 @@ static void ccw_init(MachineState *machine) qdev_realize_and_unref(DEVICE(ms->sclp), NULL, &error_fatal); =20 /* init memory + setup max page size. Required for the CPU model */ - s390_memory_init(machine->ram); + s390_memory_init(machine); =20 /* init CPUs (incl. CPU model) early so s390_has_feature() works */ s390_init_cpus(machine); diff --git a/hw/s390x/sclp.c b/hw/s390x/sclp.c index e725dcd5fd..fac09816bf 100644 --- a/hw/s390x/sclp.c +++ b/hw/s390x/sclp.c @@ -381,10 +381,7 @@ void sclp_service_interrupt(uint32_t sccb) /* qemu object creation and initialization functions */ static void sclp_realize(DeviceState *dev, Error **errp) { - MachineState *machine =3D MACHINE(qdev_get_machine()); SCLPDevice *sclp =3D SCLP(dev); - uint64_t hw_limit; - int ret; =20 /* * qdev_device_add searches the sysbus for TYPE_SCLP_EVENTS_BUS. As lo= ng @@ -394,14 +391,6 @@ static void sclp_realize(DeviceState *dev, Error **err= p) if (!sysbus_realize(SYS_BUS_DEVICE(sclp->event_facility), errp)) { return; } - - ret =3D s390_set_memory_limit(machine->maxram_size, &hw_limit); - if (ret =3D=3D -E2BIG) { - error_setg(errp, "host supports a maximum of %" PRIu64 " GB", - hw_limit / GiB); - } else if (ret) { - error_setg(errp, "setting the guest size failed"); - } } =20 static void sclp_memory_init(SCLPDevice *sclp) diff --git a/target/s390x/kvm/pv.c b/target/s390x/kvm/pv.c index dde836d21a..424cce75ca 100644 --- a/target/s390x/kvm/pv.c +++ b/target/s390x/kvm/pv.c @@ -133,7 +133,7 @@ bool s390_pv_vm_try_disable_async(S390CcwMachineState *= ms) * If the feature is not present or if the VM is not larger than 2 GiB, * KVM_PV_ASYNC_CLEANUP_PREPARE fill fail; no point in attempting it. */ - if ((MACHINE(ms)->maxram_size <=3D 2 * GiB) || + if ((MACHINE(ms)->ram_size <=3D 2 * GiB) || !kvm_check_extension(kvm_state, KVM_CAP_S390_PROTECTED_ASYNC_DISAB= LE)) { return false; } --=20 2.46.1 From nobody Sat Nov 23 21:40:13 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1728385009; cv=none; d=zohomail.com; s=zohoarc; b=Vk+HbVEG4rEg/OqwpXNHuYPYxXFXBmnuXrKf8fMCcSmuMJpUS0e1yhN5JEmHPHbzYmlxwWdz+Db7aJ56MZp7HTEOia8BklXgLKe6YF3JrSls4F2UEMODas+MNkSYguEjgWUvERJyKXAmGEYxHQV9uafl9Fllv1PfYCNViMz/a5Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728385009; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=7cnFX49gGE3YJQwNcOJpdqmqR2DbawMaGFlaZXXGIP0=; b=WnR0wfJl/bD6cpgZqkPrjrXd/vSV4HeIlpec9osdPCeN3iRdLkVd2IAwESP5TNKZs6ZQWoklqs6XHxheHpNI4JapuMciHAugsLsFeYNqAxSPjfTCPab/O2FiRiLa38sojQDG5uOyii6bBMNK/i+qSsTdWBySKVNjdxyXoVxiCWw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1728385009118986.5695650965116; Tue, 8 Oct 2024 03:56:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sy7tO-0002Dn-S2; Tue, 08 Oct 2024 06:56:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sy7sa-0001RI-Ho for qemu-devel@nongnu.org; Tue, 08 Oct 2024 06:55:55 -0400 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 1sy7sW-0001gM-K9 for qemu-devel@nongnu.org; Tue, 08 Oct 2024 06:55:47 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-156-3ETxc9L9PHWXGLYLMmR3bQ-1; Tue, 08 Oct 2024 06:55:38 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9A8D119560A2; Tue, 8 Oct 2024 10:55:36 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.22.16.102]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 6CD3B19560A3; Tue, 8 Oct 2024 10:55:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728384942; 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=7cnFX49gGE3YJQwNcOJpdqmqR2DbawMaGFlaZXXGIP0=; b=aZnP0QXqlmWAXQa/6cKqNyIBdq5BEqztx+eXk69mkweXdU/Ucw4Vp5/kXe7ys028NRksHa qsUJrC7ZfQZMf58BEdRf6G/qDfyE+BV41uZIQsrUnlveLhew6H9YkYlSC04+hhXhUyxiAl 6FianA8YW3Jmv815rFvQu1DGYdTYPkQ= X-MC-Unique: 3ETxc9L9PHWXGLYLMmR3bQ-1 From: David Hildenbrand To: qemu-devel@nongnu.org Cc: qemu-s390x@nongnu.org, 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 Subject: [PATCH v2 06/14] s390x: introduce s390_get_memory_limit() Date: Tue, 8 Oct 2024 12:54:47 +0200 Message-ID: <20241008105455.2302628-7-david@redhat.com> In-Reply-To: <20241008105455.2302628-1-david@redhat.com> References: <20241008105455.2302628-1-david@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=david@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.153, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1728385010577116600 Content-Type: text/plain; charset="utf-8" Let's add s390_get_memory_limit(), to query what has been successfully set via s390_set_memory_limit(). Allow setting the limit only once. We'll remember the limit in the machine state. Move s390_set_memory_limit() to machine code, merging it into set_memory_limit(), because this really is a machine property. Acked-by: Michael S. Tsirkin Signed-off-by: David Hildenbrand Reviewed-by: Thomas Huth Tested-by: Mario Casquero --- hw/s390x/s390-virtio-ccw.c | 22 ++++++++++++++++++---- include/hw/s390x/s390-virtio-ccw.h | 3 +++ target/s390x/cpu-sysemu.c | 8 -------- target/s390x/cpu.h | 1 - 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c index f4c4433b23..749d46e700 100644 --- a/hw/s390x/s390-virtio-ccw.c +++ b/hw/s390x/s390-virtio-ccw.c @@ -45,6 +45,7 @@ #include "migration/blocker.h" #include "qapi/visitor.h" #include "hw/s390x/cpu-topology.h" +#include "kvm/kvm_s390x.h" #include CONFIG_DEVICES =20 static Error *pv_mig_blocker; @@ -121,12 +122,16 @@ static void subsystem_reset(void) } } =20 -static void set_memory_limit(uint64_t new_limit) +static void s390_set_memory_limit(S390CcwMachineState *s390ms, + uint64_t new_limit) { uint64_t hw_limit; - int ret; + int ret =3D 0; =20 - ret =3D s390_set_memory_limit(new_limit, &hw_limit); + assert(!s390ms->memory_limit && new_limit); + if (kvm_enabled()) { + ret =3D kvm_s390_set_mem_limit(new_limit, &hw_limit); + } if (ret =3D=3D -E2BIG) { error_report("host supports a maximum of %" PRIu64 " GB", hw_limit / GiB); @@ -135,10 +140,19 @@ static void set_memory_limit(uint64_t new_limit) error_report("setting the guest size failed"); exit(EXIT_FAILURE); } + s390ms->memory_limit =3D new_limit; +} + +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; } =20 static void s390_memory_init(MachineState *machine) { + S390CcwMachineState *s390ms =3D S390_CCW_MACHINE(machine); MemoryRegion *sysmem =3D get_system_memory(); MemoryRegion *ram =3D machine->ram; uint64_t ram_size =3D memory_region_size(ram); @@ -154,7 +168,7 @@ static void s390_memory_init(MachineState *machine) exit(EXIT_FAILURE); } =20 - set_memory_limit(ram_size); + s390_set_memory_limit(s390ms, ram_size); =20 /* Map the initial memory. Must happen after setting the memory limit.= */ memory_region_add_subregion(sysmem, 0, ram); diff --git a/include/hw/s390x/s390-virtio-ccw.h b/include/hw/s390x/s390-vir= tio-ccw.h index 996864a34e..eb04542979 100644 --- a/include/hw/s390x/s390-virtio-ccw.h +++ b/include/hw/s390x/s390-virtio-ccw.h @@ -29,10 +29,13 @@ struct S390CcwMachineState { bool dea_key_wrap; bool pv; uint8_t loadparm[8]; + uint64_t memory_limit; =20 SCLPDevice *sclp; }; =20 +uint64_t s390_get_memory_limit(S390CcwMachineState *s390ms); + #define S390_PTF_REASON_NONE (0x00 << 8) #define S390_PTF_REASON_DONE (0x01 << 8) #define S390_PTF_REASON_BUSY (0x02 << 8) diff --git a/target/s390x/cpu-sysemu.c b/target/s390x/cpu-sysemu.c index 1cd30c1d84..3118a25fee 100644 --- a/target/s390x/cpu-sysemu.c +++ b/target/s390x/cpu-sysemu.c @@ -255,14 +255,6 @@ unsigned int s390_cpu_set_state(uint8_t cpu_state, S39= 0CPU *cpu) return s390_count_running_cpus(); } =20 -int s390_set_memory_limit(uint64_t new_limit, uint64_t *hw_limit) -{ - if (kvm_enabled()) { - return kvm_s390_set_mem_limit(new_limit, hw_limit); - } - return 0; -} - void s390_set_max_pagesize(uint64_t pagesize, Error **errp) { if (kvm_enabled()) { diff --git a/target/s390x/cpu.h b/target/s390x/cpu.h index 5ef61b1f75..b4506539f0 100644 --- a/target/s390x/cpu.h +++ b/target/s390x/cpu.h @@ -881,7 +881,6 @@ static inline void s390_do_cpu_load_normal(CPUState *cs= , run_on_cpu_data arg) =20 /* cpu.c */ void s390_crypto_reset(void); -int s390_set_memory_limit(uint64_t new_limit, uint64_t *hw_limit); void s390_set_max_pagesize(uint64_t pagesize, Error **errp); void s390_cmma_reset(void); void s390_enable_css_support(S390CPU *cpu); --=20 2.46.1 From nobody Sat Nov 23 21:40:13 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1728385019; cv=none; d=zohomail.com; s=zohoarc; b=RGpE6n6Jo41LOzz8XLScNiuXD9cYtQT/0L0tkbHA4O4iJjL9iU+Lo2sJxvg1hmX3LKJzQ2huOQ08L/Bh8f3+xkXBxdW1mJFoHjpQyG3VRGzJ7njOIvQCizubghFB2QW83FM2YV8LQyH2gr4PnCEfHcRZxIHQR6A3i2hFch6GZ+s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728385019; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=M7QMvTsPftoKG+QTqsTw1mgotPDejidgbpsMvywl6gM=; b=Ac+0EDuiBaMiMAT5OzhcrHZ/JIKhW0zkZVQuLBnA4ZWWrFqS2ANRlCZiuVubV2z4vpZI0rHfbDitQFMeRRjEX6ddbwan3FxZPloA2BVm+P9qcyEJzF3pO9tMUE5wHjhZ834YJi+yE4NkPxRYa7GOum3KdSffG+rcSwjrPGG7DIM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1728385019430674.78553499335; Tue, 8 Oct 2024 03:56:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sy7tG-0001qV-2S; Tue, 08 Oct 2024 06:56:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sy7sm-0001Vo-3x for qemu-devel@nongnu.org; Tue, 08 Oct 2024 06:56:04 -0400 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 1sy7sh-0001hI-TK for qemu-devel@nongnu.org; Tue, 08 Oct 2024 06:55:58 -0400 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-132-12eYDCRINIiWdanpch7QWQ-1; Tue, 08 Oct 2024 06:55:43 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 368721955BC6; Tue, 8 Oct 2024 10:55:42 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.22.16.102]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 12D4C19560A3; Tue, 8 Oct 2024 10:55:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728384949; 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=M7QMvTsPftoKG+QTqsTw1mgotPDejidgbpsMvywl6gM=; b=YnPdVE5N5bvWbPESaH3l0Mj3+TtfFazkBn9T/KXD2c3Q1SO8P89OJmcxk3irsfjY5v4VFk csGVIGrgrwXpFsIFzVASit0TATQgdfkLHCvDY1Q7F3zxBEpUcRj0dSjEM8d8AoLk1ayF1t HftGED7bqvIL85/3+YEB09DOMYEWzf8= X-MC-Unique: 12eYDCRINIiWdanpch7QWQ-1 From: David Hildenbrand To: qemu-devel@nongnu.org Cc: qemu-s390x@nongnu.org, 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 Subject: [PATCH v2 07/14] s390x/s390-hypercall: introduce DIAG500 STORAGE_LIMIT Date: Tue, 8 Oct 2024 12:54:48 +0200 Message-ID: <20241008105455.2302628-8-david@redhat.com> In-Reply-To: <20241008105455.2302628-1-david@redhat.com> References: <20241008105455.2302628-1-david@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=david@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.153, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1728385020632116600 Content-Type: text/plain; charset="utf-8" A guest OS that supports memory hotplug / memory devices must during boot be aware of the maximum possible physical memory address that it might have to handle at a later stage during its runtime. For example, the maximum possible memory address might be required to prepare the kernel virtual address space accordingly (e.g., select page table hierarchy depth). On s390x there is currently no such mechanism that is compatible with paravirtualized memory devices, because the whole SCLP interface was designed around the idea of "storage increments" and "standby memory". Paravirtualized memory devices we want to support, such as virtio-mem, have no intersection with any of that, but could co-exist with them in the future if ever needed. In particular, a guest OS must never detect and use device memory without the help of a proper device driver. Device memory must not be exposed in any firmware-provided memory map (SCLP or diag260 on s390x). For this reason, these memory devices will be places in memory *above* the "maximum storage increment" exposed via SCLP. Let's provide a new diag500 subcode to query the memory limit determined in s390_memory_init(). Acked-by: Michael S. Tsirkin Reviewed-by: Thomas Huth Signed-off-by: David Hildenbrand Tested-by: Mario Casquero --- hw/s390x/s390-hypercall.c | 12 +++++++++++- hw/s390x/s390-hypercall.h | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/hw/s390x/s390-hypercall.c b/hw/s390x/s390-hypercall.c index f816c2b1ef..ac1b08b2cd 100644 --- a/hw/s390x/s390-hypercall.c +++ b/hw/s390x/s390-hypercall.c @@ -11,7 +11,7 @@ =20 #include "qemu/osdep.h" #include "cpu.h" -#include "hw/boards.h" +#include "hw/s390x/s390-virtio-ccw.h" #include "hw/s390x/s390-hypercall.h" #include "hw/s390x/ioinst.h" #include "hw/s390x/css.h" @@ -57,6 +57,13 @@ static int handle_virtio_ccw_notify(uint64_t subch_id, u= int64_t data) return 0; } =20 +static uint64_t handle_storage_limit(void) +{ + S390CcwMachineState *s390ms =3D S390_CCW_MACHINE(qdev_get_machine()); + + return s390_get_memory_limit(s390ms) - 1; +} + void handle_diag_500(S390CPU *cpu, uintptr_t ra) { CPUS390XState *env =3D &cpu->env; @@ -69,6 +76,9 @@ void handle_diag_500(S390CPU *cpu, uintptr_t ra) case DIAG500_VIRTIO_CCW_NOTIFY: env->regs[2] =3D handle_virtio_ccw_notify(env->regs[2], env->regs[= 3]); break; + case DIAG500_STORAGE_LIMIT: + env->regs[2] =3D handle_storage_limit(); + break; default: s390_program_interrupt(env, PGM_SPECIFICATION, ra); } diff --git a/hw/s390x/s390-hypercall.h b/hw/s390x/s390-hypercall.h index 2fa81dbfdd..4f07209128 100644 --- a/hw/s390x/s390-hypercall.h +++ b/hw/s390x/s390-hypercall.h @@ -18,6 +18,7 @@ #define DIAG500_VIRTIO_RESET 1 /* legacy */ #define DIAG500_VIRTIO_SET_STATUS 2 /* legacy */ #define DIAG500_VIRTIO_CCW_NOTIFY 3 /* KVM_S390_VIRTIO_CCW_NOTIFY */ +#define DIAG500_STORAGE_LIMIT 4 =20 void handle_diag_500(S390CPU *cpu, uintptr_t ra); =20 --=20 2.46.1 From nobody Sat Nov 23 21:40:13 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1728385061; cv=none; d=zohomail.com; s=zohoarc; b=fTKQqY3QtcebWVZZSr7hFU+E673BL4aWQK6SBZNaVHv4p347+ZQ/kpUDxvkWmXVoGihvmuK7WJjekEHx/HAlyrv6hfv+77jVJBYo3j+pa7tYbb4XQ5Ql8o7SEKH8ZjsPNk1yw3kMp84dHh/ztGwmIg9lm49AvRodLWQYjY7Fk70= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728385061; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=9ptUoL5ViI+klHpO6WnvgtLo1vPdIs4CY5BwVWYDacA=; b=iJYt/HzS916b4ihwwjp7AlFb3lbfdxblO8K7u1hGS1qcYfnD2XOisUGHjbhYpi2QEKdCdga7cEtfy8CyUNQMBYVnVCMzxLx4GuPz4bM5zQT78bnbtyRApk628OT0WALuMed7Xg03VAJY3GCYSDLkhFX4DZpX07PyWwtjQdmBQAM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 172838506160641.67224212340352; Tue, 8 Oct 2024 03:57:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sy7tm-0002pH-OO; Tue, 08 Oct 2024 06:57:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sy7sm-0001Vn-3x for qemu-devel@nongnu.org; Tue, 08 Oct 2024 06:56:04 -0400 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 1sy7sj-0001hQ-1A for qemu-devel@nongnu.org; Tue, 08 Oct 2024 06:55:59 -0400 Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-386-7V9DwEWmOBmUFnHyFexdhQ-1; Tue, 08 Oct 2024 06:55:49 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 807C71955D62; Tue, 8 Oct 2024 10:55:47 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.22.16.102]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B9CD119560A3; Tue, 8 Oct 2024 10:55:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728384950; 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=9ptUoL5ViI+klHpO6WnvgtLo1vPdIs4CY5BwVWYDacA=; b=TVNT4pckD4Fu36TJj0AjSrNDBgBGwiJbxgBu0JBqdk8XcSqUGjZnlfJGFuxtoeEZz3JP/C 2yNzanKU0tWq2YX0HKGWNHtwnY7kCsrZxn2nilVcZ5hxaLLq4fA5YDv0kp3HExSE1g7Kt7 GbsgvyYsGV2ip4LM4SALMmM/aK3azkA= X-MC-Unique: 7V9DwEWmOBmUFnHyFexdhQ-1 From: David Hildenbrand To: qemu-devel@nongnu.org Cc: qemu-s390x@nongnu.org, 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 Subject: [PATCH v2 08/14] s390x/s390-stattrib-kvm: prepare for memory devices and sparse memory layouts Date: Tue, 8 Oct 2024 12:54:49 +0200 Message-ID: <20241008105455.2302628-9-david@redhat.com> In-Reply-To: <20241008105455.2302628-1-david@redhat.com> References: <20241008105455.2302628-1-david@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=david@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.153, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1728385062765116600 Content-Type: text/plain; charset="utf-8" With memory devices, we will have storage attributes for memory that exceeds the initial ram size. Further, we can easily have memory holes, for which there (currently) are no storage attributes. In particular, with memory holes, KVM_S390_SET_CMMA_BITS will fail to set some storage attributes. So let's do it like we handle storage keys migration, relying on guest_phys_blocks_append(). However, in contrast to storage key migration, we will handle it on the migration destination. This is a preparation for virtio-mem support. Note that ever since the "early migration" feature was added (x-early-migration), the state of device blocks (plugged/unplugged) is migrated early such that guest_phys_blocks_append() will properly consider all currently plugged memory blocks and skip any unplugged ones. In the future, we should try getting rid of the large temporary buffer and also not send any attributes for any memory holes, just so they get ignored on the destination. Acked-by: Michael S. Tsirkin Signed-off-by: David Hildenbrand Reviewed-by: Thomas Huth Tested-by: Mario Casquero --- hw/s390x/s390-stattrib-kvm.c | 67 +++++++++++++++++++++++------------- 1 file changed, 43 insertions(+), 24 deletions(-) diff --git a/hw/s390x/s390-stattrib-kvm.c b/hw/s390x/s390-stattrib-kvm.c index eeaa811098..33ec91422a 100644 --- a/hw/s390x/s390-stattrib-kvm.c +++ b/hw/s390x/s390-stattrib-kvm.c @@ -10,11 +10,12 @@ */ =20 #include "qemu/osdep.h" -#include "hw/boards.h" +#include "hw/s390x/s390-virtio-ccw.h" #include "migration/qemu-file.h" #include "hw/s390x/storage-attributes.h" #include "qemu/error-report.h" #include "sysemu/kvm.h" +#include "sysemu/memory_mapping.h" #include "exec/ram_addr.h" #include "kvm/kvm_s390x.h" #include "qapi/error.h" @@ -84,8 +85,8 @@ static int kvm_s390_stattrib_set_stattr(S390StAttribState= *sa, uint8_t *values) { KVMS390StAttribState *sas =3D KVM_S390_STATTRIB(sa); - MachineState *machine =3D MACHINE(qdev_get_machine()); - unsigned long max =3D machine->ram_size / TARGET_PAGE_SIZE; + S390CcwMachineState *s390ms =3D S390_CCW_MACHINE(qdev_get_machine()); + unsigned long max =3D s390_get_memory_limit(s390ms) / TARGET_PAGE_SIZE; =20 if (start_gfn + count > max) { error_report("Out of memory bounds when setting storage attributes= "); @@ -103,39 +104,57 @@ static int kvm_s390_stattrib_set_stattr(S390StAttribS= tate *sa, static void kvm_s390_stattrib_synchronize(S390StAttribState *sa) { KVMS390StAttribState *sas =3D KVM_S390_STATTRIB(sa); - MachineState *machine =3D MACHINE(qdev_get_machine()); - unsigned long max =3D machine->ram_size / TARGET_PAGE_SIZE; - /* We do not need to reach the maximum buffer size allowed */ - unsigned long cx, len =3D KVM_S390_SKEYS_MAX / 2; + S390CcwMachineState *s390ms =3D S390_CCW_MACHINE(qdev_get_machine()); + unsigned long max =3D s390_get_memory_limit(s390ms) / TARGET_PAGE_SIZE; + unsigned long start_gfn, end_gfn, pages; + GuestPhysBlockList guest_phys_blocks; + GuestPhysBlock *block; int r; struct kvm_s390_cmma_log clog =3D { .flags =3D 0, .mask =3D ~0ULL, }; =20 - if (sas->incoming_buffer) { - for (cx =3D 0; cx + len <=3D max; cx +=3D len) { - clog.start_gfn =3D cx; - clog.count =3D len; - clog.values =3D (uint64_t)(sas->incoming_buffer + cx); - r =3D kvm_vm_ioctl(kvm_state, KVM_S390_SET_CMMA_BITS, &clog); - if (r) { - error_report("KVM_S390_SET_CMMA_BITS failed: %s", strerror= (-r)); - return; - } - } - if (cx < max) { - clog.start_gfn =3D cx; - clog.count =3D max - cx; - clog.values =3D (uint64_t)(sas->incoming_buffer + cx); + if (!sas->incoming_buffer) { + return; + } + guest_phys_blocks_init(&guest_phys_blocks); + guest_phys_blocks_append(&guest_phys_blocks); + + QTAILQ_FOREACH(block, &guest_phys_blocks.head, next) { + assert(QEMU_IS_ALIGNED(block->target_start, TARGET_PAGE_SIZE)); + assert(QEMU_IS_ALIGNED(block->target_end, TARGET_PAGE_SIZE)); + + start_gfn =3D block->target_start / TARGET_PAGE_SIZE; + end_gfn =3D block->target_end / TARGET_PAGE_SIZE; + + while (start_gfn < end_gfn) { + /* Don't exceed the maximum buffer size. */ + pages =3D MIN(end_gfn - start_gfn, KVM_S390_SKEYS_MAX / 2); + + /* + * If we ever get guest physical memory beyond the configured + * memory limit, something went very wrong. + */ + assert(start_gfn + pages <=3D max); + + clog.start_gfn =3D start_gfn; + clog.count =3D pages; + clog.values =3D (uint64_t)(sas->incoming_buffer + start_gfn); r =3D kvm_vm_ioctl(kvm_state, KVM_S390_SET_CMMA_BITS, &clog); if (r) { error_report("KVM_S390_SET_CMMA_BITS failed: %s", strerror= (-r)); + goto out; } + + start_gfn +=3D pages; } - g_free(sas->incoming_buffer); - sas->incoming_buffer =3D NULL; } + +out: + guest_phys_blocks_free(&guest_phys_blocks); + g_free(sas->incoming_buffer); + sas->incoming_buffer =3D NULL; } =20 static int kvm_s390_stattrib_set_migrationmode(S390StAttribState *sa, bool= val, --=20 2.46.1 From nobody Sat Nov 23 21:40:13 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1728385085; cv=none; d=zohomail.com; s=zohoarc; b=G2VnkAUgws2IDivTUzkP4wcCmPTel9MGXB81I6MZurjvpy4Ls0I7QVtFM6R0AHzZwnF3AMpPQ/x7TXwWUqxuAr+K1leV19mzu55bARgOdD149jg01RbfKCQeqiUFKJ+SyDnlOHZQx/6JdQr16potOWoTNIuj+jqjdruyeqUfR4M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728385085; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=LcZFBFQwCJYDI15ROqYbWXm9iurrpc+RbzeIjtauEUM=; b=chImo/j7KN/lFcCO9rdTOdhBqg3umRQmhHV6RSnj6UqLbQxbZGELXO4+jB4Ewnnd3h6pjMkMGbcpalM1L3w3TEsGAmGp9qGKPb6IT+2y49gCttPC8cPI+xePioijInkuSbP+S3wSumHuxaKklMZB5yucgBBj2trl4ZByMAkLQRI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 172838508541784.14163317153339; Tue, 8 Oct 2024 03:58:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sy7tn-0002rc-0B; Tue, 08 Oct 2024 06:57:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sy7sp-0001WC-1D for qemu-devel@nongnu.org; Tue, 08 Oct 2024 06:56:04 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sy7sl-0001hf-TN for qemu-devel@nongnu.org; Tue, 08 Oct 2024 06:56:02 -0400 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-357-nMHfzspMOOiFeDqNyESyNw-1; Tue, 08 Oct 2024 06:55:54 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id DC81F1955F40; Tue, 8 Oct 2024 10:55:52 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.22.16.102]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id DEAA41956056; Tue, 8 Oct 2024 10:55:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728384957; 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=LcZFBFQwCJYDI15ROqYbWXm9iurrpc+RbzeIjtauEUM=; b=EXcTv6bGOZRlcVyG6WTgMi656b6ooRkO+oSfL+vaTRY+fOexhhlDe2VYzQ5htmZYW9PcE1 4P7RWwBix7JMDGBAI8oNMwB4jXqlBzMAMaWrh9XRAUN2RGtSkNY173A1lp9UiPVS+EsfK6 hcATa31DaYNQg/shZAn0JTb8BXHPBmE= X-MC-Unique: nMHfzspMOOiFeDqNyESyNw-1 From: David Hildenbrand To: qemu-devel@nongnu.org Cc: qemu-s390x@nongnu.org, 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 Subject: [PATCH v2 09/14] s390x/s390-skeys: prepare for memory devices Date: Tue, 8 Oct 2024 12:54:50 +0200 Message-ID: <20241008105455.2302628-10-david@redhat.com> In-Reply-To: <20241008105455.2302628-1-david@redhat.com> References: <20241008105455.2302628-1-david@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=david@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.153, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1728385086874116600 Content-Type: text/plain; charset="utf-8" With memory devices, we will have storage keys for memory that exceeds the initial ram size. The TODO already states that current handling is subopimal, but we won't worry about improving that (TCG-only) thing for now. Acked-by: Michael S. Tsirkin Signed-off-by: David Hildenbrand Tested-by: Mario Casquero --- 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 bf22d6863e..e4297b3b8a 100644 --- a/hw/s390x/s390-skeys.c +++ b/hw/s390x/s390-skeys.c @@ -11,7 +11,7 @@ =20 #include "qemu/osdep.h" #include "qemu/units.h" -#include "hw/boards.h" +#include "hw/s390x/s390-virtio-ccw.h" #include "hw/qdev-properties.h" #include "hw/s390x/storage-keys.h" #include "qapi/error.h" @@ -251,9 +251,9 @@ static bool qemu_s390_enable_skeys(S390SKeysState *ss) * g_once_init_enter() is good enough. */ if (g_once_init_enter(&initialized)) { - MachineState *machine =3D MACHINE(qdev_get_machine()); + S390CcwMachineState *s390ms =3D S390_CCW_MACHINE(qdev_get_machine(= )); =20 - skeys->key_count =3D machine->ram_size / TARGET_PAGE_SIZE; + skeys->key_count =3D s390_get_memory_limit(s390ms) / TARGET_PAGE_S= IZE; skeys->keydata =3D g_malloc0(skeys->key_count); g_once_init_leave(&initialized, 1); } --=20 2.46.1 From nobody Sat Nov 23 21:40:13 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1728385098; cv=none; d=zohomail.com; s=zohoarc; b=OJbuckWVjsAQKWzJnXIqvRXYIShFRhVL4xPKwG50ue8QQoE/N2lL/Rn4gtc+3gC/vpUaCD8tP05GLEBBMm3OqMOhOvS5NSwZ2DjTJRUihmOQdoSdYsOAfhdNh+X/G9ZY3zXjGIRf2pcGrFhKwBznTpbc1M7ihyYI2BRlnv5a+3w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728385098; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=JvZfOHK3bg9z1CnC9PzacrSMSFqYls7EfsF1YoACfv0=; b=YJ7D92MGvR7DrXXxPtcFe5CppTnRACMKz3s46J/ezcnn1nkjwrHC5rBvlfFR73f0PD/n0J1LS2iwR5JIcjBVde1bTNUItG3bKjUz229HdI9TadAnBqwZ/tiVCEsZEKpod2yd0qlXp+jFTSae5he+u8VmKPtqTDu7RncIqT7+2i4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1728385098199831.0747204820177; Tue, 8 Oct 2024 03:58:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sy7tq-0003EO-0O; Tue, 08 Oct 2024 06:57:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sy7sr-0001Wb-DL for qemu-devel@nongnu.org; Tue, 08 Oct 2024 06:56:06 -0400 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 1sy7sp-0001id-J7 for qemu-devel@nongnu.org; Tue, 08 Oct 2024 06:56:05 -0400 Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-314-VTK2pChHN7O_EUVYj8QgxQ-1; Tue, 08 Oct 2024 06:55:59 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4167F1955DD4; Tue, 8 Oct 2024 10:55:58 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.22.16.102]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 73CE419560A3; Tue, 8 Oct 2024 10:55:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728384963; 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=JvZfOHK3bg9z1CnC9PzacrSMSFqYls7EfsF1YoACfv0=; b=M+D0W66orpnTiiH917zeIaYR185halc+pR/s3N8qmsCFUy0FFRTsZ5OFyT/cr1sWS54TWN IGD5c2NgDmG9D7x+QKPliFDPTQdzPRSk/TTqASDXHaa4Mrb/HQOdtuQ3DY9/O5jzsEJeZD ifVJH/HNyZckQC8kARmAmqC7YFfjUyE= X-MC-Unique: VTK2pChHN7O_EUVYj8QgxQ-1 From: David Hildenbrand To: qemu-devel@nongnu.org Cc: qemu-s390x@nongnu.org, 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 Subject: [PATCH v2 10/14] s390x/s390-virtio-ccw: prepare for memory devices Date: Tue, 8 Oct 2024 12:54:51 +0200 Message-ID: <20241008105455.2302628-11-david@redhat.com> In-Reply-To: <20241008105455.2302628-1-david@redhat.com> References: <20241008105455.2302628-1-david@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=david@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.153, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1728385098901116600 Content-Type: text/plain; charset="utf-8" Let's prepare our address space for memory devices if enabled via "maxmem" and if we have CONFIG_MEM_DEVICE enabled at all. Note that CONFIG_MEM_DEVICE will be selected automatically once we add support for devices. Just like on other architectures, the region container for memory devices is placed directly above our initial memory. For now, we only align the start address of the region up to 1 GiB, but we won't add any additional space to the region for internal alignment purposes; this can be done in the future if really required. The RAM size returned via SCLP is not modified, as this only covers initial RAM (and standby memory we don't implement) and not memory devices; clarify that in the docs of read_SCP_info(). Existing OSes without support for memory devices will keep working as is, even when memory devices would be attached the VM. Guest OSs which support memory devices, such as virtio-mem, will consult diag500(), to find out the maximum possible pfn. Guest OSes that don't support memory devices, don't have to be changed and will continue relying on information provided by SCLP. There are no remaining maxram_size users in s390x code, and the remaining ram_size users only care about initial RAM: * hw/s390x/ipl.c * hw/s390x/s390-hypercall.c * hw/s390x/sclp.c * target/s390x/kvm/pv.c Acked-by: Michael S. Tsirkin Signed-off-by: David Hildenbrand Tested-by: Mario Casquero --- 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 749d46e700..2031c4cf29 100644 --- a/hw/s390x/s390-virtio-ccw.c +++ b/hw/s390x/s390-virtio-ccw.c @@ -156,6 +156,7 @@ static void s390_memory_init(MachineState *machine) MemoryRegion *sysmem =3D get_system_memory(); MemoryRegion *ram =3D machine->ram; uint64_t ram_size =3D memory_region_size(ram); + uint64_t devmem_base, devmem_size; =20 if (!QEMU_IS_ALIGNED(ram_size, 1 * MiB)) { /* @@ -168,11 +169,31 @@ static void s390_memory_init(MachineState *machine) exit(EXIT_FAILURE); } =20 - s390_set_memory_limit(s390ms, ram_size); + devmem_size =3D 0; + devmem_base =3D ram_size; +#ifdef CONFIG_MEM_DEVICE + if (machine->ram_size < machine->maxram_size) { + + /* + * Make sure memory devices have a sane default alignment, even + * when weird initial memory sizes are specified. + */ + devmem_base =3D QEMU_ALIGN_UP(devmem_base, 1 * GiB); + devmem_size =3D machine->maxram_size - machine->ram_size; + } +#endif + s390_set_memory_limit(s390ms, devmem_base + devmem_size); =20 /* Map the initial memory. Must happen after setting the memory limit.= */ memory_region_add_subregion(sysmem, 0, ram); =20 + /* Initialize address space for memory devices. */ +#ifdef CONFIG_MEM_DEVICE + if (devmem_size) { + machine_memory_devices_init(machine, devmem_base, devmem_size); + } +#endif /* CONFIG_MEM_DEVICE */ + /* * Configure the maximum page size. As no memory devices were created * yet, this is the page size of initial memory only. diff --git a/hw/s390x/sclp.c b/hw/s390x/sclp.c index fac09816bf..fe4216a10d 100644 --- a/hw/s390x/sclp.c +++ b/hw/s390x/sclp.c @@ -162,7 +162,11 @@ static void read_SCP_info(SCLPDevice *sclp, SCCB *sccb) read_info->rnsize2 =3D cpu_to_be32(rnsize); } =20 - /* we don't support standby memory, maxram_size is never exposed */ + /* + * We don't support standby memory. maxram_size is used for sizing the + * memory device region, which is not exposed through SCLP but through + * diag500. + */ rnmax =3D machine->ram_size >> sclp->increment_size; if (rnmax < 0x10000) { read_info->rnmax =3D cpu_to_be16(rnmax); --=20 2.46.1 From nobody Sat Nov 23 21:40:13 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1728385075; cv=none; d=zohomail.com; s=zohoarc; b=anOzK5SmYHIw4h9Eq/zJitzHI+7W0oqWESkaIFEqDsxxtnu7FVKy7CT9WMDpW34JkYgkBEwocUQRyvJJMIYkd7NPaP8LbKrxONhUL/TR43rtq40GfQPbjuWxW1CgLEVObVAT+iduXxZFBhF8TmIRp8GaMc4ybkWfi64y1h6uxpI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728385075; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=63ljXjbAopNmOe8Zx78W0ueNcUiBfGI8IJ4b29vSJFI=; b=kC04gv8URHM3VlpuOdKfI1KeclT9F6jzu3IlD6WxRkkS6RaoWA+hqz3KbbtGvdZp7+yEwrxDiM6FoHpoFmvAmzzEmTsPbHWyWUQvP2MWanoXDXrB5wGAnk510S4Sc0F4vbu1wtRJ1D89jiPfMN+Bq5PmCLF3epNDTO7MCK2gUR0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1728385075877196.6763501744332; Tue, 8 Oct 2024 03:57:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sy7tp-00036R-E1; Tue, 08 Oct 2024 06:57:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sy7sw-0001bx-Hq for qemu-devel@nongnu.org; Tue, 08 Oct 2024 06:56:10 -0400 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 1sy7sv-0001jl-3m for qemu-devel@nongnu.org; Tue, 08 Oct 2024 06:56:10 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-50-0WbXsbsuNYaGqjtlIx1rFA-1; Tue, 08 Oct 2024 06:56:05 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C29F719560BE; Tue, 8 Oct 2024 10:56:03 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.22.16.102]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A716919560A3; Tue, 8 Oct 2024 10:55:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728384968; 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=63ljXjbAopNmOe8Zx78W0ueNcUiBfGI8IJ4b29vSJFI=; b=KbHZibKj8mJSIP9hMGbTvQazscJXmehQBYeFHZ6+xuE4AlQqxqpTt8YIc4arjARAEeRPY+ GJufIdGIfdBew31L52ljwC+A9A9FyLDt+b8DbIoYW3YtTb76PTqH4aIC8zFqLXX2pgEkD+ 5DM6h2w1YnjxIP/WFptbba6WbieFrlQ= X-MC-Unique: 0WbXsbsuNYaGqjtlIx1rFA-1 From: David Hildenbrand To: qemu-devel@nongnu.org Cc: qemu-s390x@nongnu.org, 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 Subject: [PATCH v2 11/14] s390x/pv: prepare for memory devices Date: Tue, 8 Oct 2024 12:54:52 +0200 Message-ID: <20241008105455.2302628-12-david@redhat.com> In-Reply-To: <20241008105455.2302628-1-david@redhat.com> References: <20241008105455.2302628-1-david@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=david@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.153, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1728385077825116600 Content-Type: text/plain; charset="utf-8" Let's avoid checking for the maxram_size, and instead rely on the memory limit determined in s390_memory_init(), that might be larger than maxram_size, for example due to alignment purposes. This check now correctly mimics what the kernel will check in kvm_s390_pv_set_aside(), whereby a VM <=3D 2 GiB VM would end up using a segment type ASCE. Acked-by: Michael S. Tsirkin Reviewed-by: Nina Schoetterl-Glausch Signed-off-by: David Hildenbrand Tested-by: Mario Casquero --- target/s390x/kvm/pv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/s390x/kvm/pv.c b/target/s390x/kvm/pv.c index 424cce75ca..fa66607e7b 100644 --- a/target/s390x/kvm/pv.c +++ b/target/s390x/kvm/pv.c @@ -133,7 +133,7 @@ bool s390_pv_vm_try_disable_async(S390CcwMachineState *= ms) * If the feature is not present or if the VM is not larger than 2 GiB, * KVM_PV_ASYNC_CLEANUP_PREPARE fill fail; no point in attempting it. */ - if ((MACHINE(ms)->ram_size <=3D 2 * GiB) || + if (s390_get_memory_limit(ms) <=3D 2 * GiB || !kvm_check_extension(kvm_state, KVM_CAP_S390_PROTECTED_ASYNC_DISAB= LE)) { return false; } --=20 2.46.1 From nobody Sat Nov 23 21:40:13 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1728385062; cv=none; d=zohomail.com; s=zohoarc; b=P8usNcoci1gfh1goijb/TJvgh/qVBP5jwE7lf1WNsMoOLAS4uMArE5x5M/E2AhWSN92Y04VYzW7LOzgeM0ywaW5y5db3m8jRmcz/LhsOMacF/yHDM+/OL6DlttyZu82PVoJicGrr6ygqujeqjRMKHqhrITU+c4ZbwBcqLw2tY3M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728385062; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=yPi+AZLrBrpcNAFLeYI6i11INU1VCx0iDUBL5LxkFmI=; b=P22pN51nEyLTmCvGuaz/bKRSbvVn7z05kHKE1jrJ0aGwf9IOPl1Z8DHc/McbEm9YktpoRGH6XP1UzZb5G2YWswZHcgNfZfW1Rwgz5ypTLrPWKxZGlf8GNFjDa5+ryn/Sg3LWRSpi99cIdNwCc4fntGXrof0quMLzwjsEc8pckQA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1728385062485349.329403021688; Tue, 8 Oct 2024 03:57:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sy7tr-0003Ry-Gx; Tue, 08 Oct 2024 06:57:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sy7t1-0001k5-2L for qemu-devel@nongnu.org; Tue, 08 Oct 2024 06:56:15 -0400 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 1sy7sz-0001kl-9G for qemu-devel@nongnu.org; Tue, 08 Oct 2024 06:56:14 -0400 Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-344-mU2F3o5DMHGzxaQC56f6DQ-1; Tue, 08 Oct 2024 06:56:11 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5DA891955D61; Tue, 8 Oct 2024 10:56:09 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.22.16.102]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3F40319560A3; Tue, 8 Oct 2024 10:56:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728384972; 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=yPi+AZLrBrpcNAFLeYI6i11INU1VCx0iDUBL5LxkFmI=; b=IONg/yvkLkkU8964WKScgaqz2rgHHxhFhQGqDUxXYcTaDF61uxGsMumkF/5ke93yIawogQ bA/mHpJqvb+nGGfq5jyPZrw5YHcknTKrecBHv7aQHGX2U3nG6YpALOqTNe/C5TLnyrFuAo GceD5sErPBCH/u3Jg4bZhgmRA2aMgdo= X-MC-Unique: mU2F3o5DMHGzxaQC56f6DQ-1 From: David Hildenbrand To: qemu-devel@nongnu.org Cc: qemu-s390x@nongnu.org, 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 Subject: [PATCH v2 12/14] s390x: remember the maximum page size Date: Tue, 8 Oct 2024 12:54:53 +0200 Message-ID: <20241008105455.2302628-13-david@redhat.com> In-Reply-To: <20241008105455.2302628-1-david@redhat.com> References: <20241008105455.2302628-1-david@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=david@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.153, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1728385062743116600 Content-Type: text/plain; charset="utf-8" Let's remember the value (successfully) set via s390_set_max_pagesize(). This will be helpful to reject hotplugged memory devices that would exceed this initially set page size. Handle it just like how we handle s390_get_memory_limit(), storing it in the machine, and moving the handling to machine code. Acked-by: Michael S. Tsirkin Signed-off-by: David Hildenbrand Tested-by: Mario Casquero --- 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 2031c4cf29..65f266a78f 100644 --- a/hw/s390x/s390-virtio-ccw.c +++ b/hw/s390x/s390-virtio-ccw.c @@ -150,6 +150,16 @@ uint64_t s390_get_memory_limit(S390CcwMachineState *s3= 90ms) return s390ms->memory_limit; } =20 +static void s390_set_max_pagesize(S390CcwMachineState *s390ms, + uint64_t pagesize) +{ + assert(!s390ms->max_pagesize && pagesize); + if (kvm_enabled()) { + kvm_s390_set_max_pagesize(pagesize, &error_fatal); + } + s390ms->max_pagesize =3D pagesize; +} + static void s390_memory_init(MachineState *machine) { S390CcwMachineState *s390ms =3D S390_CCW_MACHINE(machine); @@ -198,7 +208,7 @@ static void s390_memory_init(MachineState *machine) * Configure the maximum page size. As no memory devices were created * yet, this is the page size of initial memory only. */ - s390_set_max_pagesize(qemu_maxrampagesize(), &error_fatal); + s390_set_max_pagesize(s390ms, qemu_maxrampagesize()); /* Initialize storage key device */ s390_skeys_init(); /* Initialize storage attributes device */ diff --git a/include/hw/s390x/s390-virtio-ccw.h b/include/hw/s390x/s390-vir= tio-ccw.h index eb04542979..5a730f5d07 100644 --- a/include/hw/s390x/s390-virtio-ccw.h +++ b/include/hw/s390x/s390-virtio-ccw.h @@ -30,6 +30,7 @@ struct S390CcwMachineState { bool pv; uint8_t loadparm[8]; uint64_t memory_limit; + uint64_t max_pagesize; =20 SCLPDevice *sclp; }; diff --git a/target/s390x/cpu-sysemu.c b/target/s390x/cpu-sysemu.c index 3118a25fee..706a5c53e2 100644 --- a/target/s390x/cpu-sysemu.c +++ b/target/s390x/cpu-sysemu.c @@ -255,13 +255,6 @@ unsigned int s390_cpu_set_state(uint8_t cpu_state, S39= 0CPU *cpu) return s390_count_running_cpus(); } =20 -void s390_set_max_pagesize(uint64_t pagesize, Error **errp) -{ - if (kvm_enabled()) { - kvm_s390_set_max_pagesize(pagesize, errp); - } -} - void s390_cmma_reset(void) { if (kvm_enabled()) { diff --git a/target/s390x/cpu.h b/target/s390x/cpu.h index b4506539f0..5b7992deda 100644 --- a/target/s390x/cpu.h +++ b/target/s390x/cpu.h @@ -881,7 +881,6 @@ static inline void s390_do_cpu_load_normal(CPUState *cs= , run_on_cpu_data arg) =20 /* cpu.c */ void s390_crypto_reset(void); -void s390_set_max_pagesize(uint64_t pagesize, Error **errp); void s390_cmma_reset(void); void s390_enable_css_support(S390CPU *cpu); void s390_do_cpu_set_diag318(CPUState *cs, run_on_cpu_data arg); --=20 2.46.1 From nobody Sat Nov 23 21:40:13 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1728385087; cv=none; d=zohomail.com; s=zohoarc; b=cdn83nqg8oVy2zqEAa48Jw5XePnTD9B0c8Wq5CkufXhlBJvSmFC/JL5+F9WtrUGyWNPOUNCUvfjxzjdaXjuyECf3PKxOnDu72wmxaC1qGLfSlY+EDVRoK7NmLKRjbwxAHRnB4xEKhPNLxQKJ9ABlp9rkNL3XxPUZx1Q/zjzsGiA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728385087; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=69hri59KYylWZ5oi8AQj7hjywQm9gem6vRXNxK6MfZA=; b=nsK5esfR5RPaDOYXfE/Cm/3nHrwDLHAPKhWqNLZCA12B+t9iD3Jbqj0+loWqazrFRiYkfwTskhIqVVw7KsSPpfWt0v8QQWkIJ4fSGnVI/NbaLGxOvK72xYaKqxnhfjvkVbQ/kF366RcG5Lkxek75QNWncoOS476NLgCrcELuvrc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1728385087451604.8172063426667; Tue, 8 Oct 2024 03:58:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sy7tq-0003Mk-QN; Tue, 08 Oct 2024 06:57:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sy7tA-00023I-Sc for qemu-devel@nongnu.org; Tue, 08 Oct 2024 06:56:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sy7t8-0001mF-KL for qemu-devel@nongnu.org; Tue, 08 Oct 2024 06:56:24 -0400 Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-347-pDsFdSc0NDab7TkZd1lx4g-1; Tue, 08 Oct 2024 06:56:16 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 323261955DCE; Tue, 8 Oct 2024 10:56:15 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.22.16.102]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id EBD0119560A3; Tue, 8 Oct 2024 10:56:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728384981; 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=69hri59KYylWZ5oi8AQj7hjywQm9gem6vRXNxK6MfZA=; b=eP3zN1o4hLWTvb8ta1YEDvxLCYCyLGCx5K31wbP+dKHGPFxWc/mXjE3SzJvz1+nEnKLj8n KOPIukSOrOwos7rGkhv9P+PassjjCnAaZRd07vWJdH30AAubjMsP+srT3aIQ5DcaI+1t6s p9K3/9K/gDqLuuilqj0gkO++LX/3dAs= X-MC-Unique: pDsFdSc0NDab7TkZd1lx4g-1 From: David Hildenbrand To: qemu-devel@nongnu.org Cc: qemu-s390x@nongnu.org, 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 Subject: [PATCH v2 13/14] s390x/virtio-ccw: add support for virtio based memory devices Date: Tue, 8 Oct 2024 12:54:54 +0200 Message-ID: <20241008105455.2302628-14-david@redhat.com> In-Reply-To: <20241008105455.2302628-1-david@redhat.com> References: <20241008105455.2302628-1-david@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=david@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.153, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1728385088927116600 Content-Type: text/plain; charset="utf-8" Let's implement support for abstract virtio based memory devices, using the virtio-pci implementation as an orientation. Wire them up in the machine hotplug handler, taking care of s390x page size limitations. As we neither support virtio-mem or virtio-pmem yet, the code is effectively unused. We'll implement support for virtio-mem based on this next. Note that we won't wire up the virtio-pci variant (should currently be impossible due to lack of support for MSI-X), but we'll add a safety net to reject plugging them in the pre-plug handler. Acked-by: Michael S. Tsirkin Signed-off-by: David Hildenbrand Tested-by: Mario Casquero --- 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 d7a11fe601..1b337f52d1 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2325,6 +2325,9 @@ F: include/hw/virtio/virtio-crypto.h virtio based memory device M: David Hildenbrand S: Supported +F: hw/s390x/virtio-ccw-md.c +F: hw/s390x/virtio-ccw-md.h +F: hw/s390x/virtio-ccw-md-stubs.c F: hw/virtio/virtio-md-pci.c F: include/hw/virtio/virtio-md-pci.h F: stubs/virtio-md-pci.c diff --git a/hw/s390x/meson.build b/hw/s390x/meson.build index 71ec747f4c..28bbe4b06c 100644 --- a/hw/s390x/meson.build +++ b/hw/s390x/meson.build @@ -48,8 +48,11 @@ endif virtio_ss.add(when: 'CONFIG_VHOST_SCSI', if_true: files('vhost-scsi-ccw.c'= )) virtio_ss.add(when: 'CONFIG_VHOST_VSOCK', if_true: files('vhost-vsock-ccw.= c')) virtio_ss.add(when: 'CONFIG_VHOST_USER_FS', if_true: files('vhost-user-fs-= ccw.c')) +virtio_ss.add(when: 'CONFIG_VIRTIO_MD', if_true: files('virtio-ccw-md.c')) s390x_ss.add_all(when: 'CONFIG_VIRTIO_CCW', if_true: virtio_ss) =20 +s390x_ss.add(when: 'CONFIG_VIRTIO_MD', if_false: files('virtio-ccw-md-stub= s.c')) + hw_arch +=3D {'s390x': s390x_ss} =20 hw_s390x_modules =3D {} diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c index 65f266a78f..16be9f25e8 100644 --- a/hw/s390x/s390-virtio-ccw.c +++ b/hw/s390x/s390-virtio-ccw.c @@ -46,6 +46,8 @@ #include "qapi/visitor.h" #include "hw/s390x/cpu-topology.h" #include "kvm/kvm_s390x.h" +#include "hw/virtio/virtio-md-pci.h" +#include "hw/s390x/virtio-ccw-md.h" #include CONFIG_DEVICES =20 static Error *pv_mig_blocker; @@ -559,11 +561,39 @@ static void s390_machine_reset(MachineState *machine,= ResetType type) s390_ipl_clear_reset_request(); } =20 +static void s390_machine_device_pre_plug(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **errp) +{ + if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MD_CCW)) { + virtio_ccw_md_pre_plug(VIRTIO_MD_CCW(dev), MACHINE(hotplug_dev), e= rrp); + } else if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MD_PCI)) { + error_setg(errp, + "PCI-attached virtio based memory devices not supported= "); + } +} + static void s390_machine_device_plug(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) { + S390CcwMachineState *s390ms =3D S390_CCW_MACHINE(hotplug_dev); + if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) { s390_cpu_plug(hotplug_dev, dev, errp); + } else if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MD_CCW)) { + /* + * At this point, the device is realized and set all memdevs mappe= d, so + * qemu_maxrampagesize() will pick up the page sizes of these memd= evs + * as well. Before we plug the device and expose any RAM memory re= gions + * to the system, make sure we don't exceed the previously set max= page + * size. While only relevant for KVM, there is not really any use = case + * for this with TCG, so we'll unconditionally reject it. + */ + if (qemu_maxrampagesize() !=3D s390ms->max_pagesize) { + error_setg(errp, "Memory device uses a bigger page size than" + " initial memory"); + return; + } + virtio_ccw_md_plug(VIRTIO_MD_CCW(dev), MACHINE(hotplug_dev), errp); } } =20 @@ -573,9 +603,20 @@ static void s390_machine_device_unplug_request(Hotplug= Handler *hotplug_dev, if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) { error_setg(errp, "CPU hot unplug not supported on this machine"); return; + } else if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MD_CCW)) { + virtio_ccw_md_unplug_request(VIRTIO_MD_CCW(dev), MACHINE(hotplug_d= ev), + errp); } } =20 +static void s390_machine_device_unplug(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **errp) +{ + if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MD_CCW)) { + virtio_ccw_md_unplug(VIRTIO_MD_CCW(dev), MACHINE(hotplug_dev), err= p); + } + } + static CpuInstanceProperties s390_cpu_index_to_props(MachineState *ms, unsigned cpu_index) { @@ -622,7 +663,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; @@ -798,8 +841,10 @@ static void ccw_machine_class_init(ObjectClass *oc, vo= id *data) mc->possible_cpu_arch_ids =3D s390_possible_cpu_arch_ids; /* it is overridden with 'host' cpu *in kvm_arch_init* */ mc->default_cpu_type =3D S390_CPU_TYPE_NAME("qemu"); + hc->pre_plug =3D s390_machine_device_pre_plug; hc->plug =3D s390_machine_device_plug; hc->unplug_request =3D s390_machine_device_unplug_request; + hc->unplug =3D s390_machine_device_unplug; nc->nmi_monitor_handler =3D s390_nmi; mc->default_ram_id =3D "s390.ram"; mc->default_nic =3D "virtio-net-ccw"; diff --git a/hw/s390x/virtio-ccw-md-stubs.c b/hw/s390x/virtio-ccw-md-stubs.c new file mode 100644 index 0000000000..e937865550 --- /dev/null +++ b/hw/s390x/virtio-ccw-md-stubs.c @@ -0,0 +1,24 @@ +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "hw/s390x/virtio-ccw-md.h" + +void virtio_ccw_md_pre_plug(VirtIOMDCcw *vmd, MachineState *ms, Error **er= rp) +{ + error_setg(errp, "virtio based memory devices not supported"); +} + +void virtio_ccw_md_plug(VirtIOMDCcw *vmd, MachineState *ms, Error **errp) +{ + error_setg(errp, "virtio based memory devices not supported"); +} + +void virtio_ccw_md_unplug_request(VirtIOMDCcw *vmd, MachineState *ms, + Error **errp) +{ + error_setg(errp, "virtio based memory devices not supported"); +} + +void virtio_ccw_md_unplug(VirtIOMDCcw *vmd, MachineState *ms, Error **errp) +{ + error_setg(errp, "virtio based memory devices not supported"); +} diff --git a/hw/s390x/virtio-ccw-md.c b/hw/s390x/virtio-ccw-md.c new file mode 100644 index 0000000000..de333282df --- /dev/null +++ b/hw/s390x/virtio-ccw-md.c @@ -0,0 +1,153 @@ +/* + * Virtio CCW support for abstract virtio based memory device + * + * Copyright (C) 2024 Red Hat, Inc. + * + * Authors: + * David Hildenbrand + * + * This work is licensed under the terms of the GNU GPL, version 2. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "hw/s390x/virtio-ccw-md.h" +#include "hw/mem/memory-device.h" +#include "qapi/error.h" +#include "qemu/error-report.h" + +void virtio_ccw_md_pre_plug(VirtIOMDCcw *vmd, MachineState *ms, Error **er= rp) +{ + DeviceState *dev =3D DEVICE(vmd); + HotplugHandler *bus_handler =3D qdev_get_bus_hotplug_handler(dev); + MemoryDeviceState *md =3D MEMORY_DEVICE(vmd); + Error *local_err =3D NULL; + + if (!bus_handler && dev->hotplugged) { + /* + * Without a bus hotplug handler, we cannot control the plug/unplug + * order. We should never reach this point when hotplugging, but + * better add a safety net. + */ + error_setg(errp, "hotplug of virtio based memory devices not suppo= rted" + " on this bus."); + return; + } + + /* + * First, see if we can plug this memory device at all. If that + * succeeds, branch of to the actual hotplug handler. + */ + memory_device_pre_plug(md, ms, &local_err); + if (!local_err && bus_handler) { + hotplug_handler_pre_plug(bus_handler, dev, &local_err); + } + error_propagate(errp, local_err); +} + +void virtio_ccw_md_plug(VirtIOMDCcw *vmd, MachineState *ms, Error **errp) +{ + DeviceState *dev =3D DEVICE(vmd); + HotplugHandler *bus_handler =3D qdev_get_bus_hotplug_handler(dev); + MemoryDeviceState *md =3D MEMORY_DEVICE(vmd); + Error *local_err =3D NULL; + + /* + * Plug the memory device first and then branch off to the actual + * hotplug handler. If that one fails, we can easily undo the memory + * device bits. + */ + memory_device_plug(md, ms); + if (bus_handler) { + hotplug_handler_plug(bus_handler, dev, &local_err); + if (local_err) { + memory_device_unplug(md, ms); + } + } + error_propagate(errp, local_err); +} + +void virtio_ccw_md_unplug_request(VirtIOMDCcw *vmd, MachineState *ms, + Error **errp) +{ + VirtIOMDCcwClass *vmdc =3D VIRTIO_MD_CCW_GET_CLASS(vmd); + DeviceState *dev =3D DEVICE(vmd); + HotplugHandler *bus_handler =3D qdev_get_bus_hotplug_handler(dev); + HotplugHandlerClass *hdc; + Error *local_err =3D NULL; + + if (!vmdc->unplug_request_check) { + error_setg(errp, + "this virtio based memory devices cannot be unplugged"); + return; + } + + if (!bus_handler) { + error_setg(errp, "hotunplug of virtio based memory devices not" + "supported on this bus"); + return; + } + + vmdc->unplug_request_check(vmd, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } + + /* + * Forward the async request or turn it into a sync request (handling = it + * like qdev_unplug()). + */ + hdc =3D HOTPLUG_HANDLER_GET_CLASS(bus_handler); + if (hdc->unplug_request) { + hotplug_handler_unplug_request(bus_handler, dev, &local_err); + } else { + virtio_ccw_md_unplug(vmd, ms, &local_err); + if (!local_err) { + object_unparent(OBJECT(dev)); + } + } +} + +void virtio_ccw_md_unplug(VirtIOMDCcw *vmd, MachineState *ms, Error **errp) +{ + DeviceState *dev =3D DEVICE(vmd); + HotplugHandler *bus_handler =3D qdev_get_bus_hotplug_handler(dev); + MemoryDeviceState *md =3D MEMORY_DEVICE(vmd); + Error *local_err =3D NULL; + + /* Unplug the memory device while it is still realized. */ + memory_device_unplug(md, ms); + + if (bus_handler) { + hotplug_handler_unplug(bus_handler, dev, &local_err); + if (local_err) { + /* Not expected to fail ... but still try to recover. */ + memory_device_plug(md, ms); + error_propagate(errp, local_err); + return; + } + } else { + /* Very unexpected, but let's just try to do the right thing. */ + warn_report("Unexpected unplug of virtio based memory device"); + qdev_unrealize(dev); + } +} + +static const TypeInfo virtio_ccw_md_info =3D { + .name =3D TYPE_VIRTIO_MD_CCW, + .parent =3D TYPE_VIRTIO_CCW_DEVICE, + .instance_size =3D sizeof(VirtIOMDCcw), + .class_size =3D sizeof(VirtIOMDCcwClass), + .abstract =3D true, + .interfaces =3D (InterfaceInfo[]) { + { TYPE_MEMORY_DEVICE }, + { } + }, +}; + +static void virtio_ccw_md_register(void) +{ + type_register_static(&virtio_ccw_md_info); +} +type_init(virtio_ccw_md_register) diff --git a/hw/s390x/virtio-ccw-md.h b/hw/s390x/virtio-ccw-md.h new file mode 100644 index 0000000000..39ba864c92 --- /dev/null +++ b/hw/s390x/virtio-ccw-md.h @@ -0,0 +1,44 @@ +/* + * Virtio CCW support for abstract virtio based memory device + * + * Copyright (C) 2024 Red Hat, Inc. + * + * Authors: + * David Hildenbrand + * + * This work is licensed under the terms of the GNU GPL, version 2. + * See the COPYING file in the top-level directory. + */ + +#ifndef HW_S390X_VIRTIO_CCW_MD_H +#define HW_S390X_VIRTIO_CCW_MD_H + +#include "virtio-ccw.h" +#include "qom/object.h" + +/* + * virtio-md-ccw: This extends VirtioCcwDevice. + */ +#define TYPE_VIRTIO_MD_CCW "virtio-md-ccw" + +OBJECT_DECLARE_TYPE(VirtIOMDCcw, VirtIOMDCcwClass, VIRTIO_MD_CCW) + +struct VirtIOMDCcwClass { + /* private */ + VirtIOCCWDeviceClass parent; + + /* public */ + void (*unplug_request_check)(VirtIOMDCcw *vmd, Error **errp); +}; + +struct VirtIOMDCcw { + VirtioCcwDevice parent_obj; +}; + +void virtio_ccw_md_pre_plug(VirtIOMDCcw *vmd, MachineState *ms, Error **er= rp); +void virtio_ccw_md_plug(VirtIOMDCcw *vmd, MachineState *ms, Error **errp); +void virtio_ccw_md_unplug_request(VirtIOMDCcw *vmd, MachineState *ms, + Error **errp); +void virtio_ccw_md_unplug(VirtIOMDCcw *vmd, MachineState *ms, Error **errp= ); + +#endif /* HW_S390X_VIRTIO_CCW_MD_H */ diff --git a/hw/virtio/Kconfig b/hw/virtio/Kconfig index 17595ff350..653ddfdfa8 100644 --- a/hw/virtio/Kconfig +++ b/hw/virtio/Kconfig @@ -25,6 +25,7 @@ config VIRTIO_MMIO config VIRTIO_CCW bool select VIRTIO + select VIRTIO_MD_SUPPORTED =20 config VIRTIO_BALLOON bool --=20 2.46.1 From nobody Sat Nov 23 21:40:13 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1728385058; cv=none; d=zohomail.com; s=zohoarc; b=dknRaJol3YAOnAbE2Vta79wdNLvqczc+apCRARL0icXNkPTA9FpG/Yr7mgpDAUZRkqEplq0mf29+KL2hagCljt/MwQdCgtic063T66khFJZzgSi8tubPSqYeDsHEkhAInD4/iGlAPtDKR5A2hKLssQQPJs3p8FONNGJSUzO7g50= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728385058; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=uKpuYCrdcPSFTbwDwJL/fnIIPqH17A+xX2q6QhyHoAc=; b=Xe1OHcQ6k5IQ8JjVyo8ZZz/RqF5ymxjZdiVVpBXTjoopmiizviKVwZzy62ammuoDlHNgvsximgzgetJ8Ry2uuK8o62DPBHfioP5aBDoSuNQ9otmuOsqZnQjpp3b4kcqQP9koE1K3ALMaITBSqwmU0lf8HrBv3SnjG3+8BG74LAE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1728385058011111.69096989602735; Tue, 8 Oct 2024 03:57:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sy7tp-00038o-Pr; Tue, 08 Oct 2024 06:57:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sy7tF-0002AS-BL for qemu-devel@nongnu.org; Tue, 08 Oct 2024 06:56:33 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sy7tB-0001nG-TI for qemu-devel@nongnu.org; Tue, 08 Oct 2024 06:56:29 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-473-v07apjTHOTSVPVCz1MestQ-1; Tue, 08 Oct 2024 06:56:22 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 663F519560AA; Tue, 8 Oct 2024 10:56:20 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.22.16.102]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id BFED919560A3; Tue, 8 Oct 2024 10:56:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728384985; 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=uKpuYCrdcPSFTbwDwJL/fnIIPqH17A+xX2q6QhyHoAc=; b=dFMC/hmKWr488Ei7VDxDHIAWY8vwV96B7as6aNWIKWZmNeATVehq7b2Zvpg3XT7oSuwkVT v7ab0y8kc59PJ5ZwUH4NKfIrjDZDWAtOO6dvgebgZdksAbZvvKelD/MYaV5IUz1/1XVhbG /p4yHzM6snhVoG2HeFQMcnXXSDXcNeE= X-MC-Unique: v07apjTHOTSVPVCz1MestQ-1 From: David Hildenbrand To: qemu-devel@nongnu.org Cc: qemu-s390x@nongnu.org, 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 Subject: [PATCH v2 14/14] s390x: virtio-mem support Date: Tue, 8 Oct 2024 12:54:55 +0200 Message-ID: <20241008105455.2302628-15-david@redhat.com> In-Reply-To: <20241008105455.2302628-1-david@redhat.com> References: <20241008105455.2302628-1-david@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=david@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.153, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1728385058813116600 Content-Type: text/plain; charset="utf-8" Let's add our virtio-mem-ccw proxy device and wire it up. We should be supporting everything (e.g., device unplug, "dynamic-memslots") that we already support for the virtio-pci variant. With a Linux guest that supports virtio-mem (and has automatic memory onlining properly configured) the following example will work: 1. Start a VM with 4G initial memory and a virtio-mem device with a maximum capacity of 16GB: qemu/build/qemu-system-s390x \ --enable-kvm \ -m 4G,maxmem=3D20G \ -nographic \ -smp 8 \ -hda Fedora-Server-KVM-40-1.14.s390x.qcow2 \ -chardev socket,id=3Dmonitor,path=3D/var/tmp/monitor,server,nowait \ -mon chardev=3Dmonitor,mode=3Dreadline \ -object memory-backend-ram,id=3Dmem0,size=3D16G,reserve=3Doff \ -device virtio-mem-ccw,id=3Dvmem0,memdev=3Dmem0,dynamic-memslots=3Don 2. Query the current size of virtio-mem device: (qemu) info memory-devices Memory device [virtio-mem]: "vmem0" memaddr: 0x100000000 node: 0 requested-size: 0 size: 0 max-size: 17179869184 block-size: 1048576 memdev: /objects/mem0 3. Request to grow it to 8GB (hotplug 8GB): (qemu) qom-set vmem0 requested-size 8G (qemu) info memory-devices Memory device [virtio-mem]: "vmem0" memaddr: 0x100000000 node: 0 requested-size: 8589934592 size: 8589934592 max-size: 17179869184 block-size: 1048576 memdev: /objects/mem0 4. Request to grow to 16GB (hotplug another 8GB): (qemu) qom-set vmem0 requested-size 16G (qemu) info memory-devices Memory device [virtio-mem]: "vmem0" memaddr: 0x100000000 node: 0 requested-size: 17179869184 size: 17179869184 max-size: 17179869184 block-size: 1048576 memdev: /objects/mem0 5. Try to hotunplug all memory again, shrinking to 0GB: (qemu) qom-set vmem0 requested-size 0G (qemu) info memory-devices Memory device [virtio-mem]: "vmem0" memaddr: 0x100000000 node: 0 requested-size: 0 size: 0 max-size: 17179869184 block-size: 1048576 memdev: /objects/mem0 6. If it worked, unplug the device (qemu) device_del vmem0 (qemu) info memory-devices (qemu) object_del mem0 7. Hotplug a new device with a smaller capacity and directly size it to 1GB (qemu) object_add memory-backend-ram,id=3Dmem0,size=3D8G,reserve=3Doff (qemu) device_add virtio-mem-ccw,id=3Dvmem0,memdev=3Dmem0,\ dynamic-memslots=3Don,requested-size=3D1G (qemu) info memory-devices Memory device [virtio-mem]: "vmem0" memaddr: 0x100000000 node: 0 requested-size: 1073741824 size: 1073741824 max-size: 8589934592 block-size: 1048576 memdev: /objects/mem0 Trying to use a virtio-mem device backed by hugetlb into a !hugetlb VM correctly results in the error: ... Memory device uses a bigger page size than initial memory Note that the virtio-mem driver in Linux will supports 1 MiB (pageblock) granularity. Acked-by: Michael S. Tsirkin Signed-off-by: David Hildenbrand Tested-by: Mario Casquero --- 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 1b337f52d1..1a5f6eeaf1 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2339,6 +2339,8 @@ W: https://virtio-mem.gitlab.io/ F: hw/virtio/virtio-mem.c F: hw/virtio/virtio-mem-pci.h F: hw/virtio/virtio-mem-pci.c +F: hw/s390x/virtio-ccw-mem.c +F: hw/s390x/virtio-ccw-mem.h F: include/hw/virtio/virtio-mem.h =20 virtio-snd diff --git a/hw/s390x/Kconfig b/hw/s390x/Kconfig index 3bbf4ae56e..5d57daff77 100644 --- a/hw/s390x/Kconfig +++ b/hw/s390x/Kconfig @@ -15,3 +15,4 @@ config S390_CCW_VIRTIO select SCLPCONSOLE select VIRTIO_CCW select MSI_NONBROKEN + select VIRTIO_MEM_SUPPORTED diff --git a/hw/s390x/meson.build b/hw/s390x/meson.build index 28bbe4b06c..094435cd3b 100644 --- a/hw/s390x/meson.build +++ b/hw/s390x/meson.build @@ -49,6 +49,7 @@ virtio_ss.add(when: 'CONFIG_VHOST_SCSI', if_true: files('= vhost-scsi-ccw.c')) virtio_ss.add(when: 'CONFIG_VHOST_VSOCK', if_true: files('vhost-vsock-ccw.= c')) virtio_ss.add(when: 'CONFIG_VHOST_USER_FS', if_true: files('vhost-user-fs-= ccw.c')) virtio_ss.add(when: 'CONFIG_VIRTIO_MD', if_true: files('virtio-ccw-md.c')) +virtio_ss.add(when: 'CONFIG_VIRTIO_MEM', if_true: files('virtio-ccw-mem.c'= )) s390x_ss.add_all(when: 'CONFIG_VIRTIO_CCW', if_true: virtio_ss) =20 s390x_ss.add(when: 'CONFIG_VIRTIO_MD', if_false: files('virtio-ccw-md-stub= s.c')) diff --git a/hw/s390x/virtio-ccw-mem.c b/hw/s390x/virtio-ccw-mem.c new file mode 100644 index 0000000000..bee0d560cb --- /dev/null +++ b/hw/s390x/virtio-ccw-mem.c @@ -0,0 +1,226 @@ +/* + * virtio-mem CCW implementation + * + * Copyright (C) 2024 Red Hat, Inc. + * + * Authors: + * David Hildenbrand + * + * This work is licensed under the terms of the GNU GPL, version 2. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "hw/qdev-properties.h" +#include "qapi/error.h" +#include "qemu/module.h" +#include "virtio-ccw-mem.h" +#include "hw/mem/memory-device.h" +#include "qapi/qapi-events-machine.h" +#include "qapi/qapi-events-misc.h" + +static void virtio_ccw_mem_realize(VirtioCcwDevice *ccw_dev, Error **errp) +{ + VirtIOMEMCcw *dev =3D VIRTIO_MEM_CCW(ccw_dev); + DeviceState *vdev =3D DEVICE(&dev->vdev); + + qdev_realize(vdev, BUS(&ccw_dev->bus), errp); +} + +static void virtio_ccw_mem_set_addr(MemoryDeviceState *md, uint64_t addr, + Error **errp) +{ + object_property_set_uint(OBJECT(md), VIRTIO_MEM_ADDR_PROP, addr, errp); +} + +static uint64_t virtio_ccw_mem_get_addr(const MemoryDeviceState *md) +{ + return object_property_get_uint(OBJECT(md), VIRTIO_MEM_ADDR_PROP, + &error_abort); +} + +static MemoryRegion *virtio_ccw_mem_get_memory_region(MemoryDeviceState *m= d, + Error **errp) +{ + VirtIOMEMCcw *dev =3D VIRTIO_MEM_CCW(md); + VirtIOMEM *vmem =3D &dev->vdev; + VirtIOMEMClass *vmc =3D VIRTIO_MEM_GET_CLASS(vmem); + + return vmc->get_memory_region(vmem, errp); +} + +static void virtio_ccw_mem_decide_memslots(MemoryDeviceState *md, + unsigned int limit) +{ + VirtIOMEMCcw *dev =3D VIRTIO_MEM_CCW(md); + VirtIOMEM *vmem =3D VIRTIO_MEM(&dev->vdev); + VirtIOMEMClass *vmc =3D VIRTIO_MEM_GET_CLASS(vmem); + + vmc->decide_memslots(vmem, limit); +} + +static unsigned int virtio_ccw_mem_get_memslots(MemoryDeviceState *md) +{ + VirtIOMEMCcw *dev =3D VIRTIO_MEM_CCW(md); + VirtIOMEM *vmem =3D VIRTIO_MEM(&dev->vdev); + VirtIOMEMClass *vmc =3D VIRTIO_MEM_GET_CLASS(vmem); + + return vmc->get_memslots(vmem); +} + +static uint64_t virtio_ccw_mem_get_plugged_size(const MemoryDeviceState *m= d, + Error **errp) +{ + return object_property_get_uint(OBJECT(md), VIRTIO_MEM_SIZE_PROP, + errp); +} + +static void virtio_ccw_mem_fill_device_info(const MemoryDeviceState *md, + MemoryDeviceInfo *info) +{ + VirtioMEMDeviceInfo *vi =3D g_new0(VirtioMEMDeviceInfo, 1); + VirtIOMEMCcw *dev =3D VIRTIO_MEM_CCW(md); + VirtIOMEM *vmem =3D &dev->vdev; + VirtIOMEMClass *vpc =3D VIRTIO_MEM_GET_CLASS(vmem); + DeviceState *vdev =3D DEVICE(md); + + if (vdev->id) { + vi->id =3D g_strdup(vdev->id); + } + + /* let the real device handle everything else */ + vpc->fill_device_info(vmem, vi); + + info->u.virtio_mem.data =3D vi; + info->type =3D MEMORY_DEVICE_INFO_KIND_VIRTIO_MEM; +} + +static uint64_t virtio_ccw_mem_get_min_alignment(const MemoryDeviceState *= md) +{ + return object_property_get_uint(OBJECT(md), VIRTIO_MEM_BLOCK_SIZE_PROP, + &error_abort); +} + +static void virtio_ccw_mem_size_change_notify(Notifier *notifier, void *da= ta) +{ + VirtIOMEMCcw *dev =3D container_of(notifier, VirtIOMEMCcw, + size_change_notifier); + DeviceState *vdev =3D DEVICE(dev); + char *qom_path =3D object_get_canonical_path(OBJECT(dev)); + const uint64_t * const size_p =3D data; + + qapi_event_send_memory_device_size_change(vdev->id, *size_p, qom_path); + g_free(qom_path); +} + +static void virtio_ccw_mem_unplug_request_check(VirtIOMDCcw *vmd, Error **= errp) +{ + VirtIOMEMCcw *dev =3D VIRTIO_MEM_CCW(vmd); + VirtIOMEM *vmem =3D &dev->vdev; + VirtIOMEMClass *vpc =3D VIRTIO_MEM_GET_CLASS(vmem); + + vpc->unplug_request_check(vmem, errp); +} + +static void virtio_ccw_mem_get_requested_size(Object *obj, Visitor *v, + const char *name, void *opaq= ue, + Error **errp) +{ + VirtIOMEMCcw *dev =3D VIRTIO_MEM_CCW(obj); + + object_property_get(OBJECT(&dev->vdev), name, v, errp); +} + +static void virtio_ccw_mem_set_requested_size(Object *obj, Visitor *v, + const char *name, void *opaq= ue, + Error **errp) +{ + VirtIOMEMCcw *dev =3D VIRTIO_MEM_CCW(obj); + DeviceState *vdev =3D DEVICE(obj); + + /* + * If we passed virtio_ccw_mem_unplug_request_check(), making sure that + * the requested size is 0, don't allow modifying the requested size + * anymore, otherwise the VM might end up hotplugging memory before + * handling the unplug request. + */ + if (vdev->pending_deleted_event) { + error_setg(errp, "'%s' cannot be changed if the device is in the" + " process of unplug", name); + return; + } + + object_property_set(OBJECT(&dev->vdev), name, v, errp); +} + +static Property virtio_ccw_mem_properties[] =3D { + DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags, + VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true), + DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice, max_rev, + VIRTIO_CCW_MAX_REV), + DEFINE_PROP_END_OF_LIST(), +}; + +static void virtio_ccw_mem_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + VirtIOCCWDeviceClass *k =3D VIRTIO_CCW_DEVICE_CLASS(klass); + MemoryDeviceClass *mdc =3D MEMORY_DEVICE_CLASS(klass); + VirtIOMDCcwClass *vmdc =3D VIRTIO_MD_CCW_CLASS(klass); + + k->realize =3D virtio_ccw_mem_realize; + set_bit(DEVICE_CATEGORY_MISC, dc->categories); + device_class_set_props(dc, virtio_ccw_mem_properties); + + mdc->get_addr =3D virtio_ccw_mem_get_addr; + mdc->set_addr =3D virtio_ccw_mem_set_addr; + mdc->get_plugged_size =3D virtio_ccw_mem_get_plugged_size; + mdc->get_memory_region =3D virtio_ccw_mem_get_memory_region; + mdc->decide_memslots =3D virtio_ccw_mem_decide_memslots; + mdc->get_memslots =3D virtio_ccw_mem_get_memslots; + mdc->fill_device_info =3D virtio_ccw_mem_fill_device_info; + mdc->get_min_alignment =3D virtio_ccw_mem_get_min_alignment; + + vmdc->unplug_request_check =3D virtio_ccw_mem_unplug_request_check; +} + +static void virtio_ccw_mem_instance_init(Object *obj) +{ + VirtIOMEMCcw *dev =3D VIRTIO_MEM_CCW(obj); + VirtIOMEMClass *vmc; + VirtIOMEM *vmem; + + virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), + TYPE_VIRTIO_MEM); + + dev->size_change_notifier.notify =3D virtio_ccw_mem_size_change_notify; + vmem =3D &dev->vdev; + vmc =3D VIRTIO_MEM_GET_CLASS(vmem); + /* + * We never remove the notifier again, as we expect both devices to + * disappear at the same time. + */ + vmc->add_size_change_notifier(vmem, &dev->size_change_notifier); + + object_property_add_alias(obj, VIRTIO_MEM_BLOCK_SIZE_PROP, + OBJECT(&dev->vdev), VIRTIO_MEM_BLOCK_SIZE_PR= OP); + object_property_add_alias(obj, VIRTIO_MEM_SIZE_PROP, OBJECT(&dev->vdev= ), + VIRTIO_MEM_SIZE_PROP); + object_property_add(obj, VIRTIO_MEM_REQUESTED_SIZE_PROP, "size", + virtio_ccw_mem_get_requested_size, + virtio_ccw_mem_set_requested_size, NULL, NULL); +} + +static const TypeInfo virtio_ccw_mem =3D { + .name =3D TYPE_VIRTIO_MEM_CCW, + .parent =3D TYPE_VIRTIO_MD_CCW, + .instance_size =3D sizeof(VirtIOMEMCcw), + .instance_init =3D virtio_ccw_mem_instance_init, + .class_init =3D virtio_ccw_mem_class_init, +}; + +static void virtio_ccw_mem_register_types(void) +{ + type_register_static(&virtio_ccw_mem); +} +type_init(virtio_ccw_mem_register_types) diff --git a/hw/s390x/virtio-ccw-mem.h b/hw/s390x/virtio-ccw-mem.h new file mode 100644 index 0000000000..738ab2c744 --- /dev/null +++ b/hw/s390x/virtio-ccw-mem.h @@ -0,0 +1,34 @@ +/* + * Virtio MEM CCW device + * + * Copyright (C) 2024 Red Hat, Inc. + * + * Authors: + * David Hildenbrand + * + * This work is licensed under the terms of the GNU GPL, version 2. + * See the COPYING file in the top-level directory. + */ + +#ifndef HW_S390X_VIRTIO_CCW_MEM_H +#define HW_S390X_VIRTIO_CCW_MEM_H + +#include "virtio-ccw-md.h" +#include "hw/virtio/virtio-mem.h" +#include "qom/object.h" + +typedef struct VirtIOMEMCcw VirtIOMEMCcw; + +/* + * virtio-mem-ccw: This extends VirtIOMDCcw + */ +#define TYPE_VIRTIO_MEM_CCW "virtio-mem-ccw" +DECLARE_INSTANCE_CHECKER(VirtIOMEMCcw, VIRTIO_MEM_CCW, TYPE_VIRTIO_MEM_CCW) + +struct VirtIOMEMCcw { + VirtIOMDCcw parent_obj; + VirtIOMEM vdev; + Notifier size_change_notifier; +}; + +#endif /* HW_S390X_VIRTIO_CCW_MEM_H */ diff --git a/hw/virtio/virtio-mem.c b/hw/virtio/virtio-mem.c index ae1e81d7ba..7885f6babb 100644 --- a/hw/virtio/virtio-mem.c +++ b/hw/virtio/virtio-mem.c @@ -61,6 +61,8 @@ static uint32_t virtio_mem_default_thp_size(void) } else if (qemu_real_host_page_size() =3D=3D 64 * KiB) { default_thp_size =3D 512 * MiB; } +#elif defined(__s390x__) + default_thp_size =3D 1 * MiB; #endif =20 return default_thp_size; @@ -168,7 +170,7 @@ static bool virtio_mem_has_shared_zeropage(RAMBlock *rb) * necessary (as the section size can change). But it's more likely that t= he * section size will rather get smaller and not bigger over time. */ -#if defined(TARGET_X86_64) || defined(TARGET_I386) +#if defined(TARGET_X86_64) || defined(TARGET_I386) || defined(TARGET_S390X) #define VIRTIO_MEM_USABLE_EXTENT (2 * (128 * MiB)) #elif defined(TARGET_ARM) #define VIRTIO_MEM_USABLE_EXTENT (2 * (512 * MiB)) --=20 2.46.1