From nobody Tue May 7 21:52:10 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=1638775448; cv=none; d=zohomail.com; s=zohoarc; b=U69efVlg/s7jxC4HYvDpX4iS1OBb8y1G5qalkzfgY1Oqh9JJ7wfChENEI0Eu+mt7ufsOcs3FmHYLL7FVIWi852ydjRr7D8qw/tMeeiA/mNmVLMnPEcCLLVaillJAJ9qOUOd7Ltsb4Gls+MwVTCmyNd8XXwXsS34656A2LwJdlnM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1638775448; 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=ghs7dH81d+PxzOXZve6mJ+XqQ2rbDs2GA2Tqi5wpJxo=; b=NrcVy3EFLuKE6jQLIxl6DZuSlDaKqZnqjGIRHTilAjyMoOe64ygXQLvb6seMprkLVYMuLVTSqp2DRF68Xn5rfz2i7b51kCh1Bhg1ylUpZI04nM8DXid9CSDdEo06FQ8FGqY2WtDpGAQoykXiUjF/7auGPeQw3tTtFvRgUt+Wqf8= 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 1638775448523597.8271746703865; Sun, 5 Dec 2021 23:24:08 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.238653.413697 (Exim 4.92) (envelope-from ) id 1mu8Lq-00024f-By; Mon, 06 Dec 2021 07:23:54 +0000 Received: by outflank-mailman (output) from mailman id 238653.413697; Mon, 06 Dec 2021 07:23:54 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mu8Lp-00022P-PT; Mon, 06 Dec 2021 07:23:53 +0000 Received: by outflank-mailman (input) for mailman id 238653; Mon, 06 Dec 2021 07:23:50 +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 1mu8Lm-0008Mw-GE for xen-devel@lists.xenproject.org; Mon, 06 Dec 2021 07:23:50 +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 6f396786-5665-11ec-a5e1-b9374ead2679; Mon, 06 Dec 2021 08:23:42 +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 CA4D61FD59; Mon, 6 Dec 2021 07:23:39 +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 9EF421330B; Mon, 6 Dec 2021 07:23:39 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id KKGEJXu6rWHVdAAAMHmgww (envelope-from ); Mon, 06 Dec 2021 07:23:39 +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: 6f396786-5665-11ec-a5e1-b9374ead2679 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1638775419; 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=ghs7dH81d+PxzOXZve6mJ+XqQ2rbDs2GA2Tqi5wpJxo=; b=OKwKoUrehXPVJyeGD0q7h6PTVg1vpJY4V3WRj8a0M5nmGD2nhxvxM0zF1W8AXCkJDP8y3d oipMt3+qVet8MOZX0Swjma4RTLCZ4YGo8jAHf+Dd6ZZzreBpv8tC4xV8TwFfeh6fVsif42 caXHqF6dCnlRbxGY2ZEk+0wFANnkF0I= 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 01/10] mini-os: split e820 map handling into new source file Date: Mon, 6 Dec 2021 08:23:28 +0100 Message-Id: <20211206072337.9517-2-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20211206072337.9517-1-jgross@suse.com> References: <20211206072337.9517-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1638775449347100004 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 Tue May 7 21:52:10 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=1638775448; cv=none; d=zohomail.com; s=zohoarc; b=I076fVkDDQpnAmo1SbsDakNMY9kFBClNYr1wZ6T3A0fivQpwJcupynkOTygUitLOwxv902tAKhbMEo4rW2rMmm4TSGgpYkJyj98cJAe01JwSN6qZTS1ZLcBZZuw9azbP3ZtcHrdyNLAglFS9r/GLdTIl15s9aKA7EurEinXOXv0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1638775448; 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=9EBgP/t2UoDrCarm09EUmFu2+s1qFBTeUbKK/KiO/DY=; b=WaWlrJWM1Gp735JcAWzzFQsCOCL6BPA+QDy8hva/fzEpxwSgvbhaPOm7QegNE7O70MYON2FkSdAk2lwj0croDrwRTcEecR0bTsPPtiBcoCD5qd8dWF0+Ua0Y+FjpB/hp7PkEeBH+iwdJOG6OdFwOsbcqmGGdyWPceZiDNDK3qPs= 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 1638775448640802.4465656308694; Sun, 5 Dec 2021 23:24:08 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.238646.413647 (Exim 4.92) (envelope-from ) id 1mu8Lk-0000tH-L2; Mon, 06 Dec 2021 07:23:48 +0000 Received: by outflank-mailman (output) from mailman id 238646.413647; Mon, 06 Dec 2021 07:23:48 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mu8Lk-0000rp-An; Mon, 06 Dec 2021 07:23:48 +0000 Received: by outflank-mailman (input) for mailman id 238646; Mon, 06 Dec 2021 07:23:47 +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 1mu8Li-0008Mk-PL for xen-devel@lists.xenproject.org; Mon, 06 Dec 2021 07:23:46 +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 6f610693-5665-11ec-8a4d-196798b21f7b; Mon, 06 Dec 2021 08:23:41 +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 08A651FD5F; Mon, 6 Dec 2021 07:23:40 +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 D17051330B; Mon, 6 Dec 2021 07:23:39 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id +KHPMXu6rWHVdAAAMHmgww (envelope-from ); Mon, 06 Dec 2021 07:23:39 +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: 6f610693-5665-11ec-8a4d-196798b21f7b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1638775420; 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=9EBgP/t2UoDrCarm09EUmFu2+s1qFBTeUbKK/KiO/DY=; b=BRqj6916g8tEUhYg2upskhF6cz1U43E+S8kWYjh4/UANTdYbnyxixtQ0HloMJ9ZR7FWFOz DXxLfY9F/iyeWYFWKluw1kbLFenMDocBRk0rG0hYDlJ3571vIMJADFgot0qLlVzrDxLijz Itl0wPxaH91UsJn7gYh4bdUmNigV4iI= 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 02/10] mini-os: sort and sanitize e820 memory map Date: Mon, 6 Dec 2021 08:23:29 +0100 Message-Id: <20211206072337.9517-3-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20211206072337.9517-1-jgross@suse.com> References: <20211206072337.9517-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1638775449283100001 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 --- e820.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/e820.c b/e820.c index 2165280..336a8b8 100644 --- a/e820.c +++ b/e820.c @@ -57,6 +57,60 @@ static char *e820_types[E820_TYPES] =3D { [E820_PMEM] =3D "PMEM" }; =20 +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_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; +} + +static void e820_sanitize(void) +{ + int i; + unsigned long end; + + /* Adjust map entries to page boundaries. */ + for ( i =3D 0; i < e820_entries; i++ ) + { + end =3D (e820_map[i].addr + e820_map[i].size + PAGE_SIZE - 1) & PA= GE_MASK; + e820_map[i].addr &=3D PAGE_MASK; + e820_map[i].size =3D end - e820_map[i].addr; + } + + /* Sort entries by start address. */ + for ( i =3D 0; i < e820_entries - 1; i++ ) + { + if ( e820_map[i].addr > e820_map[i + 1].addr ) + { + e820_swap_entries(i, i + 1); + i =3D -1; + } + } + + /* Merge adjacent entries of same type. */ + 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=3D e820_map[i + 1].ad= dr ) + { + e820_map[i].size +=3D e820_map[i + 1].size; + e820_remove_entry(i + 1); + i--; + } + } +} + static void e820_get_memmap(void) { long ret; @@ -71,6 +125,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 Tue May 7 21:52:10 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=1638775448; cv=none; d=zohomail.com; s=zohoarc; b=OCo8RO+ZqV5ljjHo6ThmnHXsLaUwoFOkWLGsm0AgcrsIumf6uOsIYqQUs7c6zeOWSFvrdQvbpu3FLYG9s2/mFZ0IqxphsmdhBXfrMXT5Bp07pgG24HKEw3LY3Ol5b5tqmaJehkrWu/OqIUiIrtVQPQrz1GsneUVdJeFejyE0lMs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1638775448; 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=2T/0NcFBUay+umzcIVeBLzt93p/NF1ROTt/i4aaQWm8=; b=hgEhQqe5UV0R/6dSFaY6bAGUhdqLyGgfcombuEdIGwBBuZQVo3PrHrHij5a4hxKfGje7qAm+OAzF/GiQBcgKodEIOtmmshY6zm3N6SOpuQDhvlqolI7gY+AhJkIDWy/wwboBaS8KialqrLXfA6E81areJNMlzgszFs6PkmXSLIw= 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 1638775448107398.1166890737737; Sun, 5 Dec 2021 23:24:08 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.238642.413624 (Exim 4.92) (envelope-from ) id 1mu8Li-0000Uz-N3; Mon, 06 Dec 2021 07:23:46 +0000 Received: by outflank-mailman (output) from mailman id 238642.413624; Mon, 06 Dec 2021 07:23:46 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mu8Li-0000U6-EV; Mon, 06 Dec 2021 07:23:46 +0000 Received: by outflank-mailman (input) for mailman id 238642; Mon, 06 Dec 2021 07:23:44 +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 1mu8Lg-0008Mk-P7 for xen-devel@lists.xenproject.org; Mon, 06 Dec 2021 07:23:44 +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 6f7d7449-5665-11ec-8a4d-196798b21f7b; Mon, 06 Dec 2021 08:23:41 +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 395151FDF2; Mon, 6 Dec 2021 07:23:40 +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 0E8A01330B; Mon, 6 Dec 2021 07:23:40 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 8D9LAny6rWHVdAAAMHmgww (envelope-from ); Mon, 06 Dec 2021 07:23:40 +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: 6f7d7449-5665-11ec-8a4d-196798b21f7b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1638775420; 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=2T/0NcFBUay+umzcIVeBLzt93p/NF1ROTt/i4aaQWm8=; b=Efh8bL88xHn6VBERl0JJiPtNHp4+hYDaguiD7BajgSnsl1zjovl6LdewERRMNpnIvJ+zAg +N/0Aw1awnndKXgPYBx7VqGyfzGegxatcKxZnM2tdUBUNqmw4p+gSU/wEyCxlNpAKvf6GH 9sxgiwDdn7genYuvrgcOIKLeZ0DmU8k= 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 03/10] mini-os: don't assume contiguous RAM when initializing in PVH mode Date: Mon, 6 Dec 2021 08:23:30 +0100 Message-Id: <20211206072337.9517-4-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20211206072337.9517-1-jgross@suse.com> References: <20211206072337.9517-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1638775449366100005 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 --- arch/x86/mm.c | 6 +----- e820.c | 13 ++++++++----- include/e820.h | 2 +- 3 files changed, 10 insertions(+), 11 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 336a8b8..14fd3cd 100644 --- a/e820.c +++ b/e820.c @@ -155,10 +155,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, max =3D 0; =20 e820_get_memmap(); =20 @@ -166,9 +166,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; + max =3D e820_map[i].addr >> PAGE_SHIFT; + if ( pages <=3D pfns ) + return max + pages; + pages -=3D pfns; + max +=3D pfns; } =20 return max; 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 Tue May 7 21:52:10 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=1638775450; cv=none; d=zohomail.com; s=zohoarc; b=FhUIa1Etar0oCgEYFXajeBF8+a0dUZ9J9KKSv+w8N7pYEWkw9Bh5Ko561gr7kns6tFEiBti0ELm2/JHNO+jNmHOXRRGIeBmuToJBJR63xqGqOFAwVrER10wJ6SHEWizSaZIt1w8QynL8rWOqe3esr/f9q4cQSBhWs/W9BVm4h88= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1638775450; 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=fifZXfrZUGkUNpcAkG1BRfuMQBISL/dU4QUsOAzQL4U=; b=gdx4t7BkEYduZD2aWFwlMxuBpaulr2IbgxVxbRF3XS849iAH7NfKZUZwUOhixPJLjOJ7OtzIFh4RM8rCps4Vm6A+hoQMrarUA4I7OXZi+SALuSo1rzENuz4WCWuQ/mWldnQiUDBiBNUf4gW09jP7GCic1D/keInmJUBeTAloZyk= 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 1638775450885156.14411316724238; Sun, 5 Dec 2021 23:24:10 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.238655.413711 (Exim 4.92) (envelope-from ) id 1mu8Ls-0002Ka-29; Mon, 06 Dec 2021 07:23:56 +0000 Received: by outflank-mailman (output) from mailman id 238655.413711; Mon, 06 Dec 2021 07:23:55 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mu8Lr-0002GP-3A; Mon, 06 Dec 2021 07:23:55 +0000 Received: by outflank-mailman (input) for mailman id 238655; Mon, 06 Dec 2021 07:23:51 +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 1mu8Ln-0008Mw-G9 for xen-devel@lists.xenproject.org; Mon, 06 Dec 2021 07:23:51 +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 6f91d96a-5665-11ec-a5e1-b9374ead2679; Mon, 06 Dec 2021 08:23:42 +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 6BA2A1FDFB; Mon, 6 Dec 2021 07:23:40 +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 3F22913A9C; Mon, 6 Dec 2021 07:23:40 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id kF8qDny6rWHVdAAAMHmgww (envelope-from ); Mon, 06 Dec 2021 07:23:40 +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: 6f91d96a-5665-11ec-a5e1-b9374ead2679 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1638775420; 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=fifZXfrZUGkUNpcAkG1BRfuMQBISL/dU4QUsOAzQL4U=; b=U7vdUqmDl+BDqN1mx8zjLDu96BhdhcWXq6/5iz61LD62GKIzbUBiD3T/HyEFWp5I49it6z uurD1jtDEmFVhZsQBdzctRD1tOjpdvcyPwVmNrxqODmABcUHkwV+WQtC9n7tZATJVMtlNV 7eUgUf2JwnHICoD2dAJekdXOvvj0zE0= 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 04/10] mini-os: respect memory map when ballooning up Date: Mon, 6 Dec 2021 08:23:31 +0100 Message-Id: <20211206072337.9517-5-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20211206072337.9517-1-jgross@suse.com> References: <20211206072337.9517-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1638775451442100013 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 --- 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..80d89c7 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_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 14fd3cd..50029bb 100644 --- a/e820.c +++ b/e820.c @@ -160,7 +160,8 @@ unsigned long e820_get_maxpfn(unsigned long pages) int i; unsigned long pfns, max =3D 0; =20 - e820_get_memmap(); + if ( !e820_entries ) + e820_get_memmap(); =20 for ( i =3D 0; i < e820_entries; i++ ) { @@ -176,3 +177,21 @@ unsigned long e820_get_maxpfn(unsigned long pages) =20 return max; } + +unsigned long e820_get_max_pages(unsigned long pfn, unsigned long pages) +{ + int i; + unsigned long end; + + for ( i =3D 0; i < e820_entries; i++ ) + { + if ( e820_map[i].type !=3D E820_RAM || + (e820_map[i].addr >> PAGE_SHIFT) > pfn ) + continue; + + end =3D (e820_map[i].addr + e820_map[i].size) >> PAGE_SHIFT; + 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..49daefa 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_pages(unsigned long pfn, unsigned long pages); =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 Tue May 7 21:52:10 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=1638775448; cv=none; d=zohomail.com; s=zohoarc; b=IWVzV/kheGfksIOuFOI09dy3GdiGktVNuYHxtPkG5GtfD5EUVizbQmSZQMGjvrYbXAG/bxRGvU8fP1r+Yc8/s/b31aru8xVoefOa+x3Jgh4INf9AorRBplmExW2qedsPUzsIX1KWj8SVSdBilh2kszKLVZbKZQw4Ai0ihYqkIX4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1638775448; 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=d8/sEf5zxip/z6wrXT3urxSeGPiRIv+pRBh5TUEPjPg=; b=M8pE2W1h8Xi0wh0/NTYyW8o/eSuS+H70eVfXCIAee3uu0yUMwu6SDJqcOl57OaWDbc3NsGZd3cKEUin//tTBKHgyOGU1uv/UlJlcpyqSsTLHsBy1QhCGRsCQi/PE6A5pXvTT97wE5d/i/FvNLkXcWSuIyhnBOescnKrZH2VGops= 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 1638775447990223.58988156945668; Sun, 5 Dec 2021 23:24:07 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.238638.413595 (Exim 4.92) (envelope-from ) id 1mu8Lg-0008PG-SQ; Mon, 06 Dec 2021 07:23:44 +0000 Received: by outflank-mailman (output) from mailman id 238638.413595; Mon, 06 Dec 2021 07:23:44 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mu8Lg-0008P9-OU; Mon, 06 Dec 2021 07:23:44 +0000 Received: by outflank-mailman (input) for mailman id 238638; Mon, 06 Dec 2021 07:23:42 +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 1mu8Le-0008Mk-Ov for xen-devel@lists.xenproject.org; Mon, 06 Dec 2021 07:23:42 +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 6fb54773-5665-11ec-8a4d-196798b21f7b; Mon, 06 Dec 2021 08:23:41 +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 9BC782192D; Mon, 6 Dec 2021 07:23:40 +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 7136C1330B; Mon, 6 Dec 2021 07:23:40 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id CIJWGny6rWHVdAAAMHmgww (envelope-from ); Mon, 06 Dec 2021 07:23:40 +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: 6fb54773-5665-11ec-8a4d-196798b21f7b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1638775420; 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=d8/sEf5zxip/z6wrXT3urxSeGPiRIv+pRBh5TUEPjPg=; b=sLHRlJRgHai3r+90pA2coKYs9ibAH4mCtD76N9qGrGMXaMr3rg9LAALP04EJ7vL1KjMQrA kFV9HwUesSh0/l0lhyBYOvNpt+LqYKWDwjPly9BqLThPvPNQ+5lVxcKVj1yhHCi+qBaQDM CgomOAfJe0Nf/fJuEJ7vKIgHiGcOuY8= 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 05/10] mini-os: don't repeat definition available via header file Date: Mon, 6 Dec 2021 08:23:32 +0100 Message-Id: <20211206072337.9517-6-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20211206072337.9517-1-jgross@suse.com> References: <20211206072337.9517-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1638775449505100009 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 Tue May 7 21:52:10 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=1638775448; cv=none; d=zohomail.com; s=zohoarc; b=W0aWG7cGy9/h+Zt9smtl6eJojXiEGZfWvkmGaWtRbTSPw8A2mMpHtjXGAnbj5Gn3PYFhQ9C8cTk3qSmDJn+kf+1biZvt0tcfJGebNlPS0s+ljhlYttTkHznw8q0c8euCi3yvME7n1bdKCQMXXqX7ak+rJoHLIhgHIHyE8pCcT8c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1638775448; 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=vd3HZ1Ub/A6C0NepRB2jPIIL8ubajSRfG+DMd9e6lrQ=; b=VqJioE86WB5oUypFUf95cpbcX1t430Dxq5l32rlRZgwiLk6llv7HeMyOWLd7ctTuHrJ1042VIUWTNcm63aDuk+4BLxYxtIjIvtLAFjX+gPTrmRrJCeAp8/f5YnJM3qBFgkawMwLhBO9rAZ8PbNDa8SCLrce04otR6uvPVN4HRXo= 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 163877544799557.25842250736264; Sun, 5 Dec 2021 23:24:07 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.238650.413675 (Exim 4.92) (envelope-from ) id 1mu8Ln-0001WZ-GT; Mon, 06 Dec 2021 07:23:51 +0000 Received: by outflank-mailman (output) from mailman id 238650.413675; Mon, 06 Dec 2021 07:23:51 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mu8Ln-0001UJ-5M; Mon, 06 Dec 2021 07:23:51 +0000 Received: by outflank-mailman (input) for mailman id 238650; Mon, 06 Dec 2021 07:23:49 +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 1mu8Lk-0008Mk-PU for xen-devel@lists.xenproject.org; Mon, 06 Dec 2021 07:23:48 +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 6fd34f57-5665-11ec-8a4d-196798b21f7b; Mon, 06 Dec 2021 08:23:41 +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 CC5DD1FE02; Mon, 6 Dec 2021 07:23:40 +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 A1AF01330B; Mon, 6 Dec 2021 07:23:40 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id KBYtJny6rWHVdAAAMHmgww (envelope-from ); Mon, 06 Dec 2021 07:23:40 +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: 6fd34f57-5665-11ec-8a4d-196798b21f7b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1638775420; 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=vd3HZ1Ub/A6C0NepRB2jPIIL8ubajSRfG+DMd9e6lrQ=; b=qHWwtj7KcAOcPH8k3zOeliWh+e0spXwxDmmr1q/QVVhN62V4tJBjwiMqJKYRJ1lO6Gi1Ut lEgK3mDVN36vJTDIAFV81d5ILR18qUCN5ynObSV6aGi66CVhknpVzLO26jSWGfS0fwO+R+ 06lm+HKOUvMveLFJKNI3h2wtEFwxu/w= 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 06/10] mini-os: add memory map service functions Date: Mon, 6 Dec 2021 08:23:33 +0100 Message-Id: <20211206072337.9517-7-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20211206072337.9517-1-jgross@suse.com> References: <20211206072337.9517-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1638775449328100002 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 --- e820.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/e820.h | 4 +++ 2 files changed, 76 insertions(+) diff --git a/e820.c b/e820.c index 50029bb..2888932 100644 --- a/e820.c +++ b/e820.c @@ -66,6 +66,21 @@ static void e820_remove_entry(int idx) e820_map[i] =3D e820_map[i + 1]; } =20 +static void e820_insert_entry(int idx) +{ + 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]; +} + static void e820_swap_entries(int idx1, int idx2) { struct e820entry entry; @@ -153,6 +168,63 @@ 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(i); + e820_map[i].addr =3D last; + e820_map[i].size =3D needed; + e820_map[i].type =3D 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 < e820_map[i].addr; i++ ); + + BUG_ON(i =3D=3D e820_entries || e820_map[i].type !=3D E820_RESERVED); + + 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].addr =3D addr; + e820_map[i].size =3D size; + return; + } + + e820_insert_entry(i + 1); + e820_map[i + 1].addr =3D addr + size; + e820_map[i + 1].size =3D e820_map[i].addr + e820_map[i].size - + e820_map[i + 1].addr; + e820_map[i + 1].type =3D 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 49daefa..694ce3b 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_pages(unsigned long pfn, unsigned long pages); +#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 Tue May 7 21:52:10 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=1638775452; cv=none; d=zohomail.com; s=zohoarc; b=EZvr663j+pVeO8ZWWZnBn39d8azyNrjlH8CkOiXi3qc7TY+WR3ikCxbznQJRYl7QnAJOBHklU2YA3tUkCnN/jnCO/rSds7rdbun7sAiLW6JYQMBWHepvBI3kOtxYDw0+fO7MKRpY0fVTG2Sh3cvrva0VQu6Yekz66lMs0Zh7yKI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1638775452; 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=jJ0RmLtKB8UkcvX+Y3JuijTbu6nHqV/hpfXxOIuN+R4=; b=SeLJPzkD+0tdBK9b3xA05pF2Sq9okAim16S63rZD6mDijo8fZVhZJtIQSsFhiHul7wEsUrHPHLQXTc1nRSi38Qi8OuvPU2BJKffDIFi4PepQiHm90YQJlOmx2mTA2cgz4ksw9vZWRgeQdvZAzJk2u5cVgYZHF1MkqSW5+4rm2rg= 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 1638775452145973.7720282710512; Sun, 5 Dec 2021 23:24:12 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.238647.413655 (Exim 4.92) (envelope-from ) id 1mu8Ll-000120-8z; Mon, 06 Dec 2021 07:23:49 +0000 Received: by outflank-mailman (output) from mailman id 238647.413655; Mon, 06 Dec 2021 07:23:49 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mu8Lk-0000zi-QB; Mon, 06 Dec 2021 07:23:48 +0000 Received: by outflank-mailman (input) for mailman id 238647; Mon, 06 Dec 2021 07:23:47 +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 1mu8Lj-0008Mw-Ff for xen-devel@lists.xenproject.org; Mon, 06 Dec 2021 07:23:47 +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 7022dedf-5665-11ec-a5e1-b9374ead2679; Mon, 06 Dec 2021 08:23:42 +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 0823F1FE04; Mon, 6 Dec 2021 07:23:41 +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 D21C21330B; Mon, 6 Dec 2021 07:23:40 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id YC8CMny6rWHVdAAAMHmgww (envelope-from ); Mon, 06 Dec 2021 07:23:40 +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: 7022dedf-5665-11ec-a5e1-b9374ead2679 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1638775421; 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=jJ0RmLtKB8UkcvX+Y3JuijTbu6nHqV/hpfXxOIuN+R4=; b=dNA4rT4w7GOiBlM5Kmz8jsutTtW4O/BdSr4y396zKhGKNlRRf6sRGYOoPEhT9pubzIaxgV vUNVo9O8b28ePqjllYVqkYx5QLJLa+NLpclGZLvUJHx6m1m/s2KjJbR4625rUfKAMVbAHh hh/ji8MQP/L/ZsLI+F2z3eDzE5ZiHW0= 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 07/10] mini-os: move x86 specific gnttab coding into arch/x86/gnttab.c Date: Mon, 6 Dec 2021 08:23:34 +0100 Message-Id: <20211206072337.9517-8-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20211206072337.9517-1-jgross@suse.com> References: <20211206072337.9517-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1638775453690100002 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. 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 1638775453273436.64570169780734; Sun, 5 Dec 2021 23:24:13 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.238639.413600 (Exim 4.92) (envelope-from ) id 1mu8Lh-0008SV-7g; Mon, 06 Dec 2021 07:23:45 +0000 Received: by outflank-mailman (output) from mailman id 238639.413600; Mon, 06 Dec 2021 07:23:45 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mu8Lh-0008S6-0r; Mon, 06 Dec 2021 07:23:45 +0000 Received: by outflank-mailman (input) for mailman id 238639; Mon, 06 Dec 2021 07:23:43 +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 1mu8Lf-0008Mw-N6 for xen-devel@lists.xenproject.org; Mon, 06 Dec 2021 07:23:43 +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 7022ded4-5665-11ec-a5e1-b9374ead2679; Mon, 06 Dec 2021 08:23:42 +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 389BF1FE05; Mon, 6 Dec 2021 07:23:41 +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 0E5901330B; Mon, 6 Dec 2021 07:23:41 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id kLs5An26rWHVdAAAMHmgww (envelope-from ); Mon, 06 Dec 2021 07:23:41 +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: 7022ded4-5665-11ec-a5e1-b9374ead2679 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1638775421; 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=NkthQq3sOoUO2D/mfhsQzY8AtroPqg7IVvaaK/lNSyg=; b=NGet1YZOyh4euiYxkOXsJV6LrEs7LCH7qOFfbjS6pHlqjn7LH2kEJpxYVaflWNi5aRJFq1 F2GoEyVlbMEHX/ZvoJZFkB8hmgmzYs16rUTewlgN7xhDFfkq+NQaZqWNXI5TinfAKPNiEZ vkLeF+R1YlpPPKC2g614AirthTWs+yU= 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 08/10] mini-os: add proper pvh grant table handling Date: Mon, 6 Dec 2021 08:23:35 +0100 Message-Id: <20211206072337.9517-9-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20211206072337.9517-1-jgross@suse.com> References: <20211206072337.9517-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1638775453841100005 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 Tue May 7 21:52:10 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=1638775449; cv=none; d=zohomail.com; s=zohoarc; b=EqUjuohYpupKcH4JX19rfBGxH4RRKyYAbCNyxGTicXlaDb/CUtgKZWhhMhd6FqwC59JuwYFm6BVGeGpqfY799bzs5Iyc/cQEKvdn1yxuoxRJuLH7b01kARbK23ZsFGB1pZkrSli1nZsOWlEflok+/ofK9Y2ovcIA1QI9Sw3OJdQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1638775449; 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=6ZwIQ/iqw4tJOJDbjhXNjxEyNK1FoP/fIru8GNLpj3E=; b=Rc+7wr2AESqUKGWXhdiW4L9VdOrcEjVuNzrHMw6LiFA0k3O528DA30uy0wBl1TQM6T9lwDNY4CyBCXOETXLkDtZWWpWE+ouuW0fp44Wur3kwX31naEU6+fhGkOXz3NQbxZ4qBw0xROtUBPU8IQ3EUtLcbVwv67y8Nh0cPXMecAo= 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 1638775449334850.528203184052; Sun, 5 Dec 2021 23:24:09 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.238652.413692 (Exim 4.92) (envelope-from ) id 1mu8Lp-0001uJ-AP; Mon, 06 Dec 2021 07:23:53 +0000 Received: by outflank-mailman (output) from mailman id 238652.413692; Mon, 06 Dec 2021 07:23:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mu8Lo-0001sz-TC; Mon, 06 Dec 2021 07:23:52 +0000 Received: by outflank-mailman (input) for mailman id 238652; Mon, 06 Dec 2021 07:23:50 +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 1mu8Ll-0008Mk-PV for xen-devel@lists.xenproject.org; Mon, 06 Dec 2021 07:23:49 +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 702d5e8a-5665-11ec-8a4d-196798b21f7b; Mon, 06 Dec 2021 08:23:41 +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 67E9A21940; Mon, 6 Dec 2021 07:23:41 +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 3F43413A9C; Mon, 6 Dec 2021 07:23:41 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id eKQ0Dn26rWHVdAAAMHmgww (envelope-from ); Mon, 06 Dec 2021 07:23:41 +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: 702d5e8a-5665-11ec-8a4d-196798b21f7b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1638775421; 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=6ZwIQ/iqw4tJOJDbjhXNjxEyNK1FoP/fIru8GNLpj3E=; b=Dx4H9mkwe6zA3efQNNiTwU8kUNk9Ej8hkMBKut7osjyQ2cr7rnD6CpIA0Nj0RHtFNQgcyg TXfAw58DejxvNQ7ZkIyHrNSxZegZP9MrQRcqoeaTzRwkxZaq5qsws8rpYRbWhG91FY5ejP Q0+4ad5Lmp4I657Xw5k2xxfGMqbAuks= 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 09/10] mini-os: prepare grantmap entry interface for use by PVH mode Date: Mon, 6 Dec 2021 08:23:36 +0100 Message-Id: <20211206072337.9517-10-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20211206072337.9517-1-jgross@suse.com> References: <20211206072337.9517-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1638775451341100011 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 Tue May 7 21:52:10 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=1638775689; cv=none; d=zohomail.com; s=zohoarc; b=RoNZdu0+AXGqjaRP8H8OGI9y3tkQNwjmfNw0eZVRdMLfZI7OGvqHK903ORtmmtiSpShb+ufauCyv0T6Lm2aGI2jO2gq/UMaTYthnhuLpYZCgU89VV3MeByBoELU1LvCg+KjIieppMsuQXSQeblzls1io1kWJzSIlyo5ZuO8PGGc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1638775689; 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=130MnSWpuIXwnTm+cjFHpVCXYuVhbtrRePozwlMpV2g=; b=A2L26STf59LnssmY2cVp0uCxffLXjFxhiE6n29HRcHpLAD6Vg2c0mM6/7/kX2/vFTngdQqgq6DB4ryu0AoXKen0M0r9iX5ppfVeHCPdR0x+o/3Gb1ba9333A4RJR8KTpS5EYpUZq83gJwFNjemz0oCSchxMom2cPwvg/yF1zxH4= 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 1638775689729853.7603772658833; Sun, 5 Dec 2021 23:28:09 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.238684.413752 (Exim 4.92) (envelope-from ) id 1mu8Pl-0007M4-03; Mon, 06 Dec 2021 07:27:57 +0000 Received: by outflank-mailman (output) from mailman id 238684.413752; Mon, 06 Dec 2021 07:27: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 1mu8Pk-0007Lx-Rb; Mon, 06 Dec 2021 07:27:56 +0000 Received: by outflank-mailman (input) for mailman id 238684; Mon, 06 Dec 2021 07:27:55 +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 1mu8Ln-0008Mk-Q4 for xen-devel@lists.xenproject.org; Mon, 06 Dec 2021 07:23:51 +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 704d2002-5665-11ec-8a4d-196798b21f7b; Mon, 06 Dec 2021 08:23:41 +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 9B0511FD5F; Mon, 6 Dec 2021 07:23:41 +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 6F70C1330B; Mon, 6 Dec 2021 07:23:41 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id WBT3GX26rWHVdAAAMHmgww (envelope-from ); Mon, 06 Dec 2021 07:23:41 +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: 704d2002-5665-11ec-8a4d-196798b21f7b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1638775421; 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=130MnSWpuIXwnTm+cjFHpVCXYuVhbtrRePozwlMpV2g=; b=AjWTSxYJ89XHPHLQyeWDS9DruwhbMIEjTvgUQZfbYULENVf01Zk806s0nai32nYXZUYys7 qzDQHb/ETuvZPzcVy73h72PRM3pubDegRurfcWareknP4FbyHbLW8bKR2Koc1pFcKB6LhU dumF55ESzsn9V9MbWQP4ulrTkzxjYag= 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 10/10] mini-os: modify grant mappings to work in PVH mode Date: Mon, 6 Dec 2021 08:23:37 +0100 Message-Id: <20211206072337.9517-11-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20211206072337.9517-1-jgross@suse.com> References: <20211206072337.9517-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1638775690665100001 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 From nobody Tue May 7 21:52:10 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=1638794806; cv=none; d=zohomail.com; s=zohoarc; b=Ed0qHe8YRH1AZ8Xk1cewbl8ucce1gHa6zS06aun+xH9kUA0GH9kHkY3IVP3b0IHhd+YpeDnBJUnVI8eFTqQ/dZxD6c+NgAmR4PAjJNWbAT98DtKylmBEgFkfCzroNac5FbYzBZufvFi/x4y4+pA87o4GgKRcgw5CPw22tQE7osw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1638794806; 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=/A9hituH0+aNT0T1wCGc2OkDoQuYF+gpjDznKK7VZyY=; b=govT5RDQVpDvs+vohEsYFksJxeQ0nPG2SbOPw/gtelOKYh1JsFq78oc1elj8keBl8rirNs51OKsCLYh96z50F5qtCEo5VQafCyiIOh0tQOFVcm2iAtvhxReCJK66RS6W5cmLMlgdGU13+ZRHT0NaXa/t+fhfR+s1yaMtL2slQpg= 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 163879480680647.61216501211436; Mon, 6 Dec 2021 04:46:46 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.238844.413919 (Exim 4.92) (envelope-from ) id 1muDNs-0008I7-0z; Mon, 06 Dec 2021 12:46:20 +0000 Received: by outflank-mailman (output) from mailman id 238844.413919; Mon, 06 Dec 2021 12:46: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 1muDNr-0008I0-U7; Mon, 06 Dec 2021 12:46:19 +0000 Received: by outflank-mailman (input) for mailman id 238844; Mon, 06 Dec 2021 12:46:18 +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 1muDNq-0008Hp-5W for xen-devel@lists.xenproject.org; Mon, 06 Dec 2021 12:46:18 +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 80c9bbf1-5692-11ec-8a4d-196798b21f7b; Mon, 06 Dec 2021 13:46:17 +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 9082F212C0; Mon, 6 Dec 2021 12:46:15 +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 569A413C18; Mon, 6 Dec 2021 12:46:15 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id RTnhExcGrmGACgAAMHmgww (envelope-from ); Mon, 06 Dec 2021 12:46:15 +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: 80c9bbf1-5692-11ec-8a4d-196798b21f7b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1638794775; 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=/A9hituH0+aNT0T1wCGc2OkDoQuYF+gpjDznKK7VZyY=; b=sMm+Y895O0EMvsESVYoYMPjP+qY/t980M9zrWHQy010a6pGQqMqpy34xMtKhzo6hxaeM96 L2yuI7aFWFCEaWR503e4VfHsKhGdxpghBvA68AOKebDHvflqU5YL4qxLbFXOYNEaKyK/fq /S7mGpe2S0PIThYZ2G4/8Q9ZpzFCDCs= 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] mini-os: support event channel 0 for console Date: Mon, 6 Dec 2021 13:46:12 +0100 Message-Id: <20211206124612.24758-1-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20211206072337.9517-1-jgross@suse.com> References: <20211206072337.9517-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1638794809014100001 Content-Type: text/plain; charset="utf-8" The console event channel might be 0 for the console, so use the value of ~0 as invalid instead. Signed-off-by: Juergen Gross --- console/xencons_ring.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/console/xencons_ring.c b/console/xencons_ring.c index b6db74e..5c2573e 100644 --- a/console/xencons_ring.c +++ b/console/xencons_ring.c @@ -17,7 +17,7 @@ DECLARE_WAIT_QUEUE_HEAD(console_queue); =20 static struct xencons_interface *console_ring; -uint32_t console_evtchn; +uint32_t console_evtchn =3D ~0; =20 static struct consfront_dev* resume_xen_console(struct consfront_dev* dev); =20 @@ -55,7 +55,7 @@ static inline void notify_daemon(struct consfront_dev *de= v) =20 static inline struct xencons_interface *xencons_interface(void) { - return console_evtchn ? console_ring : NULL; + return (console_evtchn !=3D ~0) ? console_ring : NULL; }=20 =20 int xencons_ring_send_no_notify(struct consfront_dev *dev, const char *dat= a, unsigned len) @@ -181,7 +181,7 @@ struct consfront_dev *xencons_ring_init(void) { struct consfront_dev *dev; =20 - if (!console_evtchn) + if (console_evtchn !=3D ~0) return 0; =20 dev =3D malloc(sizeof(struct consfront_dev)); --=20 2.26.2