From nobody Sun May 5 06:07:21 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=1640016468; cv=none; d=zohomail.com; s=zohoarc; b=kt1U71YQO2/dBd3j0bN366BCOt08gHOLpHfQokVfBKcHqV40r+2qkhwD5KUW3ALZ0NE6nSyYBZOwEpr91Ezct2Vf5CyDT9DoEgH2bWuPqk3G8jkZ0neS9kQOQVDS9eXuRHHancJE/x84gjjKqa1996KDmnVcjbGA+K5Q2r5KcCA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1640016468; 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=mSN062dw6GT/3I8gNR4Q8RbZ9DLyd+MF5QLSF+D0H2BIhL5FW07t5V3Jy+tDh+gmpOM5DbevwHQ5S+9UjIrqktAbJPnF7T4mr60yptdnYfxqDZQ3C3V2uVDbS4RSblAFARmVeS3H8J/ZeeDdxoXSZXTHXbBhkxNX6a9vsUM5+Wo= 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 1640016468198483.5330619197323; Mon, 20 Dec 2021 08:07:48 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.249864.430333 (Exim 4.92) (envelope-from ) id 1mzLCE-0006qI-QA; Mon, 20 Dec 2021 16:07:30 +0000 Received: by outflank-mailman (output) from mailman id 249864.430333; Mon, 20 Dec 2021 16:07:30 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mzLCE-0006pF-Fd; Mon, 20 Dec 2021 16:07:30 +0000 Received: by outflank-mailman (input) for mailman id 249864; Mon, 20 Dec 2021 16:07:28 +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 1mzLCC-00055w-9i for xen-devel@lists.xenproject.org; Mon, 20 Dec 2021 16:07:28 +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 e8682008-61ae-11ec-85d3-df6b77346a89; Mon, 20 Dec 2021 17:07:20 +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 27F6D1F3A0; Mon, 20 Dec 2021 16:07:19 +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 F143313D6B; Mon, 20 Dec 2021 16:07:18 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 2BiUOTaqwGEUTAAAMHmgww (envelope-from ); Mon, 20 Dec 2021 16:07:18 +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: e8682008-61ae-11ec-85d3-df6b77346a89 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1640016439; 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=b9kSDOD54CjbEdJV0hisvDcPiih19/6ZkGnbHGHR3e43ywtVC4E7DbvckDK2pby5sfe7dg CoxJj6F1lFGjiywDODLGuE3h32KgsGtOC6OY2CQd24DyzVA4V4VYA8GXSAnQByvl7lwxEz ag3iL+3lDG3nsoXlzpQSjLuE0N0kTS0= 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 v2 01/10] mini-os: split e820 map handling into new source file Date: Mon, 20 Dec 2021 17:07:07 +0100 Message-Id: <20211220160716.4159-2-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20211220160716.4159-1-jgross@suse.com> References: <20211220160716.4159-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1640016469182100007 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 Sun May 5 06:07:21 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=1640016470; cv=none; d=zohomail.com; s=zohoarc; b=CUNPkg3ByEtqCXZQVrKSVqbgY87HnzrZA0pJIf2+whxeR+QKLGu1bn/ww5QHc1JalWvAh0PA4EAE4aePF87l/c7Tm/eAXRcuvfk+d39+mMEK6aR23QL+P06Q+D2sHklz9WeU+YeeWIkHJomqmzqCXTAdVoDftDTKOvInBhNZa4A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1640016470; 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=Cv003J0xi/p+K/xvrdTTejHNr9Au2kqIdVjkJGzcq9s=; b=S19ok6gkAsrdbec7bGEsWvhVcq7PgqTTmUswrXAFb0GdnvHJePyUuvIlOEoONBSlVu5YSJ5aFlNcPqOP/iYPQDKeSBnFy9qxU4oeK+QUu3JLY6zRqgTClscE++RUEFuGrq03fbCNLJVcDHOeE0l3RBt8iGlQsnAcgFbKy1n5Vs8= 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 1640016470522181.49672060594366; Mon, 20 Dec 2021 08:07:50 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.249861.430315 (Exim 4.92) (envelope-from ) id 1mzLCD-0006Te-0h; Mon, 20 Dec 2021 16:07:29 +0000 Received: by outflank-mailman (output) from mailman id 249861.430315; Mon, 20 Dec 2021 16:07:28 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mzLCC-0006RZ-OU; Mon, 20 Dec 2021 16:07:28 +0000 Received: by outflank-mailman (input) for mailman id 249861; Mon, 20 Dec 2021 16:07:27 +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 1mzLCA-00055x-M5 for xen-devel@lists.xenproject.org; Mon, 20 Dec 2021 16:07:26 +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 e882fae1-61ae-11ec-9e60-abaf8a552007; Mon, 20 Dec 2021 17:07:21 +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 5C6E21F3A2; Mon, 20 Dec 2021 16:07:19 +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 2EBAC13D6B; Mon, 20 Dec 2021 16:07:19 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id QLsnCjeqwGEUTAAAMHmgww (envelope-from ); Mon, 20 Dec 2021 16:07:19 +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: e882fae1-61ae-11ec-9e60-abaf8a552007 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1640016439; 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=Cv003J0xi/p+K/xvrdTTejHNr9Au2kqIdVjkJGzcq9s=; b=CKeX6VviJeP816wpS1Rj6o9fD+i+6fsB3sa7bc+GY2FusiNziIREux6JNomUDXC3LDdwcw rtyjynefgFUAj3U4HLU/bwGrgKeBEX73nlrF1maMpRt/HxfAH43Um52sEUPxPGS50LoD/Z 1crt9EVyXV1jnYG4mpdS7w9naF85M+E= 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 v2 02/10] mini-os: sort and sanitize e820 memory map Date: Mon, 20 Dec 2021 17:07:08 +0100 Message-Id: <20211220160716.4159-3-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20211220160716.4159-1-jgross@suse.com> References: <20211220160716.4159-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1640016471804100003 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) --- e820.c | 186 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 186 insertions(+) diff --git a/e820.c b/e820.c index 2165280..1770158 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, end, PAGE_SIZE, E820_TMP_RESERVED); + 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 Sun May 5 06:07:21 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=1640016468; cv=none; d=zohomail.com; s=zohoarc; b=mheyigw3isQe80SpFiNaZAVGztt1BdskgLPrboTkZu7YjiHUFvmnUmVFVFLtPj5kjTLATK8jnl7/4hqxYpy5Hfuj4h7fkWEA3kyUYTuJdrVJVS2J+kCou9OXF2waw3e3VSdZboH7FMXg1ME6KL0HLUghyUm6Txctg3SY6F01at8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1640016468; 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=POjxJaAzzZfNKLwq8GHwwKNxLxPxY05Rtom00f9HoLs=; b=klSUJsljuGM3XXEkXQGz7Qr35Zlh0hhZEn08FPaaFXt3D8F5FEzdLLcKyyVFQ1OfvpuVajWCuKNURU+1xZeZrMCrGa+VXguJBxLQJlA/TAI4ckaqy+CE3oU4PdRqqYC/KjatSSjP9nZnXMyuODu06I//tu/yKrHA1pBWQOvEKKk= 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 1640016468664714.9964661286654; Mon, 20 Dec 2021 08:07:48 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.249854.430263 (Exim 4.92) (envelope-from ) id 1mzLC8-0005Sy-MX; Mon, 20 Dec 2021 16:07:24 +0000 Received: by outflank-mailman (output) from mailman id 249854.430263; Mon, 20 Dec 2021 16:07:24 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mzLC8-0005RG-HJ; Mon, 20 Dec 2021 16:07:24 +0000 Received: by outflank-mailman (input) for mailman id 249854; Mon, 20 Dec 2021 16:07:23 +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 1mzLC7-00055w-8c for xen-devel@lists.xenproject.org; Mon, 20 Dec 2021 16:07:23 +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 e89f5515-61ae-11ec-85d3-df6b77346a89; Mon, 20 Dec 2021 17:07:20 +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 8C06B218F9; Mon, 20 Dec 2021 16:07:19 +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 60D7B13DAC; Mon, 20 Dec 2021 16:07:19 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id gIdVFjeqwGEUTAAAMHmgww (envelope-from ); Mon, 20 Dec 2021 16:07:19 +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: e89f5515-61ae-11ec-85d3-df6b77346a89 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1640016439; 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=POjxJaAzzZfNKLwq8GHwwKNxLxPxY05Rtom00f9HoLs=; b=DWDOfJA+puFbtAWZuJ7ORNsrBHHByIxVt5Ct3fW6WHOQwjgHh5Mct3pwvJBCgcxZ/gHkFe t1m8cf7IjZuS5omEBLcxBOJBVlNi3KG5Wb6mqSwxK+zr6/bD75NROoCs9H5MZ/6/X6Ehwp Z+3h7ZW693CQz7mU/TpRqUO+ViHT35c= 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 v2 03/10] mini-os: don't assume contiguous RAM when initializing in PVH mode Date: Mon, 20 Dec 2021 17:07:09 +0100 Message-Id: <20211220160716.4159-4-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20211220160716.4159-1-jgross@suse.com> References: <20211220160716.4159-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1640016469154100004 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 1770158..6d15cdf 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 Sun May 5 06:07:21 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=1640016468; cv=none; d=zohomail.com; s=zohoarc; b=drDNrlt6Gp+VAMIDEupA4FdA4XkskyoP6NK2mZ518ZqcmGThyh86IgbNH4ArHT+cYnKVXv64TtRKaYfefoNE9Lx78XXGtssyLGL8/6WY0ep65T2WrzXrQtQBM3H5nkyidivJ5d+O9frDqnkIjaCOyBu9ydjg03eJAtMj672mE0s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1640016468; 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=ZJxJEFiHs3uH1jT5/e24KC56tHdpQMXoWtlkInpMjy4=; b=eh/jZYhjHPTaXkaihDVs740rugG75P/xk9maCatM8waXK8RfjkhGv6jW8JiPGbIdVryd4E8AnWFM0BcMGMlTzV4GTbCRj8pT3xJnnz78ObX9nWUJx95bng3lAAif2tn54EC7SsE6r/GFz7VTE5wdkO+v5qcGhOAQDExcVYy3ln8= 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 164001646854759.06465940176497; Mon, 20 Dec 2021 08:07:48 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.249860.430308 (Exim 4.92) (envelope-from ) id 1mzLCC-0006N1-9V; Mon, 20 Dec 2021 16:07:28 +0000 Received: by outflank-mailman (output) from mailman id 249860.430308; Mon, 20 Dec 2021 16:07:28 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mzLCC-0006Mm-4j; Mon, 20 Dec 2021 16:07:28 +0000 Received: by outflank-mailman (input) for mailman id 249860; Mon, 20 Dec 2021 16:07:26 +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 1mzLCA-00055w-9I for xen-devel@lists.xenproject.org; Mon, 20 Dec 2021 16:07:26 +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 e8c303e1-61ae-11ec-85d3-df6b77346a89; Mon, 20 Dec 2021 17:07:20 +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 BD8AE1F3A3; Mon, 20 Dec 2021 16:07:19 +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 9272213D6B; Mon, 20 Dec 2021 16:07:19 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id YJl6IjeqwGEUTAAAMHmgww (envelope-from ); Mon, 20 Dec 2021 16:07:19 +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: e8c303e1-61ae-11ec-85d3-df6b77346a89 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1640016439; 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=ZJxJEFiHs3uH1jT5/e24KC56tHdpQMXoWtlkInpMjy4=; b=Ho/HSDwECpZMfw9sIrvOOQyj1wHST8peaJ8xVzPJ2EmXuE9djCKi4FimsP/eHMj59LJqqr Lj8Pqib5o0Bm8YL+ud/YPtReFbuIcKgoaJzykS3ElqlXNTXL6ZJaw7UZmeJqR+MmwqRebN NPe4jzUxPGPluWhRinGt5oV+w8cFf2Q= 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 v2 04/10] mini-os: respect memory map when ballooning up Date: Mon, 20 Dec 2021 17:07:10 +0100 Message-Id: <20211220160716.4159-5-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20211220160716.4159-1-jgross@suse.com> References: <20211220160716.4159-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1640016469160100005 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) --- 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 6d15cdf..659f71c 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 < (pfn << PAGE_SHI= FT); + 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 Sun May 5 06:07:21 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=1640016468; cv=none; d=zohomail.com; s=zohoarc; b=gvZFVdKovPZnMyjHYqgTSehW/nUaxXrVag0l5sb5G2DIypkHuIRMsAEXIzKUPkmeXOYbwnWQo7IYeTvhSdzrI+/TGmJCMHun/Pkq7LUhHv5RoqwvMd+gJ4CnhLMg2kiNLNgBQ+vRcvJE53bmUCfgkdBDh9jeRM+dN8wjc/eOFpg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1640016468; 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=M1zb1rzZNROFrQGUulaN6Fg/6slOhVBtfCKGEG9e1NI5S3aHZ/ouG7wiyIcPZQF+1GJY9rOMwjYvSL2+ENY99lf2thE2T11li4Vf8udiozz/supKpl2/ALe9bZ7b5sz/JH7drmCnaPIvAxqvG40i1Y2+6haXKshBJ6+y6YT+8a8= 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 1640016468295215.10061117390467; Mon, 20 Dec 2021 08:07:48 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.249852.430247 (Exim 4.92) (envelope-from ) id 1mzLC7-00058f-5n; Mon, 20 Dec 2021 16:07:23 +0000 Received: by outflank-mailman (output) from mailman id 249852.430247; Mon, 20 Dec 2021 16:07:23 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mzLC7-00058Q-1Y; Mon, 20 Dec 2021 16:07:23 +0000 Received: by outflank-mailman (input) for mailman id 249852; Mon, 20 Dec 2021 16:07:22 +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 1mzLC6-00055w-8b for xen-devel@lists.xenproject.org; Mon, 20 Dec 2021 16:07:22 +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 e8dda842-61ae-11ec-85d3-df6b77346a89; Mon, 20 Dec 2021 17:07:20 +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 EE279218FC; Mon, 20 Dec 2021 16:07:19 +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 C321013D6B; Mon, 20 Dec 2021 16:07:19 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id KFlaLjeqwGEUTAAAMHmgww (envelope-from ); Mon, 20 Dec 2021 16:07:19 +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: e8dda842-61ae-11ec-85d3-df6b77346a89 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1640016439; 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=mq8DOsnesC1v2dMnluoobHNTmIK5fdEb4eiejWMKxSn3+Gfha/rG2sCSv3YuIuqxi21u7p Tk5gC55nVa8Kx+4o4rHH3dRf9EkZ3v/KmKPhNz/wPgb4HPiPCSmZOClV7oXq1S/78vuwT+ 8cxFGqBOaAsqWn97WKARaNazRkyj+eo= 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 v2 05/10] mini-os: don't repeat definition available via header file Date: Mon, 20 Dec 2021 17:07:11 +0100 Message-Id: <20211220160716.4159-6-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20211220160716.4159-1-jgross@suse.com> References: <20211220160716.4159-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1640016469148100003 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 Sun May 5 06:07:21 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=1640016468; cv=none; d=zohomail.com; s=zohoarc; b=AFILIhXGBlesLbR5U9XW9067cpXFKUD0nbI5q85ycXDq5H6+3wQKrFDtUCDCzD5g3XZYYIQZcdpzdS4VEp9Do9VK8pPmU5K8PiUwVgY4BKyRw1jtkqfJax/JCVdfkDf/geAukCU4nSwKDkNLU2AatcL5cELhUMkvqjiW2D3Ip2o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1640016468; 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=0KigAZz9hYluMyaBKPARA/gJpt6ihPK6ZX8SoZiA/8c=; b=MjrPqVbEVhsj9ZtpPCDrkriXheYPDyiISI8gRvvJX6NgIhDZ0wK+znDuPij+/NuSeswqyqK9ERQs75/W5cNA5IUeAcB1WcT1e9R7HfhnJgyB8djewgkilkN2vrnHlbW6nkRaYb4+QrNAnHrRi+MTK5cB9s129e9ivS5CZkZXMSQ= 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 1640016468225190.1737083167768; Mon, 20 Dec 2021 08:07:48 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.249855.430281 (Exim 4.92) (envelope-from ) id 1mzLCA-0005uJ-3P; Mon, 20 Dec 2021 16:07:26 +0000 Received: by outflank-mailman (output) from mailman id 249855.430281; Mon, 20 Dec 2021 16:07:26 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mzLC9-0005so-Rw; Mon, 20 Dec 2021 16:07:25 +0000 Received: by outflank-mailman (input) for mailman id 249855; Mon, 20 Dec 2021 16:07:23 +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 1mzLC7-00055x-LQ for xen-devel@lists.xenproject.org; Mon, 20 Dec 2021 16:07:23 +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 e8f9097a-61ae-11ec-9e60-abaf8a552007; Mon, 20 Dec 2021 17:07:21 +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 2F11D1F3B0; Mon, 20 Dec 2021 16:07:20 +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 026CA13D6B; Mon, 20 Dec 2021 16:07:19 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id eIh+OjeqwGEUTAAAMHmgww (envelope-from ); Mon, 20 Dec 2021 16:07:19 +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: e8f9097a-61ae-11ec-9e60-abaf8a552007 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1640016440; 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=0KigAZz9hYluMyaBKPARA/gJpt6ihPK6ZX8SoZiA/8c=; b=BGZCu+VhIL6E6RPcvOccUnBg36tJGuE8MKAUkblyrPPxIhFgMUC38Vgxam65yTOA/6etGK 1FUXdp7oY5jJHkWxYtQhUDTxHM39/P+EDR++VaRNe4xOm49JXsEe9ojD4wWqCTrJmz3XsL +rS9zMb5p5OENE6OL0+w6RPfCDe3EvY= 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 v2 06/10] mini-os: add memory map service functions Date: Mon, 20 Dec 2021 17:07:12 +0100 Message-Id: <20211220160716.4159-7-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20211220160716.4159-1-jgross@suse.com> References: <20211220160716.4159-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1640016469140100001 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 659f71c..25e2f9d 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 Sun May 5 06:07:21 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=1640016468; cv=none; d=zohomail.com; s=zohoarc; b=bsSoFcjS6n0KF1p+c73gFfuJir/0BccH01eyUzN9FxWoOGbJNFN9ONVLnfqgEqXiD5PDufWDZSLoV9qu71S7HXynUzztHugh56E1BsOW2yZXBGcJNO3rYMHyoWG/zfqsjbrpnCpsvfayfzMF86kFAjNqFAynoawAZAhvduNReRY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1640016468; 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=iO+9+OQF/U6Pn1mUHJZD53G9XIsBpnF5IlxJFpJ7tEdTnZUaehEHZBbpMLxirLS6Ts6+ke/jsEeqSsA6tGcCpABo5GgWdcYrcQmxNvtn9q4xim1XHPbkYN/InlnmQjnKpkNdMT9nNH/0en8ERuU5rtvfrTnVQ32Wn9rinGW0nqI= 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 1640016468233709.603277039415; Mon, 20 Dec 2021 08:07:48 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.249867.430351 (Exim 4.92) (envelope-from ) id 1mzLCH-0007Ed-1F; Mon, 20 Dec 2021 16:07:33 +0000 Received: by outflank-mailman (output) from mailman id 249867.430351; Mon, 20 Dec 2021 16:07:32 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mzLCG-0007AI-Au; Mon, 20 Dec 2021 16:07:32 +0000 Received: by outflank-mailman (input) for mailman id 249867; Mon, 20 Dec 2021 16:07:30 +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 1mzLCD-00055x-MC for xen-devel@lists.xenproject.org; Mon, 20 Dec 2021 16:07:29 +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 e994c24c-61ae-11ec-9e60-abaf8a552007; Mon, 20 Dec 2021 17:07:21 +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 64E341F3B1; Mon, 20 Dec 2021 16:07:20 +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 3632913D6B; Mon, 20 Dec 2021 16:07:20 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id OOncCziqwGEUTAAAMHmgww (envelope-from ); Mon, 20 Dec 2021 16:07:20 +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: e994c24c-61ae-11ec-9e60-abaf8a552007 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1640016440; 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=cWUUXYQwUV2VTvC9d9SQ9id2mBJZNdCT3LP25oCPV00TvQZE9kaOz3Azd9AskgY4CNA0Dv dQ28BZ8n0gQWEnarVEmdCAcJclsluUIV7kvfpR8bfO4/Xo2sXSbzGgYq2GLpQiTKSeqcsK bA1PDGndrRJ8nQviz8883vQuZGuk4nc= 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 v2 07/10] mini-os: move x86 specific gnttab coding into arch/x86/gnttab.c Date: Mon, 20 Dec 2021 17:07:13 +0100 Message-Id: <20211220160716.4159-8-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20211220160716.4159-1-jgross@suse.com> References: <20211220160716.4159-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1640016469181100006 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 1640016468807377.77394614927937; Mon, 20 Dec 2021 08:07:48 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.249865.430339 (Exim 4.92) (envelope-from ) id 1mzLCF-0006vX-L6; Mon, 20 Dec 2021 16:07:31 +0000 Received: by outflank-mailman (output) from mailman id 249865.430339; Mon, 20 Dec 2021 16:07:31 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mzLCF-0006tV-0Q; Mon, 20 Dec 2021 16:07:31 +0000 Received: by outflank-mailman (input) for mailman id 249865; Mon, 20 Dec 2021 16:07:28 +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 1mzLCC-00055x-M2 for xen-devel@lists.xenproject.org; Mon, 20 Dec 2021 16:07:28 +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 e994da1d-61ae-11ec-9e60-abaf8a552007; Mon, 20 Dec 2021 17:07:21 +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 964191F3B2; Mon, 20 Dec 2021 16:07:20 +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 6B20A13D6B; Mon, 20 Dec 2021 16:07:20 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id WF3cGDiqwGEUTAAAMHmgww (envelope-from ); Mon, 20 Dec 2021 16:07:20 +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: e994da1d-61ae-11ec-9e60-abaf8a552007 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1640016440; 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=fHEmzq/8xHjjE8HlcsZAhETWt6xchVyelqjXalZEawE5P2CesILBUlsexQGDAgwxM+PkCb fszdw2vuUHFFe49W4v4AsgaCYhYm6bhruP2/Iz3zsYKPY6x0XV65JzElA4X34mMFIQE5Eb WxQb8SqipT8QPtMfbAL58Zu4qkIek3w= 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 v2 08/10] mini-os: add proper pvh grant table handling Date: Mon, 20 Dec 2021 17:07:14 +0100 Message-Id: <20211220160716.4159-9-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20211220160716.4159-1-jgross@suse.com> References: <20211220160716.4159-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1640016469146100002 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 Sun May 5 06:07:21 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=1640016469; cv=none; d=zohomail.com; s=zohoarc; b=Qh4w0vipVRP+fjQrq7yY79UYKRx55lSJyJB/MGtLvsNc9UbDrhIo5Hkj9PEaxo3R3N5Uyebr7jlVyXzxnDWPiDy9kwLC2DKl/znipXDUSSwwrx857wyqRJDveFzfGdggpqwMUh9yzOmFYnwctr38dQK14vEBrNMWZIbdON5qNSQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1640016469; 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=i7rjgOckfr+WmIQwWjav/wv8VYfZP1j2K/Er3OGQLfOCpblVEgZIY9A6FUqJzRr7vdZ/wD9cxezMomYeXM28FxqBDV6XcvaI/6qNpIXv4qkL9tA40YnPh6BXtoWNWfYHqBoRWKHRaNthsgl3x6oorbB28vfgxd3QQK253m9G1tU= 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 1640016469071386.9987011612633; Mon, 20 Dec 2021 08:07:49 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.249868.430361 (Exim 4.92) (envelope-from ) id 1mzLCI-0007SP-7F; Mon, 20 Dec 2021 16:07:34 +0000 Received: by outflank-mailman (output) from mailman id 249868.430361; Mon, 20 Dec 2021 16:07:33 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mzLCH-0007OY-9u; Mon, 20 Dec 2021 16:07:33 +0000 Received: by outflank-mailman (input) for mailman id 249868; Mon, 20 Dec 2021 16:07:30 +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 1mzLCE-00055w-9y for xen-devel@lists.xenproject.org; Mon, 20 Dec 2021 16:07:30 +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 e95ea199-61ae-11ec-85d3-df6b77346a89; Mon, 20 Dec 2021 17:07:21 +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 C9E35218FD; Mon, 20 Dec 2021 16:07:20 +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 9D6D913D6B; Mon, 20 Dec 2021 16:07:20 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id IBMRJTiqwGEUTAAAMHmgww (envelope-from ); Mon, 20 Dec 2021 16:07:20 +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: e95ea199-61ae-11ec-85d3-df6b77346a89 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1640016440; 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=raxQRDTsz+PEwKz8cqE8gFusgSjw7umtA/NC6kZo3TyDhlKqnpxL3RkcIr1m58M8RLw3YL PAcwPavo0qZmknQsfDyg2XHWqUZqn5Xep6xznNY/lWZtnYQTpCWx9Wm437zz9DpC5ybOAq 8Cfty8nb4eVMNMfMPZPvaNpG73hzk6U= 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 v2 09/10] mini-os: prepare grantmap entry interface for use by PVH mode Date: Mon, 20 Dec 2021 17:07:15 +0100 Message-Id: <20211220160716.4159-10-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20211220160716.4159-1-jgross@suse.com> References: <20211220160716.4159-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1640016471456100001 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 Sun May 5 06:07:21 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=1640016596; cv=none; d=zohomail.com; s=zohoarc; b=NrEEnhq2U1adI3zgYvaVrrVf/MPX5Fb2tOAtUyuVfqEuYoeUycvgJUo0bovTsje1qHq4ghxz0J5KaRGrkJlFMRABaTohmuMUSPzfz88lNpBg7ikQ9JtgDPAZ4g2YIyCd4DF1G6KyKdCXARQ1z2XA8XX1FAKIvx1oKBVO9Zb0ews= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1640016596; 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=YU5cO7yKc0sErm+ZmQXLKdJ2hYMB5NyLfISy0rdpvPzFlDElinGFY5bvONxhZcbf/gI8Z+REKUwegSU1+uq4ITycbQzvjqD2yN9KOCS9Io2fHBJgWFUWTF9SWyFJz0NX+UyF6tT5o5TGkhwpsCZvDDCv7pigyqcl/vrUViQSiuA= 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 1640016596616531.6148116876444; Mon, 20 Dec 2021 08:09:56 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.249883.430392 (Exim 4.92) (envelope-from ) id 1mzLEF-0003LZ-A4; Mon, 20 Dec 2021 16:09:35 +0000 Received: by outflank-mailman (output) from mailman id 249883.430392; Mon, 20 Dec 2021 16:09: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 1mzLEF-0003LS-78; Mon, 20 Dec 2021 16:09:35 +0000 Received: by outflank-mailman (input) for mailman id 249883; Mon, 20 Dec 2021 16:09:33 +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 1mzLCG-00055x-Mv for xen-devel@lists.xenproject.org; Mon, 20 Dec 2021 16:07:32 +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 e99c05da-61ae-11ec-9e60-abaf8a552007; Mon, 20 Dec 2021 17:07:21 +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 0B0E61F3B3; Mon, 20 Dec 2021 16:07:21 +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 D252713D6B; Mon, 20 Dec 2021 16:07:20 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id kBDxMTiqwGEUTAAAMHmgww (envelope-from ); Mon, 20 Dec 2021 16:07:20 +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: e99c05da-61ae-11ec-9e60-abaf8a552007 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1640016441; 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=cIrE1NZbVnDGYkqyRper8jcEWCZAJdk3Br9r1GRzza5OM5fPT4kXfv0ngZHUl4fn0iZ6tW h+sq6ZsGnP6RsLm13byTnCo1CZ/lDlcTRnxfrTeHnM0uZeZ0+Vt8185UPLyFFrxJrZ/wCp aTJZL567BK5Z4U1aCMcRfCtgiowLuQA= 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 v2 10/10] mini-os: modify grant mappings to work in PVH mode Date: Mon, 20 Dec 2021 17:07:16 +0100 Message-Id: <20211220160716.4159-11-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20211220160716.4159-1-jgross@suse.com> References: <20211220160716.4159-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1640016598256100001 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