From nobody Mon May 20 18:04:45 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=1685446945; cv=none; d=zohomail.com; s=zohoarc; b=NJS20VOIrf6l/FQsY4QR6LBYtIvDRLIvSZcq1zdriUWLa1PcZKEst/w3JE89G1Kz95apWwM2V2cQMQz7KaOWtlyvsCSEDxDFT3ZSMw8dAW5R4kIGOgHjq+0XKkF6vOwftfU+4DXY9YZE7+jD2rxcvjXUODCx1TyqMAW4ltVonCA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685446945; h=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=LO6y5tkfgNged57O731G9ECwYnoNXu48Izp7SYxqk34=; b=gttaV0qAPVc+CK50qnc/LV5LrHr3UAWJoDaNuNPIL94WJqZFuxwxBD9FbQGozDx+snpWWdNsO3QIGqLpaGWFq2qWAlkzrK0YERIp00yTxQ5nxzQgZV9d8SDIAbUsQpCPmGMRNAmpO8yfK8wzzKh9wQCDLbcrSZTBi6/2Sk9InHY= 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 1685446945010185.20339846537524; Tue, 30 May 2023 04:42:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q3xgu-0007t8-9X; Tue, 30 May 2023 07:39: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 1q3xgo-0007rc-5j for qemu-devel@nongnu.org; Tue, 30 May 2023 07:38:58 -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 1q3xgk-0003zH-Qp for qemu-devel@nongnu.org; Tue, 30 May 2023 07:38:57 -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-103-rjPf2xe3Oo6cI8Z-FOWwzA-1; Tue, 30 May 2023 07:38:49 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 496ED1C03DA3; Tue, 30 May 2023 11:38:48 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.39.194.167]) by smtp.corp.redhat.com (Postfix) with ESMTP id F0D0F40CFD45; Tue, 30 May 2023 11:38:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685446734; 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=LO6y5tkfgNged57O731G9ECwYnoNXu48Izp7SYxqk34=; b=C9vy/1wkGxWQaP7PerVuoMpbKWzoe+2b2zKXCj2tOKP14WR6g5Rk7iDod+uvF3TuEHQWMV 82Q+Uq/DTZyvjiS0mOQcMmAR/KlJoIbzL05O6Gin+nVIpI/MqEc4qlr8CvgjUU4AI51kcw okW/TbkKX7Ha/n/L4eD0eSaerWW5Npo= X-MC-Unique: rjPf2xe3Oo6cI8Z-FOWwzA-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 01/10] memory-device: Unify enabled vs. supported error messages Date: Tue, 30 May 2023 13:38:29 +0200 Message-Id: <20230530113838.257755-2-david@redhat.com> In-Reply-To: <20230530113838.257755-1-david@redhat.com> References: <20230530113838.257755-1-david@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.167, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: 1685446945892100001 Content-Type: text/plain; charset="utf-8" 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 ... Signed-off-by: David Hildenbrand Acked-by: Michael S. Tsirkin Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- 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 Mon May 20 18:04:45 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=1685446821; cv=none; d=zohomail.com; s=zohoarc; b=EEV+Mq2xKEb5T7JenC1vbK9ocgKD3qiCcpFjSk3o28IT360U6myIGjm/pq4G4PfhL/6VxqtQ5OtC8YK7FGgcw4GHvoGE3LjY4FZ73JI5RRUulOo5GGwVX5A2HzZlPSEHjPF4H+F0w9VQizp6hDLzwGXaxIw2WsaTvi0HRLgCmwI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685446821; h=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=fEpFnrqBabMN09y+0YSZgUsRDzt7crbSSBiCNJQKLNQ=; b=Kia0zcXNz+gznfzn04Cvb4BLdReO/kHmtHjnCE55wlo8VVWyeAvFYiv4eSLru7yNBX91zHgUKQBV2biEMFu2oiYM11sQilW5VI1949aJ3u8J7zOWh6JFOmbQ1sdJ5jCoiXeciz0hE26HQv/VcreJ/G958Dvyv6dKXY1DnsHDbjk= 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 1685446821462780.5835791838748; Tue, 30 May 2023 04:40:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q3xh7-0007u9-Cd; Tue, 30 May 2023 07:39:19 -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 1q3xgq-0007ru-O4 for qemu-devel@nongnu.org; Tue, 30 May 2023 07:39:02 -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 1q3xgm-0003zt-QF for qemu-devel@nongnu.org; Tue, 30 May 2023 07:39:00 -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-196-MtdJrl9CMjGhTs1Ksiq0Gg-1; Tue, 30 May 2023 07:38:53 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 27F80802A55; Tue, 30 May 2023 11:38:52 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.39.194.167]) by smtp.corp.redhat.com (Postfix) with ESMTP id 882A240CFD45; Tue, 30 May 2023 11:38:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685446736; 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=fEpFnrqBabMN09y+0YSZgUsRDzt7crbSSBiCNJQKLNQ=; b=VCZ3kqGgvBMls93JDTrbtJPFASNb8/GK+bWCA7+2R+LP648yekUlor8ULD6OQUVWqMdBtp uCnQYfKVp4Y8zCjsae7iIXV2MNZXe00K5aCDfrRnE4eNGVc6BCvn45S0vxgSLqsoXQVugF jFZwfXb4NCWtppSTzwSkKjldm+YEUhk= X-MC-Unique: MtdJrl9CMjGhTs1Ksiq0Gg-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 02/10] memory-device: Introduce memory_devices_init() Date: Tue, 30 May 2023 13:38:30 +0200 Message-Id: <20230530113838.257755-3-david@redhat.com> In-Reply-To: <20230530113838.257755-1-david@redhat.com> References: <20230530113838.257755-1-david@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.167, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: 1685446823545100003 Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: David Hildenbrand Acked-by: Michael S. Tsirkin Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/mem/memory-device.c | 14 ++++++++++++++ include/hw/mem/memory-device.h | 2 ++ 2 files changed, 16 insertions(+) diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c index 49f86ec8a8..2197dcf356 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 memory_devices_init(MachineState *ms, hwaddr base, uint64_t size) +{ + 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/mem/memory-device.h b/include/hw/mem/memory-device.h index 48d2611fc5..6e8a10e2f5 100644 --- a/include/hw/mem/memory-device.h +++ b/include/hw/mem/memory-device.h @@ -16,6 +16,7 @@ #include "hw/qdev-core.h" #include "qapi/qapi-types-machine.h" #include "qom/object.h" +#include "exec/hwaddr.h" =20 #define TYPE_MEMORY_DEVICE "memory-device" =20 @@ -113,5 +114,6 @@ void memory_device_plug(MemoryDeviceState *md, MachineS= tate *ms); void memory_device_unplug(MemoryDeviceState *md, MachineState *ms); uint64_t memory_device_get_region_size(const MemoryDeviceState *md, Error **errp); +void memory_devices_init(MachineState *ms, hwaddr base, uint64_t size); =20 #endif --=20 2.40.1 From nobody Mon May 20 18:04:45 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=1685446858; cv=none; d=zohomail.com; s=zohoarc; b=Id649dHqYlXJapPiM2ZaWc0m3eMFKsAlVl00vWd/nGuQ5nlm6kHok2kOWlEI9GtnmtbY2KbaA2bO4VGVKo9PhA3V97ydLRSVEhYYvdqmAWTnnOX/I0g7Lp5fvZBJdFCKwKmxWJJ1ewO2rSnmfqWCVJ/7Kdk/7um1PixfoZYXoV4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685446858; h=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=XinK48gMtdhK2Jrt5yYTeK2A0TRIxNMgvQ0AqBqN7hY=; b=aQ1s4muuI13zDE7X26yTFyZQA8L8v/yseHzJT1pd6I730dJdALxgPB6JSl+gFbNiMXpIFICjfDNi0Fe02iR5yJwi7l7tH6UAF0hMHyNizIi/8+cuyZ1QXRQjJCzz5uSOka+muB556mWDblWq+baBh6VT7vNvxY7hZnLSIWdxrcU= 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 1685446858165619.2773789281944; Tue, 30 May 2023 04:40:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q3xhD-00082L-61; Tue, 30 May 2023 07:39: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 1q3xgw-0007uJ-Nj for qemu-devel@nongnu.org; Tue, 30 May 2023 07:39:13 -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 1q3xgu-000439-AN for qemu-devel@nongnu.org; Tue, 30 May 2023 07:39:06 -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-551-AFB7OFj6NDWyUCmKhbY5Cw-1; Tue, 30 May 2023 07:38:57 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5F5AD185A791; Tue, 30 May 2023 11:38:56 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.39.194.167]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6CD1840CFD45; Tue, 30 May 2023 11:38:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685446743; 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=XinK48gMtdhK2Jrt5yYTeK2A0TRIxNMgvQ0AqBqN7hY=; b=O/sz5PchFqmIge4Eai9VcgWw7BOI5bh1TVF7hhqL4e8lDn7eZHQwO/st8VreBMrG/tLu/n WfjepI5apruEeoS3paZa9wyHxgtoLludDHRI3GAM9vfYUj3FTJk7C4jgBPuXBY+4Hbk4bh dtKMVOHEUiDtOFXnfEoG7fZKvkNNAqI= X-MC-Unique: AFB7OFj6NDWyUCmKhbY5Cw-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 03/10] hw/arm/virt: Use memory_devices_init() Date: Tue, 30 May 2023 13:38:31 +0200 Message-Id: <20230530113838.257755-4-david@redhat.com> In-Reply-To: <20230530113838.257755-1-david@redhat.com> References: <20230530113838.257755-1-david@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.167, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: 1685446858939100004 Content-Type: text/plain; charset="utf-8" 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 Signed-off-by: David Hildenbrand Acked-by: Michael S. Tsirkin Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- 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..49bc8378ec 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); + 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 Mon May 20 18:04:45 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=1685446831; cv=none; d=zohomail.com; s=zohoarc; b=laK8PZSIaMvjEFzC1pQWikOMqMsEd93OGt3OPaPpZKDeYuPa8AOfwhS1eYitMx3ok7yizUVGrUqID1cZ8kJxQnXkOYWhNP90b3Ay4lwOuDpd20GL0sX+dVBD43JTFgIz4aNezB/+o/Q54JNgI/cY9+embO+Aijsx3GFcwcyepFU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685446831; 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=DTaSB7tq88uaqaTxCgp6OdSh0CxSz9wsEaDtBmyhZgc=; b=Pb6WlmTIzm3gntp/VU9/rZX2jtB0v6PY4ESj4F/HClzcHhdG2SiD5s60gXZYZFvhYotCyhwrTBPJqjiqbwqxcSqEUUckPVAcwPYYdYpp1n12QGk93Lalr6JA3eQJI7JNhZMgYWi44f6fs3QJfgTIC+0NxR8SBYp5SUUxN1Vufus= 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 1685446831611832.7880868641563; Tue, 30 May 2023 04:40:31 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q3xhC-000822-T5; Tue, 30 May 2023 07:39:22 -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 1q3xgz-0007uS-2F for qemu-devel@nongnu.org; Tue, 30 May 2023 07:39:13 -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 1q3xgx-00044Y-HZ for qemu-devel@nongnu.org; Tue, 30 May 2023 07:39:08 -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-595-IJsiPpRUMRKbKhbAZide6w-1; Tue, 30 May 2023 07:39:01 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7C03E811E7C; Tue, 30 May 2023 11:39:00 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.39.194.167]) by smtp.corp.redhat.com (Postfix) with ESMTP id C0D2540CFD45; Tue, 30 May 2023 11:38:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685446746; 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=DTaSB7tq88uaqaTxCgp6OdSh0CxSz9wsEaDtBmyhZgc=; b=jH5CrEBfl8hDhQUZbRxVfbGE/oYoxYdRxUBtry5013bZC6+LMNYulahnSXLFSELGpxyslL LgwfFFZqSaQXNd/VkXS/5M6HE1t4m++DjU+AiIBPd2/PahdL6WZNPLQ/wNrzS3E/9wLsLP yT/uszJhcJN9WjnFtlwVy3ApnEEhSMo= X-MC-Unique: IJsiPpRUMRKbKhbAZide6w-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 04/10] hw/ppc/spapr: Use memory_devices_init() Date: Tue, 30 May 2023 13:38:32 +0200 Message-Id: <20230530113838.257755-5-david@redhat.com> In-Reply-To: <20230530113838.257755-1-david@redhat.com> References: <20230530113838.257755-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.1 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: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.167, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: 1685446833540100003 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 Signed-off-by: David Hildenbrand Acked-by: Michael S. Tsirkin Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- 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..44155f6613 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); + memory_devices_init(machine, device_mem_base, device_mem_size); } =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 Mon May 20 18:04:45 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=1685446859; cv=none; d=zohomail.com; s=zohoarc; b=KbO6fnVO1elbMLzcJsKGwo1+qzFo2WJBgO5obUWl+Sth43nwfIMIk8r+wx48jtovtczgDsSaCwqvi3VQiOlT0FWV9LHsgnmeqfw++/pp2KRaUUit2vjYhtOzqAfsMlMzfhrsRi1mNO9QrGrw/fz5S7z7iTbzHa4zWMtFTO2mAvI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685446859; h=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=KkLnYI7ZC/XGHU4LuLPG/YHBgPd/PcXz1iS/ExnG6IM=; b=M+t98v7pzymtZhz/AnwVRTaoFRwqHltIA57L5dAGTN1/OlD6cVGEpGMMHI8DrFXaYKaqyZ8oqFNbPN35Kgc3aVkHvUKXCmTKKw6ceD6oxm47d6p2f+xX/Vi9oAtnd6km5MobqI6IKImMvFecvr0jG7Mwkqad7XD0kTuv1Mtraqg= 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 1685446859584851.7439041787222; Tue, 30 May 2023 04:40:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q3xhF-00083j-FK; Tue, 30 May 2023 07:39: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 1q3xh1-0007ul-Iy for qemu-devel@nongnu.org; Tue, 30 May 2023 07:39:15 -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 1q3xgz-00045O-6n for qemu-devel@nongnu.org; Tue, 30 May 2023 07:39:10 -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-609-act1RaTXNdu0yx38jYus9Q-1; Tue, 30 May 2023 07:39:05 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9107685A5AA; Tue, 30 May 2023 11:39:04 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.39.194.167]) by smtp.corp.redhat.com (Postfix) with ESMTP id C5E3D40CFD45; Tue, 30 May 2023 11:39:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685446748; 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=KkLnYI7ZC/XGHU4LuLPG/YHBgPd/PcXz1iS/ExnG6IM=; b=Kwg+yrPlitbaRqd2CS3nXebOCuJ2bGC/bcYM7oJexPS8Q5bsciPkIURaM8GmqNpWuT3PMb cn6ueAnpRPrYSPwdcKvaZNcuwpQeERtXLpl4yAWEC7QAquUfVb76JR+/ob4ZR+f0cc4HUl muWLNF0wF2IZKxzv36d5YI+F3S+M7N8= X-MC-Unique: act1RaTXNdu0yx38jYus9Q-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 05/10] hw/loongarch/virt: Use memory_devices_init() Date: Tue, 30 May 2023 13:38:33 +0200 Message-Id: <20230530113838.257755-6-david@redhat.com> In-Reply-To: <20230530113838.257755-1-david@redhat.com> References: <20230530113838.257755-1-david@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.167, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: 1685446861217100019 Content-Type: text/plain; charset="utf-8" Let's use our new helper. Cc: Xiaojuan Yang Cc: Song Gao Signed-off-by: David Hildenbrand Acked-by: Michael S. Tsirkin Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Song Gao --- hw/loongarch/virt.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c index ceddec1b23..a6790714fe 100644 --- a/hw/loongarch/virt.c +++ b/hw/loongarch/virt.c @@ -45,7 +45,7 @@ #include "sysemu/block-backend.h" #include "hw/block/flash.h" #include "qemu/error-report.h" - +#include "hw/mem/memory-device.h" =20 static void virt_flash_create(LoongArchMachineState *lams) { @@ -805,8 +805,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, @@ -821,14 +821,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(0x90000000 + highram_size, 1 * GiB); + memory_devices_init(machine, device_mem_base, device_mem_size); } =20 /* Add isa io region */ --=20 2.40.1 From nobody Mon May 20 18:04:45 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=1685446884; cv=none; d=zohomail.com; s=zohoarc; b=Y5XKyhcSy8AQjG07lqRPLCghThCLkxxlfrPC64QLZ5BIyYeQS2Kn4Xyan0DncXRHlHwH8vAadSAgon7G5eFnyRubCvZxlVxm0JyGGAnJklWPLrOMEBt2m5LEJ8IW2mTA3lLvB1bCKCZn92dOG1LsuQr4K4kbk+NaVfRISwKQgd0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685446884; h=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=ypSNjxk8rJUKShrG/cQHxTCZ8bHXJz6ssKLCoH3afkk=; b=Kg7pz0DI8zt8xzJp8hK/kA0p5hK82rz24Xw+bH0lSqj8RnD97aH5YPOPEUUZ6/qluoViTpqDXmOMCez9ZiN0sJS+I0EDH9xvWIA8YvsxSrXT9yjSvVYSDT+Bz7c2FUITTur87uvovSCNcSrvDe2SY2fQu7bzN7b/PJUh5dJuE0g= 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 1685446884092303.2039065335674; Tue, 30 May 2023 04:41:24 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q3xhF-00083v-Mw; Tue, 30 May 2023 07:39: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 1q3xh8-0007vo-4C for qemu-devel@nongnu.org; Tue, 30 May 2023 07:39: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 1q3xh6-00048i-Kb for qemu-devel@nongnu.org; Tue, 30 May 2023 07:39:17 -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-402-4IePjxoQObOgdcDZpBNbfA-1; Tue, 30 May 2023 07:39:08 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D7BB9101A53A; Tue, 30 May 2023 11:39:07 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.39.194.167]) by smtp.corp.redhat.com (Postfix) with ESMTP id D195040CFD48; Tue, 30 May 2023 11:39:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685446754; 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=ypSNjxk8rJUKShrG/cQHxTCZ8bHXJz6ssKLCoH3afkk=; b=MZeh1QPv1h1rGMLy/ajpIRwgQT/HHCFz6LgjGQLFW0EVOSph3XZrzCrz+Rj1Q3sFSQ/MXQ eJpGGrJKP1zULuOxhVha81zBkvN7q1+a51FfzkajPLQW9hRlAmyD5h7/lEUPwG1tnJmhRo V0ritnckNSnE42EcvPcLIFjmFkxTXOw= X-MC-Unique: 4IePjxoQObOgdcDZpBNbfA-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 06/10] hw/i386/pc: Use memory_devices_init() Date: Tue, 30 May 2023 13:38:34 +0200 Message-Id: <20230530113838.257755-7-david@redhat.com> In-Reply-To: <20230530113838.257755-1-david@redhat.com> References: <20230530113838.257755-1-david@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.167, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: 1685446885724100001 Content-Type: text/plain; charset="utf-8" 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 Signed-off-by: David Hildenbrand Acked-by: Michael S. Tsirkin Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- 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 bb62c994fa..920aa32b53 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); + memory_devices_init(machine, device_mem_base, device_mem_size); } =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 Mon May 20 18:04:45 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=1685446857; cv=none; d=zohomail.com; s=zohoarc; b=ED7ddvfcf8iG3GNywRm5JHvvgbDpLVoLNvu/V3lHe/ENow8crCCc8zp51sm/5XPWeH5TOMB/rxp7PLxf6KzC97MqA1bmJ+XALoZE/d1YkTI4zmOynubMyQxuExdOUTzwSezif8Z2RA3qBXm2RTK5YPqk+JJslInTZ3rinHl4onM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685446857; h=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=V7PkcJ6DVo7MMGulOFY19ajlG0QrNz/+An8Z4BW518g=; b=DMBXpnXbkFMqX9IkFxxE27feC28vOGndqWPWsa1k/5StjvPbyyNxGaI3vyFW+534d5tscAb0phE/Tyx3LVpQA0n+4iLUTjdlDAAyKzMT4fOVRknvona8ZJ0Cv2YoV2/tGOQzex/dQQbF3tcHy0xxDUthBO3+9/lBGazrZN8aDQE= 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 1685446857149497.0091871196638; Tue, 30 May 2023 04:40:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q3xhG-00084g-Vg; Tue, 30 May 2023 07:39:27 -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 1q3xh9-0007xR-Ey for qemu-devel@nongnu.org; Tue, 30 May 2023 07:39:21 -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 1q3xh8-0004B7-0P for qemu-devel@nongnu.org; Tue, 30 May 2023 07:39: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-554-TiiqfpmPNL-OZJ8s-rnmiA-1; Tue, 30 May 2023 07:39:12 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 524973C0CEED; Tue, 30 May 2023 11:39:11 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.39.194.167]) by smtp.corp.redhat.com (Postfix) with ESMTP id 290BD40CFD45; Tue, 30 May 2023 11:39:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685446757; 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=V7PkcJ6DVo7MMGulOFY19ajlG0QrNz/+An8Z4BW518g=; b=Ge2+h44GyYA/ImnNIMCktLeduMKQj9urwGPkms1Vp344AgYEiarqw+OYOI2ZQoUsBvkMCT N4ALbQ1XwwdB5vLhjp6kJmM5qm5eISNgpw2+5PXu9rYh6MUqmZxNT1Ye1YmTu3D0nM+YjZ xVxZtooJOKDmTJbBBIW6fW0YXqPSOMQ= X-MC-Unique: TiiqfpmPNL-OZJ8s-rnmiA-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 07/10] hw/i386/acpi-build: Rely on machine->device_memory when building SRAT Date: Tue, 30 May 2023 13:38:35 +0200 Message-Id: <20230530113838.257755-8-david@redhat.com> In-Reply-To: <20230530113838.257755-1-david@redhat.com> References: <20230530113838.257755-1-david@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.167, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: 1685446857433100001 Content-Type: text/plain; charset="utf-8" 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 Signed-off-by: David Hildenbrand Acked-by: Michael S. Tsirkin Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- 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 Mon May 20 18:04:45 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=1685446858; cv=none; d=zohomail.com; s=zohoarc; b=UDH1z6d8pzP9kqtomSZba0Ott2xxN+0GhmwQ6cfTwiC0Sf4PxqSlfDRWHHbEtGKtcXDTn0eU6LX2NASdMpPCBavD87USN/2ZOXsQsvWz4jJg2/Ipu0OV+6Mlc98gNsQ2kPX1YpAjKzWT5RHYy+yQ5yeSpMDZr+H46dJ+3QgbA4Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685446858; h=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=y1o8JwHfKO0g83U4avSDTqgBOKXfwEYHCi8B3HZYx1E=; b=cs4Unk79PHsnRjBoEh8/pBNenhR/mDNbp2dsIhfcA/+z66rK7av6ITdUbEtFAFPT3n3gp1pgPh1/k0IEnILc+MLG+A4NKfgw16AV8jknexO1kJFCyrjpbYGd0Pyd7EqLuA2nCFZFnptoR9xBu7UGmDQI0Uev9X99Co3MIwHBlUU= 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 1685446858166401.122806450069; Tue, 30 May 2023 04:40:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q3xhI-00087v-Rp; Tue, 30 May 2023 07:39: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 1q3xhF-00083L-5t for qemu-devel@nongnu.org; Tue, 30 May 2023 07:39:25 -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 1q3xhC-0004EH-Nd for qemu-devel@nongnu.org; Tue, 30 May 2023 07:39:24 -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-538-EfHJyXHsNU6Zxu4j8ONrqQ-1; Tue, 30 May 2023 07:39:15 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 065192A59566; Tue, 30 May 2023 11:39:15 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.39.194.167]) by smtp.corp.redhat.com (Postfix) with ESMTP id A25E540CFD45; Tue, 30 May 2023 11:39:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685446762; 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=y1o8JwHfKO0g83U4avSDTqgBOKXfwEYHCi8B3HZYx1E=; b=RpPJDXWE7NfMxksijWJorH1DlE38cSphCZb7GIjxgU+xH94+SS2RNAaKgsOKqcTYze2qJ3 Q5wGNU8QFLXPzG9dIv3fA5G9B5ivsMumGiPygklrSUYWz/geekKCADIYgxygrYKocmf7aS 1VVLr4QbMJmA3ExdjGdcYEyn2jkLBvI= X-MC-Unique: EfHJyXHsNU6Zxu4j8ONrqQ-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 08/10] hw/i386/pc: Remove PC_MACHINE_DEVMEM_REGION_SIZE Date: Tue, 30 May 2023 13:38:36 +0200 Message-Id: <20230530113838.257755-9-david@redhat.com> In-Reply-To: <20230530113838.257755-1-david@redhat.com> References: <20230530113838.257755-1-david@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.167, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: 1685446858941100005 Content-Type: text/plain; charset="utf-8" There are no remaining users in the tree, so let's remove it. Cc: Paolo Bonzini Cc: Richard Henderson Cc: Eduardo Habkost Cc: "Michael S. Tsirkin" Cc: Marcel Apfelbaum Signed-off-by: David Hildenbrand Acked-by: Michael S. Tsirkin Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- 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 920aa32b53..c4789e2f35 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1646,21 +1646,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) { @@ -1980,10 +1965,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 Mon May 20 18:04:45 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=1685446987; cv=none; d=zohomail.com; s=zohoarc; b=JpI5NUR6eMSjvSFCmcG8ms67ccCqDc2zpzEmv4zWSqFQ39cV8bKlPxNufRABVxU5Ryi6xY5hWRR+RHhL30Xe+HrvQydSjOQA2QcxQLKvvnOFJtWdhOSJdbFWEfXtqfv/oQvw6cgDDexoCixbnd7obsEgabXo1def7cbtYWKKtf0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685446987; h=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=cb4iSjQQh27x17LFuIUvzkQ0NEv7gRmk65M7DLN/NpQ=; b=S0RUbD0NqQpsfwYk3CjV9UA3DMYNqb9Apfb5fyi4X4Q/8W1mtKbc3NpxRcEvHnvn3/qRuGmt8ibRXzOvLUL770V43cOmXaBQbwqKZwo8uaTu+1DGsJeEwNsQGAFEAJCEKaRfOBwbb5AYyP9Flm+7Pgb7TfigLiMK9jXH3LuFOO0= 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 1685446987772374.9618429906735; Tue, 30 May 2023 04:43:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q3xhL-0008Cv-Ex; Tue, 30 May 2023 07:39:31 -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 1q3xhI-00086p-0a for qemu-devel@nongnu.org; Tue, 30 May 2023 07:39: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 1q3xhG-0004FZ-ED for qemu-devel@nongnu.org; Tue, 30 May 2023 07:39: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-600-aM7XQF0uO6CQpYbyd7cHhg-1; Tue, 30 May 2023 07:39:19 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7F3CF85A5A8; Tue, 30 May 2023 11:39:18 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.39.194.167]) by smtp.corp.redhat.com (Postfix) with ESMTP id 50FF940CFD45; Tue, 30 May 2023 11:39:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685446765; 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=cb4iSjQQh27x17LFuIUvzkQ0NEv7gRmk65M7DLN/NpQ=; b=ALV/c8bzelu/zWfKe2KJy8g73JjRNIKzVgutFeDyfmzXMgkUSBAUVPj1qb8ftRT5X1qyR/ Ns+oUfR4jKWgf1cAKOw090aZm0wYmHG6MCHq78VXpN6CP2xLoOte+cYbHH+MvyFMkWDQzx 7KsF1fUADYzFlmN/EdccMiqSuRtrq1o= X-MC-Unique: aM7XQF0uO6CQpYbyd7cHhg-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 09/10] memory-device: Refactor memory_device_pre_plug() Date: Tue, 30 May 2023 13:38:37 +0200 Message-Id: <20230530113838.257755-10-david@redhat.com> In-Reply-To: <20230530113838.257755-1-david@redhat.com> References: <20230530113838.257755-1-david@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.167, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: 1685446988075100003 Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: David Hildenbrand Acked-by: Michael S. Tsirkin --- 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 2197dcf356..616067cbdc 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 Mon May 20 18:04:45 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=1685446857; cv=none; d=zohomail.com; s=zohoarc; b=dHV5l+Gy1P+yeMfmn5R5q4R8tAiFjtiibSvwJemUQvtaEunOvGah84Y5WntUqhBOG++0B4ZgDt4ZbkfxLZKWpsFXqX3BAHCwR8/tEvJQMoXTHUmEB4PGrLOuNEOtiKXtWzgxag/7ThDfkrbAsAJFPOyb4xAnEkAfiWt3xoLFpBY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685446857; h=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=AbpdkhgEkcr82y0XKOnC+ouxwPZu0/gMo9cQrOH8aKk=; b=H7UKXRnWi3I2BJ1puUWEhHkdAsk4zVTYEFUscQS9wHSJwmSF322UeBRHWRqRtHkOhUwOZR26SyIoYYBHbERZTO8RBdSdXAxN4cigw0EU2xXd0ro+/SNCTO1GbnPJVNaUI4Lih0P+haVscLYkZXPC6m/KEaiFpy+zn7lZzbc6F5A= 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 1685446857502626.5355445730397; Tue, 30 May 2023 04:40:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q3xhM-0008Dv-IJ; Tue, 30 May 2023 07:39:32 -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 1q3xhK-0008C8-P5 for qemu-devel@nongnu.org; Tue, 30 May 2023 07:39:30 -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 1q3xhI-0004Gd-IV for qemu-devel@nongnu.org; Tue, 30 May 2023 07:39: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-505-dp9e51U8MGG1eL5S8ZfNEQ-1; Tue, 30 May 2023 07:39:22 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DBED58032FE; Tue, 30 May 2023 11:39:21 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.39.194.167]) by smtp.corp.redhat.com (Postfix) with ESMTP id BD6FD40CFD45; Tue, 30 May 2023 11:39:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685446768; 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=AbpdkhgEkcr82y0XKOnC+ouxwPZu0/gMo9cQrOH8aKk=; b=XrRY3lV1gP088AOTm95M2OTrXtKjR0Zw0Q3CnP+wgm3TLH237UHHo3eaTcXm61Oq/UDYWp wFFd7B0m0/E/+HaBzjkmCcYW6pOjQPkxriPL4X7OeSXYH8kav7iOiVheqFRC2HCkcFBG3u Ka9VnLkKraNDuJb4NRDS8g9D3wEIl04= X-MC-Unique: dp9e51U8MGG1eL5S8ZfNEQ-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 10/10] memory-device: Track used region size in DeviceMemoryState Date: Tue, 30 May 2023 13:38:38 +0200 Message-Id: <20230530113838.257755-11-david@redhat.com> In-Reply-To: <20230530113838.257755-1-david@redhat.com> References: <20230530113838.257755-1-david@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.167, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: 1685446858946100006 Content-Type: text/plain; charset="utf-8" Let's avoid iterating over all devices and simply track it in the DeviceMemoryState. Signed-off-by: David Hildenbrand Acked-by: Michael S. Tsirkin Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- 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 616067cbdc..b8eb2a7188 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 a385010909..9d48c73edb 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -294,11 +294,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