From nobody Thu Oct 30 23:19:48 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1751956681; cv=none; d=zohomail.com; s=zohoarc; b=HjAzybtOUMme6JbjH+npTdo+QeQNY49MYkmdGUfZrouiZ1hzfV2hIwR2NxmQL3Y0TQjQCODNsfCHOYMmbZSjtY0ZUPOuuJcnqauUcNxXq9xPysNUkkK3Wv8c5TljahUd5aRiLtCX59KP1NnqCHabUaHxd4tvkkh26g/jNJwdDaw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1751956681; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=XaZCtOmxWZ4bchm6r7N9WhOaU6PIDyHDuampVATjIrE=; b=aTN2+QSUSTvsmRnma0AzvADCmIKrcRofbjLr+DFes9hrA9fId11c7XhvrycKApftAnkeFIFgkCbCAt8vfbXX/lXjRasExa1CI0qvmUQCYpLz4rci4OEk4eSn6nsB+t3C8kTOGmpJKP9iim8aLQRUXiAcEkn9AoNS4qaoXnIpkJA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 175195668127346.91383772004576; Mon, 7 Jul 2025 23:38:01 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1035971.1408428 (Exim 4.92) (envelope-from ) id 1uZ1xc-00037o-GN; Tue, 08 Jul 2025 06:37:48 +0000 Received: by outflank-mailman (output) from mailman id 1035971.1408428; Tue, 08 Jul 2025 06:37:48 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uZ1xc-00037h-Dm; Tue, 08 Jul 2025 06:37:48 +0000 Received: by outflank-mailman (input) for mailman id 1035971; Tue, 08 Jul 2025 06:37:47 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uZ1xb-0002pb-S0 for xen-devel@lists.xenproject.org; Tue, 08 Jul 2025 06:37:47 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [2a07:de40:b251:101:10:150:64:2]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 0f335bb9-5bc6-11f0-a316-13f23c93f187; Tue, 08 Jul 2025 08:37:46 +0200 (CEST) Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id E83BF1F393; Tue, 8 Jul 2025 06:37:45 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id BE0FC13A68; Tue, 8 Jul 2025 06:37:45 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id h6/+LLm8bGhGNAAAD6G6ig (envelope-from ); Tue, 08 Jul 2025 06:37:45 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 0f335bb9-5bc6-11f0-a316-13f23c93f187 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1751956665; 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=XaZCtOmxWZ4bchm6r7N9WhOaU6PIDyHDuampVATjIrE=; b=oFFrplB2fUkdVy4vsi4s+FPh2TnplrEOFA2H7Xm22aXDq3IXING/fmexWuQnJw0ujRfqbe x/I9nHofkS6McLMoey0hueleuGXaLrZaGDZxO46N38tAE/FgJmJZm+9yZdqeoikQ7PLcE4 5ENvIvR5bi80Rp+rOUXUkiwTVV+25eg= Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1751956665; 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=XaZCtOmxWZ4bchm6r7N9WhOaU6PIDyHDuampVATjIrE=; b=oFFrplB2fUkdVy4vsi4s+FPh2TnplrEOFA2H7Xm22aXDq3IXING/fmexWuQnJw0ujRfqbe x/I9nHofkS6McLMoey0hueleuGXaLrZaGDZxO46N38tAE/FgJmJZm+9yZdqeoikQ7PLcE4 5ENvIvR5bi80Rp+rOUXUkiwTVV+25eg= From: Juergen Gross To: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org Cc: samuel.thibault@ens-lyon.org, Juergen Gross Subject: [MINI-OS PATCH 1/2] mm: provide a way to do very early page table allocations Date: Tue, 8 Jul 2025 08:37:37 +0200 Message-ID: <20250708063738.18994-2-jgross@suse.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250708063738.18994-1-jgross@suse.com> References: <20250708063738.18994-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Level: X-Spamd-Result: default: False [-6.80 / 50.00]; REPLY(-4.00)[]; BAYES_HAM(-3.00)[99.99%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-0.999]; MIME_GOOD(-0.10)[text/plain]; RCVD_COUNT_TWO(0.00)[2]; FROM_HAS_DN(0.00)[]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; FUZZY_RATELIMITED(0.00)[rspamd.com]; RCPT_COUNT_THREE(0.00)[4]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,suse.com:email,suse.com:mid]; RCVD_TLS_ALL(0.00)[] X-Spam-Flag: NO X-Spam-Score: -6.80 X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1751956682742116600 Content-Type: text/plain; charset="utf-8" Add a small pool of statically allocated memory pages to be handed out for very early page table allocations. This will make it possible to do virtual allocations e.g. for mapping the shared info page. Signed-off-by: Juergen Gross --- arch/x86/mm.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/arch/x86/mm.c b/arch/x86/mm.c index bdff38fd..3f5c7ea7 100644 --- a/arch/x86/mm.c +++ b/arch/x86/mm.c @@ -640,12 +640,17 @@ void change_readonly(bool readonly) * return a valid PTE for a given virtual address. If PTE does not exist, * allocate page-table pages. */ +#define N_PTS 4 +static char early_pt[PAGE_SIZE * N_PTS] __attribute__((aligned(PAGE_SIZE))= ); +static unsigned long n_early_pt =3D N_PTS; + static int need_pgt_func(unsigned long va, unsigned int lvl, bool is_leaf, pgentry_t *pte, void *par) { pgentry_t **result =3D par; unsigned long pt_mfn; unsigned long pt_pfn; + unsigned long pt_addr; unsigned int idx; =20 if ( !is_leaf ) @@ -664,7 +669,16 @@ static int need_pgt_func(unsigned long va, unsigned in= t lvl, bool is_leaf, } =20 pt_mfn =3D virt_to_mfn(pte); - pt_pfn =3D virt_to_pfn(alloc_page()); + if ( n_early_pt ) + { + n_early_pt--; + pt_addr =3D (unsigned long)&early_pt[n_early_pt * PAGE_SIZE]; + } + else + { + pt_addr =3D alloc_page(); + } + pt_pfn =3D virt_to_pfn(pt_addr); if ( !pt_pfn ) return -1; idx =3D idx_from_va_lvl(va, lvl); --=20 2.43.0 From nobody Thu Oct 30 23:19:48 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=quarantine dis=quarantine) header.from=suse.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1751956690886164.44340025073575; Mon, 7 Jul 2025 23:38:10 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1035973.1408444 (Exim 4.92) (envelope-from ) id 1uZ1xn-0003YK-SD; Tue, 08 Jul 2025 06:37:59 +0000 Received: by outflank-mailman (output) from mailman id 1035973.1408444; Tue, 08 Jul 2025 06:37: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 1uZ1xn-0003YB-Ne; Tue, 08 Jul 2025 06:37:59 +0000 Received: by outflank-mailman (input) for mailman id 1035973; Tue, 08 Jul 2025 06:37: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 1uZ1xm-0003U3-0w for xen-devel@lists.xenproject.org; Tue, 08 Jul 2025 06:37:58 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 1236dfdc-5bc6-11f0-b894-0df219b8e170; Tue, 08 Jul 2025 08:37:51 +0200 (CEST) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 7B81021167; Tue, 8 Jul 2025 06:37:51 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 52BED13A68; Tue, 8 Jul 2025 06:37:51 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id /ITUEr+8bGhPNAAAD6G6ig (envelope-from ); Tue, 08 Jul 2025 06:37:51 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 1236dfdc-5bc6-11f0-b894-0df219b8e170 Authentication-Results: smtp-out1.suse.de; none From: Juergen Gross To: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org Cc: samuel.thibault@ens-lyon.org, Juergen Gross Subject: [MINI-OS PATCH 2/2] x86: don't use a memory page for mapping the shared info page Date: Tue, 8 Jul 2025 08:37:38 +0200 Message-ID: <20250708063738.18994-3-jgross@suse.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250708063738.18994-1-jgross@suse.com> References: <20250708063738.18994-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Action: no action X-Spam-Flag: NO X-Spam-Level: X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Rspamd-Queue-Id: 7B81021167 X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spam-Score: -4.00 X-ZM-MESSAGEID: 1751956694553116600 Content-Type: text/plain; charset="utf-8" There is no need to use a populated memory page for mapping the shared info page at that location. Just use an allocated virtual address for the shared info page. For PVH allocate an unused pfn. Signed-off-by: Juergen Gross --- arch/x86/mm.c | 7 ------- arch/x86/setup.c | 15 ++++++++------- arch/x86/x86_32.S | 7 +------ arch/x86/x86_64.S | 7 +------ hypervisor.c | 15 +++++++++++---- 5 files changed, 21 insertions(+), 30 deletions(-) diff --git a/arch/x86/mm.c b/arch/x86/mm.c index 3f5c7ea7..78d614a6 100644 --- a/arch/x86/mm.c +++ b/arch/x86/mm.c @@ -497,7 +497,6 @@ static void build_pagetable(unsigned long *start_pfn, u= nsigned long *max_pfn) /* * Mark portion of the address space read only. */ -extern struct shared_info shared_info; =20 struct change_readonly_par { unsigned long etext; @@ -519,12 +518,6 @@ static int change_readonly_func(unsigned long va, unsi= gned int lvl, if ( va + (1UL << ptdata[lvl].shift) > ro->etext ) return 1; =20 - if ( va =3D=3D (unsigned long)&shared_info ) - { - printk("skipped %lx\n", va); - return 0; - } - newval =3D ro->readonly ? (*pte & ~_PAGE_RW) : (*pte | _PAGE_RW); =20 #ifdef CONFIG_PARAVIRT diff --git a/arch/x86/setup.c b/arch/x86/setup.c index 299ff8c7..8fd55c51 100644 --- a/arch/x86/setup.c +++ b/arch/x86/setup.c @@ -47,8 +47,6 @@ shared_info_t *HYPERVISOR_shared_info; */ char stack[2*STACK_SIZE]; =20 -extern char shared_info[PAGE_SIZE]; - static inline void fpu_init(void) { asm volatile("fninit"); } @@ -76,18 +74,21 @@ static void set_info_ptr(start_info_t *ptr) =20 #define hpc_init() =20 +static unsigned long shared_info_va; + shared_info_t *map_shared_info(void) { int rc; - unsigned long pa =3D start_info_ptr->shared_info; =20 - if ( (rc =3D HYPERVISOR_update_va_mapping((unsigned long)shared_info, - __pte(pa | 7), UVMF_INVLPG)) ) + if ( !shared_info_va ) + shared_info_va =3D alloc_virt_kernel(1); + rc =3D map_frame_rw(shared_info_va, PHYS_PFN(start_info_ptr->shared_in= fo)); + if ( rc ) { printk("Failed to map shared_info!! rc=3D%d\n", rc); do_exit(); } - return (shared_info_t *)shared_info; + return (shared_info_t *)shared_info_va; } =20 void unmap_shared_info(void) @@ -95,7 +96,7 @@ void unmap_shared_info(void) int rc; pte_t nullpte =3D { }; =20 - if ( (rc =3D HYPERVISOR_update_va_mapping((unsigned long)shared_info, + if ( (rc =3D HYPERVISOR_update_va_mapping(shared_info_va, nullpte, UVMF_INVLPG)) ) { printk("Failed to unmap shared_info page!! rc=3D%d\n", rc); diff --git a/arch/x86/x86_32.S b/arch/x86/x86_32.S index 3de00277..5d891164 100644 --- a/arch/x86/x86_32.S +++ b/arch/x86/x86_32.S @@ -36,13 +36,8 @@ _start: stack_start: .long stack+(2*__STACK_SIZE), __KERNEL_SS =20 -.globl shared_info, hypercall_page - /* Unpleasant -- the PTE that maps this page is actually overwritt= en */ - /* to map the real shared-info page! :-) = */ .align __PAGE_SIZE -shared_info: - .fill __PAGE_SIZE,1,0 - +.globl hypercall_page hypercall_page: .fill __PAGE_SIZE,1,0 =20 diff --git a/arch/x86/x86_64.S b/arch/x86/x86_64.S index 7529c02e..09b93e39 100644 --- a/arch/x86/x86_64.S +++ b/arch/x86/x86_64.S @@ -33,13 +33,8 @@ _start: stack_start: .quad stack+(2*__STACK_SIZE) =20 -.globl shared_info, hypercall_page - /* Unpleasant -- the PTE that maps this page is actually overwritt= en */ - /* to map the real shared-info page! :-) = */ .align __PAGE_SIZE -shared_info: - .fill __PAGE_SIZE,1,0 - +.globl hypercall_page hypercall_page: .fill __PAGE_SIZE,1,0 =20 diff --git a/hypervisor.c b/hypervisor.c index 6476d658..519a4680 100644 --- a/hypervisor.c +++ b/hypervisor.c @@ -27,8 +27,10 @@ =20 #include #include +#include #include #include +#include #include =20 EXPORT_SYMBOL(hypercall_page); @@ -37,7 +39,8 @@ EXPORT_SYMBOL(hypercall_page); ((sh)->evtchn_pending[idx] & ~(sh)->evtchn_mask[idx]) =20 #ifndef CONFIG_PARAVIRT -extern shared_info_t shared_info; +static unsigned long shinfo_pfn; +static unsigned long shinfo_va; =20 int hvm_get_parameter(int idx, uint64_t *value) { @@ -69,14 +72,16 @@ shared_info_t *map_shared_info(void) { struct xen_add_to_physmap xatp; =20 + shinfo_pfn =3D e820_get_reserved_pfns(1); xatp.domid =3D DOMID_SELF; xatp.idx =3D 0; xatp.space =3D XENMAPSPACE_shared_info; - xatp.gpfn =3D virt_to_pfn(&shared_info); + xatp.gpfn =3D shinfo_pfn; if ( HYPERVISOR_memory_op(XENMEM_add_to_physmap, &xatp) !=3D 0 ) BUG(); + shinfo_va =3D map_frame_virt(shinfo_pfn); =20 - return &shared_info; + return (shared_info_t *)shinfo_va; } =20 void unmap_shared_info(void) @@ -84,9 +89,11 @@ void unmap_shared_info(void) struct xen_remove_from_physmap xrtp; =20 xrtp.domid =3D DOMID_SELF; - xrtp.gpfn =3D virt_to_pfn(&shared_info); + xrtp.gpfn =3D shinfo_pfn; if ( HYPERVISOR_memory_op(XENMEM_remove_from_physmap, &xrtp) !=3D 0 ) BUG(); + unmap_frames(shinfo_va, 1); + e820_put_reserved_pfns(shinfo_pfn, 1); } #endif =20 --=20 2.43.0