From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A15E8ECAAD8 for ; Tue, 20 Sep 2022 05:12:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229793AbiITFMB (ORCPT ); Tue, 20 Sep 2022 01:12:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229767AbiITFL7 (ORCPT ); Tue, 20 Sep 2022 01:11:59 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98DE65A88F for ; Mon, 19 Sep 2022 22:11:56 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id b5so2376156wrr.5 for ; Mon, 19 Sep 2022 22:11:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :sender:from:to:cc:subject:date; bh=pnla9efotYFd/3Jw4qRJIL4xlOWxFHoq332oc/9bbqo=; b=WvvRv/4VUhzyb4J7QRcwkeJBidNZGJR96FFEPsAXWbf8VLcpCXht2BEDjJNBcmmf4q B9BYrOZLleB7KiX3SS/A3sJvc264Ej3tiwc3zGaUvi5i726p0npX6EaT2nlzWeA2+YFX 8GTlDoczWFQldhtWnsIUiRTYwYsgNJm3kyA/24figJL3TCNySpOfwDjd3289KgW1XDyL ERzD6kKsPvOAQCvh+laZl5zPT/ZSZiZs1LcmpHaoACHzTBRIGuB5hrb+MzvGTkUhNaoj 4ok/LujOcM0U/ZAvrwSbQDTdue9Vb6REatLt7pz9bKtwK5aVEYH2l8wALn4jushh7SCo jWTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :sender:x-gm-message-state:from:to:cc:subject:date; bh=pnla9efotYFd/3Jw4qRJIL4xlOWxFHoq332oc/9bbqo=; b=m42D2+kel95zYHQK3ahkiRxajhE06lZX36ARg2iMioyRrkHCLSJmK7Oshb3oDur1M+ 8lnwqASz6uAHsxOJqS8NC3ati7UIsbqmg09VA8iNbk9RKMAh+EFhbzHfJ72SVCpmViyA y9avjhCwWiGciOj3ajGyShEWzZ3DkzVkyLa3YtpNYfvYucKZPtqp2rNAVU35xGCTM7N3 6voDtow6ZHckH2AexaZ59lEAOFmvUTW2SNT8m6eEObIps7TP+YLqWIq1JjMmuAoOK+yA 7IyxGsxRZMXrZc7D5q2qbQq6eUmJFRBg5Neay/4zKREWpWSbSttJ8Gsj2UHwc1ETUPNB ixiw== X-Gm-Message-State: ACrzQf3wBaOhGLEVDpZog7UwqBqxZGdWUauFPJtlmqwRIMuGZYOPJAEE hKXbu3eHPAhTHj2+4Urp5c0= X-Google-Smtp-Source: AMsMyM68Pblt5BIGotnw6q4CbijQ/TryMLJf4D1jxUGITEtnEY/vODYKCiaQW21HjH1kYP7yEoWclA== X-Received: by 2002:a5d:6147:0:b0:22a:6035:a878 with SMTP id y7-20020a5d6147000000b0022a6035a878mr12295976wrt.528.1663650715031; Mon, 19 Sep 2022 22:11:55 -0700 (PDT) Received: from [192.168.1.115] ([185.126.107.38]) by smtp.gmail.com with ESMTPSA id y12-20020adfe6cc000000b0022a293ab1e9sm452848wrm.11.2022.09.19.22.11.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 19 Sep 2022 22:11:53 -0700 (PDT) Sender: =?UTF-8?Q?Philippe_Mathieu=2DDaud=C3=A9?= Message-ID: Date: Tue, 20 Sep 2022 07:11:48 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.13.0 Subject: Re: [PATCH 8/9] softmmu/physmem: Let SysBusState absorb memory region and address space singletons Content-Language: en-US To: Bernhard Beschow , qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Magnus Damm , Aleksandar Rikalo , Bandan Das , Matthew Rosato , Daniel Henrique Barboza , Sergio Lopez , Alexey Kardashevskiy , Xiaojuan Yang , Cameron Esfahani , Michael Rolnik , Song Gao , Jagannathan Raman , Greg Kurz , Kamil Rytarowski , Peter Xu , Joel Stanley , Alistair Francis , "Dr. David Alan Gilbert" , Paolo Bonzini , haxm-team@intel.com, Roman Bolshakov , Markus Armbruster , Eric Auger , David Gibson , =?UTF-8?Q?Daniel_P=2e_Berrang=c3=a9?= , Christian Borntraeger , =?UTF-8?Q?C=c3=a9dric_Le_Goater?= , Stefan Hajnoczi , qemu-block@nongnu.org, Eduardo Habkost , =?UTF-8?Q?Herv=c3=a9_Poussineau?= , qemu-ppc@nongnu.org, Cornelia Huck , Palmer Dabbelt , Helge Deller , Stefano Stabellini , qemu-riscv@nongnu.org, Stafford Horne , Paul Durrant , Havard Skinnemoen , Elena Ufimtseva , Alexander Graf , Thomas Huth , Alex Williamson , Wenchao Wang , Tony Krowiak , Marcel Apfelbaum , qemu-s390x@nongnu.org, =?UTF-8?Q?Marc-Andr=c3=a9_Lureau?= , Mark Cave-Ayland , Eric Farman , Reinoud Zandijk , Alexander Bulekov , Yanan Wang , "Edgar E. Iglesias" , Gerd Hoffmann , Tyrone Ting , xen-devel@lists.xenproject.org, Yoshinori Sato , John Snow , Richard Henderson , Darren Kenny , kvm@vger.kernel.org, Qiuhao Li , John G Johnson , Bin Meng , Sunil Muthuswamy , Max Filippov , qemu-arm@nongnu.org, Marcelo Tosatti , Peter Maydell , Anthony Perard , Andrew Jeffery , Artyom Tarasenko , Halil Pasic , "Maciej S. Szmigiero" , Jason Wang , David Hildenbrand , Laurent Vivier , Alistair Francis , Jason Herne References: <20220919231720.163121-1-shentey@gmail.com> <20220919231720.163121-9-shentey@gmail.com> From: =?UTF-8?Q?Philippe_Mathieu-Daud=c3=a9?= In-Reply-To: <20220919231720.163121-9-shentey@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org On 20/9/22 01:17, Bernhard Beschow wrote: > These singletons are actually properties of the system bus but so far it > hasn't been modelled that way. Fix this to make this relationship very > obvious. > > The idea of the patch is to restrain futher proliferation of the use of > get_system_memory() and get_system_io() which are "temprary interfaces" "further", "temporary" > "until a proper bus interface is available". This should now be the > case. > > Note that the new attributes are values rather than a pointers. This > trades pointer dereferences for pointer arithmetic. The idea is to > reduce cache misses - a rule of thumb says that every pointer > dereference causes a cache miss while arithmetic is basically free. > > Signed-off-by: Bernhard Beschow > --- > include/exec/address-spaces.h | 19 ++++++++++++--- > include/hw/sysbus.h | 6 +++++ > softmmu/physmem.c | 46 ++++++++++++++++++----------------- > 3 files changed, 45 insertions(+), 26 deletions(-) > > diff --git a/include/exec/address-spaces.h b/include/exec/address-spaces.h > index d5c8cbd718..b31bd8dcf0 100644 > --- a/include/exec/address-spaces.h > +++ b/include/exec/address-spaces.h > @@ -23,17 +23,28 @@ > > #ifndef CONFIG_USER_ONLY > > -/* Get the root memory region. This interface should only be used temporarily > - * until a proper bus interface is available. > +/** > + * Get the root memory region. This is a legacy function, provided for > + * compatibility. Prefer using SysBusState::system_memory directly. > */ > MemoryRegion *get_system_memory(void); > diff --git a/include/hw/sysbus.h b/include/hw/sysbus.h > index 5bb3b88501..516e9091dc 100644 > --- a/include/hw/sysbus.h > +++ b/include/hw/sysbus.h > @@ -17,6 +17,12 @@ struct SysBusState { > /*< private >*/ > BusState parent_obj; > /*< public >*/ > + > + MemoryRegion system_memory; > + MemoryRegion system_io; > + > + AddressSpace address_space_io; > + AddressSpace address_space_memory; Alternatively (renaming doc accordingly): struct { MemoryRegion mr; AddressSpace as; } io, memory; > }; > > #define TYPE_SYS_BUS_DEVICE "sys-bus-device" > diff --git a/softmmu/physmem.c b/softmmu/physmem.c > index 0ac920d446..07e9a9171c 100644 > --- a/softmmu/physmem.c > +++ b/softmmu/physmem.c > @@ -86,12 +86,6 @@ > */ > RAMList ram_list = { .blocks = QLIST_HEAD_INITIALIZER(ram_list.blocks) }; > > -static MemoryRegion *system_memory; > -static MemoryRegion *system_io; > - > -static AddressSpace address_space_io; > -static AddressSpace address_space_memory; > - > static MemoryRegion io_mem_unassigned; > > typedef struct PhysPageEntry PhysPageEntry; > @@ -146,7 +140,7 @@ typedef struct subpage_t { > #define PHYS_SECTION_UNASSIGNED 0 > > static void io_mem_init(void); > -static void memory_map_init(void); > +static void memory_map_init(SysBusState *sysbus); > static void tcg_log_global_after_sync(MemoryListener *listener); > static void tcg_commit(MemoryListener *listener); > > @@ -2667,37 +2661,45 @@ static void tcg_commit(MemoryListener *listener) > tlb_flush(cpuas->cpu); > } > > -static void memory_map_init(void) > +static void memory_map_init(SysBusState *sysbus) > { No need to pass a singleton by argument. assert(current_machine); You can use get_system_memory() and get_system_io() in place :) LGTM otherwise, great! > - system_memory = g_malloc(sizeof(*system_memory)); > + MemoryRegion *system_memory = &sysbus->system_memory; > + MemoryRegion *system_io = &sysbus->system_io; > > memory_region_init(system_memory, NULL, "system", UINT64_MAX); > - address_space_init(&address_space_memory, system_memory, "memory"); > + address_space_init(&sysbus->address_space_memory, system_memory, "memory"); > > - system_io = g_malloc(sizeof(*system_io)); > memory_region_init_io(system_io, NULL, &unassigned_io_ops, NULL, "io", > 65536); > - address_space_init(&address_space_io, system_io, "I/O"); > + address_space_init(&sysbus->address_space_io, system_io, "I/O"); > } > > MemoryRegion *get_system_memory(void) > { > - return system_memory; > + assert(current_machine); > + > + return ¤t_machine->main_system_bus.system_memory; > } > > MemoryRegion *get_system_io(void) > { > - return system_io; > + assert(current_machine); > + > + return ¤t_machine->main_system_bus.system_io; > } > > AddressSpace *get_address_space_memory(void) > { > - return &address_space_memory; > + assert(current_machine); > + > + return ¤t_machine->main_system_bus.address_space_memory; > } > > AddressSpace *get_address_space_io(void) > { > - return &address_space_io; > + assert(current_machine); > + > + return ¤t_machine->main_system_bus.address_space_io; > } From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 06B97C54EE9 for ; Tue, 20 Sep 2022 05:14:17 +0000 (UTC) Received: from localhost ([::1]:44736 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oaVaK-0002zL-Mo for qemu-devel@archiver.kernel.org; Tue, 20 Sep 2022 01:14:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41260) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oaVY8-0001Vg-VB; Tue, 20 Sep 2022 01:12:01 -0400 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]:37774) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oaVY6-0003mC-UI; Tue, 20 Sep 2022 01:12:00 -0400 Received: by mail-wr1-x42e.google.com with SMTP id bq9so2387102wrb.4; Mon, 19 Sep 2022 22:11:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :sender:from:to:cc:subject:date; bh=pnla9efotYFd/3Jw4qRJIL4xlOWxFHoq332oc/9bbqo=; b=WvvRv/4VUhzyb4J7QRcwkeJBidNZGJR96FFEPsAXWbf8VLcpCXht2BEDjJNBcmmf4q B9BYrOZLleB7KiX3SS/A3sJvc264Ej3tiwc3zGaUvi5i726p0npX6EaT2nlzWeA2+YFX 8GTlDoczWFQldhtWnsIUiRTYwYsgNJm3kyA/24figJL3TCNySpOfwDjd3289KgW1XDyL ERzD6kKsPvOAQCvh+laZl5zPT/ZSZiZs1LcmpHaoACHzTBRIGuB5hrb+MzvGTkUhNaoj 4ok/LujOcM0U/ZAvrwSbQDTdue9Vb6REatLt7pz9bKtwK5aVEYH2l8wALn4jushh7SCo jWTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :sender:x-gm-message-state:from:to:cc:subject:date; bh=pnla9efotYFd/3Jw4qRJIL4xlOWxFHoq332oc/9bbqo=; b=YIi4FvitemPltQboUA6ca84NruyvUsYhrlw5vle/t8yD4WdCW8v6U8KxZLMFN+/YxD 4WsM2qHZeurdHMOIq+5ooOtT84y0nT5a3+fq5QwONPQvf0k34M+AWZsTl0Xj6WRt8LLJ 8cTygt61RoZDUknPcloi1my6bCZwFtK+dxocnWuBA6kfYKeZLGFmKAz3LdkZNyzB2c9j lgdwv6TnyETJV8aGIUkjYBMO/Ws2YwQZ8kjyiZL+V+oWbNyDXgokw87PGX46Ym+3OV4x nuFBlQi0iD0LvZhmqRYjudoSxqz8z9O+Jetqj0+0jQOxivTrE2puW12x1c6gS5W/1PZ7 PXxQ== X-Gm-Message-State: ACrzQf00+KUFaJSq6CJBqscEzdf4olLiHoAapLauloe2XyZ872cca7At lfqRZ3N9Ohp2D3eHGyY6450= X-Google-Smtp-Source: AMsMyM68Pblt5BIGotnw6q4CbijQ/TryMLJf4D1jxUGITEtnEY/vODYKCiaQW21HjH1kYP7yEoWclA== X-Received: by 2002:a5d:6147:0:b0:22a:6035:a878 with SMTP id y7-20020a5d6147000000b0022a6035a878mr12295976wrt.528.1663650715031; Mon, 19 Sep 2022 22:11:55 -0700 (PDT) Received: from [192.168.1.115] ([185.126.107.38]) by smtp.gmail.com with ESMTPSA id y12-20020adfe6cc000000b0022a293ab1e9sm452848wrm.11.2022.09.19.22.11.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 19 Sep 2022 22:11:53 -0700 (PDT) Message-ID: Date: Tue, 20 Sep 2022 07:11:48 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.13.0 Subject: Re: [PATCH 8/9] softmmu/physmem: Let SysBusState absorb memory region and address space singletons Content-Language: en-US To: Bernhard Beschow , qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Magnus Damm , Aleksandar Rikalo , Bandan Das , Matthew Rosato , Daniel Henrique Barboza , Sergio Lopez , Alexey Kardashevskiy , Xiaojuan Yang , Cameron Esfahani , Michael Rolnik , Song Gao , Jagannathan Raman , Greg Kurz , Kamil Rytarowski , Peter Xu , Joel Stanley , Alistair Francis , "Dr. David Alan Gilbert" , Paolo Bonzini , haxm-team@intel.com, Roman Bolshakov , Markus Armbruster , Eric Auger , David Gibson , =?UTF-8?Q?Daniel_P=2e_Berrang=c3=a9?= , Christian Borntraeger , =?UTF-8?Q?C=c3=a9dric_Le_Goater?= , Stefan Hajnoczi , qemu-block@nongnu.org, Eduardo Habkost , =?UTF-8?Q?Herv=c3=a9_Poussineau?= , qemu-ppc@nongnu.org, Cornelia Huck , Palmer Dabbelt , Helge Deller , Stefano Stabellini , qemu-riscv@nongnu.org, Stafford Horne , Paul Durrant , Havard Skinnemoen , Elena Ufimtseva , Alexander Graf , Thomas Huth , Alex Williamson , Wenchao Wang , Tony Krowiak , Marcel Apfelbaum , qemu-s390x@nongnu.org, =?UTF-8?Q?Marc-Andr=c3=a9_Lureau?= , Mark Cave-Ayland , Eric Farman , Reinoud Zandijk , Alexander Bulekov , Yanan Wang , "Edgar E. Iglesias" , Gerd Hoffmann , Tyrone Ting , xen-devel@lists.xenproject.org, Yoshinori Sato , John Snow , Richard Henderson , Darren Kenny , kvm@vger.kernel.org, Qiuhao Li , John G Johnson , Bin Meng , Sunil Muthuswamy , Max Filippov , qemu-arm@nongnu.org, Marcelo Tosatti , Peter Maydell , Anthony Perard , Andrew Jeffery , Artyom Tarasenko , Halil Pasic , "Maciej S. Szmigiero" , Jason Wang , David Hildenbrand , Laurent Vivier , Alistair Francis , Jason Herne References: <20220919231720.163121-1-shentey@gmail.com> <20220919231720.163121-9-shentey@gmail.com> In-Reply-To: <20220919231720.163121-9-shentey@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Received-SPF: pass client-ip=2a00:1450:4864:20::42e; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-x42e.google.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, NICE_REPLY_A=-0.952, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Reply-to: =?UTF-8?Q?Philippe_Mathieu-Daud=c3=a9?= From: =?UTF-8?Q?Philippe_Mathieu-Daud=c3=a9?= via On 20/9/22 01:17, Bernhard Beschow wrote: > These singletons are actually properties of the system bus but so far it > hasn't been modelled that way. Fix this to make this relationship very > obvious. > > The idea of the patch is to restrain futher proliferation of the use of > get_system_memory() and get_system_io() which are "temprary interfaces" "further", "temporary" > "until a proper bus interface is available". This should now be the > case. > > Note that the new attributes are values rather than a pointers. This > trades pointer dereferences for pointer arithmetic. The idea is to > reduce cache misses - a rule of thumb says that every pointer > dereference causes a cache miss while arithmetic is basically free. > > Signed-off-by: Bernhard Beschow > --- > include/exec/address-spaces.h | 19 ++++++++++++--- > include/hw/sysbus.h | 6 +++++ > softmmu/physmem.c | 46 ++++++++++++++++++----------------- > 3 files changed, 45 insertions(+), 26 deletions(-) > > diff --git a/include/exec/address-spaces.h b/include/exec/address-spaces.h > index d5c8cbd718..b31bd8dcf0 100644 > --- a/include/exec/address-spaces.h > +++ b/include/exec/address-spaces.h > @@ -23,17 +23,28 @@ > > #ifndef CONFIG_USER_ONLY > > -/* Get the root memory region. This interface should only be used temporarily > - * until a proper bus interface is available. > +/** > + * Get the root memory region. This is a legacy function, provided for > + * compatibility. Prefer using SysBusState::system_memory directly. > */ > MemoryRegion *get_system_memory(void); > diff --git a/include/hw/sysbus.h b/include/hw/sysbus.h > index 5bb3b88501..516e9091dc 100644 > --- a/include/hw/sysbus.h > +++ b/include/hw/sysbus.h > @@ -17,6 +17,12 @@ struct SysBusState { > /*< private >*/ > BusState parent_obj; > /*< public >*/ > + > + MemoryRegion system_memory; > + MemoryRegion system_io; > + > + AddressSpace address_space_io; > + AddressSpace address_space_memory; Alternatively (renaming doc accordingly): struct { MemoryRegion mr; AddressSpace as; } io, memory; > }; > > #define TYPE_SYS_BUS_DEVICE "sys-bus-device" > diff --git a/softmmu/physmem.c b/softmmu/physmem.c > index 0ac920d446..07e9a9171c 100644 > --- a/softmmu/physmem.c > +++ b/softmmu/physmem.c > @@ -86,12 +86,6 @@ > */ > RAMList ram_list = { .blocks = QLIST_HEAD_INITIALIZER(ram_list.blocks) }; > > -static MemoryRegion *system_memory; > -static MemoryRegion *system_io; > - > -static AddressSpace address_space_io; > -static AddressSpace address_space_memory; > - > static MemoryRegion io_mem_unassigned; > > typedef struct PhysPageEntry PhysPageEntry; > @@ -146,7 +140,7 @@ typedef struct subpage_t { > #define PHYS_SECTION_UNASSIGNED 0 > > static void io_mem_init(void); > -static void memory_map_init(void); > +static void memory_map_init(SysBusState *sysbus); > static void tcg_log_global_after_sync(MemoryListener *listener); > static void tcg_commit(MemoryListener *listener); > > @@ -2667,37 +2661,45 @@ static void tcg_commit(MemoryListener *listener) > tlb_flush(cpuas->cpu); > } > > -static void memory_map_init(void) > +static void memory_map_init(SysBusState *sysbus) > { No need to pass a singleton by argument. assert(current_machine); You can use get_system_memory() and get_system_io() in place :) LGTM otherwise, great! > - system_memory = g_malloc(sizeof(*system_memory)); > + MemoryRegion *system_memory = &sysbus->system_memory; > + MemoryRegion *system_io = &sysbus->system_io; > > memory_region_init(system_memory, NULL, "system", UINT64_MAX); > - address_space_init(&address_space_memory, system_memory, "memory"); > + address_space_init(&sysbus->address_space_memory, system_memory, "memory"); > > - system_io = g_malloc(sizeof(*system_io)); > memory_region_init_io(system_io, NULL, &unassigned_io_ops, NULL, "io", > 65536); > - address_space_init(&address_space_io, system_io, "I/O"); > + address_space_init(&sysbus->address_space_io, system_io, "I/O"); > } > > MemoryRegion *get_system_memory(void) > { > - return system_memory; > + assert(current_machine); > + > + return ¤t_machine->main_system_bus.system_memory; > } > > MemoryRegion *get_system_io(void) > { > - return system_io; > + assert(current_machine); > + > + return ¤t_machine->main_system_bus.system_io; > } > > AddressSpace *get_address_space_memory(void) > { > - return &address_space_memory; > + assert(current_machine); > + > + return ¤t_machine->main_system_bus.address_space_memory; > } > > AddressSpace *get_address_space_io(void) > { > - return &address_space_io; > + assert(current_machine); > + > + return ¤t_machine->main_system_bus.address_space_io; > }