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.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 2343FC433F5 for ; Sat, 11 Dec 2021 23:56:49 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.245491.423565 (Exim 4.92) (envelope-from ) id 1mwCEF-0007K5-5A; Sat, 11 Dec 2021 23:56:35 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 245491.423565; Sat, 11 Dec 2021 23:56:35 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mwCEF-0007Jf-0V; Sat, 11 Dec 2021 23:56:35 +0000 Received: by outflank-mailman (input) for mailman id 245491; Sat, 11 Dec 2021 23:56:33 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mwCED-0007JG-Jk for xen-devel@lists.xenproject.org; Sat, 11 Dec 2021 23:56:33 +0000 Received: from hera.aquilenet.fr (hera.aquilenet.fr [185.233.100.1]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id f61515b0-5add-11ec-bf02-3911bdbc85ab; Sun, 12 Dec 2021 00:56:31 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 466AB28B; Sun, 12 Dec 2021 00:56:30 +0100 (CET) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id fN01haenjv7s; Sun, 12 Dec 2021 00:56:29 +0100 (CET) Received: from begin (unknown [IPv6:2a01:cb19:956:1b00:de41:a9ff:fe47:ec49]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 00D7A1CF; Sun, 12 Dec 2021 00:56:28 +0100 (CET) Received: from samy by begin with local (Exim 4.95) (envelope-from ) id 1mwCE8-001qNi-88; Sun, 12 Dec 2021 00:56:28 +0100 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: f61515b0-5add-11ec-bf02-3911bdbc85ab X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Date: Sun, 12 Dec 2021 00:56:28 +0100 From: Samuel Thibault To: Juergen Gross Cc: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org, wl@xen.org Subject: Re: [PATCH 01/10] mini-os: split e820 map handling into new source file Message-ID: <20211211235628.kcbzkjl4xnlduu5w@begin> Mail-Followup-To: Samuel Thibault , Juergen Gross , minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org, wl@xen.org References: <20211206072337.9517-1-jgross@suse.com> <20211206072337.9517-2-jgross@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20211206072337.9517-2-jgross@suse.com> Organization: I am not organized User-Agent: NeoMutt/20170609 (1.8.3) X-Spamd-Bar: / Authentication-Results: hera.aquilenet.fr; none X-Rspamd-Server: hera X-Rspamd-Queue-Id: 466AB28B X-Spamd-Result: default: False [0.40 / 15.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; HAS_ORG_HEADER(0.00)[]; RCVD_COUNT_THREE(0.00)[3]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_LAST(0.00)[]; MID_RHS_NOT_FQDN(0.50)[] Juergen Gross, le lun. 06 déc. 2021 08:23:28 +0100, a ecrit: > Introduce e820.c containing all the E820 memory map handling. > > No functional change. > > Signed-off-by: Juergen Gross Reviewed-by: Samuel Thibault > --- > Makefile | 1 + > arch/arm/mm.c | 8 ---- > arch/x86/mm.c | 70 +---------------------------- > e820.c | 119 +++++++++++++++++++++++++++++++++++++++++++++++++ > include/e820.h | 6 +++ > 5 files changed, 128 insertions(+), 76 deletions(-) > create mode 100644 e820.c > > diff --git a/Makefile b/Makefile > index 4b76b55..06b60fc 100644 > --- a/Makefile > +++ b/Makefile > @@ -41,6 +41,7 @@ src-$(CONFIG_TPMFRONT) += tpmfront.c > src-$(CONFIG_TPM_TIS) += tpm_tis.c > src-$(CONFIG_TPMBACK) += tpmback.c > src-y += daytime.c > +src-y += e820.c > src-y += events.c > src-$(CONFIG_FBFRONT) += fbfront.c > src-y += gntmap.c > diff --git a/arch/arm/mm.c b/arch/arm/mm.c > index f806c9f..9068166 100644 > --- a/arch/arm/mm.c > +++ b/arch/arm/mm.c > @@ -7,14 +7,6 @@ > #include > > uint32_t physical_address_offset; > -struct e820entry e820_map[1] = { > - { > - .addr = 0, > - .size = ULONG_MAX - 1, > - .type = E820_RAM > - } > -}; > -unsigned e820_entries = 1; > > unsigned long allocate_ondemand(unsigned long n, unsigned long alignment) > { > diff --git a/arch/x86/mm.c b/arch/x86/mm.c > index 8ba14a5..8df93da 100644 > --- a/arch/x86/mm.c > +++ b/arch/x86/mm.c > @@ -64,15 +64,6 @@ extern char stack[]; > extern void page_walk(unsigned long va); > > #ifdef CONFIG_PARAVIRT > -struct e820entry e820_map[1] = { > - { > - .addr = 0, > - .size = ULONG_MAX - 1, > - .type = E820_RAM > - } > -}; > -unsigned e820_entries = 1; > - > void arch_mm_preinit(void *p) > { > start_info_t *si = p; > @@ -112,25 +103,11 @@ desc_ptr idt_ptr = > .base = (unsigned long)&idt, > }; > > -struct e820entry e820_map[E820_MAX]; > -unsigned e820_entries; > - > -static char *e820_types[E820_TYPES] = { > - [E820_RAM] = "RAM", > - [E820_RESERVED] = "Reserved", > - [E820_ACPI] = "ACPI", > - [E820_NVS] = "NVS", > - [E820_UNUSABLE] = "Unusable", > - [E820_PMEM] = "PMEM" > -}; > - > void arch_mm_preinit(void *p) > { > long ret; > domid_t domid = DOMID_SELF; > - struct xen_memory_map memmap; > - int i; > - unsigned long pfn, max = 0; > + unsigned long max; > > pt_base = page_table_base; > first_free_pfn = PFN_UP(to_phys(&_end)); > @@ -142,53 +119,10 @@ void arch_mm_preinit(void *p) > } > last_free_pfn = ret; > > - memmap.nr_entries = E820_MAX; > - set_xen_guest_handle(memmap.buffer, e820_map); > - ret = HYPERVISOR_memory_op(XENMEM_memory_map, &memmap); > - if ( ret < 0 ) > - { > - xprintk("could not get memory map\n"); > - do_exit(); > - } > - e820_entries = memmap.nr_entries; > - > - for ( i = 0; i < e820_entries; i++ ) > - { > - if ( e820_map[i].type != E820_RAM ) > - continue; > - pfn = (e820_map[i].addr + e820_map[i].size) >> PAGE_SHIFT; > - if ( pfn > max ) > - max = pfn; > - } > - > + max = e820_get_maxpfn(); > if ( max < last_free_pfn ) > last_free_pfn = max; > } > - > -void arch_print_memmap(void) > -{ > - int i; > - unsigned long from, to; > - char *type; > - char buf[12]; > - > - printk("Memory map:\n"); > - for ( i = 0; i < e820_entries; i++ ) > - { > - if ( e820_map[i].type >= E820_TYPES || !e820_types[e820_map[i].type] ) > - { > - snprintf(buf, sizeof(buf), "%8x", e820_map[i].type); > - type = buf; > - } > - else > - { > - type = e820_types[e820_map[i].type]; > - } > - from = e820_map[i].addr; > - to = from + e820_map[i].size - 1; > - printk("%012lx-%012lx: %s\n", from, to, type); > - } > -} > #endif > > /* > diff --git a/e820.c b/e820.c > new file mode 100644 > index 0000000..2165280 > --- /dev/null > +++ b/e820.c > @@ -0,0 +1,119 @@ > +/* -*- Mode:C; c-basic-offset:4; tab-width:4 -*- > + * > + * (C) 2021 - Juergen Gross, SUSE Software Solutions Germany GmbH > + * > + * Permission is hereby granted, free of charge, to any person obtaining a copy > + * of this software and associated documentation files (the "Software"), to > + * deal in the Software without restriction, including without limitation the > + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or > + * sell copies of the Software, and to permit persons to whom the Software is > + * furnished to do so, subject to the following conditions: > + * > + * The above copyright notice and this permission notice shall be included in > + * all copies or substantial portions of the Software. > + * > + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR > + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, > + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE > + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER > + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING > + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER > + * DEALINGS IN THE SOFTWARE. > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#ifdef CONFIG_E820_TRIVIAL > +struct e820entry e820_map[1] = { > + { > + .addr = 0, > + .size = ULONG_MAX - 1, > + .type = E820_RAM > + } > +}; > + > +unsigned e820_entries = 1; > + > +static void e820_get_memmap(void) > +{ > +} > + > +#else > +struct e820entry e820_map[E820_MAX]; > +unsigned e820_entries; > + > +static char *e820_types[E820_TYPES] = { > + [E820_RAM] = "RAM", > + [E820_RESERVED] = "Reserved", > + [E820_ACPI] = "ACPI", > + [E820_NVS] = "NVS", > + [E820_UNUSABLE] = "Unusable", > + [E820_PMEM] = "PMEM" > +}; > + > +static void e820_get_memmap(void) > +{ > + long ret; > + struct xen_memory_map memmap; > + > + memmap.nr_entries = E820_MAX; > + set_xen_guest_handle(memmap.buffer, e820_map); > + ret = HYPERVISOR_memory_op(XENMEM_memory_map, &memmap); > + if ( ret < 0 ) > + { > + xprintk("could not get memory map\n"); > + do_exit(); > + } > + e820_entries = memmap.nr_entries; > +} > + > +void arch_print_memmap(void) > +{ > + int i; > + unsigned long from, to; > + char *type; > + char buf[12]; > + > + printk("Memory map:\n"); > + for ( i = 0; i < e820_entries; i++ ) > + { > + if ( e820_map[i].type >= E820_TYPES || !e820_types[e820_map[i].type] ) > + { > + snprintf(buf, sizeof(buf), "%8x", e820_map[i].type); > + type = buf; > + } > + else > + { > + type = e820_types[e820_map[i].type]; > + } > + from = e820_map[i].addr; > + to = from + e820_map[i].size - 1; > + printk("%012lx-%012lx: %s\n", from, to, type); > + } > +} > +#endif > + > +unsigned long e820_get_maxpfn(void) > +{ > + int i; > + unsigned long pfn, max = 0; > + > + e820_get_memmap(); > + > + for ( i = 0; i < e820_entries; i++ ) > + { > + if ( e820_map[i].type != E820_RAM ) > + continue; > + pfn = (e820_map[i].addr + e820_map[i].size) >> PAGE_SHIFT; > + if ( pfn > max ) > + max = pfn; > + } > + > + return max; > +} > diff --git a/include/e820.h b/include/e820.h > index 920551c..af2129f 100644 > --- a/include/e820.h > +++ b/include/e820.h > @@ -24,6 +24,10 @@ > #ifndef __E820_HEADER > #define __E820_HEADER > > +#if defined(__arm__) || defined(__aarch64__) || defined(CONFIG_PARAVIRT) > +#define CONFIG_E820_TRIVIAL > +#endif > + > /* PC BIOS standard E820 types and structure. */ > #define E820_RAM 1 > #define E820_RESERVED 2 > @@ -45,4 +49,6 @@ struct __packed e820entry { > extern struct e820entry e820_map[]; > extern unsigned e820_entries; > > +unsigned long e820_get_maxpfn(void); > + > #endif /*__E820_HEADER*/ > -- > 2.26.2 > -- Samuel * c is away : cuisine; bouffe oh, moi je fais plutôt cuisine & bouffe en fait :) oui c'est vrai, certains font cuisine && bouffe (juste au cas où... ;-)) ( cuisine && bouffe ) || restau voire ((cuisine && bouffe) || restau) & apéritif -+- #ens-mim -+-