From nobody Mon Feb 9 09:17:05 2026 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=1689604894; cv=none; d=zohomail.com; s=zohoarc; b=mlH1EXXmQiFOpC+Bkl6tNcJbEbeYvX54NftKZoKJZnNkwtk5OFt5uNHfk8ULzHxYziVEnwa6IjXyaw0f5VQFTU9R3ulKZeDIjzCCaVgWvsJd5OTxLTTijFddbrhyFU9oyMxZhMPzF3Zc/g1ZakCeLJC0ZBIAcMUy/5+ozXg0a0M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689604894; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=z/2F9nnRVGFmm2tz+bdsw6Ss/1KfKE3SpzTYZVGLTXE=; b=gY7JpFjQBG6FjPcy1BidiTeTHABaAlp43n0/3K2T5pznUmLGxa+D79i9KFYHGEIwR7SKS84efd6auutAVuEVQHusLsZGcls/0BVs6OlWZweZhidwjo09ZQSAQh8kUlvlPlnJGRcXYzXCxjpGucnaAY/xAPwZVjhLvEO1DITwyeA= 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 1689604894901306.21648499282946; Mon, 17 Jul 2023 07:41:34 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.564651.882245 (Exim 4.92) (envelope-from ) id 1qLPPH-00027B-8a; Mon, 17 Jul 2023 14:40:59 +0000 Received: by outflank-mailman (output) from mailman id 564651.882245; Mon, 17 Jul 2023 14:40: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 1qLPPH-00025T-4f; Mon, 17 Jul 2023 14:40:59 +0000 Received: by outflank-mailman (input) for mailman id 564651; Mon, 17 Jul 2023 14:40: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 1qLPPF-0001ez-CU for xen-devel@lists.xenproject.org; Mon, 17 Jul 2023 14:40:57 +0000 Received: from mail-lf1-x12c.google.com (mail-lf1-x12c.google.com [2a00:1450:4864:20::12c]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id efa3b88a-24af-11ee-8611-37d641c3527e; Mon, 17 Jul 2023 16:40:55 +0200 (CEST) Received: by mail-lf1-x12c.google.com with SMTP id 2adb3069b0e04-4f122ff663eso7234949e87.2 for ; Mon, 17 Jul 2023 07:40:55 -0700 (PDT) Received: from fedora.. ([94.75.70.14]) by smtp.gmail.com with ESMTPSA id d15-20020ac25ecf000000b004fa52552c7csm2836284lfq.151.2023.07.17.07.40.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jul 2023 07:40:54 -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: efa3b88a-24af-11ee-8611-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689604855; x=1692196855; 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=z/2F9nnRVGFmm2tz+bdsw6Ss/1KfKE3SpzTYZVGLTXE=; b=lqUs0GUk7T/Gmfti/vLam1duKm80RulBZAv5/pC438w509C/VdzpUtRARpk1mdtS8O LVVsWdNfrBqTzDiIZhfUiqE/+QyQEA4CVZuSgXUTp0BPXHTmgmEvkGcD5s26E2HfsU2k U6ap/WfqpbIMaazzLbi0+IRO5lGNiOYiAH0VIKFJ4f8CExAdRfEj4N87vuR41htGlOgq 5IOt1wKxw5afMuqob/p88EbavgD70kEj1Rvhu+gGDdoMz1+4tGV1C2FyyctOGkFQ4//J edGoXgMPM55VcGS99TCOs8A+e4jcF8soCMKk0fyMAK60r/Un0Vc4Wasi2oPTeyA3QW6c vDdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689604855; x=1692196855; 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=z/2F9nnRVGFmm2tz+bdsw6Ss/1KfKE3SpzTYZVGLTXE=; b=lSuTScOs2V+oeAeQB1MrxU0d2e+gpQ1twZ+UE7pWg/h1vyFavcl03sQS6pG8VOtCxe WDLW/TFgVUE5IGjOkzPwuaVdIx2aIMSlm46N26YVYDzUkPNzEIx5OwAYq9domU+2rLpg iJVp/O8qftu9T+9cIOSkNmfzznmm5U4T0DfJEOEUmtuSzlfhMlnItIeeIZAIxtlnSmj1 fAEnmV0yHDiOu+RfB9wUm2c1sraLrURDfH02TUFN+kYV/ZrEBhB5wA8+NxQfyofK2/M7 UsidH2e/33fSGygTBUIlaDXGpeawqRGzbYt5iFjUrSfeZ/ECeSi2Vh8jc5VY8Olspx8j lIWQ== X-Gm-Message-State: ABy/qLYrsMY1OZmBpaNlPWMPJXlONrhRs5jhmD6ZwtiT7LZB6e2AiDB8 FgZSUrn3FWFIbf5qq+FY1SoSbyp9dS0k0Yqv X-Google-Smtp-Source: APBJJlFbutT6L4rml+gTbWHiN8ncHVcF6LtvPPIHXQ+IgNKQ+o4+k4iQ8zhsq57OXAtV6O45uHT+og== X-Received: by 2002:a05:6512:b17:b0:4fb:c67e:b067 with SMTP id w23-20020a0565120b1700b004fbc67eb067mr7689109lfu.66.1689604854547; Mon, 17 Jul 2023 07:40:54 -0700 (PDT) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Jan Beulich , Andrew Cooper , Oleksii Kurochko , Bob Eshleman , Alistair Francis , Connor Davis Subject: [PATCH v3 2/3] xen/riscv: introduce function for physical offset calculation Date: Mon, 17 Jul 2023 17:40:49 +0300 Message-ID: X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1689604896995100001 Content-Type: text/plain; charset="utf-8" The function was introduced to calculate and save physical offset before MMU is enabled because access to start() is PC-relative and in case of linker_addr !=3D load_addr it will result in incorrect value in phys_offset. Signed-off-by: Oleksii Kurochko --- Changes in V3: - save/restore of a0/a1 registers before C first function call. --- Changes in V2: - add __ro_after_init for phys_offset variable. - remove double blank lines. - add __init for calc_phys_offset(). - update the commit message. - declaring variable phys_off as non static as it will be used in head.S. --- xen/arch/riscv/include/asm/mm.h | 2 ++ xen/arch/riscv/mm.c | 18 +++++++++++++++--- xen/arch/riscv/riscv64/head.S | 14 ++++++++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/xen/arch/riscv/include/asm/mm.h b/xen/arch/riscv/include/asm/m= m.h index 5e3ac5cde3..d9c4205103 100644 --- a/xen/arch/riscv/include/asm/mm.h +++ b/xen/arch/riscv/include/asm/mm.h @@ -15,4 +15,6 @@ void setup_initial_pagetables(void); void enable_mmu(void); void cont_after_mmu_is_enabled(void); =20 +void calc_phys_offset(void); + #endif /* _ASM_RISCV_MM_H */ diff --git a/xen/arch/riscv/mm.c b/xen/arch/riscv/mm.c index fddb3cd0bd..c84a8a7c3c 100644 --- a/xen/arch/riscv/mm.c +++ b/xen/arch/riscv/mm.c @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0-only */ =20 +#include #include #include #include @@ -19,9 +20,10 @@ struct mmu_desc { pte_t *pgtbl_base; }; =20 -#define PHYS_OFFSET ((unsigned long)_start - XEN_VIRT_START) -#define LOAD_TO_LINK(addr) ((addr) - PHYS_OFFSET) -#define LINK_TO_LOAD(addr) ((addr) + 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) =20 /* * It is expected that Xen won't be more then 2 MB. @@ -273,3 +275,13 @@ void __init noreturn noinline enable_mmu() switch_stack_and_jump((unsigned long)cpu0_boot_stack + STACK_SIZE, cont_after_mmu_is_enabled); } + +/* + * calc_phys_offset() should be used before MMU is enabled because access = to + * start() is PC-relative and in case when load_addr !=3D linker_addr phys= _offset + * will have an incorrect value + */ +void __init calc_phys_offset(void) +{ + phys_offset =3D (unsigned long)start - XEN_VIRT_START; +} diff --git a/xen/arch/riscv/riscv64/head.S b/xen/arch/riscv/riscv64/head.S index 2c0304646a..9015d06233 100644 --- a/xen/arch/riscv/riscv64/head.S +++ b/xen/arch/riscv/riscv64/head.S @@ -29,6 +29,20 @@ ENTRY(start) =20 jal reset_stack =20 + /* + * save hart_id and dtb_base as a0 and a1 register can be used + * by C code ( f.e. setup_initial_pagetables will update a0 and + * a1 ) + */ + mv s0, a0 + mv s1, a1 + + jal calc_phys_offset + + /* restore bootcpu_id and dtb address */ + mv a0, s0 + mv a1, s1 + tail start_xen =20 .section .text, "ax", %progbits --=20 2.41.0