From nobody Mon Feb 9 10:51:40 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=1691507700; cv=none; d=zohomail.com; s=zohoarc; b=NwGJgfmGsXj7dPBJWtPVycqvdm3kZPqQaLxg534/0Ib91wH5cKNzsKdwJJMZWlvxaqgOeFQwRfcc/QYv8iHtOCYv2AqjD/X7TJb9n6o3SoDgPH5J0NkkD7BFJqMOJjwgPi39hKEgVe0K5MINYDAMfb2ygU43yy54dQRlCyG8YZ4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691507700; 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=XVnapX6pJbuyIiJqPHyIE7upozAeCAUpzwk8pWdYKkk=; b=GLMMMlypPVsxNXBoI/QZkyIuUK/0Fdbh2nfr5m8wPocIiWbIzwPPwO+w46AROawSn4I8uvDzXHsB96jwpJMFHefWYFVoUhAjB3/N1LcMnmxXdGZ02k82WUgyYehe68hQIWp5vaebDpvpg6kJYFWxTfVzuzuNNBfzR/3O+1jc7Xw= 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 1691507700046550.5062001409568; Tue, 8 Aug 2023 08:15:00 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.580030.908295 (Exim 4.92) (envelope-from ) id 1qTOPx-0004k6-FF; Tue, 08 Aug 2023 15:14:41 +0000 Received: by outflank-mailman (output) from mailman id 580030.908295; Tue, 08 Aug 2023 15:14:41 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qTOPx-0004jz-CM; Tue, 08 Aug 2023 15:14:41 +0000 Received: by outflank-mailman (input) for mailman id 580030; Tue, 08 Aug 2023 15:14:39 +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 1qTOPv-0004UR-KT for xen-devel@lists.xenproject.org; Tue, 08 Aug 2023 15:14:39 +0000 Received: from mail-lj1-x22d.google.com (mail-lj1-x22d.google.com [2a00:1450:4864:20::22d]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 4aae772e-35fe-11ee-b280-6b7b168915f2; Tue, 08 Aug 2023 17:14:38 +0200 (CEST) Received: by mail-lj1-x22d.google.com with SMTP id 38308e7fff4ca-2b9e6cc93c6so88864971fa.2 for ; Tue, 08 Aug 2023 08:14:38 -0700 (PDT) Received: from fedora.. ([94.75.70.14]) by smtp.gmail.com with ESMTPSA id i19-20020a2e8093000000b002ba053e1f9bsm2319794ljg.35.2023.08.08.08.14.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Aug 2023 08:14:37 -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: 4aae772e-35fe-11ee-b280-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691507678; x=1692112478; 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=XVnapX6pJbuyIiJqPHyIE7upozAeCAUpzwk8pWdYKkk=; b=F45IcP//lDRI8/cXxnZYlW9HKIKiVcS2qrf7XQdv3kUb2RmiOD1XLwunLcM85kSwW5 ECWtqCGXl8lIjZmkNXmH9oEHNoQyjG4rcNGXW0QxQgjEeZQo7EmQ19b2zzSTIb60ZBnU rQMG/Fhc4InsAfAOTk0aHj8NBvSCOw1O6gjk+zyLU+X11suCjrAg4IzVYcZMr9Axq9WG 5oUYOOZoiDFSTmZddXXMtqoQF9KjGl/h0G/AMjmPFd+IlmMyXB39EOgGQ4vsTzFtVRZ+ Qz/BiEPrIdg8cv15AyvlunAxWxHX5/uUFU9xm39qNjMxVM1sHhHcukLBtpe7qrMSAlBi AFRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691507678; x=1692112478; 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=XVnapX6pJbuyIiJqPHyIE7upozAeCAUpzwk8pWdYKkk=; b=dUPcnWPXYClKV3RsBheJ/znN/r9krvUIRwEDdsWrI728o9FjjVkU0feYctjqXVU1v9 XmWkYER54km05OdPCN2XAsxqYLCcxJlkPWn0WYnyaY5UXEoAR1pptKIwG213u+mqH18F rn/SkyybyRZqZiCHyEVJSanrdHdO8bUXyP1GlIDHnZkhQeoKxOgB/dOr596gQkX7Rren rO7Jrl0CWPnxsWmXtQ8nXyJzXWyMvte+rO/zyCFszZnjtOYTiLiHnf6MqRlBsHNwzAbB 9IOXeHJNED3HCrDUg3/qkm5rl8vr+fTnFY9v2XCw47+avmU1EYujKuPzpRkhOKX22ywD ivBQ== X-Gm-Message-State: AOJu0YwUhfNzwZRkMcQcdkkIsVoZiM6fVCWAbZ/Rmpx+EJtOaV8IVVGj OUjPrNPRUN8CggVUkhfU2CEwlya7e2I= X-Google-Smtp-Source: AGHT+IFzCBnt4pdAkSiRqtYmX3q6Mntbuz8yqFz0Mml4QXcR3rKhYsF3I0dAe5a/yBsW7Ovkm7ENOw== X-Received: by 2002:a2e:6a11:0:b0:2b6:a6e7:5afa with SMTP id f17-20020a2e6a11000000b002b6a6e75afamr8817605ljc.12.1691507677614; Tue, 08 Aug 2023 08:14:37 -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 v7 1/2] xen/riscv: introduce function for physical offset calculation Date: Tue, 8 Aug 2023 18:14:33 +0300 Message-ID: <53d4251e79c5b4effb3a077d1b102c57ed1a10b3.1691507564.git.oleksii.kurochko@gmail.com> 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: 1691507822306100001 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 V7: - nothing changed. only rebase --- Changes in V6: - After 9380f06fe8("xen: Drop the (almost) unused extern start[]") an update of calc_phys_offset() was needed: - change start to _start. - add local volatile variable load_start to get properly Xens' load addr= ess. Otherwise compile thinks that (start - XEN_VIRT_START) is equal to 0. --- Changes in V5: - update prototype of calc_phys_offset(). now it returns phys_offset. - declare phys_offset as static. - save returned value of calc_phys_offset to register s2. --- Changes in V4: - update the comment messages in head.S related to save/restore of a0/a1 r= egs. --- 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 | 21 ++++++++++++++++++--- xen/arch/riscv/riscv64/head.S | 14 ++++++++++++++ 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/xen/arch/riscv/include/asm/mm.h b/xen/arch/riscv/include/asm/m= m.h index 5e3ac5cde3..7b94cbadd7 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 +unsigned long calc_phys_offset(void); + #endif /* _ASM_RISCV_MM_H */ diff --git a/xen/arch/riscv/mm.c b/xen/arch/riscv/mm.c index 99ed5e9623..a73f135a3c 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) +static 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,16 @@ 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 + */ +unsigned long __init calc_phys_offset(void) +{ + volatile unsigned long load_start =3D (unsigned long)_start; + + phys_offset =3D load_start - XEN_VIRT_START; + return phys_offset; +} diff --git a/xen/arch/riscv/riscv64/head.S b/xen/arch/riscv/riscv64/head.S index 2c0304646a..ae194bb099 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 ( bootcpu_id ) and dtb_base as a0 and a1 register = can + * be used by C code + */ + mv s0, a0 + mv s1, a1 + + jal calc_phys_offset + mv s2, a0 + + /* restore hart_id ( bootcpu_id ) and dtb address */ + mv a0, s0 + mv a1, s1 + tail start_xen =20 .section .text, "ax", %progbits --=20 2.41.0