From nobody Mon Mar 23 21:28:29 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=1774283437; cv=none; d=zohomail.com; s=zohoarc; b=lH/ozNL2yKSayDLoNW9td5H+ndA9PwQoILQO7qUlE4+Ro1B6qe6R6dLfW79v02WQLD7S1Iajtnmr4aA0BcdkfbV9r+Tq5Y5J5sbVaAb0BqSyRnZBE1/VqVpQSw0Mc4buz08gJuksFNp1ttAAlbZlLm56AMQcJBzc2fqs5F9ogWI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1774283437; 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=4LuRVqlpFi1rpvJNwjCUxIjgt4P93RXegQDELQdKOhc=; b=cAPT1T6kEuX93kjwf+LCyJNGmDPKz1BAhk899KwOuFxaJ1khJ87IeNIcxvn58clR1ChPLCEHwr2o6jYtRJ+D0KHpZbvo43yC4zy8txo5POHeoebTjYYxID+EgSf3cHc0eYkQH0DWzLCMDbAx/+BSiAZrRL4c16QTdsXOWd+kOqw= 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 1774283437311884.7639153245983; Mon, 23 Mar 2026 09:30:37 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1259434.1552744 (Exim 4.92) (envelope-from ) id 1w4iAX-0004tz-Ez; Mon, 23 Mar 2026 16:30:21 +0000 Received: by outflank-mailman (output) from mailman id 1259434.1552744; Mon, 23 Mar 2026 16:30:21 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1w4iAX-0004ts-CC; Mon, 23 Mar 2026 16:30:21 +0000 Received: by outflank-mailman (input) for mailman id 1259434; Mon, 23 Mar 2026 16:30:19 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1w4iAV-0004tJ-M3 for xen-devel@lists.xenproject.org; Mon, 23 Mar 2026 16:30:19 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1w4iAV-009kq3-1e for xen-devel@lists.xenproject.org; Mon, 23 Mar 2026 17:30:19 +0100 Received: from [10.42.69.3] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 69c16a97-bab6-0a2a0a5309dd-0a2a4503b4ec-6 for ; Mon, 23 Mar 2026 17:30:19 +0100 Received: from [209.85.218.51] (helo=mail-ej1-f51.google.com) by tlsNG-33051d.mxtls.expurgate.net with ESMTPS (eXpurgate 4.55.2) (envelope-from ) id 69c16a9a-1947-0a2a45030019-d155da33b922-3 for ; Mon, 23 Mar 2026 17:30:18 +0100 Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-b936331786dso483276166b.3 for ; Mon, 23 Mar 2026 09:30:18 -0700 (PDT) Received: from fedora (user-109-243-69-121.play-internet.pl. [109.243.69.121]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b9832f8be14sm536248166b.17.2026.03.23.09.30.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Mar 2026 09:30:09 -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" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=20230601 header.d=gmail.com header.i="@gmail.com" header.h="Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1774283418; x=1774888218; 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=4LuRVqlpFi1rpvJNwjCUxIjgt4P93RXegQDELQdKOhc=; b=P+/egHRbfmt6nU4zj+dn97cFhaE4jKP/Ca4zPCD+RUKBbeneJeFBCVy+qoTESBGMSJ auf0VJTSte8coVX0LFmk0M2GwbCSE0pKWjpIfZudcEsfkvJwtq7e+vvKHPYRGPdQGCPw 6s9MGBA1anak9WuljlKAGOkO9+RjMvdJ5VmY1M+FSZxeYCK2ALYqu9mz0jJdkIT254gq UFhiMtgn0O/8M1ZkolAtJasc0xHVg+dHS4zfTz2CLuP5M9lfW2ztKVQFpzp54HjxhRPu VGbJTaUzRyJoZQ4eGsQhAbGfO0Ty5gAuyopC7z8XsfRrWG5+VbgmijLBwvllAREMUCQv MZuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774283418; x=1774888218; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=4LuRVqlpFi1rpvJNwjCUxIjgt4P93RXegQDELQdKOhc=; b=hCN3KJcCXUKl3fzBpRMbkfQAPFWZEcQuXx8ifXPxtRX31dphJs+7oXUmz2Nu8bTd+/ Jucp5rxp64l/b6BvjrOehdQKQeEWezPgJ+0mk3TeJ3DDg7ktOiFCaJU2eIXAst9oQ/SP feotIp+vaM6/sdAN+ZGqLojkinAQMbdivz8fmTC9EbF5pHXuUG+ngEbDr7GHmQ9Ds/m8 U1hgaxU1gwVEV5fONgdGsKpoannKkKdpJXZRPzBbFwWex5ltQMMuIxt6zTTtDS5zK0lG kSatX36UYnOQEWhKwWrre5mPhqqPNdgT78REmR5P6dqT2k52ZcDqlu8OWhv08rJtvzbc mKNw== X-Gm-Message-State: AOJu0YzBfUdYk8Ye5HqRFomeRc3x+yPPfKd/sGuFyU4+ILd+EnEixi3n 0rRTl8aaMn5HGsCFHwnfzhaVGK3kZvko+I9PX0ybHYrN2rbw2DvTI0cywdM6kA== X-Gm-Gg: ATEYQzzxd3lypRXP5gVTI7zItD0V586+zulx6g9/XJexak5gb7p18D7Efd11gtGxNDM dKIgrnMbaCYsAToiGT3P2Sk1Jz2xbZDFP7ZNdrHwOGnClL4HjV+fwXmMHJRTKxlwQDdbupwawvY vUgF4iR0KpTvUH2Foq8pWdtT2cxd6g3Ceb1/yvvL0KOGiaWWmhCIyChNBpXlKOauJzaYCaTE8Ts gvlCfIgaQJBATFkMI2fbi3/AzVdNh68Vym84AWmEcvysT4auHXOX3jIAnCZneADA/WZbN8rD7CN L5YZfuP4sH+AlXhOsQcCeYZa5qrnPYY0N3HcLZWz4EFZcv2y3DrQG1JrjQEX6uK6uCmH7boNama Dwfr1eBRsxsVHGiTMWEYxlKj12UEM2otwiYWDyT+eT2Yj0J2+iKFraSw+NNRDyAL8R/tpPJWOIg kZi3/vujRv7JiHa7eUxLYH/24cZNcwYW/YHUoh5gePevGyNGtXmG9LRPmykelsr6k60Q== X-Received: by 2002:a17:907:1c1f:b0:b98:3d79:40c0 with SMTP id a640c23a62f3a-b983d794e9cmr811089066b.12.1774283417745; Mon, 23 Mar 2026 09:30:17 -0700 (PDT) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Romain Caritey , Oleksii Kurochko , Alistair Francis , Connor Davis , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini Subject: [PATCH v2 01/11] xen/riscv: implement get_page_from_gfn() Date: Mon, 23 Mar 2026 17:29:42 +0100 Message-ID: X-Mailer: git-send-email 2.53.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-33051d/1774283419-4A05C72C-5C73FF64/0/0 X-purgate-type: clean X-purgate-size: 3842 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1774283440367154100 Content-Type: text/plain; charset="utf-8" Provide a RISC-V implementation of get_page_from_gfn(), matching the semantics used by other architectures. For translated guests, this is implemented as a wrapper around p2m_get_page_from_gfn(). For DOMID_XEN, which is not auto-translated, provide a 1:1 RAM/MMIO mapping and perform the required validation and reference counting. The function is implemented out-of-line rather than as a static inline, to avoid header ordering issues where struct domain is incomplete when asm/p2m.h is included, leading to build failures: In file included from ./arch/riscv/include/asm/domain.h:10, from ./include/xen/domain.h:16, from ./include/xen/sched.h:11, from ./include/xen/event.h:12, from common/cpu.c:3: ./arch/riscv/include/asm/p2m.h: In function 'get_page_from_gfn': ./arch/riscv/include/asm/p2m.h:50:33: error: invalid use of undefined typ= e 'struct domain' 50 | #define p2m_get_hostp2m(d) (&(d)->arch.p2m) | ^~ ./arch/riscv/include/asm/p2m.h:180:38: note: in expansion of macro 'p2m_g= et_hostp2m' 180 | return p2m_get_page_from_gfn(p2m_get_hostp2m(d), _gfn(gfn= ), t); | ^~~~~~~~~~~~~~~ make[2]: *** [Rules.mk:253: common/cpu.o] Error 1 make[1]: *** [build.mk:72: common] Error 2 make: *** [Makefile:623: xen] Error 2 Signed-off-by: Oleksii Kurochko --- Changes in v2: - Align implemntation with Arm's get_page_from_gfn(). - Update the first comment about DOMID_XEN to mention that isn't "normal" domain instead of no-autotranslated. - Drop footer after commit message. --- xen/arch/riscv/include/asm/p2m.h | 8 ++------ xen/arch/riscv/p2m.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/xen/arch/riscv/include/asm/p2m.h b/xen/arch/riscv/include/asm/= p2m.h index 60f27f9b347e..54ea67990f06 100644 --- a/xen/arch/riscv/include/asm/p2m.h +++ b/xen/arch/riscv/include/asm/p2m.h @@ -164,12 +164,8 @@ typedef unsigned int p2m_query_t; #define P2M_ALLOC (1u<<0) /* Populate PoD and paged-out entries */ #define P2M_UNSHARE (1u<<1) /* Break CoW sharing */ =20 -static inline struct page_info *get_page_from_gfn( - struct domain *d, unsigned long gfn, p2m_type_t *t, p2m_query_t q) -{ - BUG_ON("unimplemented"); - return NULL; -} +struct page_info *get_page_from_gfn(struct domain *d, unsigned long gfn, + p2m_type_t *t, p2m_query_t q); =20 static inline void memory_type_changed(struct domain *d) { diff --git a/xen/arch/riscv/p2m.c b/xen/arch/riscv/p2m.c index 89e5db606fc8..11beaeead5ac 100644 --- a/xen/arch/riscv/p2m.c +++ b/xen/arch/riscv/p2m.c @@ -1534,3 +1534,32 @@ void p2m_handle_vmenter(void) * won't be reused until need_flush is set to true. */ } + +struct page_info *get_page_from_gfn(struct domain *d, unsigned long gfn, + p2m_type_t *t, p2m_query_t q) +{ + struct page_info *page; + p2m_type_t p2mt; + + /* Special case for DOMID_XEN as it isn't "normal" domain */ + if ( likely(d !=3D dom_xen) ) + return p2m_get_page_from_gfn(p2m_get_hostp2m(d), _gfn(gfn), t); + + if ( !t ) + t =3D &p2mt; + + *t =3D p2m_invalid; + + /* DOMID_XEN sees 1-1 RAM. The p2m_type is based on the type of the pa= ge */ + page =3D mfn_to_page(_mfn(gfn)); + + if ( !mfn_valid(_mfn(gfn)) || !get_page(page, d) ) + return NULL; + + if ( page->u.inuse.type_info & PGT_writable_page ) + *t =3D p2m_ram_rw; + else + BUG_ON("unimplemented. p2m_ram_ro hasn't been introduced yet"); + + return page; +} --=20 2.53.0