From nobody Sun Dec 29 01:14:48 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=1734453210; cv=none; d=zohomail.com; s=zohoarc; b=JmEriNq+uCMmIyJfVjRIjk5C4JVzZKOB/kj5GtuJo57vSme4pYXea9apXzRYxU/FIOvll86z0z+2JaS8xQ91kr2qGijAskq3iTmBHi7n/fB9BhXr+wUaaAziAa4L3nzZY/TzFqnSsgf7XWgVmlH6ejpbmHZYZDG/MJ3KT0LiWpc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1734453210; 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=8zJCydD52IvfuBY2R8KEd3EZvy2mjVloYZmx2VGVw6o=; b=lXH5sR8tzNE3zfR/KCpn64o3Dkes6F8rsRmdV3jlG7hwfAy49C1YF/0hBG/OylJgVw1I5WVifFHVzh+AqYuZ6y2YjJ3sz37f3CP2ieJrackF0WOhuRPB3xjRwoNwaoSjkM6PSRi2khGLlqYgo616830Zn0mrZTdiCiuTfKlCL4w= 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 1734453210710260.58134690083523; Tue, 17 Dec 2024 08:33:30 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.859440.1271609 (Exim 4.92) (envelope-from ) id 1tNaVM-0002Pr-Nl; Tue, 17 Dec 2024 16:33:04 +0000 Received: by outflank-mailman (output) from mailman id 859440.1271609; Tue, 17 Dec 2024 16:33:04 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tNaVM-0002Oh-Hx; Tue, 17 Dec 2024 16:33:04 +0000 Received: by outflank-mailman (input) for mailman id 859440; Tue, 17 Dec 2024 16:33:03 +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 1tNaVL-0001JJ-SL for xen-devel@lists.xenproject.org; Tue, 17 Dec 2024 16:33:03 +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 95d0d1b0-bc94-11ef-a0d6-8be0dac302b0; Tue, 17 Dec 2024 17:33:02 +0100 (CET) Received: by mail-lj1-x22d.google.com with SMTP id 38308e7fff4ca-3003e203acaso52209231fa.1 for ; Tue, 17 Dec 2024 08:33:02 -0800 (PST) Received: from fedora.. ([94.75.70.14]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-30344175b51sm13179021fa.69.2024.12.17.08.33.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Dec 2024 08:33:01 -0800 (PST) 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: 95d0d1b0-bc94-11ef-a0d6-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734453182; x=1735057982; 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=8zJCydD52IvfuBY2R8KEd3EZvy2mjVloYZmx2VGVw6o=; b=fYCxt9PuTSXdm2ieCmnG7j8tTmCF+vL5P5UQYnz/TuejqawGQe4QKLE9/pSHAXkPdq dhOGFAGA9wTE2lYyxGXYrygA+qKgAT5orE5erkRJHosyLXPUs9DHx9IfQHrbRp0pLaLm rluM+SrD6LiLtB0Y8yaqqxG7U/P4dUCy6E04/HrECk0J3f3nF1dn5mPQACHZpvQACMQ2 aWROD8hTsS9elOJe+iiG3mTauUPLrxfeW1+QKTDFBLsgGxPJEyomEejpD0uiYqcLAOq3 OLBj+x1tG59alVcq9RpNpdem2guXi9VMqs8ghKYOmrFjMWQZLagxYGmA8ty0pHL4dUql GF4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734453182; x=1735057982; 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=8zJCydD52IvfuBY2R8KEd3EZvy2mjVloYZmx2VGVw6o=; b=KAuVcuhJPPz3+v+DnZVeKJHU/AmtPRwbs2/BVHm60StR5HhAbInZgBOAihkyHos0F9 TxAmZhUVaczvgX8DoIE0lZXfS0E0Jv9JxbLzV2bEyp1o6iCpepOrWbr2BhLtKW2QJ9GB Y//by6ozDmqLqEiArF9yRK9IN2orFs/k57Hk3nk2NT/oh1guv85LF+Zysh0FF4InGLOj Mru2KALbr88ZfQupZc6RWqeLxFC9/orQfjZ7ZRYH2dEfeFiL8QkoMQu0osU7RGrEzp27 mkZUXmVsJLh5COrxYNoDWbTKmx973aG9UMx0t0SW4A2OTtZnOXC54RK89m2/+sLhXtfO VpzA== X-Gm-Message-State: AOJu0Yw6K3U/Z1Q1Llkj0mKYls30FKECtP4XOPzrrU4DIqnA4zJMtokm t9iUT2cpqOb3sx6cUYRy7/44wAflNTx6jDkUzqAhLJqq8a+Afrt77ZjDFlLj X-Gm-Gg: ASbGncvNZPUKPV0+gZt1YESqnAPHgQXjDDQNaIvVEAAafASannXXNzlSgKVhVfHiAUD 6J9Hm3f9EbUIA6gQuX9HY1hzwDo+kIk4z4fIkE5FWV2ZtuCh1CYm0IINxduvq5yzBoveImLadI5 4ymTtRsrJI5g8NEfQbJaBqjipTmnprhZhjrjESKPgWG0Uw6tKITeOtmL1vZHYLC/txE/QkNKQ+o 5YRW1DL5X55dIbQCRsnTQuHP7iPjjQfrZfg5NfPwPr7WzMoZOURpGCqJQ== X-Google-Smtp-Source: AGHT+IF/ywl5xmKCF/65QK9oCKKp8PnV+GsZVobG5aeoL61ppmef5h+bMXlo/IeRwhN0Kd+YKjaK8A== X-Received: by 2002:a2e:a541:0:b0:300:15f1:cd5c with SMTP id 38308e7fff4ca-3044d063c32mr479601fa.17.1734453181771; Tue, 17 Dec 2024 08:33:01 -0800 (PST) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Oleksii Kurochko , Alistair Francis , Bob Eshleman , Connor Davis , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini Subject: [PATCH v3 6/7] xen/riscv: implement prereq for DTB relocation Date: Tue, 17 Dec 2024 17:32:50 +0100 Message-ID: <79b7e0a4938e4be1f37d209ce01c859e5c208429.1734452721.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1734453211341116600 Content-Type: text/plain; charset="utf-8" DTB relocatin in Xen heap requires the following functions which are introduced in current patch: - xvmalloc_array() - copy_from_paddr() For internal use of xvmalloc, the functions flush_page_to_ram() and virt_to_page() are introduced. virt_to_page() is also required for free_xenheap_pages(). Signed-off-by: Oleksii Kurochko Acked-by: Jan Beulich --- Changes in V3: - Rewrite part of flush_page_to_ram() to use BUG() instead of BUG_ON(). - Add Acked-by: Jan Beulich . --- Changes in V2: - Drop variable directmap_virt_end. - Update ASSERT in virt_to_page() to use DIRECTMAP_VIRT_END instead of variable directmap_virt_end. - Declare local varibale v as const inside flush_page_to_ram(). - Declare copy_from_paddr() in riscv/setup.h as in the future it will be used for copying kernel in guest memory. - Code style updates for copy_from_paddr(). - Make l and s variable in copy_from_paddr() as the virables' initializers. - Drop call of clean_dcache_va_range(dst, l) in copy_from_paddr() as the necessiry of it is Arm-specific: After memcpy'ing the kernel in guest memory Arm need to flush the dcac= he to make sure that the data actually reaches the memory before we start executing guest code with caches disabled. RISC-V has caches always enabled thereby there is no such issue for RISC= -V. - Make local variable src in copy_from_paddr() as const. - Update the commit message and subject: drop information of relocate_fdt() introduction and rename it to "prereq for DTB relocation". - Add BUG_ON() inside flush_page_to_ram() to check the return value of clean_and_invalidate_dcache_va_range(). - Move relocate_fdt() introduction to the next patch to make this patch compilable. --- xen/arch/riscv/include/asm/mm.h | 8 ++++++-- xen/arch/riscv/include/asm/page.h | 12 ++++++++++-- xen/arch/riscv/include/asm/setup.h | 4 ++++ xen/arch/riscv/setup.c | 26 ++++++++++++++++++++++++++ 4 files changed, 46 insertions(+), 4 deletions(-) diff --git a/xen/arch/riscv/include/asm/mm.h b/xen/arch/riscv/include/asm/m= m.h index 699ed23f0d..292aa48fc1 100644 --- a/xen/arch/riscv/include/asm/mm.h +++ b/xen/arch/riscv/include/asm/mm.h @@ -8,6 +8,7 @@ #include #include #include +#include #include =20 #include @@ -148,8 +149,11 @@ static inline void *page_to_virt(const struct page_inf= o *pg) /* Convert between Xen-heap virtual addresses and page-info structures. */ static inline struct page_info *virt_to_page(const void *v) { - BUG_ON("unimplemented"); - return NULL; + unsigned long va =3D (unsigned long)v; + + ASSERT((va >=3D DIRECTMAP_VIRT_START) && (va <=3D DIRECTMAP_VIRT_END)); + + return frametable_virt_start + PFN_DOWN(va - directmap_virt_start); } =20 /* diff --git a/xen/arch/riscv/include/asm/page.h b/xen/arch/riscv/include/asm= /page.h index c82432dc67..a1d54c7fb1 100644 --- a/xen/arch/riscv/include/asm/page.h +++ b/xen/arch/riscv/include/asm/page.h @@ -7,6 +7,7 @@ =20 #include #include +#include #include #include =20 @@ -176,10 +177,17 @@ static inline void invalidate_icache(void) #define clear_page(page) memset((void *)(page), 0, PAGE_SIZE) #define copy_page(dp, sp) memcpy(dp, sp, PAGE_SIZE) =20 -/* TODO: Flush the dcache for an entire page. */ static inline void flush_page_to_ram(unsigned long mfn, bool sync_icache) { - BUG_ON("unimplemented"); + const void *v =3D map_domain_page(_mfn(mfn)); + + if ( clean_and_invalidate_dcache_va_range(v, PAGE_SIZE) ) + BUG(); + + unmap_domain_page(v); + + if ( sync_icache ) + invalidate_icache(); } =20 /* Write a pagetable entry. */ diff --git a/xen/arch/riscv/include/asm/setup.h b/xen/arch/riscv/include/as= m/setup.h index 844a2f0ef1..c9d69cdf51 100644 --- a/xen/arch/riscv/include/asm/setup.h +++ b/xen/arch/riscv/include/asm/setup.h @@ -3,10 +3,14 @@ #ifndef ASM__RISCV__SETUP_H #define ASM__RISCV__SETUP_H =20 +#include + #define max_init_domid (0) =20 void setup_mm(void); =20 +void copy_from_paddr(void *dst, paddr_t paddr, unsigned long len); + #endif /* ASM__RISCV__SETUP_H */ =20 /* diff --git a/xen/arch/riscv/setup.c b/xen/arch/riscv/setup.c index 9680332fee..bea3f27c4d 100644 --- a/xen/arch/riscv/setup.c +++ b/xen/arch/riscv/setup.c @@ -12,6 +12,7 @@ #include =20 #include +#include #include #include #include @@ -26,6 +27,31 @@ void arch_get_xen_caps(xen_capabilities_info_t *info) unsigned char __initdata cpu0_boot_stack[STACK_SIZE] __aligned(STACK_SIZE); =20 +/** + * copy_from_paddr - copy data from a physical address + * @dst: destination virtual address + * @paddr: source physical address + * @len: length to copy + */ +void __init copy_from_paddr(void *dst, paddr_t paddr, unsigned long len) +{ + const void *src =3D (void *)FIXMAP_ADDR(FIX_MISC); + + while ( len ) + { + unsigned long s =3D paddr & (PAGE_SIZE - 1); + unsigned long l =3D min(PAGE_SIZE - s, len); + + set_fixmap(FIX_MISC, maddr_to_mfn(paddr), PAGE_HYPERVISOR_RW); + memcpy(dst, src + s, l); + clear_fixmap(FIX_MISC); + + paddr +=3D l; + dst +=3D l; + len -=3D l; + } +} + void __init noreturn start_xen(unsigned long bootcpu_id, paddr_t dtb_addr) { --=20 2.47.1