From nobody Mon May 6 01:46:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1640076444; cv=none; d=zohomail.com; s=zohoarc; b=CvOScrQIxxaY3e94XOpl4OO338kz+0ROdnuxoom26FP+aFm7eg7c1qN8btijrcf/pua+agdxD7PuJldz8WNhiPYvmcqY1p0KoJ/dA0G/yxU22bobTbYSgTwcGpS8BPHLZEf7INOTcG+98ePJexSF/qmyEO7hmZ8ln0ZA6vq6i+s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1640076444; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Cvjzn61nlQz/5cNRGk/V3qCPy6sEZi3f9w8y3gbMdqw=; b=L+foTidc6Fbt2JVP6L/Oz206Fc7DBiXyy6V0k4egqQ1bEQmwRqhnGWm6Gnuw/39zVorbByLRv20E1/cJqYqdoVaGMS1IQMAf9PlQJgxH+zpbaGgOp9oqdevS1s5sSAp5Mj3KmlAqM4u/IZiASejYUiSRgJCGYnS4vuERELvVHsY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1640076444164552.7756689315127; Tue, 21 Dec 2021 00:47:24 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.250187.430905 (Exim 4.92) (envelope-from ) id 1mzanU-0004B8-S6; Tue, 21 Dec 2021 08:47:00 +0000 Received: by outflank-mailman (output) from mailman id 250187.430905; Tue, 21 Dec 2021 08:47:00 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mzanU-0004AK-IH; Tue, 21 Dec 2021 08:47:00 +0000 Received: by outflank-mailman (input) for mailman id 250187; Tue, 21 Dec 2021 08:46:58 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mzanS-0002yE-8m for xen-devel@lists.xenproject.org; Tue, 21 Dec 2021 08:46:58 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 8b20b9f3-623a-11ec-9e60-abaf8a552007; Tue, 21 Dec 2021 09:46:52 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 454F81F388; Tue, 21 Dec 2021 08:46:52 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 1B70313E02; Tue, 21 Dec 2021 08:46:52 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id KJN2BXyUwWFHMAAAMHmgww (envelope-from ); Tue, 21 Dec 2021 08:46:52 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 8b20b9f3-623a-11ec-9e60-abaf8a552007 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1640076412; h=from:from:reply-to: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=Cvjzn61nlQz/5cNRGk/V3qCPy6sEZi3f9w8y3gbMdqw=; b=fa8B1tQDlQXQ4Zt907exiM6Ql2bQhOqA1zwNXh83f22gymhDvkN6ex5NyHRm8Xje0g1RF/ zO77Ntx1TsENJ1Q3imQwrB/gNxiaKA1BhSlTiz8foW9/jrzSrJplsJUYgRwyyDrKS0V1pu DaQT7mYXn6HwUg4s970wqufVJaGqoTQ= From: Juergen Gross To: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org Cc: samuel.thibault@ens-lyon.org, wl@xen.org, Juergen Gross Subject: [PATCH v3 01/10] mini-os: split e820 map handling into new source file Date: Tue, 21 Dec 2021 09:46:27 +0100 Message-Id: <20211221084636.6987-2-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20211221084636.6987-1-jgross@suse.com> References: <20211221084636.6987-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1640077347817100001 Content-Type: text/plain; charset="utf-8" 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) +=3D tpmfront.c src-$(CONFIG_TPM_TIS) +=3D tpm_tis.c src-$(CONFIG_TPMBACK) +=3D tpmback.c src-y +=3D daytime.c +src-y +=3D e820.c src-y +=3D events.c src-$(CONFIG_FBFRONT) +=3D fbfront.c src-y +=3D 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 =20 uint32_t physical_address_offset; -struct e820entry e820_map[1] =3D { - { - .addr =3D 0, - .size =3D ULONG_MAX - 1, - .type =3D E820_RAM - } -}; -unsigned e820_entries =3D 1; =20 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); =20 #ifdef CONFIG_PARAVIRT -struct e820entry e820_map[1] =3D { - { - .addr =3D 0, - .size =3D ULONG_MAX - 1, - .type =3D E820_RAM - } -}; -unsigned e820_entries =3D 1; - void arch_mm_preinit(void *p) { start_info_t *si =3D p; @@ -112,25 +103,11 @@ desc_ptr idt_ptr =3D .base =3D (unsigned long)&idt, }; =20 -struct e820entry e820_map[E820_MAX]; -unsigned e820_entries; - -static char *e820_types[E820_TYPES] =3D { - [E820_RAM] =3D "RAM", - [E820_RESERVED] =3D "Reserved", - [E820_ACPI] =3D "ACPI", - [E820_NVS] =3D "NVS", - [E820_UNUSABLE] =3D "Unusable", - [E820_PMEM] =3D "PMEM" -}; - void arch_mm_preinit(void *p) { long ret; domid_t domid =3D DOMID_SELF; - struct xen_memory_map memmap; - int i; - unsigned long pfn, max =3D 0; + unsigned long max; =20 pt_base =3D page_table_base; first_free_pfn =3D PFN_UP(to_phys(&_end)); @@ -142,53 +119,10 @@ void arch_mm_preinit(void *p) } last_free_pfn =3D ret; =20 - memmap.nr_entries =3D E820_MAX; - set_xen_guest_handle(memmap.buffer, e820_map); - ret =3D HYPERVISOR_memory_op(XENMEM_memory_map, &memmap); - if ( ret < 0 ) - { - xprintk("could not get memory map\n"); - do_exit(); - } - e820_entries =3D memmap.nr_entries; - - for ( i =3D 0; i < e820_entries; i++ ) - { - if ( e820_map[i].type !=3D E820_RAM ) - continue; - pfn =3D (e820_map[i].addr + e820_map[i].size) >> PAGE_SHIFT; - if ( pfn > max ) - max =3D pfn; - } - + max =3D e820_get_maxpfn(); if ( max < last_free_pfn ) last_free_pfn =3D max; } - -void arch_print_memmap(void) -{ - int i; - unsigned long from, to; - char *type; - char buf[12]; - - printk("Memory map:\n"); - for ( i =3D 0; i < e820_entries; i++ ) - { - if ( e820_map[i].type >=3D E820_TYPES || !e820_types[e820_map[i].t= ype] ) - { - snprintf(buf, sizeof(buf), "%8x", e820_map[i].type); - type =3D buf; - } - else - { - type =3D e820_types[e820_map[i].type]; - } - from =3D e820_map[i].addr; - to =3D from + e820_map[i].size - 1; - printk("%012lx-%012lx: %s\n", from, to, type); - } -} #endif =20 /* 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, an= d/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] =3D { + { + .addr =3D 0, + .size =3D ULONG_MAX - 1, + .type =3D E820_RAM + } +}; + +unsigned e820_entries =3D 1; + +static void e820_get_memmap(void) +{ +} + +#else +struct e820entry e820_map[E820_MAX]; +unsigned e820_entries; + +static char *e820_types[E820_TYPES] =3D { + [E820_RAM] =3D "RAM", + [E820_RESERVED] =3D "Reserved", + [E820_ACPI] =3D "ACPI", + [E820_NVS] =3D "NVS", + [E820_UNUSABLE] =3D "Unusable", + [E820_PMEM] =3D "PMEM" +}; + +static void e820_get_memmap(void) +{ + long ret; + struct xen_memory_map memmap; + + memmap.nr_entries =3D E820_MAX; + set_xen_guest_handle(memmap.buffer, e820_map); + ret =3D HYPERVISOR_memory_op(XENMEM_memory_map, &memmap); + if ( ret < 0 ) + { + xprintk("could not get memory map\n"); + do_exit(); + } + e820_entries =3D 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 =3D 0; i < e820_entries; i++ ) + { + if ( e820_map[i].type >=3D E820_TYPES || !e820_types[e820_map[i].t= ype] ) + { + snprintf(buf, sizeof(buf), "%8x", e820_map[i].type); + type =3D buf; + } + else + { + type =3D e820_types[e820_map[i].type]; + } + from =3D e820_map[i].addr; + to =3D 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 =3D 0; + + e820_get_memmap(); + + for ( i =3D 0; i < e820_entries; i++ ) + { + if ( e820_map[i].type !=3D E820_RAM ) + continue; + pfn =3D (e820_map[i].addr + e820_map[i].size) >> PAGE_SHIFT; + if ( pfn > max ) + max =3D 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 =20 +#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; =20 +unsigned long e820_get_maxpfn(void); + #endif /*__E820_HEADER*/ --=20 2.26.2 From nobody Mon May 6 01:46:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1640076444; cv=none; d=zohomail.com; s=zohoarc; b=EfUuL2JTn977jj2dZXctRUjVdiGUW58b911+ficxOjBo/H3GzPNmExO/yG0YevjfQ9A71l6znmf/OMW4GlBLPTY+NFr6y4sRQUOCAr8dtKwt9CEysbZCuxES6z2pvMmuioFuhZOEUjMPjGQKvMVAhlYaMx/ChL9fPaXdxKFA0iI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1640076444; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=cWXSsRb7aAVsvcWbgBY23t6rGMkd9cnCIBDGNyaoF64=; b=UxhkNcxOiRPiT6qGN0rsE4Ej31NfPrH3YdLBcK+Zn4x9t/07+Ik93K30MciocPpA4lZQlSU8C4WcpBIc5+VtHehcm8vtHwLlgPYAMC3G/lCBEgsdZouA+Ha9cqttmAVFZi7MWBfHkB85moa02rb9ywUpn3L1vWRclaE2dDiPRA0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1640076444156443.66004774900387; Tue, 21 Dec 2021 00:47:24 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.250183.430879 (Exim 4.92) (envelope-from ) id 1mzanS-0003bI-BB; Tue, 21 Dec 2021 08:46:58 +0000 Received: by outflank-mailman (output) from mailman id 250183.430879; Tue, 21 Dec 2021 08:46:58 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mzanS-0003Zh-15; Tue, 21 Dec 2021 08:46:58 +0000 Received: by outflank-mailman (input) for mailman id 250183; Tue, 21 Dec 2021 08:46:56 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mzanQ-0002yE-8g for xen-devel@lists.xenproject.org; Tue, 21 Dec 2021 08:46:56 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 8b3e5efb-623a-11ec-9e60-abaf8a552007; Tue, 21 Dec 2021 09:46:52 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 75C921F3B6; Tue, 21 Dec 2021 08:46:52 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 4B40013BEC; Tue, 21 Dec 2021 08:46:52 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id kKs1EXyUwWFHMAAAMHmgww (envelope-from ); Tue, 21 Dec 2021 08:46:52 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 8b3e5efb-623a-11ec-9e60-abaf8a552007 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1640076412; h=from:from:reply-to: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=cWXSsRb7aAVsvcWbgBY23t6rGMkd9cnCIBDGNyaoF64=; b=irEHSRRpWz7T4cfCEBeCvZnHmHhIhSwu2Q6XuAxDuRJkO4E8/+tswxDUV4Kmbjqezrdxh/ RTssKq/iFE2QHg+cTsC3kvgyUH+WtXXtZLkgrbcIMVK4ZYxHmn3zHHkoSS/6twrBC012mP SjScZVuWvOMoFJLFRNHe19R2YaVlJ3c= From: Juergen Gross To: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org Cc: samuel.thibault@ens-lyon.org, wl@xen.org, Juergen Gross Subject: [PATCH v3 02/10] mini-os: sort and sanitize e820 memory map Date: Tue, 21 Dec 2021 09:46:28 +0100 Message-Id: <20211221084636.6987-3-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20211221084636.6987-1-jgross@suse.com> References: <20211221084636.6987-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1640077347931100002 Content-Type: text/plain; charset="utf-8" Do some processing of the E820 memory map obtained from the hypervisor: - align the entries to page boundaries - sort the entries by their start address - merge adjacent entries of same type This is relevant for PVH mode only. Signed-off-by: Juergen Gross Reviewed-by: Samuel Thibault --- V2: - correct page boundary rounding - handle overlaps after rounding (Samuel Thibault) - improve sorting (Samuel Thibault) V3: - small optimization in e820_sanitize() (Samuel Thibault) --- e820.c | 186 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 186 insertions(+) diff --git a/e820.c b/e820.c index 2165280..70286cb 100644 --- a/e820.c +++ b/e820.c @@ -57,6 +57,190 @@ static char *e820_types[E820_TYPES] =3D { [E820_PMEM] =3D "PMEM" }; =20 +/* + * E820 type based bitmask for deciding how to round entries to page + * boundaries: A set bit means the type relates to a resource managed by + * Mini-OS (e.g. RAM), so rounding needs to be done to only include pages + * completely of the related type (narrowing). All other types need to be + * rounded to include all pages with parts of that type (widening). + */ +#define E820_NARROW ((1U << E820_RAM) | (1U << E820_NVS) | (1 << E820_PMEM= )) + +/* Private type used to mark a range temporarily as reserved (lowest prio)= . */ +#define E820_TMP_RESERVED 0 + +static void e820_remove_entry(int idx) +{ + int i; + + e820_entries--; + for ( i =3D idx; i < e820_entries; i++ ) + e820_map[i] =3D e820_map[i + 1]; +} + +static void e820_insert_entry_at(int idx, unsigned long addr, + unsigned long size, unsigned int type) +{ + int i; + + if ( e820_entries =3D=3D E820_MAX ) + { + xprintk("E820 memory map overflow\n"); + do_exit(); + } + + e820_entries++; + for ( i =3D e820_entries - 1; i > idx; i-- ) + e820_map[i] =3D e820_map[i - 1]; + + e820_map[idx].addr =3D addr; + e820_map[idx].size =3D size; + e820_map[idx].type =3D type; +} + +static void e820_insert_entry(unsigned long addr, unsigned long size, + unsigned int type) +{ + int i; + + for ( i =3D 0; i < e820_entries && addr > e820_map[i].addr; i++ ); + + e820_insert_entry_at(i, addr, size, type); +} + +static void e820_swap_entries(int idx1, int idx2) +{ + struct e820entry entry; + + entry =3D e820_map[idx1]; + e820_map[idx1] =3D e820_map[idx2]; + e820_map[idx2] =3D entry; +} + +/* + * Do a memory map sanitizing sweep: + * - sort the entries by start address + * - remove overlaps of entries (higher type value wins) + * - merge adjacent entries of same type + */ +static void e820_process_entries(void) +{ + int i, j; + unsigned long end, start; + unsigned int type; + + /* Sort entries. */ + for ( i =3D 1; i < e820_entries; i++ ) + for ( j =3D i; j > 0 && e820_map[j - 1].addr > e820_map[j].addr; j= -- ) + e820_swap_entries(j - 1, j); + + /* Handle overlapping entries (higher type values win). */ + for ( i =3D 1; i < e820_entries; i++ ) + { + if ( e820_map[i - 1].addr + e820_map[i - 1].size <=3D e820_map[i].= addr ) + continue; + if ( e820_map[i - 1].addr < e820_map[i].addr ) + { + e820_insert_entry_at(i - 1, e820_map[i - 1].addr, + e820_map[i].addr - e820_map[i - 1].addr, + e820_map[i - 1].type); + e820_map[i].addr +=3D e820_map[i - 1].size; + e820_map[i].size -=3D e820_map[i - 1].size; + i++; + } + if ( e820_map[i - 1].type < e820_map[i].type ) + e820_swap_entries(i - 1, i); + if ( e820_map[i - 1].size >=3D e820_map[i].size ) + { + e820_remove_entry(i); + i--; + } + else + { + start =3D e820_map[i].addr + e820_map[i - 1].size; + end =3D e820_map[i].addr + e820_map[i].size; + type =3D e820_map[i].type; + e820_remove_entry(i); + e820_insert_entry(start, end - start, type); + } + } + + /* Merge adjacent entries. */ + for ( i =3D 0; i < e820_entries - 1; i++ ) + { + if ( e820_map[i].type =3D=3D e820_map[i + 1].type && + e820_map[i].addr + e820_map[i].size >=3D e820_map[i + 1].addr= ) + { + if ( e820_map[i].addr + e820_map[i].size < + e820_map[i + 1].addr + e820_map[i + 1].size ) + { + e820_map[i].size =3D e820_map[i + 1].addr - e820_map[i].ad= dr + + e820_map[i + 1].size; + } + e820_remove_entry(i + 1); + i--; + } + } +} + +/* + * Transform memory map into a well sorted map without any overlaps. + * - sort map entries by start address + * - handle overlaps + * - merge adjacent entries of same type (possibly removing boundary in the + * middle of a page) + * - trim entries to page boundaries (depending on type either expanding + * the entry or narrowing it down) + * - repeat first 3 sanitizing steps + * - make remaining temporarily reserved entries permanently reserved + */ +static void e820_sanitize(void) +{ + int i; + unsigned long end, start; + + /* Sanitize memory map in current form. */ + e820_process_entries(); + + /* Adjust map entries to page boundaries. */ + for ( i =3D 0; i < e820_entries; i++ ) + { + start =3D e820_map[i].addr; + end =3D start + e820_map[i].size; + if ( (1U << e820_map[i].type) & E820_NARROW ) + { + if ( start & (PAGE_SIZE - 1) ) + { + start =3D round_pgup(start); + e820_insert_entry_at(i, start - PAGE_SIZE, PAGE_SIZE, + E820_TMP_RESERVED); + i++; + } + if ( end & (PAGE_SIZE - 1) ) + { + end =3D round_pgdown(end); + e820_insert_entry_at(i + 1, end, PAGE_SIZE, E820_TMP_RESER= VED); + i++; + } + } + else + { + start =3D round_pgdown(start); + end =3D round_pgup(end); + } + e820_map[i].addr =3D start; + e820_map[i].size =3D end - start; + } + + /* Sanitize memory map (again). */ + e820_process_entries(); + + /* Make remaining temporarily reserved entries permanently reserved. */ + for ( i =3D 0; i < e820_entries; i++ ) + if ( e820_map[i].type =3D=3D E820_TMP_RESERVED ) + e820_map[i].type =3D E820_RESERVED; +} + static void e820_get_memmap(void) { long ret; @@ -71,6 +255,8 @@ static void e820_get_memmap(void) do_exit(); } e820_entries =3D memmap.nr_entries; + + e820_sanitize(); } =20 void arch_print_memmap(void) --=20 2.26.2 From nobody Mon May 6 01:46:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1640076445; cv=none; d=zohomail.com; s=zohoarc; b=W5ZYs7nEJHKw6blU7TRNH1Fcffx3g0hNBHxxoC9kIJPcK6rn5l5hJhlLxrfMTqfgUoOaPky+PP5ZL+QyLgbgNoDb6Pbglg1a6E48RE7PupsBhNbcT3oTsndTbEZ0TBGZcEmX9CKeuzDVJCi3O10RmJdMoMD30LwkvxrnCyuA+tw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1640076445; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=UOETZh2f6WeeCiugBSdED352ymyLb1Vp+v99fCDGOVo=; b=N51eyAamebj7DIFwaXP0KuNIZUR/vNjIMcD6MDHPrzqw1A0/kfUMSz8ZdG7ed6BCGsBRoMtQbqIFEegH8DCzZeKhD3E8ugSLARyJJkvCImRGiwz5/z3j3Z40bAyTsK9ee8aj4igqS6/oo25xN9vaQ6qV2lGV4t0k5s8FRNfb1Os= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1640076445440163.81793042917798; Tue, 21 Dec 2021 00:47:25 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.250179.430855 (Exim 4.92) (envelope-from ) id 1mzanQ-0003GF-GN; Tue, 21 Dec 2021 08:46:56 +0000 Received: by outflank-mailman (output) from mailman id 250179.430855; Tue, 21 Dec 2021 08:46:56 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mzanQ-0003G1-C3; Tue, 21 Dec 2021 08:46:56 +0000 Received: by outflank-mailman (input) for mailman id 250179; Tue, 21 Dec 2021 08:46:54 +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 1mzanO-0002z5-BS for xen-devel@lists.xenproject.org; Tue, 21 Dec 2021 08:46:54 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 8b55e180-623a-11ec-8d39-b1a4ed000e3e; Tue, 21 Dec 2021 09:46:53 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id A534421106; Tue, 21 Dec 2021 08:46:52 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 7BA5513BEC; Tue, 21 Dec 2021 08:46:52 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id mNnzHHyUwWFHMAAAMHmgww (envelope-from ); Tue, 21 Dec 2021 08:46:52 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 8b55e180-623a-11ec-8d39-b1a4ed000e3e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1640076412; h=from:from:reply-to: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=UOETZh2f6WeeCiugBSdED352ymyLb1Vp+v99fCDGOVo=; b=K+hcy7x1iKb9VYzLkL4sA69QZvp0PvKxySYlmloAtVeZRTMhdSj8eVGQS04N0xJ+Ld7obm xRv7sZHBRokmzx5i3PO8qJ0bp9IJUmQ/87QIPz+vC6v2CaiLk/dX/EaUc2p4yh96L/uWiF icnbrFHADIeXyOG/2SKNSaTodzd0VJQ= From: Juergen Gross To: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org Cc: samuel.thibault@ens-lyon.org, wl@xen.org, Juergen Gross Subject: [PATCH v3 03/10] mini-os: don't assume contiguous RAM when initializing in PVH mode Date: Tue, 21 Dec 2021 09:46:29 +0100 Message-Id: <20211221084636.6987-4-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20211221084636.6987-1-jgross@suse.com> References: <20211221084636.6987-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1640077347951100004 Content-Type: text/plain; charset="utf-8" Sizing the available memory should respect memory holes, so look at the memory map when setting the boundary for the memory allocator. Signed-off-by: Juergen Gross Reviewed-by: Samuel Thibault --- V2: - rename "max" to "start" (Samuel Thibault) --- arch/x86/mm.c | 6 +----- e820.c | 14 ++++++++------ include/e820.h | 2 +- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/arch/x86/mm.c b/arch/x86/mm.c index 8df93da..3bf6170 100644 --- a/arch/x86/mm.c +++ b/arch/x86/mm.c @@ -107,7 +107,6 @@ void arch_mm_preinit(void *p) { long ret; domid_t domid =3D DOMID_SELF; - unsigned long max; =20 pt_base =3D page_table_base; first_free_pfn =3D PFN_UP(to_phys(&_end)); @@ -117,11 +116,8 @@ void arch_mm_preinit(void *p) xprintk("could not get memory size\n"); do_exit(); } - last_free_pfn =3D ret; =20 - max =3D e820_get_maxpfn(); - if ( max < last_free_pfn ) - last_free_pfn =3D max; + last_free_pfn =3D e820_get_maxpfn(ret); } #endif =20 diff --git a/e820.c b/e820.c index 70286cb..8030f43 100644 --- a/e820.c +++ b/e820.c @@ -285,10 +285,10 @@ void arch_print_memmap(void) } #endif =20 -unsigned long e820_get_maxpfn(void) +unsigned long e820_get_maxpfn(unsigned long pages) { int i; - unsigned long pfn, max =3D 0; + unsigned long pfns, start =3D 0; =20 e820_get_memmap(); =20 @@ -296,10 +296,12 @@ unsigned long e820_get_maxpfn(void) { if ( e820_map[i].type !=3D E820_RAM ) continue; - pfn =3D (e820_map[i].addr + e820_map[i].size) >> PAGE_SHIFT; - if ( pfn > max ) - max =3D pfn; + pfns =3D e820_map[i].size >> PAGE_SHIFT; + start =3D e820_map[i].addr >> PAGE_SHIFT; + if ( pages <=3D pfns ) + return start + pages; + pages -=3D pfns; } =20 - return max; + return start + pfns; } diff --git a/include/e820.h b/include/e820.h index af2129f..6a57f05 100644 --- a/include/e820.h +++ b/include/e820.h @@ -49,6 +49,6 @@ struct __packed e820entry { extern struct e820entry e820_map[]; extern unsigned e820_entries; =20 -unsigned long e820_get_maxpfn(void); +unsigned long e820_get_maxpfn(unsigned long pages); =20 #endif /*__E820_HEADER*/ --=20 2.26.2 From nobody Mon May 6 01:46:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1640076446; cv=none; d=zohomail.com; s=zohoarc; b=eLv9O/sXeVKwKxuOiZ2KRHLmZizePMRBO5NVvbnMf0KoDwfgA5dGm7+aO3SLwtlqDEw9Ye0/zJp5rB+e84V2OjDKHDQi+UL6NrrXekqYn7W3hUj0468gQwZM2zVt6tTU61y7+J83LD5porK3Tm1yU0Dm9WqQVJzNJ1HrPcA7VS8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1640076446; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Re/Y81QPVsmb4huxIK864YtWHyj0GbHOxxQ8cDq1GGE=; b=BOd2S7OthsCmG7CWP/undeiG80GW5hDSlBUmBBmBkE5mpP6yNkXIi28H3/sEs6aw1TgPZ412jm6q2RxrRV//lubL5UuZJxREyHFuF4IXtydY8KSLgImrxe8e+OTPW9v7Nd3+z1XKhaJjYhoEIqKtWMr2LLBDDggW2eQjPWW59/g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1640076446272972.0992773145518; Tue, 21 Dec 2021 00:47:26 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.250193.430939 (Exim 4.92) (envelope-from ) id 1mzanY-0004y7-EY; Tue, 21 Dec 2021 08:47:04 +0000 Received: by outflank-mailman (output) from mailman id 250193.430939; Tue, 21 Dec 2021 08:47:04 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mzanY-0004v8-49; Tue, 21 Dec 2021 08:47:04 +0000 Received: by outflank-mailman (input) for mailman id 250193; Tue, 21 Dec 2021 08:47:01 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mzanV-0002yE-9F for xen-devel@lists.xenproject.org; Tue, 21 Dec 2021 08:47:01 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 8b7a08f9-623a-11ec-9e60-abaf8a552007; Tue, 21 Dec 2021 09:46:53 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id D46A31F3A6; Tue, 21 Dec 2021 08:46:52 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id ABE9513BEC; Tue, 21 Dec 2021 08:46:52 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id SGmyKHyUwWFHMAAAMHmgww (envelope-from ); Tue, 21 Dec 2021 08:46:52 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 8b7a08f9-623a-11ec-9e60-abaf8a552007 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1640076412; h=from:from:reply-to: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=Re/Y81QPVsmb4huxIK864YtWHyj0GbHOxxQ8cDq1GGE=; b=Mfrv1lJy+dqaaiGaP9d3hiugLOv7FGKQy3VpDcnzqICvE8JgzAtISoxngcE0mWGgL/Ds4T OnYA5ETKwVe//bIhMtXU6KJmmdvNlFNby+tVxCNiMMPfElPBj5XzlC0WbFbGEaODkDZjkR TxQ74K3Oq77dhzzrUKv+831L82dSIwg= From: Juergen Gross To: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org Cc: samuel.thibault@ens-lyon.org, wl@xen.org, Juergen Gross Subject: [PATCH v3 04/10] mini-os: respect memory map when ballooning up Date: Tue, 21 Dec 2021 09:46:30 +0100 Message-Id: <20211221084636.6987-5-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20211221084636.6987-1-jgross@suse.com> References: <20211221084636.6987-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1640076446772100015 Content-Type: text/plain; charset="utf-8" Today Mini-OS won't look at the memory map when ballooning up. This can result in problems for PVH domains with more than 4 GB of RAM, as ballooning will happily run into the ACPI area. Fix that by adding only pages being marked as RAM in the memory map and by distinguishing between the current number of RAM pages and the first unallocated page. Signed-off-by: Juergen Gross Reviewed-by: Samuel Thibault --- V2: - rename and fix e820_get_max_pages() (Samuel Thibault) V3: - fix loop condition --- arch/arm/mm.c | 3 +++ arch/x86/balloon.c | 4 ++-- arch/x86/mm.c | 2 ++ balloon.c | 33 ++++++++++++++++++++++++--------- e820.c | 21 ++++++++++++++++++++- include/balloon.h | 5 +++-- include/e820.h | 1 + mm.c | 7 ++----- 8 files changed, 57 insertions(+), 19 deletions(-) diff --git a/arch/arm/mm.c b/arch/arm/mm.c index 9068166..11962f8 100644 --- a/arch/arm/mm.c +++ b/arch/arm/mm.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include =20 @@ -70,6 +71,8 @@ void arch_init_mm(unsigned long *start_pfn_p, unsigned lo= ng *max_pfn_p) } device_tree =3D new_device_tree; *max_pfn_p =3D to_phys(new_device_tree) >> PAGE_SHIFT; + + balloon_set_nr_pages(*max_pfn_p, *max_pfn_p); } =20 void arch_init_demand_mapping_area(void) diff --git a/arch/x86/balloon.c b/arch/x86/balloon.c index 10b440c..fe79644 100644 --- a/arch/x86/balloon.c +++ b/arch/x86/balloon.c @@ -61,10 +61,10 @@ void arch_remap_p2m(unsigned long max_pfn) p2m_invalidate(l2_list, L2_P2M_IDX(max_pfn - 1) + 1); p2m_invalidate(l1_list, L1_P2M_IDX(max_pfn - 1) + 1); =20 - if ( p2m_pages(nr_max_pages) <=3D p2m_pages(max_pfn) ) + if ( p2m_pages(nr_max_pfn) <=3D p2m_pages(max_pfn) ) return; =20 - new_p2m =3D alloc_virt_kernel(p2m_pages(nr_max_pages)); + new_p2m =3D alloc_virt_kernel(p2m_pages(nr_max_pfn)); for ( pfn =3D 0; pfn < max_pfn; pfn +=3D P2M_ENTRIES ) { map_frame_rw(new_p2m + PAGE_SIZE * (pfn / P2M_ENTRIES), diff --git a/arch/x86/mm.c b/arch/x86/mm.c index 3bf6170..c30d8bc 100644 --- a/arch/x86/mm.c +++ b/arch/x86/mm.c @@ -72,6 +72,7 @@ void arch_mm_preinit(void *p) pt_base =3D (pgentry_t *)si->pt_base; first_free_pfn =3D PFN_UP(to_phys(pt_base)) + si->nr_pt_frames; last_free_pfn =3D si->nr_pages; + balloon_set_nr_pages(last_free_pfn, last_free_pfn); } #else #include @@ -118,6 +119,7 @@ void arch_mm_preinit(void *p) } =20 last_free_pfn =3D e820_get_maxpfn(ret); + balloon_set_nr_pages(ret, last_free_pfn); } #endif =20 diff --git a/balloon.c b/balloon.c index 5676d3b..9dc77c5 100644 --- a/balloon.c +++ b/balloon.c @@ -23,14 +23,24 @@ =20 #include #include +#include #include #include #include #include #include =20 -unsigned long nr_max_pages; -unsigned long nr_mem_pages; +unsigned long nr_max_pfn; + +static unsigned long nr_max_pages; +static unsigned long nr_mem_pfn; +static unsigned long nr_mem_pages; + +void balloon_set_nr_pages(unsigned long pages, unsigned long pfn) +{ + nr_mem_pages =3D pages; + nr_mem_pfn =3D pfn; +} =20 void get_max_pages(void) { @@ -46,16 +56,18 @@ void get_max_pages(void) =20 nr_max_pages =3D ret; printk("Maximum memory size: %ld pages\n", nr_max_pages); + + nr_max_pfn =3D e820_get_maxpfn(nr_max_pages); } =20 void mm_alloc_bitmap_remap(void) { unsigned long i, new_bitmap; =20 - if ( mm_alloc_bitmap_size >=3D ((nr_max_pages + 1) >> 3) ) + if ( mm_alloc_bitmap_size >=3D ((nr_max_pfn + 1) >> 3) ) return; =20 - new_bitmap =3D alloc_virt_kernel(PFN_UP((nr_max_pages + 1) >> 3)); + new_bitmap =3D alloc_virt_kernel(PFN_UP((nr_max_pfn + 1) >> 3)); for ( i =3D 0; i < mm_alloc_bitmap_size; i +=3D PAGE_SIZE ) { map_frame_rw(new_bitmap + i, @@ -70,7 +82,7 @@ static unsigned long balloon_frames[N_BALLOON_FRAMES]; =20 int balloon_up(unsigned long n_pages) { - unsigned long page, pfn; + unsigned long page, pfn, start_pfn; int rc; struct xen_memory_reservation reservation =3D { .domid =3D DOMID_SELF @@ -81,8 +93,11 @@ int balloon_up(unsigned long n_pages) if ( n_pages > N_BALLOON_FRAMES ) n_pages =3D N_BALLOON_FRAMES; =20 + start_pfn =3D e820_get_maxpfn(nr_mem_pages + 1) - 1; + n_pages =3D e820_get_max_contig_pages(start_pfn, n_pages); + /* Resize alloc_bitmap if necessary. */ - while ( mm_alloc_bitmap_size * 8 < nr_mem_pages + n_pages ) + while ( mm_alloc_bitmap_size * 8 < start_pfn + n_pages ) { page =3D alloc_page(); if ( !page ) @@ -99,14 +114,14 @@ int balloon_up(unsigned long n_pages) mm_alloc_bitmap_size +=3D PAGE_SIZE; } =20 - rc =3D arch_expand_p2m(nr_mem_pages + n_pages); + rc =3D arch_expand_p2m(start_pfn + n_pages); if ( rc ) return rc; =20 /* Get new memory from hypervisor. */ for ( pfn =3D 0; pfn < n_pages; pfn++ ) { - balloon_frames[pfn] =3D nr_mem_pages + pfn; + balloon_frames[pfn] =3D start_pfn + pfn; } set_xen_guest_handle(reservation.extent_start, balloon_frames); reservation.nr_extents =3D n_pages; @@ -116,7 +131,7 @@ int balloon_up(unsigned long n_pages) =20 for ( pfn =3D 0; pfn < rc; pfn++ ) { - arch_pfn_add(nr_mem_pages + pfn, balloon_frames[pfn]); + arch_pfn_add(start_pfn + pfn, balloon_frames[pfn]); free_page(pfn_to_virt(nr_mem_pages + pfn)); } =20 diff --git a/e820.c b/e820.c index 8030f43..2a371c7 100644 --- a/e820.c +++ b/e820.c @@ -290,7 +290,8 @@ unsigned long e820_get_maxpfn(unsigned long pages) int i; unsigned long pfns, start =3D 0; =20 - e820_get_memmap(); + if ( !e820_entries ) + e820_get_memmap(); =20 for ( i =3D 0; i < e820_entries; i++ ) { @@ -305,3 +306,21 @@ unsigned long e820_get_maxpfn(unsigned long pages) =20 return start + pfns; } + +unsigned long e820_get_max_contig_pages(unsigned long pfn, unsigned long p= ages) +{ + int i; + unsigned long end; + + for ( i =3D 0; i < e820_entries && e820_map[i].addr <=3D (pfn << PAGE_= SHIFT); + i++ ) + { + end =3D (e820_map[i].addr + e820_map[i].size) >> PAGE_SHIFT; + if ( e820_map[i].type !=3D E820_RAM || end <=3D pfn ) + continue; + + return ((end - pfn) > pages) ? pages : end - pfn; + } + + return 0; +} diff --git a/include/balloon.h b/include/balloon.h index 6cfec4f..8f7c8bd 100644 --- a/include/balloon.h +++ b/include/balloon.h @@ -32,11 +32,11 @@ */ #define BALLOON_EMERGENCY_PAGES 64 =20 -extern unsigned long nr_max_pages; -extern unsigned long nr_mem_pages; +extern unsigned long nr_max_pfn; =20 void get_max_pages(void); int balloon_up(unsigned long n_pages); +void balloon_set_nr_pages(unsigned long pages, unsigned long pfn); =20 void mm_alloc_bitmap_remap(void); void arch_pfn_add(unsigned long pfn, unsigned long mfn); @@ -50,6 +50,7 @@ static inline int chk_free_pages(unsigned long needed) { return needed <=3D nr_free_pages; } +static inline balloon_set_nr_pages(unsigned long pages, unsigned long pfn)= { } =20 #endif /* CONFIG_BALLOON */ #endif /* _BALLOON_H_ */ diff --git a/include/e820.h b/include/e820.h index 6a57f05..8d4d371 100644 --- a/include/e820.h +++ b/include/e820.h @@ -50,5 +50,6 @@ extern struct e820entry e820_map[]; extern unsigned e820_entries; =20 unsigned long e820_get_maxpfn(unsigned long pages); +unsigned long e820_get_max_contig_pages(unsigned long pfn, unsigned long p= ages); =20 #endif /*__E820_HEADER*/ diff --git a/mm.c b/mm.c index 932ceeb..6493bdd 100644 --- a/mm.c +++ b/mm.c @@ -396,8 +396,9 @@ void init_mm(void) =20 printk("MM: Init\n"); =20 - get_max_pages(); arch_init_mm(&start_pfn, &max_pfn); + get_max_pages(); + /* * now we can initialise the page allocator */ @@ -407,10 +408,6 @@ void init_mm(void) arch_init_p2m(max_pfn); =20 arch_init_demand_mapping_area(); - -#ifdef CONFIG_BALLOON - nr_mem_pages =3D max_pfn; -#endif } =20 void fini_mm(void) --=20 2.26.2 From nobody Mon May 6 01:46:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1640076444; cv=none; d=zohomail.com; s=zohoarc; b=jBC8AipzKPsw+fmUIEvwI1ug4ovhzZymsKgWOVA2FYtRJPFXMo9UbLQOIQWJwjOc9AZVQzXJgYXLxuqlnpwV/AUjaTQmdSXdu7C03XXyV+/T/OUZMNO4prUqdMYCHDzkRnZkJACB2x5NvGraSy1BuWsX7iuvkRc/CI8XKPOUN28= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1640076444; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=VPgUZQEXWMjuiDqJWRTGWtw72dHgK1/ZM2te4tasytk=; b=FcTscN+ZWC0mnuIrQkWfCEWqkoovtBg30K91Mf0xo2WjFowFDe+yWIGYbzwY5cjKEfBgdByiKgrKb/Ku2SAdOxz8f0UIze2BiGBFkTMBA6qE3BYLcJEmH8Ele5p48nL2CrnhrQnWHcAi3NpVhpABc6fBAAaeG5Eb5RX6X+op5cw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1640076444848161.78508587526733; Tue, 21 Dec 2021 00:47:24 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.250191.430928 (Exim 4.92) (envelope-from ) id 1mzanX-0004Y4-34; Tue, 21 Dec 2021 08:47:03 +0000 Received: by outflank-mailman (output) from mailman id 250191.430928; Tue, 21 Dec 2021 08:47:02 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mzanW-0004VJ-CR; Tue, 21 Dec 2021 08:47:02 +0000 Received: by outflank-mailman (input) for mailman id 250191; Tue, 21 Dec 2021 08:47:00 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mzanU-0002yE-9F for xen-devel@lists.xenproject.org; Tue, 21 Dec 2021 08:47:00 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 8b9b42a0-623a-11ec-9e60-abaf8a552007; Tue, 21 Dec 2021 09:46:53 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 0D6AD1F3B8; Tue, 21 Dec 2021 08:46:53 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id D923913E02; Tue, 21 Dec 2021 08:46:52 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id cDrRM3yUwWFHMAAAMHmgww (envelope-from ); Tue, 21 Dec 2021 08:46:52 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 8b9b42a0-623a-11ec-9e60-abaf8a552007 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1640076413; h=from:from:reply-to: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=VPgUZQEXWMjuiDqJWRTGWtw72dHgK1/ZM2te4tasytk=; b=aSoZNdrwNngkftb9vRyT0Tgl6iYG9pMY7oN8BFJ/KQJicMhyy+wxXQePW1Ttf30oHdA1fR s1QDTXkGOVmk4FqGz/qMr1yU3LO3deBY2VRHKCLGhYE329bKD/TPFzOYDTOsom1gN9SQGK loar0Q4wvHrEuTPnbZk0gIvhBIAoNZA= From: Juergen Gross To: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org Cc: samuel.thibault@ens-lyon.org, wl@xen.org, Juergen Gross Subject: [PATCH v3 05/10] mini-os: don't repeat definition available via header file Date: Tue, 21 Dec 2021 09:46:31 +0100 Message-Id: <20211221084636.6987-6-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20211221084636.6987-1-jgross@suse.com> References: <20211221084636.6987-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1640076446444100001 Content-Type: text/plain; charset="utf-8" arch/x86/setup.c is repeating the definition of __pte() instead using the appropriate header. Fix that. Signed-off-by: Juergen Gross Reviewed-by: Samuel Thibault --- arch/x86/setup.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/arch/x86/setup.c b/arch/x86/setup.c index 1ec68d3..b27bbed 100644 --- a/arch/x86/setup.c +++ b/arch/x86/setup.c @@ -29,6 +29,7 @@ #include #include /* for printk, memcpy */ #include +#include #include #include #include @@ -61,13 +62,6 @@ char stack[2*STACK_SIZE]; =20 extern char shared_info[PAGE_SIZE]; =20 -#if defined(__x86_64__) -#define __pte(x) ((pte_t) { (x) } ) -#else -#define __pte(x) ({ unsigned long long _x =3D (x); \ - ((pte_t) {(unsigned long)(_x), (unsigned long)(_x>>32)}); }) -#endif - static inline void fpu_init(void) { asm volatile("fninit"); } --=20 2.26.2 From nobody Mon May 6 01:46:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1640076561; cv=none; d=zohomail.com; s=zohoarc; b=iBTf5vYjfhcXQtpCLom7jFvTyuuWQPncVbxG5h1RvF297l3hNirdZh4Dx+vCsMAlGX2NHrOlU+eBtoiRAxN4tAN1JpsBqqUl/jI54HRHZ24/BLicdo08+/AGZoZW6MRc+4QxYWnxc+ZpfYRu0xBV6kS9Z1Ny1UTTdIaB6vw89RI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1640076561; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=gkrJ2Rw3Dbpj849TiQ+tx0qwA3eebDMmjLB6sPY/E/c=; b=hM384pv50f+D1Y71rbaB63ZCcGV9tikLDFlk2vDSn6WO86wfgum4tg7eLZfN+WOPmmmLGutKKKj9mWvzUeZmAiSNC9qZSP2QnMYq5uDG7zGbuWWkp6GOtHRkurRfHtJFiUzEqPrlcw+cDtIrOKdcWW8kFySePu2e/Aus5fhK3Ao= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1640076561502129.09438218414982; Tue, 21 Dec 2021 00:49:21 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.250210.430976 (Exim 4.92) (envelope-from ) id 1mzapY-0000a0-Sf; Tue, 21 Dec 2021 08:49:08 +0000 Received: by outflank-mailman (output) from mailman id 250210.430976; Tue, 21 Dec 2021 08:49:08 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mzapY-0000Zt-PU; Tue, 21 Dec 2021 08:49:08 +0000 Received: by outflank-mailman (input) for mailman id 250210; Tue, 21 Dec 2021 08:49:07 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mzanY-0002yE-9m for xen-devel@lists.xenproject.org; Tue, 21 Dec 2021 08:47:04 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 8bb37657-623a-11ec-9e60-abaf8a552007; Tue, 21 Dec 2021 09:46:53 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 3E1612112A; Tue, 21 Dec 2021 08:46:53 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 131F013BEC; Tue, 21 Dec 2021 08:46:53 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id +IiFA32UwWFHMAAAMHmgww (envelope-from ); Tue, 21 Dec 2021 08:46:53 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 8bb37657-623a-11ec-9e60-abaf8a552007 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1640076413; h=from:from:reply-to: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=gkrJ2Rw3Dbpj849TiQ+tx0qwA3eebDMmjLB6sPY/E/c=; b=JtzdSdItfXsN2W9sNhfn78CilA/vDshhfL6A7w5J/GMrEmXsafdjaf32zzblrYqBd28cQR gD4N1ykB7jzpvw3lkVevqfNkhWTxWO95SEdJZWWv/numj2RrD4ZbOYzVEl3hRAlh9uYZEe LcKfXWk/STHgeAYpXdwJ9w6eYhhsHPI= From: Juergen Gross To: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org Cc: samuel.thibault@ens-lyon.org, wl@xen.org, Juergen Gross Subject: [PATCH v3 06/10] mini-os: add memory map service functions Date: Tue, 21 Dec 2021 09:46:32 +0100 Message-Id: <20211221084636.6987-7-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20211221084636.6987-1-jgross@suse.com> References: <20211221084636.6987-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1640076561878100001 Content-Type: text/plain; charset="utf-8" Add two functions for adding reserved areas to the memory map and for removing them again. Those will be needed for proper grant table/mapping support in PVH mode. Signed-off-by: Juergen Gross Reviewed-by: Samuel Thibault --- V2: - fix e820_put_reserved_pfns() (Samuel Thibault) --- e820.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/e820.h | 4 ++++ 2 files changed, 54 insertions(+) diff --git a/e820.c b/e820.c index 2a371c7..df29097 100644 --- a/e820.c +++ b/e820.c @@ -283,6 +283,56 @@ void arch_print_memmap(void) printk("%012lx-%012lx: %s\n", from, to, type); } } + +unsigned long e820_get_reserved_pfns(int pages) +{ + int i; + unsigned long last =3D 0, needed =3D (long)pages << PAGE_SHIFT; + + for ( i =3D 0; i < e820_entries && e820_map[i].addr < last + needed; i= ++ ) + last =3D e820_map[i].addr + e820_map[i].size; + + if ( i =3D=3D 0 || e820_map[i - 1].type !=3D E820_RESERVED ) + e820_insert_entry_at(i, last, needed, E820_RESERVED); + else + e820_map[i - 1].size +=3D needed; + + return last >> PAGE_SHIFT; +} + +void e820_put_reserved_pfns(unsigned long start_pfn, int pages) +{ + int i; + unsigned long addr =3D start_pfn << PAGE_SHIFT; + unsigned long size =3D (long)pages << PAGE_SHIFT; + + for ( i =3D 0; + i < e820_entries && addr >=3D e820_map[i].addr + e820_map[i].siz= e; + i++ ); + + BUG_ON(i =3D=3D e820_entries || e820_map[i].type !=3D E820_RESERVED || + addr + size > e820_map[i].addr + e820_map[i].size); + + if ( addr =3D=3D e820_map[i].addr ) + { + e820_map[i].addr +=3D size; + e820_map[i].size -=3D size; + if ( e820_map[i].size =3D=3D 0 ) + e820_remove_entry(i); + return; + } + + if ( addr + size =3D=3D e820_map[i].addr + e820_map[i].size ) + { + e820_map[i].size -=3D size; + return; + } + + e820_insert_entry_at(i + 1, addr + size, + e820_map[i].addr + e820_map[i].size - addr - size, + E820_RESERVED); + e820_map[i].size =3D addr - e820_map[i].addr; +} #endif =20 unsigned long e820_get_maxpfn(unsigned long pages) diff --git a/include/e820.h b/include/e820.h index 8d4d371..aaf2f2c 100644 --- a/include/e820.h +++ b/include/e820.h @@ -51,5 +51,9 @@ extern unsigned e820_entries; =20 unsigned long e820_get_maxpfn(unsigned long pages); unsigned long e820_get_max_contig_pages(unsigned long pfn, unsigned long p= ages); +#ifndef CONFIG_E820_TRIVIAL +unsigned long e820_get_reserved_pfns(int pages); +void e820_put_reserved_pfns(unsigned long start_pfn, int pages); +#endif =20 #endif /*__E820_HEADER*/ --=20 2.26.2 From nobody Mon May 6 01:46:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1640076573; cv=none; d=zohomail.com; s=zohoarc; b=W7FvUMqAf3RoYdDh3Y5Bvl69D8h6JsQt/puPs4qEDHEpD/XK0BOobQikDB55nVx10q8xjYIIN3xlBuZsq9dQ+y1qctxF47KcbjiiQZwFR/5crfcqHK+mYrOdxz/egrJC/C9CaAympKI1gHFQ3HhHBfZETw0/ro8J+Reml+msz8c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1640076573; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Ce+N1zGKQYy8hCldpOth9Bm5wXCCEJvD9D9LhUj9MqQ=; b=IzDfgb1mlC7QCLwr+Uwks7fkbpDRnlTk0das/NzOTQjSgMb/wcVrXzEbIQ2ghmUfKQZt5WxC18EJBEPdpavjfIeZNipVkkvyLOaKtbHKwAYeWWBd3sHe7h3JYcsaxdI7Yr3ebwj0ymDrMbaQZMC6L6aEH/iKZkKP+bWWx/FFg9M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1640076573355951.3417817827254; Tue, 21 Dec 2021 00:49:33 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.250212.430987 (Exim 4.92) (envelope-from ) id 1mzapk-0000wi-4h; Tue, 21 Dec 2021 08:49:20 +0000 Received: by outflank-mailman (output) from mailman id 250212.430987; Tue, 21 Dec 2021 08:49:20 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mzapk-0000wZ-1A; Tue, 21 Dec 2021 08:49:20 +0000 Received: by outflank-mailman (input) for mailman id 250212; Tue, 21 Dec 2021 08:49:18 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mzana-0002yE-A1 for xen-devel@lists.xenproject.org; Tue, 21 Dec 2021 08:47:06 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 8bd0e23b-623a-11ec-9e60-abaf8a552007; Tue, 21 Dec 2021 09:46:53 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 6CF1B1F388; Tue, 21 Dec 2021 08:46:53 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 445B213BEC; Tue, 21 Dec 2021 08:46:53 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id gNqGD32UwWFHMAAAMHmgww (envelope-from ); Tue, 21 Dec 2021 08:46:53 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 8bd0e23b-623a-11ec-9e60-abaf8a552007 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1640076413; h=from:from:reply-to: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=Ce+N1zGKQYy8hCldpOth9Bm5wXCCEJvD9D9LhUj9MqQ=; b=C+NEGzRxpqZaAzIh3PRUMHaMYnMxQpFq5PgkbgGz1JstYjKyZrQj4ErAFXufxUew0l2fdm ItAws4Rg/eKrhfVHyZXx82dOQmMMNiHGXTaF+/8MPYDcegUwKFioeYBGADKQQ+CuwcwAdW IJ3q93eJKQVd0BcZ1nNdG1HQFJVUvFE= From: Juergen Gross To: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org Cc: samuel.thibault@ens-lyon.org, wl@xen.org, Juergen Gross Subject: [PATCH v3 07/10] mini-os: move x86 specific gnttab coding into arch/x86/gnttab.c Date: Tue, 21 Dec 2021 09:46:33 +0100 Message-Id: <20211221084636.6987-8-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20211221084636.6987-1-jgross@suse.com> References: <20211221084636.6987-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1640076575205100001 Content-Type: text/plain; charset="utf-8" Having grant table code in arch/x86/mm.c seems wrong. Move it to the new file arch/x86/gnttab.c, especially as the amount of code is expected to grow further. While doing that replace type casts to pte_t with the more appropriate __pte() macro. No functional change. Signed-off-by: Juergen Gross Reviewed-by: Samuel Thibault --- arch/x86/gnttab.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++ arch/x86/mm.c | 47 ---------------------------- 2 files changed, 78 insertions(+), 47 deletions(-) create mode 100644 arch/x86/gnttab.c diff --git a/arch/x86/gnttab.c b/arch/x86/gnttab.c new file mode 100644 index 0000000..56e59d7 --- /dev/null +++ b/arch/x86/gnttab.c @@ -0,0 +1,78 @@ +/* -*- 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, an= d/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 + +grant_entry_v1_t *arch_init_gnttab(int nr_grant_frames) +{ + struct gnttab_setup_table setup; + unsigned long frames[nr_grant_frames]; + + setup.dom =3D DOMID_SELF; + setup.nr_frames =3D nr_grant_frames; + set_xen_guest_handle(setup.frame_list, frames); + + HYPERVISOR_grant_table_op(GNTTABOP_setup_table, &setup, 1); + return map_frames(frames, nr_grant_frames); +} + +void arch_suspend_gnttab(grant_entry_v1_t *gnttab_table, int nr_grant_fram= es) +{ +#ifdef CONFIG_PARAVIRT + int i; + + for ( i =3D 0; i < nr_grant_frames; i++ ) + { + HYPERVISOR_update_va_mapping((unsigned long)gnttab_table + PAGE_SI= ZE * i, + __pte(0x0 << PAGE_SHIFT), UVMF_INVLPG); + } +#endif + return; +} + +void arch_resume_gnttab(grant_entry_v1_t *gnttab_table, int nr_grant_frame= s) +{ + struct gnttab_setup_table setup; + unsigned long frames[nr_grant_frames]; +#ifdef CONFIG_PARAVIRT + int i; +#endif + + setup.dom =3D DOMID_SELF; + setup.nr_frames =3D nr_grant_frames; + set_xen_guest_handle(setup.frame_list, frames); + + HYPERVISOR_grant_table_op(GNTTABOP_setup_table, &setup, 1); + +#ifdef CONFIG_PARAVIRT + for ( i =3D 0; i < nr_grant_frames; i++ ) + { + HYPERVISOR_update_va_mapping((unsigned long)gnttab_table + PAGE_SI= ZE * i, + __pte((frames[i] << PAGE_SHIFT) | L1_PROT), UVMF_INVLPG); + } +#endif +} diff --git a/arch/x86/mm.c b/arch/x86/mm.c index c30d8bc..220c0b4 100644 --- a/arch/x86/mm.c +++ b/arch/x86/mm.c @@ -837,53 +837,6 @@ void arch_init_mm(unsigned long* start_pfn_p, unsigned= long* max_pfn_p) #endif } =20 -grant_entry_v1_t *arch_init_gnttab(int nr_grant_frames) -{ - struct gnttab_setup_table setup; - unsigned long frames[nr_grant_frames]; - - setup.dom =3D DOMID_SELF; - setup.nr_frames =3D nr_grant_frames; - set_xen_guest_handle(setup.frame_list, frames); - - HYPERVISOR_grant_table_op(GNTTABOP_setup_table, &setup, 1); - return map_frames(frames, nr_grant_frames); -} - -void arch_suspend_gnttab(grant_entry_v1_t *gnttab_table, int nr_grant_fram= es) -{ -#ifdef CONFIG_PARAVIRT - int i; - - for (i =3D 0; i < nr_grant_frames; i++) { - HYPERVISOR_update_va_mapping((unsigned long)(((char *)gnttab_table= ) + PAGE_SIZE * i), - (pte_t){0x0< (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1640076444887332.3193260632694; Tue, 21 Dec 2021 00:47:24 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.250184.430883 (Exim 4.92) (envelope-from ) id 1mzanS-0003gV-OH; Tue, 21 Dec 2021 08:46:58 +0000 Received: by outflank-mailman (output) from mailman id 250184.430883; Tue, 21 Dec 2021 08:46:58 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mzanS-0003fM-Dj; Tue, 21 Dec 2021 08:46:58 +0000 Received: by outflank-mailman (input) for mailman id 250184; Tue, 21 Dec 2021 08:46:57 +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 1mzanR-0002z5-5G for xen-devel@lists.xenproject.org; Tue, 21 Dec 2021 08:46:57 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 8be91413-623a-11ec-8d39-b1a4ed000e3e; Tue, 21 Dec 2021 09:46:53 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 9AABA210FE; Tue, 21 Dec 2021 08:46:53 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 727C513BEC; Tue, 21 Dec 2021 08:46:53 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id mCPKGn2UwWFHMAAAMHmgww (envelope-from ); Tue, 21 Dec 2021 08:46:53 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 8be91413-623a-11ec-8d39-b1a4ed000e3e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1640076413; h=from:from:reply-to: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=NwQ4mRiosEanvExB6LuAnyU1/Dqqja/tWJzhJY5Y3Ms=; b=toWR3hQZog096RnIYPQ1YgpGL+3XJJxAKXFR7/u0lBiMX8IQz65YmqikDO2VThhMo2Tr3m QGM+C2XHhFTEbmPyMPCNWoSGauQPn5SGNIQF/NQb6AZvt55hcNQR2AXv5iD2Q63LhjqSzl Ssb+a4Zou4T5AnVmYfO6lj2lQbaarsg= From: Juergen Gross To: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org Cc: samuel.thibault@ens-lyon.org, wl@xen.org, Juergen Gross Subject: [PATCH v3 08/10] mini-os: add proper pvh grant table handling Date: Tue, 21 Dec 2021 09:46:34 +0100 Message-Id: <20211221084636.6987-9-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20211221084636.6987-1-jgross@suse.com> References: <20211221084636.6987-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1640076446538100005 Content-Type: text/plain; charset="utf-8" Grant table initialization for PVH requires some additional actions compared to PV mode. Add those. Signed-off-by: Juergen Gross Reviewed-by: Samuel Thibault --- arch/x86/gnttab.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/arch/x86/gnttab.c b/arch/x86/gnttab.c index 56e59d7..281c207 100644 --- a/arch/x86/gnttab.c +++ b/arch/x86/gnttab.c @@ -22,11 +22,15 @@ */ =20 #include +#include +#include #include #include #include #include +#include =20 +#ifdef CONFIG_PARAVIRT grant_entry_v1_t *arch_init_gnttab(int nr_grant_frames) { struct gnttab_setup_table setup; @@ -39,6 +43,33 @@ grant_entry_v1_t *arch_init_gnttab(int nr_grant_frames) HYPERVISOR_grant_table_op(GNTTABOP_setup_table, &setup, 1); return map_frames(frames, nr_grant_frames); } +#else +grant_entry_v1_t *arch_init_gnttab(int nr_grant_frames) +{ + int i, rc; + struct xen_add_to_physmap xatp; + unsigned long pfn; + unsigned long frames[nr_grant_frames]; + + pfn =3D e820_get_reserved_pfns(nr_grant_frames); + for ( i =3D 0; i < nr_grant_frames; i++ ) + { + xatp.domid =3D DOMID_SELF; + xatp.idx =3D i; + xatp.space =3D XENMAPSPACE_grant_table; + xatp.gpfn =3D pfn + i; + rc =3D HYPERVISOR_memory_op(XENMEM_add_to_physmap, &xatp); + if ( rc ) + { + xprintk("could not init grant table\n"); + do_exit(); + } + frames[i] =3D pfn + i; + } + + return map_frames(frames, nr_grant_frames); +} +#endif =20 void arch_suspend_gnttab(grant_entry_v1_t *gnttab_table, int nr_grant_fram= es) { --=20 2.26.2 From nobody Mon May 6 01:46:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1640076446; cv=none; d=zohomail.com; s=zohoarc; b=jIjYKcHhcjzA1vOeoq9NATKFLYX7PdOlBTFwWFTlts6lgcY75tVXP3RdQFSsieA4Y5ToG5ZyCQxJQBykw++Q9RPnl2Ul8hGGxTNOZQ45hmDUUEjxRrGlDuYwkQaJUImHRkeIyjjoSyF6/A7tlJeGolTFUuH3Ux4U4ebZOwWxEk0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1640076446; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=VFqq/QNK2D+xIQFRd42TWwa5OQ2iSim/015QEF+tkx0=; b=LSBCxTRwqE5fz1X3DVW+rIC9cGKAAO09/JIcpFRxU9vdmfudTtszf8L9FbaubdWzLJMHDtLw4LXRS+OY54twazwjiGHimgfyrWKobd2VMfjPxHPeNQ4t2cReqh76Gj4vYE4blySnZIS2SddymxpHy3XMV3URgcrR0TeWIJ4p8vI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1640076446127134.61761305141; Tue, 21 Dec 2021 00:47:26 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.250188.430913 (Exim 4.92) (envelope-from ) id 1mzanV-0004Kz-LW; Tue, 21 Dec 2021 08:47:01 +0000 Received: by outflank-mailman (output) from mailman id 250188.430913; Tue, 21 Dec 2021 08:47:01 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mzanV-0004Is-9U; Tue, 21 Dec 2021 08:47:01 +0000 Received: by outflank-mailman (input) for mailman id 250188; Tue, 21 Dec 2021 08:46:59 +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 1mzanT-0002z5-5U for xen-devel@lists.xenproject.org; Tue, 21 Dec 2021 08:46:59 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 8c057068-623a-11ec-8d39-b1a4ed000e3e; Tue, 21 Dec 2021 09:46:54 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id CA6711F3B6; Tue, 21 Dec 2021 08:46:53 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id A0D1B13BEC; Tue, 21 Dec 2021 08:46:53 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id yHzgJX2UwWFHMAAAMHmgww (envelope-from ); Tue, 21 Dec 2021 08:46:53 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 8c057068-623a-11ec-8d39-b1a4ed000e3e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1640076413; h=from:from:reply-to: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=VFqq/QNK2D+xIQFRd42TWwa5OQ2iSim/015QEF+tkx0=; b=py3Ua/EMWwloebQRKZoMF3+usUlu4h4yJhdL87S5KIZ9xfqVpY5OHrcvMBovHdVmZTSKZX 8FjMDQRmqcqIKHwIQBjhaR9CTHHp690IyDqjXizB/TZ2/He+pI+BviFQIGNwcomvAdztj8 H+S0Cq+6m8+7jSJK2xYFXoYjK1JXD1Y= From: Juergen Gross To: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org Cc: samuel.thibault@ens-lyon.org, wl@xen.org, Juergen Gross Subject: [PATCH v3 09/10] mini-os: prepare grantmap entry interface for use by PVH mode Date: Tue, 21 Dec 2021 09:46:35 +0100 Message-Id: <20211221084636.6987-10-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20211221084636.6987-1-jgross@suse.com> References: <20211221084636.6987-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1640076446648100009 Content-Type: text/plain; charset="utf-8" Instead of passing the pointer of a grantmap entry to the _gntmap_[un]map_grant_ref() sub-functions use the map pointer and the entry index instead. This will be needed for PVH mode usage. Signed-off-by: Juergen Gross Reviewed-by: Samuel Thibault --- gntmap.c | 48 +++++++++++++++++++++++------------------------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/gntmap.c b/gntmap.c index f6ab3ad..7ae8fe6 100644 --- a/gntmap.c +++ b/gntmap.c @@ -55,36 +55,34 @@ struct gntmap_entry { }; =20 static inline int -gntmap_entry_used(struct gntmap_entry *entry) +gntmap_entry_used(struct gntmap *map, int idx) { - return entry->host_addr !=3D 0; + return map->entries[idx].host_addr !=3D 0; } =20 -static struct gntmap_entry* -gntmap_find_free_entry(struct gntmap *map) +static int gntmap_find_free_entry(struct gntmap *map) { int i; =20 for (i =3D 0; i < map->nentries; i++) { - if (!gntmap_entry_used(&map->entries[i])) - return &map->entries[i]; + if (!gntmap_entry_used(map, i)) + return i; } =20 DEBUG("(map=3D%p): all %d entries full", map, map->nentries); - return NULL; + return -1; } =20 -static struct gntmap_entry* -gntmap_find_entry(struct gntmap *map, unsigned long addr) +static int gntmap_find_entry(struct gntmap *map, unsigned long addr) { int i; =20 for (i =3D 0; i < map->nentries; i++) { if (map->entries[i].host_addr =3D=3D addr) - return &map->entries[i]; + return i; } - return NULL; + return -1; } =20 int @@ -105,12 +103,13 @@ gntmap_set_max_grants(struct gntmap *map, int count) } =20 static int -_gntmap_map_grant_ref(struct gntmap_entry *entry,=20 +_gntmap_map_grant_ref(struct gntmap *map, int idx, unsigned long host_addr, uint32_t domid, uint32_t ref, int writable) { + struct gntmap_entry *entry =3D map->entries + idx; struct gnttab_map_grant_ref op; int rc; =20 @@ -135,8 +134,9 @@ _gntmap_map_grant_ref(struct gntmap_entry *entry, } =20 static int -_gntmap_unmap_grant_ref(struct gntmap_entry *entry) +_gntmap_unmap_grant_ref(struct gntmap *map, int idx) { + struct gntmap_entry *entry =3D map->entries + idx; struct gnttab_unmap_grant_ref op; int rc; =20 @@ -160,19 +160,19 @@ int gntmap_munmap(struct gntmap *map, unsigned long start_address, int count) { int i, rc; - struct gntmap_entry *ent; + int idx; =20 DEBUG("(map=3D%p, start_address=3D%lx, count=3D%d)", map, start_address, count); =20 for (i =3D 0; i < count; i++) { - ent =3D gntmap_find_entry(map, start_address + PAGE_SIZE * i); - if (ent =3D=3D NULL) { + idx =3D gntmap_find_entry(map, start_address + PAGE_SIZE * i); + if (idx < 0) { printk("gntmap: tried to munmap unknown page\n"); return -EINVAL; } =20 - rc =3D _gntmap_unmap_grant_ref(ent); + rc =3D _gntmap_unmap_grant_ref(map, idx); if (rc !=3D 0) return rc; } @@ -189,7 +189,7 @@ gntmap_map_grant_refs(struct gntmap *map, int writable) { unsigned long addr; - struct gntmap_entry *ent; + int idx; int i; =20 DEBUG("(map=3D%p, count=3D%" PRIu32 ", " @@ -206,9 +206,9 @@ gntmap_map_grant_refs(struct gntmap *map, return NULL; =20 for (i =3D 0; i < count; i++) { - ent =3D gntmap_find_free_entry(map); - if (ent =3D=3D NULL || - _gntmap_map_grant_ref(ent, + idx =3D gntmap_find_free_entry(map); + if (idx < 0 || + _gntmap_map_grant_ref(map, idx, addr + PAGE_SIZE * i, domids[i * domids_stride], refs[i], @@ -233,15 +233,13 @@ gntmap_init(struct gntmap *map) void gntmap_fini(struct gntmap *map) { - struct gntmap_entry *ent; int i; =20 DEBUG("(map=3D%p)", map); =20 for (i =3D 0; i < map->nentries; i++) { - ent =3D &map->entries[i]; - if (gntmap_entry_used(ent)) - (void) _gntmap_unmap_grant_ref(ent); + if (gntmap_entry_used(map, i)) + (void) _gntmap_unmap_grant_ref(map, i); } =20 xfree(map->entries); --=20 2.26.2 From nobody Mon May 6 01:46:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1640076447; cv=none; d=zohomail.com; s=zohoarc; b=N1Do7+oaV6dnWOAz0CQaUMFi2sIsGBmjM2RK8xKl/JAcApzuVGe4yQIShwtbMHh6c0UFycir9fRf1VBkg+21rDm4TTJnb//Y3yEV153z/ypVqJieaKH8VwWMwyndY0UTvmdbudDyr0xbA7/TM9bQAgg+YyyB0+f9j/fI4mD/r2E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1640076447; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=2zdQgzlV0Lz7UQXRFdnEwu37UxJwIePFbmpJgrcmrrs=; b=ZgTrhk/e+7RrWDP/tFNek7lxJea43dJZ+9aFwN3hyePy12XVnvWRHqwfilzxnerunvC+FS+GciaUaJ5Rk7+N/qih7S9FkPnWItGNrMBs1TCFcLPeQBPueNpB6Z3jxvhOBfxsJxE49+eNaxAz1Qwgp+8iQSI5HSb5NXMBYPhsGFY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1640076447846866.1133886941608; Tue, 21 Dec 2021 00:47:27 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.250192.430933 (Exim 4.92) (envelope-from ) id 1mzanX-0004mw-Pr; Tue, 21 Dec 2021 08:47:03 +0000 Received: by outflank-mailman (output) from mailman id 250192.430933; Tue, 21 Dec 2021 08:47:03 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mzanX-0004id-Ak; Tue, 21 Dec 2021 08:47:03 +0000 Received: by outflank-mailman (input) for mailman id 250192; Tue, 21 Dec 2021 08:47:01 +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 1mzanV-0002z5-5i for xen-devel@lists.xenproject.org; Tue, 21 Dec 2021 08:47:01 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 8c2aae34-623a-11ec-8d39-b1a4ed000e3e; Tue, 21 Dec 2021 09:46:54 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 1143521106; Tue, 21 Dec 2021 08:46:54 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id CFBDF13BEC; Tue, 21 Dec 2021 08:46:53 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id wAh0MX2UwWFHMAAAMHmgww (envelope-from ); Tue, 21 Dec 2021 08:46:53 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 8c2aae34-623a-11ec-8d39-b1a4ed000e3e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1640076414; h=from:from:reply-to: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=2zdQgzlV0Lz7UQXRFdnEwu37UxJwIePFbmpJgrcmrrs=; b=km1hd/hcAwn5S/3yJHlr/WcnHQ4YQD+O7shAA5ihsxw4YOGkaPUqTnFZ+crwtIwm/pa0a+ wZwgjA2zKOf8MpBk9VB+H26114WblOoZrvPI2Bo7fc5+B0xU5hQHNpjYxzeSXnBlMqMlAh PVCkjUpQN5ip2Bc6vGMUabWVz7ESYXk= From: Juergen Gross To: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org Cc: samuel.thibault@ens-lyon.org, wl@xen.org, Juergen Gross Subject: [PATCH v3 10/10] mini-os: modify grant mappings to work in PVH mode Date: Tue, 21 Dec 2021 09:46:36 +0100 Message-Id: <20211221084636.6987-11-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20211221084636.6987-1-jgross@suse.com> References: <20211221084636.6987-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1640076449059100001 Content-Type: text/plain; charset="utf-8" For being able to use the grant mapping interface in PVH mode some changes are required, as the guest needs to specify a physical address in the hypercall interface. Signed-off-by: Juergen Gross Reviewed-by: Samuel Thibault --- gntmap.c | 81 ++++++++++++++++++++++++++++++++++-------------- include/gntmap.h | 1 + 2 files changed, 59 insertions(+), 23 deletions(-) diff --git a/gntmap.c b/gntmap.c index 7ae8fe6..126b04f 100644 --- a/gntmap.c +++ b/gntmap.c @@ -32,6 +32,7 @@ =20 #include #include +#include #include #include #include @@ -97,11 +98,42 @@ gntmap_set_max_grants(struct gntmap *map, int count) if (map->entries =3D=3D NULL) return -ENOMEM; =20 +#ifndef CONFIG_PARAVIRT + map->start_pfn =3D e820_get_reserved_pfns(count); +#endif + memset(map->entries, 0, sizeof(struct gntmap_entry) * count); map->nentries =3D count; return 0; } =20 +static int +_gntmap_unmap_grant_ref(struct gntmap *map, int idx) +{ + struct gntmap_entry *entry =3D map->entries + idx; + struct gnttab_unmap_grant_ref op; + int rc; + +#ifdef CONFIG_PARAVIRT + op.host_addr =3D (uint64_t) entry->host_addr; +#else + op.host_addr =3D (uint64_t)(map->start_pfn + idx) << PAGE_SHIFT; +#endif + op.dev_bus_addr =3D 0; + op.handle =3D entry->handle; + + rc =3D HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1); + if (rc !=3D 0 || op.status !=3D GNTST_okay) { + printk("GNTTABOP_unmap_grant_ref failed: " + "returned %d, status %" PRId16 "\n", + rc, op.status); + return rc !=3D 0 ? rc : op.status; + } + + entry->host_addr =3D 0; + return 0; +} + static int _gntmap_map_grant_ref(struct gntmap *map, int idx, unsigned long host_addr, @@ -112,10 +144,17 @@ _gntmap_map_grant_ref(struct gntmap *map, int idx, struct gntmap_entry *entry =3D map->entries + idx; struct gnttab_map_grant_ref op; int rc; +#ifndef CONFIG_PARAVIRT + unsigned long pfn =3D map->start_pfn + idx; +#endif =20 op.ref =3D (grant_ref_t) ref; op.dom =3D (domid_t) domid; +#ifdef CONFIG_PARAVIRT op.host_addr =3D (uint64_t) host_addr; +#else + op.host_addr =3D (uint64_t)pfn << PAGE_SHIFT;=20 +#endif op.flags =3D GNTMAP_host_map; if (!writable) op.flags |=3D GNTMAP_readonly; @@ -128,31 +167,18 @@ _gntmap_map_grant_ref(struct gntmap *map, int idx, return rc !=3D 0 ? rc : op.status; } =20 - entry->host_addr =3D host_addr; - entry->handle =3D op.handle; - return 0; -} - -static int -_gntmap_unmap_grant_ref(struct gntmap *map, int idx) -{ - struct gntmap_entry *entry =3D map->entries + idx; - struct gnttab_unmap_grant_ref op; - int rc; - - op.host_addr =3D (uint64_t) entry->host_addr; - op.dev_bus_addr =3D 0; - op.handle =3D entry->handle; - - rc =3D HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1); - if (rc !=3D 0 || op.status !=3D GNTST_okay) { - printk("GNTTABOP_unmap_grant_ref failed: " - "returned %d, status %" PRId16 "\n", - rc, op.status); - return rc !=3D 0 ? rc : op.status; +#ifndef CONFIG_PARAVIRT + rc =3D do_map_frames(host_addr, &pfn, 1, 0, 0, DOMID_SELF, NULL, + writable ? L1_PROT : L1_PROT_RO); + if ( rc ) + { + _gntmap_unmap_grant_ref(map, idx); + return rc; } +#endif =20 - entry->host_addr =3D 0; + entry->host_addr =3D host_addr; + entry->handle =3D op.handle; return 0; } =20 @@ -165,6 +191,10 @@ gntmap_munmap(struct gntmap *map, unsigned long start_= address, int count) DEBUG("(map=3D%p, start_address=3D%lx, count=3D%d)", map, start_address, count); =20 +#ifndef CONFIG_PARAVIRT + unmap_frames(start_address, count); +#endif + for (i =3D 0; i < count; i++) { idx =3D gntmap_find_entry(map, start_address + PAGE_SIZE * i); if (idx < 0) { @@ -242,6 +272,11 @@ gntmap_fini(struct gntmap *map) (void) _gntmap_unmap_grant_ref(map, i); } =20 +#ifndef CONFIG_PARAVIRT + e820_put_reserved_pfns(map->start_pfn, map->nentries); + map->start_pfn =3D 0; +#endif + xfree(map->entries); map->entries =3D NULL; map->nentries =3D 0; diff --git a/include/gntmap.h b/include/gntmap.h index fde53f3..d3d7e88 100644 --- a/include/gntmap.h +++ b/include/gntmap.h @@ -10,6 +10,7 @@ struct gntmap { int nentries; struct gntmap_entry *entries; + unsigned long start_pfn; }; =20 int --=20 2.26.2