From patchwork Wed Oct 16 09:15:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksii Kurochko X-Patchwork-Id: 13837961 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E665AD1AD30 for ; Wed, 16 Oct 2024 09:16:19 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.819722.1233146 (Exim 4.92) (envelope-from ) id 1t108T-00055m-TU; Wed, 16 Oct 2024 09:16:05 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 819722.1233146; Wed, 16 Oct 2024 09:16:05 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t108T-00055e-PK; Wed, 16 Oct 2024 09:16:05 +0000 Received: by outflank-mailman (input) for mailman id 819722; Wed, 16 Oct 2024 09:16:05 +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 1t108S-0004r9-UK for xen-devel@lists.xenproject.org; Wed, 16 Oct 2024 09:16:04 +0000 Received: from mail-lj1-x231.google.com (mail-lj1-x231.google.com [2a00:1450:4864:20::231]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 44274d92-8b9f-11ef-99a3-01e77a169b0f; Wed, 16 Oct 2024 11:16:03 +0200 (CEST) Received: by mail-lj1-x231.google.com with SMTP id 38308e7fff4ca-2fb59652cb9so22534091fa.3 for ; Wed, 16 Oct 2024 02:16:03 -0700 (PDT) Received: from fedora.. ([94.75.70.14]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53a000129eesm391451e87.259.2024.10.16.02.16.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Oct 2024 02:16:00 -0700 (PDT) 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: 44274d92-8b9f-11ef-99a3-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729070161; x=1729674961; 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=FUi2WJJTrylVj2kHi62rhC3wT5w2qKiq8sfSJLHijNw=; b=OLfcMp6jd2wJO/AI0zZN8EKwpcGZWnN91cXbiVSQurhvxjfxfoHL5Zw61726NK1cnf Sy70v2dmbMhH+hBvctyKPi+WLd6B2e83TF/yQOOMYpBYwRQ4e/iTucHubSeFDbNFe//+ 9mz1Wk2Vuag+Xv7Ry4c5r+h2z4qoJB7eUck/9vN5YDjKaeEY6x8aK72NQINoc8hZNgd/ Bgry8MDOGjilT7nHrDtaXsmzJyKJwTfDvJcUE6Tw/iLJ5XEE82AUDB5lv97j9ICys0wv GPdeHtjlLZxGWGFjNF7H5nE6PhothGPUAh4277Epf2jv0CvwUe8xj8H3EHJhklOr0eEW 4bIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729070161; x=1729674961; 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=FUi2WJJTrylVj2kHi62rhC3wT5w2qKiq8sfSJLHijNw=; b=oeq0c166YrWarczeVLbMAhyN3hS0oMsx09nCFlMQYTU1J1+vBvQitusJ/vXNVGYE88 dWvrguzlKTNNPdmoBVdRDOW8QIyxfIrJ/9lRI2aQ2QpXM6F3dcUcCxzidq6x0pjjf1OG Np+5fkpO8vV1G9wUFyc98GxjlWdyXNctLwmeaHLYc99xeZZcNeBJAxJq4PJ+RVfGGhS6 3hMya0lb+b00Ubg7nUMcXGjvo5efB2ZmgROtw1lxeUH1EtVTPEI2edZ6vvGznGHZ8ggx x8ZGPJXHjEsw7yU6dfI9eY8Q1oNrA2v7LW4d0TKYYZ8uMzQ4GT6Gr+MWAuH0aXnVHJqm AyZQ== X-Gm-Message-State: AOJu0YwDPq8CCLz9ftLrWSZF7MgS5RKMCnoFMO9+sbrh0IbvFyScmLWW npKS42OY1L+ZINMcQfsoZP7VTZxmYihS8obMxvxCZTzC8RHC538Hw2Qbmw== X-Google-Smtp-Source: AGHT+IER3QcgvTjxn2/fyXoLjy8xB7tf/OJVdzSVEvhg72jqpoBa/NoQ/kGK1cJewxHeYkXQQOSFOg== X-Received: by 2002:a05:6512:6d2:b0:539:f4c1:71d3 with SMTP id 2adb3069b0e04-539f4c17406mr6039710e87.29.1729070161226; Wed, 16 Oct 2024 02:16:01 -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/5] xen/riscv: add stub for share_xen_page_with_guest() Date: Wed, 16 Oct 2024 11:15:53 +0200 Message-ID: <3dfd4bdf6584e73ecdbff5a66fdbaec68e31cc3c.1729068334.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: MIME-Version: 1.0 To avoid the following linkage fail the stub for share_xen_page_with_guest() is introduced: riscv64-linux-gnu-ld: prelink.o: in function `tasklet_kill': /build/xen/common/tasklet.c:176: undefined reference to `share_xen_page_with_guest' riscv64-linux-gnu-ld: ./.xen-syms.0: hidden symbol `share_xen_page_with_guest' isn't defined riscv64-linux-gnu-ld: final link failed: bad value $ find . -name \*.o | while read F; do nm $F | grep share_xen_page_with_guest && echo $F; done U share_xen_page_with_guest ./xen/common/built_in.o U share_xen_page_with_guest ./xen/common/trace.o U share_xen_page_with_guest ./xen/prelink.o Despite the linker fingering tasklet.c (very likely a toolchain bug), it's trace.o which has the undefined reference. Looking at trace.i, there is call of share_xen_page_with_guest() in share_xen_page_with_privileged_guests() from asm/mm.h. Signed-off-by: Oleksii Kurochko --- xen/arch/riscv/stubs.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/xen/arch/riscv/stubs.c b/xen/arch/riscv/stubs.c index 5951b0ce91..c9a590b225 100644 --- a/xen/arch/riscv/stubs.c +++ b/xen/arch/riscv/stubs.c @@ -2,7 +2,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -409,3 +411,11 @@ unsigned long get_upper_mfn_bound(void) { BUG_ON("unimplemented"); } + +/* mm.c */ + +void share_xen_page_with_guest(struct page_info *page, struct domain *d, + enum XENSHARE_flags flags) +{ + BUG_ON("unimplemented"); +} From patchwork Wed Oct 16 09:15:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksii Kurochko X-Patchwork-Id: 13837962 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C089DD1AD32 for ; Wed, 16 Oct 2024 09:16:21 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.819723.1233156 (Exim 4.92) (envelope-from ) id 1t108V-0005La-6O; Wed, 16 Oct 2024 09:16:07 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 819723.1233156; Wed, 16 Oct 2024 09:16:07 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t108V-0005LR-3f; Wed, 16 Oct 2024 09:16:07 +0000 Received: by outflank-mailman (input) for mailman id 819723; Wed, 16 Oct 2024 09:16:05 +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 1t108T-0004r9-L4 for xen-devel@lists.xenproject.org; Wed, 16 Oct 2024 09:16:05 +0000 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [2a00:1450:4864:20::136]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 44c55a29-8b9f-11ef-99a3-01e77a169b0f; Wed, 16 Oct 2024 11:16:04 +0200 (CEST) Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-539f2b95775so4121713e87.1 for ; Wed, 16 Oct 2024 02:16:04 -0700 (PDT) Received: from fedora.. ([94.75.70.14]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53a000129eesm391451e87.259.2024.10.16.02.16.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Oct 2024 02:16:01 -0700 (PDT) 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: 44c55a29-8b9f-11ef-99a3-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729070163; x=1729674963; 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=zTo8wcoBAnZWVL6JY0i7rOCMbKVxaD9bONOTGNKU9j0=; b=C2cAA6GZr+IRir0BpoKtgIeq9vxBXkASqUuKhHDfWjUW8xpbf619sAIPRX4oh8aQwo 38y9neezO0KcnrmiYbsdzWYwGPLyflyoXBF5KA7UYO1PR/S23nvfBk36kyEiNwYdQWh/ JSKplRCW3zR7e7wOP6Og9tUsK81Jv0RFlmQFObHr/KAoXFF8jYZU5nJJkZSX/FGIQg2+ lG53A0YXTeEipLzj+OsIBbZllTCt1IWTf5rDEL3hDNeKz+5vNT3470/YO3CLzgYZvMFr NODx42L/ojBUgAzrIuzV6jLiTVwoafclyRPd33jtoUyohtW96BiEA/gKcXHG3iI3I30Y V7jQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729070163; x=1729674963; 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=zTo8wcoBAnZWVL6JY0i7rOCMbKVxaD9bONOTGNKU9j0=; b=XT/4qknI1gm3xEKUVyk+OpybGkd5ydNMUH8FtXa1plRe7z3PQGgHTp6/RAOa11nn9r PC5qkS9fftJeMTSwyNmcLZihPh1RY0TKOXN/zAur36sKE/Hblwn3cLaiiqqthbLVJf3U sKN4R4QKdBKy/GjwbE2u9HIwRUrBxUpMaYLSDnrSRbDUJPsxKHCtPdz6Nvf7Q1rtjlDk Vv1J2MUKFPCMOt1XmpXwhGyTpzzfeob2HwqFLjMDjGHlEv2oK4JY5AlLueaovrhlP9hl pu5ZZW9eZcN0dI4lU+2qw5w+PJXYbpoL0sHxSCyS0Afh4sXcVKrZSYOJy3h6ZIs46cS0 KuKw== X-Gm-Message-State: AOJu0YyMwYuZLlm8h9KPXsGtAOaauTYrTf9YU72o4YWBK8dZgCK//cLq pot3rcidG8vs96ld7g7bT5DpFueTHHG5IWIEUFdOKrx5v7g86Mke0Z5otA== X-Google-Smtp-Source: AGHT+IGiD8tLBcbs6M/QvfKxQOuo5Zgnq6pEzPkd4C4CIXLglaZ+oIXatCYihqviEWs7KjcKGIUlFA== X-Received: by 2002:a05:6512:220d:b0:539:8a50:6ee8 with SMTP id 2adb3069b0e04-539e57282b1mr9234525e87.57.1729070163190; Wed, 16 Oct 2024 02:16:03 -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 2/5] xen/riscv: implement maddr_to_virt() Date: Wed, 16 Oct 2024 11:15:54 +0200 Message-ID: X-Mailer: git-send-email 2.47.0 In-Reply-To: References: MIME-Version: 1.0 Implement the `maddr_to_virt()` function to convert a machine address to a virtual address. This function is specifically designed to be used only for the DIRECTMAP region, so a check has been added to ensure that the address does not exceed `DIRECTMAP_SIZE`. Signed-off-by: Oleksii Kurochko --- xen/arch/riscv/include/asm/mm.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/xen/arch/riscv/include/asm/mm.h b/xen/arch/riscv/include/asm/mm.h index ebb142502e..0396e66f47 100644 --- a/xen/arch/riscv/include/asm/mm.h +++ b/xen/arch/riscv/include/asm/mm.h @@ -25,8 +25,12 @@ static inline void *maddr_to_virt(paddr_t ma) { - BUG_ON("unimplemented"); - return NULL; + /* Offset in the direct map, accounting for pdx compression */ + unsigned long va_offset = maddr_to_directmapoff(ma); + + ASSERT(va_offset < DIRECTMAP_SIZE); + + return (void *)(DIRECTMAP_VIRT_START + va_offset); } /* From patchwork Wed Oct 16 09:15:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksii Kurochko X-Patchwork-Id: 13837960 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 41411D1AD30 for ; Wed, 16 Oct 2024 09:16:16 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.819724.1233166 (Exim 4.92) (envelope-from ) id 1t108W-0005bX-FM; Wed, 16 Oct 2024 09:16:08 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 819724.1233166; Wed, 16 Oct 2024 09:16:08 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t108W-0005bD-AV; Wed, 16 Oct 2024 09:16:08 +0000 Received: by outflank-mailman (input) for mailman id 819724; Wed, 16 Oct 2024 09:16:06 +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 1t108U-0005Dr-K1 for xen-devel@lists.xenproject.org; Wed, 16 Oct 2024 09:16:06 +0000 Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [2a00:1450:4864:20::12a]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 458c7379-8b9f-11ef-a0be-8be0dac302b0; Wed, 16 Oct 2024 11:16:05 +0200 (CEST) Received: by mail-lf1-x12a.google.com with SMTP id 2adb3069b0e04-539f76a6f0dso2882761e87.1 for ; Wed, 16 Oct 2024 02:16:05 -0700 (PDT) Received: from fedora.. ([94.75.70.14]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53a000129eesm391451e87.259.2024.10.16.02.16.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Oct 2024 02:16:03 -0700 (PDT) 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: 458c7379-8b9f-11ef-a0be-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729070165; x=1729674965; 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=fGuFYCXwauYG/Y17jk3tmaCDchtBJlytkAwIlTZfzko=; b=Wbrq0EcMkiODkwUFRkqGJwOY180q+enFGkXV7OzyML3HclgAY5NGw1kCm74rZIqTau 3Grqu61S0+I3JJD9JiW0LWQroJ7hYJOQDVWA1QiTEQ/sZ0ZccPnpy+Um6+jckrQHyM2n oep4MykeDfgaioDDDb66TvYr4TbbI2mwXHfQEqIQgZek47Q7pV2eXvtq0PnU9SgyPqsE FsigDQ8CoUdMExA1GhoBnmXQONOTxhCgx0Ub/kTsUircqdz6F0NRcbyxxI++lx3TAumr 7nsKNCurpCYdZgKVPedhkG259QpUqV0J4mlb2Msth9I4o4YRYl1XyyhZptmIe6gNtDM3 yKcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729070165; x=1729674965; 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=fGuFYCXwauYG/Y17jk3tmaCDchtBJlytkAwIlTZfzko=; b=isMRpWokANn5nQRtSPzry1+/x94aBQhT5C0FsGmBjdp6upqIdEdLETvU0tCOz8RAyQ coTfqDJ+/Jpx5dfYrFeMzgqgoyvU1l1/MnM406uRt+Gkxs7DK4OEwq3X1cDSwL0+JZhl 5uSqjEXZTMngtKNfWh+m2eGZB5sLAFkCcuBGCH1rURnGdz9KO1xPLshLnYmsuu383h2U j54Sd9g9/RPJuAfNPFWjKYOm2GpoYHEbBZPquaNBdm6likpnORUanftWFknDXbm2JwAZ zr1WN25IQ8IYogV5daXCiC3HmLmrarLonOv6TllWcpiTU2dxkJVoo5F1N4EcAzz8JRX9 6iWg== X-Gm-Message-State: AOJu0YxvRilVtNzj0q5QEKGQWbhTVj3L0evMxo4MfEFr1vP0IDUURAs/ 9gcxUiHI4QKuO0kJxh+fUcsyoRVkmRCWGkK/RS1BpLiy4qdNONIE4WIAOQ== X-Google-Smtp-Source: AGHT+IHZkUCj21Y7l52VIWLe416ZSMs2Ro+dERhPbC13frSrZPSSU46sMhzh1iRQsImnvC/Xb+KtPg== X-Received: by 2002:a05:6512:e9c:b0:539:f807:ad93 with SMTP id 2adb3069b0e04-539f807caf1mr5086745e87.38.1729070164430; Wed, 16 Oct 2024 02:16:04 -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 3/5] xen/riscv: introduce setup_mm() Date: Wed, 16 Oct 2024 11:15:55 +0200 Message-ID: <300a4a5911766d42ec01c3fcaee664d72b484296.1729068334.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: MIME-Version: 1.0 Introduce the implementation of setup_mm(), which includes: 1. Adding all free regions to the boot allocator, as memory is needed to allocate page tables used for frame table mapping. 2. Calculating RAM size and the RAM end address. 3. Setting up direct map mappings from the PFN of physical address 0 to the PFN of RAM end. 4. Setting up frame table mappings from physical address 0 to ram_end. 5. Setting up total_pages and max_page. 6. Establishing `directmap_virt_end`, which is not currently used but is intended for future use in virt_to_page() to ensure that virtual addresses do not exceed directmap_virt_end. In the case of RISC-V 64, which has a large virtual address space (the minimum supported MMU mode is Sv39, providing TB of VA space), the direct map and frame table are mapped starting from physical address 0. This simplifies the calculations and thereby improves performance for page_to_mfn(), mfn_to_page(), and maddr_to_virt(), as there is no need to account for {directmap, frametable}_base_pdx. Signed-off-by: Oleksii Kurochko --- xen/arch/riscv/include/asm/mm.h | 2 + xen/arch/riscv/include/asm/setup.h | 2 + xen/arch/riscv/mm.c | 93 ++++++++++++++++++++++++++++++ xen/arch/riscv/setup.c | 3 + 4 files changed, 100 insertions(+) diff --git a/xen/arch/riscv/include/asm/mm.h b/xen/arch/riscv/include/asm/mm.h index 0396e66f47..7b472220e5 100644 --- a/xen/arch/riscv/include/asm/mm.h +++ b/xen/arch/riscv/include/asm/mm.h @@ -12,6 +12,8 @@ #include +extern vaddr_t directmap_virt_end; + #define pfn_to_paddr(pfn) ((paddr_t)(pfn) << PAGE_SHIFT) #define paddr_to_pfn(pa) ((unsigned long)((pa) >> PAGE_SHIFT)) diff --git a/xen/arch/riscv/include/asm/setup.h b/xen/arch/riscv/include/asm/setup.h index c0214a9bf2..844a2f0ef1 100644 --- a/xen/arch/riscv/include/asm/setup.h +++ b/xen/arch/riscv/include/asm/setup.h @@ -5,6 +5,8 @@ #define max_init_domid (0) +void setup_mm(void); + #endif /* ASM__RISCV__SETUP_H */ /* diff --git a/xen/arch/riscv/mm.c b/xen/arch/riscv/mm.c index 27026d803b..53b7483f75 100644 --- a/xen/arch/riscv/mm.c +++ b/xen/arch/riscv/mm.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -423,3 +424,95 @@ void * __init early_fdt_map(paddr_t fdt_paddr) return fdt_virt; } + +#ifndef CONFIG_RISCV_32 +/* Map the region in the directmap area. */ +static void __init setup_directmap_mappings(unsigned long nr_mfns) +{ + if ( nr_mfns > PFN_DOWN(DIRECTMAP_SIZE) ) + panic("The directmap cannot cover the physical region %#"PRIpaddr" - %#"PRIpaddr"\n", + 0UL, nr_mfns << PAGE_SHIFT); + + if ( map_pages_to_xen((vaddr_t)mfn_to_virt(0), + _mfn(0), nr_mfns, + PAGE_HYPERVISOR_RW) ) + panic("Unable to setup the directmap mappings.\n"); +} + +/* Map a frame table to cover physical addresses ps through pe */ +static void __init setup_frametable_mappings(paddr_t ps, paddr_t pe) +{ + unsigned long nr_mfns = mfn_x(mfn_add(maddr_to_mfn(pe), -1)) - + mfn_x(maddr_to_mfn(ps)) + 1; + unsigned long frametable_size = nr_mfns * sizeof(struct page_info); + mfn_t base_mfn; + + if ( frametable_size > FRAMETABLE_SIZE ) + panic("The frametable cannot cover the physical region %#"PRIpaddr" - %#"PRIpaddr"\n", + ps, pe); + + frametable_size = ROUNDUP(frametable_size, MB(2)); + base_mfn = alloc_boot_pages(frametable_size >> PAGE_SHIFT, 2<<(20-12)); + + if ( map_pages_to_xen(FRAMETABLE_VIRT_START, base_mfn, + frametable_size >> PAGE_SHIFT, + PAGE_HYPERVISOR_RW) ) + panic("Unable to setup the frametable mappings.\n"); + + memset(&frame_table[0], 0, nr_mfns * sizeof(struct page_info)); + memset(&frame_table[nr_mfns], -1, + frametable_size - (nr_mfns * sizeof(struct page_info))); +} + +vaddr_t directmap_virt_end __read_mostly; + +/* + * Setup memory management + * + * RISC-V 64 has a large virtual address space (the minimum supported + * MMU mode is Sv39, which provides TBs of VA space). + * In the case of RISC-V 64, the directmap and frametable are mapped + * starting from physical address 0 to simplify the page_to_mfn(), + * mfn_to_page(), and maddr_to_virt() calculations, as there is no need + * to account for {directmap, frametable}_base_pdx in this setup. + */ +void __init setup_mm(void) +{ + const struct membanks *banks = bootinfo_get_mem(); + paddr_t ram_end = 0; + paddr_t ram_size = 0; + unsigned int i; + + /* + * We need some memory to allocate the page-tables used for the directmap + * mappings. But some regions may contain memory already allocated + * for other uses (e.g. modules, reserved-memory...). + * + * For simplicity, add all the free regions in the boot allocator. + */ + populate_boot_allocator(); + + total_pages = 0; + + for ( i = 0; i < banks->nr_banks; i++ ) + { + const struct membank *bank = &banks->bank[i]; + paddr_t bank_end = bank->start + bank->size; + + ram_size = ram_size + bank->size; + ram_end = max(ram_end, bank_end); + } + + setup_directmap_mappings(PFN_DOWN(ram_end)); + + total_pages = PFN_DOWN(ram_size); + + directmap_virt_end = DIRECTMAP_VIRT_START + ram_end; + + setup_frametable_mappings(0, ram_end); + max_page = PFN_DOWN(ram_end); +} + +#else /* CONFIG_RISCV_32 */ +#error setup_mm(), setup_{directmap,frametable}_mapping() should be implemented for RV_32 +#endif diff --git a/xen/arch/riscv/setup.c b/xen/arch/riscv/setup.c index e29bd75d7c..2887a18c0c 100644 --- a/xen/arch/riscv/setup.c +++ b/xen/arch/riscv/setup.c @@ -12,6 +12,7 @@ #include #include +#include #include #include @@ -59,6 +60,8 @@ void __init noreturn start_xen(unsigned long bootcpu_id, printk("Command line: %s\n", cmdline); cmdline_parse(cmdline); + setup_mm(); + printk("All set up\n"); machine_halt(); From patchwork Wed Oct 16 09:15:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksii Kurochko X-Patchwork-Id: 13837963 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AFC36D1AD2E for ; Wed, 16 Oct 2024 09:16:27 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.819725.1233172 (Exim 4.92) (envelope-from ) id 1t108W-0005fR-Te; Wed, 16 Oct 2024 09:16:08 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 819725.1233172; Wed, 16 Oct 2024 09:16:08 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t108W-0005es-MA; Wed, 16 Oct 2024 09:16:08 +0000 Received: by outflank-mailman (input) for mailman id 819725; Wed, 16 Oct 2024 09:16:07 +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 1t108V-0005Dr-9e for xen-devel@lists.xenproject.org; Wed, 16 Oct 2024 09:16:07 +0000 Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [2a00:1450:4864:20::132]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 45fe840f-8b9f-11ef-a0be-8be0dac302b0; Wed, 16 Oct 2024 11:16:06 +0200 (CEST) Received: by mail-lf1-x132.google.com with SMTP id 2adb3069b0e04-539983beb19so6739871e87.3 for ; Wed, 16 Oct 2024 02:16:06 -0700 (PDT) Received: from fedora.. ([94.75.70.14]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53a000129eesm391451e87.259.2024.10.16.02.16.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Oct 2024 02:16:04 -0700 (PDT) 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: 45fe840f-8b9f-11ef-a0be-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729070166; x=1729674966; 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=5lMS96kWM5Eui5gIIP4UZOxeSh3q2YL3fIRawSS4m1s=; b=Mj0Wx8eCBhJJoinEo/hdwMCMVWWoA0evI5uarwiSx5zXUCfwylbAaVBCq/3d+L1m+L Hp8jepS4l7vnMfL/QApXfrnwVyPnwO2LSSpzGV4Nblh2Wn4HOsxLi+4GdSQU2dK3PXQE Mic6MA02b3SSZso4H0L6s+/LX6F3oaHaYHLzM7Ec2XlicUW7d7/m5/RzRXxloVdyolcM +fDIvM5BRsfEIgQ2q0fsrDL/W8X2YDFcl9SI5+4HAtW9ySZxTiw3gSSnLNjOoebP/9/+ B37FBZClijhVdeqvHBgpY1bavUte3WK2RKGomkV4nQWETTazGUhrhrorcZs8YbMTctbC QBIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729070166; x=1729674966; 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=5lMS96kWM5Eui5gIIP4UZOxeSh3q2YL3fIRawSS4m1s=; b=W5DQMtfJX0Q1r6FZVQ5+IL5bLSb2+IYTgSTXF+B26BLU1S02QPtXQ0beO9j2uDe+io gCM6jiM3ongdZ1qOWKWrwle/umbRTX8nCPiY3oiyB6SA8WHqIUiFDzIVATEfJDogEPbK wRoYkMXcvjYeMxzXr04uut9XFCjPF9YKZH04nxSkrdxXgaCtCQi7irXjHPSSiOu4nsqG jCBiakjaMWJHhLcddfbAVEOVUQMZvq/orjrcwO0YECZjlf6z5jtxHtXIoNnOh5KZwbS2 5x2ot7I90zMq5WFh6Dy1m+JdyKOTzVGEMWJzn/xvypCj4EB4UY9gMQWLdfjr9jKWQZX8 0t2A== X-Gm-Message-State: AOJu0YwQgBBq9goMRSNjGuV7cEU1lMI6cmIMic/5dXcywUWvCNIqV70s DJzhRWNovGoA8+cQ47AqfdVk4S3NpEbVokjRBhEBcvGdCKKTg0INYhi/eQ== X-Google-Smtp-Source: AGHT+IGb80fSI23TL9q6T+bth+NXlB2cHrY4hxUWVqG0EVh54POIsEn5HZendV2P+tHGigv2GJpZ1Q== X-Received: by 2002:ac2:4c4c:0:b0:539:8e77:9129 with SMTP id 2adb3069b0e04-539da583e0fmr9305769e87.44.1729070165278; Wed, 16 Oct 2024 02:16:05 -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 4/5] xen/riscv: initialize the VMAP_DEFAULT virtual range Date: Wed, 16 Oct 2024 11:15:56 +0200 Message-ID: X-Mailer: git-send-email 2.47.0 In-Reply-To: References: MIME-Version: 1.0 Call vm_init() to initialize the VMAP_DEFAULT virtual range. To support this, introduce the populate_pt_range() and arch_vmap_virt_end() functions, which are used by vm_init()->vm_init_type(). Signed-off-by: Oleksii Kurochko Acked-by: Jan Beulich --- xen/arch/riscv/mm.c | 11 +++++------ xen/arch/riscv/pt.c | 6 ++++++ xen/arch/riscv/setup.c | 3 +++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/xen/arch/riscv/mm.c b/xen/arch/riscv/mm.c index 53b7483f75..2a55246f80 100644 --- a/xen/arch/riscv/mm.c +++ b/xen/arch/riscv/mm.c @@ -352,12 +352,6 @@ void arch_dump_shared_mem_info(void) BUG_ON("unimplemented"); } -int populate_pt_range(unsigned long virt, unsigned long nr_mfns) -{ - BUG_ON("unimplemented"); - return -1; -} - int xenmem_add_to_physmap_one(struct domain *d, unsigned int space, union add_to_physmap_extra extra, unsigned long idx, gfn_t gfn) @@ -516,3 +510,8 @@ void __init setup_mm(void) #else /* CONFIG_RISCV_32 */ #error setup_mm(), setup_{directmap,frametable}_mapping() should be implemented for RV_32 #endif + +void *__init arch_vmap_virt_end(void) +{ + return (void *)(VMAP_VIRT_START + VMAP_VIRT_SIZE); +} diff --git a/xen/arch/riscv/pt.c b/xen/arch/riscv/pt.c index cc5e2d3266..d62aceb36c 100644 --- a/xen/arch/riscv/pt.c +++ b/xen/arch/riscv/pt.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -419,3 +420,8 @@ int map_pages_to_xen(unsigned long virt, return pt_update(virt, mfn, nr_mfns, flags); } + +int __init populate_pt_range(unsigned long virt, unsigned long nr_mfns) +{ + return pt_update(virt, INVALID_MFN, nr_mfns, PTE_POPULATE); +} diff --git a/xen/arch/riscv/setup.c b/xen/arch/riscv/setup.c index 2887a18c0c..3652cb056d 100644 --- a/xen/arch/riscv/setup.c +++ b/xen/arch/riscv/setup.c @@ -7,6 +7,7 @@ #include #include #include +#include #include @@ -62,6 +63,8 @@ void __init noreturn start_xen(unsigned long bootcpu_id, setup_mm(); + vm_init(); + printk("All set up\n"); machine_halt(); From patchwork Wed Oct 16 09:15:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksii Kurochko X-Patchwork-Id: 13837964 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5D6B4D1AD32 for ; Wed, 16 Oct 2024 09:16:28 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.819726.1233187 (Exim 4.92) (envelope-from ) id 1t108Y-00065c-8i; Wed, 16 Oct 2024 09:16:10 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 819726.1233187; Wed, 16 Oct 2024 09:16:10 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t108Y-00065H-2I; Wed, 16 Oct 2024 09:16:10 +0000 Received: by outflank-mailman (input) for mailman id 819726; Wed, 16 Oct 2024 09:16:08 +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 1t108W-0005Dr-9j for xen-devel@lists.xenproject.org; Wed, 16 Oct 2024 09:16:08 +0000 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [2a00:1450:4864:20::12f]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 464a56a6-8b9f-11ef-a0be-8be0dac302b0; Wed, 16 Oct 2024 11:16:06 +0200 (CEST) Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-539fbbadf83so3650876e87.0 for ; Wed, 16 Oct 2024 02:16:06 -0700 (PDT) Received: from fedora.. ([94.75.70.14]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53a000129eesm391451e87.259.2024.10.16.02.16.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Oct 2024 02:16:05 -0700 (PDT) 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: 464a56a6-8b9f-11ef-a0be-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729070166; x=1729674966; 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=uq1Ji0h1S5Dw2PEhn0+S62eckwVA0WVyWGndSlD+Pe0=; b=LpondwmI2+PhEDMQBJFrAL4cBU9ir79eVPXLnvmxhrrQmPkN0Umj7jksn3+hTjqyDl S7X+ExE9M3QPziSXfm6cFi+JTSq/5EaFy+oqpNeTlfELvqR7gQJdQr+yWE5XFvUYKqR8 PNbificNlG4guCVl+FwnYvOd2Qhm5oBvYAGk6y6WRnEcS/VpQREqKJFOheabCq9mBgES xWqwsrhIM8DGsHxrbrpf+vbrl8EGV7KbG3mWWWGddH7maUkEw4GQpuYiEg02GE2t5ACC td/SQMA/nKp8RnZoAeIZ2Pk/gJY8zFTZNY01u8Xjg+w2xqtjsW7JQLGVtCQgOUt6/d9R VIXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729070166; x=1729674966; 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=uq1Ji0h1S5Dw2PEhn0+S62eckwVA0WVyWGndSlD+Pe0=; b=ofIHNf2XHbR3jONHaZg2Sb0hQokUt/6IlCL9mJPeJUTgVPPKy8tWaqy6mfMdpC79mE ZKzLGdx3gNoq8itqn/X3xPiZtMdCpanzsrqQbxMX4nX3vK2+jmV72UpvFzEx1Gkt2Ega 9jim8Cs7uvJE9vulaWiC0bXy0vvnzZv0FUDf7jdHSIsWcQHHWiCpK47HgilMXB7qXUlR 86dkt4+n/3xQHu4+F+ccrZBQZ4ctel5haKbx+/ZBN83rUY0pWTrQ0nAJ6wBuX/WSl83q 5Kw9xDRMl3VwmLzuc19JCfvlRphb3IKiXQzybzqf9kTZx2R6xY4rkI2HfZokDT03Zhwd aNmA== X-Gm-Message-State: AOJu0Yxkuc1M/LmsTsviJcPvPJct59f3we3+fkgDkUHWMRKlv2y+0Z2U 4pE4VBl1WoNWLs1iJb7zXGx5XoqvPSz+ReJZLIWDEQT7C2WliucaPjB1+w== X-Google-Smtp-Source: AGHT+IGO+hyNoyG8ho2yeBme03+6EdXfXPmLx1WZxdmZiZeFAIbiv88WI4R0FDSR9TzuYZZ5fIxFCw== X-Received: by 2002:a05:6512:3d23:b0:536:568f:c5ed with SMTP id 2adb3069b0e04-539da3b41c0mr8592917e87.1.1729070165984; Wed, 16 Oct 2024 02:16:05 -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 5/5] xen/riscv: finalize boot allocator and transition to boot state Date: Wed, 16 Oct 2024 11:15:57 +0200 Message-ID: X-Mailer: git-send-email 2.47.0 In-Reply-To: References: MIME-Version: 1.0 Add a call to end_boot_allocator() in start_xen() to finalize the boot memory allocator, moving free pages to the domain sub-allocator. After initializing the memory subsystem, update `system_state` from `SYS_STATE_early_boot` to `SYS_STATE_boot`, signifying the end of the early boot phase. Signed-off-by: Oleksii Kurochko Acked-by: Jan Beulich --- xen/arch/riscv/setup.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/xen/arch/riscv/setup.c b/xen/arch/riscv/setup.c index 3652cb056d..9680332fee 100644 --- a/xen/arch/riscv/setup.c +++ b/xen/arch/riscv/setup.c @@ -65,6 +65,14 @@ void __init noreturn start_xen(unsigned long bootcpu_id, vm_init(); + end_boot_allocator(); + + /* + * The memory subsystem has been initialized, we can now switch from + * early_boot -> boot. + */ + system_state = SYS_STATE_boot; + printk("All set up\n"); machine_halt();