From nobody Fri May 17 07:07:46 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=1687524463; cv=none; d=zohomail.com; s=zohoarc; b=WSwmAmqcyC7m0ukdKXAQupN7KbgpEY2eSXIpkBY8haM8kZJbG+sLDqcqWbH/qXZ6Mjj8IkFIx+g6yuo4rlVIe3Ui1KKPgiM7bWfkrmz9cdthRlLMkfZt/i0OgdZ5TnwxX0Jt3jOXGFVgkticHbjjTiG6xPCA9pSrrWzOwDyyEZo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1687524463; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=T6lLbn4wAevaYNir88uHLSoS3ayt4mzOGJLEgmNI+xk=; b=Rnzqn+s2ESX0evqOLIt7COaNe8DWG7u/wJX++T+NZeV1/kxq1FgQIzpZE/mTJd45Mdh+jHCd0UA5fPbQBO9CRqtIbh59Ps1ZPEjmizviruBT98FbT5c2GAxI0+sbgC3rfyRIcNKQam8yV4nATfH8FtPZO1bF8o9e/cvzMqhgwXk= 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 1687524463704971.3899402319036; Fri, 23 Jun 2023 05:47:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qCgB6-0001Yi-Q4; Fri, 23 Jun 2023 08:46:16 -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 1qCgAz-0001TL-RR for qemu-devel@nongnu.org; Fri, 23 Jun 2023 08:46:12 -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 1qCgAy-0000kb-8n for qemu-devel@nongnu.org; Fri, 23 Jun 2023 08:46:09 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-359-iXuqt_pvNKSFIp741b79dQ-1; Fri, 23 Jun 2023 08:46:03 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 892C28E44E2; Fri, 23 Jun 2023 12:46:02 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.22.32.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id D22721121314; Fri, 23 Jun 2023 12:45:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687524367; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=T6lLbn4wAevaYNir88uHLSoS3ayt4mzOGJLEgmNI+xk=; b=IDhW7KnPQRLGi4uzRigq1WlY6jqAKYljjy0kC86Tzqn9lwTkXWZw+2KKooRlqWFFnEeeWk cvYaATIQ8DfnBJGoTAMGImkdIh9eCq/HQ4mGAaDltgZ0f3Q+tRSZ76OvICk6APGQHRcXqc 9B8Dn4M2aFyHjJCEiZdUbFMICA9uiIo= X-MC-Unique: iXuqt_pvNKSFIp741b79dQ-1 From: David Hildenbrand To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, qemu-ppc@nongnu.org, Igor Mammedov , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Xiao Guangrong , David Hildenbrand , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Daniel Henrique Barboza , David Gibson , Eduardo Habkost , Greg Kurz , Harsh Prateek Bora , Marcel Apfelbaum , "Michael S. Tsirkin" , Paolo Bonzini , Peter Maydell , Richard Henderson , Song Gao , Xiaojuan Yang Subject: [PATCH v4 01/10] memory-device: Unify enabled vs. supported error messages Date: Fri, 23 Jun 2023 14:45:44 +0200 Message-Id: <20230623124553.400585-2-david@redhat.com> In-Reply-To: <20230623124553.400585-1-david@redhat.com> References: <20230623124553.400585-1-david@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=david@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=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: 1687524464388100001 Let's unify the error messages, such that we can simply stop allocating ms->device_memory if the size would be 0 (and there are no memory devices ever). The case of "not supported by the machine" should barely pop up either way: if the machine doesn't support memory devices, it usually doesn't call the pre_plug handler ... Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: David Hildenbrand --- hw/mem/memory-device.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c index 1636db9679..49f86ec8a8 100644 --- a/hw/mem/memory-device.c +++ b/hw/mem/memory-device.c @@ -104,15 +104,10 @@ static uint64_t memory_device_get_free_addr(MachineSt= ate *ms, GSList *list =3D NULL, *item; Range as, new =3D range_empty; =20 - if (!ms->device_memory) { - error_setg(errp, "memory devices (e.g. for memory hotplug) are not= " - "supported by the machine"); - return 0; - } - - if (!memory_region_size(&ms->device_memory->mr)) { - error_setg(errp, "memory devices (e.g. for memory hotplug) are not= " - "enabled, please specify the maxmem option"); + if (!ms->device_memory || !memory_region_size(&ms->device_memory->mr))= { + error_setg(errp, "the configuration is not prepared for memory dev= ices" + " (e.g., for memory hotplug), consider specifying= the" + " maxmem option"); return 0; } range_init_nofail(&as, ms->device_memory->base, --=20 2.40.1 From nobody Fri May 17 07:07:46 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=1687524497; cv=none; d=zohomail.com; s=zohoarc; b=nCY96XrCd1MWlfhq3Zceis1tLt3Itqh0SopWpPo8BPQGzGU2OsVN4FaW1L5Pe1pXOAJGrfslqieDeaKp6WJ3wBVtTWlovs0houIIKjFR8jVAw9eLM85eYEDMsPZ78Y4aCtGY42zqK4hBYeWbsezfTICbnQpqMDEm6TWoIWaoKio= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1687524497; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=IZwikLA6WEV50lQOcrHMyhhRsDNuPxp6wdeJAdkCAGE=; b=liYN5QL8HzHMxrAzwKDlrY1lyijzR+AsPfs/tyJ6CA8S+AFJ62vBzwQ2Vau+MLB4FEq3JMJsbxDACIUdJ4QUYI+BFqco5C+7y4Ui6l/2Zw2DcdrgI2mGDwR3SoHNPZT7uZh0ry2Ca9EAPvFLUvdaM0+r8dcX51B5gRbTgxIidcs= 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 168752449703418.419392588823598; Fri, 23 Jun 2023 05:48:17 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qCgB7-0001aS-Jm; Fri, 23 Jun 2023 08:46:17 -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 1qCgB4-0001Va-4k for qemu-devel@nongnu.org; Fri, 23 Jun 2023 08:46: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 1qCgB2-0000ls-Jd for qemu-devel@nongnu.org; Fri, 23 Jun 2023 08:46:13 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-462-u7VM_4f2OTqAdV1SiAd8SQ-1; Fri, 23 Jun 2023 08:46:08 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BDA021C041A7; Fri, 23 Jun 2023 12:46:06 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.22.32.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id E979D1121314; Fri, 23 Jun 2023 12:46:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687524371; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IZwikLA6WEV50lQOcrHMyhhRsDNuPxp6wdeJAdkCAGE=; b=JizJGHT4LccpOBRfcL3SGqu5Faa616s4Z6HCYIGjQ7z/Z6QX3QIEpRc6CfInyY2GV54PJF mBBHii03YeHQPu2qpISAlMHsttOnKhysRkXGTaqwkui+5q0cBDa/YNmfRhCMBvtck+GYe7 QfTx88aejjTDlakhhH3RNRnuM37v48E= X-MC-Unique: u7VM_4f2OTqAdV1SiAd8SQ-1 From: David Hildenbrand To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, qemu-ppc@nongnu.org, Igor Mammedov , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Xiao Guangrong , David Hildenbrand , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Daniel Henrique Barboza , David Gibson , Eduardo Habkost , Greg Kurz , Harsh Prateek Bora , Marcel Apfelbaum , "Michael S. Tsirkin" , Paolo Bonzini , Peter Maydell , Richard Henderson , Song Gao , Xiaojuan Yang Subject: [PATCH v4 02/10] memory-device: Introduce machine_memory_devices_init() Date: Fri, 23 Jun 2023 14:45:45 +0200 Message-Id: <20230623124553.400585-3-david@redhat.com> In-Reply-To: <20230623124553.400585-1-david@redhat.com> References: <20230623124553.400585-1-david@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1687524498528100007 Let's intrduce a new helper that we will use to replace existing memory device setup code during machine initialization. We'll enforce that the size has to be > 0. Once all machines were converted, we'll only allocate ms->device_memory if the size > 0. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: David Hildenbrand --- hw/mem/memory-device.c | 14 ++++++++++++++ include/hw/boards.h | 2 ++ 2 files changed, 16 insertions(+) diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c index 49f86ec8a8..bb9d7c2a20 100644 --- a/hw/mem/memory-device.c +++ b/hw/mem/memory-device.c @@ -17,6 +17,7 @@ #include "qemu/range.h" #include "hw/virtio/vhost.h" #include "sysemu/kvm.h" +#include "exec/address-spaces.h" #include "trace.h" =20 static gint memory_device_addr_sort(gconstpointer a, gconstpointer b) @@ -328,6 +329,19 @@ uint64_t memory_device_get_region_size(const MemoryDev= iceState *md, return memory_region_size(mr); } =20 +void machine_memory_devices_init(MachineState *ms, hwaddr base, uint64_t s= ize) +{ + g_assert(size); + g_assert(!ms->device_memory); + ms->device_memory =3D g_new0(DeviceMemoryState, 1); + ms->device_memory->base =3D base; + + memory_region_init(&ms->device_memory->mr, OBJECT(ms), "device-memory", + size); + memory_region_add_subregion(get_system_memory(), ms->device_memory->ba= se, + &ms->device_memory->mr); +} + static const TypeInfo memory_device_info =3D { .name =3D TYPE_MEMORY_DEVICE, .parent =3D TYPE_INTERFACE, diff --git a/include/hw/boards.h b/include/hw/boards.h index a385010909..be06e8a41f 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -35,6 +35,8 @@ void machine_set_cpu_numa_node(MachineState *machine, Error **errp); void machine_parse_smp_config(MachineState *ms, const SMPConfiguration *config, Error **errp= ); +void machine_memory_devices_init(MachineState *ms, hwaddr base, uint64_t s= ize); + =20 /** * machine_class_allow_dynamic_sysbus_dev: Add type to list of valid devic= es --=20 2.40.1 From nobody Fri May 17 07:07:46 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=1687524506; cv=none; d=zohomail.com; s=zohoarc; b=VY9/+Mi01sHh/af7BZxqjcM2tflgp48/gpDtuSPuC1/w6ieNDWb4GqrcZ1DUy7d7CrKc35UzQ57ySahiw07lw6QPFyqNGDWYc2H+Lmy4LnAdFrl1UqpGRWLf+T7CIZk4gfJLI35l364NUsU1W4jSOTb1vXF3DhBWvUeQyxgQG1Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1687524506; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=jMrjKIwF2doZ7d+bJuI++1uBw5sxaxYx0JtiQurPOSc=; b=bV6Y4wEYDaW91OInOHsPkpj+Wu0q66tq3Nv+6VP3Ng2MWKMx3YKtAM4QxHayYFCUYaIT0MKADXoUM3Xlox3XK62UF45937+GxJvS+B2pRp6mddlQa15Ra/7X2vuoOUgsmADwURTeWkvbqvBxrc3HpV8q/KM9mahRl/q1udlSv+4= 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 1687524506445531.7603987039083; Fri, 23 Jun 2023 05:48:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qCgBA-0001cf-Q1; Fri, 23 Jun 2023 08:46:20 -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 1qCgB9-0001bw-F1 for qemu-devel@nongnu.org; Fri, 23 Jun 2023 08:46:19 -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 1qCgB7-0000oF-WD for qemu-devel@nongnu.org; Fri, 23 Jun 2023 08:46:19 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-526-05Tyf5rYNrWLnjp3yezIIw-1; Fri, 23 Jun 2023 08:46:11 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 31F501C04194; Fri, 23 Jun 2023 12:46:10 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.22.32.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0715C1121315; Fri, 23 Jun 2023 12:46:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687524377; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jMrjKIwF2doZ7d+bJuI++1uBw5sxaxYx0JtiQurPOSc=; b=QGpEmsYpDxDSMotU/UuyVMW0pg6A0bBoi/2YrXe9K6YP9kLEIdHsNeb92c/HoCZ9LuNPdh 0ljs0DM6Q2Eiw20BKwfmewvv790y6TI7fa7AthPWq54H/+SB3bahjVdpFSLdJ3ok5Jgq5y wynVEHV+oxExZNrl47JzZoobfhFldb4= X-MC-Unique: 05Tyf5rYNrWLnjp3yezIIw-1 From: David Hildenbrand To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, qemu-ppc@nongnu.org, Igor Mammedov , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Xiao Guangrong , David Hildenbrand , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Daniel Henrique Barboza , David Gibson , Eduardo Habkost , Greg Kurz , Harsh Prateek Bora , Marcel Apfelbaum , "Michael S. Tsirkin" , Paolo Bonzini , Peter Maydell , Richard Henderson , Song Gao , Xiaojuan Yang Subject: [PATCH v4 03/10] hw/arm/virt: Use machine_memory_devices_init() Date: Fri, 23 Jun 2023 14:45:46 +0200 Message-Id: <20230623124553.400585-4-david@redhat.com> In-Reply-To: <20230623124553.400585-1-david@redhat.com> References: <20230623124553.400585-1-david@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=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: 1687524508564100002 Let's use our new helper. We'll add the subregion to system RAM now earlier. That shouldn't matter, because the system RAM memory region should already be alive at that point. Cc: Peter Maydell Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: David Hildenbrand --- hw/arm/virt.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 9b9f7d9c68..087e7059c7 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -1817,10 +1817,7 @@ static void virt_set_memmap(VirtMachineState *vms, i= nt pa_bits) virt_set_high_memmap(vms, base, pa_bits); =20 if (device_memory_size > 0) { - ms->device_memory =3D g_malloc0(sizeof(*ms->device_memory)); - ms->device_memory->base =3D device_memory_base; - memory_region_init(&ms->device_memory->mr, OBJECT(vms), - "device-memory", device_memory_size); + machine_memory_devices_init(ms, device_memory_base, device_memory_= size); } } =20 @@ -2261,10 +2258,6 @@ static void machvirt_init(MachineState *machine) =20 memory_region_add_subregion(sysmem, vms->memmap[VIRT_MEM].base, machine->ram); - if (machine->device_memory) { - memory_region_add_subregion(sysmem, machine->device_memory->base, - &machine->device_memory->mr); - } =20 virt_flash_fdt(vms, sysmem, secure_sysmem ?: sysmem); =20 --=20 2.40.1 From nobody Fri May 17 07:07:46 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=1687524483; cv=none; d=zohomail.com; s=zohoarc; b=Ty89jlT9vYHb31YT/DgT3FU3jihrirXeznSlDnCS8OC5CgUBkW34/xSQG+PIz+RibI1VVPCtkqI0aCZqsrKDoWtOk0wqfUQH54ePmRPBHLnXjhmtCbDz27wn242ITksrK/t16bGyC/DcKD4D8AuDHdmyM9+4tcI8tN5qPtBCxKo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1687524483; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=DpY+YdyZgMDc1cbYNJcvvVMtZKgCSiKfLNMocUDN0eU=; b=gBTmvmB4gkRID9U5Vi5Mtq09fQBnHAC+rGzqKA9t2ZOniOqOzE+5m4D/5I7g53sO9+MZabZOgz+MwWppa8EOTsRAxja2ntjfCZ72PriNJBqSYJ3ENh/nY/kq1hlwJ5tRN3Ju9RQcf65bsiiiHWUR8Cv6hDcfBxjXRV1eNTRJir8= 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 1687524483180549.7377893612346; Fri, 23 Jun 2023 05:48:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qCgBD-0001fb-42; Fri, 23 Jun 2023 08:46:23 -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 1qCgBA-0001cj-QX for qemu-devel@nongnu.org; Fri, 23 Jun 2023 08:46:20 -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 1qCgB9-0000oN-4f for qemu-devel@nongnu.org; Fri, 23 Jun 2023 08:46:20 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-248-5zrWeMCiM8WKzYq_l65fIg-1; Fri, 23 Jun 2023 08:46:15 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6B6AD3C11A1C; Fri, 23 Jun 2023 12:46:14 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.22.32.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id 82DF21121314; Fri, 23 Jun 2023 12:46:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687524378; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DpY+YdyZgMDc1cbYNJcvvVMtZKgCSiKfLNMocUDN0eU=; b=aCwmeomGoEeIM0E0guhMKnMClprCKM+Qsv9IJw12isJpRsKx9JStwMScezjRUZuLbvjV+u lVKkjLMYdWfaDXZKfkyRWtWAs5wGKMWpU3tKs8J+IFCldUImq6a6ggl8JFqAeY7Xu9KaLX E0to+EP3MD11hlVvGTyHuR8qDSPudmI= X-MC-Unique: 5zrWeMCiM8WKzYq_l65fIg-1 From: David Hildenbrand To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, qemu-ppc@nongnu.org, Igor Mammedov , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Xiao Guangrong , David Hildenbrand , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Daniel Henrique Barboza , David Gibson , Eduardo Habkost , Greg Kurz , Harsh Prateek Bora , Marcel Apfelbaum , "Michael S. Tsirkin" , Paolo Bonzini , Peter Maydell , Richard Henderson , Song Gao , Xiaojuan Yang Subject: [PATCH v4 04/10] hw/ppc/spapr: Use machine_memory_devices_init() Date: Fri, 23 Jun 2023 14:45:47 +0200 Message-Id: <20230623124553.400585-5-david@redhat.com> In-Reply-To: <20230623124553.400585-1-david@redhat.com> References: <20230623124553.400585-1-david@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1687524484451100001 Let's use our new helper and stop always allocating ms->device_memory. There is no difference in common memory-device code anymore between ms->device_memory being NULL or the size being 0. So we only have to teach spapr code that ms->device_memory isn't always around. We can now modify two maxram_size checks to rely on ms->device_memory for detecting whether we have memory devices. Cc: Daniel Henrique Barboza Cc: "C=C3=A9dric Le Goater" Cc: David Gibson Cc: Greg Kurz Cc: Harsh Prateek Bora Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: David Hildenbrand --- hw/ppc/spapr.c | 37 +++++++++++++++++++------------------ hw/ppc/spapr_hcall.c | 2 +- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index dcb7f1c70a..b53aa4b5a8 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -546,10 +546,8 @@ static int spapr_dt_dynamic_reconfiguration_memory(Spa= prMachineState *spapr, cpu_to_be32(lmb_size & 0xffffffff)}; MemoryDeviceInfoList *dimms =3D NULL; =20 - /* - * Don't create the node if there is no device memory - */ - if (machine->ram_size =3D=3D machine->maxram_size) { + /* Don't create the node if there is no device memory. */ + if (!machine->device_memory) { return 0; } =20 @@ -859,16 +857,23 @@ static void spapr_dt_rtas(SpaprMachineState *spapr, v= oid *fdt) int rtas; GString *hypertas =3D g_string_sized_new(256); GString *qemu_hypertas =3D g_string_sized_new(256); - uint64_t max_device_addr =3D MACHINE(spapr)->device_memory->base + - memory_region_size(&MACHINE(spapr)->device_memory->mr); uint32_t lrdr_capacity[] =3D { - cpu_to_be32(max_device_addr >> 32), - cpu_to_be32(max_device_addr & 0xffffffff), + 0, + 0, cpu_to_be32(SPAPR_MEMORY_BLOCK_SIZE >> 32), cpu_to_be32(SPAPR_MEMORY_BLOCK_SIZE & 0xffffffff), cpu_to_be32(ms->smp.max_cpus / ms->smp.threads), }; =20 + /* Do we have device memory? */ + if (MACHINE(spapr)->device_memory) { + uint64_t max_device_addr =3D MACHINE(spapr)->device_memory->base + + memory_region_size(&MACHINE(spapr)->device_memory->mr); + + lrdr_capacity[0] =3D cpu_to_be32(max_device_addr >> 32); + lrdr_capacity[1] =3D cpu_to_be32(max_device_addr & 0xffffffff); + } + _FDT(rtas =3D fdt_add_subnode(fdt, 0, "rtas")); =20 /* hypertas */ @@ -2454,6 +2459,7 @@ static void spapr_create_lmb_dr_connectors(SpaprMachi= neState *spapr) uint32_t nr_lmbs =3D (machine->maxram_size - machine->ram_size)/lmb_si= ze; int i; =20 + g_assert(!nr_lmbs || machine->device_memory); for (i =3D 0; i < nr_lmbs; i++) { uint64_t addr; =20 @@ -2866,12 +2872,11 @@ static void spapr_machine_init(MachineState *machin= e) /* map RAM */ memory_region_add_subregion(sysmem, 0, machine->ram); =20 - /* always allocate the device memory information */ - machine->device_memory =3D g_malloc0(sizeof(*machine->device_memory)); - /* initialize hotplug memory address space */ if (machine->ram_size < machine->maxram_size) { ram_addr_t device_mem_size =3D machine->maxram_size - machine->ram= _size; + hwaddr device_mem_base; + /* * Limit the number of hotpluggable memory slots to half the number * slots that KVM supports, leaving the other half for PCI and oth= er @@ -2890,12 +2895,8 @@ static void spapr_machine_init(MachineState *machine) exit(1); } =20 - machine->device_memory->base =3D ROUND_UP(machine->ram_size, - SPAPR_DEVICE_MEM_ALIGN); - memory_region_init(&machine->device_memory->mr, OBJECT(spapr), - "device-memory", device_mem_size); - memory_region_add_subregion(sysmem, machine->device_memory->base, - &machine->device_memory->mr); + device_mem_base =3D ROUND_UP(machine->ram_size, SPAPR_DEVICE_MEM_A= LIGN); + machine_memory_devices_init(machine, device_mem_base, device_mem_s= ize); } =20 if (smc->dr_lmb_enabled) { @@ -5109,7 +5110,7 @@ static bool phb_placement_2_7(SpaprMachineState *spap= r, uint32_t index, int i; =20 /* Do we have device memory? */ - if (MACHINE(spapr)->maxram_size > ram_top) { + if (MACHINE(spapr)->device_memory) { /* Can't just use maxram_size, because there may be an * alignment gap between normal and device memory regions */ diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c index b904755575..1dd32f340f 100644 --- a/hw/ppc/spapr_hcall.c +++ b/hw/ppc/spapr_hcall.c @@ -31,7 +31,7 @@ bool is_ram_address(SpaprMachineState *spapr, hwaddr addr) if (addr < machine->ram_size) { return true; } - if ((addr >=3D dms->base) + if (dms && (addr >=3D dms->base) && ((addr - dms->base) < memory_region_size(&dms->mr))) { return true; } --=20 2.40.1 From nobody Fri May 17 07:07:46 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=1687524415; cv=none; d=zohomail.com; s=zohoarc; b=T2HZ7DX9wbTZcb9++SFuyHme2iI9JmvBVwCr6OUDaUe5s5WA3618dORm0cvPkkcCUSqO8io66lMpOiLtiSC8Bs4rpEvxKKW2EM1qg29FE/ZKQ6Db9U3DcNoMgoAJhuj73NX+FjjAbPeYXeFrgBhbW8u23XNLM8bFQRWl0rulb+E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1687524415; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=4/VjV4Ehnq9V+Qr7lMovEi6GKY2Z5BCQx1wXui6RiEQ=; b=Oq5B5CjluJFZX/snqAnRWk6/POs2xozFJBJ2xDfm/+RRVqeoCVCfSqNdULBPIXhwWSBC+J+A3UMUCiiHh+rCdoBOR6esoUjYNV6sm/lz5M8xxegU/AIHCFdAakU3hUFMT60Km1oJkHp47uqlRN5IuvNHk+RAvGQeneOqtw8nCZc= 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 1687524415454136.04868113964937; Fri, 23 Jun 2023 05:46:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qCgBJ-0001kG-8W; Fri, 23 Jun 2023 08:46:29 -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 1qCgBI-0001jY-2b for qemu-devel@nongnu.org; Fri, 23 Jun 2023 08:46:28 -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 1qCgBG-0000ph-Ae for qemu-devel@nongnu.org; Fri, 23 Jun 2023 08:46:27 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-154-SymYy_hNNT2dx7TnjxJ0SA-1; Fri, 23 Jun 2023 08:46:21 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C3CC1185A794; Fri, 23 Jun 2023 12:46:18 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.22.32.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id CB8EA1121315; Fri, 23 Jun 2023 12:46:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687524385; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4/VjV4Ehnq9V+Qr7lMovEi6GKY2Z5BCQx1wXui6RiEQ=; b=QvMC4zpBg0Rst5+ri8ziuEsMbGkm4wchQi9eAXbKmPULOKVRqmKhUKzkzenUdpStT3CC3U 5NQjeqnZ13dwEB1WFLcTNTe084wyABHqY89s4hwr9bnrxMJUwFb0VUr/uSTdDWgqu2b3ws 3UXDnCS1yWF0kMq5koPk7nzit52024k= X-MC-Unique: SymYy_hNNT2dx7TnjxJ0SA-1 From: David Hildenbrand To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, qemu-ppc@nongnu.org, Igor Mammedov , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Xiao Guangrong , David Hildenbrand , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Daniel Henrique Barboza , David Gibson , Eduardo Habkost , Greg Kurz , Harsh Prateek Bora , Marcel Apfelbaum , "Michael S. Tsirkin" , Paolo Bonzini , Peter Maydell , Richard Henderson , Song Gao , Xiaojuan Yang Subject: [PATCH v4 05/10] hw/loongarch/virt: Use machine_memory_devices_init() Date: Fri, 23 Jun 2023 14:45:48 +0200 Message-Id: <20230623124553.400585-6-david@redhat.com> In-Reply-To: <20230623124553.400585-1-david@redhat.com> References: <20230623124553.400585-1-david@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1687524417198100001 Let's use our new helper. While at it, use VIRT_HIGHMEM_BASE. Cc: Xiaojuan Yang Cc: Song Gao Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Song Gao Signed-off-by: David Hildenbrand --- hw/loongarch/virt.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c index ca8824b6ef..4a42a8119a 100644 --- a/hw/loongarch/virt.c +++ b/hw/loongarch/virt.c @@ -863,8 +863,8 @@ static void loongarch_init(MachineState *machine) =20 /* initialize device memory address space */ if (machine->ram_size < machine->maxram_size) { - machine->device_memory =3D g_malloc0(sizeof(*machine->device_memor= y)); ram_addr_t device_mem_size =3D machine->maxram_size - machine->ram= _size; + hwaddr device_mem_base; =20 if (machine->ram_slots > ACPI_MAX_RAM_SLOTS) { error_report("unsupported amount of memory slots: %"PRIu64, @@ -879,14 +879,8 @@ static void loongarch_init(MachineState *machine) exit(EXIT_FAILURE); } /* device memory base is the top of high memory address. */ - machine->device_memory->base =3D 0x90000000 + highram_size; - machine->device_memory->base =3D - ROUND_UP(machine->device_memory->base, 1 * GiB); - - memory_region_init(&machine->device_memory->mr, OBJECT(lams), - "device-memory", device_mem_size); - memory_region_add_subregion(address_space_mem, machine->device_mem= ory->base, - &machine->device_memory->mr); + device_mem_base =3D ROUND_UP(VIRT_HIGHMEM_BASE + highram_size, 1 *= GiB); + machine_memory_devices_init(machine, device_mem_base, device_mem_s= ize); } =20 /* Add isa io region */ --=20 2.40.1 From nobody Fri May 17 07:07:46 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=1687524502; cv=none; d=zohomail.com; s=zohoarc; b=hR13k/WhsmWkn5uhfieXCDrKZMG1xrdIsNcpOzcZSoLJaBNG6/YVcxuLDsWQ6xy2EC8w3UTwqOJr5ooS700Dazoze+BkwvSkYE8Rzaj5JdIJdeutF8AdK0fSL5mOlaxfl8Q8Bf+pFXn7n3i3pTN3eTfxq3eMCMMc/Y6vnM+aMZA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1687524502; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=HS+rn+rSOJ+bc6A+utNdOfK4JSbfjcwPWa2L9WtvCog=; b=UPOhPvAHQHXocHTr4TufNJjbJbJzXbw8t6KzR2TaYiSnSpldd4Y13pStHvpc5peWlOMd5GL1fjqf90RbVOUYFdz5/IBMFdBGWo2eYCJKw8VJrVP2Cb+6ShQTrfS/MzyuZTzcRto/niYC0G4xnKloeu7u6JnuePJAaaQLe25v4kQ= 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 1687524502436141.11823170870287; Fri, 23 Jun 2023 05:48:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qCgBN-0001rc-1k; Fri, 23 Jun 2023 08:46: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 1qCgBK-0001oY-Qf for qemu-devel@nongnu.org; Fri, 23 Jun 2023 08:46:30 -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 1qCgBI-0000qA-PT for qemu-devel@nongnu.org; Fri, 23 Jun 2023 08:46:30 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-596-eIg2eubYNEGV-7ttExq-jw-1; Fri, 23 Jun 2023 08:46:23 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C5D8E8CC201; Fri, 23 Jun 2023 12:46:22 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.22.32.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0A8F01121315; Fri, 23 Jun 2023 12:46:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687524388; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HS+rn+rSOJ+bc6A+utNdOfK4JSbfjcwPWa2L9WtvCog=; b=GwBeqsHf53jjGL1gHAGzCiKLaz05Ckqk8CC5ulCbI07uGTuqqu7vWCjzHy0qXd9/hd4njm rjH7m3QIymhygbM3l+nsD0U4aLuAaU6Cy18FZxGBFD5GpZLaYk2VGBrLZpfkHMhQVhXyUD e/6F+vSHsNIPg1s/OLDBvexCkt1l+Pw= X-MC-Unique: eIg2eubYNEGV-7ttExq-jw-1 From: David Hildenbrand To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, qemu-ppc@nongnu.org, Igor Mammedov , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Xiao Guangrong , David Hildenbrand , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Daniel Henrique Barboza , David Gibson , Eduardo Habkost , Greg Kurz , Harsh Prateek Bora , Marcel Apfelbaum , "Michael S. Tsirkin" , Paolo Bonzini , Peter Maydell , Richard Henderson , Song Gao , Xiaojuan Yang Subject: [PATCH v4 06/10] hw/i386/pc: Use machine_memory_devices_init() Date: Fri, 23 Jun 2023 14:45:49 +0200 Message-Id: <20230623124553.400585-7-david@redhat.com> In-Reply-To: <20230623124553.400585-1-david@redhat.com> References: <20230623124553.400585-1-david@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=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: 1687524504556100007 Let's use our new helper and stop always allocating ms->device_memory. Once allcoated, we're sure that the size > 0 and that the base was initialized. Adjust the code in pc_memory_init() to check for machine->device_memory instead of pcmc->has_reserved_memory and machine->device_memory->base. Cc: Paolo Bonzini Cc: Richard Henderson Cc: Eduardo Habkost Cc: "Michael S. Tsirkin" Cc: Marcel Apfelbaum Reviewed-by: Philippe Mathieu-Daud=C3=A9 Acked-by: Michael S. Tsirkin Signed-off-by: David Hildenbrand --- hw/i386/pc.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index fc52772fdd..a1dbece31e 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1039,13 +1039,11 @@ void pc_memory_init(PCMachineState *pcms, exit(EXIT_FAILURE); } =20 - /* always allocate the device memory information */ - machine->device_memory =3D g_malloc0(sizeof(*machine->device_memory)); - /* initialize device memory address space */ if (pcmc->has_reserved_memory && (machine->ram_size < machine->maxram_size)) { ram_addr_t device_mem_size; + hwaddr device_mem_base; =20 if (machine->ram_slots > ACPI_MAX_RAM_SLOTS) { error_report("unsupported amount of memory slots: %"PRIu64, @@ -1060,19 +1058,14 @@ void pc_memory_init(PCMachineState *pcms, exit(EXIT_FAILURE); } =20 - pc_get_device_memory_range(pcms, &machine->device_memory->base, &d= evice_mem_size); + pc_get_device_memory_range(pcms, &device_mem_base, &device_mem_siz= e); =20 - if ((machine->device_memory->base + device_mem_size) < - device_mem_size) { + if (device_mem_base + device_mem_size < device_mem_size) { error_report("unsupported amount of maximum memory: " RAM_ADDR= _FMT, machine->maxram_size); exit(EXIT_FAILURE); } - - memory_region_init(&machine->device_memory->mr, OBJECT(pcms), - "device-memory", device_mem_size); - memory_region_add_subregion(system_memory, machine->device_memory-= >base, - &machine->device_memory->mr); + machine_memory_devices_init(machine, device_mem_base, device_mem_s= ize); } =20 if (pcms->cxl_devices_state.is_enabled) { @@ -1120,7 +1113,7 @@ void pc_memory_init(PCMachineState *pcms, =20 rom_set_fw(fw_cfg); =20 - if (pcmc->has_reserved_memory && machine->device_memory->base) { + if (machine->device_memory) { uint64_t *val =3D g_malloc(sizeof(*val)); PCMachineClass *pcmc =3D PC_MACHINE_GET_CLASS(pcms); uint64_t res_mem_end =3D machine->device_memory->base; --=20 2.40.1 From nobody Fri May 17 07:07:46 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=1687524411; cv=none; d=zohomail.com; s=zohoarc; b=NNjpTJur7F4hCSDY+6Wjfb9SxfkNXBRJyrW2F+v7yrwU/8Lpjt6sHx8Z9fcSaQXezbxTgjn3tjgqgc69vFlLbjz80ZPv6zKAf7HRMswdAIsYP4DtgC6BH8+7n1qrJeUFdoyHOH4xJmAMFThGbmVgowkec7cwfb8WLNMIsbck/eU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1687524411; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=OD4aiA7h6MlijuzsPBGwt+/c6jfgut3ElqXIr9TIDpo=; b=HUiZFgapzMiu87GDzwG4RGAzRv1gsL0HjcVSor/I3LnRFON+V1GKfreIsCCDPozUq9eDdJdf9cNz42m/DIkCllol29DYGdx52cMcVY+hI5Crd6EkvSLIZCfhKdNWkeu8Lkts5ZIGPlKSZe7L58tp/iwtmdr8CoesMV8e1sVXsi8= 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 1687524411218696.7519850896509; Fri, 23 Jun 2023 05:46:51 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qCgBP-0001si-Jy; Fri, 23 Jun 2023 08:46:35 -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 1qCgBN-0001rd-13 for qemu-devel@nongnu.org; Fri, 23 Jun 2023 08:46: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 1qCgBL-0000qp-Fc for qemu-devel@nongnu.org; Fri, 23 Jun 2023 08:46:32 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-227-UB6ke3MAMoydfKRrV0EBHg-1; Fri, 23 Jun 2023 08:46:27 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 538A01044590; Fri, 23 Jun 2023 12:46:26 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.22.32.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1F6F21121314; Fri, 23 Jun 2023 12:46:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687524390; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OD4aiA7h6MlijuzsPBGwt+/c6jfgut3ElqXIr9TIDpo=; b=MuEPfxqFryKqnYD6blHlRToKUsOE13gvCG6Jn31RJCuoE6sgR4HS2eZSmBN0wjsXNMKE93 XbgEq9E6uPlt6DWViakQfbeus+o8lzyERxjf4A27dRPM+7vbm9BeVBqMWz2RUPPZF3oHgW 0+B3u3Pwn45E/vCivfoUghUMbVw04Yk= X-MC-Unique: UB6ke3MAMoydfKRrV0EBHg-1 From: David Hildenbrand To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, qemu-ppc@nongnu.org, Igor Mammedov , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Xiao Guangrong , David Hildenbrand , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Daniel Henrique Barboza , David Gibson , Eduardo Habkost , Greg Kurz , Harsh Prateek Bora , Marcel Apfelbaum , "Michael S. Tsirkin" , Paolo Bonzini , Peter Maydell , Richard Henderson , Song Gao , Xiaojuan Yang Subject: [PATCH v4 07/10] hw/i386/acpi-build: Rely on machine->device_memory when building SRAT Date: Fri, 23 Jun 2023 14:45:50 +0200 Message-Id: <20230623124553.400585-8-david@redhat.com> In-Reply-To: <20230623124553.400585-1-david@redhat.com> References: <20230623124553.400585-1-david@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=david@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1687524411883100001 We're already looking at machine->device_memory when calling build_srat_memory(), so let's simply avoid going via PC_MACHINE_DEVMEM_REGION_SIZE to get the size and rely on machine->device_memory directly. Once machine->device_memory is set, we know that the size > 0. The code now looks much more similar the hw/arm/virt-acpi-build.c variant. Cc: Paolo Bonzini Cc: Richard Henderson Cc: Eduardo Habkost Cc: "Michael S. Tsirkin" Cc: Marcel Apfelbaum Reviewed-by: Philippe Mathieu-Daud=C3=A9 Acked-by: Michael S. Tsirkin Signed-off-by: David Hildenbrand --- hw/i386/acpi-build.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index 512162003b..9c74fa17ad 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -1950,12 +1950,8 @@ build_srat(GArray *table_data, BIOSLinker *linker, M= achineState *machine) MachineClass *mc =3D MACHINE_GET_CLASS(machine); X86MachineState *x86ms =3D X86_MACHINE(machine); const CPUArchIdList *apic_ids =3D mc->possible_cpu_arch_ids(machine); - PCMachineState *pcms =3D PC_MACHINE(machine); int nb_numa_nodes =3D machine->numa_state->num_nodes; NodeInfo *numa_info =3D machine->numa_state->nodes; - ram_addr_t hotpluggable_address_space_size =3D - object_property_get_int(OBJECT(pcms), PC_MACHINE_DEVMEM_REGION_SIZ= E, - NULL); AcpiTable table =3D { .sig =3D "SRAT", .rev =3D 1, .oem_id =3D x86ms->= oem_id, .oem_table_id =3D x86ms->oem_table_id }; =20 @@ -2071,9 +2067,10 @@ build_srat(GArray *table_data, BIOSLinker *linker, M= achineState *machine) * Memory devices may override proximity set by this entry, * providing _PXM method if necessary. */ - if (hotpluggable_address_space_size) { + if (machine->device_memory) { build_srat_memory(table_data, machine->device_memory->base, - hotpluggable_address_space_size, nb_numa_nodes -= 1, + memory_region_size(&machine->device_memory->mr), + nb_numa_nodes - 1, MEM_AFFINITY_HOTPLUGGABLE | MEM_AFFINITY_ENABLED= ); } =20 --=20 2.40.1 From nobody Fri May 17 07:07:46 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=1687524498; cv=none; d=zohomail.com; s=zohoarc; b=jHAIY5Z22KupI5iHriwPVhBZZWRKGI7u545A0PkDMAsb8Z/WWbFuabmGUiJ6IwkVPwaMlyP2WCb8TxjvFj3fgh6+CJStPrUb/kICz4uWdqZIkrBw2eOofa1iOJISgEVo0KG5IaMhW7wz+RoZzlSD7A9vFOm8oouQ51LWyU9PQiM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1687524498; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=o0nk12NyOdxSa7W1XLwJ5BYEwzU/9oz2vOKSkY29znw=; b=MAWnL8Kp8EyVq7gv6BX2V8zwydv3CE500fclzAzE0plmMuIWL7qGMdOWSN/Di9iVwZQ+XPWuIZGR7HzJlMMRlRsiXgl94ElvutJSvwtHmp4CzdxsWWAb1VxZShceNiMr2l1MOwW8k4gTH6jdDSxie/5lmMQtntrwkpuD6gkiS+o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1687524498552964.8755897082029; Fri, 23 Jun 2023 05:48:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qCgBq-0002H7-PY; Fri, 23 Jun 2023 08:47: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 1qCgBe-00027q-AJ for qemu-devel@nongnu.org; Fri, 23 Jun 2023 08:46:53 -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 1qCgBc-0000tX-0f for qemu-devel@nongnu.org; Fri, 23 Jun 2023 08:46:50 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-647-QqdGj4DfN6KkY6mUVyiphQ-1; Fri, 23 Jun 2023 08:46:31 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 65C2880123E; Fri, 23 Jun 2023 12:46:30 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.22.32.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id AF0AB1121314; Fri, 23 Jun 2023 12:46:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687524406; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=o0nk12NyOdxSa7W1XLwJ5BYEwzU/9oz2vOKSkY29znw=; b=MWMl7FbTPxK1mNoPRYzdeP/DfUtXDBeCNWeJfxpnI70IHE7/oJtB3oYGdsrVuPqjAJxOvR y8Dd3SBGyZr8mYJE6HCtl0xY55scyRMARM8I0AHcvI3K2agjXqVyGtY+ltoSAlyHCFmXeN cwMSyxIhb/bDr75gpv0Pch+gFtW801U= X-MC-Unique: QqdGj4DfN6KkY6mUVyiphQ-1 From: David Hildenbrand To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, qemu-ppc@nongnu.org, Igor Mammedov , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Xiao Guangrong , David Hildenbrand , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Daniel Henrique Barboza , David Gibson , Eduardo Habkost , Greg Kurz , Harsh Prateek Bora , Marcel Apfelbaum , "Michael S. Tsirkin" , Paolo Bonzini , Peter Maydell , Richard Henderson , Song Gao , Xiaojuan Yang Subject: [PATCH v4 08/10] hw/i386/pc: Remove PC_MACHINE_DEVMEM_REGION_SIZE Date: Fri, 23 Jun 2023 14:45:51 +0200 Message-Id: <20230623124553.400585-9-david@redhat.com> In-Reply-To: <20230623124553.400585-1-david@redhat.com> References: <20230623124553.400585-1-david@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=david@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=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: 1687524500534100011 There are no remaining users in the tree. Libvirt never used that property and a quick internet search revealed no other users. Further, we renamed that property already in commit f2ffbe2b7dd0 ("pc: rename "hotplug memory" terminology to "device memory"") without anybody complaining. So let's just get rid of it. Cc: Paolo Bonzini Cc: Richard Henderson Cc: Eduardo Habkost Cc: "Michael S. Tsirkin" Cc: Marcel Apfelbaum Reviewed-by: Philippe Mathieu-Daud=C3=A9 Acked-by: Michael S. Tsirkin Signed-off-by: David Hildenbrand --- hw/i386/pc.c | 19 ------------------- include/hw/i386/pc.h | 1 - 2 files changed, 20 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index a1dbece31e..900499d876 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1649,21 +1649,6 @@ static HotplugHandler *pc_get_hotplug_handler(Machin= eState *machine, return NULL; } =20 -static void -pc_machine_get_device_memory_region_size(Object *obj, Visitor *v, - const char *name, void *opaque, - Error **errp) -{ - MachineState *ms =3D MACHINE(obj); - int64_t value =3D 0; - - if (ms->device_memory) { - value =3D memory_region_size(&ms->device_memory->mr); - } - - visit_type_int(v, name, &value, errp); -} - static void pc_machine_get_vmport(Object *obj, Visitor *v, const char *nam= e, void *opaque, Error **errp) { @@ -1975,10 +1960,6 @@ static void pc_machine_class_init(ObjectClass *oc, v= oid *data) object_class_property_set_description(oc, PC_MACHINE_MAX_RAM_BELOW_4G, "Maximum ram below the 4G boundary (32bit boundary)"); =20 - object_class_property_add(oc, PC_MACHINE_DEVMEM_REGION_SIZE, "int", - pc_machine_get_device_memory_region_size, NULL, - NULL, NULL); - object_class_property_add(oc, PC_MACHINE_VMPORT, "OnOffAuto", pc_machine_get_vmport, pc_machine_set_vmport, NULL, NULL); diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index c661e9cc80..6c9ad2d132 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -60,7 +60,6 @@ typedef struct PCMachineState { =20 #define PC_MACHINE_ACPI_DEVICE_PROP "acpi-device" #define PC_MACHINE_MAX_RAM_BELOW_4G "max-ram-below-4g" -#define PC_MACHINE_DEVMEM_REGION_SIZE "device-memory-region-size" #define PC_MACHINE_VMPORT "vmport" #define PC_MACHINE_SMBUS "smbus" #define PC_MACHINE_SATA "sata" --=20 2.40.1 From nobody Fri May 17 07:07:46 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=1687524491; cv=none; d=zohomail.com; s=zohoarc; b=PXIgGciEqGzjoEXQonEqO001/CMBk/sjOtjta1Xpo3m2INmtNdYEwNUPuy995N7UwDW9y4lt3s1yTc0NM83nOkRh1S/G0fLjWqhbsPfsUhG+xjPbSmZlPS451J7lheHK4nz7+aq3D2gpF4eX65erzIkg3Kytt87LPkTwo7VEFGk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1687524491; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=EC4/yct8sIAw5ODpRfK2OCvTa9g83NRaxOMLluErnc8=; b=Bf4Llq36cAq22xlcZib0URgjaBjbsLBeeyAj1zX+9PgYk+idjJ8KrScXOc+f0phGMc+U/WC1uKvZ86umhTCrNw8GLGi8vTAC1XvVMFQWhM5hJlE/gfXUXmqwt+dh//HWO1dczq76o8rY6fm995/S/WksEyjbaVBGSmWArpRdGPU= 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 168752449165112.442292815653673; Fri, 23 Jun 2023 05:48:11 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qCgBr-0002U7-Ub; Fri, 23 Jun 2023 08:47:04 -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 1qCgBW-000221-MW for qemu-devel@nongnu.org; Fri, 23 Jun 2023 08:46:45 -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 1qCgBT-0000sJ-9Z for qemu-devel@nongnu.org; Fri, 23 Jun 2023 08:46:40 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-45-PYd8v78vOnmHtC99LKd82w-1; Fri, 23 Jun 2023 08:46:35 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 32B7529AA3B6; Fri, 23 Jun 2023 12:46:34 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.22.32.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id C55991121314; Fri, 23 Jun 2023 12:46:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687524398; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EC4/yct8sIAw5ODpRfK2OCvTa9g83NRaxOMLluErnc8=; b=W2jDDy1pcMsIjrqfpUXdJ0smAix7NwWrN82T5ztkgElq7WzU/g5HChYeJKmSFabuD9I44y l8lRGZn13M9ap8ZScqjX2ZdIrKdAMGNzZCuaxPoi8imVh2aAoo4oqnwdhBpRvXej2vlkVs iLMHBlgpSQMHjTFkA7YJOHCe/mZXTAg= X-MC-Unique: PYd8v78vOnmHtC99LKd82w-1 From: David Hildenbrand To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, qemu-ppc@nongnu.org, Igor Mammedov , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Xiao Guangrong , David Hildenbrand , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Daniel Henrique Barboza , David Gibson , Eduardo Habkost , Greg Kurz , Harsh Prateek Bora , Marcel Apfelbaum , "Michael S. Tsirkin" , Paolo Bonzini , Peter Maydell , Richard Henderson , Song Gao , Xiaojuan Yang Subject: [PATCH v4 09/10] memory-device: Refactor memory_device_pre_plug() Date: Fri, 23 Jun 2023 14:45:52 +0200 Message-Id: <20230623124553.400585-10-david@redhat.com> In-Reply-To: <20230623124553.400585-1-david@redhat.com> References: <20230623124553.400585-1-david@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=david@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=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: 1687524492460100001 Let's move memory_device_check_addable() and basic checks out of memory_device_get_free_addr() directly into memory_device_pre_plug(). Separating basic checks from address assignment is cleaner and prepares for further changes. As all memory device users now use memory_devices_init(), and that function enforces that the size is 0, we can drop the check for an empty region. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: David Hildenbrand --- hw/mem/memory-device.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c index bb9d7c2a20..00c7755557 100644 --- a/hw/mem/memory-device.c +++ b/hw/mem/memory-device.c @@ -69,9 +69,10 @@ static int memory_device_used_region_size(Object *obj, v= oid *opaque) return 0; } =20 -static void memory_device_check_addable(MachineState *ms, uint64_t size, +static void memory_device_check_addable(MachineState *ms, MemoryRegion *mr, Error **errp) { + const uint64_t size =3D memory_region_size(mr); uint64_t used_region_size =3D 0; =20 /* we will need a new memory slot for kvm and vhost */ @@ -101,16 +102,9 @@ static uint64_t memory_device_get_free_addr(MachineSta= te *ms, uint64_t align, uint64_t size, Error **errp) { - Error *err =3D NULL; GSList *list =3D NULL, *item; Range as, new =3D range_empty; =20 - if (!ms->device_memory || !memory_region_size(&ms->device_memory->mr))= { - error_setg(errp, "the configuration is not prepared for memory dev= ices" - " (e.g., for memory hotplug), consider specifying= the" - " maxmem option"); - return 0; - } range_init_nofail(&as, ms->device_memory->base, memory_region_size(&ms->device_memory->mr)); =20 @@ -122,12 +116,6 @@ static uint64_t memory_device_get_free_addr(MachineSta= te *ms, align); } =20 - memory_device_check_addable(ms, size, &err); - if (err) { - error_propagate(errp, err); - return 0; - } - if (hint && !QEMU_IS_ALIGNED(*hint, align)) { error_setg(errp, "address must be aligned to 0x%" PRIx64 " bytes", align); @@ -251,11 +239,23 @@ void memory_device_pre_plug(MemoryDeviceState *md, Ma= chineState *ms, uint64_t addr, align =3D 0; MemoryRegion *mr; =20 + if (!ms->device_memory) { + error_setg(errp, "the configuration is not prepared for memory dev= ices" + " (e.g., for memory hotplug), consider specifying= the" + " maxmem option"); + return; + } + mr =3D mdc->get_memory_region(md, &local_err); if (local_err) { goto out; } =20 + memory_device_check_addable(ms, mr, &local_err); + if (local_err) { + goto out; + } + if (legacy_align) { align =3D *legacy_align; } else { --=20 2.40.1 From nobody Fri May 17 07:07:46 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=1687524500; cv=none; d=zohomail.com; s=zohoarc; b=YIKcKQzPU6TNqnRyk0cHGDXKFqd6a+3ho1tP+iUNUyCZX452a2hkVtX0w3vK+Jegonyts0/UaPnuPqtt5icvzf/sCBu8aVvHTgC3aK+EoruuYpqD2lWxgZSyYhIGiLuV/C2hgleuiJZy6bWYWT+YWy5BZdKCIuOnGlKRBsQlosw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1687524500; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=nGACEA2aET2msOqUDIABoGnBLI/7CCZG+nBmgrENL+k=; b=je7713ICj5z07IjcSIV2c/6JFEGzR9kPHYoTucqEHgQT7umuTwuXixQ2lMePE1/98qA7bE8BsqdUfOPQW0byVDGqsUTBhv11xmkpUiBIpV/Ec8k6SQhMnNQOTMH4pajw79JsRSWj1uv4IN8DnVfV2x8qXXnvH5S8Ywc5DUR/vl4= 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 1687524500777959.3239610225995; Fri, 23 Jun 2023 05:48:20 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qCgBu-0002fT-12; Fri, 23 Jun 2023 08:47: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 1qCgBc-00027P-8K for qemu-devel@nongnu.org; Fri, 23 Jun 2023 08:46:53 -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 1qCgBX-0000sv-7Z for qemu-devel@nongnu.org; Fri, 23 Jun 2023 08:46:44 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-47-VxWzc_S0MJKGCN8lzDVvDA-1; Fri, 23 Jun 2023 08:46:39 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 118653C11A0E; Fri, 23 Jun 2023 12:46:38 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.22.32.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id 91F641121314; Fri, 23 Jun 2023 12:46:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687524402; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nGACEA2aET2msOqUDIABoGnBLI/7CCZG+nBmgrENL+k=; b=NG7XkjdPb9mLOS88eo9XMreWvAzfchImrpyytGzabfGBDOMILdUun9wN1VI2H/dmCdhB61 dTDzL65ljPQT7/jLNF4DEbB9D6pVeNyvUiOgSLQw8yDEtEMvnD0YjIkecalZVltZ7Fkcn/ IlW4KWdk/XDIvf48RScUpI5H/0ge7Go= X-MC-Unique: VxWzc_S0MJKGCN8lzDVvDA-1 From: David Hildenbrand To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, qemu-ppc@nongnu.org, Igor Mammedov , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Xiao Guangrong , David Hildenbrand , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Daniel Henrique Barboza , David Gibson , Eduardo Habkost , Greg Kurz , Harsh Prateek Bora , Marcel Apfelbaum , "Michael S. Tsirkin" , Paolo Bonzini , Peter Maydell , Richard Henderson , Song Gao , Xiaojuan Yang Subject: [PATCH v4 10/10] memory-device: Track used region size in DeviceMemoryState Date: Fri, 23 Jun 2023 14:45:53 +0200 Message-Id: <20230623124553.400585-11-david@redhat.com> In-Reply-To: <20230623124553.400585-1-david@redhat.com> References: <20230623124553.400585-1-david@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=david@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=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: 1687524502618100001 Let's avoid iterating over all devices and simply track it in the DeviceMemoryState. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: David Hildenbrand --- hw/mem/memory-device.c | 22 +++------------------- include/hw/boards.h | 2 ++ 2 files changed, 5 insertions(+), 19 deletions(-) diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c index 00c7755557..667d56bd29 100644 --- a/hw/mem/memory-device.c +++ b/hw/mem/memory-device.c @@ -52,28 +52,11 @@ static int memory_device_build_list(Object *obj, void *= opaque) return 0; } =20 -static int memory_device_used_region_size(Object *obj, void *opaque) -{ - uint64_t *size =3D opaque; - - if (object_dynamic_cast(obj, TYPE_MEMORY_DEVICE)) { - const DeviceState *dev =3D DEVICE(obj); - const MemoryDeviceState *md =3D MEMORY_DEVICE(obj); - - if (dev->realized) { - *size +=3D memory_device_get_region_size(md, &error_abort); - } - } - - object_child_foreach(obj, memory_device_used_region_size, opaque); - return 0; -} - static void memory_device_check_addable(MachineState *ms, MemoryRegion *mr, Error **errp) { + const uint64_t used_region_size =3D ms->device_memory->used_region_siz= e; const uint64_t size =3D memory_region_size(mr); - uint64_t used_region_size =3D 0; =20 /* we will need a new memory slot for kvm and vhost */ if (kvm_enabled() && !kvm_has_free_slot(ms)) { @@ -86,7 +69,6 @@ static void memory_device_check_addable(MachineState *ms,= MemoryRegion *mr, } =20 /* will we exceed the total amount of memory specified */ - memory_device_used_region_size(OBJECT(ms), &used_region_size); if (used_region_size + size < used_region_size || used_region_size + size > ms->maxram_size - ms->ram_size) { error_setg(errp, "not enough space, currently 0x%" PRIx64 @@ -292,6 +274,7 @@ void memory_device_plug(MemoryDeviceState *md, MachineS= tate *ms) mr =3D mdc->get_memory_region(md, &error_abort); g_assert(ms->device_memory); =20 + ms->device_memory->used_region_size +=3D memory_region_size(mr); memory_region_add_subregion(&ms->device_memory->mr, addr - ms->device_memory->base, mr); trace_memory_device_plug(DEVICE(md)->id ? DEVICE(md)->id : "", addr); @@ -310,6 +293,7 @@ void memory_device_unplug(MemoryDeviceState *md, Machin= eState *ms) g_assert(ms->device_memory); =20 memory_region_del_subregion(&ms->device_memory->mr, mr); + ms->device_memory->used_region_size -=3D memory_region_size(mr); trace_memory_device_unplug(DEVICE(md)->id ? DEVICE(md)->id : "", mdc->get_addr(md)); } diff --git a/include/hw/boards.h b/include/hw/boards.h index be06e8a41f..fcaf40b9da 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -296,11 +296,13 @@ struct MachineClass { * address space for memory devices starts * @mr: address space container for memory devices * @dimm_size: the sum of plugged DIMMs' sizes + * @used_region_size: the part of @mr already used by memory devices */ typedef struct DeviceMemoryState { hwaddr base; MemoryRegion mr; uint64_t dimm_size; + uint64_t used_region_size; } DeviceMemoryState; =20 /** --=20 2.40.1