From patchwork Mon Sep 30 15:08:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksii Kurochko X-Patchwork-Id: 13816598 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1BFB2CE8359 for ; Mon, 30 Sep 2024 15:08:57 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.807433.1218893 (Exim 4.92) (envelope-from ) id 1svI0j-0002Ww-Ub; Mon, 30 Sep 2024 15:08:29 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 807433.1218893; Mon, 30 Sep 2024 15:08: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 1svI0j-0002Wm-RS; Mon, 30 Sep 2024 15:08:29 +0000 Received: by outflank-mailman (input) for mailman id 807433; Mon, 30 Sep 2024 15:08:28 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1svI0i-00022q-LS for xen-devel@lists.xenproject.org; Mon, 30 Sep 2024 15:08:28 +0000 Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [2a00:1450:4864:20::134]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id d855b50b-7f3d-11ef-99a2-01e77a169b0f; Mon, 30 Sep 2024 17:08:27 +0200 (CEST) Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-5399041167cso2164067e87.0 for ; Mon, 30 Sep 2024 08:08:27 -0700 (PDT) Received: from fedora.. ([94.75.70.14]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-538a0432219sm1264423e87.132.2024.09.30.08.08.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 08:08:25 -0700 (PDT) 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: d855b50b-7f3d-11ef-99a2-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727708906; x=1728313706; 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=OAL8c3GW2uyga/G1EVaDK0Z5EZU/EC3svPKlERObHus=; b=WLP6wSU6g+4wFJNdOUFG5TctPLLXUTqz+sR6Kg6gNY7bYwh2kUr2prXpUgpSpKE7vg P2qb7fcEYUHc2sgSSKc8a6l8SGZzH+XAl6QDxrx+pOF6+7MBFVwgOgxQdKLpq8Vg2ucc gh1oT/s8t87OKY62v1g9fhYg/yTzshJVVAwM7V5eMvD229HNlVI1ZZrEEfZAJoyO286D t+ZUFQj+kcPOw6VicK345vzaopyXjriHxdjG6Rer0aZusRGkxyvkBSR2nGuzp7fvyhb0 I1oN2FAYSsXfCponVSlLmFq44TnYAkNcp1ZAzczGISbpi1PQ8aErizJbevB8D7twcYys pKeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727708906; x=1728313706; 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=OAL8c3GW2uyga/G1EVaDK0Z5EZU/EC3svPKlERObHus=; b=Sjx7SpeozYoY91bUex3+tnJWUzojiJE/qrF1LjPsqyDGW1c3tPuV3FBGEIRLgVtfyV DjurMD/w5HEYwuvJJcSePEsPcyqlbTYgErX8kLlz/ON2XFaF0CSRZ1brbcfancsIpHlR sqV6jLC6j5Xyf6gteveIlKHRsXOhLCcnMXRyRYIlr+7eWsnJ4/BxKYjKNXDVMvb7pwVh Pd+BFhH4guIRtLzmCjGxKV6T2TTA33IWEcc2+HkkTIror4db3QL9da1JXKCxxABblIXB vNXbF4ShL0Yz4PAFHURoIButWKmwlVQS6xBlnWI7ovhhsHOOK9mI4TR/a1vW5vezqc8j wAew== X-Gm-Message-State: AOJu0Yzcu2b+3e76VuFem7DSlb+B5SDvgIdZNGbq20KFGDHufD2IK+zf PIooL9cZB9RivGUA00lvUYb2F3yr2x+Qeyd7fJ9I4csWGwsUCI7gFJxUIg== X-Google-Smtp-Source: AGHT+IH7aEAQXCy/i3YX3YbUX6WObvTj3zirVkQ4qR/nnBeN3hj60JKDTTq0fRHr6v5e9HrzHe0szw== X-Received: by 2002:a05:6512:2c04:b0:539:8f3c:4586 with SMTP id 2adb3069b0e04-5398f3c45famr3711256e87.55.1727708905915; Mon, 30 Sep 2024 08:08:25 -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 v1 1/3] xen/riscv: implement virt_to_maddr() Date: Mon, 30 Sep 2024 17:08:20 +0200 Message-ID: <1d4270af6469af2f95ede34abd8e9f98f775c1f1.1727708665.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.46.1 In-Reply-To: References: MIME-Version: 1.0 Implement the virt_to_maddr() function to convert virtual addresses to machine addresses, including checks for address ranges such as the direct mapping area (DIRECTMAP_VIRT_START) and the Xen virtual address space. To implement this, the phys_offset variable is made accessible outside of riscv/mm.c. Signed-off-by: Oleksii Kurochko --- xen/arch/riscv/include/asm/config.h | 4 ++++ xen/arch/riscv/include/asm/mm.h | 15 ++++++++++++++- xen/arch/riscv/mm.c | 2 +- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/xen/arch/riscv/include/asm/config.h b/xen/arch/riscv/include/asm/config.h index 7dbb235685..8884aeab16 100644 --- a/xen/arch/riscv/include/asm/config.h +++ b/xen/arch/riscv/include/asm/config.h @@ -155,6 +155,10 @@ #define IDENT_AREA_SIZE 64 +#ifndef __ASSEMBLY__ +extern unsigned long phys_offset; +#endif + #endif /* __RISCV_CONFIG_H__ */ /* * Local variables: diff --git a/xen/arch/riscv/include/asm/mm.h b/xen/arch/riscv/include/asm/mm.h index 4b7b00b850..aa1f86cd5e 100644 --- a/xen/arch/riscv/include/asm/mm.h +++ b/xen/arch/riscv/include/asm/mm.h @@ -28,7 +28,20 @@ static inline void *maddr_to_virt(paddr_t ma) return NULL; } -#define virt_to_maddr(va) ({ BUG_ON("unimplemented"); 0; }) +static inline unsigned long virt_to_maddr(unsigned long va) +{ + ASSERT(va >= (DIRECTMAP_VIRT_START + DIRECTMAP_SIZE)); + if ((va >= DIRECTMAP_VIRT_START) && + (va < (DIRECTMAP_VIRT_START + DIRECTMAP_SIZE))) + return directmapoff_to_maddr(va - DIRECTMAP_VIRT_START); + + BUILD_BUG_ON(XEN_VIRT_SIZE != MB(2)); + ASSERT(((long)va >> (PAGETABLE_ORDER + PAGE_SHIFT)) == + ((long)XEN_VIRT_START >> (PAGETABLE_ORDER + PAGE_SHIFT))); + + return phys_offset + va; +} +#define virt_to_maddr(va) virt_to_maddr((unsigned long)(va)) /* Convert between Xen-heap virtual addresses and machine frame numbers. */ #define __virt_to_mfn(va) mfn_x(maddr_to_mfn(virt_to_maddr(va))) diff --git a/xen/arch/riscv/mm.c b/xen/arch/riscv/mm.c index 4a628aef83..7a1919e07e 100644 --- a/xen/arch/riscv/mm.c +++ b/xen/arch/riscv/mm.c @@ -26,7 +26,7 @@ struct mmu_desc { pte_t *pgtbl_base; }; -static unsigned long __ro_after_init phys_offset; +unsigned long __ro_after_init phys_offset; #define LOAD_TO_LINK(addr) ((unsigned long)(addr) - phys_offset) #define LINK_TO_LOAD(addr) ((unsigned long)(addr) + phys_offset) From patchwork Mon Sep 30 15:08:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksii Kurochko X-Patchwork-Id: 13816597 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B14B5CE835C for ; Mon, 30 Sep 2024 15:08:56 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.807435.1218913 (Exim 4.92) (envelope-from ) id 1svI0l-00031D-GP; Mon, 30 Sep 2024 15:08:31 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 807435.1218913; Mon, 30 Sep 2024 15:08:31 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1svI0l-000311-Co; Mon, 30 Sep 2024 15:08:31 +0000 Received: by outflank-mailman (input) for mailman id 807435; Mon, 30 Sep 2024 15:08: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 1svI0j-00022q-Lb for xen-devel@lists.xenproject.org; Mon, 30 Sep 2024 15:08:29 +0000 Received: from mail-lj1-x22b.google.com (mail-lj1-x22b.google.com [2a00:1450:4864:20::22b]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id d8ceb4b8-7f3d-11ef-99a2-01e77a169b0f; Mon, 30 Sep 2024 17:08:28 +0200 (CEST) Received: by mail-lj1-x22b.google.com with SMTP id 38308e7fff4ca-2fac49b17ebso12486181fa.0 for ; Mon, 30 Sep 2024 08:08:27 -0700 (PDT) Received: from fedora.. ([94.75.70.14]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-538a0432219sm1264423e87.132.2024.09.30.08.08.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 08:08:26 -0700 (PDT) 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: d8ceb4b8-7f3d-11ef-99a2-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727708907; x=1728313707; 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=d/37IdOCxVXI2z1guCYamgvqmlzEY2bjfj9nmrfmg4E=; b=MAnG1ScBxLNvzfkD+zRAKoWNNNjzQ/K5+BEbp6sa+AUqavcBDs+HMIGeEhjXZL8JSK TeHVC+CiSVNEDinvEoou7OOIOOtKVeDye2tnaVyAmdJSp6nFCmh8g+yg0iN2O9WasmEM +vUk4UZJRQJ7YhnlSI5rNkxNUKHAEUV7UCkpI56GPuaNnOJRbmpNK8P6amOT1TZPhmbO VW90mPdY+XB6c/EpyjTjaHUJBl8F6L//jFyha4sD7IUqueRXHjmyaSnnPoHBGXf9nYnq Y4WTyy4k5455RNUdiSRyREs5zRH7Hhd/EuRKyLmfZFpfjcgUUkQoPH2d1oXO2hDg7eDw HLhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727708907; x=1728313707; 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=d/37IdOCxVXI2z1guCYamgvqmlzEY2bjfj9nmrfmg4E=; b=NcHYO05EI58TelKfiLHcjLCYfpV/Cs2YzxH6Ydj81UqB6w3dm9XMSaKU7nxo0Ljc0y 8jZhneLaYhW42IkCH1KC9SLmbFqaOxm6ZYCSes3BtuwrpJXxrZJzih1YeA3qXosk6x6h TKiXaz5sRxhhfbO0XcjjMwwU1YlSOyApeul0K9UCSMg1zHeuNszMgSnlF0U7roWShnmM WjZ71lOc0EsYi2EPSN3jT90k7oKnOoMWfgE1dYgSln3lgTEpUOkVJPLMDstyEnMk+9jb KZy+ZEiS2ub8L8u02X3q5epvoKtGvhFj7YYQwXoAqZtjF/aSczAJxfwR1wz19D9IRNjD uBJA== X-Gm-Message-State: AOJu0Yxwu5yriCzSogqP51VKJwigLVagECHk3hhn/QjocJz7CoF/hxlB oBR3/6XW498G/RLFUCnnkzba3kV6ohLtJgHf2alz5OhZpPa+1lpWKlBVDg== X-Google-Smtp-Source: AGHT+IGq/yaJsQpWzmrjwiC8QsA6trMJCZDFbf4/V9BBieWtt8Z4Zgm8g0b3EEMhx+BRdc6+0/KDEA== X-Received: by 2002:a05:6512:334f:b0:539:8847:d7e9 with SMTP id 2adb3069b0e04-5398847d900mr4524107e87.35.1727708906904; Mon, 30 Sep 2024 08:08:26 -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 v1 2/3] xen/riscv: switch LINK_TO_LOAD() to virt_to_maddr() Date: Mon, 30 Sep 2024 17:08:21 +0200 Message-ID: <9a462c58f3af0ff5e5d312777cd1552b2a5a930c.1727708665.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.46.1 In-Reply-To: References: MIME-Version: 1.0 Except for switching LINK_TO_LOAD() to virt_to_maddr(), LINK_TO_LOAD() is dropped, as virt_to_maddr() covers all the cases where LINK_TO_LOAD() is used. Signed-off-by: Oleksii Kurochko --- xen/arch/riscv/mm.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/xen/arch/riscv/mm.c b/xen/arch/riscv/mm.c index 7a1919e07e..59da61716c 100644 --- a/xen/arch/riscv/mm.c +++ b/xen/arch/riscv/mm.c @@ -29,7 +29,6 @@ struct mmu_desc { unsigned long __ro_after_init phys_offset; #define LOAD_TO_LINK(addr) ((unsigned long)(addr) - phys_offset) -#define LINK_TO_LOAD(addr) ((unsigned long)(addr) + phys_offset) /* * It is expected that Xen won't be more then 2 MB. @@ -122,7 +121,7 @@ static void __init setup_initial_mapping(struct mmu_desc *mmu_desc, unsigned long paddr = (page_addr - map_start) + pa_start; unsigned int permissions = PTE_LEAF_DEFAULT; unsigned long addr = is_identity_mapping - ? page_addr : LINK_TO_LOAD(page_addr); + ? page_addr : virt_to_maddr(page_addr); pte_t pte_to_be_written; index = pt_index(0, page_addr); @@ -225,7 +224,7 @@ void __init setup_fixmap_mappings(void) BUG_ON(pte_is_valid(*pte)); - tmp = paddr_to_pte(LINK_TO_LOAD((unsigned long)&xen_fixmap), PTE_TABLE); + tmp = paddr_to_pte(virt_to_maddr(&xen_fixmap), PTE_TABLE); write_pte(pte, tmp); RISCV_FENCE(rw, rw); @@ -312,7 +311,7 @@ void __init remove_identity_mapping(void) pte_t *pgtbl; unsigned int index, xen_index; unsigned long ident_start = - LINK_TO_LOAD(turn_on_mmu) & XEN_PT_LEVEL_MAP_MASK(0); + virt_to_maddr((unsigned long)turn_on_mmu) & XEN_PT_LEVEL_MAP_MASK(0); for ( pgtbl = stage1_pgtbl_root, i = CONFIG_PAGING_LEVELS; i; i-- ) { From patchwork Mon Sep 30 15:08:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksii Kurochko X-Patchwork-Id: 13816595 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C44B5CE835C for ; Mon, 30 Sep 2024 15:08:47 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.807434.1218897 (Exim 4.92) (envelope-from ) id 1svI0k-0002aN-7b; Mon, 30 Sep 2024 15:08:30 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 807434.1218897; Mon, 30 Sep 2024 15:08:30 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1svI0k-0002a2-3g; Mon, 30 Sep 2024 15:08:30 +0000 Received: by outflank-mailman (input) for mailman id 807434; Mon, 30 Sep 2024 15:08:29 +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 1svI0j-0002H5-3d for xen-devel@lists.xenproject.org; Mon, 30 Sep 2024 15:08:29 +0000 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [2a00:1450:4864:20::133]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id d9146b33-7f3d-11ef-a0ba-8be0dac302b0; Mon, 30 Sep 2024 17:08:28 +0200 (CEST) Received: by mail-lf1-x133.google.com with SMTP id 2adb3069b0e04-53959a88668so3586288e87.2 for ; Mon, 30 Sep 2024 08:08:28 -0700 (PDT) Received: from fedora.. ([94.75.70.14]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-538a0432219sm1264423e87.132.2024.09.30.08.08.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 08:08:27 -0700 (PDT) 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: d9146b33-7f3d-11ef-a0ba-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727708908; x=1728313708; 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=TSOroKPGJr4XSbKSq9mzOX8MhVcwff6sm7/6Oa6ej/U=; b=GB1Om2QF3d2TE65T/jY4ZKyvMJfcWFB+f6I7/CZD6hfgM7M2oZTmjw7aVaPGui3JHz whJKpoWfo/azX+dpX3oFQ70gCDfZt+rcGePlqlYfLuW9g6VlQluKNhU7F4OOFTy+hU5R DEqE1ZQD2bcRlhEnGo59JFCT0+sjfpbSCY2w+aytVGLE9ORjbr1sIJ+aN6KKztDFKREz R6Lahop7ZSJ6VKxM6htnaw61sKKlnCk+VNXHffn6GOisGFoiqWXXFEWM00YdMZnhDLR/ R7fFvdm+sNGRueA9ooSMNcD7rOBScvrw9Ff8UjHugnexmR2hJ7gLMIiyQu6sfZMZoc/U +jIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727708908; x=1728313708; 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=TSOroKPGJr4XSbKSq9mzOX8MhVcwff6sm7/6Oa6ej/U=; b=QRnhcAE7ZS4lLz6FJe13df+2VVcBhImib5C2VVrI2N23nKebsBVZOJ/LkKl/5fC9D7 nSBKbCK1+ef00UXTzYvgokkx6mYtXkaDjOjotnQbjZ/sQdfZgcq2k5Dv/obg3enoQaS0 sPXN4a6zWLfsQ+sBwWKzJv/W2THPvOF1rrhH8Gh1/6r0WZuuoX/N1YxNLdqpUAHEhuT0 Rs65hro1a7GZqCoHdjEuTrbDoixaU59BGvE1uFkHPFbZJU1+uQlNRL/VlJEYzFtuboQa 6UeHziPhlrlOsfwsN9YP+POI2FdcXeTR3Uag69ZSsV7kFzuhxK1G06qtUm4hxB8A6lJo 2FKw== X-Gm-Message-State: AOJu0Yw3krN+K5lHhVpWhDOGGxHdMGY0w3aNKj1LU/zop8ePhnMG2rkx 7y3sOejl+AX5KS1ajvZw7Apx8qV9/xlZzZVwlYhcAdD0GDL3QVgVFq22tg== X-Google-Smtp-Source: AGHT+IHiBtjsiueFbwVyej97It6FzP3dmxCYRHI65dyUougsaNjUslq5ZDsmuTVVeoorhen+1N9V2w== X-Received: by 2002:a05:6512:4010:b0:539:8ef3:6688 with SMTP id 2adb3069b0e04-5398ef368c5mr3442546e87.23.1727708907546; Mon, 30 Sep 2024 08:08:27 -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 v1 3/3] xen/riscv: register Xen's load address as a boot module Date: Mon, 30 Sep 2024 17:08:22 +0200 Message-ID: <2bd3589f322d30e93d81d091ca64439048c068fc.1727708665.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.46.1 In-Reply-To: References: MIME-Version: 1.0 Avoid using BOOTMOD_XEN region for other purposes or boot modules which could result in memory corruption or undefined behaviour. Signed-off-by: Oleksii Kurochko --- xen/arch/riscv/setup.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/xen/arch/riscv/setup.c b/xen/arch/riscv/setup.c index 6d156c3a40..39375b3366 100644 --- a/xen/arch/riscv/setup.c +++ b/xen/arch/riscv/setup.c @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0-only */ #include +#include #include #include #include @@ -26,6 +27,8 @@ unsigned char __initdata cpu0_boot_stack[STACK_SIZE] void __init noreturn start_xen(unsigned long bootcpu_id, paddr_t dtb_addr) { + struct bootmodule *xen_bootmodule; + remove_identity_mapping(); set_processor_id(0); @@ -44,6 +47,13 @@ void __init noreturn start_xen(unsigned long bootcpu_id, "Please check your bootloader.\n", dtb_addr, BOOT_FDT_VIRT_SIZE); + /* Register Xen's load address as a boot module. */ + xen_bootmodule = add_boot_module(BOOTMOD_XEN, + virt_to_maddr(_start), + (paddr_t)(_end - _start), false); + + BUG_ON(!xen_bootmodule); + printk("All set up\n"); machine_halt();