From patchwork Wed Oct 9 13:45:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksii Kurochko X-Patchwork-Id: 13828460 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 25E65CEDD91 for ; Wed, 9 Oct 2024 13:46:42 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.814531.1228112 (Exim 4.92) (envelope-from ) id 1syX0i-0005PN-Cf; Wed, 09 Oct 2024 13:45:52 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 814531.1228112; Wed, 09 Oct 2024 13:45: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 1syX0i-0005P4-8s; Wed, 09 Oct 2024 13:45:52 +0000 Received: by outflank-mailman (input) for mailman id 814531; Wed, 09 Oct 2024 13:45: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 1syX0h-0005Gw-Lj for xen-devel@lists.xenproject.org; Wed, 09 Oct 2024 13:45:51 +0000 Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [2a00:1450:4864:20::52e]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id cb0bbab1-8644-11ef-99a2-01e77a169b0f; Wed, 09 Oct 2024 15:45:49 +0200 (CEST) Received: by mail-ed1-x52e.google.com with SMTP id 4fb4d7f45d1cf-5c89f3e8a74so9244150a12.0 for ; Wed, 09 Oct 2024 06:45:49 -0700 (PDT) Received: from fedora.. ([94.75.70.14]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c8e0598947sm5435334a12.11.2024.10.09.06.45.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Oct 2024 06:45:47 -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: cb0bbab1-8644-11ef-99a2-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728481549; x=1729086349; 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=eKN+iZaDpNy8yOn7LaIk1Lnug9+dT93sjGvELvafAMY=; b=XSiyFcyRw7MPZ0zG4eDOTCV3nEzyALTa+OQO5xfybV/Wd9k8LFqPsDHNohbHsrRGJl KS8PAQZv+NfK71TGti6yXF2bv3hGZalTLhiFFz74DkQCKwQOrgksrMZCzVo6DiAE1ZSh 8CmajU1XFJ1DkDQU6Mqc6LuJcRHbtX5n3xX2RgaL5XjW75xlxhjKrdXMihoTMWox/p0I RVWdiP1rC65vSdOURoKnT4d1KOt6s2l6gWkzDsqEmzP/9+9wofMD1dgU/2uWH0OqtAQ2 OMkG7XAnEQr4ke97jb/1HdOtjKtURrziaZJcvoqOPo+kdHcFVavMBycAXhzH8QuUo/NT nGhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728481549; x=1729086349; 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=eKN+iZaDpNy8yOn7LaIk1Lnug9+dT93sjGvELvafAMY=; b=mmHOcDHNsQhtxjxfW6M0gL50KxXevEIZ8oREE8gPIB+oDYvZVdQw/4M4kuriq/UuA9 CcQOedRf8+EdpiwpZT8iQT3GpaP3DB3d/Trs6nWkkQXhOOL4AzPKk9Nh0hqKThKojtnq Id8rOToy38fFiFmz0NFvcCannd2ZQIDv+rnHLn6btp8VxzJc63ZeCOFosZw/IeuzW97O 3U+CY2QH2LTV7RliLA2YWJvNdjFprolaFVSK6HL9GnxuOVRQdnCGtatPi0JLEo4v1SC2 L0BGRC3o4vT/C3DvkQ0DO3gv+Vjw1TjFEIBi1BDqUvnwLIvhxtLS3dn0uDqVp4AQvl5y inPQ== X-Gm-Message-State: AOJu0YyUPNkYsbERGZ2eAnGYadWdePJPyc+TVV1TM9WsahOACWvOHsWc sC+CoBvzquWBDO+4wsgrEkigH5WjkW3UWNuvoP4ODFyEjLJn0XAKONIjPQ== X-Google-Smtp-Source: AGHT+IFFr1X0wG6rMgUWf8llcjPefsJc4bQAC4Pnrsp7GHMqAJvAqYBIqUr91an8k5hG50KpyBmKwA== X-Received: by 2002:a05:6402:3582:b0:5c8:bb09:b417 with SMTP id 4fb4d7f45d1cf-5c91d4062bbmr1982190a12.0.1728481548326; Wed, 09 Oct 2024 06:45:48 -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: implement virt_to_maddr() Date: Wed, 9 Oct 2024 15:45:39 +0200 Message-ID: <9f7d9ebde6fc7224490d1fd565676e051c57a80d.1728472163.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: References: MIME-Version: 1.0 Implement the virt_to_maddr() function to convert virtual addresses to machine addresses. The function includes checks for valid address ranges, specifically the direct mapping region (DIRECTMAP_VIRT_START) and the Xen's Linkage (XEN_VIRT_START) region. If the virtual address falls outside of these regions, an assertion will trigger. To implement this, the phys_offset variable is made accessible outside of riscv/mm.c. Signed-off-by: Oleksii Kurochko Acked-by: Jan Beulich --- Changes in v3: - Drop ASSERT(va >= (DIRECTMAP_VIRT_START + DIRECTMAP_SIZE)) as it is enough to have 'if (...)' for directmap region and ASSERT() for checking that virtual address is from Xen's linkage virtual space. - Add the comment above virt_to_maddr(). - Update the commit message. - Add the comment for declaration and defoition of phys_offset: /* = load_start - XEN_VIRT_START */. --- Changes in V2: - Drop casts in virt_to_maddr() for ASSERT which checks that VA is in the range of where Xen is located. - Add UL suffix for or XEN_VIRT_START by using _AC(..., UL) and add inclusion of - Add the comment above return which explains why there is no need to do " - XEN_VIRT_START. --- xen/arch/riscv/include/asm/config.h | 4 ++++ xen/arch/riscv/include/asm/mm.h | 22 +++++++++++++++++++++- xen/arch/riscv/mm.c | 2 +- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/xen/arch/riscv/include/asm/config.h b/xen/arch/riscv/include/asm/config.h index ef68281653..ad75871283 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; /* = load_start - XEN_VIRT_START */ +#endif + #endif /* ASM__RISCV__CONFIG_H */ /* * Local variables: diff --git a/xen/arch/riscv/include/asm/mm.h b/xen/arch/riscv/include/asm/mm.h index 5c79f3def3..ebb142502e 100644 --- a/xen/arch/riscv/include/asm/mm.h +++ b/xen/arch/riscv/include/asm/mm.h @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -28,7 +29,26 @@ static inline void *maddr_to_virt(paddr_t ma) return NULL; } -#define virt_to_maddr(va) ({ BUG_ON("unimplemented"); 0; }) +/* + * virt_to_maddr() is expected to work with virtual addresses from either + * the directmap region or Xen's linkage (XEN_VIRT_START) region. + * Therefore, it is sufficient to check only these regions and assert if `va` + * is not within the directmap or Xen's linkage region. + */ +static inline unsigned long virt_to_maddr(unsigned long va) +{ + 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((va >> (PAGETABLE_ORDER + PAGE_SHIFT)) == + (_AC(XEN_VIRT_START, UL) >> (PAGETABLE_ORDER + PAGE_SHIFT))); + + /* phys_offset = load_start - XEN_VIRT_START */ + 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..daa02b2c60 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; /* = load_start - XEN_VIRT_START */ #define LOAD_TO_LINK(addr) ((unsigned long)(addr) - phys_offset) #define LINK_TO_LOAD(addr) ((unsigned long)(addr) + phys_offset) From patchwork Wed Oct 9 13:45:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksii Kurochko X-Patchwork-Id: 13828457 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 6DAC5CEDD91 for ; Wed, 9 Oct 2024 13:46:08 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.814530.1228107 (Exim 4.92) (envelope-from ) id 1syX0i-0005Nd-4s; Wed, 09 Oct 2024 13:45:52 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 814530.1228107; Wed, 09 Oct 2024 13:45: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 1syX0i-0005NW-2B; Wed, 09 Oct 2024 13:45:52 +0000 Received: by outflank-mailman (input) for mailman id 814530; Wed, 09 Oct 2024 13:45:50 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1syX0g-00059A-ST for xen-devel@lists.xenproject.org; Wed, 09 Oct 2024 13:45:50 +0000 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [2a00:1450:4864:20::52b]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id cb8a0ee9-8644-11ef-a0bd-8be0dac302b0; Wed, 09 Oct 2024 15:45:50 +0200 (CEST) Received: by mail-ed1-x52b.google.com with SMTP id 4fb4d7f45d1cf-5c8a2579d94so8001566a12.0 for ; Wed, 09 Oct 2024 06:45:50 -0700 (PDT) Received: from fedora.. ([94.75.70.14]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c8e0598947sm5435334a12.11.2024.10.09.06.45.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Oct 2024 06:45:48 -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: cb8a0ee9-8644-11ef-a0bd-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728481549; x=1729086349; 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=LUbIlgBj8AycXaBiq5VvH9Kf8b686NBX0+bgyidJsiQ=; b=WHmA/dLgXuAe173oIJcYW1IJo9mN/znHW0fpDm05w3VAgnByBlbOf0fS3B8Uwd00A/ F+m+cc2R1zjOJGbWWr5/TdWi/H+tjaP90htdg8WVk1FblUuL7YNlxlN+v4Av2SI68i3o YHCkENNl2ys5qRqdQ9oImN248O9j+y9TXIyxfyXsQTeIz6y4u5flFD2nhj0b4k7SIUcp 37lPG7CLobCxD+A8U/2ImvhgZ06fwBWGfSrr3ZeEaWPryePlmnDDvQV/M+EC/CPQsRlU DDLAG+LuIYcqsreEZ4PMWRQ4W21Zi9rjTROXF5KNbIe+uhGKrsPK87O0M+K2H04as8zH htuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728481549; x=1729086349; 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=LUbIlgBj8AycXaBiq5VvH9Kf8b686NBX0+bgyidJsiQ=; b=CePayOe3D3hhLRZ2XRvQYW5CS674WU3RJvY7nL525ZRwHt+TxLoreodEJBL2E8hYxK SYD9VPmpcV3mmmxi694JWkSj4kdVpYsckm1J03b5R2KYILuTU9wvYwvHWDzHQOik3aLM ejIBCOvTErSiOuN+Lvge5gzyikIZNgpYIzVSYH2sDOwbrSU2CG1GgHre/ndQf6s57TxS SFg81hB/heWIxbRHZhsc7j04TdGDfJQdZJRJB/VRAuYpxPBDv5SU8JdlYfr5fiFQL1MG Ps8aw2qxQWYEdScyMykGE1xOu6o1hCX3A0c8aciiiSMxA3MCymCys8IdgjLZKzfnpngY B/Lg== X-Gm-Message-State: AOJu0YwpvEk9hiwz7V8qod3mJNTshiQPBvcZEA2dhvXaeYVS6voW4wRd a24/AIhP4CFezUFRjwd/qWh2lf4bXh8GsDJnSZienm01LGTzyMnqfuJsyA== X-Google-Smtp-Source: AGHT+IGpv4Y1dh2fzkZF3rlKiORYVcUQIKhHp0dDzWuxXE3eqKRkHNw+iA6zorlLDNgRrAXJIhNQrQ== X-Received: by 2002:a05:6402:3714:b0:5c8:8d60:600f with SMTP id 4fb4d7f45d1cf-5c91d5a5526mr2133434a12.14.1728481549206; Wed, 09 Oct 2024 06:45:49 -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: switch LINK_TO_LOAD() to virt_to_maddr() Date: Wed, 9 Oct 2024 15:45:40 +0200 Message-ID: X-Mailer: git-send-email 2.46.2 In-Reply-To: References: MIME-Version: 1.0 Use virt_to_maddr() instead of LINK_TO_LOAD as virt_to_maddr() covers all the cases where LINK_TO_LOAD() is used. Signed-off-by: Oleksii Kurochko Acked-by: Jan Beulich --- Changes in V3: - Add Acked-by: Jan Beulich . --- Changes in V2: - Drop the cast of virt_to_maddr() argument in remove_identity_mapping() as this cast is done inside virtu_to_maddr() wrapper macros. - Update the commit message ( rewording to be more clear ) --- 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 daa02b2c60..27026d803b 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; /* = load_start - XEN_VIRT_START */ #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(turn_on_mmu) & XEN_PT_LEVEL_MAP_MASK(0); for ( pgtbl = stage1_pgtbl_root, i = CONFIG_PAGING_LEVELS; i; i-- ) { From patchwork Wed Oct 9 13:45:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksii Kurochko X-Patchwork-Id: 13828459 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 A6E50CEDD91 for ; Wed, 9 Oct 2024 13:46:38 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.814532.1228127 (Exim 4.92) (envelope-from ) id 1syX0j-0005ql-N8; Wed, 09 Oct 2024 13:45:53 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 814532.1228127; Wed, 09 Oct 2024 13:45: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 1syX0j-0005qb-Jo; Wed, 09 Oct 2024 13:45:53 +0000 Received: by outflank-mailman (input) for mailman id 814532; Wed, 09 Oct 2024 13:45:52 +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 1syX0i-0005Gw-I0 for xen-devel@lists.xenproject.org; Wed, 09 Oct 2024 13:45:52 +0000 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [2a00:1450:4864:20::136]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id cbfea96b-8644-11ef-99a2-01e77a169b0f; Wed, 09 Oct 2024 15:45:51 +0200 (CEST) Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-53994aadb66so6262247e87.2 for ; Wed, 09 Oct 2024 06:45:51 -0700 (PDT) Received: from fedora.. ([94.75.70.14]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c8e0598947sm5435334a12.11.2024.10.09.06.45.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Oct 2024 06:45:49 -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: cbfea96b-8644-11ef-99a2-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728481550; x=1729086350; 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=PSPaRmxzt0eAVlcbacBly/DaDiKEi9jlpaGGhdonnXU=; b=nFDSlchmC6qt4Yfd40Sz2ZKbuss5LIlunBOwS/NPmUw6kFf2ACF8fDnyl1vQ/Z6Agz QqqECZtdpOu09GNbp+BicS/LneTW+gkJpREzkWKqL5al61YJG/wRf8yKIt5dNABaTP+X 8/jkQ1fvhI7jncgH0r5EshIycaEOm6BJtvD0HJT06k0Kf66EZVElQFlGvqyWfCh5Hrg2 7ibqT3WJQMzC1H2SvQ3eHbKkR+fyUUSD+pe95GPTXcTqEyADpgVwzCRb0ZFEQdctRqaO J7BObTDqUgIGaMtu+LbJsAIc5q3h9a6jFnydfGOFMkHQHdd5ripbrYXppnmZtK91fzj0 qeYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728481550; x=1729086350; 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=PSPaRmxzt0eAVlcbacBly/DaDiKEi9jlpaGGhdonnXU=; b=ta4wzEh51Mph+0rEO7/JOa6GFN+0tglbVMk6FjWovqmUm4PpfmzcEyETAws40S0p95 5oWZZqRdNU8wC2QLVtU5iH9a1/5XutKq6he5gJ3uIySJhRinu6vNx4EmPSq9yBdT8e+I z49Dp+zZTJCbhdXaya1dobwH8YemmqA/CQYTIYZlN38Heb1qiLe+1HQNgM80vGgkZbbM UBl6tN7MqR9Upyn9+BVQQiobqA/9VIwm4TKGuCJOMj0GhXiQ4xMPhr7xiIDySHL8fi+X iVUvnY1oUL2vdA+FQ2pe+dS/nEVChNVwy4feSEvNJLnBgynhGoi5svQrepMrO3QIwzSY /U0g== X-Gm-Message-State: AOJu0Yyj7S1SDRjBXcRH7yt85n7xeVLjk4/KLiPjwFg0lemkr6APX6JC akD+9oBm21FLbwqIwu23mn9RdIuHomAyqVVynl3rKm1svCvvZwBFwYz2Cg== X-Google-Smtp-Source: AGHT+IETkjSORs4fMVZO6b+/grQCRsc7UVKkbbOABRhAOi7uwdEmraxZ2/th2k7e3kvUZwRQbn65RA== X-Received: by 2002:a05:6512:3050:b0:533:46cc:a736 with SMTP id 2adb3069b0e04-539c92b1a6bmr141554e87.37.1728481550026; Wed, 09 Oct 2024 06:45: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 3/3] xen/riscv: register Xen's load address as a boot module Date: Wed, 9 Oct 2024 15:45:41 +0200 Message-ID: X-Mailer: git-send-email 2.46.2 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 Acked-by: Jan Beulich --- Changes in V3: - Add Acked-by: Jan Beulich . --- Changes in V2: - Drop local variable xen_bootmodule as it won't be used after initialization. - Drop unnecessary cast for the 3rd argument of add_boot_module() call in start_xen(). - Change BUG_ON(!xen_bootmodule) to panic(). --- xen/arch/riscv/setup.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/xen/arch/riscv/setup.c b/xen/arch/riscv/setup.c index 6d156c3a40..f531ca38ee 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 @@ -44,6 +45,11 @@ 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. */ + if ( !add_boot_module(BOOTMOD_XEN, virt_to_maddr(_start), + _end - _start, false) ) + panic("Failed to add BOOTMOD_XEN\n"); + printk("All set up\n"); machine_halt();