From nobody Sun Dec 22 01:14:06 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=1727708944; cv=none; d=zohomail.com; s=zohoarc; b=QvQjg4dabDWLD+o/h5tsTqlOukrmLIO/rVEUgK+Z5ixU6rwmOl9h9XEvnmS0xSOMoFjIOOc/mtuqGaOVScKAiE0tsmkUYb5Tl2cnuzkCsEjGl/actC77dX9HRT52M2EcHgEP9WKeSnP+ouVBJPHJXMgMtySiZfNXdtsL8lY2t/M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1727708944; 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=OAL8c3GW2uyga/G1EVaDK0Z5EZU/EC3svPKlERObHus=; b=dbUEBdE97B9i85cZ+70Gun9uZUDXd2AhC6kDDuvh92eBLD6dh0b7C8cDEksqFAfiyyjn58MhzM1ZxKs1iVUuv0H0Mm28g8yPROrzQ9vqO53+5Gx54dHuR9S2BL0DgfWhRDD3mNu6ZqGFjJg0ufD4+SIOsJm93UYLJ8lg6mD0fQM= 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 1727708944749827.9269853124076; Mon, 30 Sep 2024 08:09:04 -0700 (PDT) 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 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-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: 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 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1727708946314116600 Content-Type: text/plain; charset="utf-8" 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/a= sm/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 @@ =20 #define IDENT_AREA_SIZE 64 =20 +#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/m= m.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; } =20 -#define virt_to_maddr(va) ({ BUG_ON("unimplemented"); 0; }) +static inline unsigned long virt_to_maddr(unsigned long va) +{ + ASSERT(va >=3D (DIRECTMAP_VIRT_START + DIRECTMAP_SIZE)); + if ((va >=3D DIRECTMAP_VIRT_START) && + (va < (DIRECTMAP_VIRT_START + DIRECTMAP_SIZE))) + return directmapoff_to_maddr(va - DIRECTMAP_VIRT_START); + + BUILD_BUG_ON(XEN_VIRT_SIZE !=3D MB(2)); + ASSERT(((long)va >> (PAGETABLE_ORDER + PAGE_SHIFT)) =3D=3D + ((long)XEN_VIRT_START >> (PAGETABLE_ORDER + PAGE_SHIFT))); + + return phys_offset + va; +} +#define virt_to_maddr(va) virt_to_maddr((unsigned long)(va)) =20 /* 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; }; =20 -static unsigned long __ro_after_init phys_offset; +unsigned long __ro_after_init phys_offset; =20 #define LOAD_TO_LINK(addr) ((unsigned long)(addr) - phys_offset) #define LINK_TO_LOAD(addr) ((unsigned long)(addr) + phys_offset) --=20 2.46.1