From nobody Thu Nov 21 16:12:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1730467050; cv=none; d=zohomail.com; s=zohoarc; b=hzAjE10D6A5I9g1nficidAh3bluNYeEj5unk6Y8sDhqHs2oekHaJjN+xrchr/T+cGuCslcUy0qGioYXeD7DWlUskCW4WXc/2RNRVVZb+1F6C8FU4e5gcAGBt9/sbcJkNx8KlO7XGNF4aL6//HMuhjkpEhpWhdpa0HqolAsvM4fI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730467050; 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=kwCWlUmP+fvklPMi2ZGyZefz6lAo2zH73CUd2mOyJ44=; b=lMCxyFoU6bqQmrcZQrYgpxu2OPrN/Pxi3wor4rCZYre4+GqH5RpelWP0n9gDQm5U4ElpFfmLMukqOnJ/nvTaoH6bPPGtpmkKFIhuBSCxPTsIR155ijgD66Hzq8jOiIrNV54YpyPAU/Y6J9U2XIvNkZyhGStq7mu9Zk1lJwx6r2E= 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=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1730467050876313.42230663888336; Fri, 1 Nov 2024 06:17:30 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.829110.1244183 (Exim 4.92) (envelope-from ) id 1t6rWJ-0000WS-LC; Fri, 01 Nov 2024 13:16:55 +0000 Received: by outflank-mailman (output) from mailman id 829110.1244183; Fri, 01 Nov 2024 13:16:55 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t6rWJ-0000WL-I6; Fri, 01 Nov 2024 13:16:55 +0000 Received: by outflank-mailman (input) for mailman id 829110; Fri, 01 Nov 2024 13:16: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 1t6rWI-0000Hs-5g for xen-devel@lists.xenproject.org; Fri, 01 Nov 2024 13:16:54 +0000 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [2a00:1450:4864:20::135]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 8e78aacc-9853-11ef-a0c5-8be0dac302b0; Fri, 01 Nov 2024 14:16:51 +0100 (CET) Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-539f84907caso2150218e87.3 for ; Fri, 01 Nov 2024 06:16:51 -0700 (PDT) Received: from fedora.. ([94.75.70.14]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53c7bdcbcf6sm549745e87.194.2024.11.01.06.16.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Nov 2024 06:16:46 -0700 (PDT) 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: 8e78aacc-9853-11ef-a0c5-8be0dac302b0 X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjoxMzUiLCJoZWxvIjoibWFpbC1sZjEteDEzNS5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6IjhlNzhhYWNjLTk4NTMtMTFlZi1hMGM1LThiZTBkYWMzMDJiMCIsInRzIjoxNzMwNDY3MDExLjI1ODUzNywic2VuZGVyIjoib2xla3NpaS5rdXJvY2hrb0BnbWFpbC5jb20iLCJyZWNpcGllbnQiOiJ4ZW4tZGV2ZWxAbGlzdHMueGVucHJvamVjdC5vcmcifQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730467007; x=1731071807; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kwCWlUmP+fvklPMi2ZGyZefz6lAo2zH73CUd2mOyJ44=; b=AaAWq+v4mK4jGQNhntAHVrAKdJ2oqyv0rY+mys4fAYis0Mf645uUTSdBcM+uU8RCxW Fwg5oWS1tVo9JUCUUbS3W7bW6tLsSxW2Rjtjtwk2YIf1ZLIfNuPOp0iKXvCHvNHaMtbX 46YbZO4dZsr9R00JTkXzQHKxdoFELyEO6ADT3qOKnyG8Xgv+Q5fUa43vjHtoMinW6xcu W/is0BwFUGAbJ1cJSbqElBw4OFND5PGf94WLht8LkUGrVUCKnKo7tl2evzNF9p8mVtjw 5i7QOc8+a9d/6EteE8utPHiGHorPL9wOOeI7AZFjRggwrbi4SRdH3Vfs+ODETQx6UmSd UTJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730467007; x=1731071807; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kwCWlUmP+fvklPMi2ZGyZefz6lAo2zH73CUd2mOyJ44=; b=PHxqyE76xmalYxrU/sPntT/gygyBVzcFa/mgkNLpcwIdiZC3VXv/ymtWfeO8WkDGUR C7hWD8hoPNCdrkBD8C4eLYpKV9I4nThjqZvSYeTMtkozWl4fQRU0jUE43V1OZqvkLy/Q +vH/fURnT9A93IZZOstjqB6v8ogVwpkbGppHaRBvlbyqH4WhZLnVfwlaatQlOlW/Xev3 vI3QCQNWxLwofgD/oFnAs45txCCYrkViQ+WQVHRyH2CD2emME82YZ5EB4XPD5aKn2XgW SxJUsCKLgMhPh+HMKk4Az2PoBnGI9sdcCrx0e6eEvjfQEu/wZwm31tBNUPd0DKqa4Fta RAPA== X-Gm-Message-State: AOJu0YzHs3gwiGl5ZAoJDVpXf53eKDn0/b+1IIzHqKioxjPbsxPEpldi T/OChX0apcyIRhsi2VlYRjIhe7zUUWkufnGM4rRTaQii7+jqtS/wK5p3IA== X-Google-Smtp-Source: AGHT+IHWXVkoZyh7cvRuQrZFRaZv0JzQGmEWN64XuSSS1UhuoII2B+cGLmcEqop3h20WA7SJHNoCrA== X-Received: by 2002:a05:6512:104d:b0:539:d10b:e389 with SMTP id 2adb3069b0e04-53b348f9681mr12117599e87.13.1730467006577; Fri, 01 Nov 2024 06:16:46 -0700 (PDT) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Oleksii Kurochko , Alistair Francis , Bob Eshleman , Connor Davis , Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini Subject: [PATCH v3 1/3] xen/riscv: introduce setup_mm() Date: Fri, 1 Nov 2024 14:16:40 +0100 Message-ID: <0f7cd809e848607408ff4615e55b847f5a524559.1730465154.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1730467052091116600 Content-Type: text/plain; charset="utf-8" Introduce the implementation of setup_mm(), which includes: 1. Adding all free regions to the boot allocator, as memory is needed to allocate page tables used for frame table mapping. 2. Calculating RAM size and the RAM end address. 3. Setting up direct map mappings from each RAM bank and initialize directmap_virt_start to keep simple VA <-> PA translation and map DIRECTMAP_VIRT_START with some offset ( if RAM start isn't properly aligned ) to RAM start to be properly aligned with RAM start to use more superpages to reduce pressure on the TLB 4. Setting up frame table mappings from physical address 0 to ram_end to simplify mfn_to_page() and page_to_mfn() conversions. 5. Setting up total_pages and max_page. Update virt_to_maddr() to use introduced directmap_virt_start. Implement maddr_to_virt() function to convert a machine address to a virtual address. This function is specifically designed to be used only for the DIRECTMAP region, so a check has been added to ensure that the address does not exceed DIRECTMAP_SIZE. After the introduction of maddr_to_virt() the following linkage error starts to occur and to avoid it share_xen_page_with_guest() stub is added: riscv64-linux-gnu-ld: prelink.o: in function `tasklet_kill': /build/xen/common/tasklet.c:176: undefined reference to `share_xen_page_with_guest' riscv64-linux-gnu-ld: ./.xen-syms.0: hidden symbol `share_xen_page_with_g= uest' isn't defined riscv64-linux-gnu-ld: final link failed: bad value Despite the linkger fingering tasklet.c, it's trace.o which has the undefin= ed refenrece: $ find . -name \*.o | while read F; do nm $F | grep share_xen_page_with_g= uest && echo $F; done U share_xen_page_with_guest ./xen/common/built_in.o U share_xen_page_with_guest ./xen/common/trace.o U share_xen_page_with_guest ./xen/prelink.o Looking at trace.i, there is call of share_xen_page_with_guest() but in cas= e of when maddr_to_virt() is defined as stub ("BUG_ON(); return NULL;") DCE happ= ens and the code is just eliminated. Signed-off-by: Oleksii Kurochko --- Changes in V3: - Update the comment the part where DCE should be mentioned and directmap= -related things are touched. - Move ROUNDDOWN to . - s/sizeof(struct page_info)/sizeof(*frame_table) in setup_frametable_map= ping(). - Updates in setup_frametable_mapping(): - align phys_start (ps) up to a page boundary and align phys_end (pe) d= own to a page boundary. - Update panic message. - Add the comment about alignment of frametable_size and base_mfn. - invalidate all frame_table entries and then just init with 0 only val= id ones. - Double blank lines removing. - Initialize directmap_virt_start with DIRECTMAP_VIRT_START. - Updates in setup_directmap_mapping(): - Drop local variable rc as it is used only once. - Move directmap_mfn_start definition to setup_directmap_mapping() and change __ro_after_init to __initdata. - Update the commit message about alignment of directmap_virt_start. - Move down directmap_virt_start for (base_addr & ~XEN_PT_LEVEL_SIZE(HY= P_PT_ROOT_LEVEL)) to not waste a lot of directmap space. - Map DIRECTMAP_VIRT_START + (base_addr & XEN_PT_LEVEL_SIZE(HYP_PT_ROOT= _LEVEL)) to _mfn(base_mfn). - Add log of the range in case directmap mapping failure. - Drop XENHEAP_VIRT_START and use directmap_virt_start instead. - Update the comment above setup_mm(). - Update the calculation of bank_start and bank_end in setup_mm() to cover the case when a bank doesn't cover full pages. - Move share_xen_page_with_guest() to riscv/mm.c instead of riscv/stub.c. - Drop inclusion of in riscv/mm.c as thery is nothing used anymore in riscv/mm.c. - Move variable directmap_virt_start and setup_mm() outside #ifndef CONFIG_RISCV_32 ... #endif as they are likely to be common. --- Changes in V2: - merge patch 2 ( xen/riscv: implement maddr_to_virt() ) to the current o= ne as maddr_to_virt() started to use the thing which are introduced in the current patch. - merge with patch 1 ( xen/riscv: add stub for share_xen_page_with_guest(= ) ) as this linkage issue happens during introduction of maddr_to_virt(). - use mathematical range expressions for log messages. - calculate properly amount of mfns in setup_frametable_mapping() taking = into account that ps and pe can be not properly aligned. - drop full stop at the end of debug message. - use PFN_DOWN(framsetable_size) instead of frametable_size >> PAGE_SHIFT. - round down ram_size when it is being accumulated in setup_mm() to guara= ntee that banks can never have partial pages at their start/end. - call setup_directmap_mappings() only for ram bank regions instead of mapping [0, ram_end] region. - drop directmap_virt_end for now as it isn't used at the moment. - update the commit message. --- xen/arch/riscv/include/asm/mm.h | 13 ++- xen/arch/riscv/include/asm/setup.h | 2 + xen/arch/riscv/mm.c | 141 +++++++++++++++++++++++++++++ xen/arch/riscv/setup.c | 3 + xen/include/xen/macros.h | 1 + 5 files changed, 156 insertions(+), 4 deletions(-) diff --git a/xen/arch/riscv/include/asm/mm.h b/xen/arch/riscv/include/asm/m= m.h index ebb142502e..50d2ac3830 100644 --- a/xen/arch/riscv/include/asm/mm.h +++ b/xen/arch/riscv/include/asm/mm.h @@ -12,6 +12,8 @@ =20 #include =20 +extern vaddr_t directmap_virt_start; + #define pfn_to_paddr(pfn) ((paddr_t)(pfn) << PAGE_SHIFT) #define paddr_to_pfn(pa) ((unsigned long)((pa) >> PAGE_SHIFT)) =20 @@ -25,8 +27,11 @@ =20 static inline void *maddr_to_virt(paddr_t ma) { - BUG_ON("unimplemented"); - return NULL; + unsigned long va_offset =3D maddr_to_directmapoff(ma); + + ASSERT(va_offset < DIRECTMAP_SIZE); + + return (void *)(directmap_virt_start + va_offset); } =20 /* @@ -37,9 +42,9 @@ static inline void *maddr_to_virt(paddr_t ma) */ static inline unsigned long virt_to_maddr(unsigned long va) { - if ((va >=3D DIRECTMAP_VIRT_START) && + if ((va >=3D directmap_virt_start) && (va < (DIRECTMAP_VIRT_START + DIRECTMAP_SIZE))) - return directmapoff_to_maddr(va - DIRECTMAP_VIRT_START); + return directmapoff_to_maddr(va - directmap_virt_start); =20 BUILD_BUG_ON(XEN_VIRT_SIZE !=3D MB(2)); ASSERT((va >> (PAGETABLE_ORDER + PAGE_SHIFT)) =3D=3D diff --git a/xen/arch/riscv/include/asm/setup.h b/xen/arch/riscv/include/as= m/setup.h index c0214a9bf2..844a2f0ef1 100644 --- a/xen/arch/riscv/include/asm/setup.h +++ b/xen/arch/riscv/include/asm/setup.h @@ -5,6 +5,8 @@ =20 #define max_init_domid (0) =20 +void setup_mm(void); + #endif /* ASM__RISCV__SETUP_H */ =20 /* diff --git a/xen/arch/riscv/mm.c b/xen/arch/riscv/mm.c index 27026d803b..185008f4c6 100644 --- a/xen/arch/riscv/mm.c +++ b/xen/arch/riscv/mm.c @@ -372,6 +372,12 @@ int destroy_xen_mappings(unsigned long s, unsigned lon= g e) return -1; } =20 +void share_xen_page_with_guest(struct page_info *page, struct domain *d, + enum XENSHARE_flags flags) +{ + BUG_ON("unimplemented"); +} + void * __init early_fdt_map(paddr_t fdt_paddr) { /* We are using 2MB superpage for mapping the FDT */ @@ -423,3 +429,138 @@ void * __init early_fdt_map(paddr_t fdt_paddr) =20 return fdt_virt; } + +vaddr_t __ro_after_init directmap_virt_start =3D DIRECTMAP_VIRT_START; + +#ifndef CONFIG_RISCV_32 + +/* Map a frame table to cover physical addresses ps through pe */ +static void __init setup_frametable_mappings(paddr_t ps, paddr_t pe) +{ + paddr_t aligned_ps =3D ROUNDUP(ps, PAGE_SIZE); + paddr_t aligned_pe =3D ROUNDDOWN(pe, PAGE_SIZE); + unsigned long nr_mfns =3D PFN_DOWN(aligned_pe - aligned_ps); + unsigned long frametable_size =3D nr_mfns * sizeof(*frame_table); + mfn_t base_mfn; + + if ( frametable_size > FRAMETABLE_SIZE ) + panic("The frametable cannot cover [%#"PRIpaddr", %#"PRIpaddr")\n", + ps, pe); + + /* + * align base_mfn and frametable_size to MB(2) to have superpage mappi= ng + * in map_pages_to_xen() + */ + frametable_size =3D ROUNDUP(frametable_size, MB(2)); + base_mfn =3D alloc_boot_pages(frametable_size >> PAGE_SHIFT, PFN_DOWN(= MB(2))); + + if ( map_pages_to_xen(FRAMETABLE_VIRT_START, base_mfn, + PFN_DOWN(frametable_size), + PAGE_HYPERVISOR_RW) ) + panic("frametable mappings failed: %#lx -> %#lx\n", + FRAMETABLE_VIRT_START, mfn_x(base_mfn)); + + memset(&frame_table[0], -1, frametable_size); + memset(&frame_table[PFN_DOWN(aligned_ps)], + 0, nr_mfns * sizeof(*frame_table)); +} + +/* Map the region in the directmap area. */ +static void __init setup_directmap_mappings(unsigned long base_mfn, + unsigned long nr_mfns) +{ + static mfn_t __initdata directmap_mfn_start =3D INVALID_MFN_INITIALIZE= R; + + unsigned long base_addr =3D mfn_to_maddr(_mfn(base_mfn)); + unsigned long high_bits_mask =3D XEN_PT_LEVEL_MAP_MASK(HYP_PT_ROOT_LEV= EL); + + /* First call sets the directmap physical and virtual offset. */ + if ( mfn_eq(directmap_mfn_start, INVALID_MFN) ) + { + directmap_mfn_start =3D _mfn(base_mfn); + + directmap_virt_start -=3D (base_addr & high_bits_mask); + } + + if ( base_mfn < mfn_x(directmap_mfn_start) ) + panic("cannot add directmap mapping at %#lx below heap start %#lx\= n", + base_mfn, mfn_x(directmap_mfn_start)); + + /* + * The base address may not be aligned to the second level + * size in case of Sv39 (e.g. 1GB when using 4KB pages). + * This would prevent superpage mappings for all the regions + * because the virtual address and machine address should + * both be suitably aligned. + * + * Prevent that by offsetting the start of the directmap virtual + * address. + */ + if ( map_pages_to_xen(DIRECTMAP_VIRT_START + (base_addr & ~high_bits_m= ask), + _mfn(base_mfn), nr_mfns, + PAGE_HYPERVISOR_RW) ) + panic("Directmap mappings for [%#"PRIpaddr", %#"PRIpaddr") failed\= n", + mfn_to_maddr(_mfn(base_mfn)), + mfn_to_maddr(_mfn(base_mfn + nr_mfns))); +} + +#else /* CONFIG_RISCV_32 */ +#error setup_{directmap,frametable}_mapping() should be implemented for RV= _32 +#endif + +/* + * Setup memory management + * + * RISC-V 64 has a large virtual address space (the minimum supported + * MMU mode is Sv39, which provides GBs of VA space). + * + * The directmap_virt_start is shifted lower in the VA space to + * (DIRECTMAP_VIRT_START - masked_low_bits_of_ram_start_address) to avoid + * wasting a large portion of the directmap space, this also allows for si= mple + * VA <-> PA translations. Also aligns DIRECTMAP_VIRT_START to a GB bounda= ry + * (for Sv39; for other MMU mode boundaries will be bigger ) by masking the + * higher bits of the RAM start address to enable the use of superpages in + * map_pages_to_xen(). + * + * The frametable is mapped starting from physical address 0, minimizing + * wasted VA space and simplifying page_to_mfn() and mfn_to_page() + * translations. + */ +void __init setup_mm(void) +{ + const struct membanks *banks =3D bootinfo_get_mem(); + paddr_t ram_start =3D INVALID_PADDR; + paddr_t ram_end =3D 0; + paddr_t ram_size =3D 0; + unsigned int i; + + /* + * We need some memory to allocate the page-tables used for the direct= map + * mappings. But some regions may contain memory already allocated + * for other uses (e.g. modules, reserved-memory...). + * + * For simplicity, add all the free regions in the boot allocator. + */ + populate_boot_allocator(); + + total_pages =3D 0; + + for ( i =3D 0; i < banks->nr_banks; i++ ) + { + const struct membank *bank =3D &banks->bank[i]; + paddr_t bank_start =3D ROUNDUP(bank->start, PAGE_SIZE); + paddr_t bank_end =3D ROUNDDOWN(bank->start + bank->size, PAGE_SIZE= ); + unsigned long bank_size =3D bank_end - bank_start; + + ram_size +=3D bank_size; + ram_start =3D min(ram_start, bank_start); + ram_end =3D max(ram_end, bank_end); + + setup_directmap_mappings(PFN_DOWN(bank_start), PFN_DOWN(bank_size)= ); + } + + total_pages =3D PFN_DOWN(ram_size); + + setup_frametable_mappings(0, ram_end); + max_page =3D PFN_DOWN(ram_end); +} diff --git a/xen/arch/riscv/setup.c b/xen/arch/riscv/setup.c index e29bd75d7c..2887a18c0c 100644 --- a/xen/arch/riscv/setup.c +++ b/xen/arch/riscv/setup.c @@ -12,6 +12,7 @@ =20 #include #include +#include #include #include =20 @@ -59,6 +60,8 @@ void __init noreturn start_xen(unsigned long bootcpu_id, printk("Command line: %s\n", cmdline); cmdline_parse(cmdline); =20 + setup_mm(); + printk("All set up\n"); =20 machine_halt(); diff --git a/xen/include/xen/macros.h b/xen/include/xen/macros.h index 19caaa8026..cd528fbdb1 100644 --- a/xen/include/xen/macros.h +++ b/xen/include/xen/macros.h @@ -2,6 +2,7 @@ #define __MACROS_H__ =20 #define ROUNDUP(x, a) (((x) + (a) - 1) & ~((a) - 1)) +#define ROUNDDOWN(x, a) ((x) & ~((a) - 1)) =20 #define IS_ALIGNED(val, align) (!((val) & ((align) - 1))) =20 --=20 2.47.0 From nobody Thu Nov 21 16:12:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1730467045; cv=none; d=zohomail.com; s=zohoarc; b=Udz+1F5fEqHQ9xbGW9r6c4TS72aLRlRThDAuHFJDi/iwk3tkfLIBEohg7wvrF1NKWOU5ezbBl+rBcDYmrjc/R7ABHMBhY8SKkLxjcS6odQUW9LahlGFLQ+cqLwRVQpH8j4MsctlGE1Sq1xGCKT/h1pN2Re737SULDQu4h120F+U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730467045; 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=raCa0Y19+glB0odfz1RMTbbLMqPF4E5Qqp9OuEhrM1g=; b=npVQTVezbTjIKh6F43bY+yWTx7+8SKl7YakmMcA8aEaDMK7UF3Gzh8+g978Nyuzqyl7lW9e2o4mxSYnrn1+D7XTpzWQ3B4AEiHP2PuUcgGzbFDbJu0Q/Ch4Vvty4jGdin2qOmp58W9HT2Q7/EAla9XZvXsc2+sWWpK8Bn/ehBWc= 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=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1730467045021487.4562104591138; Fri, 1 Nov 2024 06:17:25 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.829112.1244203 (Exim 4.92) (envelope-from ) id 1t6rWN-00011B-3d; Fri, 01 Nov 2024 13:16:59 +0000 Received: by outflank-mailman (output) from mailman id 829112.1244203; Fri, 01 Nov 2024 13:16: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 1t6rWM-00010z-W0; Fri, 01 Nov 2024 13:16:58 +0000 Received: by outflank-mailman (input) for mailman id 829112; Fri, 01 Nov 2024 13:16:57 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t6rWL-0000WD-8V for xen-devel@lists.xenproject.org; Fri, 01 Nov 2024 13:16:57 +0000 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [2a00:1450:4864:20::133]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 8e866fbe-9853-11ef-99a3-01e77a169b0f; Fri, 01 Nov 2024 14:16:51 +0100 (CET) Received: by mail-lf1-x133.google.com with SMTP id 2adb3069b0e04-539f7606199so2014122e87.0 for ; Fri, 01 Nov 2024 06:16:51 -0700 (PDT) Received: from fedora.. ([94.75.70.14]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53c7bdcbcf6sm549745e87.194.2024.11.01.06.16.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Nov 2024 06:16:47 -0700 (PDT) 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: 8e866fbe-9853-11ef-99a3-01e77a169b0f X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjoxMzMiLCJoZWxvIjoibWFpbC1sZjEteDEzMy5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6IjhlODY2ZmJlLTk4NTMtMTFlZi05OWEzLTAxZTc3YTE2OWIwZiIsInRzIjoxNzMwNDY3MDExLjM4Nzc2Miwic2VuZGVyIjoib2xla3NpaS5rdXJvY2hrb0BnbWFpbC5jb20iLCJyZWNpcGllbnQiOiJ4ZW4tZGV2ZWxAbGlzdHMueGVucHJvamVjdC5vcmcifQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730467010; x=1731071810; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=raCa0Y19+glB0odfz1RMTbbLMqPF4E5Qqp9OuEhrM1g=; b=DPzaaxiexH/8i3wfHvGCMsFZi5Ro8ERvvjjP4QavweyKNITbhyKfKeC3+QPCKPGXMo ms4HnYJphjQcvVTj3BYcrGnRBdPb12X2rdfEwugwjlJapX4IXRV8tGLTV2QS2AqOypnG RjAtIl5i4o7qiHXuwca2qXrpSOyHE/a/bL795iR+6aMz72NF5UK3nf8t6oqm5zmcmEHH rR3FwtG/WYkKl6shOKzBTMs0ctfm6J7XXQkLDVu3Sj783Ql7gFWOiAGwQf/GDzS7Nlvt Xo20Px3cs4tsV2Rhqob0x/Uw9vm181YyOec11V2xH48jAz8Ftr+pf3umjiw49qlxJSKv Sb0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730467010; x=1731071810; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=raCa0Y19+glB0odfz1RMTbbLMqPF4E5Qqp9OuEhrM1g=; b=olucdAaj1K9KYb2ShCLfr2E00oaaHjlIYOjLy8DoatpCyUoCi5R206jnsXIxB+pYY7 +X3KcVq7E8pPnze+lH8nACY3s6SnjXPnAlL3e+M4ELvVZmdpJJfrAy7EHWwKyzMYNiov spL/su6aSu1DH7eEj7wC5pnGGqjn3o7/fb7oTbB3kgMkBBWHPyGjTBIHTIXk5bTeqIgg EAcVtwLLc1s/yywcU4AlbH9JBA6Uyyx6vcmRf5jhdPNEeOYzZhwMkeLqE308TGTqWr9S D3XsoT2NfoHqpLz3eE58aM4mpvxUu3hNaBTi1n11GBaMdrEqSbNhONNb6+FJgkxgXqty OOlg== X-Gm-Message-State: AOJu0YzT7zbxF8AuP8QegyWdwmFjLtX7qEfK+Al/fwnLYQATfBG+DH2P y2/D82J/ue1MBA2Y16dEV3z9QwH7Nqcmb4vZnW43YuSLdJuJ+RnNGnBINA== X-Google-Smtp-Source: AGHT+IEdYtglvc8ZrGe4Lg6gkk4TyLs2TxMc6upOoe9rOr1KLBp/NjIVK0naj8wGyjRpZY5zzJeERQ== X-Received: by 2002:a05:6512:281b:b0:536:55ef:69e8 with SMTP id 2adb3069b0e04-53b7eb9d73fmr6363459e87.0.1730467010294; Fri, 01 Nov 2024 06:16:50 -0700 (PDT) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Oleksii Kurochko , Alistair Francis , Bob Eshleman , Connor Davis , Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini Subject: [PATCH v3 2/3] xen/riscv: initialize the VMAP_DEFAULT virtual range Date: Fri, 1 Nov 2024 14:16:41 +0100 Message-ID: <98f8bd0253a8988283610fabb19de664a523c6f8.1730465154.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1730467045854116600 Content-Type: text/plain; charset="utf-8" Call vm_init() to initialize the VMAP_DEFAULT virtual range. To support this, introduce the populate_pt_range() and arch_vmap_virt_end() functions, which are used by vm_init()->vm_init_type(). Signed-off-by: Oleksii Kurochko Acked-by: Jan Beulich --- Change in V2-V3: - Acked-by: Jan Beulich --- xen/arch/riscv/mm.c | 11 +++++------ xen/arch/riscv/pt.c | 6 ++++++ xen/arch/riscv/setup.c | 3 +++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/xen/arch/riscv/mm.c b/xen/arch/riscv/mm.c index 185008f4c6..db75aa1d4f 100644 --- a/xen/arch/riscv/mm.c +++ b/xen/arch/riscv/mm.c @@ -351,12 +351,6 @@ void arch_dump_shared_mem_info(void) BUG_ON("unimplemented"); } =20 -int populate_pt_range(unsigned long virt, unsigned long nr_mfns) -{ - BUG_ON("unimplemented"); - return -1; -} - int xenmem_add_to_physmap_one(struct domain *d, unsigned int space, union add_to_physmap_extra extra, unsigned long idx, gfn_t gfn) @@ -564,3 +558,8 @@ void __init setup_mm(void) setup_frametable_mappings(0, ram_end); max_page =3D PFN_DOWN(ram_end); } + +void *__init arch_vmap_virt_end(void) +{ + return (void *)(VMAP_VIRT_START + VMAP_VIRT_SIZE); +} diff --git a/xen/arch/riscv/pt.c b/xen/arch/riscv/pt.c index cc5e2d3266..d62aceb36c 100644 --- a/xen/arch/riscv/pt.c +++ b/xen/arch/riscv/pt.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -419,3 +420,8 @@ int map_pages_to_xen(unsigned long virt, =20 return pt_update(virt, mfn, nr_mfns, flags); } + +int __init populate_pt_range(unsigned long virt, unsigned long nr_mfns) +{ + return pt_update(virt, INVALID_MFN, nr_mfns, PTE_POPULATE); +} diff --git a/xen/arch/riscv/setup.c b/xen/arch/riscv/setup.c index 2887a18c0c..3652cb056d 100644 --- a/xen/arch/riscv/setup.c +++ b/xen/arch/riscv/setup.c @@ -7,6 +7,7 @@ #include #include #include +#include =20 #include =20 @@ -62,6 +63,8 @@ void __init noreturn start_xen(unsigned long bootcpu_id, =20 setup_mm(); =20 + vm_init(); + printk("All set up\n"); =20 machine_halt(); --=20 2.47.0 From nobody Thu Nov 21 16:12:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1730467048; cv=none; d=zohomail.com; s=zohoarc; b=Ms6mkn5FiyN6bOaoRm7EdsdfC0DUvH2t+9I5zCEunZ2K7wfZ21EMfxkyJvfwvZ36iYUui3dIZ5sOtXZ8UIu99v8f6mV9fYGvqb9wzrbOgqbaDcQuKZG/8uuFUkeuC2Viu2JZPOVZCOb91r5NIOlqVCu8hYaAkwY7B99d//p/cbc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730467048; 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=H0tCjI4kCmIi/dimFkccnAhbpz2v4MkjIHvRt5/LZKc=; b=B6So8aZaA7gEsnJ8ybUZJgbTxROUX20ukSk3JuRDA4rP6sIqcXWDcwofOPjucJHmNl7bCPLYUR2/qeHusgIP8z/37o4avpuDFycp3JDQaU9tlrBB9HwFAocnBQwOveWKRpdzbDqF9e83DulPAQpufJqirGe3Z90xEXwNs8Z5Z1o= 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=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1730467048840139.34994557234484; Fri, 1 Nov 2024 06:17:28 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.829113.1244209 (Exim 4.92) (envelope-from ) id 1t6rWN-00014V-EI; Fri, 01 Nov 2024 13:16:59 +0000 Received: by outflank-mailman (output) from mailman id 829113.1244209; Fri, 01 Nov 2024 13:16: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 1t6rWN-00013J-6u; Fri, 01 Nov 2024 13:16:59 +0000 Received: by outflank-mailman (input) for mailman id 829113; Fri, 01 Nov 2024 13:16:57 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t6rWL-0000WD-FN for xen-devel@lists.xenproject.org; Fri, 01 Nov 2024 13:16:57 +0000 Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [2a00:1450:4864:20::12d]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 8f57c2a7-9853-11ef-99a3-01e77a169b0f; Fri, 01 Nov 2024 14:16:52 +0100 (CET) Received: by mail-lf1-x12d.google.com with SMTP id 2adb3069b0e04-539f58c68c5so3755774e87.3 for ; Fri, 01 Nov 2024 06:16:52 -0700 (PDT) Received: from fedora.. ([94.75.70.14]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53c7bdcbcf6sm549745e87.194.2024.11.01.06.16.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Nov 2024 06:16:50 -0700 (PDT) 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: 8f57c2a7-9853-11ef-99a3-01e77a169b0f X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjoxMmQiLCJoZWxvIjoibWFpbC1sZjEteDEyZC5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6IjhmNTdjMmE3LTk4NTMtMTFlZi05OWEzLTAxZTc3YTE2OWIwZiIsInRzIjoxNzMwNDY3MDEyLjc1ODg1Miwic2VuZGVyIjoib2xla3NpaS5rdXJvY2hrb0BnbWFpbC5jb20iLCJyZWNpcGllbnQiOiJ4ZW4tZGV2ZWxAbGlzdHMueGVucHJvamVjdC5vcmcifQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730467012; x=1731071812; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=H0tCjI4kCmIi/dimFkccnAhbpz2v4MkjIHvRt5/LZKc=; b=bS/TOcc9eOY6e/oP3zOhDFIK4LC6RNGRKpeTas2rkMEI/UphktQwARA6OP42KxBYL9 kTo+VQX4hlmSkxI3CiV0tcPQJ9/Z+rridX1LWhGIAIpg9KOKGf/Fqr06/kyPe//xzURF 4vBa1JdrbHGNOX6u56Js0FN7jGI8ie2cI5eRyhNq0AYS/gxhcZfk7VbmhUg5Prf/sj5i 1TBOFfdvoziyRbszAMevSImcg/4bhzkYMBsnbTn00LdaGwAXNnSOW0PtOUt0QdGcHMM5 Dd7w0kzpRblRSd+UdcNeSXM2/nHMPcJxop4BycRKCnJEkWo1+5Q+Oh1JMDZs9oYnPhF+ Msnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730467012; x=1731071812; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=H0tCjI4kCmIi/dimFkccnAhbpz2v4MkjIHvRt5/LZKc=; b=rekl324VztLNMgYWjOwEF5mkvFdpJns/Q9sYxmdaEGzUmR2trLuyrl3S8lbMGfP5I0 eLtetZcqpmAVsj87FT2bxMXo9XS/NfmQvGNFI5jV8xvki9d76GI93m9cXinuesdPHqRy NUZwRc9JUL8Ye+js2BYWWZQBSDAQiempEvvlTZoZAxVqEA0KtRWY8Upj7sfne7/ARD+M NBXnkMk45+nKIoARgnvXpeXpPl1YYIqX43o3k1gIacbGdTvpX8UYQPZPXf28pzcX3RRs PtruFLa+8dsNx9mHZqeNHqtDqW5q0PkhENx/b9dyEZi2G3IrP1xNfyb6IewUFXWmtB1K i9xQ== X-Gm-Message-State: AOJu0YwxQG6Be2DuUjcOzIUUllQVVTOVPzQb786VegNCZR6TXVi+Bs8S MOtnTwQ0/FhizRwJ/U4FFWGmrGdupktGNjnrkydD+DK3Jy8zJ2M2gsKYdw== X-Google-Smtp-Source: AGHT+IFQx18uTeC/Snv59cGLNLIp1Lxw6/5eIE0h/7dXmAj1Y1L+LsPcMbcCgYlU6b4OezBlGLEr5g== X-Received: by 2002:a05:6512:3d10:b0:539:94f5:bf with SMTP id 2adb3069b0e04-53d65e16d9dmr3248992e87.59.1730467011519; Fri, 01 Nov 2024 06:16:51 -0700 (PDT) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Oleksii Kurochko , Alistair Francis , Bob Eshleman , Connor Davis , Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini Subject: [PATCH v3 3/3] xen/riscv: finalize boot allocator and transition to boot state Date: Fri, 1 Nov 2024 14:16:42 +0100 Message-ID: <85a6e3165f4952882b5c430842ccf724650d78d5.1730465154.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1730467049749116600 Content-Type: text/plain; charset="utf-8" Add a call to end_boot_allocator() in start_xen() to finalize the boot memory allocator, moving free pages to the domain sub-allocator. After initializing the memory subsystem, update `system_state` from `SYS_STATE_early_boot` to `SYS_STATE_boot`, signifying the end of the early boot phase. Signed-off-by: Oleksii Kurochko Acked-by: Jan Beulich --- Change in V2-V3: - Acked-by: Jan Beulich --- xen/arch/riscv/setup.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/xen/arch/riscv/setup.c b/xen/arch/riscv/setup.c index 3652cb056d..9680332fee 100644 --- a/xen/arch/riscv/setup.c +++ b/xen/arch/riscv/setup.c @@ -65,6 +65,14 @@ void __init noreturn start_xen(unsigned long bootcpu_id, =20 vm_init(); =20 + end_boot_allocator(); + + /* + * The memory subsystem has been initialized, we can now switch from + * early_boot -> boot. + */ + system_state =3D SYS_STATE_boot; + printk("All set up\n"); =20 machine_halt(); --=20 2.47.0