From minios-devel-bounces@lists.xenproject.org Mon Dec 06 07:23:46 2021 Return-path: Envelope-to: archives@lists.xenproject.org Delivery-date: Mon, 06 Dec 2021 07:23:46 +0000 Received: from list by lists.xenproject.org with outflank-mailman.238637.413590 (Exim 4.92) (envelope-from ) id 1mu8Lf-0008N5-Pi; Mon, 06 Dec 2021 07:23:43 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 238637.413590; Mon, 06 Dec 2021 07:23:43 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mu8Lf-0008Mx-M7; Mon, 06 Dec 2021 07:23:43 +0000 Received: by outflank-mailman (input) for mailman id 238637; 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-0O for minios-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-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-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: 8bit arch/x86/setup.c is repeating the definition of __pte() instead using the appropriate header. Fix that. Signed-off-by: Juergen Gross --- 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]; extern char shared_info[PAGE_SIZE]; -#if defined(__x86_64__) -#define __pte(x) ((pte_t) { (x) } ) -#else -#define __pte(x) ({ unsigned long long _x = (x); \ - ((pte_t) {(unsigned long)(_x), (unsigned long)(_x>>32)}); }) -#endif - static inline void fpu_init(void) { asm volatile("fninit"); } -- 2.26.2 From minios-devel-bounces@lists.xenproject.org Mon Dec 06 07:23:46 2021 Return-path: Envelope-to: archives@lists.xenproject.org Delivery-date: Mon, 06 Dec 2021 07:23:46 +0000 Received: from list by lists.xenproject.org with outflank-mailman.238640.413606 (Exim 4.92) (envelope-from ) id 1mu8Lh-00004u-JS; Mon, 06 Dec 2021 07:23:45 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 238640.413606; 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-0008Uw-8i; Mon, 06 Dec 2021 07:23:45 +0000 Received: by outflank-mailman (input) for mailman id 238640; Mon, 06 Dec 2021 07:23:43 +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 1mu8Lf-0008Mk-P4 for minios-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-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-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-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: 8bit 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 = DOMID_SELF; - unsigned long max; pt_base = page_table_base; first_free_pfn = 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 = ret; - max = e820_get_maxpfn(); - if ( max < last_free_pfn ) - last_free_pfn = max; + last_free_pfn = e820_get_maxpfn(ret); } #endif 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 -unsigned long e820_get_maxpfn(void) +unsigned long e820_get_maxpfn(unsigned long pages) { int i; - unsigned long pfn, max = 0; + unsigned long pfns, max = 0; e820_get_memmap(); @@ -166,9 +166,12 @@ unsigned long e820_get_maxpfn(void) { if ( e820_map[i].type != E820_RAM ) continue; - pfn = (e820_map[i].addr + e820_map[i].size) >> PAGE_SHIFT; - if ( pfn > max ) - max = pfn; + pfns = e820_map[i].size >> PAGE_SHIFT; + max = e820_map[i].addr >> PAGE_SHIFT; + if ( pages <= pfns ) + return max + pages; + pages -= pfns; + max += pfns; } 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; -unsigned long e820_get_maxpfn(void); +unsigned long e820_get_maxpfn(unsigned long pages); #endif /*__E820_HEADER*/ -- 2.26.2 From minios-devel-bounces@lists.xenproject.org Mon Dec 06 07:23:47 2021 Return-path: Envelope-to: archives@lists.xenproject.org Delivery-date: Mon, 06 Dec 2021 07:23:47 +0000 Received: from list by lists.xenproject.org with outflank-mailman.238643.413630 (Exim 4.92) (envelope-from ) id 1mu8Lj-0000Y0-1K; Mon, 06 Dec 2021 07:23:47 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 238643.413630; 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-0000XI-NT; Mon, 06 Dec 2021 07:23:46 +0000 Received: by outflank-mailman (input) for mailman id 238643; Mon, 06 Dec 2021 07:23:45 +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 1mu8Lh-0008Mw-FM for minios-devel@lists.xenproject.org; Mon, 06 Dec 2021 07:23:45 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 6f37a3df-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-out1.suse.de (Postfix) with ESMTPS id 970A8212BF; 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 66A981330B; 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 V+avF3u6rWHVdAAAMHmgww (envelope-from ); Mon, 06 Dec 2021 07:23:39 +0000 X-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-devel" X-Inumbo-ID: 6f37a3df-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; bh=YTvNTjnUOIGBj3YdpCPw4zpcXKpaBuF0gzLw707mgsE=; b=tmk7+wFY10jFTOB9Ko3FAHrAoEIsfCMGn3XfYgI99dBVTXqEVi/13y8voc+0MyZa/uu3Np KRLLLYL0AwST/uuAfRVsYtWo1D792Nenvpfc+RMBkAtFxFGkqJYS2VEfQwgJX9mWU7HjXH kc9BtSYyKCefIUGLD45/hTSaqDSomFY= 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 00/10] mini-os: add missing PVH features Date: Mon, 6 Dec 2021 08:23:27 +0100 Message-Id: <20211206072337.9517-1-jgross@suse.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Mini-OS in PVH mode is missing some features, especially in the areas of ballooning and grant tables. With this series I am able to run Xenstore stubdom in PVH mode. Juergen Gross (10): mini-os: split e820 map handling into new source file mini-os: sort and sanitize e820 memory map mini-os: don't assume contiguous RAM when initializing in PVH mode mini-os: respect memory map when ballooning up mini-os: don't repeat definition available via header file mini-os: add memory map service functions mini-os: move x86 specific gnttab coding into arch/x86/gnttab.c mini-os: add proper pvh grant table handling mini-os: prepare grantmap entry interface for use by PVH mode mini-os: modify grant mappings to work in PVH mode Makefile | 1 + arch/arm/mm.c | 11 +- arch/x86/balloon.c | 4 +- arch/x86/gnttab.c | 109 ++++++++++++++++++ arch/x86/mm.c | 121 +------------------- arch/x86/setup.c | 8 +- balloon.c | 33 ++++-- e820.c | 269 +++++++++++++++++++++++++++++++++++++++++++++ gntmap.c | 125 +++++++++++++-------- include/balloon.h | 5 +- include/e820.h | 11 ++ include/gntmap.h | 1 + mm.c | 7 +- 13 files changed, 508 insertions(+), 197 deletions(-) create mode 100644 arch/x86/gnttab.c create mode 100644 e820.c -- 2.26.2 From minios-devel-bounces@lists.xenproject.org Mon Dec 06 07:23:47 2021 Return-path: Envelope-to: archives@lists.xenproject.org Delivery-date: Mon, 06 Dec 2021 07:23:47 +0000 Received: from list by lists.xenproject.org with outflank-mailman.238641.413610 (Exim 4.92) (envelope-from ) id 1mu8Lh-00008P-KF; Mon, 06 Dec 2021 07:23:45 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 238641.413610; 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-00004s-Ab; Mon, 06 Dec 2021 07:23:45 +0000 Received: by outflank-mailman (input) for mailman id 238641; Mon, 06 Dec 2021 07:23:44 +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 1mu8Lg-0008Mw-FH for minios-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-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-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-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: 8bit Grant table initialization for PVH requires some additional actions compared to PV mode. Add those. Signed-off-by: Juergen Gross --- 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 @@ */ #include +#include +#include #include #include #include #include +#include +#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 = e820_get_reserved_pfns(nr_grant_frames); + for ( i = 0; i < nr_grant_frames; i++ ) + { + xatp.domid = DOMID_SELF; + xatp.idx = i; + xatp.space = XENMAPSPACE_grant_table; + xatp.gpfn = pfn + i; + rc = HYPERVISOR_memory_op(XENMEM_add_to_physmap, &xatp); + if ( rc ) + { + xprintk("could not init grant table\n"); + do_exit(); + } + frames[i] = pfn + i; + } + + return map_frames(frames, nr_grant_frames); +} +#endif void arch_suspend_gnttab(grant_entry_v1_t *gnttab_table, int nr_grant_frames) { -- 2.26.2 From minios-devel-bounces@lists.xenproject.org Mon Dec 06 07:23:48 2021 Return-path: Envelope-to: archives@lists.xenproject.org Delivery-date: Mon, 06 Dec 2021 07:23:48 +0000 Received: from list by lists.xenproject.org with outflank-mailman.238644.413639 (Exim 4.92) (envelope-from ) id 1mu8Lj-0000oX-Ud; Mon, 06 Dec 2021 07:23:47 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 238644.413639; Mon, 06 Dec 2021 07:23:47 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mu8Lj-0000oK-PI; Mon, 06 Dec 2021 07:23:47 +0000 Received: by outflank-mailman (input) for mailman id 238644; Mon, 06 Dec 2021 07:23:45 +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 1mu8Lh-0008Mk-PE for minios-devel@lists.xenproject.org; Mon, 06 Dec 2021 07:23:45 +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-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-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: 8bit 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] = { [E820_PMEM] = "PMEM" }; +static void e820_remove_entry(int idx) +{ + int i; + + e820_entries--; + for ( i = idx; i < e820_entries; i++ ) + e820_map[i] = e820_map[i + 1]; +} + +static void e820_swap_entries(int idx1, int idx2) +{ + struct e820entry entry; + + entry = e820_map[idx1]; + e820_map[idx1] = e820_map[idx2]; + e820_map[idx2] = entry; +} + +static void e820_sanitize(void) +{ + int i; + unsigned long end; + + /* Adjust map entries to page boundaries. */ + for ( i = 0; i < e820_entries; i++ ) + { + end = (e820_map[i].addr + e820_map[i].size + PAGE_SIZE - 1) & PAGE_MASK; + e820_map[i].addr &= PAGE_MASK; + e820_map[i].size = end - e820_map[i].addr; + } + + /* Sort entries by start address. */ + for ( i = 0; i < e820_entries - 1; i++ ) + { + if ( e820_map[i].addr > e820_map[i + 1].addr ) + { + e820_swap_entries(i, i + 1); + i = -1; + } + } + + /* Merge adjacent entries of same type. */ + for ( i = 0; i < e820_entries - 1; i++ ) + { + if ( e820_map[i].type == e820_map[i + 1].type && + e820_map[i].addr + e820_map[i].size == e820_map[i + 1].addr ) + { + e820_map[i].size += 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 = memmap.nr_entries; + + e820_sanitize(); } void arch_print_memmap(void) -- 2.26.2 From minios-devel-bounces@lists.xenproject.org Mon Dec 06 07:23:50 2021 Return-path: Envelope-to: archives@lists.xenproject.org Delivery-date: Mon, 06 Dec 2021 07:23:50 +0000 Received: from list by lists.xenproject.org with outflank-mailman.238648.413660 (Exim 4.92) (envelope-from ) id 1mu8Lm-0001BW-0L; Mon, 06 Dec 2021 07:23:50 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 238648.413660; 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 1mu8Ll-000191-Lw; Mon, 06 Dec 2021 07:23:49 +0000 Received: by outflank-mailman (input) for mailman id 238648; Mon, 06 Dec 2021 07:23:48 +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 1mu8Lj-0008Mk-PS for minios-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-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-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-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: 8bit 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] = e820_map[i + 1]; } +static void e820_insert_entry(int idx) +{ + int i; + + if ( e820_entries == E820_MAX ) + { + xprintk("E820 memory map overflow\n"); + do_exit(); + } + + e820_entries++; + for ( i = e820_entries - 1; i > idx; i-- ) + e820_map[i] = 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 = 0, needed = (long)pages << PAGE_SHIFT; + + for ( i = 0; i < e820_entries && e820_map[i].addr < last + needed; i++ ) + last = e820_map[i].addr + e820_map[i].size; + + if ( i == 0 || e820_map[i - 1].type != E820_RESERVED ) + { + e820_insert_entry(i); + e820_map[i].addr = last; + e820_map[i].size = needed; + e820_map[i].type = E820_RESERVED; + } + else + { + e820_map[i - 1].size += needed; + } + + return last >> PAGE_SHIFT; +} + +void e820_put_reserved_pfns(unsigned long start_pfn, int pages) +{ + int i; + unsigned long addr = start_pfn << PAGE_SHIFT; + unsigned long size = (long)pages << PAGE_SHIFT; + + for ( i = 0; i < e820_entries && addr < e820_map[i].addr; i++ ); + + BUG_ON(i == e820_entries || e820_map[i].type != E820_RESERVED); + + if ( addr == e820_map[i].addr ) + { + e820_map[i].addr += size; + e820_map[i].size -= size; + if ( e820_map[i].size == 0 ) + e820_remove_entry(i); + return; + } + + if ( addr + size == e820_map[i].addr + e820_map[i].size ) + { + e820_map[i].addr = addr; + e820_map[i].size = size; + return; + } + + e820_insert_entry(i + 1); + e820_map[i + 1].addr = addr + size; + e820_map[i + 1].size = e820_map[i].addr + e820_map[i].size - + e820_map[i + 1].addr; + e820_map[i + 1].type = E820_RESERVED; + e820_map[i].size = addr - e820_map[i].addr; +} #endif 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; 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 #endif /*__E820_HEADER*/ -- 2.26.2 From minios-devel-bounces@lists.xenproject.org Mon Dec 06 07:23:50 2021 Return-path: Envelope-to: archives@lists.xenproject.org Delivery-date: Mon, 06 Dec 2021 07:23:50 +0000 Received: from list by lists.xenproject.org with outflank-mailman.238649.413661 (Exim 4.92) (envelope-from ) id 1mu8Lm-0001EM-9E; Mon, 06 Dec 2021 07:23:50 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 238649.413661; Mon, 06 Dec 2021 07:23:50 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mu8Ll-0001Br-SC; Mon, 06 Dec 2021 07:23:49 +0000 Received: by outflank-mailman (input) for mailman id 238649; Mon, 06 Dec 2021 07:23:48 +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 1mu8Lk-0008Mw-G0 for minios-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-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-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-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: 8bit 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 --- 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, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include +#include +#include +#include +#include + +grant_entry_v1_t *arch_init_gnttab(int nr_grant_frames) +{ + struct gnttab_setup_table setup; + unsigned long frames[nr_grant_frames]; + + setup.dom = DOMID_SELF; + setup.nr_frames = 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_frames) +{ +#ifdef CONFIG_PARAVIRT + int i; + + for ( i = 0; i < nr_grant_frames; i++ ) + { + HYPERVISOR_update_va_mapping((unsigned long)gnttab_table + PAGE_SIZE * i, + __pte(0x0 << PAGE_SHIFT), UVMF_INVLPG); + } +#endif + return; +} + +void arch_resume_gnttab(grant_entry_v1_t *gnttab_table, int nr_grant_frames) +{ + struct gnttab_setup_table setup; + unsigned long frames[nr_grant_frames]; +#ifdef CONFIG_PARAVIRT + int i; +#endif + + setup.dom = DOMID_SELF; + setup.nr_frames = 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 = 0; i < nr_grant_frames; i++ ) + { + HYPERVISOR_update_va_mapping((unsigned long)gnttab_table + PAGE_SIZE * 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 } -grant_entry_v1_t *arch_init_gnttab(int nr_grant_frames) -{ - struct gnttab_setup_table setup; - unsigned long frames[nr_grant_frames]; - - setup.dom = DOMID_SELF; - setup.nr_frames = 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_frames) -{ -#ifdef CONFIG_PARAVIRT - int i; - - for (i = 0; i < nr_grant_frames; i++) { - HYPERVISOR_update_va_mapping((unsigned long)(((char *)gnttab_table) + PAGE_SIZE * i), - (pte_t){0x0< Envelope-to: archives@lists.xenproject.org Delivery-date: Mon, 06 Dec 2021 07:23:52 +0000 Received: from list by lists.xenproject.org with outflank-mailman.238651.413682 (Exim 4.92) (envelope-from ) id 1mu8Lo-0001ee-DM; Mon, 06 Dec 2021 07:23:52 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 238651.413682; Mon, 06 Dec 2021 07:23:52 +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-0001cx-Mw; Mon, 06 Dec 2021 07:23:51 +0000 Received: by outflank-mailman (input) for mailman id 238651; Mon, 06 Dec 2021 07:23:49 +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 1mu8Ll-0008Mw-Fy for minios-devel@lists.xenproject.org; Mon, 06 Dec 2021 07:23:49 +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-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-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: 8bit Introduce e820.c containing all the E820 memory map handling. No functional change. Signed-off-by: Juergen Gross --- Makefile | 1 + arch/arm/mm.c | 8 ---- arch/x86/mm.c | 70 +---------------------------- e820.c | 119 +++++++++++++++++++++++++++++++++++++++++++++++++ include/e820.h | 6 +++ 5 files changed, 128 insertions(+), 76 deletions(-) create mode 100644 e820.c diff --git a/Makefile b/Makefile index 4b76b55..06b60fc 100644 --- a/Makefile +++ b/Makefile @@ -41,6 +41,7 @@ src-$(CONFIG_TPMFRONT) += tpmfront.c src-$(CONFIG_TPM_TIS) += tpm_tis.c src-$(CONFIG_TPMBACK) += tpmback.c src-y += daytime.c +src-y += e820.c src-y += events.c src-$(CONFIG_FBFRONT) += fbfront.c src-y += gntmap.c diff --git a/arch/arm/mm.c b/arch/arm/mm.c index f806c9f..9068166 100644 --- a/arch/arm/mm.c +++ b/arch/arm/mm.c @@ -7,14 +7,6 @@ #include uint32_t physical_address_offset; -struct e820entry e820_map[1] = { - { - .addr = 0, - .size = ULONG_MAX - 1, - .type = E820_RAM - } -}; -unsigned e820_entries = 1; unsigned long allocate_ondemand(unsigned long n, unsigned long alignment) { diff --git a/arch/x86/mm.c b/arch/x86/mm.c index 8ba14a5..8df93da 100644 --- a/arch/x86/mm.c +++ b/arch/x86/mm.c @@ -64,15 +64,6 @@ extern char stack[]; extern void page_walk(unsigned long va); #ifdef CONFIG_PARAVIRT -struct e820entry e820_map[1] = { - { - .addr = 0, - .size = ULONG_MAX - 1, - .type = E820_RAM - } -}; -unsigned e820_entries = 1; - void arch_mm_preinit(void *p) { start_info_t *si = p; @@ -112,25 +103,11 @@ desc_ptr idt_ptr = .base = (unsigned long)&idt, }; -struct e820entry e820_map[E820_MAX]; -unsigned e820_entries; - -static char *e820_types[E820_TYPES] = { - [E820_RAM] = "RAM", - [E820_RESERVED] = "Reserved", - [E820_ACPI] = "ACPI", - [E820_NVS] = "NVS", - [E820_UNUSABLE] = "Unusable", - [E820_PMEM] = "PMEM" -}; - void arch_mm_preinit(void *p) { long ret; domid_t domid = DOMID_SELF; - struct xen_memory_map memmap; - int i; - unsigned long pfn, max = 0; + unsigned long max; pt_base = page_table_base; first_free_pfn = PFN_UP(to_phys(&_end)); @@ -142,53 +119,10 @@ void arch_mm_preinit(void *p) } last_free_pfn = ret; - memmap.nr_entries = E820_MAX; - set_xen_guest_handle(memmap.buffer, e820_map); - ret = HYPERVISOR_memory_op(XENMEM_memory_map, &memmap); - if ( ret < 0 ) - { - xprintk("could not get memory map\n"); - do_exit(); - } - e820_entries = memmap.nr_entries; - - for ( i = 0; i < e820_entries; i++ ) - { - if ( e820_map[i].type != E820_RAM ) - continue; - pfn = (e820_map[i].addr + e820_map[i].size) >> PAGE_SHIFT; - if ( pfn > max ) - max = pfn; - } - + max = e820_get_maxpfn(); if ( max < last_free_pfn ) last_free_pfn = max; } - -void arch_print_memmap(void) -{ - int i; - unsigned long from, to; - char *type; - char buf[12]; - - printk("Memory map:\n"); - for ( i = 0; i < e820_entries; i++ ) - { - if ( e820_map[i].type >= E820_TYPES || !e820_types[e820_map[i].type] ) - { - snprintf(buf, sizeof(buf), "%8x", e820_map[i].type); - type = buf; - } - else - { - type = e820_types[e820_map[i].type]; - } - from = e820_map[i].addr; - to = from + e820_map[i].size - 1; - printk("%012lx-%012lx: %s\n", from, to, type); - } -} #endif /* diff --git a/e820.c b/e820.c new file mode 100644 index 0000000..2165280 --- /dev/null +++ b/e820.c @@ -0,0 +1,119 @@ +/* -*- Mode:C; c-basic-offset:4; tab-width:4 -*- + * + * (C) 2021 - Juergen Gross, SUSE Software Solutions Germany GmbH + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include +#include +#include +#include +#include +#include +#include + +#ifdef CONFIG_E820_TRIVIAL +struct e820entry e820_map[1] = { + { + .addr = 0, + .size = ULONG_MAX - 1, + .type = E820_RAM + } +}; + +unsigned e820_entries = 1; + +static void e820_get_memmap(void) +{ +} + +#else +struct e820entry e820_map[E820_MAX]; +unsigned e820_entries; + +static char *e820_types[E820_TYPES] = { + [E820_RAM] = "RAM", + [E820_RESERVED] = "Reserved", + [E820_ACPI] = "ACPI", + [E820_NVS] = "NVS", + [E820_UNUSABLE] = "Unusable", + [E820_PMEM] = "PMEM" +}; + +static void e820_get_memmap(void) +{ + long ret; + struct xen_memory_map memmap; + + memmap.nr_entries = E820_MAX; + set_xen_guest_handle(memmap.buffer, e820_map); + ret = HYPERVISOR_memory_op(XENMEM_memory_map, &memmap); + if ( ret < 0 ) + { + xprintk("could not get memory map\n"); + do_exit(); + } + e820_entries = memmap.nr_entries; +} + +void arch_print_memmap(void) +{ + int i; + unsigned long from, to; + char *type; + char buf[12]; + + printk("Memory map:\n"); + for ( i = 0; i < e820_entries; i++ ) + { + if ( e820_map[i].type >= E820_TYPES || !e820_types[e820_map[i].type] ) + { + snprintf(buf, sizeof(buf), "%8x", e820_map[i].type); + type = buf; + } + else + { + type = e820_types[e820_map[i].type]; + } + from = e820_map[i].addr; + to = from + e820_map[i].size - 1; + printk("%012lx-%012lx: %s\n", from, to, type); + } +} +#endif + +unsigned long e820_get_maxpfn(void) +{ + int i; + unsigned long pfn, max = 0; + + e820_get_memmap(); + + for ( i = 0; i < e820_entries; i++ ) + { + if ( e820_map[i].type != E820_RAM ) + continue; + pfn = (e820_map[i].addr + e820_map[i].size) >> PAGE_SHIFT; + if ( pfn > max ) + max = pfn; + } + + return max; +} diff --git a/include/e820.h b/include/e820.h index 920551c..af2129f 100644 --- a/include/e820.h +++ b/include/e820.h @@ -24,6 +24,10 @@ #ifndef __E820_HEADER #define __E820_HEADER +#if defined(__arm__) || defined(__aarch64__) || defined(CONFIG_PARAVIRT) +#define CONFIG_E820_TRIVIAL +#endif + /* PC BIOS standard E820 types and structure. */ #define E820_RAM 1 #define E820_RESERVED 2 @@ -45,4 +49,6 @@ struct __packed e820entry { extern struct e820entry e820_map[]; extern unsigned e820_entries; +unsigned long e820_get_maxpfn(void); + #endif /*__E820_HEADER*/ -- 2.26.2 From minios-devel-bounces@lists.xenproject.org Mon Dec 06 07:23:55 2021 Return-path: Envelope-to: archives@lists.xenproject.org Delivery-date: Mon, 06 Dec 2021 07:23:55 +0000 Received: from list by lists.xenproject.org with outflank-mailman.238654.413707 (Exim 4.92) (envelope-from ) id 1mu8Lr-0002EI-F6; Mon, 06 Dec 2021 07:23:55 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 238654.413707; 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 1mu8Lq-0002CH-JR; Mon, 06 Dec 2021 07:23:54 +0000 Received: by outflank-mailman (input) for mailman id 238654; Mon, 06 Dec 2021 07:23:51 +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 1mu8Lm-0008Mk-Pt for minios-devel@lists.xenproject.org; Mon, 06 Dec 2021 07:23:50 +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-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-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: 8bit 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 --- 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 { }; static inline int -gntmap_entry_used(struct gntmap_entry *entry) +gntmap_entry_used(struct gntmap *map, int idx) { - return entry->host_addr != 0; + return map->entries[idx].host_addr != 0; } -static struct gntmap_entry* -gntmap_find_free_entry(struct gntmap *map) +static int gntmap_find_free_entry(struct gntmap *map) { int i; for (i = 0; i < map->nentries; i++) { - if (!gntmap_entry_used(&map->entries[i])) - return &map->entries[i]; + if (!gntmap_entry_used(map, i)) + return i; } DEBUG("(map=%p): all %d entries full", map, map->nentries); - return NULL; + return -1; } -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; for (i = 0; i < map->nentries; i++) { if (map->entries[i].host_addr == addr) - return &map->entries[i]; + return i; } - return NULL; + return -1; } int @@ -105,12 +103,13 @@ gntmap_set_max_grants(struct gntmap *map, int count) } static int -_gntmap_map_grant_ref(struct gntmap_entry *entry, +_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 = map->entries + idx; struct gnttab_map_grant_ref op; int rc; @@ -135,8 +134,9 @@ _gntmap_map_grant_ref(struct gntmap_entry *entry, } static int -_gntmap_unmap_grant_ref(struct gntmap_entry *entry) +_gntmap_unmap_grant_ref(struct gntmap *map, int idx) { + struct gntmap_entry *entry = map->entries + idx; struct gnttab_unmap_grant_ref op; int rc; @@ -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; DEBUG("(map=%p, start_address=%lx, count=%d)", map, start_address, count); for (i = 0; i < count; i++) { - ent = gntmap_find_entry(map, start_address + PAGE_SIZE * i); - if (ent == NULL) { + idx = gntmap_find_entry(map, start_address + PAGE_SIZE * i); + if (idx < 0) { printk("gntmap: tried to munmap unknown page\n"); return -EINVAL; } - rc = _gntmap_unmap_grant_ref(ent); + rc = _gntmap_unmap_grant_ref(map, idx); if (rc != 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; DEBUG("(map=%p, count=%" PRIu32 ", " @@ -206,9 +206,9 @@ gntmap_map_grant_refs(struct gntmap *map, return NULL; for (i = 0; i < count; i++) { - ent = gntmap_find_free_entry(map); - if (ent == NULL || - _gntmap_map_grant_ref(ent, + idx = 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; DEBUG("(map=%p)", map); for (i = 0; i < map->nentries; i++) { - ent = &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); } xfree(map->entries); -- 2.26.2 From minios-devel-bounces@lists.xenproject.org Mon Dec 06 07:23:57 2021 Return-path: Envelope-to: archives@lists.xenproject.org Delivery-date: Mon, 06 Dec 2021 07:23:57 +0000 Received: from list by lists.xenproject.org with outflank-mailman.238656.413718 (Exim 4.92) (envelope-from ) id 1mu8Lt-0002ZM-9C; Mon, 06 Dec 2021 07:23:57 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 238656.413718; Mon, 06 Dec 2021 07:23: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 1mu8Ls-0002WB-64; Mon, 06 Dec 2021 07:23:56 +0000 Received: by outflank-mailman (input) for mailman id 238656; Mon, 06 Dec 2021 07:23:52 +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 1mu8Lo-0008Mw-Gc for minios-devel@lists.xenproject.org; Mon, 06 Dec 2021 07:23:52 +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-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-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: 8bit 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 @@ -70,6 +71,8 @@ void arch_init_mm(unsigned long *start_pfn_p, unsigned long *max_pfn_p) } device_tree = new_device_tree; *max_pfn_p = to_phys(new_device_tree) >> PAGE_SHIFT; + + balloon_set_nr_pages(*max_pfn_p, *max_pfn_p); } 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); - if ( p2m_pages(nr_max_pages) <= p2m_pages(max_pfn) ) + if ( p2m_pages(nr_max_pfn) <= p2m_pages(max_pfn) ) return; - new_p2m = alloc_virt_kernel(p2m_pages(nr_max_pages)); + new_p2m = alloc_virt_kernel(p2m_pages(nr_max_pfn)); for ( pfn = 0; pfn < max_pfn; pfn += 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 = (pgentry_t *)si->pt_base; first_free_pfn = PFN_UP(to_phys(pt_base)) + si->nr_pt_frames; last_free_pfn = 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) } last_free_pfn = e820_get_maxpfn(ret); + balloon_set_nr_pages(ret, last_free_pfn); } #endif diff --git a/balloon.c b/balloon.c index 5676d3b..80d89c7 100644 --- a/balloon.c +++ b/balloon.c @@ -23,14 +23,24 @@ #include #include +#include #include #include #include #include #include -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 = pages; + nr_mem_pfn = pfn; +} void get_max_pages(void) { @@ -46,16 +56,18 @@ void get_max_pages(void) nr_max_pages = ret; printk("Maximum memory size: %ld pages\n", nr_max_pages); + + nr_max_pfn = e820_get_maxpfn(nr_max_pages); } void mm_alloc_bitmap_remap(void) { unsigned long i, new_bitmap; - if ( mm_alloc_bitmap_size >= ((nr_max_pages + 1) >> 3) ) + if ( mm_alloc_bitmap_size >= ((nr_max_pfn + 1) >> 3) ) return; - new_bitmap = alloc_virt_kernel(PFN_UP((nr_max_pages + 1) >> 3)); + new_bitmap = alloc_virt_kernel(PFN_UP((nr_max_pfn + 1) >> 3)); for ( i = 0; i < mm_alloc_bitmap_size; i += PAGE_SIZE ) { map_frame_rw(new_bitmap + i, @@ -70,7 +82,7 @@ static unsigned long balloon_frames[N_BALLOON_FRAMES]; int balloon_up(unsigned long n_pages) { - unsigned long page, pfn; + unsigned long page, pfn, start_pfn; int rc; struct xen_memory_reservation reservation = { .domid = DOMID_SELF @@ -81,8 +93,11 @@ int balloon_up(unsigned long n_pages) if ( n_pages > N_BALLOON_FRAMES ) n_pages = N_BALLOON_FRAMES; + start_pfn = e820_get_maxpfn(nr_mem_pages + 1) - 1; + n_pages = 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 = alloc_page(); if ( !page ) @@ -99,14 +114,14 @@ int balloon_up(unsigned long n_pages) mm_alloc_bitmap_size += PAGE_SIZE; } - rc = arch_expand_p2m(nr_mem_pages + n_pages); + rc = arch_expand_p2m(start_pfn + n_pages); if ( rc ) return rc; /* Get new memory from hypervisor. */ for ( pfn = 0; pfn < n_pages; pfn++ ) { - balloon_frames[pfn] = nr_mem_pages + pfn; + balloon_frames[pfn] = start_pfn + pfn; } set_xen_guest_handle(reservation.extent_start, balloon_frames); reservation.nr_extents = n_pages; @@ -116,7 +131,7 @@ int balloon_up(unsigned long n_pages) for ( pfn = 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)); } 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 = 0; - e820_get_memmap(); + if ( !e820_entries ) + e820_get_memmap(); for ( i = 0; i < e820_entries; i++ ) { @@ -176,3 +177,21 @@ unsigned long e820_get_maxpfn(unsigned long pages) return max; } + +unsigned long e820_get_max_pages(unsigned long pfn, unsigned long pages) +{ + int i; + unsigned long end; + + for ( i = 0; i < e820_entries; i++ ) + { + if ( e820_map[i].type != E820_RAM || + (e820_map[i].addr >> PAGE_SHIFT) > pfn ) + continue; + + end = (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 -extern unsigned long nr_max_pages; -extern unsigned long nr_mem_pages; +extern unsigned long nr_max_pfn; void get_max_pages(void); int balloon_up(unsigned long n_pages); +void balloon_set_nr_pages(unsigned long pages, unsigned long pfn); 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 <= nr_free_pages; } +static inline balloon_set_nr_pages(unsigned long pages, unsigned long pfn) { } #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; unsigned long e820_get_maxpfn(unsigned long pages); +unsigned long e820_get_max_pages(unsigned long pfn, unsigned long pages); #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) printk("MM: Init\n"); - 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); arch_init_demand_mapping_area(); - -#ifdef CONFIG_BALLOON - nr_mem_pages = max_pfn; -#endif } void fini_mm(void) -- 2.26.2 From minios-devel-bounces@lists.xenproject.org Mon Dec 06 07:27:57 2021 Return-path: Envelope-to: archives@lists.xenproject.org Delivery-date: Mon, 06 Dec 2021 07:27:57 +0000 Received: from list by lists.xenproject.org with outflank-mailman.238686.413757 (Exim 4.92) (envelope-from ) id 1mu8Pl-0007Ol-8e; Mon, 06 Dec 2021 07:27:57 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 238686.413757; Mon, 06 Dec 2021 07:27:57 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mu8Pl-0007NW-28; Mon, 06 Dec 2021 07:27:57 +0000 Received: by outflank-mailman (input) for mailman id 238686; 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 1mu8Lo-0008Mk-QF for minios-devel@lists.xenproject.org; Mon, 06 Dec 2021 07:23:52 +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-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-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: 8bit 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 --- 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 @@ #include #include +#include #include #include #include @@ -97,11 +98,42 @@ gntmap_set_max_grants(struct gntmap *map, int count) if (map->entries == NULL) return -ENOMEM; +#ifndef CONFIG_PARAVIRT + map->start_pfn = e820_get_reserved_pfns(count); +#endif + memset(map->entries, 0, sizeof(struct gntmap_entry) * count); map->nentries = count; return 0; } +static int +_gntmap_unmap_grant_ref(struct gntmap *map, int idx) +{ + struct gntmap_entry *entry = map->entries + idx; + struct gnttab_unmap_grant_ref op; + int rc; + +#ifdef CONFIG_PARAVIRT + op.host_addr = (uint64_t) entry->host_addr; +#else + op.host_addr = (uint64_t)(map->start_pfn + idx) << PAGE_SHIFT; +#endif + op.dev_bus_addr = 0; + op.handle = entry->handle; + + rc = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1); + if (rc != 0 || op.status != GNTST_okay) { + printk("GNTTABOP_unmap_grant_ref failed: " + "returned %d, status %" PRId16 "\n", + rc, op.status); + return rc != 0 ? rc : op.status; + } + + entry->host_addr = 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 = map->entries + idx; struct gnttab_map_grant_ref op; int rc; +#ifndef CONFIG_PARAVIRT + unsigned long pfn = map->start_pfn + idx; +#endif op.ref = (grant_ref_t) ref; op.dom = (domid_t) domid; +#ifdef CONFIG_PARAVIRT op.host_addr = (uint64_t) host_addr; +#else + op.host_addr = (uint64_t)pfn << PAGE_SHIFT; +#endif op.flags = GNTMAP_host_map; if (!writable) op.flags |= GNTMAP_readonly; @@ -128,31 +167,18 @@ _gntmap_map_grant_ref(struct gntmap *map, int idx, return rc != 0 ? rc : op.status; } - entry->host_addr = host_addr; - entry->handle = op.handle; - return 0; -} - -static int -_gntmap_unmap_grant_ref(struct gntmap *map, int idx) -{ - struct gntmap_entry *entry = map->entries + idx; - struct gnttab_unmap_grant_ref op; - int rc; - - op.host_addr = (uint64_t) entry->host_addr; - op.dev_bus_addr = 0; - op.handle = entry->handle; - - rc = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1); - if (rc != 0 || op.status != GNTST_okay) { - printk("GNTTABOP_unmap_grant_ref failed: " - "returned %d, status %" PRId16 "\n", - rc, op.status); - return rc != 0 ? rc : op.status; +#ifndef CONFIG_PARAVIRT + rc = 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 - entry->host_addr = 0; + entry->host_addr = host_addr; + entry->handle = op.handle; return 0; } @@ -165,6 +191,10 @@ gntmap_munmap(struct gntmap *map, unsigned long start_address, int count) DEBUG("(map=%p, start_address=%lx, count=%d)", map, start_address, count); +#ifndef CONFIG_PARAVIRT + unmap_frames(start_address, count); +#endif + for (i = 0; i < count; i++) { idx = 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); } +#ifndef CONFIG_PARAVIRT + e820_put_reserved_pfns(map->start_pfn, map->nentries); + map->start_pfn = 0; +#endif + xfree(map->entries); map->entries = NULL; map->nentries = 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; }; int -- 2.26.2 From minios-devel-bounces@lists.xenproject.org Mon Dec 06 12:46:23 2021 Return-path: Envelope-to: archives@lists.xenproject.org Delivery-date: Mon, 06 Dec 2021 12:46:23 +0000 Received: from list by lists.xenproject.org with outflank-mailman.238845.413924 (Exim 4.92) (envelope-from ) id 1muDNs-0008Km-9S; Mon, 06 Dec 2021 12:46:20 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 238845.413924; 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 1muDNs-0008KI-5A; Mon, 06 Dec 2021 12:46:20 +0000 Received: by outflank-mailman (input) for mailman id 238845; 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-Ss for minios-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-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-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: 8bit 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); static struct xencons_interface *console_ring; -uint32_t console_evtchn; +uint32_t console_evtchn = ~0; static struct consfront_dev* resume_xen_console(struct consfront_dev* dev); @@ -55,7 +55,7 @@ static inline void notify_daemon(struct consfront_dev *dev) static inline struct xencons_interface *xencons_interface(void) { - return console_evtchn ? console_ring : NULL; + return (console_evtchn != ~0) ? console_ring : NULL; } int xencons_ring_send_no_notify(struct consfront_dev *dev, const char *data, unsigned len) @@ -181,7 +181,7 @@ struct consfront_dev *xencons_ring_init(void) { struct consfront_dev *dev; - if (!console_evtchn) + if (console_evtchn != ~0) return 0; dev = malloc(sizeof(struct consfront_dev)); -- 2.26.2 From minios-devel-bounces@lists.xenproject.org Mon Dec 06 13:24:43 2021 Return-path: Envelope-to: archives@lists.xenproject.org Delivery-date: Mon, 06 Dec 2021 13:24:43 +0000 Received: from list by lists.xenproject.org with outflank-mailman.238892.414019 (Exim 4.92) (envelope-from ) id 1muDz0-00082R-KK; Mon, 06 Dec 2021 13:24:42 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 238892.414019; Mon, 06 Dec 2021 13:24:42 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1muDz0-00082K-HH; Mon, 06 Dec 2021 13:24:42 +0000 Received: by outflank-mailman (input) for mailman id 238892; Mon, 06 Dec 2021 13:24:41 +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 1muDyz-000827-8A for minios-devel@lists.xenproject.org; Mon, 06 Dec 2021 13:24:41 +0000 Received: from de-smtp-delivery-102.mimecast.com (de-smtp-delivery-102.mimecast.com [194.104.109.102]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id dd995ff2-5697-11ec-a5e1-b9374ead2679; Mon, 06 Dec 2021 14:24:40 +0100 (CET) Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04lp2059.outbound.protection.outlook.com [104.47.14.59]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id de-mta-5-g_DZWoWMN5GqEvmL3CQEpQ-1; Mon, 06 Dec 2021 14:24:38 +0100 Received: from VI1PR04MB5600.eurprd04.prod.outlook.com (2603:10a6:803:e7::16) by VI1PR04MB6176.eurprd04.prod.outlook.com (2603:10a6:803:f6::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.21; Mon, 6 Dec 2021 13:24:36 +0000 Received: from VI1PR04MB5600.eurprd04.prod.outlook.com ([fe80::5951:a489:1cf0:19fe]) by VI1PR04MB5600.eurprd04.prod.outlook.com ([fe80::5951:a489:1cf0:19fe%6]) with mapi id 15.20.4755.021; Mon, 6 Dec 2021 13:24:36 +0000 Received: from [10.156.60.236] (37.24.206.209) by AM6PR0202CA0047.eurprd02.prod.outlook.com (2603:10a6:20b:3a::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.11 via Frontend Transport; Mon, 6 Dec 2021 13:24:35 +0000 X-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-devel" X-Inumbo-ID: dd995ff2-5697-11ec-a5e1-b9374ead2679 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1638797079; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Wz5reFBIoDMHY6Wx6KZn6tzgyF4Qv4/Rr22OybwzF7k=; b=BlLaYDp9vNfYkTO9S8ImKADA/qKz6P0oO9tn0j0wDrcXwlFAHhWDnxf/SL+w6+DYJxzAJ5 obPPYswB9By5kiYoIffJ45QqAtUXdaQ8XjNH3tTM/tnb+0LD7WwFyXiN5nJhTKgfx34FAC 6H97ySInhqbEK1khFagZTBLOyQJDscg= X-MC-Unique: g_DZWoWMN5GqEvmL3CQEpQ-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=I2AGsXfHiYimp6XepQVG32upadsAedynS3GgX85EDl9qQssPGT2y06zMOxVDFbKo9GbTwZJSPriUfOV3rBY2Bc5FNC51TUMLtEiFJqhoLOGeu84QGs/y7bXVy99xqhn9lU2SLLkXwyo06LsCJ8dgXB9Jq744/JZbAnpsz7AFV1PsR9YbJ+aivsHWFlSZpbe2kay+F+Fchd5K2xLfZa4fbxIiQ9him5u6ea4n/cfSydCFE5D0RKQtY59GPrucfKKlVh8aFPsiFjzNY24B7HnZssQw9PnQZUtk73CqiH6/NSYLBECMeymk9w7Qks3LARn/2O9MJUqAeprzdKr3qYM1HA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Wz5reFBIoDMHY6Wx6KZn6tzgyF4Qv4/Rr22OybwzF7k=; b=C1J32GxekkMnO1PGdnCnpBaF+Z0u06F7AnlN7UWD1QBZgY8LyGbErwiwX6CETVAM/sIf5m1q9rH9WXKK27m015lr4Z679J4n/ZQHcfqJfP5DJY96DKUvkr9SuMpUKtGkGIoYXofbGjmi/Im8Ek2CgdL97Kt+/AT9IS9YWbs3Dof9lP0nI/kExN3BCZALkgIWxxRneOoYth0wDB6i6qqq+riNtQ/CUu4FoHni6kwjjuXmD2evVH/3NckC94ehbYU9VEDoCT2/XjJ4rpfLR0xUDbG61qrdEideYyU5PH/U0MGZKxLsvQEUCaHbSKeDr+OO6/8A0dsUgxTfCyTS8iIhog== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: <39a4ae01-7ea9-7526-74da-1fea71274890@suse.com> Date: Mon, 6 Dec 2021 14:24:34 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.3.2 Subject: Re: [PATCH] mini-os: support event channel 0 for console Content-Language: en-US To: Juergen Gross Cc: samuel.thibault@ens-lyon.org, wl@xen.org, minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org References: <20211206072337.9517-1-jgross@suse.com> <20211206124612.24758-1-jgross@suse.com> From: Jan Beulich In-Reply-To: <20211206124612.24758-1-jgross@suse.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-ClientProxiedBy: AM6PR0202CA0047.eurprd02.prod.outlook.com (2603:10a6:20b:3a::24) To VI1PR04MB5600.eurprd04.prod.outlook.com (2603:10a6:803:e7::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2b62ed72-d34c-449b-2600-08d9b8bbbf6a X-MS-TrafficTypeDiagnostic: VI1PR04MB6176:EE_ X-LD-Processed: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba,ExtFwd X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /9pXj7xd3e+s/St+4XHNv+M4rgmPepHF56SQnqOBiAiJrYsxQtgSuyG7sIxS5gszsK0JjPfzkrgbDyZSrpAo5gxGAlmAlJ6lOxb8sjF82UXGafwoa+etNeMm/TI0lbx8X95EueTMrifpU1ewBzSs/Ub81ZhtcrJhNONhMakfy7xhmz1DdX41KlAYf8PaR2BEDSC0hTseURGYbabg0ENeq+Fbs5MP7XjHSUl4Y1/bUDyxYTAdr+x2LTi/+cpcAdCUBEzB1JA7Ojfn5oEpHii4m3SQwzjdF5bN1Oy2tm/Xhygt6VHp8/5RO69QqR3u3qDCdddDJg90IwScPIzWsRkuXL4dxsfKw05Ef6Cims/KZMDvY2LrW6jEOSZEVWR4W8AgN1POzJwSjcEMo4d7CRkarF+mXovRGaSbsaICCtKwE/8Uaa56yXxVdChXJTl+6jklcbhwRbhmO3oxvkz4aM3MmJV3gS4eRxwvl3Ojd3jah9z0Gx1b0CxY6lI2pYtVHJ/NlzOU639r6nY78d66l9u5j/dU/HYyx7lXPlhsIh89dggUysC+w2OnGZRAgFDp1VFJ0ph8hnei6SBK242RuFARmhUAz2CB0T5w5gaY+iYwxlQJoWs7FOd0gBaGYdPkqght5JcVHVNCt/k+rC4cZjLfwndsC+Km2lHxkvhXEfupYpqotjO61TMbaVhyNjjEagk+ONR0qUmS2whunv8zRo7K2+w8zuG1f1GyMtloaIzuTUi4DvCfrnWH4NbjlPyc5a8e X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR04MB5600.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(366004)(956004)(558084003)(86362001)(6636002)(6486002)(31686004)(508600001)(66556008)(2616005)(6862004)(38100700002)(66946007)(4326008)(66476007)(31696002)(8676002)(186003)(316002)(37006003)(16576012)(2906002)(26005)(5660300002)(36756003)(53546011)(8936002)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?UnYvVmJ0R0lOYS9Jb2J4RGdYSWd2amk5QVI5bHBaVE5Rcjl3djRNTzhmbllr?= =?utf-8?B?REJJWlAzZE5uSFNGRHBNUnltWXhYUnlNcjRiUVd5OGVyL1ZucXBPOGpLKysy?= =?utf-8?B?YjBwOGNPWjBRcmcxajF2eW1SM2YrSFFzWnQwSWlrMGs3bWZJL1NmVjRaTWxy?= =?utf-8?B?RzVId2NDY3p1MUZpT1VLOXlRS0dYNVRSTXA5WEIrNmFrZ2UzSm16azhpNHds?= =?utf-8?B?Z3dsTE5RL2VxUVVRMCtqcCszV3ZpWUVXeVZpK0IwRTJvOUExeGVmNDdsQnlw?= =?utf-8?B?M0Mzd3RrM1JDdjkrc2tqZlEzYlMvTWJuVzI2Rkl3NHJLQkFDTW5uVWhQL0Vm?= =?utf-8?B?OTlGY1FucUp6WDNiTEZjdVl4OHc1dGFueGZ1clVteGF2OFlWQnRGVllXaUJy?= =?utf-8?B?RWNaL0tZWTd4QkgxeGs4VkdGTS9vOGV6Y1VUSVkxMjhaTlI1bTEwS1lBdnZh?= =?utf-8?B?azd3OEY4cm5WWFRNYkpGWVVFTTlTODFaNkhoSkJZTWU0OUxmQ29XNUtaSm1F?= =?utf-8?B?b2duTlZiUHJXQzd3QXRaaEdzSHkwbTI3aUlScGZCRVJPa3g0elVXV1NLYlNP?= =?utf-8?B?RmdHNGlVNkJIWEhpS0gvUUhJN0czcDVqaHRQSFNobktCdGJ5eU5qVElKa3J0?= =?utf-8?B?L293aWptenovdE9mTlBocHhWcmRxQWZoNXpSZkxHNlplOENMMzBkZk9rQ0Ra?= =?utf-8?B?WE9Ldk1ubE9tZFh5cXJuRUpDU1RRUnlUNGg0VUZTWHBsM2IwWWlwUmgrVUZC?= =?utf-8?B?b0RES3NXb2tiN0xsNU9UUjlOdWZiVkE1NFRTcnN5UCs0dTBLYkRJanpidmpE?= =?utf-8?B?RGZxUnFuT1phRUk3UCsycklUY3JMWkcvSkU1VmNrbjdmMmc1ektOSmNFNkUw?= =?utf-8?B?SUxwVUtRc3FmUmJ0d0dOZlFXK3VUOUthUlIzWjZkQjI2bnpQaEZrL2s5NWM5?= =?utf-8?B?ZWNUSEFVRFdmRUZTc25NdWVtVDNxeWNmRStuVnJ1WktIRGZ0Z0h1TWVRSUly?= =?utf-8?B?Qm1PMDdPQ1lEdmwvUVhkNnh2Nm9sSDlmUnhIK01QOWEyMERIMURqN3d6WHJN?= =?utf-8?B?dGJNWFdtbFo2aDlxZGJrdCtSTDA5L3VnZ09ydGc2cXFJZ1dTa1E5VUN5QzVp?= =?utf-8?B?VDBSWnh2OEhaRXZLRjYwVjdxRktHMDJ1Y3RzQVh4eFFLNmYvdmVXQWY4bTdp?= =?utf-8?B?eDgwdlZLWDl3WThGSWNXcXorRThnM3Q1OHVmVkVVcjNNRUFkT3BvSllSdENw?= =?utf-8?B?OFhzdVgybjFpZEhpeUdLR2pVR2cwZ0M0QzgvTmUwTUNUcmk0L0FzdlJueW41?= =?utf-8?B?L3U2dTZ6eS9OQlN1MVYwbmFSN3BaUE1pSWpsSHJwM0kvN3U2T3BtMktNeGdZ?= =?utf-8?B?OEI4Q2cwWTBVTFpqSjdMcWkzcENPTmJVSkxqeUo3YXV6QWZDSVYxVDBNdDRx?= =?utf-8?B?ZnBQSWw3V0t4d0k0Vm8zYzFvVG4xUE0zT3JuZkJPZ3FJSFVJL3V4bWdXQ1BZ?= =?utf-8?B?blBoRHdkOExWQk42T1V4cUZ1WXlJcTVMalB4dWhhS1R3dFQrT05TelI4SGRz?= =?utf-8?B?SlExekFRU0NyMTZHdWZJamJEdzduK0pZQ3EvZUU5NHdkMFhRQlpwQkU3R1pH?= =?utf-8?B?amRqTmJnckcwc0NqcWxQK0tzbUZPZnZOYlNIL3NOQWRZbDFWK3o5WnI5V2JZ?= =?utf-8?B?elY5SjZtN0ZuTVp5U01sbWU4Y0FLUTRGWUNVREZlc0ZSR1VPQkorQm14WWhk?= =?utf-8?B?djN1SjI0TW91TEVrQ1d0SmZlTlJ0UFZERUdMWUJLTTU2U2dZd3M5Y0IybkQr?= =?utf-8?B?YnlabnZYUnlRdzlEL2JDWjlVemhGMGxnbnVMWGw1aGFTSEJwM21LRmdKYW9a?= =?utf-8?B?M24xR1pwN3dMN3ZXU0tVbmMzMllCV29kNFdkSS92U2VXWHE5VVlyUXJsUzAx?= =?utf-8?B?ZE12czhWMlBHa21veTMvQzZWMW5IMWtLVFU0YU9UemhSaGRhM2ljTUZ5dVFn?= =?utf-8?B?VzRlNGs4N045b21kcGlDa2VTVC9jZGNIcnJ6dHhlemVHbS9xVEJRaGlvaU5R?= =?utf-8?B?b1dJenhmK1IvU0hGVDllR0JuOVhnaWt5ZUVFUUhCNUNpa3NKY2I3Nnh2d1N1?= =?utf-8?B?Z20zWHFOdU9lS1N2aUxtUDAzSGtRa00xWXJQeGtJSHVSdWF5RDQyUUJ6eHJV?= =?utf-8?Q?T9pqZ6HvRbHPhlWgc0Zd1ME=3D?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2b62ed72-d34c-449b-2600-08d9b8bbbf6a X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5600.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Dec 2021 13:24:36.1514 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: QA2ZKKsLHFGecx1rAEH3Jtz2mrlGPa1mzNaXifp79f2xAd3tCJHikA9hLHizlKbFcpvLqjeF1iEKJz+yyfZYLg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB6176 On 06.12.2021 13:46, Juergen Gross wrote: > The console event channel might be 0 for the console, so use the value > of ~0 as invalid instead. I may be missing something mini-os specific here, but in Xen channel 0 is always invalid. It's not just here that this value would be used as a sentinel. Jan From minios-devel-bounces@lists.xenproject.org Mon Dec 06 13:30:22 2021 Return-path: Envelope-to: archives@lists.xenproject.org Delivery-date: Mon, 06 Dec 2021 13:30:22 +0000 Received: from list by lists.xenproject.org with outflank-mailman.238916.414077 (Exim 4.92) (envelope-from ) id 1muE4U-0003Dn-I3; Mon, 06 Dec 2021 13:30:22 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 238916.414077; Mon, 06 Dec 2021 13:30:22 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1muE4U-0003Dg-Ez; Mon, 06 Dec 2021 13:30:22 +0000 Received: by outflank-mailman (input) for mailman id 238916; Mon, 06 Dec 2021 13:30:21 +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 1muE4S-0002vN-UG for minios-devel@lists.xenproject.org; Mon, 06 Dec 2021 13:30:21 +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 a7af0572-5698-11ec-8a4d-196798b21f7b; Mon, 06 Dec 2021 14:30:19 +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 AFF9921138; Mon, 6 Dec 2021 13:30:18 +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 79B1D13BAE; Mon, 6 Dec 2021 13:30:18 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id qh0KHGoQrmFAIAAAMHmgww (envelope-from ); Mon, 06 Dec 2021 13:30:18 +0000 X-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-devel" X-Inumbo-ID: a7af0572-5698-11ec-8a4d-196798b21f7b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1638797418; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=rjH3GlR6qZT+gmpjB2DhmHifnrM7sEnhkVMQpV3UbrE=; b=gS6adLdFpQXfcIb97KxYBNFuK2u8R+zBKWC7a2XW9CMfeRrykQBu3V2raxnNFjdw1EFmoK +lECzyB3BGaNGHJawdRoplBik6ZGfVN3Q72zf6MxbskPRpEYoPP8PaxdDB+9rlbWocvNRp svgM+2KCXB2kAWQMkQQ4e8MPeIP55qM= Subject: Re: [PATCH] mini-os: support event channel 0 for console To: Jan Beulich Cc: samuel.thibault@ens-lyon.org, wl@xen.org, minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org References: <20211206072337.9517-1-jgross@suse.com> <20211206124612.24758-1-jgross@suse.com> <39a4ae01-7ea9-7526-74da-1fea71274890@suse.com> From: Juergen Gross Message-ID: Date: Mon, 6 Dec 2021 14:30:17 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: <39a4ae01-7ea9-7526-74da-1fea71274890@suse.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="0yj4b187kHHxs2gYxzlqTiOSZhnZSWTHm" This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --0yj4b187kHHxs2gYxzlqTiOSZhnZSWTHm Content-Type: multipart/mixed; boundary="Ppp2vYvGThO8wQQ2EBYyUaL68OiVZg9IC"; protected-headers="v1" From: Juergen Gross To: Jan Beulich Cc: samuel.thibault@ens-lyon.org, wl@xen.org, minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org Message-ID: Subject: Re: [PATCH] mini-os: support event channel 0 for console References: <20211206072337.9517-1-jgross@suse.com> <20211206124612.24758-1-jgross@suse.com> <39a4ae01-7ea9-7526-74da-1fea71274890@suse.com> In-Reply-To: <39a4ae01-7ea9-7526-74da-1fea71274890@suse.com> --Ppp2vYvGThO8wQQ2EBYyUaL68OiVZg9IC Content-Type: multipart/mixed; boundary="------------2BC56277A4C35AB15AE644E2" Content-Language: en-US This is a multi-part message in MIME format. --------------2BC56277A4C35AB15AE644E2 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable On 06.12.21 14:24, Jan Beulich wrote: > On 06.12.2021 13:46, Juergen Gross wrote: >> The console event channel might be 0 for the console, so use the value= >> of ~0 as invalid instead. >=20 > I may be missing something mini-os specific here, but in Xen channel 0 > is always invalid. It's not just here that this value would be used as > a sentinel. Maybe this is a special case for Xenstore stubdom. Without this change I can't connect to the console when the system is up, with this patch it is possible. Juergen --------------2BC56277A4C35AB15AE644E2 Content-Type: application/pgp-keys; name="OpenPGP_0xB0DE9DD628BF132F.asc" Content-Transfer-Encoding: quoted-printable Content-Description: OpenPGP public key Content-Disposition: attachment; filename="OpenPGP_0xB0DE9DD628BF132F.asc" -----BEGIN PGP PUBLIC KEY BLOCK----- xsBNBFOMcBYBCACgGjqjoGvbEouQZw/ToiBg9W98AlM2QHV+iNHsEs7kxWhKMjrioyspZKOBy= cWx w3ie3j9uvg9EOB3aN4xiTv4qbnGiTr3oJhkB1gsb6ToJQZ8uxGq2kaV2KL9650I1SJvedYm8O= f8Z d621lSmoKOwlNClALZNew72NjJLEzTalU1OdT7/i1TXkH09XSSI8mEQ/ouNcMvIJNwQpd369y= 9bf IhWUiVXEK7MlRgUG6MvIj6Y3Am/BBLUVbDa4+gmzDC9ezlZkTZG2t14zWPvxXP3FAp2pkW0xq= G7/ 377qptDmrk42GlSKN4z76ELnLxussxc7I2hx18NUcbP8+uty4bMxABEBAAHNHEp1ZXJnZW4gR= 3Jv c3MgPGpnQHBmdXBmLm5ldD7CwHkEEwECACMFAlOMcBYCGwMHCwkIBwMCAQYVCAIJCgsEFgIDA= QIe AQIXgAAKCRCw3p3WKL8TL0KdB/93FcIZ3GCNwFU0u3EjNbNjmXBKDY4FUGNQH2lvWAUy+dnyT= hpw dtF/jQ6j9RwE8VP0+NXcYpGJDWlNb9/JmYqLiX2Q3TyevpB0CA3dbBQp0OW0fgCetToGIQrg0= MbD 1C/sEOv8Mr4NAfbauXjZlvTj30H2jO0u+6WGM6nHwbh2l5O8ZiHkH32iaSTfN7Eu5RnNVUJbv= oPH Z8SlM4KWm8rG+lIkGurqqu5gu8q8ZMKdsdGC4bBxdQKDKHEFExLJK/nRPFmAuGlId1E3fe10v= 5QL +qHI3EIPtyfE7i9Hz6rVwi7lWKgh7pe0ZvatAudZ+JNIlBKptb64FaiIOAWDCx1SzR9KdWVyZ= 2Vu IEdyb3NzIDxqZ3Jvc3NAc3VzZS5jb20+wsB5BBMBAgAjBQJTjHCvAhsDBwsJCAcDAgEGFQgCC= QoL BBYCAwECHgECF4AACgkQsN6d1ii/Ey/HmQf/RtI7kv5A2PS4RF7HoZhPVPogNVbC4YA6lW7Dr= Wf0 teC0RR3MzXfy6pJ+7KLgkqMlrAbN/8Dvjoz78X+5vhH/rDLa9BuZQlhFmvcGtCF8eR0T1v0nC= /nu AFVGy+67q2DH8As3KPu0344TBDpAvr2uYM4tSqxK4DURx5INz4ZZ0WNFHcqsfvlGJALDeE0Lh= ITT d9jLzdDad1pQSToCnLl6SBJZjDOX9QQcyUigZFtCXFst4dlsvddrxyqT1f17+2cFSdu7+ynLm= XBK 7abQ3rwJY8SbRO2iRulogc5vr/RLMMlscDAiDkaFQWLoqHHOdfO9rURssHNN8WkMnQfvUewRz= 80h SnVlcmdlbiBHcm9zcyA8amdyb3NzQG5vdmVsbC5jb20+wsB5BBMBAgAjBQJTjHDXAhsDBwsJC= AcD AgEGFQgCCQoLBBYCAwECHgECF4AACgkQsN6d1ii/Ey8PUQf/ehmgCI9jB9hlgexLvgOtf7PJn= FOX gMLdBQgBlVPO3/D9R8LtF9DBAFPNhlrsfIG/SqICoRCqUcJ96Pn3P7UUinFG/I0ECGF4EvTE1= jnD kfJZr6jrbjgyoZHiw/4BNwSTL9rWASyLgqlA8u1mf+c2yUwcGhgkRAd1gOwungxcwzwqgljf0= N51 N5JfVRHRtyfwq/ge+YEkDGcTU6Y0sPOuj4Dyfm8fJzdfHNQsWq3PnczLVELStJNdapwPOoE+l= otu fe3AM2vAEYJ9rTz3Cki4JFUsgLkHFqGZarrPGi1eyQcXeluldO3m91NK/1xMI3/+8jbO0tsn1= tqS EUGIJi7ox80eSnVlcmdlbiBHcm9zcyA8amdyb3NzQHN1c2UuZGU+wsB5BBMBAgAjBQJTjHDrA= hsD BwsJCAcDAgEGFQgCCQoLBBYCAwECHgECF4AACgkQsN6d1ii/Ey+LhQf9GL45eU5vOowA2u5N3= g3O ZUEBmDHVVbqMtzwlmNC4k9Kx39r5s2vcFl4tXqW7g9/ViXYuiDXb0RfUpZiIUW89siKrkzmQ5= dM7 wRqzgJpJwK8Bn2MIxAKArekWpiCKvBOB/Cc+3EXE78XdlxLyOi/NrmSGRIov0karw2RzMNOu5= D+j LRZQd1Sv27AR+IP3I8U4aqnhLpwhK7MEy9oCILlgZ1QZe49kpcumcZKORmzBTNh30FVKK1Evm= V2x AKDoaEOgQB4iFQLhJCdP1I5aSgM5IVFdn7v5YgEYuJYx37IoN1EblHI//x/e2AaIHpzK5h88N= Eaw QsaNRpNSrcfbFmAg987ATQRTjHAWAQgAyzH6AOODMBjgfWE9VeCgsrwH3exNAU32gLq2xvjpW= nHI s98ndPUDpnoxWQugJ6MpMncr0xSwFmHEgnSEjK/PAjppgmyc57BwKII3sV4on+gDVFJR6Y8ZR= wgn BC5mVM6JjQ5xDk8WRXljExRfUX9pNhdE5eBOZJrDRoLUmmjDtKzWaDhIg/+1Hzz93X4fCQkNV= bVF LELU9bMaLPBG/x5q4iYZ2k2ex6d47YE1ZFdMm6YBYMOljGkZKwYde5ldM9mo45mmwe0icXKLk= pEd IXKTZeKDO+Hdv1aqFuAcccTg9RXDQjmwhC3yEmrmcfl0+rPghO0Iv3OOImwTEe4co3c1mwARA= QAB wsBfBBgBAgAJBQJTjHAWAhsMAAoJELDendYovxMvQ/gH/1ha96vm4P/L+bQpJwrZ/dneZcmEw= Tbe 8YFsw2V/Buv6Z4Mysln3nQK5ZadD534CF7TDVft7fC4tU4PONxF5D+/tvgkPfDAfF77zy2AH1= vJz Q1fOU8lYFpZXTXIHb+559UqvIB8AdgR3SAJGHHt4RKA0F7f5ipYBBrC6cyXJyyoprT10EMvU8= VGi wXvTyJz3fjoYsdFzpWPlJEBRMedCot60g5dmbdrZ5DWClAr0yau47zpWj3enf1tLWaqcsuylW= svi uGjKGw7KHQd3bxALOknAp4dN3QwBYCKuZ7AddY9yjynVaD5X7nF9nO5BjR/i1DG86lem3iBDX= zXs ZDn8R38=3D =3D2wuH -----END PGP PUBLIC KEY BLOCK----- --------------2BC56277A4C35AB15AE644E2-- --Ppp2vYvGThO8wQQ2EBYyUaL68OiVZg9IC-- --0yj4b187kHHxs2gYxzlqTiOSZhnZSWTHm Content-Type: application/pgp-signature; name="OpenPGP_signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="OpenPGP_signature" -----BEGIN PGP SIGNATURE----- wsB5BAABCAAjFiEEhRJncuj2BJSl0Jf3sN6d1ii/Ey8FAmGuEGkFAwAAAAAACgkQsN6d1ii/Ey+U 2gf/QyjWryYWgG4hsAgy3ipz3es5FZ5ydqr/7kmBNEpyn89hb4XemnnrBpT1D61h/deoUH/i6qII OyM6GQWfCPUPSTDXXffU1BV+RrbWpXxMbKgGlW8xJAdopuHRPk8DhM3UOqVfHtR+oC6rEuHWDAWm sIJkFvnaQ8JEXgYdwBKhsp1F7ET3zr25eGWZy3YEtJd51Mw5/qipJCz33pOZg28Fadx97S8mMxnI GSPYf2Siz7kAZEkLx6p750ErOIXO2m3+lc3Aiws1YL50sWkpi47Tw53Q+ulVz2Yv8SGp+0HNqoHR bHerv1WGQ0uMKG4ymJYpt7kQSziu02ElD/Oe4OXVfQ== =OwFN -----END PGP SIGNATURE----- --0yj4b187kHHxs2gYxzlqTiOSZhnZSWTHm-- From minios-devel-bounces@lists.xenproject.org Mon Dec 06 14:17:28 2021 Return-path: Envelope-to: archives@lists.xenproject.org Delivery-date: Mon, 06 Dec 2021 14:17:28 +0000 Received: from list by lists.xenproject.org with outflank-mailman.239059.414348 (Exim 4.92) (envelope-from ) id 1muEo2-0005yr-6d; Mon, 06 Dec 2021 14:17:26 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 239059.414348; Mon, 06 Dec 2021 14:17: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 1muEo2-0005ym-3i; Mon, 06 Dec 2021 14:17:26 +0000 Received: by outflank-mailman (input) for mailman id 239059; Mon, 06 Dec 2021 14:17:25 +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 1muEo1-00043L-EY for minios-devel@lists.xenproject.org; Mon, 06 Dec 2021 14:17:25 +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 3bd67aa1-569f-11ec-8a4d-196798b21f7b; Mon, 06 Dec 2021 15:17:24 +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 49A5F21B45; Mon, 6 Dec 2021 14:17:24 +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 1A97513C4C; Mon, 6 Dec 2021 14:17:24 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id YwUeBXQbrmFENgAAMHmgww (envelope-from ); Mon, 06 Dec 2021 14:17:24 +0000 X-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-devel" X-Inumbo-ID: 3bd67aa1-569f-11ec-8a4d-196798b21f7b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1638800244; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=ci4XGMPd4XtETtT8yrd6qqmUEhD9O23TZHpCQkVi1tk=; b=P8H03erbeHbkyRoLuX8UKi1ZswOrKYHzumFywaQfHesIRVEi23MmdkXbwm5UWGqVKC0prV 5uJ8ASQDZrKIFQdPAfI6SyLrW0RXd0mojhSNyGF7qpklNV/4mEVjc7/mG1F0MV+XhylMwd hYNdF4r9iYTdExGrGkYUuGIlEfCMxRU= To: Jan Beulich Cc: samuel.thibault@ens-lyon.org, wl@xen.org, minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org References: <20211206072337.9517-1-jgross@suse.com> <20211206124612.24758-1-jgross@suse.com> <39a4ae01-7ea9-7526-74da-1fea71274890@suse.com> From: Juergen Gross Subject: Re: [PATCH] mini-os: support event channel 0 for console Message-ID: <4cd75f8f-9026-9d3b-750b-3f3c6eb200c2@suse.com> Date: Mon, 6 Dec 2021 15:17:23 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: <39a4ae01-7ea9-7526-74da-1fea71274890@suse.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="EldJmA8XQezjl9Kra1ypXlj8GflOIsPrP" This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --EldJmA8XQezjl9Kra1ypXlj8GflOIsPrP Content-Type: multipart/mixed; boundary="2hNHuU50ZUpvu1NRS1f8nBdWgvnfgdhwD"; protected-headers="v1" From: Juergen Gross To: Jan Beulich Cc: samuel.thibault@ens-lyon.org, wl@xen.org, minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org Message-ID: <4cd75f8f-9026-9d3b-750b-3f3c6eb200c2@suse.com> Subject: Re: [PATCH] mini-os: support event channel 0 for console References: <20211206072337.9517-1-jgross@suse.com> <20211206124612.24758-1-jgross@suse.com> <39a4ae01-7ea9-7526-74da-1fea71274890@suse.com> In-Reply-To: <39a4ae01-7ea9-7526-74da-1fea71274890@suse.com> --2hNHuU50ZUpvu1NRS1f8nBdWgvnfgdhwD Content-Type: multipart/mixed; boundary="------------FD3935A15D5EE7887C6FDEA3" Content-Language: en-US This is a multi-part message in MIME format. --------------FD3935A15D5EE7887C6FDEA3 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable On 06.12.21 14:24, Jan Beulich wrote: > On 06.12.2021 13:46, Juergen Gross wrote: >> The console event channel might be 0 for the console, so use the value= >> of ~0 as invalid instead. >=20 > I may be missing something mini-os specific here, but in Xen channel 0 > is always invalid. It's not just here that this value would be used as > a sentinel. This made me look at th domain creation paths again, and it seems as if the parameter settings for HVM guests is split in an awful way: the console ring page pfn is set from libxenguest, while the console event channel is set from libxl only. :-( This means that this patch can be dropped, while init-xenstore-domain needs to gain another one. Thanks for your feedback, Juergen --------------FD3935A15D5EE7887C6FDEA3 Content-Type: application/pgp-keys; name="OpenPGP_0xB0DE9DD628BF132F.asc" Content-Transfer-Encoding: quoted-printable Content-Description: OpenPGP public key Content-Disposition: attachment; filename="OpenPGP_0xB0DE9DD628BF132F.asc" -----BEGIN PGP PUBLIC KEY BLOCK----- xsBNBFOMcBYBCACgGjqjoGvbEouQZw/ToiBg9W98AlM2QHV+iNHsEs7kxWhKMjrioyspZKOBy= cWx w3ie3j9uvg9EOB3aN4xiTv4qbnGiTr3oJhkB1gsb6ToJQZ8uxGq2kaV2KL9650I1SJvedYm8O= f8Z d621lSmoKOwlNClALZNew72NjJLEzTalU1OdT7/i1TXkH09XSSI8mEQ/ouNcMvIJNwQpd369y= 9bf IhWUiVXEK7MlRgUG6MvIj6Y3Am/BBLUVbDa4+gmzDC9ezlZkTZG2t14zWPvxXP3FAp2pkW0xq= G7/ 377qptDmrk42GlSKN4z76ELnLxussxc7I2hx18NUcbP8+uty4bMxABEBAAHNHEp1ZXJnZW4gR= 3Jv c3MgPGpnQHBmdXBmLm5ldD7CwHkEEwECACMFAlOMcBYCGwMHCwkIBwMCAQYVCAIJCgsEFgIDA= QIe AQIXgAAKCRCw3p3WKL8TL0KdB/93FcIZ3GCNwFU0u3EjNbNjmXBKDY4FUGNQH2lvWAUy+dnyT= hpw dtF/jQ6j9RwE8VP0+NXcYpGJDWlNb9/JmYqLiX2Q3TyevpB0CA3dbBQp0OW0fgCetToGIQrg0= MbD 1C/sEOv8Mr4NAfbauXjZlvTj30H2jO0u+6WGM6nHwbh2l5O8ZiHkH32iaSTfN7Eu5RnNVUJbv= oPH Z8SlM4KWm8rG+lIkGurqqu5gu8q8ZMKdsdGC4bBxdQKDKHEFExLJK/nRPFmAuGlId1E3fe10v= 5QL +qHI3EIPtyfE7i9Hz6rVwi7lWKgh7pe0ZvatAudZ+JNIlBKptb64FaiIOAWDCx1SzR9KdWVyZ= 2Vu IEdyb3NzIDxqZ3Jvc3NAc3VzZS5jb20+wsB5BBMBAgAjBQJTjHCvAhsDBwsJCAcDAgEGFQgCC= QoL BBYCAwECHgECF4AACgkQsN6d1ii/Ey/HmQf/RtI7kv5A2PS4RF7HoZhPVPogNVbC4YA6lW7Dr= Wf0 teC0RR3MzXfy6pJ+7KLgkqMlrAbN/8Dvjoz78X+5vhH/rDLa9BuZQlhFmvcGtCF8eR0T1v0nC= /nu AFVGy+67q2DH8As3KPu0344TBDpAvr2uYM4tSqxK4DURx5INz4ZZ0WNFHcqsfvlGJALDeE0Lh= ITT d9jLzdDad1pQSToCnLl6SBJZjDOX9QQcyUigZFtCXFst4dlsvddrxyqT1f17+2cFSdu7+ynLm= XBK 7abQ3rwJY8SbRO2iRulogc5vr/RLMMlscDAiDkaFQWLoqHHOdfO9rURssHNN8WkMnQfvUewRz= 80h SnVlcmdlbiBHcm9zcyA8amdyb3NzQG5vdmVsbC5jb20+wsB5BBMBAgAjBQJTjHDXAhsDBwsJC= AcD AgEGFQgCCQoLBBYCAwECHgECF4AACgkQsN6d1ii/Ey8PUQf/ehmgCI9jB9hlgexLvgOtf7PJn= FOX gMLdBQgBlVPO3/D9R8LtF9DBAFPNhlrsfIG/SqICoRCqUcJ96Pn3P7UUinFG/I0ECGF4EvTE1= jnD kfJZr6jrbjgyoZHiw/4BNwSTL9rWASyLgqlA8u1mf+c2yUwcGhgkRAd1gOwungxcwzwqgljf0= N51 N5JfVRHRtyfwq/ge+YEkDGcTU6Y0sPOuj4Dyfm8fJzdfHNQsWq3PnczLVELStJNdapwPOoE+l= otu fe3AM2vAEYJ9rTz3Cki4JFUsgLkHFqGZarrPGi1eyQcXeluldO3m91NK/1xMI3/+8jbO0tsn1= tqS EUGIJi7ox80eSnVlcmdlbiBHcm9zcyA8amdyb3NzQHN1c2UuZGU+wsB5BBMBAgAjBQJTjHDrA= hsD BwsJCAcDAgEGFQgCCQoLBBYCAwECHgECF4AACgkQsN6d1ii/Ey+LhQf9GL45eU5vOowA2u5N3= g3O ZUEBmDHVVbqMtzwlmNC4k9Kx39r5s2vcFl4tXqW7g9/ViXYuiDXb0RfUpZiIUW89siKrkzmQ5= dM7 wRqzgJpJwK8Bn2MIxAKArekWpiCKvBOB/Cc+3EXE78XdlxLyOi/NrmSGRIov0karw2RzMNOu5= D+j LRZQd1Sv27AR+IP3I8U4aqnhLpwhK7MEy9oCILlgZ1QZe49kpcumcZKORmzBTNh30FVKK1Evm= V2x AKDoaEOgQB4iFQLhJCdP1I5aSgM5IVFdn7v5YgEYuJYx37IoN1EblHI//x/e2AaIHpzK5h88N= Eaw QsaNRpNSrcfbFmAg987ATQRTjHAWAQgAyzH6AOODMBjgfWE9VeCgsrwH3exNAU32gLq2xvjpW= nHI s98ndPUDpnoxWQugJ6MpMncr0xSwFmHEgnSEjK/PAjppgmyc57BwKII3sV4on+gDVFJR6Y8ZR= wgn BC5mVM6JjQ5xDk8WRXljExRfUX9pNhdE5eBOZJrDRoLUmmjDtKzWaDhIg/+1Hzz93X4fCQkNV= bVF LELU9bMaLPBG/x5q4iYZ2k2ex6d47YE1ZFdMm6YBYMOljGkZKwYde5ldM9mo45mmwe0icXKLk= pEd IXKTZeKDO+Hdv1aqFuAcccTg9RXDQjmwhC3yEmrmcfl0+rPghO0Iv3OOImwTEe4co3c1mwARA= QAB wsBfBBgBAgAJBQJTjHAWAhsMAAoJELDendYovxMvQ/gH/1ha96vm4P/L+bQpJwrZ/dneZcmEw= Tbe 8YFsw2V/Buv6Z4Mysln3nQK5ZadD534CF7TDVft7fC4tU4PONxF5D+/tvgkPfDAfF77zy2AH1= vJz Q1fOU8lYFpZXTXIHb+559UqvIB8AdgR3SAJGHHt4RKA0F7f5ipYBBrC6cyXJyyoprT10EMvU8= VGi wXvTyJz3fjoYsdFzpWPlJEBRMedCot60g5dmbdrZ5DWClAr0yau47zpWj3enf1tLWaqcsuylW= svi uGjKGw7KHQd3bxALOknAp4dN3QwBYCKuZ7AddY9yjynVaD5X7nF9nO5BjR/i1DG86lem3iBDX= zXs ZDn8R38=3D =3D2wuH -----END PGP PUBLIC KEY BLOCK----- --------------FD3935A15D5EE7887C6FDEA3-- --2hNHuU50ZUpvu1NRS1f8nBdWgvnfgdhwD-- --EldJmA8XQezjl9Kra1ypXlj8GflOIsPrP Content-Type: application/pgp-signature; name="OpenPGP_signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="OpenPGP_signature" -----BEGIN PGP SIGNATURE----- wsB4BAABCAAjFiEEhRJncuj2BJSl0Jf3sN6d1ii/Ey8FAmGuG3MFAwAAAAAACgkQsN6d1ii/Ey8L WAf4p++3OidMd8W+sJDBABGF/LRbbdyxcSoMW7KovZ5qC1oAwhNTxeH5+aKo1gKFdjqq8G1LGvFr d6xn3mVeKCHDv5RTkdJ0yxzsVlF+CPrumk71ERzbZ5PDOfrc8yJG/Qmyb/LyIllP1nYv/gMonFSX uPnbc6aptWhqeajjtsX7Z6z5fA/+P7DjnqemYpXuHxxx8JKXgsVjkALwTHTnMI+mwaiWze+2QovZ xh1AQoPmrTBzhC9OgqEsFqlgOQzpma0LDYBJZGevcuL32Mi6U3sm57GtVMKlvF2g7AglJh4/glMQ mWbWv06l4biMhTJ3LlHmSZEiVQ1V8WjfP3nAnyLI =gvaW -----END PGP SIGNATURE----- --EldJmA8XQezjl9Kra1ypXlj8GflOIsPrP-- From minios-devel-bounces@lists.xenproject.org Sat Dec 11 23:56:37 2021 Return-path: Envelope-to: archives@lists.xenproject.org Delivery-date: Sat, 11 Dec 2021 23:56:37 +0000 Received: from list by lists.xenproject.org with outflank-mailman.245490.423561 (Exim 4.92) (envelope-from ) id 1mwCEF-0007JY-0o; Sat, 11 Dec 2021 23:56:35 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 245490.423561; Sat, 11 Dec 2021 23:56:34 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mwCEE-0007JR-Tw; Sat, 11 Dec 2021 23:56:34 +0000 Received: by outflank-mailman (input) for mailman id 245490; Sat, 11 Dec 2021 23:56:32 +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 1mwCEC-0007JG-QU for minios-devel@lists.xenproject.org; Sat, 11 Dec 2021 23:56:32 +0000 Received: from hera.aquilenet.fr (hera.aquilenet.fr [185.233.100.1]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id f61515b0-5add-11ec-bf02-3911bdbc85ab; Sun, 12 Dec 2021 00:56:31 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 466AB28B; Sun, 12 Dec 2021 00:56:30 +0100 (CET) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id fN01haenjv7s; Sun, 12 Dec 2021 00:56:29 +0100 (CET) Received: from begin (unknown [IPv6:2a01:cb19:956:1b00:de41:a9ff:fe47:ec49]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 00D7A1CF; Sun, 12 Dec 2021 00:56:28 +0100 (CET) Received: from samy by begin with local (Exim 4.95) (envelope-from ) id 1mwCE8-001qNi-88; Sun, 12 Dec 2021 00:56:28 +0100 X-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-devel" X-Inumbo-ID: f61515b0-5add-11ec-bf02-3911bdbc85ab X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Date: Sun, 12 Dec 2021 00:56:28 +0100 From: Samuel Thibault To: Juergen Gross Cc: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org, wl@xen.org Subject: Re: [PATCH 01/10] mini-os: split e820 map handling into new source file Message-ID: <20211211235628.kcbzkjl4xnlduu5w@begin> Mail-Followup-To: Samuel Thibault , Juergen Gross , minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org, wl@xen.org References: <20211206072337.9517-1-jgross@suse.com> <20211206072337.9517-2-jgross@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20211206072337.9517-2-jgross@suse.com> Organization: I am not organized User-Agent: NeoMutt/20170609 (1.8.3) X-Spamd-Bar: / Authentication-Results: hera.aquilenet.fr; none X-Rspamd-Server: hera X-Rspamd-Queue-Id: 466AB28B X-Spamd-Result: default: False [0.40 / 15.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; HAS_ORG_HEADER(0.00)[]; RCVD_COUNT_THREE(0.00)[3]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_LAST(0.00)[]; MID_RHS_NOT_FQDN(0.50)[] Juergen Gross, le lun. 06 déc. 2021 08:23:28 +0100, a ecrit: > Introduce e820.c containing all the E820 memory map handling. > > No functional change. > > Signed-off-by: Juergen Gross Reviewed-by: Samuel Thibault > --- > Makefile | 1 + > arch/arm/mm.c | 8 ---- > arch/x86/mm.c | 70 +---------------------------- > e820.c | 119 +++++++++++++++++++++++++++++++++++++++++++++++++ > include/e820.h | 6 +++ > 5 files changed, 128 insertions(+), 76 deletions(-) > create mode 100644 e820.c > > diff --git a/Makefile b/Makefile > index 4b76b55..06b60fc 100644 > --- a/Makefile > +++ b/Makefile > @@ -41,6 +41,7 @@ src-$(CONFIG_TPMFRONT) += tpmfront.c > src-$(CONFIG_TPM_TIS) += tpm_tis.c > src-$(CONFIG_TPMBACK) += tpmback.c > src-y += daytime.c > +src-y += e820.c > src-y += events.c > src-$(CONFIG_FBFRONT) += fbfront.c > src-y += gntmap.c > diff --git a/arch/arm/mm.c b/arch/arm/mm.c > index f806c9f..9068166 100644 > --- a/arch/arm/mm.c > +++ b/arch/arm/mm.c > @@ -7,14 +7,6 @@ > #include > > uint32_t physical_address_offset; > -struct e820entry e820_map[1] = { > - { > - .addr = 0, > - .size = ULONG_MAX - 1, > - .type = E820_RAM > - } > -}; > -unsigned e820_entries = 1; > > unsigned long allocate_ondemand(unsigned long n, unsigned long alignment) > { > diff --git a/arch/x86/mm.c b/arch/x86/mm.c > index 8ba14a5..8df93da 100644 > --- a/arch/x86/mm.c > +++ b/arch/x86/mm.c > @@ -64,15 +64,6 @@ extern char stack[]; > extern void page_walk(unsigned long va); > > #ifdef CONFIG_PARAVIRT > -struct e820entry e820_map[1] = { > - { > - .addr = 0, > - .size = ULONG_MAX - 1, > - .type = E820_RAM > - } > -}; > -unsigned e820_entries = 1; > - > void arch_mm_preinit(void *p) > { > start_info_t *si = p; > @@ -112,25 +103,11 @@ desc_ptr idt_ptr = > .base = (unsigned long)&idt, > }; > > -struct e820entry e820_map[E820_MAX]; > -unsigned e820_entries; > - > -static char *e820_types[E820_TYPES] = { > - [E820_RAM] = "RAM", > - [E820_RESERVED] = "Reserved", > - [E820_ACPI] = "ACPI", > - [E820_NVS] = "NVS", > - [E820_UNUSABLE] = "Unusable", > - [E820_PMEM] = "PMEM" > -}; > - > void arch_mm_preinit(void *p) > { > long ret; > domid_t domid = DOMID_SELF; > - struct xen_memory_map memmap; > - int i; > - unsigned long pfn, max = 0; > + unsigned long max; > > pt_base = page_table_base; > first_free_pfn = PFN_UP(to_phys(&_end)); > @@ -142,53 +119,10 @@ void arch_mm_preinit(void *p) > } > last_free_pfn = ret; > > - memmap.nr_entries = E820_MAX; > - set_xen_guest_handle(memmap.buffer, e820_map); > - ret = HYPERVISOR_memory_op(XENMEM_memory_map, &memmap); > - if ( ret < 0 ) > - { > - xprintk("could not get memory map\n"); > - do_exit(); > - } > - e820_entries = memmap.nr_entries; > - > - for ( i = 0; i < e820_entries; i++ ) > - { > - if ( e820_map[i].type != E820_RAM ) > - continue; > - pfn = (e820_map[i].addr + e820_map[i].size) >> PAGE_SHIFT; > - if ( pfn > max ) > - max = pfn; > - } > - > + max = e820_get_maxpfn(); > if ( max < last_free_pfn ) > last_free_pfn = max; > } > - > -void arch_print_memmap(void) > -{ > - int i; > - unsigned long from, to; > - char *type; > - char buf[12]; > - > - printk("Memory map:\n"); > - for ( i = 0; i < e820_entries; i++ ) > - { > - if ( e820_map[i].type >= E820_TYPES || !e820_types[e820_map[i].type] ) > - { > - snprintf(buf, sizeof(buf), "%8x", e820_map[i].type); > - type = buf; > - } > - else > - { > - type = e820_types[e820_map[i].type]; > - } > - from = e820_map[i].addr; > - to = from + e820_map[i].size - 1; > - printk("%012lx-%012lx: %s\n", from, to, type); > - } > -} > #endif > > /* > diff --git a/e820.c b/e820.c > new file mode 100644 > index 0000000..2165280 > --- /dev/null > +++ b/e820.c > @@ -0,0 +1,119 @@ > +/* -*- Mode:C; c-basic-offset:4; tab-width:4 -*- > + * > + * (C) 2021 - Juergen Gross, SUSE Software Solutions Germany GmbH > + * > + * Permission is hereby granted, free of charge, to any person obtaining a copy > + * of this software and associated documentation files (the "Software"), to > + * deal in the Software without restriction, including without limitation the > + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or > + * sell copies of the Software, and to permit persons to whom the Software is > + * furnished to do so, subject to the following conditions: > + * > + * The above copyright notice and this permission notice shall be included in > + * all copies or substantial portions of the Software. > + * > + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR > + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, > + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE > + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER > + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING > + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER > + * DEALINGS IN THE SOFTWARE. > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#ifdef CONFIG_E820_TRIVIAL > +struct e820entry e820_map[1] = { > + { > + .addr = 0, > + .size = ULONG_MAX - 1, > + .type = E820_RAM > + } > +}; > + > +unsigned e820_entries = 1; > + > +static void e820_get_memmap(void) > +{ > +} > + > +#else > +struct e820entry e820_map[E820_MAX]; > +unsigned e820_entries; > + > +static char *e820_types[E820_TYPES] = { > + [E820_RAM] = "RAM", > + [E820_RESERVED] = "Reserved", > + [E820_ACPI] = "ACPI", > + [E820_NVS] = "NVS", > + [E820_UNUSABLE] = "Unusable", > + [E820_PMEM] = "PMEM" > +}; > + > +static void e820_get_memmap(void) > +{ > + long ret; > + struct xen_memory_map memmap; > + > + memmap.nr_entries = E820_MAX; > + set_xen_guest_handle(memmap.buffer, e820_map); > + ret = HYPERVISOR_memory_op(XENMEM_memory_map, &memmap); > + if ( ret < 0 ) > + { > + xprintk("could not get memory map\n"); > + do_exit(); > + } > + e820_entries = memmap.nr_entries; > +} > + > +void arch_print_memmap(void) > +{ > + int i; > + unsigned long from, to; > + char *type; > + char buf[12]; > + > + printk("Memory map:\n"); > + for ( i = 0; i < e820_entries; i++ ) > + { > + if ( e820_map[i].type >= E820_TYPES || !e820_types[e820_map[i].type] ) > + { > + snprintf(buf, sizeof(buf), "%8x", e820_map[i].type); > + type = buf; > + } > + else > + { > + type = e820_types[e820_map[i].type]; > + } > + from = e820_map[i].addr; > + to = from + e820_map[i].size - 1; > + printk("%012lx-%012lx: %s\n", from, to, type); > + } > +} > +#endif > + > +unsigned long e820_get_maxpfn(void) > +{ > + int i; > + unsigned long pfn, max = 0; > + > + e820_get_memmap(); > + > + for ( i = 0; i < e820_entries; i++ ) > + { > + if ( e820_map[i].type != E820_RAM ) > + continue; > + pfn = (e820_map[i].addr + e820_map[i].size) >> PAGE_SHIFT; > + if ( pfn > max ) > + max = pfn; > + } > + > + return max; > +} > diff --git a/include/e820.h b/include/e820.h > index 920551c..af2129f 100644 > --- a/include/e820.h > +++ b/include/e820.h > @@ -24,6 +24,10 @@ > #ifndef __E820_HEADER > #define __E820_HEADER > > +#if defined(__arm__) || defined(__aarch64__) || defined(CONFIG_PARAVIRT) > +#define CONFIG_E820_TRIVIAL > +#endif > + > /* PC BIOS standard E820 types and structure. */ > #define E820_RAM 1 > #define E820_RESERVED 2 > @@ -45,4 +49,6 @@ struct __packed e820entry { > extern struct e820entry e820_map[]; > extern unsigned e820_entries; > > +unsigned long e820_get_maxpfn(void); > + > #endif /*__E820_HEADER*/ > -- > 2.26.2 > -- Samuel * c is away : cuisine; bouffe oh, moi je fais plutôt cuisine & bouffe en fait :) oui c'est vrai, certains font cuisine && bouffe (juste au cas où... ;-)) ( cuisine && bouffe ) || restau voire ((cuisine && bouffe) || restau) & apéritif -+- #ens-mim -+- From minios-devel-bounces@lists.xenproject.org Sun Dec 12 00:06:05 2021 Return-path: Envelope-to: archives@lists.xenproject.org Delivery-date: Sun, 12 Dec 2021 00:06:05 +0000 Received: from list by lists.xenproject.org with outflank-mailman.245498.423580 (Exim 4.92) (envelope-from ) id 1mwCNP-0001J9-Oz; Sun, 12 Dec 2021 00:06:03 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 245498.423580; Sun, 12 Dec 2021 00:06:03 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mwCNP-0001II-Kn; Sun, 12 Dec 2021 00:06:03 +0000 Received: by outflank-mailman (input) for mailman id 245498; Sun, 12 Dec 2021 00:06:02 +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 1mwCNO-0001GN-6u for minios-devel@lists.xenproject.org; Sun, 12 Dec 2021 00:06:02 +0000 Received: from hera.aquilenet.fr (hera.aquilenet.fr [185.233.100.1]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 499aabc2-5adf-11ec-bf02-3911bdbc85ab; Sun, 12 Dec 2021 01:06:00 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 9F67C28B; Sun, 12 Dec 2021 01:05:59 +0100 (CET) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 7nCufShTzUxx; Sun, 12 Dec 2021 01:05:59 +0100 (CET) Received: from begin (unknown [IPv6:2a01:cb19:956:1b00:de41:a9ff:fe47:ec49]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 0F223181; Sun, 12 Dec 2021 01:05:58 +0100 (CET) Received: from samy by begin with local (Exim 4.95) (envelope-from ) id 1mwCNK-001qVD-2Z; Sun, 12 Dec 2021 01:05:58 +0100 X-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-devel" X-Inumbo-ID: 499aabc2-5adf-11ec-bf02-3911bdbc85ab X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Date: Sun, 12 Dec 2021 01:05:58 +0100 From: Samuel Thibault To: Juergen Gross Cc: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org, wl@xen.org Subject: Re: [PATCH 02/10] mini-os: sort and sanitize e820 memory map Message-ID: <20211212000558.232nzs7k5lklpbym@begin> Mail-Followup-To: Samuel Thibault , Juergen Gross , minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org, wl@xen.org References: <20211206072337.9517-1-jgross@suse.com> <20211206072337.9517-3-jgross@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20211206072337.9517-3-jgross@suse.com> Organization: I am not organized User-Agent: NeoMutt/20170609 (1.8.3) X-Spamd-Bar: / Authentication-Results: hera.aquilenet.fr; none X-Rspamd-Server: hera X-Rspamd-Queue-Id: 9F67C28B X-Spamd-Result: default: False [0.40 / 15.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; HAS_ORG_HEADER(0.00)[]; RCVD_COUNT_THREE(0.00)[3]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_LAST(0.00)[]; MID_RHS_NOT_FQDN(0.50)[] Hello, Juergen Gross, le lun. 06 déc. 2021 08:23:29 +0100, a ecrit: > - align the entries to page boundaries > + /* Adjust map entries to page boundaries. */ > + for ( i = 0; i < e820_entries; i++ ) > + { > + end = (e820_map[i].addr + e820_map[i].size + PAGE_SIZE - 1) & PAGE_MASK; > + e820_map[i].addr &= PAGE_MASK; > + e820_map[i].size = end - e820_map[i].addr; > + } Mmm, what if the previous entry ends after the aligned start? On real machines that does happen, and you'd rather round up the start address of usable areas, rather than rounding it down (and conversely for the end). > + /* Sort entries by start address. */ > + for ( i = 0; i < e820_entries - 1; i++ ) > + { > + if ( e820_map[i].addr > e820_map[i + 1].addr ) > + { > + e820_swap_entries(i, i + 1); > + i = -1; > + } > + } This looks O(n^3) to me? A bubble sort like this should be fine: /* Sort entries by start address. */ for ( last = e820_entries; last > 1; last-- ) { for ( i = 0; i < last - 1; i++ ) { if ( e820_map[i].addr > e820_map[i + 1].addr ) { e820_swap_entries(i, i + 1); } } } Samuel From minios-devel-bounces@lists.xenproject.org Sun Dec 12 00:15:48 2021 Return-path: Envelope-to: archives@lists.xenproject.org Delivery-date: Sun, 12 Dec 2021 00:15:48 +0000 Received: from list by lists.xenproject.org with outflank-mailman.245504.423590 (Exim 4.92) (envelope-from ) id 1mwCWo-0002xe-DD; Sun, 12 Dec 2021 00:15:46 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 245504.423590; Sun, 12 Dec 2021 00:15: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 1mwCWo-0002xX-AO; Sun, 12 Dec 2021 00:15:46 +0000 Received: by outflank-mailman (input) for mailman id 245504; Sun, 12 Dec 2021 00:15:45 +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 1mwCWn-0002xR-QD for minios-devel@lists.xenproject.org; Sun, 12 Dec 2021 00:15:45 +0000 Received: from hera.aquilenet.fr (hera.aquilenet.fr [2a0c:e300::1]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id a5f38cba-5ae0-11ec-bf02-3911bdbc85ab; Sun, 12 Dec 2021 01:15:45 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 1F0F11CF; Sun, 12 Dec 2021 01:15:44 +0100 (CET) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id yWRoFvYdAhqX; Sun, 12 Dec 2021 01:15:43 +0100 (CET) Received: from begin (unknown [IPv6:2a01:cb19:956:1b00:de41:a9ff:fe47:ec49]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 9F1801B8; Sun, 12 Dec 2021 01:15:43 +0100 (CET) Received: from samy by begin with local (Exim 4.95) (envelope-from ) id 1mwCWk-0024n2-Tk; Sun, 12 Dec 2021 01:15:42 +0100 X-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-devel" X-Inumbo-ID: a5f38cba-5ae0-11ec-bf02-3911bdbc85ab X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Date: Sun, 12 Dec 2021 01:15:42 +0100 From: Samuel Thibault To: Juergen Gross Cc: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org, wl@xen.org Subject: Re: [PATCH 03/10] mini-os: don't assume contiguous RAM when initializing in PVH mode Message-ID: <20211212001542.qhz7wfdwq7k5ymxr@begin> Mail-Followup-To: Samuel Thibault , Juergen Gross , minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org, wl@xen.org References: <20211206072337.9517-1-jgross@suse.com> <20211206072337.9517-4-jgross@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20211206072337.9517-4-jgross@suse.com> Organization: I am not organized User-Agent: NeoMutt/20170609 (1.8.3) X-Spamd-Bar: / Authentication-Results: hera.aquilenet.fr; none X-Rspamd-Server: hera X-Rspamd-Queue-Id: 1F0F11CF X-Spamd-Result: default: False [0.40 / 15.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; HAS_ORG_HEADER(0.00)[]; RCVD_COUNT_THREE(0.00)[3]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_LAST(0.00)[]; MID_RHS_NOT_FQDN(0.50)[] Juergen Gross, le lun. 06 déc. 2021 08:23:30 +0100, a ecrit: > - unsigned long pfn, max = 0; > + unsigned long pfns, max = 0; I'd say rather rename max to start. > e820_get_memmap(); > > @@ -166,9 +166,12 @@ unsigned long e820_get_maxpfn(void) > { > if ( e820_map[i].type != E820_RAM ) > continue; > - pfn = (e820_map[i].addr + e820_map[i].size) >> PAGE_SHIFT; > - if ( pfn > max ) > - max = pfn; > + pfns = e820_map[i].size >> PAGE_SHIFT; > + max = e820_map[i].addr >> PAGE_SHIFT; since it's it's always the start of the e820 entry. > + if ( pages <= pfns ) > + return max + pages; > + pages -= pfns; > + max += pfns; Here we don't need do change max, only pages. Samuel From minios-devel-bounces@lists.xenproject.org Sun Dec 12 00:26:32 2021 Return-path: Envelope-to: archives@lists.xenproject.org Delivery-date: Sun, 12 Dec 2021 00:26:32 +0000 Received: from list by lists.xenproject.org with outflank-mailman.245510.423606 (Exim 4.92) (envelope-from ) id 1mwChB-0004ff-Bt; Sun, 12 Dec 2021 00:26:29 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 245510.423606; Sun, 12 Dec 2021 00:26:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mwChB-0004fY-8y; Sun, 12 Dec 2021 00:26:29 +0000 Received: by outflank-mailman (input) for mailman id 245510; Sun, 12 Dec 2021 00:26: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 1mwChA-0004fO-LG for minios-devel@lists.xenproject.org; Sun, 12 Dec 2021 00:26:28 +0000 Received: from hera.aquilenet.fr (hera.aquilenet.fr [185.233.100.1]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 24686e93-5ae2-11ec-a74f-db008197e53d; Sun, 12 Dec 2021 01:26:27 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 8FD6F3DB; Sun, 12 Dec 2021 01:26:25 +0100 (CET) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id NHojSOqlstbh; Sun, 12 Dec 2021 01:26:25 +0100 (CET) Received: from begin (unknown [IPv6:2a01:cb19:956:1b00:de41:a9ff:fe47:ec49]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 0A0CF254; Sun, 12 Dec 2021 01:26:24 +0100 (CET) Received: from samy by begin with local (Exim 4.95) (envelope-from ) id 1mwCh6-0024s8-3U; Sun, 12 Dec 2021 01:26:24 +0100 X-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-devel" X-Inumbo-ID: 24686e93-5ae2-11ec-a74f-db008197e53d X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Date: Sun, 12 Dec 2021 01:26:24 +0100 From: Samuel Thibault To: Juergen Gross Cc: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org, wl@xen.org Subject: Re: [PATCH 04/10] mini-os: respect memory map when ballooning up Message-ID: <20211212002624.fmmebrd5sudcmco4@begin> Mail-Followup-To: Samuel Thibault , Juergen Gross , minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org, wl@xen.org References: <20211206072337.9517-1-jgross@suse.com> <20211206072337.9517-5-jgross@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20211206072337.9517-5-jgross@suse.com> Organization: I am not organized User-Agent: NeoMutt/20170609 (1.8.3) X-Spamd-Bar: / Authentication-Results: hera.aquilenet.fr; none X-Rspamd-Server: hera X-Rspamd-Queue-Id: 8FD6F3DB X-Spamd-Result: default: False [0.40 / 15.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; HAS_ORG_HEADER(0.00)[]; RCVD_COUNT_THREE(0.00)[3]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_LAST(0.00)[]; MID_RHS_NOT_FQDN(0.50)[] Juergen Gross, le lun. 06 déc. 2021 08:23:31 +0100, a ecrit: > @@ -81,8 +93,11 @@ int balloon_up(unsigned long n_pages) > if ( n_pages > N_BALLOON_FRAMES ) > n_pages = N_BALLOON_FRAMES; > > + start_pfn = e820_get_maxpfn(nr_mem_pages + 1) - 1; > + n_pages = e820_get_max_pages(start_pfn, n_pages); I'd say call it e820_get_max_contig_pages? > +unsigned long e820_get_max_pages(unsigned long pfn, unsigned long pages) > +{ > + int i; > + unsigned long end; > + > + for ( i = 0; i < e820_entries; i++ ) > + { > + if ( e820_map[i].type != E820_RAM || > + (e820_map[i].addr >> PAGE_SHIFT) > pfn ) > + continue; "> pfn" looks odd to me? If the start of the e820 entry is already beyond pfn, we'll never find any other entry. We however do want to skip entries that have addr+size that is below pfn. > + end = (e820_map[i].addr + e820_map[i].size) >> PAGE_SHIFT; > + return ((end - pfn) > pages) ? pages : end - pfn; > + } > + > + return 0; > +} From minios-devel-bounces@lists.xenproject.org Sun Dec 12 00:27:39 2021 Return-path: Envelope-to: archives@lists.xenproject.org Delivery-date: Sun, 12 Dec 2021 00:27:39 +0000 Received: from list by lists.xenproject.org with outflank-mailman.245514.423620 (Exim 4.92) (envelope-from ) id 1mwCiI-0005TR-O8; Sun, 12 Dec 2021 00:27:38 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 245514.423620; Sun, 12 Dec 2021 00:27:38 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mwCiI-0005TG-Kk; Sun, 12 Dec 2021 00:27:38 +0000 Received: by outflank-mailman (input) for mailman id 245514; Sun, 12 Dec 2021 00:27:37 +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 1mwCiH-0005T8-RO for minios-devel@lists.xenproject.org; Sun, 12 Dec 2021 00:27:37 +0000 Received: from hera.aquilenet.fr (hera.aquilenet.fr [185.233.100.1]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 4e6d91c2-5ae2-11ec-a74f-db008197e53d; Sun, 12 Dec 2021 01:27:36 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 79F633C1; Sun, 12 Dec 2021 01:27:36 +0100 (CET) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id wf_uaIP3FA89; Sun, 12 Dec 2021 01:27:36 +0100 (CET) Received: from begin (unknown [IPv6:2a01:cb19:956:1b00:de41:a9ff:fe47:ec49]) by hera.aquilenet.fr (Postfix) with ESMTPSA id A8A9828B; Sun, 12 Dec 2021 01:27:35 +0100 (CET) Received: from samy by begin with local (Exim 4.95) (envelope-from ) id 1mwCiF-0024v2-1q; Sun, 12 Dec 2021 01:27:35 +0100 X-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-devel" X-Inumbo-ID: 4e6d91c2-5ae2-11ec-a74f-db008197e53d X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Date: Sun, 12 Dec 2021 01:27:35 +0100 From: Samuel Thibault To: Juergen Gross Cc: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org, wl@xen.org Subject: Re: [PATCH 05/10] mini-os: don't repeat definition available via header file Message-ID: <20211212002735.um4q6patid5sdhvs@begin> Mail-Followup-To: Samuel Thibault , Juergen Gross , minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org, wl@xen.org References: <20211206072337.9517-1-jgross@suse.com> <20211206072337.9517-6-jgross@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20211206072337.9517-6-jgross@suse.com> Organization: I am not organized User-Agent: NeoMutt/20170609 (1.8.3) X-Spamd-Bar: / Authentication-Results: hera.aquilenet.fr; none X-Rspamd-Server: hera X-Rspamd-Queue-Id: 79F633C1 X-Spamd-Result: default: False [0.40 / 15.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; HAS_ORG_HEADER(0.00)[]; RCVD_COUNT_THREE(0.00)[3]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_LAST(0.00)[]; MID_RHS_NOT_FQDN(0.50)[] Juergen Gross, le lun. 06 déc. 2021 08:23:32 +0100, a ecrit: > 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]; > > extern char shared_info[PAGE_SIZE]; > > -#if defined(__x86_64__) > -#define __pte(x) ((pte_t) { (x) } ) > -#else > -#define __pte(x) ({ unsigned long long _x = (x); \ > - ((pte_t) {(unsigned long)(_x), (unsigned long)(_x>>32)}); }) > -#endif > - > static inline void fpu_init(void) { > asm volatile("fninit"); > } > -- > 2.26.2 > -- Samuel jr> J'ai fait. Ne bougez pas, l'aide soignante va venir nettoyer. -+- FF in GNU - Le vieil homme et la merde -+- From minios-devel-bounces@lists.xenproject.org Sun Dec 12 00:37:17 2021 Return-path: Envelope-to: archives@lists.xenproject.org Delivery-date: Sun, 12 Dec 2021 00:37:17 +0000 Received: from list by lists.xenproject.org with outflank-mailman.245523.423639 (Exim 4.92) (envelope-from ) id 1mwCrb-0007H0-V3; Sun, 12 Dec 2021 00:37:15 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 245523.423639; Sun, 12 Dec 2021 00:37:15 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mwCrb-0007GZ-RZ; Sun, 12 Dec 2021 00:37:15 +0000 Received: by outflank-mailman (input) for mailman id 245523; Sun, 12 Dec 2021 00:37:15 +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 1mwCrb-0007EB-1u for minios-devel@lists.xenproject.org; Sun, 12 Dec 2021 00:37:15 +0000 Received: from hera.aquilenet.fr (hera.aquilenet.fr [2a0c:e300::1]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id a5fcb489-5ae3-11ec-bf02-3911bdbc85ab; Sun, 12 Dec 2021 01:37:13 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 8D9493C1; Sun, 12 Dec 2021 01:37:12 +0100 (CET) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id krA46Fvan94B; Sun, 12 Dec 2021 01:37:12 +0100 (CET) Received: from begin (unknown [IPv6:2a01:cb19:956:1b00:de41:a9ff:fe47:ec49]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 0F1EF229; Sun, 12 Dec 2021 01:37:11 +0100 (CET) Received: from samy by begin with local (Exim 4.95) (envelope-from ) id 1mwCrX-00251x-5g; Sun, 12 Dec 2021 01:37:11 +0100 X-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-devel" X-Inumbo-ID: a5fcb489-5ae3-11ec-bf02-3911bdbc85ab X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Date: Sun, 12 Dec 2021 01:37:11 +0100 From: Samuel Thibault To: Juergen Gross Cc: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org, wl@xen.org Subject: Re: [PATCH 06/10] mini-os: add memory map service functions Message-ID: <20211212003711.l7jsqgbbxjzgl5iv@begin> Mail-Followup-To: Samuel Thibault , Juergen Gross , minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org, wl@xen.org References: <20211206072337.9517-1-jgross@suse.com> <20211206072337.9517-7-jgross@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20211206072337.9517-7-jgross@suse.com> Organization: I am not organized User-Agent: NeoMutt/20170609 (1.8.3) X-Spamd-Bar: / Authentication-Results: hera.aquilenet.fr; none X-Rspamd-Server: hera X-Rspamd-Queue-Id: 8D9493C1 X-Spamd-Result: default: False [0.40 / 15.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; HAS_ORG_HEADER(0.00)[]; RCVD_COUNT_THREE(0.00)[3]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_LAST(0.00)[]; MID_RHS_NOT_FQDN(0.50)[] Juergen Gross, le lun. 06 déc. 2021 08:23:33 +0100, a ecrit: > +void e820_put_reserved_pfns(unsigned long start_pfn, int pages) > +{ > + int i; > + unsigned long addr = start_pfn << PAGE_SHIFT; > + unsigned long size = (long)pages << PAGE_SHIFT; > + > + for ( i = 0; i < e820_entries && addr < e820_map[i].addr; i++ ); Shouldn't that be addr > e820_map[i].addr + e820_map[i].size? > + BUG_ON(i == e820_entries || e820_map[i].type != E820_RESERVED); We should also BUG_ON e820_map[i].addr > addr (i.e. we didn't find an entry that contained our address). > + if ( addr == e820_map[i].addr ) > + { > + e820_map[i].addr += size; I'd say BUG_ON here if e820_map[i].size < size. > + e820_map[i].size -= size; > + if ( e820_map[i].size == 0 ) > + e820_remove_entry(i); > + return; > + } > + > + if ( addr + size == e820_map[i].addr + e820_map[i].size ) > + { > + e820_map[i].addr = addr; > + e820_map[i].size = size; ? Shouldn't that rather be just > + e820_map[i].size -= size; ? (since what we remove is at the end of the area, the start of the area doesn't change) > + return; > + } From minios-devel-bounces@lists.xenproject.org Sun Dec 12 00:41:27 2021 Return-path: Envelope-to: archives@lists.xenproject.org Delivery-date: Sun, 12 Dec 2021 00:41:27 +0000 Received: from list by lists.xenproject.org with outflank-mailman.245528.423650 (Exim 4.92) (envelope-from ) id 1mwCve-0000Es-AM; Sun, 12 Dec 2021 00:41:26 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 245528.423650; Sun, 12 Dec 2021 00:41: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 1mwCve-0000El-7X; Sun, 12 Dec 2021 00:41:26 +0000 Received: by outflank-mailman (input) for mailman id 245528; Sun, 12 Dec 2021 00:41:25 +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 1mwCvc-0000Ea-W5 for minios-devel@lists.xenproject.org; Sun, 12 Dec 2021 00:41:24 +0000 Received: from hera.aquilenet.fr (hera.aquilenet.fr [185.233.100.1]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 3b5f8910-5ae4-11ec-bf02-3911bdbc85ab; Sun, 12 Dec 2021 01:41:24 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 806A23C1; Sun, 12 Dec 2021 01:41:23 +0100 (CET) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id f4QIe0UBnj1B; Sun, 12 Dec 2021 01:41:22 +0100 (CET) Received: from begin (unknown [IPv6:2a01:cb19:956:1b00:de41:a9ff:fe47:ec49]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 411ED1CF; Sun, 12 Dec 2021 01:41:22 +0100 (CET) Received: from samy by begin with local (Exim 4.95) (envelope-from ) id 1mwCvZ-00255z-GS; Sun, 12 Dec 2021 01:41:21 +0100 X-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-devel" X-Inumbo-ID: 3b5f8910-5ae4-11ec-bf02-3911bdbc85ab X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Date: Sun, 12 Dec 2021 01:41:21 +0100 From: Samuel Thibault To: Juergen Gross Cc: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org, wl@xen.org Subject: Re: [PATCH 07/10] mini-os: move x86 specific gnttab coding into arch/x86/gnttab.c Message-ID: <20211212004121.27tquytcimfd47b5@begin> Mail-Followup-To: Samuel Thibault , Juergen Gross , minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org, wl@xen.org References: <20211206072337.9517-1-jgross@suse.com> <20211206072337.9517-8-jgross@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20211206072337.9517-8-jgross@suse.com> Organization: I am not organized User-Agent: NeoMutt/20170609 (1.8.3) X-Spamd-Bar: / Authentication-Results: hera.aquilenet.fr; none X-Rspamd-Server: hera X-Rspamd-Queue-Id: 806A23C1 X-Spamd-Result: default: False [0.40 / 15.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; HAS_ORG_HEADER(0.00)[]; RCVD_COUNT_THREE(0.00)[3]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_LAST(0.00)[]; MID_RHS_NOT_FQDN(0.50)[] Juergen Gross, le lun. 06 déc. 2021 08:23:34 +0100, a ecrit: > 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. There is the __pte fix that you'd probably want to mention. > 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, and/or > + * sell copies of the Software, and to permit persons to whom the Software is > + * furnished to do so, subject to the following conditions: > + * > + * The above copyright notice and this permission notice shall be included in > + * all copies or substantial portions of the Software. > + * > + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR > + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, > + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE > + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER > + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING > + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER > + * DEALINGS IN THE SOFTWARE. > + */ > + > +#include > +#include > +#include > +#include > +#include > + > +grant_entry_v1_t *arch_init_gnttab(int nr_grant_frames) > +{ > + struct gnttab_setup_table setup; > + unsigned long frames[nr_grant_frames]; > + > + setup.dom = DOMID_SELF; > + setup.nr_frames = 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_frames) > +{ > +#ifdef CONFIG_PARAVIRT > + int i; > + > + for ( i = 0; i < nr_grant_frames; i++ ) > + { > + HYPERVISOR_update_va_mapping((unsigned long)gnttab_table + PAGE_SIZE * i, > + __pte(0x0 << PAGE_SHIFT), UVMF_INVLPG); > + } > +#endif > + return; > +} > + > +void arch_resume_gnttab(grant_entry_v1_t *gnttab_table, int nr_grant_frames) > +{ > + struct gnttab_setup_table setup; > + unsigned long frames[nr_grant_frames]; > +#ifdef CONFIG_PARAVIRT > + int i; > +#endif > + > + setup.dom = DOMID_SELF; > + setup.nr_frames = 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 = 0; i < nr_grant_frames; i++ ) > + { > + HYPERVISOR_update_va_mapping((unsigned long)gnttab_table + PAGE_SIZE * 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 > } > > -grant_entry_v1_t *arch_init_gnttab(int nr_grant_frames) > -{ > - struct gnttab_setup_table setup; > - unsigned long frames[nr_grant_frames]; > - > - setup.dom = DOMID_SELF; > - setup.nr_frames = 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_frames) > -{ > -#ifdef CONFIG_PARAVIRT > - int i; > - > - for (i = 0; i < nr_grant_frames; i++) { > - HYPERVISOR_update_va_mapping((unsigned long)(((char *)gnttab_table) + PAGE_SIZE * i), > - (pte_t){0x0< - } > -#endif > - return; > -} > - > -void arch_resume_gnttab(grant_entry_v1_t *gnttab_table, int nr_grant_frames) > -{ > - struct gnttab_setup_table setup; > - unsigned long frames[nr_grant_frames]; > -#ifdef CONFIG_PARAVIRT > - int i; > -#endif > - setup.dom = DOMID_SELF; > - setup.nr_frames = 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 = 0; i < nr_grant_frames; i++) { > - HYPERVISOR_update_va_mapping((unsigned long)(((char *)gnttab_table) + PAGE_SIZE * i), > - (pte_t){(frames[i] << PAGE_SHIFT) | L1_PROT}, UVMF_INVLPG); > - } > -#endif > -} > - > unsigned long alloc_virt_kernel(unsigned n_pages) > { > unsigned long addr; > -- > 2.26.2 > -- Samuel War doesn't prove who's right, just who's left. From minios-devel-bounces@lists.xenproject.org Sun Dec 12 00:43:33 2021 Return-path: Envelope-to: archives@lists.xenproject.org Delivery-date: Sun, 12 Dec 2021 00:43:33 +0000 Received: from list by lists.xenproject.org with outflank-mailman.245536.423665 (Exim 4.92) (envelope-from ) id 1mwCxg-0000zV-Tc; Sun, 12 Dec 2021 00:43:32 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 245536.423665; Sun, 12 Dec 2021 00:43: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 1mwCxg-0000zO-Qk; Sun, 12 Dec 2021 00:43:32 +0000 Received: by outflank-mailman (input) for mailman id 245536; Sun, 12 Dec 2021 00:43:31 +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 1mwCxf-0000zD-OP for minios-devel@lists.xenproject.org; Sun, 12 Dec 2021 00:43:31 +0000 Received: from hera.aquilenet.fr (hera.aquilenet.fr [185.233.100.1]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 86ef05c4-5ae4-11ec-bf02-3911bdbc85ab; Sun, 12 Dec 2021 01:43:30 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id E12563C1; Sun, 12 Dec 2021 01:43:29 +0100 (CET) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id jN9RwrQgMh7V; Sun, 12 Dec 2021 01:43:29 +0100 (CET) Received: from begin (unknown [IPv6:2a01:cb19:956:1b00:de41:a9ff:fe47:ec49]) by hera.aquilenet.fr (Postfix) with ESMTPSA id E724D1CF; Sun, 12 Dec 2021 01:43:28 +0100 (CET) Received: from samy by begin with local (Exim 4.95) (envelope-from ) id 1mwCxc-00256f-2y; Sun, 12 Dec 2021 01:43:28 +0100 X-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-devel" X-Inumbo-ID: 86ef05c4-5ae4-11ec-bf02-3911bdbc85ab X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Date: Sun, 12 Dec 2021 01:43:28 +0100 From: Samuel Thibault To: Juergen Gross Cc: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org, wl@xen.org Subject: Re: [PATCH 08/10] mini-os: add proper pvh grant table handling Message-ID: <20211212004328.ozyid2zh4fapcnit@begin> Mail-Followup-To: Samuel Thibault , Juergen Gross , minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org, wl@xen.org References: <20211206072337.9517-1-jgross@suse.com> <20211206072337.9517-9-jgross@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20211206072337.9517-9-jgross@suse.com> Organization: I am not organized User-Agent: NeoMutt/20170609 (1.8.3) X-Spamd-Bar: / Authentication-Results: hera.aquilenet.fr; none X-Rspamd-Server: hera X-Rspamd-Queue-Id: E12563C1 X-Spamd-Result: default: False [0.40 / 15.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; HAS_ORG_HEADER(0.00)[]; RCVD_COUNT_THREE(0.00)[3]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_LAST(0.00)[]; MID_RHS_NOT_FQDN(0.50)[] Juergen Gross, le lun. 06 déc. 2021 08:23:35 +0100, a ecrit: > 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 @@ > */ > > #include > +#include > +#include > #include > #include > #include > #include > +#include > > +#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 = e820_get_reserved_pfns(nr_grant_frames); > + for ( i = 0; i < nr_grant_frames; i++ ) > + { > + xatp.domid = DOMID_SELF; > + xatp.idx = i; > + xatp.space = XENMAPSPACE_grant_table; > + xatp.gpfn = pfn + i; > + rc = HYPERVISOR_memory_op(XENMEM_add_to_physmap, &xatp); > + if ( rc ) > + { > + xprintk("could not init grant table\n"); > + do_exit(); > + } > + frames[i] = pfn + i; > + } > + > + return map_frames(frames, nr_grant_frames); > +} > +#endif > > void arch_suspend_gnttab(grant_entry_v1_t *gnttab_table, int nr_grant_frames) > { > -- > 2.26.2 > -- Samuel > Il [e2fsck] a bien démarré, mais il m'a rendu la main aussitot en me > disant "houlala, c'est pas beau à voir votre truc, je préfèrerai que > vous teniez vous même la tronçonneuse" (traduction libre) NC in Guide du linuxien pervers : "Bien configurer sa tronçonneuse." From minios-devel-bounces@lists.xenproject.org Sun Dec 12 00:50:55 2021 Return-path: Envelope-to: archives@lists.xenproject.org Delivery-date: Sun, 12 Dec 2021 00:50:55 +0000 Received: from list by lists.xenproject.org with outflank-mailman.245543.423684 (Exim 4.92) (envelope-from ) id 1mwD4n-0002jy-W5; Sun, 12 Dec 2021 00:50:53 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 245543.423684; Sun, 12 Dec 2021 00:50: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 1mwD4n-0002iv-S3; Sun, 12 Dec 2021 00:50:53 +0000 Received: by outflank-mailman (input) for mailman id 245543; Sun, 12 Dec 2021 00:50:53 +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 1mwD4n-0002gD-4T for minios-devel@lists.xenproject.org; Sun, 12 Dec 2021 00:50:53 +0000 Received: from hera.aquilenet.fr (hera.aquilenet.fr [185.233.100.1]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 8cd37ad9-5ae5-11ec-a74f-db008197e53d; Sun, 12 Dec 2021 01:50:50 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 4E27F3C1; Sun, 12 Dec 2021 01:50:49 +0100 (CET) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 4eQWN4mfQbNI; Sun, 12 Dec 2021 01:50:48 +0100 (CET) Received: from begin (unknown [IPv6:2a01:cb19:956:1b00:de41:a9ff:fe47:ec49]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 0107C28B; Sun, 12 Dec 2021 01:50:47 +0100 (CET) Received: from samy by begin with local (Exim 4.95) (envelope-from ) id 1mwD4h-0025BJ-50; Sun, 12 Dec 2021 01:50:47 +0100 X-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-devel" X-Inumbo-ID: 8cd37ad9-5ae5-11ec-a74f-db008197e53d X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Date: Sun, 12 Dec 2021 01:50:47 +0100 From: Samuel Thibault To: Juergen Gross Cc: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org, wl@xen.org Subject: Re: [PATCH 09/10] mini-os: prepare grantmap entry interface for use by PVH mode Message-ID: <20211212005047.ksbjkax2veon2dvl@begin> Mail-Followup-To: Samuel Thibault , Juergen Gross , minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org, wl@xen.org References: <20211206072337.9517-1-jgross@suse.com> <20211206072337.9517-10-jgross@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20211206072337.9517-10-jgross@suse.com> Organization: I am not organized User-Agent: NeoMutt/20170609 (1.8.3) X-Spamd-Bar: / Authentication-Results: hera.aquilenet.fr; none X-Rspamd-Server: hera X-Rspamd-Queue-Id: 4E27F3C1 X-Spamd-Result: default: False [0.40 / 15.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; HAS_ORG_HEADER(0.00)[]; RCVD_COUNT_THREE(0.00)[3]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_LAST(0.00)[]; MID_RHS_NOT_FQDN(0.50)[] Juergen Gross, le lun. 06 déc. 2021 08:23:36 +0100, a ecrit: > 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 { > }; > > static inline int > -gntmap_entry_used(struct gntmap_entry *entry) > +gntmap_entry_used(struct gntmap *map, int idx) > { > - return entry->host_addr != 0; > + return map->entries[idx].host_addr != 0; > } > > -static struct gntmap_entry* > -gntmap_find_free_entry(struct gntmap *map) > +static int gntmap_find_free_entry(struct gntmap *map) > { > int i; > > for (i = 0; i < map->nentries; i++) { > - if (!gntmap_entry_used(&map->entries[i])) > - return &map->entries[i]; > + if (!gntmap_entry_used(map, i)) > + return i; > } > > DEBUG("(map=%p): all %d entries full", > map, map->nentries); > - return NULL; > + return -1; > } > > -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; > > for (i = 0; i < map->nentries; i++) { > if (map->entries[i].host_addr == addr) > - return &map->entries[i]; > + return i; > } > - return NULL; > + return -1; > } > > int > @@ -105,12 +103,13 @@ gntmap_set_max_grants(struct gntmap *map, int count) > } > > static int > -_gntmap_map_grant_ref(struct gntmap_entry *entry, > +_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 = map->entries + idx; > struct gnttab_map_grant_ref op; > int rc; > > @@ -135,8 +134,9 @@ _gntmap_map_grant_ref(struct gntmap_entry *entry, > } > > static int > -_gntmap_unmap_grant_ref(struct gntmap_entry *entry) > +_gntmap_unmap_grant_ref(struct gntmap *map, int idx) > { > + struct gntmap_entry *entry = map->entries + idx; > struct gnttab_unmap_grant_ref op; > int rc; > > @@ -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; > > DEBUG("(map=%p, start_address=%lx, count=%d)", > map, start_address, count); > > for (i = 0; i < count; i++) { > - ent = gntmap_find_entry(map, start_address + PAGE_SIZE * i); > - if (ent == NULL) { > + idx = gntmap_find_entry(map, start_address + PAGE_SIZE * i); > + if (idx < 0) { > printk("gntmap: tried to munmap unknown page\n"); > return -EINVAL; > } > > - rc = _gntmap_unmap_grant_ref(ent); > + rc = _gntmap_unmap_grant_ref(map, idx); > if (rc != 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; > > DEBUG("(map=%p, count=%" PRIu32 ", " > @@ -206,9 +206,9 @@ gntmap_map_grant_refs(struct gntmap *map, > return NULL; > > for (i = 0; i < count; i++) { > - ent = gntmap_find_free_entry(map); > - if (ent == NULL || > - _gntmap_map_grant_ref(ent, > + idx = 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; > > DEBUG("(map=%p)", map); > > for (i = 0; i < map->nentries; i++) { > - ent = &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); > } > > xfree(map->entries); > -- > 2.26.2 > -- Samuel pour moi le seul qui est autorisé à fasciser, c moi :-) From minios-devel-bounces@lists.xenproject.org Sun Dec 12 00:51:05 2021 Return-path: Envelope-to: archives@lists.xenproject.org Delivery-date: Sun, 12 Dec 2021 00:51:05 +0000 Received: from list by lists.xenproject.org with outflank-mailman.245545.423707 (Exim 4.92) (envelope-from ) id 1mwD4z-0003Jg-9m; Sun, 12 Dec 2021 00:51:05 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 245545.423707; Sun, 12 Dec 2021 00:51:05 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mwD4z-0003JZ-6g; Sun, 12 Dec 2021 00:51:05 +0000 Received: by outflank-mailman (input) for mailman id 245545; Sun, 12 Dec 2021 00:51:04 +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 1mwD4y-0002gD-8A for minios-devel@lists.xenproject.org; Sun, 12 Dec 2021 00:51:04 +0000 Received: from hera.aquilenet.fr (hera.aquilenet.fr [185.233.100.1]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 9426cb2d-5ae5-11ec-a74f-db008197e53d; Sun, 12 Dec 2021 01:51:02 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id F26C13C1; Sun, 12 Dec 2021 01:51:01 +0100 (CET) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id uElmtqq-kG3t; Sun, 12 Dec 2021 01:51:01 +0100 (CET) Received: from begin (unknown [IPv6:2a01:cb19:956:1b00:de41:a9ff:fe47:ec49]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 2141928B; Sun, 12 Dec 2021 01:51:01 +0100 (CET) Received: from samy by begin with local (Exim 4.95) (envelope-from ) id 1mwD4u-0025BY-DH; Sun, 12 Dec 2021 01:51:00 +0100 X-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-devel" X-Inumbo-ID: 9426cb2d-5ae5-11ec-a74f-db008197e53d X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Date: Sun, 12 Dec 2021 01:51:00 +0100 From: Samuel Thibault To: Juergen Gross Cc: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org, wl@xen.org Subject: Re: [PATCH 10/10] mini-os: modify grant mappings to work in PVH mode Message-ID: <20211212005100.gld3gajiwiog54rv@begin> Mail-Followup-To: Samuel Thibault , Juergen Gross , minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org, wl@xen.org References: <20211206072337.9517-1-jgross@suse.com> <20211206072337.9517-11-jgross@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20211206072337.9517-11-jgross@suse.com> Organization: I am not organized User-Agent: NeoMutt/20170609 (1.8.3) X-Spamd-Bar: / Authentication-Results: hera.aquilenet.fr; none X-Rspamd-Server: hera X-Rspamd-Queue-Id: F26C13C1 X-Spamd-Result: default: False [0.40 / 15.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; HAS_ORG_HEADER(0.00)[]; RCVD_COUNT_THREE(0.00)[3]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_LAST(0.00)[]; MID_RHS_NOT_FQDN(0.50)[] Juergen Gross, le lun. 06 déc. 2021 08:23:37 +0100, a ecrit: > 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 @@ > > #include > #include > +#include > #include > #include > #include > @@ -97,11 +98,42 @@ gntmap_set_max_grants(struct gntmap *map, int count) > if (map->entries == NULL) > return -ENOMEM; > > +#ifndef CONFIG_PARAVIRT > + map->start_pfn = e820_get_reserved_pfns(count); > +#endif > + > memset(map->entries, 0, sizeof(struct gntmap_entry) * count); > map->nentries = count; > return 0; > } > > +static int > +_gntmap_unmap_grant_ref(struct gntmap *map, int idx) > +{ > + struct gntmap_entry *entry = map->entries + idx; > + struct gnttab_unmap_grant_ref op; > + int rc; > + > +#ifdef CONFIG_PARAVIRT > + op.host_addr = (uint64_t) entry->host_addr; > +#else > + op.host_addr = (uint64_t)(map->start_pfn + idx) << PAGE_SHIFT; > +#endif > + op.dev_bus_addr = 0; > + op.handle = entry->handle; > + > + rc = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1); > + if (rc != 0 || op.status != GNTST_okay) { > + printk("GNTTABOP_unmap_grant_ref failed: " > + "returned %d, status %" PRId16 "\n", > + rc, op.status); > + return rc != 0 ? rc : op.status; > + } > + > + entry->host_addr = 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 = map->entries + idx; > struct gnttab_map_grant_ref op; > int rc; > +#ifndef CONFIG_PARAVIRT > + unsigned long pfn = map->start_pfn + idx; > +#endif > > op.ref = (grant_ref_t) ref; > op.dom = (domid_t) domid; > +#ifdef CONFIG_PARAVIRT > op.host_addr = (uint64_t) host_addr; > +#else > + op.host_addr = (uint64_t)pfn << PAGE_SHIFT; > +#endif > op.flags = GNTMAP_host_map; > if (!writable) > op.flags |= GNTMAP_readonly; > @@ -128,31 +167,18 @@ _gntmap_map_grant_ref(struct gntmap *map, int idx, > return rc != 0 ? rc : op.status; > } > > - entry->host_addr = host_addr; > - entry->handle = op.handle; > - return 0; > -} > - > -static int > -_gntmap_unmap_grant_ref(struct gntmap *map, int idx) > -{ > - struct gntmap_entry *entry = map->entries + idx; > - struct gnttab_unmap_grant_ref op; > - int rc; > - > - op.host_addr = (uint64_t) entry->host_addr; > - op.dev_bus_addr = 0; > - op.handle = entry->handle; > - > - rc = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1); > - if (rc != 0 || op.status != GNTST_okay) { > - printk("GNTTABOP_unmap_grant_ref failed: " > - "returned %d, status %" PRId16 "\n", > - rc, op.status); > - return rc != 0 ? rc : op.status; > +#ifndef CONFIG_PARAVIRT > + rc = 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 > > - entry->host_addr = 0; > + entry->host_addr = host_addr; > + entry->handle = op.handle; > return 0; > } > > @@ -165,6 +191,10 @@ gntmap_munmap(struct gntmap *map, unsigned long start_address, int count) > DEBUG("(map=%p, start_address=%lx, count=%d)", > map, start_address, count); > > +#ifndef CONFIG_PARAVIRT > + unmap_frames(start_address, count); > +#endif > + > for (i = 0; i < count; i++) { > idx = 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); > } > > +#ifndef CONFIG_PARAVIRT > + e820_put_reserved_pfns(map->start_pfn, map->nentries); > + map->start_pfn = 0; > +#endif > + > xfree(map->entries); > map->entries = NULL; > map->nentries = 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; > }; > > int > -- > 2.26.2 > -- Samuel Yep. Moi j'ai un clavier à une touche. Par contre, ma souris a 102 boutons, c'est pas toujours pratique. -+- OG in: Guide du Cabaliste Usenet - Le mulot contre attaque -+- From minios-devel-bounces@lists.xenproject.org Mon Dec 13 14:56:28 2021 Return-path: Envelope-to: archives@lists.xenproject.org Delivery-date: Mon, 13 Dec 2021 14:56:28 +0000 Received: from list by lists.xenproject.org with outflank-mailman.246144.424545 (Exim 4.92) (envelope-from ) id 1mwmkc-0005aR-4B; Mon, 13 Dec 2021 14:56:26 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 246144.424545; Mon, 13 Dec 2021 14:56: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 1mwmkc-0005aI-10; Mon, 13 Dec 2021 14:56:26 +0000 Received: by outflank-mailman (input) for mailman id 246144; Mon, 13 Dec 2021 14:56:24 +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 1mwmka-0005YO-EA for minios-devel@lists.xenproject.org; Mon, 13 Dec 2021 14:56:24 +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 d65b574a-5c24-11ec-85d3-df6b77346a89; Mon, 13 Dec 2021 15:56:23 +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 5167921123; Mon, 13 Dec 2021 14:56:22 +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 2D53313DE2; Mon, 13 Dec 2021 14:56:22 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id l+q1CRZft2FWNwAAMHmgww (envelope-from ); Mon, 13 Dec 2021 14:56:22 +0000 X-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-devel" X-Inumbo-ID: d65b574a-5c24-11ec-85d3-df6b77346a89 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1639407382; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=j7cVxE04IfsTIEumjoh0h0K2JpqO07CGgJNiGKv+uYU=; b=rTwGDY9Uw5nUopNc2mxAT8fkgtxzs1B/+a6gkCcbxVvv6fX0JD/YwJxlI2sBomnSIB3cwX MpqMQBL+0u9yDAtWt9av48q3fFqmW3GhSwLF9m14U3nseQb48FiK6jNId1+9O3A+9cIqZQ 0yfvDtB4AQlvH6rzj/d67Q+GB7eqv9Q= To: Samuel Thibault , minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org, wl@xen.org References: <20211206072337.9517-1-jgross@suse.com> <20211206072337.9517-3-jgross@suse.com> <20211212000558.232nzs7k5lklpbym@begin> From: Juergen Gross Subject: Re: [PATCH 02/10] mini-os: sort and sanitize e820 memory map Message-ID: Date: Mon, 13 Dec 2021 15:56:21 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: <20211212000558.232nzs7k5lklpbym@begin> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="IAFzW0f4rRLv6G6aH0YvjuKBDF6qBTSig" This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --IAFzW0f4rRLv6G6aH0YvjuKBDF6qBTSig Content-Type: multipart/mixed; boundary="eYeR0dxD77OMlNuDhk2i5UNuo2LM5MmRq"; protected-headers="v1" From: Juergen Gross To: Samuel Thibault , minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org, wl@xen.org Message-ID: Subject: Re: [PATCH 02/10] mini-os: sort and sanitize e820 memory map References: <20211206072337.9517-1-jgross@suse.com> <20211206072337.9517-3-jgross@suse.com> <20211212000558.232nzs7k5lklpbym@begin> In-Reply-To: <20211212000558.232nzs7k5lklpbym@begin> --eYeR0dxD77OMlNuDhk2i5UNuo2LM5MmRq Content-Type: multipart/mixed; boundary="------------9740D0F2639D38120BDF7612" Content-Language: en-US This is a multi-part message in MIME format. --------------9740D0F2639D38120BDF7612 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable On 12.12.21 01:05, Samuel Thibault wrote: > Hello, >=20 > Juergen Gross, le lun. 06 d=C3=A9c. 2021 08:23:29 +0100, a ecrit: >> - align the entries to page boundaries >=20 >> + /* 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)= & PAGE_MASK; >> + e820_map[i].addr &=3D PAGE_MASK; >> + e820_map[i].size =3D end - e820_map[i].addr; >> + } >=20 > Mmm, what if the previous entry ends after the aligned start? >=20 > On real machines that does happen, and you'd rather round up the start > address of usable areas, rather than rounding it down (and conversely > for the end). I think you are partially right. :-) Entries for resources managed by Mini-OS (RAM, maybe NVME?) should be rounded to cover only complete pages (start rounded up, end rounded down), but all other entries should be rounded to cover the complete area (start rounded down, end rounded up) in order not to use any partial used page for e.g. mapping foreign pages. >=20 >> + /* 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; >> + } >> + } >=20 > This looks O(n^3) to me? A bubble sort like this should be fine: >=20 > /* Sort entries by start address. */ > for ( last =3D e820_entries; last > 1; last-- ) > { > for ( i =3D 0; i < last - 1; i++ ) > { > if ( e820_map[i].addr > e820_map[i + 1].addr ) > { > e820_swap_entries(i, i + 1); > } > } > } Hmm, depends. Assuming a rather well sorted map my version is O(n), while yours is still O(n^2). In the end it won't matter that much, because a normal map will have only very few entries (usually 5 before merging consecutive entries). I'm fine both ways, whatever you prefer. Juergen --------------9740D0F2639D38120BDF7612 Content-Type: application/pgp-keys; name="OpenPGP_0xB0DE9DD628BF132F.asc" Content-Transfer-Encoding: quoted-printable Content-Description: OpenPGP public key Content-Disposition: attachment; filename="OpenPGP_0xB0DE9DD628BF132F.asc" -----BEGIN PGP PUBLIC KEY BLOCK----- xsBNBFOMcBYBCACgGjqjoGvbEouQZw/ToiBg9W98AlM2QHV+iNHsEs7kxWhKMjrioyspZKOBy= cWx w3ie3j9uvg9EOB3aN4xiTv4qbnGiTr3oJhkB1gsb6ToJQZ8uxGq2kaV2KL9650I1SJvedYm8O= f8Z d621lSmoKOwlNClALZNew72NjJLEzTalU1OdT7/i1TXkH09XSSI8mEQ/ouNcMvIJNwQpd369y= 9bf IhWUiVXEK7MlRgUG6MvIj6Y3Am/BBLUVbDa4+gmzDC9ezlZkTZG2t14zWPvxXP3FAp2pkW0xq= G7/ 377qptDmrk42GlSKN4z76ELnLxussxc7I2hx18NUcbP8+uty4bMxABEBAAHNHEp1ZXJnZW4gR= 3Jv c3MgPGpnQHBmdXBmLm5ldD7CwHkEEwECACMFAlOMcBYCGwMHCwkIBwMCAQYVCAIJCgsEFgIDA= QIe AQIXgAAKCRCw3p3WKL8TL0KdB/93FcIZ3GCNwFU0u3EjNbNjmXBKDY4FUGNQH2lvWAUy+dnyT= hpw dtF/jQ6j9RwE8VP0+NXcYpGJDWlNb9/JmYqLiX2Q3TyevpB0CA3dbBQp0OW0fgCetToGIQrg0= MbD 1C/sEOv8Mr4NAfbauXjZlvTj30H2jO0u+6WGM6nHwbh2l5O8ZiHkH32iaSTfN7Eu5RnNVUJbv= oPH Z8SlM4KWm8rG+lIkGurqqu5gu8q8ZMKdsdGC4bBxdQKDKHEFExLJK/nRPFmAuGlId1E3fe10v= 5QL +qHI3EIPtyfE7i9Hz6rVwi7lWKgh7pe0ZvatAudZ+JNIlBKptb64FaiIOAWDCx1SzR9KdWVyZ= 2Vu IEdyb3NzIDxqZ3Jvc3NAc3VzZS5jb20+wsB5BBMBAgAjBQJTjHCvAhsDBwsJCAcDAgEGFQgCC= QoL BBYCAwECHgECF4AACgkQsN6d1ii/Ey/HmQf/RtI7kv5A2PS4RF7HoZhPVPogNVbC4YA6lW7Dr= Wf0 teC0RR3MzXfy6pJ+7KLgkqMlrAbN/8Dvjoz78X+5vhH/rDLa9BuZQlhFmvcGtCF8eR0T1v0nC= /nu AFVGy+67q2DH8As3KPu0344TBDpAvr2uYM4tSqxK4DURx5INz4ZZ0WNFHcqsfvlGJALDeE0Lh= ITT d9jLzdDad1pQSToCnLl6SBJZjDOX9QQcyUigZFtCXFst4dlsvddrxyqT1f17+2cFSdu7+ynLm= XBK 7abQ3rwJY8SbRO2iRulogc5vr/RLMMlscDAiDkaFQWLoqHHOdfO9rURssHNN8WkMnQfvUewRz= 80h SnVlcmdlbiBHcm9zcyA8amdyb3NzQG5vdmVsbC5jb20+wsB5BBMBAgAjBQJTjHDXAhsDBwsJC= AcD AgEGFQgCCQoLBBYCAwECHgECF4AACgkQsN6d1ii/Ey8PUQf/ehmgCI9jB9hlgexLvgOtf7PJn= FOX gMLdBQgBlVPO3/D9R8LtF9DBAFPNhlrsfIG/SqICoRCqUcJ96Pn3P7UUinFG/I0ECGF4EvTE1= jnD kfJZr6jrbjgyoZHiw/4BNwSTL9rWASyLgqlA8u1mf+c2yUwcGhgkRAd1gOwungxcwzwqgljf0= N51 N5JfVRHRtyfwq/ge+YEkDGcTU6Y0sPOuj4Dyfm8fJzdfHNQsWq3PnczLVELStJNdapwPOoE+l= otu fe3AM2vAEYJ9rTz3Cki4JFUsgLkHFqGZarrPGi1eyQcXeluldO3m91NK/1xMI3/+8jbO0tsn1= tqS EUGIJi7ox80eSnVlcmdlbiBHcm9zcyA8amdyb3NzQHN1c2UuZGU+wsB5BBMBAgAjBQJTjHDrA= hsD BwsJCAcDAgEGFQgCCQoLBBYCAwECHgECF4AACgkQsN6d1ii/Ey+LhQf9GL45eU5vOowA2u5N3= g3O ZUEBmDHVVbqMtzwlmNC4k9Kx39r5s2vcFl4tXqW7g9/ViXYuiDXb0RfUpZiIUW89siKrkzmQ5= dM7 wRqzgJpJwK8Bn2MIxAKArekWpiCKvBOB/Cc+3EXE78XdlxLyOi/NrmSGRIov0karw2RzMNOu5= D+j LRZQd1Sv27AR+IP3I8U4aqnhLpwhK7MEy9oCILlgZ1QZe49kpcumcZKORmzBTNh30FVKK1Evm= V2x AKDoaEOgQB4iFQLhJCdP1I5aSgM5IVFdn7v5YgEYuJYx37IoN1EblHI//x/e2AaIHpzK5h88N= Eaw QsaNRpNSrcfbFmAg987ATQRTjHAWAQgAyzH6AOODMBjgfWE9VeCgsrwH3exNAU32gLq2xvjpW= nHI s98ndPUDpnoxWQugJ6MpMncr0xSwFmHEgnSEjK/PAjppgmyc57BwKII3sV4on+gDVFJR6Y8ZR= wgn BC5mVM6JjQ5xDk8WRXljExRfUX9pNhdE5eBOZJrDRoLUmmjDtKzWaDhIg/+1Hzz93X4fCQkNV= bVF LELU9bMaLPBG/x5q4iYZ2k2ex6d47YE1ZFdMm6YBYMOljGkZKwYde5ldM9mo45mmwe0icXKLk= pEd IXKTZeKDO+Hdv1aqFuAcccTg9RXDQjmwhC3yEmrmcfl0+rPghO0Iv3OOImwTEe4co3c1mwARA= QAB wsBfBBgBAgAJBQJTjHAWAhsMAAoJELDendYovxMvQ/gH/1ha96vm4P/L+bQpJwrZ/dneZcmEw= Tbe 8YFsw2V/Buv6Z4Mysln3nQK5ZadD534CF7TDVft7fC4tU4PONxF5D+/tvgkPfDAfF77zy2AH1= vJz Q1fOU8lYFpZXTXIHb+559UqvIB8AdgR3SAJGHHt4RKA0F7f5ipYBBrC6cyXJyyoprT10EMvU8= VGi wXvTyJz3fjoYsdFzpWPlJEBRMedCot60g5dmbdrZ5DWClAr0yau47zpWj3enf1tLWaqcsuylW= svi uGjKGw7KHQd3bxALOknAp4dN3QwBYCKuZ7AddY9yjynVaD5X7nF9nO5BjR/i1DG86lem3iBDX= zXs ZDn8R38=3D =3D2wuH -----END PGP PUBLIC KEY BLOCK----- --------------9740D0F2639D38120BDF7612-- --eYeR0dxD77OMlNuDhk2i5UNuo2LM5MmRq-- --IAFzW0f4rRLv6G6aH0YvjuKBDF6qBTSig Content-Type: application/pgp-signature; name="OpenPGP_signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="OpenPGP_signature" -----BEGIN PGP SIGNATURE----- wsB5BAABCAAjFiEEhRJncuj2BJSl0Jf3sN6d1ii/Ey8FAmG3XxUFAwAAAAAACgkQsN6d1ii/Ey/T 6Af/ffa1ro8nIoFT9rqUrMD4+zE0MDXNfA6ALAGIQgYN2C4K3CaBZQcObHjFxFtlKSuBhOgovOl9 cIpLS/aQHhQ3jw1rlGK5FeY6fc1XPqMq8nXvJbjL07pmpB2bwbFlyqpRttEc+Qsg5eUMtY2OLmMZ zSTgo2BGFfhplkGkT/79ytvMS8k9Y0SeiNa+J1vVUrX7cN6Tltn/6KwKLxyiYYVL/6ph2bfqItwS eFHNhHKFEIwOhED+fblcnjhVn3wM2qDzhWn+C79KbDUGOFG42fLRnM6xbFBIa4BgkOq4ZwW5tQUi 1488mBtZbBUliW7xrAfLKm4OEsYB6gVLibI7W99u0A== =CHAl -----END PGP SIGNATURE----- --IAFzW0f4rRLv6G6aH0YvjuKBDF6qBTSig-- From minios-devel-bounces@lists.xenproject.org Mon Dec 13 14:59:02 2021 Return-path: Envelope-to: archives@lists.xenproject.org Delivery-date: Mon, 13 Dec 2021 14:59:02 +0000 Received: from list by lists.xenproject.org with outflank-mailman.246153.424559 (Exim 4.92) (envelope-from ) id 1mwmn7-0006TG-Jy; Mon, 13 Dec 2021 14:59:01 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 246153.424559; Mon, 13 Dec 2021 14:59:01 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mwmn7-0006T9-HD; Mon, 13 Dec 2021 14:59:01 +0000 Received: by outflank-mailman (input) for mailman id 246153; Mon, 13 Dec 2021 14:59:00 +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 1mwmn6-0006So-6k for minios-devel@lists.xenproject.org; Mon, 13 Dec 2021 14:59:00 +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 339600a0-5c25-11ec-85d3-df6b77346a89; Mon, 13 Dec 2021 15:58:59 +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 F19AE1F3B9; Mon, 13 Dec 2021 14:58:58 +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 CBA1413DE2; Mon, 13 Dec 2021 14:58:58 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id kGmFL7Jft2F9OAAAMHmgww (envelope-from ); Mon, 13 Dec 2021 14:58:58 +0000 X-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-devel" X-Inumbo-ID: 339600a0-5c25-11ec-85d3-df6b77346a89 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1639407538; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=zurqn5UDxl0JDJcf5v6FfEBfec82sylpyBbRFRa/6YI=; b=CxhDNSX8FinoGB1L5cZc/lxKYuF3qhjYRmnVix9nq9ESMVHV7zBvKT1Y/y6aR60zIJUU27 u0FhlbNKHTk2jXqClGrNKzvRk0XbmYqKpMGxrz87pUSzb4y+SY06P9pQp2uPCkw3WTktxT Pbxm4xESdSbGSRe0NAyxP+YLELOc0Dk= Subject: Re: [PATCH 03/10] mini-os: don't assume contiguous RAM when initializing in PVH mode To: Samuel Thibault , minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org, wl@xen.org References: <20211206072337.9517-1-jgross@suse.com> <20211206072337.9517-4-jgross@suse.com> <20211212001542.qhz7wfdwq7k5ymxr@begin> From: Juergen Gross Message-ID: Date: Mon, 13 Dec 2021 15:58:58 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: <20211212001542.qhz7wfdwq7k5ymxr@begin> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="5l2iD5t6rMNHYWVMtsa1YRUnFkiq12ncu" This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --5l2iD5t6rMNHYWVMtsa1YRUnFkiq12ncu Content-Type: multipart/mixed; boundary="e3LXZZSMPTqrrIGTauAXG641EU8VjabVd"; protected-headers="v1" From: Juergen Gross To: Samuel Thibault , minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org, wl@xen.org Message-ID: Subject: Re: [PATCH 03/10] mini-os: don't assume contiguous RAM when initializing in PVH mode References: <20211206072337.9517-1-jgross@suse.com> <20211206072337.9517-4-jgross@suse.com> <20211212001542.qhz7wfdwq7k5ymxr@begin> In-Reply-To: <20211212001542.qhz7wfdwq7k5ymxr@begin> --e3LXZZSMPTqrrIGTauAXG641EU8VjabVd Content-Type: multipart/mixed; boundary="------------268835E92D5168298BA9F1DE" Content-Language: en-US This is a multi-part message in MIME format. --------------268835E92D5168298BA9F1DE Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable On 12.12.21 01:15, Samuel Thibault wrote: > Juergen Gross, le lun. 06 d=C3=A9c. 2021 08:23:30 +0100, a ecrit: >> - unsigned long pfn, max =3D 0; >> + unsigned long pfns, max =3D 0; >=20 > I'd say rather rename max to start. >=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; >=20 > since it's it's always the start of the e820 entry. >=20 >> + if ( pages <=3D pfns ) >> + return max + pages; >> + pages -=3D pfns; >> + max +=3D pfns; >=20 > Here we don't need do change max, only pages. It is needed in case the loop is finished. And this was the reason for naming it max. Juergen --------------268835E92D5168298BA9F1DE Content-Type: application/pgp-keys; name="OpenPGP_0xB0DE9DD628BF132F.asc" Content-Transfer-Encoding: quoted-printable Content-Description: OpenPGP public key Content-Disposition: attachment; filename="OpenPGP_0xB0DE9DD628BF132F.asc" -----BEGIN PGP PUBLIC KEY BLOCK----- xsBNBFOMcBYBCACgGjqjoGvbEouQZw/ToiBg9W98AlM2QHV+iNHsEs7kxWhKMjrioyspZKOBy= cWx w3ie3j9uvg9EOB3aN4xiTv4qbnGiTr3oJhkB1gsb6ToJQZ8uxGq2kaV2KL9650I1SJvedYm8O= f8Z d621lSmoKOwlNClALZNew72NjJLEzTalU1OdT7/i1TXkH09XSSI8mEQ/ouNcMvIJNwQpd369y= 9bf IhWUiVXEK7MlRgUG6MvIj6Y3Am/BBLUVbDa4+gmzDC9ezlZkTZG2t14zWPvxXP3FAp2pkW0xq= G7/ 377qptDmrk42GlSKN4z76ELnLxussxc7I2hx18NUcbP8+uty4bMxABEBAAHNHEp1ZXJnZW4gR= 3Jv c3MgPGpnQHBmdXBmLm5ldD7CwHkEEwECACMFAlOMcBYCGwMHCwkIBwMCAQYVCAIJCgsEFgIDA= QIe AQIXgAAKCRCw3p3WKL8TL0KdB/93FcIZ3GCNwFU0u3EjNbNjmXBKDY4FUGNQH2lvWAUy+dnyT= hpw dtF/jQ6j9RwE8VP0+NXcYpGJDWlNb9/JmYqLiX2Q3TyevpB0CA3dbBQp0OW0fgCetToGIQrg0= MbD 1C/sEOv8Mr4NAfbauXjZlvTj30H2jO0u+6WGM6nHwbh2l5O8ZiHkH32iaSTfN7Eu5RnNVUJbv= oPH Z8SlM4KWm8rG+lIkGurqqu5gu8q8ZMKdsdGC4bBxdQKDKHEFExLJK/nRPFmAuGlId1E3fe10v= 5QL +qHI3EIPtyfE7i9Hz6rVwi7lWKgh7pe0ZvatAudZ+JNIlBKptb64FaiIOAWDCx1SzR9KdWVyZ= 2Vu IEdyb3NzIDxqZ3Jvc3NAc3VzZS5jb20+wsB5BBMBAgAjBQJTjHCvAhsDBwsJCAcDAgEGFQgCC= QoL BBYCAwECHgECF4AACgkQsN6d1ii/Ey/HmQf/RtI7kv5A2PS4RF7HoZhPVPogNVbC4YA6lW7Dr= Wf0 teC0RR3MzXfy6pJ+7KLgkqMlrAbN/8Dvjoz78X+5vhH/rDLa9BuZQlhFmvcGtCF8eR0T1v0nC= /nu AFVGy+67q2DH8As3KPu0344TBDpAvr2uYM4tSqxK4DURx5INz4ZZ0WNFHcqsfvlGJALDeE0Lh= ITT d9jLzdDad1pQSToCnLl6SBJZjDOX9QQcyUigZFtCXFst4dlsvddrxyqT1f17+2cFSdu7+ynLm= XBK 7abQ3rwJY8SbRO2iRulogc5vr/RLMMlscDAiDkaFQWLoqHHOdfO9rURssHNN8WkMnQfvUewRz= 80h SnVlcmdlbiBHcm9zcyA8amdyb3NzQG5vdmVsbC5jb20+wsB5BBMBAgAjBQJTjHDXAhsDBwsJC= AcD AgEGFQgCCQoLBBYCAwECHgECF4AACgkQsN6d1ii/Ey8PUQf/ehmgCI9jB9hlgexLvgOtf7PJn= FOX gMLdBQgBlVPO3/D9R8LtF9DBAFPNhlrsfIG/SqICoRCqUcJ96Pn3P7UUinFG/I0ECGF4EvTE1= jnD kfJZr6jrbjgyoZHiw/4BNwSTL9rWASyLgqlA8u1mf+c2yUwcGhgkRAd1gOwungxcwzwqgljf0= N51 N5JfVRHRtyfwq/ge+YEkDGcTU6Y0sPOuj4Dyfm8fJzdfHNQsWq3PnczLVELStJNdapwPOoE+l= otu fe3AM2vAEYJ9rTz3Cki4JFUsgLkHFqGZarrPGi1eyQcXeluldO3m91NK/1xMI3/+8jbO0tsn1= tqS EUGIJi7ox80eSnVlcmdlbiBHcm9zcyA8amdyb3NzQHN1c2UuZGU+wsB5BBMBAgAjBQJTjHDrA= hsD BwsJCAcDAgEGFQgCCQoLBBYCAwECHgECF4AACgkQsN6d1ii/Ey+LhQf9GL45eU5vOowA2u5N3= g3O ZUEBmDHVVbqMtzwlmNC4k9Kx39r5s2vcFl4tXqW7g9/ViXYuiDXb0RfUpZiIUW89siKrkzmQ5= dM7 wRqzgJpJwK8Bn2MIxAKArekWpiCKvBOB/Cc+3EXE78XdlxLyOi/NrmSGRIov0karw2RzMNOu5= D+j LRZQd1Sv27AR+IP3I8U4aqnhLpwhK7MEy9oCILlgZ1QZe49kpcumcZKORmzBTNh30FVKK1Evm= V2x AKDoaEOgQB4iFQLhJCdP1I5aSgM5IVFdn7v5YgEYuJYx37IoN1EblHI//x/e2AaIHpzK5h88N= Eaw QsaNRpNSrcfbFmAg987ATQRTjHAWAQgAyzH6AOODMBjgfWE9VeCgsrwH3exNAU32gLq2xvjpW= nHI s98ndPUDpnoxWQugJ6MpMncr0xSwFmHEgnSEjK/PAjppgmyc57BwKII3sV4on+gDVFJR6Y8ZR= wgn BC5mVM6JjQ5xDk8WRXljExRfUX9pNhdE5eBOZJrDRoLUmmjDtKzWaDhIg/+1Hzz93X4fCQkNV= bVF LELU9bMaLPBG/x5q4iYZ2k2ex6d47YE1ZFdMm6YBYMOljGkZKwYde5ldM9mo45mmwe0icXKLk= pEd IXKTZeKDO+Hdv1aqFuAcccTg9RXDQjmwhC3yEmrmcfl0+rPghO0Iv3OOImwTEe4co3c1mwARA= QAB wsBfBBgBAgAJBQJTjHAWAhsMAAoJELDendYovxMvQ/gH/1ha96vm4P/L+bQpJwrZ/dneZcmEw= Tbe 8YFsw2V/Buv6Z4Mysln3nQK5ZadD534CF7TDVft7fC4tU4PONxF5D+/tvgkPfDAfF77zy2AH1= vJz Q1fOU8lYFpZXTXIHb+559UqvIB8AdgR3SAJGHHt4RKA0F7f5ipYBBrC6cyXJyyoprT10EMvU8= VGi wXvTyJz3fjoYsdFzpWPlJEBRMedCot60g5dmbdrZ5DWClAr0yau47zpWj3enf1tLWaqcsuylW= svi uGjKGw7KHQd3bxALOknAp4dN3QwBYCKuZ7AddY9yjynVaD5X7nF9nO5BjR/i1DG86lem3iBDX= zXs ZDn8R38=3D =3D2wuH -----END PGP PUBLIC KEY BLOCK----- --------------268835E92D5168298BA9F1DE-- --e3LXZZSMPTqrrIGTauAXG641EU8VjabVd-- --5l2iD5t6rMNHYWVMtsa1YRUnFkiq12ncu Content-Type: application/pgp-signature; name="OpenPGP_signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="OpenPGP_signature" -----BEGIN PGP SIGNATURE----- wsB5BAABCAAjFiEEhRJncuj2BJSl0Jf3sN6d1ii/Ey8FAmG3X7IFAwAAAAAACgkQsN6d1ii/Ey/o 5Af+NX88Uja52iDBy4HAhF+kUjk2NNlsKfBnbQHQn3ZI9aJKdD8CAunZO3UJMUWeAAOdkrRWehHR k/wIIMkJgxP7AA0autwMaG2jQhNE4sP8uq533wj9P7tz0emuGMe8tNdmUbOyjy1Ha130cNrsf6Ca oC9nDTq0p9LAJ/T9hfbdYKk52Ip1UUP6ceaRzZEWJFPuLoofekm7Apda3K/KTw2iOZgkc2rUjhEM bw6dd8FXsHhSBg+Jo3KJA+Ig4PZKItiAQOMS3iy3et+zGKvF1/VTezNHd3CMKgV+H/KhrymIJkbG XdYG1bsdSTXJikBcYzqegb6HygIZxNx5QjtNBjSXUg== =0t8/ -----END PGP SIGNATURE----- --5l2iD5t6rMNHYWVMtsa1YRUnFkiq12ncu-- From minios-devel-bounces@lists.xenproject.org Mon Dec 13 15:05:33 2021 Return-path: Envelope-to: archives@lists.xenproject.org Delivery-date: Mon, 13 Dec 2021 15:05:33 +0000 Received: from list by lists.xenproject.org with outflank-mailman.246170.424597 (Exim 4.92) (envelope-from ) id 1mwmtR-0000Yw-0B; Mon, 13 Dec 2021 15:05:33 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 246170.424597; Mon, 13 Dec 2021 15:05: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 1mwmtQ-0000Yp-Sw; Mon, 13 Dec 2021 15:05:32 +0000 Received: by outflank-mailman (input) for mailman id 246170; Mon, 13 Dec 2021 15:05:32 +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 1mwmtP-0000I2-Tu for minios-devel@lists.xenproject.org; Mon, 13 Dec 2021 15:05:32 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 1c3cba0d-5c26-11ec-9e60-abaf8a552007; Mon, 13 Dec 2021 16:05:30 +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 3BBE8210F2; Mon, 13 Dec 2021 15:05:29 +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 1B19813DE2; Mon, 13 Dec 2021 15:05:29 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id iAxvBTlht2FOOwAAMHmgww (envelope-from ); Mon, 13 Dec 2021 15:05:29 +0000 X-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-devel" X-Inumbo-ID: 1c3cba0d-5c26-11ec-9e60-abaf8a552007 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1639407929; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=43WTY6tloIhb+jp532ffO8lA63mPUVPlnlIrFB+zC54=; b=OuA1JUzGIkvlxq6t9LS1DvaihY0uIPZjo0qWbasVxtJf39XovX4PzkaDDccOtPxc3ojCJU Z66caCfB9ILqFADQ+mw2UnkUIQP7annmLgHr6youiRpdrt6aIqbGQ0m8utt21nOceE+xbY rvbFGvatNFTTrLTa/m/nqmoAKFxLm+w= Subject: Re: [PATCH 04/10] mini-os: respect memory map when ballooning up To: Samuel Thibault , minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org, wl@xen.org References: <20211206072337.9517-1-jgross@suse.com> <20211206072337.9517-5-jgross@suse.com> <20211212002624.fmmebrd5sudcmco4@begin> From: Juergen Gross Message-ID: <0b7c86f2-bddd-b650-ed58-7e69e1b1c58e@suse.com> Date: Mon, 13 Dec 2021 16:05:28 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: <20211212002624.fmmebrd5sudcmco4@begin> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="1WhaJPULB0DvvgYmQAFFoXOhtEQXABxqT" This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --1WhaJPULB0DvvgYmQAFFoXOhtEQXABxqT Content-Type: multipart/mixed; boundary="LYk1sPWTt3gNdeLkHnL5vpHg85ia8zJ0d"; protected-headers="v1" From: Juergen Gross To: Samuel Thibault , minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org, wl@xen.org Message-ID: <0b7c86f2-bddd-b650-ed58-7e69e1b1c58e@suse.com> Subject: Re: [PATCH 04/10] mini-os: respect memory map when ballooning up References: <20211206072337.9517-1-jgross@suse.com> <20211206072337.9517-5-jgross@suse.com> <20211212002624.fmmebrd5sudcmco4@begin> In-Reply-To: <20211212002624.fmmebrd5sudcmco4@begin> --LYk1sPWTt3gNdeLkHnL5vpHg85ia8zJ0d Content-Type: multipart/mixed; boundary="------------4A99575EED9A2156AA6E4B7A" Content-Language: en-US This is a multi-part message in MIME format. --------------4A99575EED9A2156AA6E4B7A Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable On 12.12.21 01:26, Samuel Thibault wrote: > Juergen Gross, le lun. 06 d=C3=A9c. 2021 08:23:31 +0100, a ecrit: >> @@ -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); >=20 > I'd say call it e820_get_max_contig_pages? Fine with me. >=20 >> +unsigned long e820_get_max_pages(unsigned long pfn, unsigned long pag= es) >> +{ >> + 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; >=20 > "> pfn" looks odd to me? If the start of the e820 entry is already > beyond pfn, we'll never find any other entry. We however do want to ski= p > entries that have addr+size that is below pfn. Oh, you are right. Juergen --------------4A99575EED9A2156AA6E4B7A Content-Type: application/pgp-keys; name="OpenPGP_0xB0DE9DD628BF132F.asc" Content-Transfer-Encoding: quoted-printable Content-Description: OpenPGP public key Content-Disposition: attachment; filename="OpenPGP_0xB0DE9DD628BF132F.asc" -----BEGIN PGP PUBLIC KEY BLOCK----- xsBNBFOMcBYBCACgGjqjoGvbEouQZw/ToiBg9W98AlM2QHV+iNHsEs7kxWhKMjrioyspZKOBy= cWx w3ie3j9uvg9EOB3aN4xiTv4qbnGiTr3oJhkB1gsb6ToJQZ8uxGq2kaV2KL9650I1SJvedYm8O= f8Z d621lSmoKOwlNClALZNew72NjJLEzTalU1OdT7/i1TXkH09XSSI8mEQ/ouNcMvIJNwQpd369y= 9bf IhWUiVXEK7MlRgUG6MvIj6Y3Am/BBLUVbDa4+gmzDC9ezlZkTZG2t14zWPvxXP3FAp2pkW0xq= G7/ 377qptDmrk42GlSKN4z76ELnLxussxc7I2hx18NUcbP8+uty4bMxABEBAAHNHEp1ZXJnZW4gR= 3Jv c3MgPGpnQHBmdXBmLm5ldD7CwHkEEwECACMFAlOMcBYCGwMHCwkIBwMCAQYVCAIJCgsEFgIDA= QIe AQIXgAAKCRCw3p3WKL8TL0KdB/93FcIZ3GCNwFU0u3EjNbNjmXBKDY4FUGNQH2lvWAUy+dnyT= hpw dtF/jQ6j9RwE8VP0+NXcYpGJDWlNb9/JmYqLiX2Q3TyevpB0CA3dbBQp0OW0fgCetToGIQrg0= MbD 1C/sEOv8Mr4NAfbauXjZlvTj30H2jO0u+6WGM6nHwbh2l5O8ZiHkH32iaSTfN7Eu5RnNVUJbv= oPH Z8SlM4KWm8rG+lIkGurqqu5gu8q8ZMKdsdGC4bBxdQKDKHEFExLJK/nRPFmAuGlId1E3fe10v= 5QL +qHI3EIPtyfE7i9Hz6rVwi7lWKgh7pe0ZvatAudZ+JNIlBKptb64FaiIOAWDCx1SzR9KdWVyZ= 2Vu IEdyb3NzIDxqZ3Jvc3NAc3VzZS5jb20+wsB5BBMBAgAjBQJTjHCvAhsDBwsJCAcDAgEGFQgCC= QoL BBYCAwECHgECF4AACgkQsN6d1ii/Ey/HmQf/RtI7kv5A2PS4RF7HoZhPVPogNVbC4YA6lW7Dr= Wf0 teC0RR3MzXfy6pJ+7KLgkqMlrAbN/8Dvjoz78X+5vhH/rDLa9BuZQlhFmvcGtCF8eR0T1v0nC= /nu AFVGy+67q2DH8As3KPu0344TBDpAvr2uYM4tSqxK4DURx5INz4ZZ0WNFHcqsfvlGJALDeE0Lh= ITT d9jLzdDad1pQSToCnLl6SBJZjDOX9QQcyUigZFtCXFst4dlsvddrxyqT1f17+2cFSdu7+ynLm= XBK 7abQ3rwJY8SbRO2iRulogc5vr/RLMMlscDAiDkaFQWLoqHHOdfO9rURssHNN8WkMnQfvUewRz= 80h SnVlcmdlbiBHcm9zcyA8amdyb3NzQG5vdmVsbC5jb20+wsB5BBMBAgAjBQJTjHDXAhsDBwsJC= AcD AgEGFQgCCQoLBBYCAwECHgECF4AACgkQsN6d1ii/Ey8PUQf/ehmgCI9jB9hlgexLvgOtf7PJn= FOX gMLdBQgBlVPO3/D9R8LtF9DBAFPNhlrsfIG/SqICoRCqUcJ96Pn3P7UUinFG/I0ECGF4EvTE1= jnD kfJZr6jrbjgyoZHiw/4BNwSTL9rWASyLgqlA8u1mf+c2yUwcGhgkRAd1gOwungxcwzwqgljf0= N51 N5JfVRHRtyfwq/ge+YEkDGcTU6Y0sPOuj4Dyfm8fJzdfHNQsWq3PnczLVELStJNdapwPOoE+l= otu fe3AM2vAEYJ9rTz3Cki4JFUsgLkHFqGZarrPGi1eyQcXeluldO3m91NK/1xMI3/+8jbO0tsn1= tqS EUGIJi7ox80eSnVlcmdlbiBHcm9zcyA8amdyb3NzQHN1c2UuZGU+wsB5BBMBAgAjBQJTjHDrA= hsD BwsJCAcDAgEGFQgCCQoLBBYCAwECHgECF4AACgkQsN6d1ii/Ey+LhQf9GL45eU5vOowA2u5N3= g3O ZUEBmDHVVbqMtzwlmNC4k9Kx39r5s2vcFl4tXqW7g9/ViXYuiDXb0RfUpZiIUW89siKrkzmQ5= dM7 wRqzgJpJwK8Bn2MIxAKArekWpiCKvBOB/Cc+3EXE78XdlxLyOi/NrmSGRIov0karw2RzMNOu5= D+j LRZQd1Sv27AR+IP3I8U4aqnhLpwhK7MEy9oCILlgZ1QZe49kpcumcZKORmzBTNh30FVKK1Evm= V2x AKDoaEOgQB4iFQLhJCdP1I5aSgM5IVFdn7v5YgEYuJYx37IoN1EblHI//x/e2AaIHpzK5h88N= Eaw QsaNRpNSrcfbFmAg987ATQRTjHAWAQgAyzH6AOODMBjgfWE9VeCgsrwH3exNAU32gLq2xvjpW= nHI s98ndPUDpnoxWQugJ6MpMncr0xSwFmHEgnSEjK/PAjppgmyc57BwKII3sV4on+gDVFJR6Y8ZR= wgn BC5mVM6JjQ5xDk8WRXljExRfUX9pNhdE5eBOZJrDRoLUmmjDtKzWaDhIg/+1Hzz93X4fCQkNV= bVF LELU9bMaLPBG/x5q4iYZ2k2ex6d47YE1ZFdMm6YBYMOljGkZKwYde5ldM9mo45mmwe0icXKLk= pEd IXKTZeKDO+Hdv1aqFuAcccTg9RXDQjmwhC3yEmrmcfl0+rPghO0Iv3OOImwTEe4co3c1mwARA= QAB wsBfBBgBAgAJBQJTjHAWAhsMAAoJELDendYovxMvQ/gH/1ha96vm4P/L+bQpJwrZ/dneZcmEw= Tbe 8YFsw2V/Buv6Z4Mysln3nQK5ZadD534CF7TDVft7fC4tU4PONxF5D+/tvgkPfDAfF77zy2AH1= vJz Q1fOU8lYFpZXTXIHb+559UqvIB8AdgR3SAJGHHt4RKA0F7f5ipYBBrC6cyXJyyoprT10EMvU8= VGi wXvTyJz3fjoYsdFzpWPlJEBRMedCot60g5dmbdrZ5DWClAr0yau47zpWj3enf1tLWaqcsuylW= svi uGjKGw7KHQd3bxALOknAp4dN3QwBYCKuZ7AddY9yjynVaD5X7nF9nO5BjR/i1DG86lem3iBDX= zXs ZDn8R38=3D =3D2wuH -----END PGP PUBLIC KEY BLOCK----- --------------4A99575EED9A2156AA6E4B7A-- --LYk1sPWTt3gNdeLkHnL5vpHg85ia8zJ0d-- --1WhaJPULB0DvvgYmQAFFoXOhtEQXABxqT Content-Type: application/pgp-signature; name="OpenPGP_signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="OpenPGP_signature" -----BEGIN PGP SIGNATURE----- wsB5BAABCAAjFiEEhRJncuj2BJSl0Jf3sN6d1ii/Ey8FAmG3YTgFAwAAAAAACgkQsN6d1ii/Ey+2 pggAnxeSG75rqOP2q1dPe7mqOcmTzY9k2hJfVUUh9zPznzcxX0Sjul6BAO3CKlxYmlYKNngr4atA sMK7YfUPWkVKykfSyyh1dKgMisLxtvwo+4jRoyoLU3KYlCizNgAE9zp/8JQRWtlE4p/BCnhgrIKw l3mn7H+bvh52foABAb5BnAtVRRUEk1DWJ/oPPJv6LA8qCvflFjOKQRbw6PfFGArl2Eh1zV84bUZX XLqkh0F1W8fgRmUaWey54fqGbQkUtNGL9LWijGuncVsS3mKAu4yut1wnh8vjkK/5SCIE9lx/ECWm bZzrsjOMiVfMhNXd1LW/ulfWNZF4MfozA+qmw6xIjw== =Ujo7 -----END PGP SIGNATURE----- --1WhaJPULB0DvvgYmQAFFoXOhtEQXABxqT-- From minios-devel-bounces@lists.xenproject.org Mon Dec 13 21:19:22 2021 Return-path: Envelope-to: archives@lists.xenproject.org Delivery-date: Mon, 13 Dec 2021 21:19:22 +0000 Received: from list by lists.xenproject.org with outflank-mailman.246302.424749 (Exim 4.92) (envelope-from ) id 1mwsj6-0005Qp-U4; Mon, 13 Dec 2021 21:19:16 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 246302.424749; Mon, 13 Dec 2021 21:19:16 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mwsj6-0005Qi-Qq; Mon, 13 Dec 2021 21:19:16 +0000 Received: by outflank-mailman (input) for mailman id 246302; Mon, 13 Dec 2021 21:19:15 +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 1mwsj5-0005QX-7f for minios-devel@lists.xenproject.org; Mon, 13 Dec 2021 21:19:15 +0000 Received: from hera.aquilenet.fr (hera.aquilenet.fr [185.233.100.1]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 507b97a9-5c5a-11ec-85d3-df6b77346a89; Mon, 13 Dec 2021 22:19:11 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 2B80938A; Mon, 13 Dec 2021 22:19:10 +0100 (CET) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id rsLAX-jPuo-M; Mon, 13 Dec 2021 22:19:09 +0100 (CET) Received: from begin (unknown [IPv6:2a01:cb19:956:1b00:de41:a9ff:fe47:ec49]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 664EF18A; Mon, 13 Dec 2021 22:19:09 +0100 (CET) Received: from samy by begin with local (Exim 4.95) (envelope-from ) id 1mwsix-006yxI-AC; Mon, 13 Dec 2021 22:19:07 +0100 X-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-devel" X-Inumbo-ID: 507b97a9-5c5a-11ec-85d3-df6b77346a89 X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Date: Mon, 13 Dec 2021 22:19:07 +0100 From: Samuel Thibault To: Juergen Gross Cc: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org, wl@xen.org Subject: Re: [PATCH 02/10] mini-os: sort and sanitize e820 memory map Message-ID: <20211213211907.lbjjnvayklf7qucb@begin> Mail-Followup-To: Samuel Thibault , Juergen Gross , minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org, wl@xen.org References: <20211206072337.9517-1-jgross@suse.com> <20211206072337.9517-3-jgross@suse.com> <20211212000558.232nzs7k5lklpbym@begin> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Organization: I am not organized User-Agent: NeoMutt/20170609 (1.8.3) X-Spamd-Bar: / Authentication-Results: hera.aquilenet.fr; none X-Rspamd-Server: hera X-Rspamd-Queue-Id: 2B80938A X-Spamd-Result: default: False [0.40 / 15.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; HAS_ORG_HEADER(0.00)[]; RCVD_COUNT_THREE(0.00)[3]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_LAST(0.00)[]; MID_RHS_NOT_FQDN(0.50)[] Juergen Gross, le lun. 13 déc. 2021 15:56:21 +0100, a ecrit: > On 12.12.21 01:05, Samuel Thibault wrote: > > Hello, > > > > Juergen Gross, le lun. 06 déc. 2021 08:23:29 +0100, a ecrit: > > > - align the entries to page boundaries > > > > > + /* Adjust map entries to page boundaries. */ > > > + for ( i = 0; i < e820_entries; i++ ) > > > + { > > > + end = (e820_map[i].addr + e820_map[i].size + PAGE_SIZE - 1) & PAGE_MASK; > > > + e820_map[i].addr &= PAGE_MASK; > > > + e820_map[i].size = end - e820_map[i].addr; > > > + } > > > > Mmm, what if the previous entry ends after the aligned start? > > > > On real machines that does happen, and you'd rather round up the start > > address of usable areas, rather than rounding it down (and conversely > > for the end). > > I think you are partially right. :-) > > Entries for resources managed by Mini-OS (RAM, maybe NVME?) should be > rounded to cover only complete pages (start rounded up, end rounded > down), but all other entries should be rounded to cover the complete > area (start rounded down, end rounded up) in order not to use any > partial used page for e.g. mapping foreign pages. Right! > > > + /* Sort entries by start address. */ > > > + for ( i = 0; i < e820_entries - 1; i++ ) > > > + { > > > + if ( e820_map[i].addr > e820_map[i + 1].addr ) > > > + { > > > + e820_swap_entries(i, i + 1); > > > + i = -1; > > > + } > > > + } > > > > This looks O(n^3) to me? A bubble sort like this should be fine: > > > > /* Sort entries by start address. */ > > for ( last = e820_entries; last > 1; last-- ) > > { > > for ( i = 0; i < last - 1; i++ ) > > { > > if ( e820_map[i].addr > e820_map[i + 1].addr ) > > { > > e820_swap_entries(i, i + 1); > > } > > } > > } > > Hmm, depends. > > Assuming a rather well sorted map my version is O(n), while yours > is still O(n^2). Right, I was a bit lazy :) This should be fine: /* Sort entries by start address. */ for ( i = 1; i < e820_entries; i++ ) for ( j = i; j > 0 && e820_map[j-1].addr > e820_map[j].addr ) ; j-- ) e820_swap_entries(j - 1, j); > I'm fine both ways, whatever you prefer. I really prefer for loops which don't unexpectedly modify their loop index, that's much less scary :) Samuel From minios-devel-bounces@lists.xenproject.org Mon Dec 13 21:22:10 2021 Return-path: Envelope-to: archives@lists.xenproject.org Delivery-date: Mon, 13 Dec 2021 21:22:10 +0000 Received: from list by lists.xenproject.org with outflank-mailman.246308.424764 (Exim 4.92) (envelope-from ) id 1mwslt-0006r0-FF; Mon, 13 Dec 2021 21:22:09 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 246308.424764; Mon, 13 Dec 2021 21:22:09 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mwslt-0006qt-CM; Mon, 13 Dec 2021 21:22:09 +0000 Received: by outflank-mailman (input) for mailman id 246308; Mon, 13 Dec 2021 21:22:09 +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 1mwslt-0006qn-3g for minios-devel@lists.xenproject.org; Mon, 13 Dec 2021 21:22:09 +0000 Received: from hera.aquilenet.fr (hera.aquilenet.fr [185.233.100.1]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id ba0c8745-5c5a-11ec-85d3-df6b77346a89; Mon, 13 Dec 2021 22:22:08 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id C313538A; Mon, 13 Dec 2021 22:22:07 +0100 (CET) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 9VvTf2Be1UGX; Mon, 13 Dec 2021 22:22:07 +0100 (CET) Received: from begin (unknown [IPv6:2a01:cb19:956:1b00:de41:a9ff:fe47:ec49]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 25AD4229; Mon, 13 Dec 2021 22:22:07 +0100 (CET) Received: from samy by begin with local (Exim 4.95) (envelope-from ) id 1mwslq-006yzC-C0; Mon, 13 Dec 2021 22:22:06 +0100 X-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-devel" X-Inumbo-ID: ba0c8745-5c5a-11ec-85d3-df6b77346a89 X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Date: Mon, 13 Dec 2021 22:22:06 +0100 From: Samuel Thibault To: Juergen Gross Cc: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org, wl@xen.org Subject: Re: [PATCH 03/10] mini-os: don't assume contiguous RAM when initializing in PVH mode Message-ID: <20211213212206.htg4eykr32x63swk@begin> Mail-Followup-To: Samuel Thibault , Juergen Gross , minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org, wl@xen.org References: <20211206072337.9517-1-jgross@suse.com> <20211206072337.9517-4-jgross@suse.com> <20211212001542.qhz7wfdwq7k5ymxr@begin> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Organization: I am not organized User-Agent: NeoMutt/20170609 (1.8.3) X-Spamd-Bar: / Authentication-Results: hera.aquilenet.fr; none X-Rspamd-Server: hera X-Rspamd-Queue-Id: C313538A X-Spamd-Result: default: False [0.40 / 15.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; HAS_ORG_HEADER(0.00)[]; RCVD_COUNT_THREE(0.00)[3]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_LAST(0.00)[]; MID_RHS_NOT_FQDN(0.50)[] Juergen Gross, le lun. 13 déc. 2021 15:58:58 +0100, a ecrit: > On 12.12.21 01:15, Samuel Thibault wrote: > > Juergen Gross, le lun. 06 déc. 2021 08:23:30 +0100, a ecrit: > > > - unsigned long pfn, max = 0; > > > + unsigned long pfns, max = 0; > > > > I'd say rather rename max to start. > > > > > e820_get_memmap(); > > > @@ -166,9 +166,12 @@ unsigned long e820_get_maxpfn(void) > > > { > > > if ( e820_map[i].type != E820_RAM ) > > > continue; > > > - pfn = (e820_map[i].addr + e820_map[i].size) >> PAGE_SHIFT; > > > - if ( pfn > max ) > > > - max = pfn; > > > + pfns = e820_map[i].size >> PAGE_SHIFT; > > > + max = e820_map[i].addr >> PAGE_SHIFT; > > > > since it's it's always the start of the e820 entry. > > > > > + if ( pages <= pfns ) > > > + return max + pages; > > > + pages -= pfns; > > > + max += pfns; > > > > Here we don't need do change max, only pages. > > It is needed in case the loop is finished. > > And this was the reason for naming it max. Ah, ok. At first read the name was confusing me. Perhaps better use two variables then: start and max, so that we have start = e820_map[i].addr >> PAGE_SHIFT; if ( pages <= pfns ) return start + pages; pages -= pfns; max = start + pfns; Samuel From minios-devel-bounces@lists.xenproject.org Tue Dec 14 06:33:08 2021 Return-path: Envelope-to: archives@lists.xenproject.org Delivery-date: Tue, 14 Dec 2021 06:33:08 +0000 Received: from list by lists.xenproject.org with outflank-mailman.246385.424907 (Exim 4.92) (envelope-from ) id 1mx1N4-00059i-MO; Tue, 14 Dec 2021 06:33:06 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 246385.424907; Tue, 14 Dec 2021 06:33:06 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mx1N4-00059b-Io; Tue, 14 Dec 2021 06:33:06 +0000 Received: by outflank-mailman (input) for mailman id 246385; Tue, 14 Dec 2021 06:33:04 +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 1mx1N2-0004tn-Qd for minios-devel@lists.xenproject.org; Tue, 14 Dec 2021 06:33:04 +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 b0174287-5ca7-11ec-85d3-df6b77346a89; Tue, 14 Dec 2021 07:33:02 +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 37B8B1F3C3; Tue, 14 Dec 2021 06:33:02 +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 0D7BA13A1E; Tue, 14 Dec 2021 06:33:02 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id OipvAZ46uGGpYwAAMHmgww (envelope-from ); Tue, 14 Dec 2021 06:33:02 +0000 X-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-devel" X-Inumbo-ID: b0174287-5ca7-11ec-85d3-df6b77346a89 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1639463582; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=zkOKhXkH4pkDY9AKrTFHL8kH6KTPVZJSV4sapU/Y16A=; b=KlSc8YUqYzyKyYZtLwIgDuXbf47EAznQqzkkfz90YWThEY/zAWJRbCurDVQgU2ZvfYUgpf a+FkdJUtlVlTybP/zap5EkXzZBDqBXUxyNIoWL/nvLMcf+2nhcInWCG0SoZTJcnvJ5u7FZ oawzglbUi39z+1xcHXJgDulb/LV1VAY= Subject: Re: [PATCH 02/10] mini-os: sort and sanitize e820 memory map To: Samuel Thibault , minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org, wl@xen.org References: <20211206072337.9517-1-jgross@suse.com> <20211206072337.9517-3-jgross@suse.com> <20211212000558.232nzs7k5lklpbym@begin> <20211213211907.lbjjnvayklf7qucb@begin> From: Juergen Gross Message-ID: <45aa9ea7-115e-af76-caf7-80b7d6f31163@suse.com> Date: Tue, 14 Dec 2021 07:33:01 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: <20211213211907.lbjjnvayklf7qucb@begin> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="CbYhcGkjwpmxHpKbfaKiDsJjUJm4KHYTy" This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --CbYhcGkjwpmxHpKbfaKiDsJjUJm4KHYTy Content-Type: multipart/mixed; boundary="lmMcK3byhWMpLkA5SAnQyF3zTT6EV3wTE"; protected-headers="v1" From: Juergen Gross To: Samuel Thibault , minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org, wl@xen.org Message-ID: <45aa9ea7-115e-af76-caf7-80b7d6f31163@suse.com> Subject: Re: [PATCH 02/10] mini-os: sort and sanitize e820 memory map References: <20211206072337.9517-1-jgross@suse.com> <20211206072337.9517-3-jgross@suse.com> <20211212000558.232nzs7k5lklpbym@begin> <20211213211907.lbjjnvayklf7qucb@begin> In-Reply-To: <20211213211907.lbjjnvayklf7qucb@begin> --lmMcK3byhWMpLkA5SAnQyF3zTT6EV3wTE Content-Type: multipart/mixed; boundary="------------576DF9A64280D1107F628895" Content-Language: en-US This is a multi-part message in MIME format. --------------576DF9A64280D1107F628895 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable On 13.12.21 22:19, Samuel Thibault wrote: > Juergen Gross, le lun. 13 d=C3=A9c. 2021 15:56:21 +0100, a ecrit: >> On 12.12.21 01:05, Samuel Thibault wrote: >>> Hello, >>> >>> Juergen Gross, le lun. 06 d=C3=A9c. 2021 08:23:29 +0100, a ecrit: >>>> - align the entries to page boundaries >>> >>>> + /* 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) & PAGE_MASK; >>>> + e820_map[i].addr &=3D PAGE_MASK; >>>> + e820_map[i].size =3D end - e820_map[i].addr; >>>> + } >>> >>> Mmm, what if the previous entry ends after the aligned start? >>> >>> On real machines that does happen, and you'd rather round up the star= t >>> address of usable areas, rather than rounding it down (and conversely= >>> for the end). >> >> I think you are partially right. :-) >> >> Entries for resources managed by Mini-OS (RAM, maybe NVME?) should be >> rounded to cover only complete pages (start rounded up, end rounded >> down), but all other entries should be rounded to cover the complete >> area (start rounded down, end rounded up) in order not to use any >> partial used page for e.g. mapping foreign pages. >=20 > Right! >=20 >>>> + /* 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; >>>> + } >>>> + } >>> >>> This looks O(n^3) to me? A bubble sort like this should be fine: >>> >>> /* Sort entries by start address. */ >>> for ( last =3D e820_entries; last > 1; last-- ) >>> { >>> for ( i =3D 0; i < last - 1; i++ ) >>> { >>> if ( e820_map[i].addr > e820_map[i + 1].addr ) >>> { >>> e820_swap_entries(i, i + 1); >>> } >>> } >>> } >> >> Hmm, depends. >> >> Assuming a rather well sorted map my version is O(n), while yours >> is still O(n^2). >=20 > Right, I was a bit lazy :) >=20 > This should be fine: >=20 > /* Sort entries by start address. */ > 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); >=20 >> I'm fine both ways, whatever you prefer. >=20 > I really prefer for loops which don't unexpectedly modify their loop > index, that's much less scary :) Agreed, I'll take your version. Juergen --------------576DF9A64280D1107F628895 Content-Type: application/pgp-keys; name="OpenPGP_0xB0DE9DD628BF132F.asc" Content-Transfer-Encoding: quoted-printable Content-Description: OpenPGP public key Content-Disposition: attachment; filename="OpenPGP_0xB0DE9DD628BF132F.asc" -----BEGIN PGP PUBLIC KEY BLOCK----- xsBNBFOMcBYBCACgGjqjoGvbEouQZw/ToiBg9W98AlM2QHV+iNHsEs7kxWhKMjrioyspZKOBy= cWx w3ie3j9uvg9EOB3aN4xiTv4qbnGiTr3oJhkB1gsb6ToJQZ8uxGq2kaV2KL9650I1SJvedYm8O= f8Z d621lSmoKOwlNClALZNew72NjJLEzTalU1OdT7/i1TXkH09XSSI8mEQ/ouNcMvIJNwQpd369y= 9bf IhWUiVXEK7MlRgUG6MvIj6Y3Am/BBLUVbDa4+gmzDC9ezlZkTZG2t14zWPvxXP3FAp2pkW0xq= G7/ 377qptDmrk42GlSKN4z76ELnLxussxc7I2hx18NUcbP8+uty4bMxABEBAAHNHEp1ZXJnZW4gR= 3Jv c3MgPGpnQHBmdXBmLm5ldD7CwHkEEwECACMFAlOMcBYCGwMHCwkIBwMCAQYVCAIJCgsEFgIDA= QIe AQIXgAAKCRCw3p3WKL8TL0KdB/93FcIZ3GCNwFU0u3EjNbNjmXBKDY4FUGNQH2lvWAUy+dnyT= hpw dtF/jQ6j9RwE8VP0+NXcYpGJDWlNb9/JmYqLiX2Q3TyevpB0CA3dbBQp0OW0fgCetToGIQrg0= MbD 1C/sEOv8Mr4NAfbauXjZlvTj30H2jO0u+6WGM6nHwbh2l5O8ZiHkH32iaSTfN7Eu5RnNVUJbv= oPH Z8SlM4KWm8rG+lIkGurqqu5gu8q8ZMKdsdGC4bBxdQKDKHEFExLJK/nRPFmAuGlId1E3fe10v= 5QL +qHI3EIPtyfE7i9Hz6rVwi7lWKgh7pe0ZvatAudZ+JNIlBKptb64FaiIOAWDCx1SzR9KdWVyZ= 2Vu IEdyb3NzIDxqZ3Jvc3NAc3VzZS5jb20+wsB5BBMBAgAjBQJTjHCvAhsDBwsJCAcDAgEGFQgCC= QoL BBYCAwECHgECF4AACgkQsN6d1ii/Ey/HmQf/RtI7kv5A2PS4RF7HoZhPVPogNVbC4YA6lW7Dr= Wf0 teC0RR3MzXfy6pJ+7KLgkqMlrAbN/8Dvjoz78X+5vhH/rDLa9BuZQlhFmvcGtCF8eR0T1v0nC= /nu AFVGy+67q2DH8As3KPu0344TBDpAvr2uYM4tSqxK4DURx5INz4ZZ0WNFHcqsfvlGJALDeE0Lh= ITT d9jLzdDad1pQSToCnLl6SBJZjDOX9QQcyUigZFtCXFst4dlsvddrxyqT1f17+2cFSdu7+ynLm= XBK 7abQ3rwJY8SbRO2iRulogc5vr/RLMMlscDAiDkaFQWLoqHHOdfO9rURssHNN8WkMnQfvUewRz= 80h SnVlcmdlbiBHcm9zcyA8amdyb3NzQG5vdmVsbC5jb20+wsB5BBMBAgAjBQJTjHDXAhsDBwsJC= AcD AgEGFQgCCQoLBBYCAwECHgECF4AACgkQsN6d1ii/Ey8PUQf/ehmgCI9jB9hlgexLvgOtf7PJn= FOX gMLdBQgBlVPO3/D9R8LtF9DBAFPNhlrsfIG/SqICoRCqUcJ96Pn3P7UUinFG/I0ECGF4EvTE1= jnD kfJZr6jrbjgyoZHiw/4BNwSTL9rWASyLgqlA8u1mf+c2yUwcGhgkRAd1gOwungxcwzwqgljf0= N51 N5JfVRHRtyfwq/ge+YEkDGcTU6Y0sPOuj4Dyfm8fJzdfHNQsWq3PnczLVELStJNdapwPOoE+l= otu fe3AM2vAEYJ9rTz3Cki4JFUsgLkHFqGZarrPGi1eyQcXeluldO3m91NK/1xMI3/+8jbO0tsn1= tqS EUGIJi7ox80eSnVlcmdlbiBHcm9zcyA8amdyb3NzQHN1c2UuZGU+wsB5BBMBAgAjBQJTjHDrA= hsD BwsJCAcDAgEGFQgCCQoLBBYCAwECHgECF4AACgkQsN6d1ii/Ey+LhQf9GL45eU5vOowA2u5N3= g3O ZUEBmDHVVbqMtzwlmNC4k9Kx39r5s2vcFl4tXqW7g9/ViXYuiDXb0RfUpZiIUW89siKrkzmQ5= dM7 wRqzgJpJwK8Bn2MIxAKArekWpiCKvBOB/Cc+3EXE78XdlxLyOi/NrmSGRIov0karw2RzMNOu5= D+j LRZQd1Sv27AR+IP3I8U4aqnhLpwhK7MEy9oCILlgZ1QZe49kpcumcZKORmzBTNh30FVKK1Evm= V2x AKDoaEOgQB4iFQLhJCdP1I5aSgM5IVFdn7v5YgEYuJYx37IoN1EblHI//x/e2AaIHpzK5h88N= Eaw QsaNRpNSrcfbFmAg987ATQRTjHAWAQgAyzH6AOODMBjgfWE9VeCgsrwH3exNAU32gLq2xvjpW= nHI s98ndPUDpnoxWQugJ6MpMncr0xSwFmHEgnSEjK/PAjppgmyc57BwKII3sV4on+gDVFJR6Y8ZR= wgn BC5mVM6JjQ5xDk8WRXljExRfUX9pNhdE5eBOZJrDRoLUmmjDtKzWaDhIg/+1Hzz93X4fCQkNV= bVF LELU9bMaLPBG/x5q4iYZ2k2ex6d47YE1ZFdMm6YBYMOljGkZKwYde5ldM9mo45mmwe0icXKLk= pEd IXKTZeKDO+Hdv1aqFuAcccTg9RXDQjmwhC3yEmrmcfl0+rPghO0Iv3OOImwTEe4co3c1mwARA= QAB wsBfBBgBAgAJBQJTjHAWAhsMAAoJELDendYovxMvQ/gH/1ha96vm4P/L+bQpJwrZ/dneZcmEw= Tbe 8YFsw2V/Buv6Z4Mysln3nQK5ZadD534CF7TDVft7fC4tU4PONxF5D+/tvgkPfDAfF77zy2AH1= vJz Q1fOU8lYFpZXTXIHb+559UqvIB8AdgR3SAJGHHt4RKA0F7f5ipYBBrC6cyXJyyoprT10EMvU8= VGi wXvTyJz3fjoYsdFzpWPlJEBRMedCot60g5dmbdrZ5DWClAr0yau47zpWj3enf1tLWaqcsuylW= svi uGjKGw7KHQd3bxALOknAp4dN3QwBYCKuZ7AddY9yjynVaD5X7nF9nO5BjR/i1DG86lem3iBDX= zXs ZDn8R38=3D =3D2wuH -----END PGP PUBLIC KEY BLOCK----- --------------576DF9A64280D1107F628895-- --lmMcK3byhWMpLkA5SAnQyF3zTT6EV3wTE-- --CbYhcGkjwpmxHpKbfaKiDsJjUJm4KHYTy Content-Type: application/pgp-signature; name="OpenPGP_signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="OpenPGP_signature" -----BEGIN PGP SIGNATURE----- wsB5BAABCAAjFiEEhRJncuj2BJSl0Jf3sN6d1ii/Ey8FAmG4Op0FAwAAAAAACgkQsN6d1ii/Ey+q YQf+MkWDkcMx4XqdV9HY4CK+Jlk7nenbn0gSJCE+isOE5i2At+lqk4cEDKOIo7jOal24ycSv5NhJ cAsEVq/fk9jYSK/19q5Z2vGqjQw/0bdXtkVZC83BuPHrH6VFjCsdgovzg97QpT/wRNgRGS5sHOg8 0ZgNySMEBs9bUzeMbiFaiwtZpaD8yOWgu52HfDNChw94+CtQxAKewbe7KZAmXTi7fnJikQKfNqFY JxlbvAV0jNCkHu6Y8tx12skm7IDviuTmMxmTS0YY9nIYVPegrgtxyl0300RSGNhoUuF49ruM4U81 CliM9Ov+6AXuXiya/8XwwTBH9BA5CHuuY0pFoIweVw== =jJ9C -----END PGP SIGNATURE----- --CbYhcGkjwpmxHpKbfaKiDsJjUJm4KHYTy-- From minios-devel-bounces@lists.xenproject.org Tue Dec 14 06:35:59 2021 Return-path: Envelope-to: archives@lists.xenproject.org Delivery-date: Tue, 14 Dec 2021 06:35:59 +0000 Received: from list by lists.xenproject.org with outflank-mailman.246390.424910 (Exim 4.92) (envelope-from ) id 1mx1Pq-0005aY-Tv; Tue, 14 Dec 2021 06:35:58 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 246390.424910; Tue, 14 Dec 2021 06:35:58 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mx1Pq-0005aR-R1; Tue, 14 Dec 2021 06:35:58 +0000 Received: by outflank-mailman (input) for mailman id 246390; Tue, 14 Dec 2021 06:35:57 +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 1mx1Pp-0005aG-0S for minios-devel@lists.xenproject.org; Tue, 14 Dec 2021 06:35:57 +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 175d0cab-5ca8-11ec-9e60-abaf8a552007; Tue, 14 Dec 2021 07:35:56 +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 AA2C61F3C3; Tue, 14 Dec 2021 06:35:55 +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 8126D13A1E; Tue, 14 Dec 2021 06:35:55 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id d5SZHUs7uGGNZAAAMHmgww (envelope-from ); Tue, 14 Dec 2021 06:35:55 +0000 X-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-devel" X-Inumbo-ID: 175d0cab-5ca8-11ec-9e60-abaf8a552007 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1639463755; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=c2zscTZWCfdTnNvE2ycq2IkmlOcYS06khPxhTTuwdj8=; b=KqIm74P6gtnRbBc1mgJyFbB+sJxsnlM9IdzCdWz3CfZc5hYBu+GpjoEaThguP0yxq2waGU pmYVk298mMlGRNQq4MJSs4KtswGYtW5rybV9A0PVP7B2tv4rwuBTwxaauPEvNoXl9Ii1EZ cXMYd9FGA4rBv5H124TNY+snzGWfx/c= Subject: Re: [PATCH 03/10] mini-os: don't assume contiguous RAM when initializing in PVH mode To: Samuel Thibault , minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org, wl@xen.org References: <20211206072337.9517-1-jgross@suse.com> <20211206072337.9517-4-jgross@suse.com> <20211212001542.qhz7wfdwq7k5ymxr@begin> <20211213212206.htg4eykr32x63swk@begin> From: Juergen Gross Message-ID: <1a2e80ed-9077-6867-5426-e7e6171feab5@suse.com> Date: Tue, 14 Dec 2021 07:35:54 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: <20211213212206.htg4eykr32x63swk@begin> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="llBbEvctv1ssYaQy46gzgggqDbLQTwPwo" This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --llBbEvctv1ssYaQy46gzgggqDbLQTwPwo Content-Type: multipart/mixed; boundary="EjDtrtdBhh5fOOFVQ4C2WCbdOs47GX0ua"; protected-headers="v1" From: Juergen Gross To: Samuel Thibault , minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org, wl@xen.org Message-ID: <1a2e80ed-9077-6867-5426-e7e6171feab5@suse.com> Subject: Re: [PATCH 03/10] mini-os: don't assume contiguous RAM when initializing in PVH mode References: <20211206072337.9517-1-jgross@suse.com> <20211206072337.9517-4-jgross@suse.com> <20211212001542.qhz7wfdwq7k5ymxr@begin> <20211213212206.htg4eykr32x63swk@begin> In-Reply-To: <20211213212206.htg4eykr32x63swk@begin> --EjDtrtdBhh5fOOFVQ4C2WCbdOs47GX0ua Content-Type: multipart/mixed; boundary="------------347B5882F2F1F0BAC21C4DBE" Content-Language: en-US This is a multi-part message in MIME format. --------------347B5882F2F1F0BAC21C4DBE Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable On 13.12.21 22:22, Samuel Thibault wrote: > Juergen Gross, le lun. 13 d=C3=A9c. 2021 15:58:58 +0100, a ecrit: >> On 12.12.21 01:15, Samuel Thibault wrote: >>> Juergen Gross, le lun. 06 d=C3=A9c. 2021 08:23:30 +0100, a ecrit: >>>> - unsigned long pfn, max =3D 0; >>>> + unsigned long pfns, max =3D 0; >>> >>> I'd say rather rename max to start. >>> >>>> e820_get_memmap(); >>>> @@ -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; >>> >>> since it's it's always the start of the e820 entry. >>> >>>> + if ( pages <=3D pfns ) >>>> + return max + pages; >>>> + pages -=3D pfns; >>>> + max +=3D pfns; >>> >>> Here we don't need do change max, only pages. >> >> It is needed in case the loop is finished. >> >> And this was the reason for naming it max. >=20 > Ah, ok. >=20 > At first read the name was confusing me. Perhaps better use two > variables then: start and max, so that we have >=20 > start =3D e820_map[i].addr >> PAGE_SHIFT; > if ( pages <=3D pfns ) > return start + pages; > pages -=3D pfns; > max =3D start + pfns; Hmm, or I can rename max to start, drop the "max +=3D pfns;" and do a "return start + pfns;" at the end of the function. Juergen --------------347B5882F2F1F0BAC21C4DBE Content-Type: application/pgp-keys; name="OpenPGP_0xB0DE9DD628BF132F.asc" Content-Transfer-Encoding: quoted-printable Content-Description: OpenPGP public key Content-Disposition: attachment; filename="OpenPGP_0xB0DE9DD628BF132F.asc" -----BEGIN PGP PUBLIC KEY BLOCK----- xsBNBFOMcBYBCACgGjqjoGvbEouQZw/ToiBg9W98AlM2QHV+iNHsEs7kxWhKMjrioyspZKOBy= cWx w3ie3j9uvg9EOB3aN4xiTv4qbnGiTr3oJhkB1gsb6ToJQZ8uxGq2kaV2KL9650I1SJvedYm8O= f8Z d621lSmoKOwlNClALZNew72NjJLEzTalU1OdT7/i1TXkH09XSSI8mEQ/ouNcMvIJNwQpd369y= 9bf IhWUiVXEK7MlRgUG6MvIj6Y3Am/BBLUVbDa4+gmzDC9ezlZkTZG2t14zWPvxXP3FAp2pkW0xq= G7/ 377qptDmrk42GlSKN4z76ELnLxussxc7I2hx18NUcbP8+uty4bMxABEBAAHNHEp1ZXJnZW4gR= 3Jv c3MgPGpnQHBmdXBmLm5ldD7CwHkEEwECACMFAlOMcBYCGwMHCwkIBwMCAQYVCAIJCgsEFgIDA= QIe AQIXgAAKCRCw3p3WKL8TL0KdB/93FcIZ3GCNwFU0u3EjNbNjmXBKDY4FUGNQH2lvWAUy+dnyT= hpw dtF/jQ6j9RwE8VP0+NXcYpGJDWlNb9/JmYqLiX2Q3TyevpB0CA3dbBQp0OW0fgCetToGIQrg0= MbD 1C/sEOv8Mr4NAfbauXjZlvTj30H2jO0u+6WGM6nHwbh2l5O8ZiHkH32iaSTfN7Eu5RnNVUJbv= oPH Z8SlM4KWm8rG+lIkGurqqu5gu8q8ZMKdsdGC4bBxdQKDKHEFExLJK/nRPFmAuGlId1E3fe10v= 5QL +qHI3EIPtyfE7i9Hz6rVwi7lWKgh7pe0ZvatAudZ+JNIlBKptb64FaiIOAWDCx1SzR9KdWVyZ= 2Vu IEdyb3NzIDxqZ3Jvc3NAc3VzZS5jb20+wsB5BBMBAgAjBQJTjHCvAhsDBwsJCAcDAgEGFQgCC= QoL BBYCAwECHgECF4AACgkQsN6d1ii/Ey/HmQf/RtI7kv5A2PS4RF7HoZhPVPogNVbC4YA6lW7Dr= Wf0 teC0RR3MzXfy6pJ+7KLgkqMlrAbN/8Dvjoz78X+5vhH/rDLa9BuZQlhFmvcGtCF8eR0T1v0nC= /nu AFVGy+67q2DH8As3KPu0344TBDpAvr2uYM4tSqxK4DURx5INz4ZZ0WNFHcqsfvlGJALDeE0Lh= ITT d9jLzdDad1pQSToCnLl6SBJZjDOX9QQcyUigZFtCXFst4dlsvddrxyqT1f17+2cFSdu7+ynLm= XBK 7abQ3rwJY8SbRO2iRulogc5vr/RLMMlscDAiDkaFQWLoqHHOdfO9rURssHNN8WkMnQfvUewRz= 80h SnVlcmdlbiBHcm9zcyA8amdyb3NzQG5vdmVsbC5jb20+wsB5BBMBAgAjBQJTjHDXAhsDBwsJC= AcD AgEGFQgCCQoLBBYCAwECHgECF4AACgkQsN6d1ii/Ey8PUQf/ehmgCI9jB9hlgexLvgOtf7PJn= FOX gMLdBQgBlVPO3/D9R8LtF9DBAFPNhlrsfIG/SqICoRCqUcJ96Pn3P7UUinFG/I0ECGF4EvTE1= jnD kfJZr6jrbjgyoZHiw/4BNwSTL9rWASyLgqlA8u1mf+c2yUwcGhgkRAd1gOwungxcwzwqgljf0= N51 N5JfVRHRtyfwq/ge+YEkDGcTU6Y0sPOuj4Dyfm8fJzdfHNQsWq3PnczLVELStJNdapwPOoE+l= otu fe3AM2vAEYJ9rTz3Cki4JFUsgLkHFqGZarrPGi1eyQcXeluldO3m91NK/1xMI3/+8jbO0tsn1= tqS EUGIJi7ox80eSnVlcmdlbiBHcm9zcyA8amdyb3NzQHN1c2UuZGU+wsB5BBMBAgAjBQJTjHDrA= hsD BwsJCAcDAgEGFQgCCQoLBBYCAwECHgECF4AACgkQsN6d1ii/Ey+LhQf9GL45eU5vOowA2u5N3= g3O ZUEBmDHVVbqMtzwlmNC4k9Kx39r5s2vcFl4tXqW7g9/ViXYuiDXb0RfUpZiIUW89siKrkzmQ5= dM7 wRqzgJpJwK8Bn2MIxAKArekWpiCKvBOB/Cc+3EXE78XdlxLyOi/NrmSGRIov0karw2RzMNOu5= D+j LRZQd1Sv27AR+IP3I8U4aqnhLpwhK7MEy9oCILlgZ1QZe49kpcumcZKORmzBTNh30FVKK1Evm= V2x AKDoaEOgQB4iFQLhJCdP1I5aSgM5IVFdn7v5YgEYuJYx37IoN1EblHI//x/e2AaIHpzK5h88N= Eaw QsaNRpNSrcfbFmAg987ATQRTjHAWAQgAyzH6AOODMBjgfWE9VeCgsrwH3exNAU32gLq2xvjpW= nHI s98ndPUDpnoxWQugJ6MpMncr0xSwFmHEgnSEjK/PAjppgmyc57BwKII3sV4on+gDVFJR6Y8ZR= wgn BC5mVM6JjQ5xDk8WRXljExRfUX9pNhdE5eBOZJrDRoLUmmjDtKzWaDhIg/+1Hzz93X4fCQkNV= bVF LELU9bMaLPBG/x5q4iYZ2k2ex6d47YE1ZFdMm6YBYMOljGkZKwYde5ldM9mo45mmwe0icXKLk= pEd IXKTZeKDO+Hdv1aqFuAcccTg9RXDQjmwhC3yEmrmcfl0+rPghO0Iv3OOImwTEe4co3c1mwARA= QAB wsBfBBgBAgAJBQJTjHAWAhsMAAoJELDendYovxMvQ/gH/1ha96vm4P/L+bQpJwrZ/dneZcmEw= Tbe 8YFsw2V/Buv6Z4Mysln3nQK5ZadD534CF7TDVft7fC4tU4PONxF5D+/tvgkPfDAfF77zy2AH1= vJz Q1fOU8lYFpZXTXIHb+559UqvIB8AdgR3SAJGHHt4RKA0F7f5ipYBBrC6cyXJyyoprT10EMvU8= VGi wXvTyJz3fjoYsdFzpWPlJEBRMedCot60g5dmbdrZ5DWClAr0yau47zpWj3enf1tLWaqcsuylW= svi uGjKGw7KHQd3bxALOknAp4dN3QwBYCKuZ7AddY9yjynVaD5X7nF9nO5BjR/i1DG86lem3iBDX= zXs ZDn8R38=3D =3D2wuH -----END PGP PUBLIC KEY BLOCK----- --------------347B5882F2F1F0BAC21C4DBE-- --EjDtrtdBhh5fOOFVQ4C2WCbdOs47GX0ua-- --llBbEvctv1ssYaQy46gzgggqDbLQTwPwo Content-Type: application/pgp-signature; name="OpenPGP_signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="OpenPGP_signature" -----BEGIN PGP SIGNATURE----- wsB5BAABCAAjFiEEhRJncuj2BJSl0Jf3sN6d1ii/Ey8FAmG4O0oFAwAAAAAACgkQsN6d1ii/Ey/b PAf+IWE544eHGTWaSvvHe0MkZgPT+JFOlO5xNTc1nASvtqDWqg4o2F4RkLvdo+xYl6eHrlCLnhHG ai3rSdYA6PMdU3EVoAzqW/p1xHgG9z1GG3Fpw+/rEVytNaSMyzQFUi9TuPTAsXYkKa0gU5hfBVCb 17UISZtNemtIeCOwl5jhe6o79A3EUXg8m4flZiWWJF+XboF4P3bs8wyXU3R2bCDSaC6jZcxkdE4Q dljL4TJAxBUHTLs0Iwu09zWoWIxhiyKdVoHeyGQVqThvyGmfw8rCJf9PxgzA02sNgqz1LXEpAgRU xf3B9wMF8N+Uto2uvLMvVFZjxnaQhsZE7QjTfWcQ5g== =vFNO -----END PGP SIGNATURE----- --llBbEvctv1ssYaQy46gzgggqDbLQTwPwo-- From minios-devel-bounces@lists.xenproject.org Tue Dec 14 07:40:39 2021 Return-path: Envelope-to: archives@lists.xenproject.org Delivery-date: Tue, 14 Dec 2021 07:40:39 +0000 Received: from list by lists.xenproject.org with outflank-mailman.246402.424928 (Exim 4.92) (envelope-from ) id 1mx2QO-0004yE-52; Tue, 14 Dec 2021 07:40:36 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 246402.424928; Tue, 14 Dec 2021 07:40:36 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mx2QO-0004xe-1r; Tue, 14 Dec 2021 07:40:36 +0000 Received: by outflank-mailman (input) for mailman id 246402; Tue, 14 Dec 2021 07:40:35 +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 1mx2QN-0004vM-65 for minios-devel@lists.xenproject.org; Tue, 14 Dec 2021 07:40:35 +0000 Received: from hera.aquilenet.fr (hera.aquilenet.fr [185.233.100.1]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 1d8f7fcf-5cb1-11ec-9e60-abaf8a552007; Tue, 14 Dec 2021 08:40:32 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 1670C32E; Tue, 14 Dec 2021 08:40:31 +0100 (CET) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 5YDjt2mkzHDQ; Tue, 14 Dec 2021 08:40:30 +0100 (CET) Received: from begin (unknown [IPv6:2a01:cb19:956:1b00:de41:a9ff:fe47:ec49]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 6BC3C230; Tue, 14 Dec 2021 08:40:30 +0100 (CET) Received: from samy by begin with local (Exim 4.95) (envelope-from ) id 1mx2QI-008b4w-04; Tue, 14 Dec 2021 08:40:30 +0100 X-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-devel" X-Inumbo-ID: 1d8f7fcf-5cb1-11ec-9e60-abaf8a552007 X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Date: Tue, 14 Dec 2021 08:40:29 +0100 From: Samuel Thibault To: Juergen Gross Cc: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org, wl@xen.org Subject: Re: [PATCH 03/10] mini-os: don't assume contiguous RAM when initializing in PVH mode Message-ID: <20211214074029.5qivn7adgp32nrfj@begin> Mail-Followup-To: Samuel Thibault , Juergen Gross , minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org, wl@xen.org References: <20211206072337.9517-1-jgross@suse.com> <20211206072337.9517-4-jgross@suse.com> <20211212001542.qhz7wfdwq7k5ymxr@begin> <20211213212206.htg4eykr32x63swk@begin> <1a2e80ed-9077-6867-5426-e7e6171feab5@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1a2e80ed-9077-6867-5426-e7e6171feab5@suse.com> Organization: I am not organized User-Agent: NeoMutt/20170609 (1.8.3) X-Spamd-Bar: / Authentication-Results: hera.aquilenet.fr; none X-Rspamd-Server: hera X-Rspamd-Queue-Id: 1670C32E X-Spamd-Result: default: False [0.40 / 15.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; HAS_ORG_HEADER(0.00)[]; RCVD_COUNT_THREE(0.00)[3]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_LAST(0.00)[]; MID_RHS_NOT_FQDN(0.50)[] Juergen Gross, le mar. 14 déc. 2021 07:35:54 +0100, a ecrit: > On 13.12.21 22:22, Samuel Thibault wrote: > > Juergen Gross, le lun. 13 déc. 2021 15:58:58 +0100, a ecrit: > > > On 12.12.21 01:15, Samuel Thibault wrote: > > > > Juergen Gross, le lun. 06 déc. 2021 08:23:30 +0100, a ecrit: > > > > > - unsigned long pfn, max = 0; > > > > > + unsigned long pfns, max = 0; > > > > > > > > I'd say rather rename max to start. > > > > > > > > > e820_get_memmap(); > > > > > @@ -166,9 +166,12 @@ unsigned long e820_get_maxpfn(void) > > > > > { > > > > > if ( e820_map[i].type != E820_RAM ) > > > > > continue; > > > > > - pfn = (e820_map[i].addr + e820_map[i].size) >> PAGE_SHIFT; > > > > > - if ( pfn > max ) > > > > > - max = pfn; > > > > > + pfns = e820_map[i].size >> PAGE_SHIFT; > > > > > + max = e820_map[i].addr >> PAGE_SHIFT; > > > > > > > > since it's it's always the start of the e820 entry. > > > > > > > > > + if ( pages <= pfns ) > > > > > + return max + pages; > > > > > + pages -= pfns; > > > > > + max += pfns; > > > > > > > > Here we don't need do change max, only pages. > > > > > > It is needed in case the loop is finished. > > > > > > And this was the reason for naming it max. > > > > Ah, ok. > > > > At first read the name was confusing me. Perhaps better use two > > variables then: start and max, so that we have > > > > start = e820_map[i].addr >> PAGE_SHIFT; > > if ( pages <= pfns ) > > return start + pages; > > pages -= pfns; > > max = start + pfns; > > Hmm, or I can rename max to start, drop the "max += pfns;" and do a > "return start + pfns;" at the end of the function. That could do as well, yes. Samuel From minios-devel-bounces@lists.xenproject.org Mon Dec 20 16:07:25 2021 Return-path: Envelope-to: archives@lists.xenproject.org Delivery-date: Mon, 20 Dec 2021 16:07:25 +0000 Received: from list by lists.xenproject.org with outflank-mailman.249850.430242 (Exim 4.92) (envelope-from ) id 1mzLC6-00056E-16; Mon, 20 Dec 2021 16:07:22 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 249850.430242; Mon, 20 Dec 2021 16:07:21 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mzLC5-000564-Tw; Mon, 20 Dec 2021 16:07:21 +0000 Received: by outflank-mailman (input) for mailman id 249850; Mon, 20 Dec 2021 16:07:21 +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 1mzLC5-00055w-GB for minios-devel@lists.xenproject.org; Mon, 20 Dec 2021 16:07:21 +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-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-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: 8bit 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]; extern char shared_info[PAGE_SIZE]; -#if defined(__x86_64__) -#define __pte(x) ((pte_t) { (x) } ) -#else -#define __pte(x) ({ unsigned long long _x = (x); \ - ((pte_t) {(unsigned long)(_x), (unsigned long)(_x>>32)}); }) -#endif - static inline void fpu_init(void) { asm volatile("fninit"); } -- 2.26.2 From minios-devel-bounces@lists.xenproject.org Mon Dec 20 16:07:25 2021 Return-path: Envelope-to: archives@lists.xenproject.org Delivery-date: Mon, 20 Dec 2021 16:07:25 +0000 Received: from list by lists.xenproject.org with outflank-mailman.249851.430245 (Exim 4.92) (envelope-from ) id 1mzLC7-00058M-2E; Mon, 20 Dec 2021 16:07:23 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 249851.430245; 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 1mzLC6-00058F-VT; Mon, 20 Dec 2021 16:07:22 +0000 Received: by outflank-mailman (input) for mailman id 249851; Mon, 20 Dec 2021 16:07:21 +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 1mzLC5-00055x-TC for minios-devel@lists.xenproject.org; Mon, 20 Dec 2021 16:07:21 +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 e85c9543-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 EA8421F388; Mon, 20 Dec 2021 16:07:18 +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 BD02A13D6B; 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 bXrPLDaqwGEUTAAAMHmgww (envelope-from ); Mon, 20 Dec 2021 16:07:18 +0000 X-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-devel" X-Inumbo-ID: e85c9543-61ae-11ec-9e60-abaf8a552007 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1640016438; 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; bh=37GUwbt+l3ZVL4jQWufvayPNooM23G4fn2Y2pwcBTd8=; b=pLzh4Dw4DOnfMVbr2vm6cwzAB9IE033KwtlpQtMwAiHPpjGIAL9C6eSiYLHE1NiNhCz2nZ k9Fjs5T6aLd3cwRfDrvYZneMm4qbidd3Xsvi+DdtIvyQdodSh+4aMZeiIdd6n7PYWdVzc+ q0/izJaMAdQYN4JeLk10qnTZaNT9KY8= 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 00/10] mini-os: add missing PVH features Date: Mon, 20 Dec 2021 17:07:06 +0100 Message-Id: <20211220160716.4159-1-jgross@suse.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Mini-OS in PVH mode is missing some features, especially in the areas of ballooning and grant tables. With this series I am able to run Xenstore stubdom in PVH mode. Changes in V2: - multiple comments addressed Juergen Gross (10): mini-os: split e820 map handling into new source file mini-os: sort and sanitize e820 memory map mini-os: don't assume contiguous RAM when initializing in PVH mode mini-os: respect memory map when ballooning up mini-os: don't repeat definition available via header file mini-os: add memory map service functions mini-os: move x86 specific gnttab coding into arch/x86/gnttab.c mini-os: add proper pvh grant table handling mini-os: prepare grantmap entry interface for use by PVH mode mini-os: modify grant mappings to work in PVH mode Makefile | 1 + arch/arm/mm.c | 11 +- arch/x86/balloon.c | 4 +- arch/x86/gnttab.c | 109 +++++++++++++ arch/x86/mm.c | 121 +-------------- arch/x86/setup.c | 8 +- balloon.c | 33 ++-- e820.c | 376 +++++++++++++++++++++++++++++++++++++++++++++ gntmap.c | 125 +++++++++------ include/balloon.h | 5 +- include/e820.h | 11 ++ include/gntmap.h | 1 + mm.c | 7 +- 13 files changed, 615 insertions(+), 197 deletions(-) create mode 100644 arch/x86/gnttab.c create mode 100644 e820.c -- 2.26.2 From minios-devel-bounces@lists.xenproject.org Mon Dec 20 16:07:26 2021 Return-path: Envelope-to: archives@lists.xenproject.org Delivery-date: Mon, 20 Dec 2021 16:07:26 +0000 Received: from list by lists.xenproject.org with outflank-mailman.249856.430288 (Exim 4.92) (envelope-from ) id 1mzLCA-0005yC-Kp; Mon, 20 Dec 2021 16:07:26 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 249856.430288; 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 1mzLCA-0005wa-7e; Mon, 20 Dec 2021 16:07:26 +0000 Received: by outflank-mailman (input) for mailman id 249856; Mon, 20 Dec 2021 16:07:24 +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 1mzLC8-00055w-8t for minios-devel@lists.xenproject.org; Mon, 20 Dec 2021 16:07:24 +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-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-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: 8bit 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 --- 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 = DOMID_SELF; - unsigned long max; pt_base = page_table_base; first_free_pfn = 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 = ret; - max = e820_get_maxpfn(); - if ( max < last_free_pfn ) - last_free_pfn = max; + last_free_pfn = e820_get_maxpfn(ret); } #endif 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 -unsigned long e820_get_maxpfn(void) +unsigned long e820_get_maxpfn(unsigned long pages) { int i; - unsigned long pfn, max = 0; + unsigned long pfns, start = 0; e820_get_memmap(); @@ -296,10 +296,12 @@ unsigned long e820_get_maxpfn(void) { if ( e820_map[i].type != E820_RAM ) continue; - pfn = (e820_map[i].addr + e820_map[i].size) >> PAGE_SHIFT; - if ( pfn > max ) - max = pfn; + pfns = e820_map[i].size >> PAGE_SHIFT; + start = e820_map[i].addr >> PAGE_SHIFT; + if ( pages <= pfns ) + return start + pages; + pages -= pfns; } - 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; -unsigned long e820_get_maxpfn(void); +unsigned long e820_get_maxpfn(unsigned long pages); #endif /*__E820_HEADER*/ -- 2.26.2 From minios-devel-bounces@lists.xenproject.org Mon Dec 20 16:07:27 2021 Return-path: Envelope-to: archives@lists.xenproject.org Delivery-date: Mon, 20 Dec 2021 16:07:27 +0000 Received: from list by lists.xenproject.org with outflank-mailman.249858.430294 (Exim 4.92) (envelope-from ) id 1mzLCB-000662-6y; Mon, 20 Dec 2021 16:07:27 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 249858.430294; Mon, 20 Dec 2021 16:07:27 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mzLCA-00063O-Mp; Mon, 20 Dec 2021 16:07:26 +0000 Received: by outflank-mailman (input) for mailman id 249858; Mon, 20 Dec 2021 16:07:25 +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 1mzLC9-00055w-93 for minios-devel@lists.xenproject.org; Mon, 20 Dec 2021 16:07:25 +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-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-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: 8bit 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 --- 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 @@ -70,6 +71,8 @@ void arch_init_mm(unsigned long *start_pfn_p, unsigned long *max_pfn_p) } device_tree = new_device_tree; *max_pfn_p = to_phys(new_device_tree) >> PAGE_SHIFT; + + balloon_set_nr_pages(*max_pfn_p, *max_pfn_p); } 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); - if ( p2m_pages(nr_max_pages) <= p2m_pages(max_pfn) ) + if ( p2m_pages(nr_max_pfn) <= p2m_pages(max_pfn) ) return; - new_p2m = alloc_virt_kernel(p2m_pages(nr_max_pages)); + new_p2m = alloc_virt_kernel(p2m_pages(nr_max_pfn)); for ( pfn = 0; pfn < max_pfn; pfn += 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 = (pgentry_t *)si->pt_base; first_free_pfn = PFN_UP(to_phys(pt_base)) + si->nr_pt_frames; last_free_pfn = 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) } last_free_pfn = e820_get_maxpfn(ret); + balloon_set_nr_pages(ret, last_free_pfn); } #endif diff --git a/balloon.c b/balloon.c index 5676d3b..9dc77c5 100644 --- a/balloon.c +++ b/balloon.c @@ -23,14 +23,24 @@ #include #include +#include #include #include #include #include #include -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 = pages; + nr_mem_pfn = pfn; +} void get_max_pages(void) { @@ -46,16 +56,18 @@ void get_max_pages(void) nr_max_pages = ret; printk("Maximum memory size: %ld pages\n", nr_max_pages); + + nr_max_pfn = e820_get_maxpfn(nr_max_pages); } void mm_alloc_bitmap_remap(void) { unsigned long i, new_bitmap; - if ( mm_alloc_bitmap_size >= ((nr_max_pages + 1) >> 3) ) + if ( mm_alloc_bitmap_size >= ((nr_max_pfn + 1) >> 3) ) return; - new_bitmap = alloc_virt_kernel(PFN_UP((nr_max_pages + 1) >> 3)); + new_bitmap = alloc_virt_kernel(PFN_UP((nr_max_pfn + 1) >> 3)); for ( i = 0; i < mm_alloc_bitmap_size; i += PAGE_SIZE ) { map_frame_rw(new_bitmap + i, @@ -70,7 +82,7 @@ static unsigned long balloon_frames[N_BALLOON_FRAMES]; int balloon_up(unsigned long n_pages) { - unsigned long page, pfn; + unsigned long page, pfn, start_pfn; int rc; struct xen_memory_reservation reservation = { .domid = DOMID_SELF @@ -81,8 +93,11 @@ int balloon_up(unsigned long n_pages) if ( n_pages > N_BALLOON_FRAMES ) n_pages = N_BALLOON_FRAMES; + start_pfn = e820_get_maxpfn(nr_mem_pages + 1) - 1; + n_pages = 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 = alloc_page(); if ( !page ) @@ -99,14 +114,14 @@ int balloon_up(unsigned long n_pages) mm_alloc_bitmap_size += PAGE_SIZE; } - rc = arch_expand_p2m(nr_mem_pages + n_pages); + rc = arch_expand_p2m(start_pfn + n_pages); if ( rc ) return rc; /* Get new memory from hypervisor. */ for ( pfn = 0; pfn < n_pages; pfn++ ) { - balloon_frames[pfn] = nr_mem_pages + pfn; + balloon_frames[pfn] = start_pfn + pfn; } set_xen_guest_handle(reservation.extent_start, balloon_frames); reservation.nr_extents = n_pages; @@ -116,7 +131,7 @@ int balloon_up(unsigned long n_pages) for ( pfn = 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)); } 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 = 0; - e820_get_memmap(); + if ( !e820_entries ) + e820_get_memmap(); for ( i = 0; i < e820_entries; i++ ) { @@ -305,3 +306,21 @@ unsigned long e820_get_maxpfn(unsigned long pages) return start + pfns; } + +unsigned long e820_get_max_contig_pages(unsigned long pfn, unsigned long pages) +{ + int i; + unsigned long end; + + for ( i = 0; i < e820_entries && e820_map[i].addr < (pfn << PAGE_SHIFT); + i++ ) + { + end = (e820_map[i].addr + e820_map[i].size) >> PAGE_SHIFT; + if ( e820_map[i].type != E820_RAM || end <= 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 -extern unsigned long nr_max_pages; -extern unsigned long nr_mem_pages; +extern unsigned long nr_max_pfn; void get_max_pages(void); int balloon_up(unsigned long n_pages); +void balloon_set_nr_pages(unsigned long pages, unsigned long pfn); 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 <= nr_free_pages; } +static inline balloon_set_nr_pages(unsigned long pages, unsigned long pfn) { } #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; unsigned long e820_get_maxpfn(unsigned long pages); +unsigned long e820_get_max_contig_pages(unsigned long pfn, unsigned long pages); #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) printk("MM: Init\n"); - 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); arch_init_demand_mapping_area(); - -#ifdef CONFIG_BALLOON - nr_mem_pages = max_pfn; -#endif } void fini_mm(void) -- 2.26.2 From minios-devel-bounces@lists.xenproject.org Mon Dec 20 16:07:27 2021 Return-path: Envelope-to: archives@lists.xenproject.org Delivery-date: Mon, 20 Dec 2021 16:07:27 +0000 Received: from list by lists.xenproject.org with outflank-mailman.249857.430293 (Exim 4.92) (envelope-from ) id 1mzLCB-00063G-6j; Mon, 20 Dec 2021 16:07:27 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 249857.430293; 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 1mzLCA-000628-JX; Mon, 20 Dec 2021 16:07:26 +0000 Received: by outflank-mailman (input) for mailman id 249857; Mon, 20 Dec 2021 16:07:24 +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 1mzLC8-00055x-Lb for minios-devel@lists.xenproject.org; Mon, 20 Dec 2021 16:07:24 +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-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-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: 8bit 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 --- 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 = 0, needed = (long)pages << PAGE_SHIFT; + + for ( i = 0; i < e820_entries && e820_map[i].addr < last + needed; i++ ) + last = e820_map[i].addr + e820_map[i].size; + + if ( i == 0 || e820_map[i - 1].type != E820_RESERVED ) + e820_insert_entry_at(i, last, needed, E820_RESERVED); + else + e820_map[i - 1].size += needed; + + return last >> PAGE_SHIFT; +} + +void e820_put_reserved_pfns(unsigned long start_pfn, int pages) +{ + int i; + unsigned long addr = start_pfn << PAGE_SHIFT; + unsigned long size = (long)pages << PAGE_SHIFT; + + for ( i = 0; + i < e820_entries && addr >= e820_map[i].addr + e820_map[i].size; + i++ ); + + BUG_ON(i == e820_entries || e820_map[i].type != E820_RESERVED || + addr + size > e820_map[i].addr + e820_map[i].size); + + if ( addr == e820_map[i].addr ) + { + e820_map[i].addr += size; + e820_map[i].size -= size; + if ( e820_map[i].size == 0 ) + e820_remove_entry(i); + return; + } + + if ( addr + size == e820_map[i].addr + e820_map[i].size ) + { + e820_map[i].size -= 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 = addr - e820_map[i].addr; +} #endif 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; unsigned long e820_get_maxpfn(unsigned long pages); unsigned long e820_get_max_contig_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 #endif /*__E820_HEADER*/ -- 2.26.2 From minios-devel-bounces@lists.xenproject.org Mon Dec 20 16:07:27 2021 Return-path: Envelope-to: archives@lists.xenproject.org Delivery-date: Mon, 20 Dec 2021 16:07:27 +0000 Received: from list by lists.xenproject.org with outflank-mailman.249859.430298 (Exim 4.92) (envelope-from ) id 1mzLCB-00067J-BZ; Mon, 20 Dec 2021 16:07:27 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 249859.430298; Mon, 20 Dec 2021 16:07:27 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mzLCA-00065f-Rj; Mon, 20 Dec 2021 16:07:26 +0000 Received: by outflank-mailman (input) for mailman id 249859; Mon, 20 Dec 2021 16:07:25 +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 1mzLC9-00055x-Lg for minios-devel@lists.xenproject.org; Mon, 20 Dec 2021 16:07:25 +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-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-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: 8bit 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 --- 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] = { [E820_PMEM] = "PMEM" }; +/* + * 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 = idx; i < e820_entries; i++ ) + e820_map[i] = 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 == E820_MAX ) + { + xprintk("E820 memory map overflow\n"); + do_exit(); + } + + e820_entries++; + for ( i = e820_entries - 1; i > idx; i-- ) + e820_map[i] = e820_map[i - 1]; + + e820_map[idx].addr = addr; + e820_map[idx].size = size; + e820_map[idx].type = type; +} + +static void e820_insert_entry(unsigned long addr, unsigned long size, + unsigned int type) +{ + int i; + + for ( i = 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 = e820_map[idx1]; + e820_map[idx1] = e820_map[idx2]; + e820_map[idx2] = 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 = 1; i < e820_entries; i++ ) + for ( j = 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 = 1; i < e820_entries; i++ ) + { + if ( e820_map[i - 1].addr + e820_map[i - 1].size <= 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 += e820_map[i - 1].size; + e820_map[i].size -= 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 >= e820_map[i].size ) + { + e820_remove_entry(i); + i--; + } + else + { + start = e820_map[i].addr + e820_map[i - 1].size; + end = e820_map[i].addr + e820_map[i].size; + type = e820_map[i].type; + e820_remove_entry(i); + e820_insert_entry(start, end - start, type); + } + } + + /* Merge adjacent entries. */ + for ( i = 0; i < e820_entries - 1; i++ ) + { + if ( e820_map[i].type == e820_map[i + 1].type && + e820_map[i].addr + e820_map[i].size >= 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 = e820_map[i + 1].addr - e820_map[i].addr + + 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 = 0; i < e820_entries; i++ ) + { + start = e820_map[i].addr; + end = start + e820_map[i].size; + if ( (1U << e820_map[i].type) & E820_NARROW ) + { + if ( start & (PAGE_SIZE - 1) ) + { + start = round_pgup(start); + e820_insert_entry_at(i, start - PAGE_SIZE, PAGE_SIZE, + E820_TMP_RESERVED); + i++; + } + if ( end & (PAGE_SIZE - 1) ) + { + end = round_pgdown(end); + e820_insert_entry_at(i, end, PAGE_SIZE, E820_TMP_RESERVED); + i++; + } + } + else + { + start = round_pgdown(start); + end = round_pgup(end); + } + e820_map[i].addr = start; + e820_map[i].size = end - start; + } + + /* Sanitize memory map (again). */ + e820_process_entries(); + + /* Make remaining temporarily reserved entries permanently reserved. */ + for ( i = 0; i < e820_entries; i++ ) + if ( e820_map[i].type == E820_TMP_RESERVED ) + e820_map[i].type = E820_RESERVED; +} + static void e820_get_memmap(void) { long ret; @@ -71,6 +255,8 @@ static void e820_get_memmap(void) do_exit(); } e820_entries = memmap.nr_entries; + + e820_sanitize(); } void arch_print_memmap(void) -- 2.26.2 From minios-devel-bounces@lists.xenproject.org Mon Dec 20 16:07:29 2021 Return-path: Envelope-to: archives@lists.xenproject.org Delivery-date: Mon, 20 Dec 2021 16:07:29 +0000 Received: from list by lists.xenproject.org with outflank-mailman.249862.430322 (Exim 4.92) (envelope-from ) id 1mzLCD-0006bK-Px; Mon, 20 Dec 2021 16:07:29 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 249862.430322; Mon, 20 Dec 2021 16:07:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mzLCD-0006Yx-7C; Mon, 20 Dec 2021 16:07:29 +0000 Received: by outflank-mailman (input) for mailman id 249862; Mon, 20 Dec 2021 16:07:27 +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 1mzLCB-00055w-9T for minios-devel@lists.xenproject.org; Mon, 20 Dec 2021 16:07:27 +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-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-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: 8bit Introduce e820.c containing all the E820 memory map handling. No functional change. Signed-off-by: Juergen Gross Reviewed-by: Samuel Thibault --- Makefile | 1 + arch/arm/mm.c | 8 ---- arch/x86/mm.c | 70 +---------------------------- e820.c | 119 +++++++++++++++++++++++++++++++++++++++++++++++++ include/e820.h | 6 +++ 5 files changed, 128 insertions(+), 76 deletions(-) create mode 100644 e820.c diff --git a/Makefile b/Makefile index 4b76b55..06b60fc 100644 --- a/Makefile +++ b/Makefile @@ -41,6 +41,7 @@ src-$(CONFIG_TPMFRONT) += tpmfront.c src-$(CONFIG_TPM_TIS) += tpm_tis.c src-$(CONFIG_TPMBACK) += tpmback.c src-y += daytime.c +src-y += e820.c src-y += events.c src-$(CONFIG_FBFRONT) += fbfront.c src-y += gntmap.c diff --git a/arch/arm/mm.c b/arch/arm/mm.c index f806c9f..9068166 100644 --- a/arch/arm/mm.c +++ b/arch/arm/mm.c @@ -7,14 +7,6 @@ #include uint32_t physical_address_offset; -struct e820entry e820_map[1] = { - { - .addr = 0, - .size = ULONG_MAX - 1, - .type = E820_RAM - } -}; -unsigned e820_entries = 1; unsigned long allocate_ondemand(unsigned long n, unsigned long alignment) { diff --git a/arch/x86/mm.c b/arch/x86/mm.c index 8ba14a5..8df93da 100644 --- a/arch/x86/mm.c +++ b/arch/x86/mm.c @@ -64,15 +64,6 @@ extern char stack[]; extern void page_walk(unsigned long va); #ifdef CONFIG_PARAVIRT -struct e820entry e820_map[1] = { - { - .addr = 0, - .size = ULONG_MAX - 1, - .type = E820_RAM - } -}; -unsigned e820_entries = 1; - void arch_mm_preinit(void *p) { start_info_t *si = p; @@ -112,25 +103,11 @@ desc_ptr idt_ptr = .base = (unsigned long)&idt, }; -struct e820entry e820_map[E820_MAX]; -unsigned e820_entries; - -static char *e820_types[E820_TYPES] = { - [E820_RAM] = "RAM", - [E820_RESERVED] = "Reserved", - [E820_ACPI] = "ACPI", - [E820_NVS] = "NVS", - [E820_UNUSABLE] = "Unusable", - [E820_PMEM] = "PMEM" -}; - void arch_mm_preinit(void *p) { long ret; domid_t domid = DOMID_SELF; - struct xen_memory_map memmap; - int i; - unsigned long pfn, max = 0; + unsigned long max; pt_base = page_table_base; first_free_pfn = PFN_UP(to_phys(&_end)); @@ -142,53 +119,10 @@ void arch_mm_preinit(void *p) } last_free_pfn = ret; - memmap.nr_entries = E820_MAX; - set_xen_guest_handle(memmap.buffer, e820_map); - ret = HYPERVISOR_memory_op(XENMEM_memory_map, &memmap); - if ( ret < 0 ) - { - xprintk("could not get memory map\n"); - do_exit(); - } - e820_entries = memmap.nr_entries; - - for ( i = 0; i < e820_entries; i++ ) - { - if ( e820_map[i].type != E820_RAM ) - continue; - pfn = (e820_map[i].addr + e820_map[i].size) >> PAGE_SHIFT; - if ( pfn > max ) - max = pfn; - } - + max = e820_get_maxpfn(); if ( max < last_free_pfn ) last_free_pfn = max; } - -void arch_print_memmap(void) -{ - int i; - unsigned long from, to; - char *type; - char buf[12]; - - printk("Memory map:\n"); - for ( i = 0; i < e820_entries; i++ ) - { - if ( e820_map[i].type >= E820_TYPES || !e820_types[e820_map[i].type] ) - { - snprintf(buf, sizeof(buf), "%8x", e820_map[i].type); - type = buf; - } - else - { - type = e820_types[e820_map[i].type]; - } - from = e820_map[i].addr; - to = from + e820_map[i].size - 1; - printk("%012lx-%012lx: %s\n", from, to, type); - } -} #endif /* diff --git a/e820.c b/e820.c new file mode 100644 index 0000000..2165280 --- /dev/null +++ b/e820.c @@ -0,0 +1,119 @@ +/* -*- Mode:C; c-basic-offset:4; tab-width:4 -*- + * + * (C) 2021 - Juergen Gross, SUSE Software Solutions Germany GmbH + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include +#include +#include +#include +#include +#include +#include + +#ifdef CONFIG_E820_TRIVIAL +struct e820entry e820_map[1] = { + { + .addr = 0, + .size = ULONG_MAX - 1, + .type = E820_RAM + } +}; + +unsigned e820_entries = 1; + +static void e820_get_memmap(void) +{ +} + +#else +struct e820entry e820_map[E820_MAX]; +unsigned e820_entries; + +static char *e820_types[E820_TYPES] = { + [E820_RAM] = "RAM", + [E820_RESERVED] = "Reserved", + [E820_ACPI] = "ACPI", + [E820_NVS] = "NVS", + [E820_UNUSABLE] = "Unusable", + [E820_PMEM] = "PMEM" +}; + +static void e820_get_memmap(void) +{ + long ret; + struct xen_memory_map memmap; + + memmap.nr_entries = E820_MAX; + set_xen_guest_handle(memmap.buffer, e820_map); + ret = HYPERVISOR_memory_op(XENMEM_memory_map, &memmap); + if ( ret < 0 ) + { + xprintk("could not get memory map\n"); + do_exit(); + } + e820_entries = memmap.nr_entries; +} + +void arch_print_memmap(void) +{ + int i; + unsigned long from, to; + char *type; + char buf[12]; + + printk("Memory map:\n"); + for ( i = 0; i < e820_entries; i++ ) + { + if ( e820_map[i].type >= E820_TYPES || !e820_types[e820_map[i].type] ) + { + snprintf(buf, sizeof(buf), "%8x", e820_map[i].type); + type = buf; + } + else + { + type = e820_types[e820_map[i].type]; + } + from = e820_map[i].addr; + to = from + e820_map[i].size - 1; + printk("%012lx-%012lx: %s\n", from, to, type); + } +} +#endif + +unsigned long e820_get_maxpfn(void) +{ + int i; + unsigned long pfn, max = 0; + + e820_get_memmap(); + + for ( i = 0; i < e820_entries; i++ ) + { + if ( e820_map[i].type != E820_RAM ) + continue; + pfn = (e820_map[i].addr + e820_map[i].size) >> PAGE_SHIFT; + if ( pfn > max ) + max = pfn; + } + + return max; +} diff --git a/include/e820.h b/include/e820.h index 920551c..af2129f 100644 --- a/include/e820.h +++ b/include/e820.h @@ -24,6 +24,10 @@ #ifndef __E820_HEADER #define __E820_HEADER +#if defined(__arm__) || defined(__aarch64__) || defined(CONFIG_PARAVIRT) +#define CONFIG_E820_TRIVIAL +#endif + /* PC BIOS standard E820 types and structure. */ #define E820_RAM 1 #define E820_RESERVED 2 @@ -45,4 +49,6 @@ struct __packed e820entry { extern struct e820entry e820_map[]; extern unsigned e820_entries; +unsigned long e820_get_maxpfn(void); + #endif /*__E820_HEADER*/ -- 2.26.2 From minios-devel-bounces@lists.xenproject.org Mon Dec 20 16:07:30 2021 Return-path: Envelope-to: archives@lists.xenproject.org Delivery-date: Mon, 20 Dec 2021 16:07:30 +0000 Received: from list by lists.xenproject.org with outflank-mailman.249863.430324 (Exim 4.92) (envelope-from ) id 1mzLCD-0006bl-T2; Mon, 20 Dec 2021 16:07:29 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 249863.430324; Mon, 20 Dec 2021 16:07:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mzLCD-0006aM-AS; Mon, 20 Dec 2021 16:07:29 +0000 Received: by outflank-mailman (input) for mailman id 249863; 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 1mzLCB-00055x-Lw for minios-devel@lists.xenproject.org; Mon, 20 Dec 2021 16:07:27 +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-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-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: 8bit 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 @@ */ #include +#include +#include #include #include #include #include +#include +#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 = e820_get_reserved_pfns(nr_grant_frames); + for ( i = 0; i < nr_grant_frames; i++ ) + { + xatp.domid = DOMID_SELF; + xatp.idx = i; + xatp.space = XENMAPSPACE_grant_table; + xatp.gpfn = pfn + i; + rc = HYPERVISOR_memory_op(XENMEM_add_to_physmap, &xatp); + if ( rc ) + { + xprintk("could not init grant table\n"); + do_exit(); + } + frames[i] = pfn + i; + } + + return map_frames(frames, nr_grant_frames); +} +#endif void arch_suspend_gnttab(grant_entry_v1_t *gnttab_table, int nr_grant_frames) { -- 2.26.2 From minios-devel-bounces@lists.xenproject.org Mon Dec 20 16:07:32 2021 Return-path: Envelope-to: archives@lists.xenproject.org Delivery-date: Mon, 20 Dec 2021 16:07:32 +0000 Received: from list by lists.xenproject.org with outflank-mailman.249866.430346 (Exim 4.92) (envelope-from ) id 1mzLCG-0007AZ-OA; Mon, 20 Dec 2021 16:07:32 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 249866.430346; 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-000775-3u; Mon, 20 Dec 2021 16:07:32 +0000 Received: by outflank-mailman (input) for mailman id 249866; Mon, 20 Dec 2021 16:07:29 +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 1mzLCD-00055w-9y for minios-devel@lists.xenproject.org; Mon, 20 Dec 2021 16:07:29 +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-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-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: 8bit 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 { }; static inline int -gntmap_entry_used(struct gntmap_entry *entry) +gntmap_entry_used(struct gntmap *map, int idx) { - return entry->host_addr != 0; + return map->entries[idx].host_addr != 0; } -static struct gntmap_entry* -gntmap_find_free_entry(struct gntmap *map) +static int gntmap_find_free_entry(struct gntmap *map) { int i; for (i = 0; i < map->nentries; i++) { - if (!gntmap_entry_used(&map->entries[i])) - return &map->entries[i]; + if (!gntmap_entry_used(map, i)) + return i; } DEBUG("(map=%p): all %d entries full", map, map->nentries); - return NULL; + return -1; } -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; for (i = 0; i < map->nentries; i++) { if (map->entries[i].host_addr == addr) - return &map->entries[i]; + return i; } - return NULL; + return -1; } int @@ -105,12 +103,13 @@ gntmap_set_max_grants(struct gntmap *map, int count) } static int -_gntmap_map_grant_ref(struct gntmap_entry *entry, +_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 = map->entries + idx; struct gnttab_map_grant_ref op; int rc; @@ -135,8 +134,9 @@ _gntmap_map_grant_ref(struct gntmap_entry *entry, } static int -_gntmap_unmap_grant_ref(struct gntmap_entry *entry) +_gntmap_unmap_grant_ref(struct gntmap *map, int idx) { + struct gntmap_entry *entry = map->entries + idx; struct gnttab_unmap_grant_ref op; int rc; @@ -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; DEBUG("(map=%p, start_address=%lx, count=%d)", map, start_address, count); for (i = 0; i < count; i++) { - ent = gntmap_find_entry(map, start_address + PAGE_SIZE * i); - if (ent == NULL) { + idx = gntmap_find_entry(map, start_address + PAGE_SIZE * i); + if (idx < 0) { printk("gntmap: tried to munmap unknown page\n"); return -EINVAL; } - rc = _gntmap_unmap_grant_ref(ent); + rc = _gntmap_unmap_grant_ref(map, idx); if (rc != 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; DEBUG("(map=%p, count=%" PRIu32 ", " @@ -206,9 +206,9 @@ gntmap_map_grant_refs(struct gntmap *map, return NULL; for (i = 0; i < count; i++) { - ent = gntmap_find_free_entry(map); - if (ent == NULL || - _gntmap_map_grant_ref(ent, + idx = 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; DEBUG("(map=%p)", map); for (i = 0; i < map->nentries; i++) { - ent = &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); } xfree(map->entries); -- 2.26.2 From minios-devel-bounces@lists.xenproject.org Mon Dec 20 16:07:36 2021 Return-path: Envelope-to: archives@lists.xenproject.org Delivery-date: Mon, 20 Dec 2021 16:07:36 +0000 Received: from list by lists.xenproject.org with outflank-mailman.249869.430366 (Exim 4.92) (envelope-from ) id 1mzLCJ-0007ny-DX; Mon, 20 Dec 2021 16:07:35 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 249869.430366; Mon, 20 Dec 2021 16:07: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 1mzLCI-0007jP-Sf; Mon, 20 Dec 2021 16:07:34 +0000 Received: by outflank-mailman (input) for mailman id 249869; Mon, 20 Dec 2021 16:07:31 +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 1mzLCE-00055x-MU for minios-devel@lists.xenproject.org; Mon, 20 Dec 2021 16:07:30 +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-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-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: 8bit 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, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include +#include +#include +#include +#include + +grant_entry_v1_t *arch_init_gnttab(int nr_grant_frames) +{ + struct gnttab_setup_table setup; + unsigned long frames[nr_grant_frames]; + + setup.dom = DOMID_SELF; + setup.nr_frames = 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_frames) +{ +#ifdef CONFIG_PARAVIRT + int i; + + for ( i = 0; i < nr_grant_frames; i++ ) + { + HYPERVISOR_update_va_mapping((unsigned long)gnttab_table + PAGE_SIZE * i, + __pte(0x0 << PAGE_SHIFT), UVMF_INVLPG); + } +#endif + return; +} + +void arch_resume_gnttab(grant_entry_v1_t *gnttab_table, int nr_grant_frames) +{ + struct gnttab_setup_table setup; + unsigned long frames[nr_grant_frames]; +#ifdef CONFIG_PARAVIRT + int i; +#endif + + setup.dom = DOMID_SELF; + setup.nr_frames = 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 = 0; i < nr_grant_frames; i++ ) + { + HYPERVISOR_update_va_mapping((unsigned long)gnttab_table + PAGE_SIZE * 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 } -grant_entry_v1_t *arch_init_gnttab(int nr_grant_frames) -{ - struct gnttab_setup_table setup; - unsigned long frames[nr_grant_frames]; - - setup.dom = DOMID_SELF; - setup.nr_frames = 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_frames) -{ -#ifdef CONFIG_PARAVIRT - int i; - - for (i = 0; i < nr_grant_frames; i++) { - HYPERVISOR_update_va_mapping((unsigned long)(((char *)gnttab_table) + PAGE_SIZE * i), - (pte_t){0x0< Envelope-to: archives@lists.xenproject.org Delivery-date: Mon, 20 Dec 2021 16:11:42 +0000 Received: from list by lists.xenproject.org with outflank-mailman.249902.430402 (Exim 4.92) (envelope-from ) id 1mzLGH-0004ss-KC; Mon, 20 Dec 2021 16:11:41 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 249902.430402; Mon, 20 Dec 2021 16:11:41 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mzLGH-0004sl-HK; Mon, 20 Dec 2021 16:11:41 +0000 Received: by outflank-mailman (input) for mailman id 249902; Mon, 20 Dec 2021 16:11:40 +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 1mzLCF-00055x-Mh for minios-devel@lists.xenproject.org; Mon, 20 Dec 2021 16:07:31 +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-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-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: 8bit 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 @@ #include #include +#include #include #include #include @@ -97,11 +98,42 @@ gntmap_set_max_grants(struct gntmap *map, int count) if (map->entries == NULL) return -ENOMEM; +#ifndef CONFIG_PARAVIRT + map->start_pfn = e820_get_reserved_pfns(count); +#endif + memset(map->entries, 0, sizeof(struct gntmap_entry) * count); map->nentries = count; return 0; } +static int +_gntmap_unmap_grant_ref(struct gntmap *map, int idx) +{ + struct gntmap_entry *entry = map->entries + idx; + struct gnttab_unmap_grant_ref op; + int rc; + +#ifdef CONFIG_PARAVIRT + op.host_addr = (uint64_t) entry->host_addr; +#else + op.host_addr = (uint64_t)(map->start_pfn + idx) << PAGE_SHIFT; +#endif + op.dev_bus_addr = 0; + op.handle = entry->handle; + + rc = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1); + if (rc != 0 || op.status != GNTST_okay) { + printk("GNTTABOP_unmap_grant_ref failed: " + "returned %d, status %" PRId16 "\n", + rc, op.status); + return rc != 0 ? rc : op.status; + } + + entry->host_addr = 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 = map->entries + idx; struct gnttab_map_grant_ref op; int rc; +#ifndef CONFIG_PARAVIRT + unsigned long pfn = map->start_pfn + idx; +#endif op.ref = (grant_ref_t) ref; op.dom = (domid_t) domid; +#ifdef CONFIG_PARAVIRT op.host_addr = (uint64_t) host_addr; +#else + op.host_addr = (uint64_t)pfn << PAGE_SHIFT; +#endif op.flags = GNTMAP_host_map; if (!writable) op.flags |= GNTMAP_readonly; @@ -128,31 +167,18 @@ _gntmap_map_grant_ref(struct gntmap *map, int idx, return rc != 0 ? rc : op.status; } - entry->host_addr = host_addr; - entry->handle = op.handle; - return 0; -} - -static int -_gntmap_unmap_grant_ref(struct gntmap *map, int idx) -{ - struct gntmap_entry *entry = map->entries + idx; - struct gnttab_unmap_grant_ref op; - int rc; - - op.host_addr = (uint64_t) entry->host_addr; - op.dev_bus_addr = 0; - op.handle = entry->handle; - - rc = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1); - if (rc != 0 || op.status != GNTST_okay) { - printk("GNTTABOP_unmap_grant_ref failed: " - "returned %d, status %" PRId16 "\n", - rc, op.status); - return rc != 0 ? rc : op.status; +#ifndef CONFIG_PARAVIRT + rc = 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 - entry->host_addr = 0; + entry->host_addr = host_addr; + entry->handle = op.handle; return 0; } @@ -165,6 +191,10 @@ gntmap_munmap(struct gntmap *map, unsigned long start_address, int count) DEBUG("(map=%p, start_address=%lx, count=%d)", map, start_address, count); +#ifndef CONFIG_PARAVIRT + unmap_frames(start_address, count); +#endif + for (i = 0; i < count; i++) { idx = 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); } +#ifndef CONFIG_PARAVIRT + e820_put_reserved_pfns(map->start_pfn, map->nentries); + map->start_pfn = 0; +#endif + xfree(map->entries); map->entries = NULL; map->nentries = 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; }; int -- 2.26.2 From minios-devel-bounces@lists.xenproject.org Mon Dec 20 23:17:41 2021 Return-path: Envelope-to: archives@lists.xenproject.org Delivery-date: Mon, 20 Dec 2021 23:17:41 +0000 Received: from list by lists.xenproject.org with outflank-mailman.250046.430612 (Exim 4.92) (envelope-from ) id 1mzRuU-0007Dd-Se; Mon, 20 Dec 2021 23:17:38 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 250046.430612; Mon, 20 Dec 2021 23:17:38 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mzRuU-0007DW-PT; Mon, 20 Dec 2021 23:17:38 +0000 Received: by outflank-mailman (input) for mailman id 250046; Mon, 20 Dec 2021 23:17:37 +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 1mzRuT-0006xl-JZ for minios-devel@lists.xenproject.org; Mon, 20 Dec 2021 23:17:37 +0000 Received: from hera.aquilenet.fr (hera.aquilenet.fr [185.233.100.1]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 0328e659-61eb-11ec-9e60-abaf8a552007; Tue, 21 Dec 2021 00:17:34 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 31D4E4EC; Tue, 21 Dec 2021 00:17:33 +0100 (CET) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xn2FJjRoLvxK; Tue, 21 Dec 2021 00:17:32 +0100 (CET) Received: from begin.home (2a01cb0088600700de41a9fffe47ec49.ipv6.abo.wanadoo.fr [IPv6:2a01:cb00:8860:700:de41:a9ff:fe47:ec49]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 7BB4E63; Tue, 21 Dec 2021 00:17:32 +0100 (CET) Received: from samy by begin.home with local (Exim 4.95) (envelope-from ) id 1mzRuN-00065d-0B; Tue, 21 Dec 2021 00:17:31 +0100 X-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-devel" X-Inumbo-ID: 0328e659-61eb-11ec-9e60-abaf8a552007 X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Date: Tue, 21 Dec 2021 00:17:30 +0100 From: Samuel Thibault To: Juergen Gross Cc: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org, wl@xen.org Subject: Re: [PATCH v2 02/10] mini-os: sort and sanitize e820 memory map Message-ID: <20211220231730.nivaq6vgtlyfqhng@begin> Mail-Followup-To: Samuel Thibault , Juergen Gross , minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org, wl@xen.org References: <20211220160716.4159-1-jgross@suse.com> <20211220160716.4159-3-jgross@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20211220160716.4159-3-jgross@suse.com> Organization: I am not organized User-Agent: NeoMutt/20170609 (1.8.3) X-Spamd-Bar: / Authentication-Results: hera.aquilenet.fr; none X-Rspamd-Server: hera X-Rspamd-Queue-Id: 31D4E4EC X-Spamd-Result: default: False [0.40 / 15.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; HAS_ORG_HEADER(0.00)[]; RCVD_COUNT_THREE(0.00)[3]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_LAST(0.00)[]; MID_RHS_NOT_FQDN(0.50)[] Juergen Gross, le lun. 20 déc. 2021 17:07:08 +0100, a ecrit: > +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 = 0; i < e820_entries; i++ ) > + { > + start = e820_map[i].addr; > + end = start + e820_map[i].size; > + if ( (1U << e820_map[i].type) & E820_NARROW ) > + { > + if ( start & (PAGE_SIZE - 1) ) > + { > + start = round_pgup(start); > + e820_insert_entry_at(i, start - PAGE_SIZE, PAGE_SIZE, > + E820_TMP_RESERVED); > + i++; > + } > + if ( end & (PAGE_SIZE - 1) ) > + { > + end = round_pgdown(end); > + e820_insert_entry_at(i, end, PAGE_SIZE, E820_TMP_RESERVED); Rather i+1 so it's most probably already sorted? Apart from that, Reviewed-by: Samuel Thibault Samuel From minios-devel-bounces@lists.xenproject.org Mon Dec 20 23:18:25 2021 Return-path: Envelope-to: archives@lists.xenproject.org Delivery-date: Mon, 20 Dec 2021 23:18:25 +0000 Received: from list by lists.xenproject.org with outflank-mailman.250049.430615 (Exim 4.92) (envelope-from ) id 1mzRvE-0007YH-Vb; Mon, 20 Dec 2021 23:18:24 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 250049.430615; Mon, 20 Dec 2021 23:18: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 1mzRvE-0007YA-Sl; Mon, 20 Dec 2021 23:18:24 +0000 Received: by outflank-mailman (input) for mailman id 250049; Mon, 20 Dec 2021 23:18: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 1mzRvD-0007Xv-Ng for minios-devel@lists.xenproject.org; Mon, 20 Dec 2021 23:18:23 +0000 Received: from hera.aquilenet.fr (hera.aquilenet.fr [185.233.100.1]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 1d1b6645-61eb-11ec-8d39-b1a4ed000e3e; Tue, 21 Dec 2021 00:18:21 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 596134EE; Tue, 21 Dec 2021 00:18:17 +0100 (CET) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ZYOuiuRNWbd9; Tue, 21 Dec 2021 00:18:16 +0100 (CET) Received: from begin.home (2a01cb0088600700de41a9fffe47ec49.ipv6.abo.wanadoo.fr [IPv6:2a01:cb00:8860:700:de41:a9ff:fe47:ec49]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 9306E199; Tue, 21 Dec 2021 00:18:16 +0100 (CET) Received: from samy by begin.home with local (Exim 4.95) (envelope-from ) id 1mzRv6-00065u-5N; Tue, 21 Dec 2021 00:18:16 +0100 X-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-devel" X-Inumbo-ID: 1d1b6645-61eb-11ec-8d39-b1a4ed000e3e X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Date: Tue, 21 Dec 2021 00:18:16 +0100 From: Samuel Thibault To: Juergen Gross Cc: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org, wl@xen.org Subject: Re: [PATCH v2 03/10] mini-os: don't assume contiguous RAM when initializing in PVH mode Message-ID: <20211220231816.pnimrlsfbs2lorik@begin> Mail-Followup-To: Samuel Thibault , Juergen Gross , minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org, wl@xen.org References: <20211220160716.4159-1-jgross@suse.com> <20211220160716.4159-4-jgross@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20211220160716.4159-4-jgross@suse.com> Organization: I am not organized User-Agent: NeoMutt/20170609 (1.8.3) X-Spamd-Bar: / Authentication-Results: hera.aquilenet.fr; none X-Rspamd-Server: hera X-Rspamd-Queue-Id: 596134EE X-Spamd-Result: default: False [0.40 / 15.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; HAS_ORG_HEADER(0.00)[]; RCVD_COUNT_THREE(0.00)[3]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_LAST(0.00)[]; MID_RHS_NOT_FQDN(0.50)[] Juergen Gross, le lun. 20 déc. 2021 17:07:09 +0100, a ecrit: > 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 = DOMID_SELF; > - unsigned long max; > > pt_base = page_table_base; > first_free_pfn = 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 = ret; > > - max = e820_get_maxpfn(); > - if ( max < last_free_pfn ) > - last_free_pfn = max; > + last_free_pfn = e820_get_maxpfn(ret); > } > #endif > > 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 > > -unsigned long e820_get_maxpfn(void) > +unsigned long e820_get_maxpfn(unsigned long pages) > { > int i; > - unsigned long pfn, max = 0; > + unsigned long pfns, start = 0; > > e820_get_memmap(); > > @@ -296,10 +296,12 @@ unsigned long e820_get_maxpfn(void) > { > if ( e820_map[i].type != E820_RAM ) > continue; > - pfn = (e820_map[i].addr + e820_map[i].size) >> PAGE_SHIFT; > - if ( pfn > max ) > - max = pfn; > + pfns = e820_map[i].size >> PAGE_SHIFT; > + start = e820_map[i].addr >> PAGE_SHIFT; > + if ( pages <= pfns ) > + return start + pages; > + pages -= pfns; > } > > - 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; > > -unsigned long e820_get_maxpfn(void); > +unsigned long e820_get_maxpfn(unsigned long pages); > > #endif /*__E820_HEADER*/ > -- > 2.26.2 > -- Samuel Now I know someone out there is going to claim, "Well then, UNIX is intuitive, because you only need to learn 5000 commands, and then everything else follows from that! Har har har!" (Andy Bates in comp.os.linux.misc, on "intuitive interfaces", slightly defending Macs.) From minios-devel-bounces@lists.xenproject.org Mon Dec 20 23:22:38 2021 Return-path: Envelope-to: archives@lists.xenproject.org Delivery-date: Mon, 20 Dec 2021 23:22:38 +0000 Received: from list by lists.xenproject.org with outflank-mailman.250055.430631 (Exim 4.92) (envelope-from ) id 1mzRzJ-0000lU-In; Mon, 20 Dec 2021 23:22:37 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 250055.430631; Mon, 20 Dec 2021 23:22:37 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mzRzJ-0000lN-FL; Mon, 20 Dec 2021 23:22:37 +0000 Received: by outflank-mailman (input) for mailman id 250055; Mon, 20 Dec 2021 23:22:35 +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 1mzRzH-0000lC-PJ for minios-devel@lists.xenproject.org; Mon, 20 Dec 2021 23:22:35 +0000 Received: from hera.aquilenet.fr (hera.aquilenet.fr [2a0c:e300::1]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id b56776d1-61eb-11ec-8d39-b1a4ed000e3e; Tue, 21 Dec 2021 00:22:34 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id CB62C4EC; Tue, 21 Dec 2021 00:22:32 +0100 (CET) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 7FQ-1_piAvVs; Tue, 21 Dec 2021 00:22:32 +0100 (CET) Received: from begin.home (2a01cb0088600700de41a9fffe47ec49.ipv6.abo.wanadoo.fr [IPv6:2a01:cb00:8860:700:de41:a9ff:fe47:ec49]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 2741A199; Tue, 21 Dec 2021 00:22:32 +0100 (CET) Received: from samy by begin.home with local (Exim 4.95) (envelope-from ) id 1mzRzD-00069H-GA; Tue, 21 Dec 2021 00:22:31 +0100 X-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-devel" X-Inumbo-ID: b56776d1-61eb-11ec-8d39-b1a4ed000e3e X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Date: Tue, 21 Dec 2021 00:22:31 +0100 From: Samuel Thibault To: Juergen Gross Cc: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org, wl@xen.org Subject: Re: [PATCH v2 04/10] mini-os: respect memory map when ballooning up Message-ID: <20211220232231.sylwjfk6rsjrgeqi@begin> Mail-Followup-To: Samuel Thibault , Juergen Gross , minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org, wl@xen.org References: <20211220160716.4159-1-jgross@suse.com> <20211220160716.4159-5-jgross@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20211220160716.4159-5-jgross@suse.com> Organization: I am not organized User-Agent: NeoMutt/20170609 (1.8.3) X-Spamd-Bar: / Authentication-Results: hera.aquilenet.fr; none X-Rspamd-Server: hera X-Rspamd-Queue-Id: CB62C4EC X-Spamd-Result: default: False [0.40 / 15.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; HAS_ORG_HEADER(0.00)[]; RCVD_COUNT_THREE(0.00)[3]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_LAST(0.00)[]; MID_RHS_NOT_FQDN(0.50)[] Juergen Gross, le lun. 20 déc. 2021 17:07:10 +0100, a ecrit: > +unsigned long e820_get_max_contig_pages(unsigned long pfn, unsigned long pages) > +{ > + int i; > + unsigned long end; > + > + for ( i = 0; i < e820_entries && e820_map[i].addr < (pfn << PAGE_SHIFT); Shouldn't that be addr+size? Otherwise if pfn is in the middle of an e820 entry, we will miss picking up that. > + i++ ) > + { > + end = (e820_map[i].addr + e820_map[i].size) >> PAGE_SHIFT; > + if ( e820_map[i].type != E820_RAM || end <= pfn ) > + continue; > + > + return ((end - pfn) > pages) ? pages : end - pfn; > + } > + > + return 0; > +} From minios-devel-bounces@lists.xenproject.org Mon Dec 20 23:30:10 2021 Return-path: Envelope-to: archives@lists.xenproject.org Delivery-date: Mon, 20 Dec 2021 23:30:10 +0000 Received: from list by lists.xenproject.org with outflank-mailman.250060.430646 (Exim 4.92) (envelope-from ) id 1mzS6b-0002Mw-EZ; Mon, 20 Dec 2021 23:30:09 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 250060.430646; Mon, 20 Dec 2021 23:30:09 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mzS6b-0002Mp-BY; Mon, 20 Dec 2021 23:30:09 +0000 Received: by outflank-mailman (input) for mailman id 250060; Mon, 20 Dec 2021 23:30:08 +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 1mzS6Z-0002IS-UI for minios-devel@lists.xenproject.org; Mon, 20 Dec 2021 23:30:07 +0000 Received: from hera.aquilenet.fr (hera.aquilenet.fr [185.233.100.1]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id c3b4ef65-61ec-11ec-9e60-abaf8a552007; Tue, 21 Dec 2021 00:30:06 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 1715E25E; Tue, 21 Dec 2021 00:30:06 +0100 (CET) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id oa-M3gAE_cT6; Tue, 21 Dec 2021 00:30:05 +0100 (CET) Received: from begin.home (2a01cb0088600700de41a9fffe47ec49.ipv6.abo.wanadoo.fr [IPv6:2a01:cb00:8860:700:de41:a9ff:fe47:ec49]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 006CB199; Tue, 21 Dec 2021 00:30:04 +0100 (CET) Received: from samy by begin.home with local (Exim 4.95) (envelope-from ) id 1mzS6W-0006Bz-Cp; Tue, 21 Dec 2021 00:30:04 +0100 X-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-devel" X-Inumbo-ID: c3b4ef65-61ec-11ec-9e60-abaf8a552007 X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Date: Tue, 21 Dec 2021 00:30:04 +0100 From: Samuel Thibault To: Juergen Gross Cc: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org, wl@xen.org Subject: Re: [PATCH v2 06/10] mini-os: add memory map service functions Message-ID: <20211220233004.kyvlnh5nlk2nfs5q@begin> Mail-Followup-To: Samuel Thibault , Juergen Gross , minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org, wl@xen.org References: <20211220160716.4159-1-jgross@suse.com> <20211220160716.4159-7-jgross@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20211220160716.4159-7-jgross@suse.com> Organization: I am not organized User-Agent: NeoMutt/20170609 (1.8.3) X-Spamd-Bar: / Authentication-Results: hera.aquilenet.fr; none X-Rspamd-Server: hera X-Rspamd-Queue-Id: 1715E25E X-Spamd-Result: default: False [0.40 / 15.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; HAS_ORG_HEADER(0.00)[]; RCVD_COUNT_THREE(0.00)[3]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_LAST(0.00)[]; MID_RHS_NOT_FQDN(0.50)[] Juergen Gross, le lun. 20 déc. 2021 17:07:12 +0100, a ecrit: > 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 = 0, needed = (long)pages << PAGE_SHIFT; > + > + for ( i = 0; i < e820_entries && e820_map[i].addr < last + needed; i++ ) > + last = e820_map[i].addr + e820_map[i].size; > + > + if ( i == 0 || e820_map[i - 1].type != E820_RESERVED ) > + e820_insert_entry_at(i, last, needed, E820_RESERVED); > + else > + e820_map[i - 1].size += needed; > + > + return last >> PAGE_SHIFT; > +} > + > +void e820_put_reserved_pfns(unsigned long start_pfn, int pages) > +{ > + int i; > + unsigned long addr = start_pfn << PAGE_SHIFT; > + unsigned long size = (long)pages << PAGE_SHIFT; > + > + for ( i = 0; > + i < e820_entries && addr >= e820_map[i].addr + e820_map[i].size; > + i++ ); > + > + BUG_ON(i == e820_entries || e820_map[i].type != E820_RESERVED || > + addr + size > e820_map[i].addr + e820_map[i].size); > + > + if ( addr == e820_map[i].addr ) > + { > + e820_map[i].addr += size; > + e820_map[i].size -= size; > + if ( e820_map[i].size == 0 ) > + e820_remove_entry(i); > + return; > + } > + > + if ( addr + size == e820_map[i].addr + e820_map[i].size ) > + { > + e820_map[i].size -= 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 = addr - e820_map[i].addr; > +} > #endif > > 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; > > unsigned long e820_get_maxpfn(unsigned long pages); > unsigned long e820_get_max_contig_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 > > #endif /*__E820_HEADER*/ > -- > 2.26.2 > -- Samuel sauf que le firewall bloque tout sauf internet -+- ben ouais, il bloque ipx/spx ! -+- From minios-devel-bounces@lists.xenproject.org Tue Dec 21 06:11:06 2021 Return-path: Envelope-to: archives@lists.xenproject.org Delivery-date: Tue, 21 Dec 2021 06:11:06 +0000 Received: from list by lists.xenproject.org with outflank-mailman.250104.430716 (Exim 4.92) (envelope-from ) id 1mzYMZ-0006cB-N1; Tue, 21 Dec 2021 06:11:03 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 250104.430716; Tue, 21 Dec 2021 06:11:03 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mzYMZ-0006c3-It; Tue, 21 Dec 2021 06:11:03 +0000 Received: by outflank-mailman (input) for mailman id 250104; Tue, 21 Dec 2021 06:11:01 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mzYMX-0006bs-JM for minios-devel@lists.xenproject.org; Tue, 21 Dec 2021 06:11:01 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id c4307c56-6224-11ec-9e60-abaf8a552007; Tue, 21 Dec 2021 07:11:00 +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 D9CB81F388; Tue, 21 Dec 2021 06:10:58 +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 B653613BEC; Tue, 21 Dec 2021 06:10:58 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 0PU/K/JvwWGpcQAAMHmgww (envelope-from ); Tue, 21 Dec 2021 06:10:58 +0000 X-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-devel" X-Inumbo-ID: c4307c56-6224-11ec-9e60-abaf8a552007 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1640067058; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=+BCGWtcrwcZjd1gTY6yMO7hvlsZU7ZjX2+zQpiK62SA=; b=EkDpu1dBgVO0DRk4iQsQDCF4Kl+0mx5Mi5troK5G4d6F5Cx7xmUHc08j0QcycF2VbdFjPG tz8miKMtxcvLnDqWHQp0BYp/O/3V1DARUVxU4ugsuretWsjNWXwCy+85YKiY5smhk6mTw+ LRLW6FOHSIkp89kS4fcZ9Dg3v1/sCuY= Subject: Re: [PATCH v2 02/10] mini-os: sort and sanitize e820 memory map To: Samuel Thibault , minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org, wl@xen.org References: <20211220160716.4159-1-jgross@suse.com> <20211220160716.4159-3-jgross@suse.com> <20211220231730.nivaq6vgtlyfqhng@begin> From: Juergen Gross Message-ID: Date: Tue, 21 Dec 2021 07:10:58 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: <20211220231730.nivaq6vgtlyfqhng@begin> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="EmIQs1fIhx0bqgUGFs2mZ38AM4ITK67AQ" This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --EmIQs1fIhx0bqgUGFs2mZ38AM4ITK67AQ Content-Type: multipart/mixed; boundary="DXQcuAgICIldR3Cl4iRbQZIN2pHSvcgAa"; protected-headers="v1" From: Juergen Gross To: Samuel Thibault , minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org, wl@xen.org Message-ID: Subject: Re: [PATCH v2 02/10] mini-os: sort and sanitize e820 memory map References: <20211220160716.4159-1-jgross@suse.com> <20211220160716.4159-3-jgross@suse.com> <20211220231730.nivaq6vgtlyfqhng@begin> In-Reply-To: <20211220231730.nivaq6vgtlyfqhng@begin> --DXQcuAgICIldR3Cl4iRbQZIN2pHSvcgAa Content-Type: multipart/mixed; boundary="------------851CCEB259C389291C020CC8" Content-Language: en-US This is a multi-part message in MIME format. --------------851CCEB259C389291C020CC8 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable On 21.12.21 00:17, Samuel Thibault wrote: > Juergen Gross, le lun. 20 d=C3=A9c. 2021 17:07:08 +0100, a ecrit: >> +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_RESE= RVED); >=20 > Rather i+1 so it's most probably already sorted? Ah, yes, good catch. >=20 > Apart from that, >=20 > Reviewed-by: Samuel Thibault Thanks, Juergen --------------851CCEB259C389291C020CC8 Content-Type: application/pgp-keys; name="OpenPGP_0xB0DE9DD628BF132F.asc" Content-Transfer-Encoding: quoted-printable Content-Description: OpenPGP public key Content-Disposition: attachment; filename="OpenPGP_0xB0DE9DD628BF132F.asc" -----BEGIN PGP PUBLIC KEY BLOCK----- xsBNBFOMcBYBCACgGjqjoGvbEouQZw/ToiBg9W98AlM2QHV+iNHsEs7kxWhKMjrioyspZKOBy= cWx w3ie3j9uvg9EOB3aN4xiTv4qbnGiTr3oJhkB1gsb6ToJQZ8uxGq2kaV2KL9650I1SJvedYm8O= f8Z d621lSmoKOwlNClALZNew72NjJLEzTalU1OdT7/i1TXkH09XSSI8mEQ/ouNcMvIJNwQpd369y= 9bf IhWUiVXEK7MlRgUG6MvIj6Y3Am/BBLUVbDa4+gmzDC9ezlZkTZG2t14zWPvxXP3FAp2pkW0xq= G7/ 377qptDmrk42GlSKN4z76ELnLxussxc7I2hx18NUcbP8+uty4bMxABEBAAHNHEp1ZXJnZW4gR= 3Jv c3MgPGpnQHBmdXBmLm5ldD7CwHkEEwECACMFAlOMcBYCGwMHCwkIBwMCAQYVCAIJCgsEFgIDA= QIe AQIXgAAKCRCw3p3WKL8TL0KdB/93FcIZ3GCNwFU0u3EjNbNjmXBKDY4FUGNQH2lvWAUy+dnyT= hpw dtF/jQ6j9RwE8VP0+NXcYpGJDWlNb9/JmYqLiX2Q3TyevpB0CA3dbBQp0OW0fgCetToGIQrg0= MbD 1C/sEOv8Mr4NAfbauXjZlvTj30H2jO0u+6WGM6nHwbh2l5O8ZiHkH32iaSTfN7Eu5RnNVUJbv= oPH Z8SlM4KWm8rG+lIkGurqqu5gu8q8ZMKdsdGC4bBxdQKDKHEFExLJK/nRPFmAuGlId1E3fe10v= 5QL +qHI3EIPtyfE7i9Hz6rVwi7lWKgh7pe0ZvatAudZ+JNIlBKptb64FaiIOAWDCx1SzR9KdWVyZ= 2Vu IEdyb3NzIDxqZ3Jvc3NAc3VzZS5jb20+wsB5BBMBAgAjBQJTjHCvAhsDBwsJCAcDAgEGFQgCC= QoL BBYCAwECHgECF4AACgkQsN6d1ii/Ey/HmQf/RtI7kv5A2PS4RF7HoZhPVPogNVbC4YA6lW7Dr= Wf0 teC0RR3MzXfy6pJ+7KLgkqMlrAbN/8Dvjoz78X+5vhH/rDLa9BuZQlhFmvcGtCF8eR0T1v0nC= /nu AFVGy+67q2DH8As3KPu0344TBDpAvr2uYM4tSqxK4DURx5INz4ZZ0WNFHcqsfvlGJALDeE0Lh= ITT d9jLzdDad1pQSToCnLl6SBJZjDOX9QQcyUigZFtCXFst4dlsvddrxyqT1f17+2cFSdu7+ynLm= XBK 7abQ3rwJY8SbRO2iRulogc5vr/RLMMlscDAiDkaFQWLoqHHOdfO9rURssHNN8WkMnQfvUewRz= 80h SnVlcmdlbiBHcm9zcyA8amdyb3NzQG5vdmVsbC5jb20+wsB5BBMBAgAjBQJTjHDXAhsDBwsJC= AcD AgEGFQgCCQoLBBYCAwECHgECF4AACgkQsN6d1ii/Ey8PUQf/ehmgCI9jB9hlgexLvgOtf7PJn= FOX gMLdBQgBlVPO3/D9R8LtF9DBAFPNhlrsfIG/SqICoRCqUcJ96Pn3P7UUinFG/I0ECGF4EvTE1= jnD kfJZr6jrbjgyoZHiw/4BNwSTL9rWASyLgqlA8u1mf+c2yUwcGhgkRAd1gOwungxcwzwqgljf0= N51 N5JfVRHRtyfwq/ge+YEkDGcTU6Y0sPOuj4Dyfm8fJzdfHNQsWq3PnczLVELStJNdapwPOoE+l= otu fe3AM2vAEYJ9rTz3Cki4JFUsgLkHFqGZarrPGi1eyQcXeluldO3m91NK/1xMI3/+8jbO0tsn1= tqS EUGIJi7ox80eSnVlcmdlbiBHcm9zcyA8amdyb3NzQHN1c2UuZGU+wsB5BBMBAgAjBQJTjHDrA= hsD BwsJCAcDAgEGFQgCCQoLBBYCAwECHgECF4AACgkQsN6d1ii/Ey+LhQf9GL45eU5vOowA2u5N3= g3O ZUEBmDHVVbqMtzwlmNC4k9Kx39r5s2vcFl4tXqW7g9/ViXYuiDXb0RfUpZiIUW89siKrkzmQ5= dM7 wRqzgJpJwK8Bn2MIxAKArekWpiCKvBOB/Cc+3EXE78XdlxLyOi/NrmSGRIov0karw2RzMNOu5= D+j LRZQd1Sv27AR+IP3I8U4aqnhLpwhK7MEy9oCILlgZ1QZe49kpcumcZKORmzBTNh30FVKK1Evm= V2x AKDoaEOgQB4iFQLhJCdP1I5aSgM5IVFdn7v5YgEYuJYx37IoN1EblHI//x/e2AaIHpzK5h88N= Eaw QsaNRpNSrcfbFmAg987ATQRTjHAWAQgAyzH6AOODMBjgfWE9VeCgsrwH3exNAU32gLq2xvjpW= nHI s98ndPUDpnoxWQugJ6MpMncr0xSwFmHEgnSEjK/PAjppgmyc57BwKII3sV4on+gDVFJR6Y8ZR= wgn BC5mVM6JjQ5xDk8WRXljExRfUX9pNhdE5eBOZJrDRoLUmmjDtKzWaDhIg/+1Hzz93X4fCQkNV= bVF LELU9bMaLPBG/x5q4iYZ2k2ex6d47YE1ZFdMm6YBYMOljGkZKwYde5ldM9mo45mmwe0icXKLk= pEd IXKTZeKDO+Hdv1aqFuAcccTg9RXDQjmwhC3yEmrmcfl0+rPghO0Iv3OOImwTEe4co3c1mwARA= QAB wsBfBBgBAgAJBQJTjHAWAhsMAAoJELDendYovxMvQ/gH/1ha96vm4P/L+bQpJwrZ/dneZcmEw= Tbe 8YFsw2V/Buv6Z4Mysln3nQK5ZadD534CF7TDVft7fC4tU4PONxF5D+/tvgkPfDAfF77zy2AH1= vJz Q1fOU8lYFpZXTXIHb+559UqvIB8AdgR3SAJGHHt4RKA0F7f5ipYBBrC6cyXJyyoprT10EMvU8= VGi wXvTyJz3fjoYsdFzpWPlJEBRMedCot60g5dmbdrZ5DWClAr0yau47zpWj3enf1tLWaqcsuylW= svi uGjKGw7KHQd3bxALOknAp4dN3QwBYCKuZ7AddY9yjynVaD5X7nF9nO5BjR/i1DG86lem3iBDX= zXs ZDn8R38=3D =3D2wuH -----END PGP PUBLIC KEY BLOCK----- --------------851CCEB259C389291C020CC8-- --DXQcuAgICIldR3Cl4iRbQZIN2pHSvcgAa-- --EmIQs1fIhx0bqgUGFs2mZ38AM4ITK67AQ Content-Type: application/pgp-signature; name="OpenPGP_signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="OpenPGP_signature" -----BEGIN PGP SIGNATURE----- wsB5BAABCAAjFiEEhRJncuj2BJSl0Jf3sN6d1ii/Ey8FAmHBb/IFAwAAAAAACgkQsN6d1ii/Ey8m MAf/Sq+eUsguw/e2YhMA3eAnmtDZGTywIHkGv7qjcSCs+xcv5ChPLakkWCktuuzA+GvBpvNsYg3f BUkf8AuvDfWdL94M+kCQqwxDkQd/2sN5u8/s3qtRPc8arLNSdNSU4qon76XKI5RAOXJuAg1XHZOR qiL0SPg/Ggki8HaBNZkQHxRT621qsyH40uee8S8A3VG62OC0rsR3itX/hnU5WQYAS1mNcVaYsDrg OlcsEF7jJus8zUnTOIb/l55JH3wjMiauR96NZUsOydkjbeU1Y0yLCgVGZugoYr7sdduHpAILwlnx 2TxxtF/IY7E55OcgI6bcyb1vC5AlkBBkG4YQIQZCkw== =xlCx -----END PGP SIGNATURE----- --EmIQs1fIhx0bqgUGFs2mZ38AM4ITK67AQ-- From minios-devel-bounces@lists.xenproject.org Tue Dec 21 06:16:53 2021 Return-path: Envelope-to: archives@lists.xenproject.org Delivery-date: Tue, 21 Dec 2021 06:16:53 +0000 Received: from list by lists.xenproject.org with outflank-mailman.250109.430731 (Exim 4.92) (envelope-from ) id 1mzYSC-0007KL-DP; Tue, 21 Dec 2021 06:16:52 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 250109.430731; Tue, 21 Dec 2021 06:16:52 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mzYSC-0007KD-9m; Tue, 21 Dec 2021 06:16:52 +0000 Received: by outflank-mailman (input) for mailman id 250109; Tue, 21 Dec 2021 06:16: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 1mzYSB-0007K2-1a for minios-devel@lists.xenproject.org; Tue, 21 Dec 2021 06:16: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 95522ac5-6225-11ec-9e60-abaf8a552007; Tue, 21 Dec 2021 07:16:50 +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 CE1331F388; Tue, 21 Dec 2021 06:16:49 +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 AC0C213BEC; Tue, 21 Dec 2021 06:16:49 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id q2ugKFFxwWHPcwAAMHmgww (envelope-from ); Tue, 21 Dec 2021 06:16:49 +0000 X-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-devel" X-Inumbo-ID: 95522ac5-6225-11ec-9e60-abaf8a552007 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1640067409; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=FNzFSW66KymIMqXtTT0NTCRx2C1DMMVxbRTWoJaBfKk=; b=NYsJQNoG6eK52gLxp8R3whIsbeaLtuwhzCfrZKqGx/iQ+TzuxRNZHfGQgjLKMA/P4GYnhb yp4ZEjqV7FzSgosQr9dQ5/DEtl5MoffMt/i2VQ8UpUecLkvFW1NO2wF+k120e9sSBZvSxQ 6h6qxL9XFCwO1LXA+WCRySQcvKn/kqQ= To: Samuel Thibault , minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org, wl@xen.org References: <20211220160716.4159-1-jgross@suse.com> <20211220160716.4159-5-jgross@suse.com> <20211220232231.sylwjfk6rsjrgeqi@begin> From: Juergen Gross Subject: Re: [PATCH v2 04/10] mini-os: respect memory map when ballooning up Message-ID: <75aa6bf0-dbbc-3076-ee45-42eb0b89eeff@suse.com> Date: Tue, 21 Dec 2021 07:16:49 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: <20211220232231.sylwjfk6rsjrgeqi@begin> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="A73FxjnSIIT9oLpEwxB9PDWIhnmEujgci" This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --A73FxjnSIIT9oLpEwxB9PDWIhnmEujgci Content-Type: multipart/mixed; boundary="ZWjDWZxF06NPOmmDPw4yOGvNfjBZravob"; protected-headers="v1" From: Juergen Gross To: Samuel Thibault , minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org, wl@xen.org Message-ID: <75aa6bf0-dbbc-3076-ee45-42eb0b89eeff@suse.com> Subject: Re: [PATCH v2 04/10] mini-os: respect memory map when ballooning up References: <20211220160716.4159-1-jgross@suse.com> <20211220160716.4159-5-jgross@suse.com> <20211220232231.sylwjfk6rsjrgeqi@begin> In-Reply-To: <20211220232231.sylwjfk6rsjrgeqi@begin> --ZWjDWZxF06NPOmmDPw4yOGvNfjBZravob Content-Type: multipart/mixed; boundary="------------CBF0F8890831CB17AA15B325" Content-Language: en-US This is a multi-part message in MIME format. --------------CBF0F8890831CB17AA15B325 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable On 21.12.21 00:22, Samuel Thibault wrote: > Juergen Gross, le lun. 20 d=C3=A9c. 2021 17:07:10 +0100, a ecrit: >> +unsigned long e820_get_max_contig_pages(unsigned long pfn, unsigned l= ong pages) >> +{ >> + int i; >> + unsigned long end; >> + >> + for ( i =3D 0; i < e820_entries && e820_map[i].addr < (pfn << PAG= E_SHIFT); >=20 > Shouldn't that be addr+size? Otherwise if pfn is in the middle of an > e820 entry, we will miss picking up that. No, we want to check all map entries starting below or at the given pfn. The test should be "e820_map[i].addr <=3D (pfn << PAGE_SHIFT)", of course= =2E Juergen --------------CBF0F8890831CB17AA15B325 Content-Type: application/pgp-keys; name="OpenPGP_0xB0DE9DD628BF132F.asc" Content-Transfer-Encoding: quoted-printable Content-Description: OpenPGP public key Content-Disposition: attachment; filename="OpenPGP_0xB0DE9DD628BF132F.asc" -----BEGIN PGP PUBLIC KEY BLOCK----- xsBNBFOMcBYBCACgGjqjoGvbEouQZw/ToiBg9W98AlM2QHV+iNHsEs7kxWhKMjrioyspZKOBy= cWx w3ie3j9uvg9EOB3aN4xiTv4qbnGiTr3oJhkB1gsb6ToJQZ8uxGq2kaV2KL9650I1SJvedYm8O= f8Z d621lSmoKOwlNClALZNew72NjJLEzTalU1OdT7/i1TXkH09XSSI8mEQ/ouNcMvIJNwQpd369y= 9bf IhWUiVXEK7MlRgUG6MvIj6Y3Am/BBLUVbDa4+gmzDC9ezlZkTZG2t14zWPvxXP3FAp2pkW0xq= G7/ 377qptDmrk42GlSKN4z76ELnLxussxc7I2hx18NUcbP8+uty4bMxABEBAAHNHEp1ZXJnZW4gR= 3Jv c3MgPGpnQHBmdXBmLm5ldD7CwHkEEwECACMFAlOMcBYCGwMHCwkIBwMCAQYVCAIJCgsEFgIDA= QIe AQIXgAAKCRCw3p3WKL8TL0KdB/93FcIZ3GCNwFU0u3EjNbNjmXBKDY4FUGNQH2lvWAUy+dnyT= hpw dtF/jQ6j9RwE8VP0+NXcYpGJDWlNb9/JmYqLiX2Q3TyevpB0CA3dbBQp0OW0fgCetToGIQrg0= MbD 1C/sEOv8Mr4NAfbauXjZlvTj30H2jO0u+6WGM6nHwbh2l5O8ZiHkH32iaSTfN7Eu5RnNVUJbv= oPH Z8SlM4KWm8rG+lIkGurqqu5gu8q8ZMKdsdGC4bBxdQKDKHEFExLJK/nRPFmAuGlId1E3fe10v= 5QL +qHI3EIPtyfE7i9Hz6rVwi7lWKgh7pe0ZvatAudZ+JNIlBKptb64FaiIOAWDCx1SzR9KdWVyZ= 2Vu IEdyb3NzIDxqZ3Jvc3NAc3VzZS5jb20+wsB5BBMBAgAjBQJTjHCvAhsDBwsJCAcDAgEGFQgCC= QoL BBYCAwECHgECF4AACgkQsN6d1ii/Ey/HmQf/RtI7kv5A2PS4RF7HoZhPVPogNVbC4YA6lW7Dr= Wf0 teC0RR3MzXfy6pJ+7KLgkqMlrAbN/8Dvjoz78X+5vhH/rDLa9BuZQlhFmvcGtCF8eR0T1v0nC= /nu AFVGy+67q2DH8As3KPu0344TBDpAvr2uYM4tSqxK4DURx5INz4ZZ0WNFHcqsfvlGJALDeE0Lh= ITT d9jLzdDad1pQSToCnLl6SBJZjDOX9QQcyUigZFtCXFst4dlsvddrxyqT1f17+2cFSdu7+ynLm= XBK 7abQ3rwJY8SbRO2iRulogc5vr/RLMMlscDAiDkaFQWLoqHHOdfO9rURssHNN8WkMnQfvUewRz= 80h SnVlcmdlbiBHcm9zcyA8amdyb3NzQG5vdmVsbC5jb20+wsB5BBMBAgAjBQJTjHDXAhsDBwsJC= AcD AgEGFQgCCQoLBBYCAwECHgECF4AACgkQsN6d1ii/Ey8PUQf/ehmgCI9jB9hlgexLvgOtf7PJn= FOX gMLdBQgBlVPO3/D9R8LtF9DBAFPNhlrsfIG/SqICoRCqUcJ96Pn3P7UUinFG/I0ECGF4EvTE1= jnD kfJZr6jrbjgyoZHiw/4BNwSTL9rWASyLgqlA8u1mf+c2yUwcGhgkRAd1gOwungxcwzwqgljf0= N51 N5JfVRHRtyfwq/ge+YEkDGcTU6Y0sPOuj4Dyfm8fJzdfHNQsWq3PnczLVELStJNdapwPOoE+l= otu fe3AM2vAEYJ9rTz3Cki4JFUsgLkHFqGZarrPGi1eyQcXeluldO3m91NK/1xMI3/+8jbO0tsn1= tqS EUGIJi7ox80eSnVlcmdlbiBHcm9zcyA8amdyb3NzQHN1c2UuZGU+wsB5BBMBAgAjBQJTjHDrA= hsD BwsJCAcDAgEGFQgCCQoLBBYCAwECHgECF4AACgkQsN6d1ii/Ey+LhQf9GL45eU5vOowA2u5N3= g3O ZUEBmDHVVbqMtzwlmNC4k9Kx39r5s2vcFl4tXqW7g9/ViXYuiDXb0RfUpZiIUW89siKrkzmQ5= dM7 wRqzgJpJwK8Bn2MIxAKArekWpiCKvBOB/Cc+3EXE78XdlxLyOi/NrmSGRIov0karw2RzMNOu5= D+j LRZQd1Sv27AR+IP3I8U4aqnhLpwhK7MEy9oCILlgZ1QZe49kpcumcZKORmzBTNh30FVKK1Evm= V2x AKDoaEOgQB4iFQLhJCdP1I5aSgM5IVFdn7v5YgEYuJYx37IoN1EblHI//x/e2AaIHpzK5h88N= Eaw QsaNRpNSrcfbFmAg987ATQRTjHAWAQgAyzH6AOODMBjgfWE9VeCgsrwH3exNAU32gLq2xvjpW= nHI s98ndPUDpnoxWQugJ6MpMncr0xSwFmHEgnSEjK/PAjppgmyc57BwKII3sV4on+gDVFJR6Y8ZR= wgn BC5mVM6JjQ5xDk8WRXljExRfUX9pNhdE5eBOZJrDRoLUmmjDtKzWaDhIg/+1Hzz93X4fCQkNV= bVF LELU9bMaLPBG/x5q4iYZ2k2ex6d47YE1ZFdMm6YBYMOljGkZKwYde5ldM9mo45mmwe0icXKLk= pEd IXKTZeKDO+Hdv1aqFuAcccTg9RXDQjmwhC3yEmrmcfl0+rPghO0Iv3OOImwTEe4co3c1mwARA= QAB wsBfBBgBAgAJBQJTjHAWAhsMAAoJELDendYovxMvQ/gH/1ha96vm4P/L+bQpJwrZ/dneZcmEw= Tbe 8YFsw2V/Buv6Z4Mysln3nQK5ZadD534CF7TDVft7fC4tU4PONxF5D+/tvgkPfDAfF77zy2AH1= vJz Q1fOU8lYFpZXTXIHb+559UqvIB8AdgR3SAJGHHt4RKA0F7f5ipYBBrC6cyXJyyoprT10EMvU8= VGi wXvTyJz3fjoYsdFzpWPlJEBRMedCot60g5dmbdrZ5DWClAr0yau47zpWj3enf1tLWaqcsuylW= svi uGjKGw7KHQd3bxALOknAp4dN3QwBYCKuZ7AddY9yjynVaD5X7nF9nO5BjR/i1DG86lem3iBDX= zXs ZDn8R38=3D =3D2wuH -----END PGP PUBLIC KEY BLOCK----- --------------CBF0F8890831CB17AA15B325-- --ZWjDWZxF06NPOmmDPw4yOGvNfjBZravob-- --A73FxjnSIIT9oLpEwxB9PDWIhnmEujgci Content-Type: application/pgp-signature; name="OpenPGP_signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="OpenPGP_signature" -----BEGIN PGP SIGNATURE----- wsB5BAABCAAjFiEEhRJncuj2BJSl0Jf3sN6d1ii/Ey8FAmHBcVEFAwAAAAAACgkQsN6d1ii/Ey9t bAf/cGtRjmjSThW9QT/JgEuMetMO6XNVQ3v7Lu6pdThHuFT5sVpVtnhBu6f83Cg/4wO3cJ5uJSjA DMZiUUYwospX2SLsT4d446C/6XJwxrhJWahVX8a3PDABd32xZts3e8+44MnihSO0Fn42Zu9YUb8T D1eQ/wda9dtVS2TTiBqpWi6mv2ZrVeXW8j6jeTD9gO9BXShHyVQKLjuLBH3FmbP0rsP4Y16P8c62 LPkRChWDU65l2GMVvOg+y/5JlL4doHYQ8TC77zSsOM2PbfMrRTFAzr65+g8GA2B1rsHbWWSpM0yy iUlN0lJ74V75IbSiZVt+Ct/FDjavRYnudFJI0qipuA== =HlF8 -----END PGP SIGNATURE----- --A73FxjnSIIT9oLpEwxB9PDWIhnmEujgci-- From minios-devel-bounces@lists.xenproject.org Tue Dec 21 08:18:12 2021 Return-path: Envelope-to: archives@lists.xenproject.org Delivery-date: Tue, 21 Dec 2021 08:18:12 +0000 Received: from list by lists.xenproject.org with outflank-mailman.250172.430826 (Exim 4.92) (envelope-from ) id 1mzaLZ-0007sA-Ot; Tue, 21 Dec 2021 08:18:09 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 250172.430826; Tue, 21 Dec 2021 08:18:09 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mzaLZ-0007s0-Li; Tue, 21 Dec 2021 08:18:09 +0000 Received: by outflank-mailman (input) for mailman id 250172; Tue, 21 Dec 2021 08:18:08 +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 1mzaLY-0007rt-T1 for minios-devel@lists.xenproject.org; Tue, 21 Dec 2021 08:18:08 +0000 Received: from hera.aquilenet.fr (hera.aquilenet.fr [185.233.100.1]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 8632c1b1-6236-11ec-9e60-abaf8a552007; Tue, 21 Dec 2021 09:18:06 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 559791F7; Tue, 21 Dec 2021 09:18:05 +0100 (CET) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id VGwyIgt8v35K; Tue, 21 Dec 2021 09:18:04 +0100 (CET) Received: from begin.home (2a01cb0088600700de41a9fffe47ec49.ipv6.abo.wanadoo.fr [IPv6:2a01:cb00:8860:700:de41:a9ff:fe47:ec49]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 9474A18E; Tue, 21 Dec 2021 09:18:03 +0100 (CET) Received: from samy by begin.home with local (Exim 4.95) (envelope-from ) id 1mzaLS-000gSV-Os; Tue, 21 Dec 2021 09:18:02 +0100 X-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-devel" X-Inumbo-ID: 8632c1b1-6236-11ec-9e60-abaf8a552007 X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Date: Tue, 21 Dec 2021 09:18:02 +0100 From: Samuel Thibault To: Juergen Gross Cc: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org, wl@xen.org Subject: Re: [PATCH v2 04/10] mini-os: respect memory map when ballooning up Message-ID: <20211221081802.qop7fsow2mu4qugy@begin> Mail-Followup-To: Samuel Thibault , Juergen Gross , minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org, wl@xen.org References: <20211220160716.4159-1-jgross@suse.com> <20211220160716.4159-5-jgross@suse.com> <20211220232231.sylwjfk6rsjrgeqi@begin> <75aa6bf0-dbbc-3076-ee45-42eb0b89eeff@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <75aa6bf0-dbbc-3076-ee45-42eb0b89eeff@suse.com> Organization: I am not organized User-Agent: NeoMutt/20170609 (1.8.3) X-Spamd-Bar: / Authentication-Results: hera.aquilenet.fr; none X-Rspamd-Server: hera X-Rspamd-Queue-Id: 559791F7 X-Spamd-Result: default: False [0.40 / 15.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; HAS_ORG_HEADER(0.00)[]; RCVD_COUNT_THREE(0.00)[3]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_LAST(0.00)[]; MID_RHS_NOT_FQDN(0.50)[] Juergen Gross, le mar. 21 déc. 2021 07:16:49 +0100, a ecrit: > On 21.12.21 00:22, Samuel Thibault wrote: > > Juergen Gross, le lun. 20 déc. 2021 17:07:10 +0100, a ecrit: > > > +unsigned long e820_get_max_contig_pages(unsigned long pfn, unsigned long pages) > > > +{ > > > + int i; > > > + unsigned long end; > > > + > > > + for ( i = 0; i < e820_entries && e820_map[i].addr < (pfn << PAGE_SHIFT); > > > > Shouldn't that be addr+size? Otherwise if pfn is in the middle of an > > e820 entry, we will miss picking up that. > > No, we want to check all map entries starting below or at the given pfn. > The test should be "e820_map[i].addr <= (pfn << PAGE_SHIFT)", of course. Ah, yes, due to the "<" I mistook it for a loop that skips the entries before the targetted pfn :) With <=, Reviewed-by: Samuel Thibault Samuel From minios-devel-bounces@lists.xenproject.org Tue Dec 21 08:46:57 2021 Return-path: Envelope-to: archives@lists.xenproject.org Delivery-date: Tue, 21 Dec 2021 08:46:57 +0000 Received: from list by lists.xenproject.org with outflank-mailman.250180.430867 (Exim 4.92) (envelope-from ) id 1mzanR-0003YR-PM; Tue, 21 Dec 2021 08:46:57 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 250180.430867; Tue, 21 Dec 2021 08:46:57 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mzanR-0003YD-LL; Tue, 21 Dec 2021 08:46:57 +0000 Received: by outflank-mailman (input) for mailman id 250180; Tue, 21 Dec 2021 08:46: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 1mzanP-0002z5-4v for minios-devel@lists.xenproject.org; Tue, 21 Dec 2021 08:46:55 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 8b55e180-623a-11ec-8d39-b1a4ed000e3e; Tue, 21 Dec 2021 09:46:53 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id A534421106; Tue, 21 Dec 2021 08:46:52 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 7BA5513BEC; Tue, 21 Dec 2021 08:46:52 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id mNnzHHyUwWFHMAAAMHmgww (envelope-from ); Tue, 21 Dec 2021 08:46:52 +0000 X-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-devel" X-Inumbo-ID: 8b55e180-623a-11ec-8d39-b1a4ed000e3e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1640076412; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UOETZh2f6WeeCiugBSdED352ymyLb1Vp+v99fCDGOVo=; b=K+hcy7x1iKb9VYzLkL4sA69QZvp0PvKxySYlmloAtVeZRTMhdSj8eVGQS04N0xJ+Ld7obm xRv7sZHBRokmzx5i3PO8qJ0bp9IJUmQ/87QIPz+vC6v2CaiLk/dX/EaUc2p4yh96L/uWiF icnbrFHADIeXyOG/2SKNSaTodzd0VJQ= From: Juergen Gross To: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org Cc: samuel.thibault@ens-lyon.org, wl@xen.org, Juergen Gross Subject: [PATCH v3 03/10] mini-os: don't assume contiguous RAM when initializing in PVH mode Date: Tue, 21 Dec 2021 09:46:29 +0100 Message-Id: <20211221084636.6987-4-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20211221084636.6987-1-jgross@suse.com> References: <20211221084636.6987-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 = DOMID_SELF; - unsigned long max; pt_base = page_table_base; first_free_pfn = 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 = ret; - max = e820_get_maxpfn(); - if ( max < last_free_pfn ) - last_free_pfn = max; + last_free_pfn = e820_get_maxpfn(ret); } #endif diff --git a/e820.c b/e820.c index 70286cb..8030f43 100644 --- a/e820.c +++ b/e820.c @@ -285,10 +285,10 @@ void arch_print_memmap(void) } #endif -unsigned long e820_get_maxpfn(void) +unsigned long e820_get_maxpfn(unsigned long pages) { int i; - unsigned long pfn, max = 0; + unsigned long pfns, start = 0; e820_get_memmap(); @@ -296,10 +296,12 @@ unsigned long e820_get_maxpfn(void) { if ( e820_map[i].type != E820_RAM ) continue; - pfn = (e820_map[i].addr + e820_map[i].size) >> PAGE_SHIFT; - if ( pfn > max ) - max = pfn; + pfns = e820_map[i].size >> PAGE_SHIFT; + start = e820_map[i].addr >> PAGE_SHIFT; + if ( pages <= pfns ) + return start + pages; + pages -= pfns; } - 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; -unsigned long e820_get_maxpfn(void); +unsigned long e820_get_maxpfn(unsigned long pages); #endif /*__E820_HEADER*/ -- 2.26.2 From minios-devel-bounces@lists.xenproject.org Tue Dec 21 08:46:58 2021 Return-path: Envelope-to: archives@lists.xenproject.org Delivery-date: Tue, 21 Dec 2021 08:46:58 +0000 Received: from list by lists.xenproject.org with outflank-mailman.250181.430868 (Exim 4.92) (envelope-from ) id 1mzanR-0003Yk-Tm; Tue, 21 Dec 2021 08:46:57 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 250181.430868; Tue, 21 Dec 2021 08:46:57 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mzanR-0003YU-NG; Tue, 21 Dec 2021 08:46:57 +0000 Received: by outflank-mailman (input) for mailman id 250181; Tue, 21 Dec 2021 08:46:55 +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 1mzanP-0002yE-8d for minios-devel@lists.xenproject.org; Tue, 21 Dec 2021 08:46:55 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 8b3e5efb-623a-11ec-9e60-abaf8a552007; Tue, 21 Dec 2021 09:46:52 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 75C921F3B6; Tue, 21 Dec 2021 08:46:52 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 4B40013BEC; Tue, 21 Dec 2021 08:46:52 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id kKs1EXyUwWFHMAAAMHmgww (envelope-from ); Tue, 21 Dec 2021 08:46:52 +0000 X-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-devel" X-Inumbo-ID: 8b3e5efb-623a-11ec-9e60-abaf8a552007 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1640076412; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cWXSsRb7aAVsvcWbgBY23t6rGMkd9cnCIBDGNyaoF64=; b=irEHSRRpWz7T4cfCEBeCvZnHmHhIhSwu2Q6XuAxDuRJkO4E8/+tswxDUV4Kmbjqezrdxh/ RTssKq/iFE2QHg+cTsC3kvgyUH+WtXXtZLkgrbcIMVK4ZYxHmn3zHHkoSS/6twrBC012mP SjScZVuWvOMoFJLFRNHe19R2YaVlJ3c= From: Juergen Gross To: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org Cc: samuel.thibault@ens-lyon.org, wl@xen.org, Juergen Gross Subject: [PATCH v3 02/10] mini-os: sort and sanitize e820 memory map Date: Tue, 21 Dec 2021 09:46:28 +0100 Message-Id: <20211221084636.6987-3-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20211221084636.6987-1-jgross@suse.com> References: <20211221084636.6987-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Do some processing of the E820 memory map obtained from the hypervisor: - align the entries to page boundaries - sort the entries by their start address - merge adjacent entries of same type This is relevant for PVH mode only. Signed-off-by: Juergen Gross Reviewed-by: Samuel Thibault --- V2: - correct page boundary rounding - handle overlaps after rounding (Samuel Thibault) - improve sorting (Samuel Thibault) V3: - small optimization in e820_sanitize() (Samuel Thibault) --- e820.c | 186 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 186 insertions(+) diff --git a/e820.c b/e820.c index 2165280..70286cb 100644 --- a/e820.c +++ b/e820.c @@ -57,6 +57,190 @@ static char *e820_types[E820_TYPES] = { [E820_PMEM] = "PMEM" }; +/* + * 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 = idx; i < e820_entries; i++ ) + e820_map[i] = 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 == E820_MAX ) + { + xprintk("E820 memory map overflow\n"); + do_exit(); + } + + e820_entries++; + for ( i = e820_entries - 1; i > idx; i-- ) + e820_map[i] = e820_map[i - 1]; + + e820_map[idx].addr = addr; + e820_map[idx].size = size; + e820_map[idx].type = type; +} + +static void e820_insert_entry(unsigned long addr, unsigned long size, + unsigned int type) +{ + int i; + + for ( i = 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 = e820_map[idx1]; + e820_map[idx1] = e820_map[idx2]; + e820_map[idx2] = 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 = 1; i < e820_entries; i++ ) + for ( j = 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 = 1; i < e820_entries; i++ ) + { + if ( e820_map[i - 1].addr + e820_map[i - 1].size <= 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 += e820_map[i - 1].size; + e820_map[i].size -= 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 >= e820_map[i].size ) + { + e820_remove_entry(i); + i--; + } + else + { + start = e820_map[i].addr + e820_map[i - 1].size; + end = e820_map[i].addr + e820_map[i].size; + type = e820_map[i].type; + e820_remove_entry(i); + e820_insert_entry(start, end - start, type); + } + } + + /* Merge adjacent entries. */ + for ( i = 0; i < e820_entries - 1; i++ ) + { + if ( e820_map[i].type == e820_map[i + 1].type && + e820_map[i].addr + e820_map[i].size >= 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 = e820_map[i + 1].addr - e820_map[i].addr + + 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 = 0; i < e820_entries; i++ ) + { + start = e820_map[i].addr; + end = start + e820_map[i].size; + if ( (1U << e820_map[i].type) & E820_NARROW ) + { + if ( start & (PAGE_SIZE - 1) ) + { + start = round_pgup(start); + e820_insert_entry_at(i, start - PAGE_SIZE, PAGE_SIZE, + E820_TMP_RESERVED); + i++; + } + if ( end & (PAGE_SIZE - 1) ) + { + end = round_pgdown(end); + e820_insert_entry_at(i + 1, end, PAGE_SIZE, E820_TMP_RESERVED); + i++; + } + } + else + { + start = round_pgdown(start); + end = round_pgup(end); + } + e820_map[i].addr = start; + e820_map[i].size = end - start; + } + + /* Sanitize memory map (again). */ + e820_process_entries(); + + /* Make remaining temporarily reserved entries permanently reserved. */ + for ( i = 0; i < e820_entries; i++ ) + if ( e820_map[i].type == E820_TMP_RESERVED ) + e820_map[i].type = E820_RESERVED; +} + static void e820_get_memmap(void) { long ret; @@ -71,6 +255,8 @@ static void e820_get_memmap(void) do_exit(); } e820_entries = memmap.nr_entries; + + e820_sanitize(); } void arch_print_memmap(void) -- 2.26.2 From minios-devel-bounces@lists.xenproject.org Tue Dec 21 08:46:58 2021 Return-path: Envelope-to: archives@lists.xenproject.org Delivery-date: Tue, 21 Dec 2021 08:46:58 +0000 Received: from list by lists.xenproject.org with outflank-mailman.250182.430875 (Exim 4.92) (envelope-from ) id 1mzanS-0003Z5-5T; Tue, 21 Dec 2021 08:46:58 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 250182.430875; Tue, 21 Dec 2021 08:46:58 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mzanR-0003Yu-Pg; Tue, 21 Dec 2021 08:46:57 +0000 Received: by outflank-mailman (input) for mailman id 250182; Tue, 21 Dec 2021 08:46:56 +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 1mzanQ-0002z5-50 for minios-devel@lists.xenproject.org; Tue, 21 Dec 2021 08:46:56 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 8be91413-623a-11ec-8d39-b1a4ed000e3e; Tue, 21 Dec 2021 09:46:53 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 9AABA210FE; Tue, 21 Dec 2021 08:46:53 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 727C513BEC; Tue, 21 Dec 2021 08:46:53 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id mCPKGn2UwWFHMAAAMHmgww (envelope-from ); Tue, 21 Dec 2021 08:46:53 +0000 X-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-devel" X-Inumbo-ID: 8be91413-623a-11ec-8d39-b1a4ed000e3e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1640076413; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NwQ4mRiosEanvExB6LuAnyU1/Dqqja/tWJzhJY5Y3Ms=; b=toWR3hQZog096RnIYPQ1YgpGL+3XJJxAKXFR7/u0lBiMX8IQz65YmqikDO2VThhMo2Tr3m QGM+C2XHhFTEbmPyMPCNWoSGauQPn5SGNIQF/NQb6AZvt55hcNQR2AXv5iD2Q63LhjqSzl Ssb+a4Zou4T5AnVmYfO6lj2lQbaarsg= From: Juergen Gross To: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org Cc: samuel.thibault@ens-lyon.org, wl@xen.org, Juergen Gross Subject: [PATCH v3 08/10] mini-os: add proper pvh grant table handling Date: Tue, 21 Dec 2021 09:46:34 +0100 Message-Id: <20211221084636.6987-9-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20211221084636.6987-1-jgross@suse.com> References: <20211221084636.6987-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 @@ */ #include +#include +#include #include #include #include #include +#include +#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 = e820_get_reserved_pfns(nr_grant_frames); + for ( i = 0; i < nr_grant_frames; i++ ) + { + xatp.domid = DOMID_SELF; + xatp.idx = i; + xatp.space = XENMAPSPACE_grant_table; + xatp.gpfn = pfn + i; + rc = HYPERVISOR_memory_op(XENMEM_add_to_physmap, &xatp); + if ( rc ) + { + xprintk("could not init grant table\n"); + do_exit(); + } + frames[i] = pfn + i; + } + + return map_frames(frames, nr_grant_frames); +} +#endif void arch_suspend_gnttab(grant_entry_v1_t *gnttab_table, int nr_grant_frames) { -- 2.26.2 From minios-devel-bounces@lists.xenproject.org Tue Dec 21 08:46:58 2021 Return-path: Envelope-to: archives@lists.xenproject.org Delivery-date: Tue, 21 Dec 2021 08:46:58 +0000 Received: from list by lists.xenproject.org with outflank-mailman.250178.430852 (Exim 4.92) (envelope-from ) id 1mzanQ-0003Fx-Da; Tue, 21 Dec 2021 08:46:56 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 250178.430852; Tue, 21 Dec 2021 08:46:56 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mzanQ-0003Fp-9k; Tue, 21 Dec 2021 08:46:56 +0000 Received: by outflank-mailman (input) for mailman id 250178; Tue, 21 Dec 2021 08:46:54 +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 1mzanO-0002yE-8T for minios-devel@lists.xenproject.org; Tue, 21 Dec 2021 08:46:54 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 8b18b320-623a-11ec-9e60-abaf8a552007; Tue, 21 Dec 2021 09:46:52 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 1B4F8210FE; Tue, 21 Dec 2021 08:46:52 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id DE35313BEC; Tue, 21 Dec 2021 08:46:51 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id ndZENHuUwWFHMAAAMHmgww (envelope-from ); Tue, 21 Dec 2021 08:46:51 +0000 X-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-devel" X-Inumbo-ID: 8b18b320-623a-11ec-9e60-abaf8a552007 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1640076412; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=U+uOMy8syfFhtMitypXYhn09cP895ccPVKrqjYHL+gw=; b=SQHIEkusJZx7ayncKT4nh3fqdmklpAZ3y6UU5v3MZBl0r9RCNU7oDVH3wz5MQ94QMGWiUp 4g8Tzg/jNUIEjSvlUAAFX66jlMTVgG5YZKzegmsu316ZO7UK/IKcS282MiedasHna/7wyI 03JCAUr3+Bt/KyZ6XvMazbPW5nQhiw4= From: Juergen Gross To: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org Cc: samuel.thibault@ens-lyon.org, wl@xen.org, Juergen Gross Subject: [PATCH v3 00/10] mini-os: add missing PVH features Date: Tue, 21 Dec 2021 09:46:26 +0100 Message-Id: <20211221084636.6987-1-jgross@suse.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Mini-OS in PVH mode is missing some features, especially in the areas of ballooning and grant tables. With this series I am able to run Xenstore stubdom in PVH mode. Changes in V3: - two minor fixes Changes in V2: - multiple comments addressed Juergen Gross (10): mini-os: split e820 map handling into new source file mini-os: sort and sanitize e820 memory map mini-os: don't assume contiguous RAM when initializing in PVH mode mini-os: respect memory map when ballooning up mini-os: don't repeat definition available via header file mini-os: add memory map service functions mini-os: move x86 specific gnttab coding into arch/x86/gnttab.c mini-os: add proper pvh grant table handling mini-os: prepare grantmap entry interface for use by PVH mode mini-os: modify grant mappings to work in PVH mode Makefile | 1 + arch/arm/mm.c | 11 +- arch/x86/balloon.c | 4 +- arch/x86/gnttab.c | 109 +++++++++++++ arch/x86/mm.c | 121 +-------------- arch/x86/setup.c | 8 +- balloon.c | 33 ++-- e820.c | 376 +++++++++++++++++++++++++++++++++++++++++++++ gntmap.c | 125 +++++++++------ include/balloon.h | 5 +- include/e820.h | 11 ++ include/gntmap.h | 1 + mm.c | 7 +- 13 files changed, 615 insertions(+), 197 deletions(-) create mode 100644 arch/x86/gnttab.c create mode 100644 e820.c -- 2.26.2 From minios-devel-bounces@lists.xenproject.org Tue Dec 21 08:46:59 2021 Return-path: Envelope-to: archives@lists.xenproject.org Delivery-date: Tue, 21 Dec 2021 08:46:59 +0000 Received: from list by lists.xenproject.org with outflank-mailman.250185.430890 (Exim 4.92) (envelope-from ) id 1mzanT-0003r6-Gq; Tue, 21 Dec 2021 08:46:59 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 250185.430890; Tue, 21 Dec 2021 08:46:59 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mzanT-0003pH-4b; Tue, 21 Dec 2021 08:46:59 +0000 Received: by outflank-mailman (input) for mailman id 250185; Tue, 21 Dec 2021 08:46:57 +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 1mzanR-0002yE-8j for minios-devel@lists.xenproject.org; Tue, 21 Dec 2021 08:46:57 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 8b20b9f3-623a-11ec-9e60-abaf8a552007; Tue, 21 Dec 2021 09:46:52 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 454F81F388; Tue, 21 Dec 2021 08:46:52 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 1B70313E02; Tue, 21 Dec 2021 08:46:52 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id KJN2BXyUwWFHMAAAMHmgww (envelope-from ); Tue, 21 Dec 2021 08:46:52 +0000 X-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-devel" X-Inumbo-ID: 8b20b9f3-623a-11ec-9e60-abaf8a552007 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1640076412; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Cvjzn61nlQz/5cNRGk/V3qCPy6sEZi3f9w8y3gbMdqw=; b=fa8B1tQDlQXQ4Zt907exiM6Ql2bQhOqA1zwNXh83f22gymhDvkN6ex5NyHRm8Xje0g1RF/ zO77Ntx1TsENJ1Q3imQwrB/gNxiaKA1BhSlTiz8foW9/jrzSrJplsJUYgRwyyDrKS0V1pu DaQT7mYXn6HwUg4s970wqufVJaGqoTQ= From: Juergen Gross To: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org Cc: samuel.thibault@ens-lyon.org, wl@xen.org, Juergen Gross Subject: [PATCH v3 01/10] mini-os: split e820 map handling into new source file Date: Tue, 21 Dec 2021 09:46:27 +0100 Message-Id: <20211221084636.6987-2-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20211221084636.6987-1-jgross@suse.com> References: <20211221084636.6987-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Introduce e820.c containing all the E820 memory map handling. No functional change. Signed-off-by: Juergen Gross Reviewed-by: Samuel Thibault --- Makefile | 1 + arch/arm/mm.c | 8 ---- arch/x86/mm.c | 70 +---------------------------- e820.c | 119 +++++++++++++++++++++++++++++++++++++++++++++++++ include/e820.h | 6 +++ 5 files changed, 128 insertions(+), 76 deletions(-) create mode 100644 e820.c diff --git a/Makefile b/Makefile index 4b76b55..06b60fc 100644 --- a/Makefile +++ b/Makefile @@ -41,6 +41,7 @@ src-$(CONFIG_TPMFRONT) += tpmfront.c src-$(CONFIG_TPM_TIS) += tpm_tis.c src-$(CONFIG_TPMBACK) += tpmback.c src-y += daytime.c +src-y += e820.c src-y += events.c src-$(CONFIG_FBFRONT) += fbfront.c src-y += gntmap.c diff --git a/arch/arm/mm.c b/arch/arm/mm.c index f806c9f..9068166 100644 --- a/arch/arm/mm.c +++ b/arch/arm/mm.c @@ -7,14 +7,6 @@ #include uint32_t physical_address_offset; -struct e820entry e820_map[1] = { - { - .addr = 0, - .size = ULONG_MAX - 1, - .type = E820_RAM - } -}; -unsigned e820_entries = 1; unsigned long allocate_ondemand(unsigned long n, unsigned long alignment) { diff --git a/arch/x86/mm.c b/arch/x86/mm.c index 8ba14a5..8df93da 100644 --- a/arch/x86/mm.c +++ b/arch/x86/mm.c @@ -64,15 +64,6 @@ extern char stack[]; extern void page_walk(unsigned long va); #ifdef CONFIG_PARAVIRT -struct e820entry e820_map[1] = { - { - .addr = 0, - .size = ULONG_MAX - 1, - .type = E820_RAM - } -}; -unsigned e820_entries = 1; - void arch_mm_preinit(void *p) { start_info_t *si = p; @@ -112,25 +103,11 @@ desc_ptr idt_ptr = .base = (unsigned long)&idt, }; -struct e820entry e820_map[E820_MAX]; -unsigned e820_entries; - -static char *e820_types[E820_TYPES] = { - [E820_RAM] = "RAM", - [E820_RESERVED] = "Reserved", - [E820_ACPI] = "ACPI", - [E820_NVS] = "NVS", - [E820_UNUSABLE] = "Unusable", - [E820_PMEM] = "PMEM" -}; - void arch_mm_preinit(void *p) { long ret; domid_t domid = DOMID_SELF; - struct xen_memory_map memmap; - int i; - unsigned long pfn, max = 0; + unsigned long max; pt_base = page_table_base; first_free_pfn = PFN_UP(to_phys(&_end)); @@ -142,53 +119,10 @@ void arch_mm_preinit(void *p) } last_free_pfn = ret; - memmap.nr_entries = E820_MAX; - set_xen_guest_handle(memmap.buffer, e820_map); - ret = HYPERVISOR_memory_op(XENMEM_memory_map, &memmap); - if ( ret < 0 ) - { - xprintk("could not get memory map\n"); - do_exit(); - } - e820_entries = memmap.nr_entries; - - for ( i = 0; i < e820_entries; i++ ) - { - if ( e820_map[i].type != E820_RAM ) - continue; - pfn = (e820_map[i].addr + e820_map[i].size) >> PAGE_SHIFT; - if ( pfn > max ) - max = pfn; - } - + max = e820_get_maxpfn(); if ( max < last_free_pfn ) last_free_pfn = max; } - -void arch_print_memmap(void) -{ - int i; - unsigned long from, to; - char *type; - char buf[12]; - - printk("Memory map:\n"); - for ( i = 0; i < e820_entries; i++ ) - { - if ( e820_map[i].type >= E820_TYPES || !e820_types[e820_map[i].type] ) - { - snprintf(buf, sizeof(buf), "%8x", e820_map[i].type); - type = buf; - } - else - { - type = e820_types[e820_map[i].type]; - } - from = e820_map[i].addr; - to = from + e820_map[i].size - 1; - printk("%012lx-%012lx: %s\n", from, to, type); - } -} #endif /* diff --git a/e820.c b/e820.c new file mode 100644 index 0000000..2165280 --- /dev/null +++ b/e820.c @@ -0,0 +1,119 @@ +/* -*- Mode:C; c-basic-offset:4; tab-width:4 -*- + * + * (C) 2021 - Juergen Gross, SUSE Software Solutions Germany GmbH + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include +#include +#include +#include +#include +#include +#include + +#ifdef CONFIG_E820_TRIVIAL +struct e820entry e820_map[1] = { + { + .addr = 0, + .size = ULONG_MAX - 1, + .type = E820_RAM + } +}; + +unsigned e820_entries = 1; + +static void e820_get_memmap(void) +{ +} + +#else +struct e820entry e820_map[E820_MAX]; +unsigned e820_entries; + +static char *e820_types[E820_TYPES] = { + [E820_RAM] = "RAM", + [E820_RESERVED] = "Reserved", + [E820_ACPI] = "ACPI", + [E820_NVS] = "NVS", + [E820_UNUSABLE] = "Unusable", + [E820_PMEM] = "PMEM" +}; + +static void e820_get_memmap(void) +{ + long ret; + struct xen_memory_map memmap; + + memmap.nr_entries = E820_MAX; + set_xen_guest_handle(memmap.buffer, e820_map); + ret = HYPERVISOR_memory_op(XENMEM_memory_map, &memmap); + if ( ret < 0 ) + { + xprintk("could not get memory map\n"); + do_exit(); + } + e820_entries = memmap.nr_entries; +} + +void arch_print_memmap(void) +{ + int i; + unsigned long from, to; + char *type; + char buf[12]; + + printk("Memory map:\n"); + for ( i = 0; i < e820_entries; i++ ) + { + if ( e820_map[i].type >= E820_TYPES || !e820_types[e820_map[i].type] ) + { + snprintf(buf, sizeof(buf), "%8x", e820_map[i].type); + type = buf; + } + else + { + type = e820_types[e820_map[i].type]; + } + from = e820_map[i].addr; + to = from + e820_map[i].size - 1; + printk("%012lx-%012lx: %s\n", from, to, type); + } +} +#endif + +unsigned long e820_get_maxpfn(void) +{ + int i; + unsigned long pfn, max = 0; + + e820_get_memmap(); + + for ( i = 0; i < e820_entries; i++ ) + { + if ( e820_map[i].type != E820_RAM ) + continue; + pfn = (e820_map[i].addr + e820_map[i].size) >> PAGE_SHIFT; + if ( pfn > max ) + max = pfn; + } + + return max; +} diff --git a/include/e820.h b/include/e820.h index 920551c..af2129f 100644 --- a/include/e820.h +++ b/include/e820.h @@ -24,6 +24,10 @@ #ifndef __E820_HEADER #define __E820_HEADER +#if defined(__arm__) || defined(__aarch64__) || defined(CONFIG_PARAVIRT) +#define CONFIG_E820_TRIVIAL +#endif + /* PC BIOS standard E820 types and structure. */ #define E820_RAM 1 #define E820_RESERVED 2 @@ -45,4 +49,6 @@ struct __packed e820entry { extern struct e820entry e820_map[]; extern unsigned e820_entries; +unsigned long e820_get_maxpfn(void); + #endif /*__E820_HEADER*/ -- 2.26.2 From minios-devel-bounces@lists.xenproject.org Tue Dec 21 08:47:00 2021 Return-path: Envelope-to: archives@lists.xenproject.org Delivery-date: Tue, 21 Dec 2021 08:47:00 +0000 Received: from list by lists.xenproject.org with outflank-mailman.250186.430900 (Exim 4.92) (envelope-from ) id 1mzanU-00049i-GK; Tue, 21 Dec 2021 08:47:00 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 250186.430900; Tue, 21 Dec 2021 08:47:00 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mzanU-00049P-Ay; Tue, 21 Dec 2021 08:47:00 +0000 Received: by outflank-mailman (input) for mailman id 250186; Tue, 21 Dec 2021 08:46:58 +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 1mzanS-0002z5-5R for minios-devel@lists.xenproject.org; Tue, 21 Dec 2021 08:46:58 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 8c057068-623a-11ec-8d39-b1a4ed000e3e; Tue, 21 Dec 2021 09:46:54 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id CA6711F3B6; Tue, 21 Dec 2021 08:46:53 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id A0D1B13BEC; Tue, 21 Dec 2021 08:46:53 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id yHzgJX2UwWFHMAAAMHmgww (envelope-from ); Tue, 21 Dec 2021 08:46:53 +0000 X-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-devel" X-Inumbo-ID: 8c057068-623a-11ec-8d39-b1a4ed000e3e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1640076413; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VFqq/QNK2D+xIQFRd42TWwa5OQ2iSim/015QEF+tkx0=; b=py3Ua/EMWwloebQRKZoMF3+usUlu4h4yJhdL87S5KIZ9xfqVpY5OHrcvMBovHdVmZTSKZX 8FjMDQRmqcqIKHwIQBjhaR9CTHHp690IyDqjXizB/TZ2/He+pI+BviFQIGNwcomvAdztj8 H+S0Cq+6m8+7jSJK2xYFXoYjK1JXD1Y= From: Juergen Gross To: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org Cc: samuel.thibault@ens-lyon.org, wl@xen.org, Juergen Gross Subject: [PATCH v3 09/10] mini-os: prepare grantmap entry interface for use by PVH mode Date: Tue, 21 Dec 2021 09:46:35 +0100 Message-Id: <20211221084636.6987-10-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20211221084636.6987-1-jgross@suse.com> References: <20211221084636.6987-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 { }; static inline int -gntmap_entry_used(struct gntmap_entry *entry) +gntmap_entry_used(struct gntmap *map, int idx) { - return entry->host_addr != 0; + return map->entries[idx].host_addr != 0; } -static struct gntmap_entry* -gntmap_find_free_entry(struct gntmap *map) +static int gntmap_find_free_entry(struct gntmap *map) { int i; for (i = 0; i < map->nentries; i++) { - if (!gntmap_entry_used(&map->entries[i])) - return &map->entries[i]; + if (!gntmap_entry_used(map, i)) + return i; } DEBUG("(map=%p): all %d entries full", map, map->nentries); - return NULL; + return -1; } -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; for (i = 0; i < map->nentries; i++) { if (map->entries[i].host_addr == addr) - return &map->entries[i]; + return i; } - return NULL; + return -1; } int @@ -105,12 +103,13 @@ gntmap_set_max_grants(struct gntmap *map, int count) } static int -_gntmap_map_grant_ref(struct gntmap_entry *entry, +_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 = map->entries + idx; struct gnttab_map_grant_ref op; int rc; @@ -135,8 +134,9 @@ _gntmap_map_grant_ref(struct gntmap_entry *entry, } static int -_gntmap_unmap_grant_ref(struct gntmap_entry *entry) +_gntmap_unmap_grant_ref(struct gntmap *map, int idx) { + struct gntmap_entry *entry = map->entries + idx; struct gnttab_unmap_grant_ref op; int rc; @@ -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; DEBUG("(map=%p, start_address=%lx, count=%d)", map, start_address, count); for (i = 0; i < count; i++) { - ent = gntmap_find_entry(map, start_address + PAGE_SIZE * i); - if (ent == NULL) { + idx = gntmap_find_entry(map, start_address + PAGE_SIZE * i); + if (idx < 0) { printk("gntmap: tried to munmap unknown page\n"); return -EINVAL; } - rc = _gntmap_unmap_grant_ref(ent); + rc = _gntmap_unmap_grant_ref(map, idx); if (rc != 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; DEBUG("(map=%p, count=%" PRIu32 ", " @@ -206,9 +206,9 @@ gntmap_map_grant_refs(struct gntmap *map, return NULL; for (i = 0; i < count; i++) { - ent = gntmap_find_free_entry(map); - if (ent == NULL || - _gntmap_map_grant_ref(ent, + idx = 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; DEBUG("(map=%p)", map); for (i = 0; i < map->nentries; i++) { - ent = &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); } xfree(map->entries); -- 2.26.2 From minios-devel-bounces@lists.xenproject.org Tue Dec 21 08:47:02 2021 Return-path: Envelope-to: archives@lists.xenproject.org Delivery-date: Tue, 21 Dec 2021 08:47:02 +0000 Received: from list by lists.xenproject.org with outflank-mailman.250189.430920 (Exim 4.92) (envelope-from ) id 1mzanW-0004Tz-OI; Tue, 21 Dec 2021 08:47:02 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 250189.430920; Tue, 21 Dec 2021 08:47:02 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mzanV-0004Pm-TS; Tue, 21 Dec 2021 08:47:01 +0000 Received: by outflank-mailman (input) for mailman id 250189; Tue, 21 Dec 2021 08:46:59 +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 1mzanT-0002yE-8u for minios-devel@lists.xenproject.org; Tue, 21 Dec 2021 08:46:59 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 8b9b42a0-623a-11ec-9e60-abaf8a552007; Tue, 21 Dec 2021 09:46:53 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 0D6AD1F3B8; Tue, 21 Dec 2021 08:46:53 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id D923913E02; Tue, 21 Dec 2021 08:46:52 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id cDrRM3yUwWFHMAAAMHmgww (envelope-from ); Tue, 21 Dec 2021 08:46:52 +0000 X-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-devel" X-Inumbo-ID: 8b9b42a0-623a-11ec-9e60-abaf8a552007 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1640076413; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VPgUZQEXWMjuiDqJWRTGWtw72dHgK1/ZM2te4tasytk=; b=aSoZNdrwNngkftb9vRyT0Tgl6iYG9pMY7oN8BFJ/KQJicMhyy+wxXQePW1Ttf30oHdA1fR s1QDTXkGOVmk4FqGz/qMr1yU3LO3deBY2VRHKCLGhYE329bKD/TPFzOYDTOsom1gN9SQGK loar0Q4wvHrEuTPnbZk0gIvhBIAoNZA= From: Juergen Gross To: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org Cc: samuel.thibault@ens-lyon.org, wl@xen.org, Juergen Gross Subject: [PATCH v3 05/10] mini-os: don't repeat definition available via header file Date: Tue, 21 Dec 2021 09:46:31 +0100 Message-Id: <20211221084636.6987-6-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20211221084636.6987-1-jgross@suse.com> References: <20211221084636.6987-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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]; extern char shared_info[PAGE_SIZE]; -#if defined(__x86_64__) -#define __pte(x) ((pte_t) { (x) } ) -#else -#define __pte(x) ({ unsigned long long _x = (x); \ - ((pte_t) {(unsigned long)(_x), (unsigned long)(_x>>32)}); }) -#endif - static inline void fpu_init(void) { asm volatile("fninit"); } -- 2.26.2 From minios-devel-bounces@lists.xenproject.org Tue Dec 21 08:47:02 2021 Return-path: Envelope-to: archives@lists.xenproject.org Delivery-date: Tue, 21 Dec 2021 08:47:02 +0000 Received: from list by lists.xenproject.org with outflank-mailman.250190.430922 (Exim 4.92) (envelope-from ) id 1mzanW-0004VH-PR; Tue, 21 Dec 2021 08:47:02 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 250190.430922; Tue, 21 Dec 2021 08:47:02 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mzanW-0004Sf-2v; Tue, 21 Dec 2021 08:47:02 +0000 Received: by outflank-mailman (input) for mailman id 250190; Tue, 21 Dec 2021 08:47:00 +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 1mzanU-0002z5-5c for minios-devel@lists.xenproject.org; Tue, 21 Dec 2021 08:47:00 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 8c2aae34-623a-11ec-8d39-b1a4ed000e3e; Tue, 21 Dec 2021 09:46:54 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 1143521106; Tue, 21 Dec 2021 08:46:54 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id CFBDF13BEC; Tue, 21 Dec 2021 08:46:53 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id wAh0MX2UwWFHMAAAMHmgww (envelope-from ); Tue, 21 Dec 2021 08:46:53 +0000 X-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-devel" X-Inumbo-ID: 8c2aae34-623a-11ec-8d39-b1a4ed000e3e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1640076414; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2zdQgzlV0Lz7UQXRFdnEwu37UxJwIePFbmpJgrcmrrs=; b=km1hd/hcAwn5S/3yJHlr/WcnHQ4YQD+O7shAA5ihsxw4YOGkaPUqTnFZ+crwtIwm/pa0a+ wZwgjA2zKOf8MpBk9VB+H26114WblOoZrvPI2Bo7fc5+B0xU5hQHNpjYxzeSXnBlMqMlAh PVCkjUpQN5ip2Bc6vGMUabWVz7ESYXk= From: Juergen Gross To: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org Cc: samuel.thibault@ens-lyon.org, wl@xen.org, Juergen Gross Subject: [PATCH v3 10/10] mini-os: modify grant mappings to work in PVH mode Date: Tue, 21 Dec 2021 09:46:36 +0100 Message-Id: <20211221084636.6987-11-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20211221084636.6987-1-jgross@suse.com> References: <20211221084636.6987-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 @@ #include #include +#include #include #include #include @@ -97,11 +98,42 @@ gntmap_set_max_grants(struct gntmap *map, int count) if (map->entries == NULL) return -ENOMEM; +#ifndef CONFIG_PARAVIRT + map->start_pfn = e820_get_reserved_pfns(count); +#endif + memset(map->entries, 0, sizeof(struct gntmap_entry) * count); map->nentries = count; return 0; } +static int +_gntmap_unmap_grant_ref(struct gntmap *map, int idx) +{ + struct gntmap_entry *entry = map->entries + idx; + struct gnttab_unmap_grant_ref op; + int rc; + +#ifdef CONFIG_PARAVIRT + op.host_addr = (uint64_t) entry->host_addr; +#else + op.host_addr = (uint64_t)(map->start_pfn + idx) << PAGE_SHIFT; +#endif + op.dev_bus_addr = 0; + op.handle = entry->handle; + + rc = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1); + if (rc != 0 || op.status != GNTST_okay) { + printk("GNTTABOP_unmap_grant_ref failed: " + "returned %d, status %" PRId16 "\n", + rc, op.status); + return rc != 0 ? rc : op.status; + } + + entry->host_addr = 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 = map->entries + idx; struct gnttab_map_grant_ref op; int rc; +#ifndef CONFIG_PARAVIRT + unsigned long pfn = map->start_pfn + idx; +#endif op.ref = (grant_ref_t) ref; op.dom = (domid_t) domid; +#ifdef CONFIG_PARAVIRT op.host_addr = (uint64_t) host_addr; +#else + op.host_addr = (uint64_t)pfn << PAGE_SHIFT; +#endif op.flags = GNTMAP_host_map; if (!writable) op.flags |= GNTMAP_readonly; @@ -128,31 +167,18 @@ _gntmap_map_grant_ref(struct gntmap *map, int idx, return rc != 0 ? rc : op.status; } - entry->host_addr = host_addr; - entry->handle = op.handle; - return 0; -} - -static int -_gntmap_unmap_grant_ref(struct gntmap *map, int idx) -{ - struct gntmap_entry *entry = map->entries + idx; - struct gnttab_unmap_grant_ref op; - int rc; - - op.host_addr = (uint64_t) entry->host_addr; - op.dev_bus_addr = 0; - op.handle = entry->handle; - - rc = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1); - if (rc != 0 || op.status != GNTST_okay) { - printk("GNTTABOP_unmap_grant_ref failed: " - "returned %d, status %" PRId16 "\n", - rc, op.status); - return rc != 0 ? rc : op.status; +#ifndef CONFIG_PARAVIRT + rc = 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 - entry->host_addr = 0; + entry->host_addr = host_addr; + entry->handle = op.handle; return 0; } @@ -165,6 +191,10 @@ gntmap_munmap(struct gntmap *map, unsigned long start_address, int count) DEBUG("(map=%p, start_address=%lx, count=%d)", map, start_address, count); +#ifndef CONFIG_PARAVIRT + unmap_frames(start_address, count); +#endif + for (i = 0; i < count; i++) { idx = 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); } +#ifndef CONFIG_PARAVIRT + e820_put_reserved_pfns(map->start_pfn, map->nentries); + map->start_pfn = 0; +#endif + xfree(map->entries); map->entries = NULL; map->nentries = 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; }; int -- 2.26.2 From minios-devel-bounces@lists.xenproject.org Tue Dec 21 08:47:05 2021 Return-path: Envelope-to: archives@lists.xenproject.org Delivery-date: Tue, 21 Dec 2021 08:47:05 +0000 Received: from list by lists.xenproject.org with outflank-mailman.250194.430951 (Exim 4.92) (envelope-from ) id 1mzanZ-0005Fu-P7; Tue, 21 Dec 2021 08:47:05 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 250194.430951; Tue, 21 Dec 2021 08:47:05 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mzanZ-0005BP-7g; Tue, 21 Dec 2021 08:47:05 +0000 Received: by outflank-mailman (input) for mailman id 250194; Tue, 21 Dec 2021 08:47:02 +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 1mzanW-0002yE-9e for minios-devel@lists.xenproject.org; Tue, 21 Dec 2021 08:47:02 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 8b7a08f9-623a-11ec-9e60-abaf8a552007; Tue, 21 Dec 2021 09:46:53 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id D46A31F3A6; Tue, 21 Dec 2021 08:46:52 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id ABE9513BEC; Tue, 21 Dec 2021 08:46:52 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id SGmyKHyUwWFHMAAAMHmgww (envelope-from ); Tue, 21 Dec 2021 08:46:52 +0000 X-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-devel" X-Inumbo-ID: 8b7a08f9-623a-11ec-9e60-abaf8a552007 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1640076412; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Re/Y81QPVsmb4huxIK864YtWHyj0GbHOxxQ8cDq1GGE=; b=Mfrv1lJy+dqaaiGaP9d3hiugLOv7FGKQy3VpDcnzqICvE8JgzAtISoxngcE0mWGgL/Ds4T OnYA5ETKwVe//bIhMtXU6KJmmdvNlFNby+tVxCNiMMPfElPBj5XzlC0WbFbGEaODkDZjkR TxQ74K3Oq77dhzzrUKv+831L82dSIwg= From: Juergen Gross To: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org Cc: samuel.thibault@ens-lyon.org, wl@xen.org, Juergen Gross Subject: [PATCH v3 04/10] mini-os: respect memory map when ballooning up Date: Tue, 21 Dec 2021 09:46:30 +0100 Message-Id: <20211221084636.6987-5-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20211221084636.6987-1-jgross@suse.com> References: <20211221084636.6987-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Today Mini-OS won't look at the memory map when ballooning up. This can result in problems for PVH domains with more than 4 GB of RAM, as ballooning will happily run into the ACPI area. Fix that by adding only pages being marked as RAM in the memory map and by distinguishing between the current number of RAM pages and the first unallocated page. Signed-off-by: Juergen Gross Reviewed-by: Samuel Thibault --- V2: - rename and fix e820_get_max_pages() (Samuel Thibault) V3: - fix loop condition --- arch/arm/mm.c | 3 +++ arch/x86/balloon.c | 4 ++-- arch/x86/mm.c | 2 ++ balloon.c | 33 ++++++++++++++++++++++++--------- e820.c | 21 ++++++++++++++++++++- include/balloon.h | 5 +++-- include/e820.h | 1 + mm.c | 7 ++----- 8 files changed, 57 insertions(+), 19 deletions(-) diff --git a/arch/arm/mm.c b/arch/arm/mm.c index 9068166..11962f8 100644 --- a/arch/arm/mm.c +++ b/arch/arm/mm.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -70,6 +71,8 @@ void arch_init_mm(unsigned long *start_pfn_p, unsigned long *max_pfn_p) } device_tree = new_device_tree; *max_pfn_p = to_phys(new_device_tree) >> PAGE_SHIFT; + + balloon_set_nr_pages(*max_pfn_p, *max_pfn_p); } 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); - if ( p2m_pages(nr_max_pages) <= p2m_pages(max_pfn) ) + if ( p2m_pages(nr_max_pfn) <= p2m_pages(max_pfn) ) return; - new_p2m = alloc_virt_kernel(p2m_pages(nr_max_pages)); + new_p2m = alloc_virt_kernel(p2m_pages(nr_max_pfn)); for ( pfn = 0; pfn < max_pfn; pfn += 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 = (pgentry_t *)si->pt_base; first_free_pfn = PFN_UP(to_phys(pt_base)) + si->nr_pt_frames; last_free_pfn = 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) } last_free_pfn = e820_get_maxpfn(ret); + balloon_set_nr_pages(ret, last_free_pfn); } #endif diff --git a/balloon.c b/balloon.c index 5676d3b..9dc77c5 100644 --- a/balloon.c +++ b/balloon.c @@ -23,14 +23,24 @@ #include #include +#include #include #include #include #include #include -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 = pages; + nr_mem_pfn = pfn; +} void get_max_pages(void) { @@ -46,16 +56,18 @@ void get_max_pages(void) nr_max_pages = ret; printk("Maximum memory size: %ld pages\n", nr_max_pages); + + nr_max_pfn = e820_get_maxpfn(nr_max_pages); } void mm_alloc_bitmap_remap(void) { unsigned long i, new_bitmap; - if ( mm_alloc_bitmap_size >= ((nr_max_pages + 1) >> 3) ) + if ( mm_alloc_bitmap_size >= ((nr_max_pfn + 1) >> 3) ) return; - new_bitmap = alloc_virt_kernel(PFN_UP((nr_max_pages + 1) >> 3)); + new_bitmap = alloc_virt_kernel(PFN_UP((nr_max_pfn + 1) >> 3)); for ( i = 0; i < mm_alloc_bitmap_size; i += PAGE_SIZE ) { map_frame_rw(new_bitmap + i, @@ -70,7 +82,7 @@ static unsigned long balloon_frames[N_BALLOON_FRAMES]; int balloon_up(unsigned long n_pages) { - unsigned long page, pfn; + unsigned long page, pfn, start_pfn; int rc; struct xen_memory_reservation reservation = { .domid = DOMID_SELF @@ -81,8 +93,11 @@ int balloon_up(unsigned long n_pages) if ( n_pages > N_BALLOON_FRAMES ) n_pages = N_BALLOON_FRAMES; + start_pfn = e820_get_maxpfn(nr_mem_pages + 1) - 1; + n_pages = 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 = alloc_page(); if ( !page ) @@ -99,14 +114,14 @@ int balloon_up(unsigned long n_pages) mm_alloc_bitmap_size += PAGE_SIZE; } - rc = arch_expand_p2m(nr_mem_pages + n_pages); + rc = arch_expand_p2m(start_pfn + n_pages); if ( rc ) return rc; /* Get new memory from hypervisor. */ for ( pfn = 0; pfn < n_pages; pfn++ ) { - balloon_frames[pfn] = nr_mem_pages + pfn; + balloon_frames[pfn] = start_pfn + pfn; } set_xen_guest_handle(reservation.extent_start, balloon_frames); reservation.nr_extents = n_pages; @@ -116,7 +131,7 @@ int balloon_up(unsigned long n_pages) for ( pfn = 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)); } diff --git a/e820.c b/e820.c index 8030f43..2a371c7 100644 --- a/e820.c +++ b/e820.c @@ -290,7 +290,8 @@ unsigned long e820_get_maxpfn(unsigned long pages) int i; unsigned long pfns, start = 0; - e820_get_memmap(); + if ( !e820_entries ) + e820_get_memmap(); for ( i = 0; i < e820_entries; i++ ) { @@ -305,3 +306,21 @@ unsigned long e820_get_maxpfn(unsigned long pages) return start + pfns; } + +unsigned long e820_get_max_contig_pages(unsigned long pfn, unsigned long pages) +{ + int i; + unsigned long end; + + for ( i = 0; i < e820_entries && e820_map[i].addr <= (pfn << PAGE_SHIFT); + i++ ) + { + end = (e820_map[i].addr + e820_map[i].size) >> PAGE_SHIFT; + if ( e820_map[i].type != E820_RAM || end <= 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 -extern unsigned long nr_max_pages; -extern unsigned long nr_mem_pages; +extern unsigned long nr_max_pfn; void get_max_pages(void); int balloon_up(unsigned long n_pages); +void balloon_set_nr_pages(unsigned long pages, unsigned long pfn); 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 <= nr_free_pages; } +static inline balloon_set_nr_pages(unsigned long pages, unsigned long pfn) { } #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; unsigned long e820_get_maxpfn(unsigned long pages); +unsigned long e820_get_max_contig_pages(unsigned long pfn, unsigned long pages); #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) printk("MM: Init\n"); - 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); arch_init_demand_mapping_area(); - -#ifdef CONFIG_BALLOON - nr_mem_pages = max_pfn; -#endif } void fini_mm(void) -- 2.26.2 From minios-devel-bounces@lists.xenproject.org Tue Dec 21 08:49:39 2021 Return-path: Envelope-to: archives@lists.xenproject.org Delivery-date: Tue, 21 Dec 2021 08:49:39 +0000 Received: from list by lists.xenproject.org with outflank-mailman.250217.430997 (Exim 4.92) (envelope-from ) id 1mzaq3-0001ft-Bh; Tue, 21 Dec 2021 08:49:39 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 250217.430997; Tue, 21 Dec 2021 08:49:39 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mzaq3-0001fm-8s; Tue, 21 Dec 2021 08:49:39 +0000 Received: by outflank-mailman (input) for mailman id 250217; Tue, 21 Dec 2021 08:49:38 +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 1mzanZ-0002yE-9v for minios-devel@lists.xenproject.org; Tue, 21 Dec 2021 08:47:05 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 8bd0e23b-623a-11ec-9e60-abaf8a552007; Tue, 21 Dec 2021 09:46:53 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 6CF1B1F388; Tue, 21 Dec 2021 08:46:53 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 445B213BEC; Tue, 21 Dec 2021 08:46:53 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id gNqGD32UwWFHMAAAMHmgww (envelope-from ); Tue, 21 Dec 2021 08:46:53 +0000 X-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-devel" X-Inumbo-ID: 8bd0e23b-623a-11ec-9e60-abaf8a552007 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1640076413; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ce+N1zGKQYy8hCldpOth9Bm5wXCCEJvD9D9LhUj9MqQ=; b=C+NEGzRxpqZaAzIh3PRUMHaMYnMxQpFq5PgkbgGz1JstYjKyZrQj4ErAFXufxUew0l2fdm ItAws4Rg/eKrhfVHyZXx82dOQmMMNiHGXTaF+/8MPYDcegUwKFioeYBGADKQQ+CuwcwAdW IJ3q93eJKQVd0BcZ1nNdG1HQFJVUvFE= From: Juergen Gross To: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org Cc: samuel.thibault@ens-lyon.org, wl@xen.org, Juergen Gross Subject: [PATCH v3 07/10] mini-os: move x86 specific gnttab coding into arch/x86/gnttab.c Date: Tue, 21 Dec 2021 09:46:33 +0100 Message-Id: <20211221084636.6987-8-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20211221084636.6987-1-jgross@suse.com> References: <20211221084636.6987-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include +#include +#include +#include +#include + +grant_entry_v1_t *arch_init_gnttab(int nr_grant_frames) +{ + struct gnttab_setup_table setup; + unsigned long frames[nr_grant_frames]; + + setup.dom = DOMID_SELF; + setup.nr_frames = 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_frames) +{ +#ifdef CONFIG_PARAVIRT + int i; + + for ( i = 0; i < nr_grant_frames; i++ ) + { + HYPERVISOR_update_va_mapping((unsigned long)gnttab_table + PAGE_SIZE * i, + __pte(0x0 << PAGE_SHIFT), UVMF_INVLPG); + } +#endif + return; +} + +void arch_resume_gnttab(grant_entry_v1_t *gnttab_table, int nr_grant_frames) +{ + struct gnttab_setup_table setup; + unsigned long frames[nr_grant_frames]; +#ifdef CONFIG_PARAVIRT + int i; +#endif + + setup.dom = DOMID_SELF; + setup.nr_frames = 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 = 0; i < nr_grant_frames; i++ ) + { + HYPERVISOR_update_va_mapping((unsigned long)gnttab_table + PAGE_SIZE * 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 } -grant_entry_v1_t *arch_init_gnttab(int nr_grant_frames) -{ - struct gnttab_setup_table setup; - unsigned long frames[nr_grant_frames]; - - setup.dom = DOMID_SELF; - setup.nr_frames = 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_frames) -{ -#ifdef CONFIG_PARAVIRT - int i; - - for (i = 0; i < nr_grant_frames; i++) { - HYPERVISOR_update_va_mapping((unsigned long)(((char *)gnttab_table) + PAGE_SIZE * i), - (pte_t){0x0< Envelope-to: archives@lists.xenproject.org Delivery-date: Tue, 21 Dec 2021 08:50:18 +0000 Received: from list by lists.xenproject.org with outflank-mailman.250227.431001 (Exim 4.92) (envelope-from ) id 1mzaqg-0002g3-El; Tue, 21 Dec 2021 08:50:18 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 250227.431001; Tue, 21 Dec 2021 08:50:18 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mzaqg-0002fw-Bs; Tue, 21 Dec 2021 08:50:18 +0000 Received: by outflank-mailman (input) for mailman id 250227; Tue, 21 Dec 2021 08:50:17 +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 1mzanX-0002yE-9h for minios-devel@lists.xenproject.org; Tue, 21 Dec 2021 08:47:03 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 8bb37657-623a-11ec-9e60-abaf8a552007; Tue, 21 Dec 2021 09:46:53 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 3E1612112A; Tue, 21 Dec 2021 08:46:53 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 131F013BEC; Tue, 21 Dec 2021 08:46:53 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id +IiFA32UwWFHMAAAMHmgww (envelope-from ); Tue, 21 Dec 2021 08:46:53 +0000 X-BeenThere: minios-devel@lists.xenproject.org List-Id: Mini-os development list List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: minios-devel-bounces@lists.xenproject.org Precedence: list Sender: "Minios-devel" X-Inumbo-ID: 8bb37657-623a-11ec-9e60-abaf8a552007 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1640076413; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gkrJ2Rw3Dbpj849TiQ+tx0qwA3eebDMmjLB6sPY/E/c=; b=JtzdSdItfXsN2W9sNhfn78CilA/vDshhfL6A7w5J/GMrEmXsafdjaf32zzblrYqBd28cQR gD4N1ykB7jzpvw3lkVevqfNkhWTxWO95SEdJZWWv/numj2RrD4ZbOYzVEl3hRAlh9uYZEe LcKfXWk/STHgeAYpXdwJ9w6eYhhsHPI= From: Juergen Gross To: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org Cc: samuel.thibault@ens-lyon.org, wl@xen.org, Juergen Gross Subject: [PATCH v3 06/10] mini-os: add memory map service functions Date: Tue, 21 Dec 2021 09:46:32 +0100 Message-Id: <20211221084636.6987-7-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20211221084636.6987-1-jgross@suse.com> References: <20211221084636.6987-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Add two functions for adding reserved areas to the memory map and for removing them again. Those will be needed for proper grant table/mapping support in PVH mode. Signed-off-by: Juergen Gross Reviewed-by: Samuel Thibault --- V2: - fix e820_put_reserved_pfns() (Samuel Thibault) --- e820.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/e820.h | 4 ++++ 2 files changed, 54 insertions(+) diff --git a/e820.c b/e820.c index 2a371c7..df29097 100644 --- a/e820.c +++ b/e820.c @@ -283,6 +283,56 @@ void arch_print_memmap(void) printk("%012lx-%012lx: %s\n", from, to, type); } } + +unsigned long e820_get_reserved_pfns(int pages) +{ + int i; + unsigned long last = 0, needed = (long)pages << PAGE_SHIFT; + + for ( i = 0; i < e820_entries && e820_map[i].addr < last + needed; i++ ) + last = e820_map[i].addr + e820_map[i].size; + + if ( i == 0 || e820_map[i - 1].type != E820_RESERVED ) + e820_insert_entry_at(i, last, needed, E820_RESERVED); + else + e820_map[i - 1].size += needed; + + return last >> PAGE_SHIFT; +} + +void e820_put_reserved_pfns(unsigned long start_pfn, int pages) +{ + int i; + unsigned long addr = start_pfn << PAGE_SHIFT; + unsigned long size = (long)pages << PAGE_SHIFT; + + for ( i = 0; + i < e820_entries && addr >= e820_map[i].addr + e820_map[i].size; + i++ ); + + BUG_ON(i == e820_entries || e820_map[i].type != E820_RESERVED || + addr + size > e820_map[i].addr + e820_map[i].size); + + if ( addr == e820_map[i].addr ) + { + e820_map[i].addr += size; + e820_map[i].size -= size; + if ( e820_map[i].size == 0 ) + e820_remove_entry(i); + return; + } + + if ( addr + size == e820_map[i].addr + e820_map[i].size ) + { + e820_map[i].size -= 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 = addr - e820_map[i].addr; +} #endif 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; unsigned long e820_get_maxpfn(unsigned long pages); unsigned long e820_get_max_contig_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 #endif /*__E820_HEADER*/ -- 2.26.2