From patchwork Wed Nov 27 12:50:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksii Kurochko X-Patchwork-Id: 13886981 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 6510CD6ACCC for ; Wed, 27 Nov 2024 12:50:41 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.844751.1260257 (Exim 4.92) (envelope-from ) id 1tGHUu-0004c0-EF; Wed, 27 Nov 2024 12:50:24 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 844751.1260257; Wed, 27 Nov 2024 12:50:24 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tGHUu-0004aM-6i; Wed, 27 Nov 2024 12:50:24 +0000 Received: by outflank-mailman (input) for mailman id 844751; Wed, 27 Nov 2024 12:50:23 +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 1tGHUt-0004Yj-1T for xen-devel@lists.xenproject.org; Wed, 27 Nov 2024 12:50:23 +0000 Received: from mail-lf1-x12e.google.com (mail-lf1-x12e.google.com [2a00:1450:4864:20::12e]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 28b59f8f-acbe-11ef-a0cd-8be0dac302b0; Wed, 27 Nov 2024 13:50:19 +0100 (CET) Received: by mail-lf1-x12e.google.com with SMTP id 2adb3069b0e04-53dde5262fdso4894826e87.2 for ; Wed, 27 Nov 2024 04:50:19 -0800 (PST) Received: from fedora.. ([94.75.70.14]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53dd8cb7f00sm2023267e87.7.2024.11.27.04.50.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Nov 2024 04:50:18 -0800 (PST) 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: 28b59f8f-acbe-11ef-a0cd-8be0dac302b0 X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjoxMmUiLCJoZWxvIjoibWFpbC1sZjEteDEyZS5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6IjI4YjU5ZjhmLWFjYmUtMTFlZi1hMGNkLThiZTBkYWMzMDJiMCIsInRzIjoxNzMyNzExODE5Ljk0NDkxNywic2VuZGVyIjoib2xla3NpaS5rdXJvY2hrb0BnbWFpbC5jb20iLCJyZWNpcGllbnQiOiJ4ZW4tZGV2ZWxAbGlzdHMueGVucHJvamVjdC5vcmcifQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732711819; x=1733316619; 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=QFk+JVoO6jJ82E1hzFEd4LqERyYR6iKKhEgzSQ920Ew=; b=WQI8SVd4Lnf1jKpH0TqwcakGE4VlWOGgOYfz85e7C3OH9c7Cj3WJkPJaD4ecXplJXe F/5822i9Wu1qu7tmg88d9IO6wdu6V4aiIoRLXC/9bpONJqrJgs9/kgBFXL5l5ibobUE+ 6oDEumkiFU4dM9CrxnPWeMsMMJwtS7XzxqO8E4poUg6EmgOgQ1y06JWcpDARM2BFTB3j TXk1luvZQW4I0O/V5P7D/cek72YRGnGR21CtyEQUvCM67r3szbJ6U+3SEWp9rpMvyfTr Ra26NmilOzf71B16EGH4o95eEmRngEkNzRJpFbQw+4x9y+ENph2U3Nt1FHUuAY8TmKrX /HWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732711819; x=1733316619; 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=QFk+JVoO6jJ82E1hzFEd4LqERyYR6iKKhEgzSQ920Ew=; b=wcZBftBPirSIKFv/PN1kLkdAqqYSLvnJVR195ysCohfNGH9v/Gy4ahSQ8LL9JrPkMK c1PLEcz6E/O7GZk75n1EZPiVfDWLVKfFVkgq3a9uiI+WXqvrWvjKvT2mnPUfgfZTG5rn pWZgp+9bELv4tDHpg3RJKGxFWXXMzuirc6IhZ7N6H3Cqy6dsR84foWWo/cRufTyEw6u9 +/q2RcaSg6b9hEby4LH21twbUvmJpxyOJ2de/AbTWiTcesCxxs/7lnV6OEkxgl+iomAE q7taotBwjM7bFVKqolDyReZOLmscjqBKH3FDl4U/uhJ2ZrhqeaxEx1Rv12NE1+OTpuut 4eCg== X-Gm-Message-State: AOJu0YxMbr8+H86f6HB2n7eOlTokZlqmnFHhInYaz4GhyHxahxXz0yBx zNJ1fxyohd5JemWE5L3gz3Q//Mk8O82iom2Br/yPlhL1kq6GJXW3gNqV1A== X-Gm-Gg: ASbGncvoV62BURnDfShY2ztMpldod2ymSn2zBCXdYTkRqiU19qiUzGM/acYQSo9UFHz FM2WLiDF2Po4TKNs2AgyMzcqUog47NXTi7ztIdK2Z0mbBr/yqjfPpZ4spVfpJ8EmPgT5K8fa++S i8Q8Q4cNZAO81SJxQJ13BEZn6W3hq2A5cycjTvI5xs0z5nFz2LQGFTrRPHAXOHdbuY+U2q43GlE 43G6wU+RreMkCOzcrxE4W/s3UHqq0vO9z0Wn9iN8UhiTHFNZQ4= X-Google-Smtp-Source: AGHT+IEtCS5jEQ4Ctfxyle6YJ3nFmVflvqq7XZvda8k58SPVAJICGdGGC8zsf5xcn2lfv7gvcDHDWQ== X-Received: by 2002:a05:6512:b15:b0:539:e317:b05f with SMTP id 2adb3069b0e04-53df00de3a9mr1519882e87.28.1732711818904; Wed, 27 Nov 2024 04:50:18 -0800 (PST) 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/6] xen/riscv: add destroy_xen_mappings() to remove mappings in Xen page tables Date: Wed, 27 Nov 2024 13:50:10 +0100 Message-ID: X-Mailer: git-send-email 2.47.0 In-Reply-To: References: MIME-Version: 1.0 Introduce the destroy_xen_mappings() function, which removes page mappings in Xen's page tables between a start address s and an end address e. The function ensures that both s and e are page-aligned and verifies that the start address is less than or equal to the end address before calling pt_update() to invalidate the mappings. The pt_update() function is called with INVALID_MFN and PTE_VALID=0 in the flags, which tell pt_update() to remove mapping. No additional ASSERT() is required to check these arguments, as they are hardcoded in the call to pt_update() within destroy_xen_mappings(). Signed-off-by: Oleksii Kurochko --- xen/arch/riscv/mm.c | 6 ------ xen/arch/riscv/pt.c | 8 ++++++++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/xen/arch/riscv/mm.c b/xen/arch/riscv/mm.c index 9359dc7f33..f2bf279bac 100644 --- a/xen/arch/riscv/mm.c +++ b/xen/arch/riscv/mm.c @@ -360,12 +360,6 @@ int xenmem_add_to_physmap_one(struct domain *d, unsigned int space, return 0; } -int destroy_xen_mappings(unsigned long s, unsigned long e) -{ - BUG_ON("unimplemented"); - return -1; -} - void share_xen_page_with_guest(struct page_info *page, struct domain *d, enum XENSHARE_flags flags) { diff --git a/xen/arch/riscv/pt.c b/xen/arch/riscv/pt.c index d62aceb36c..8d35ef5ca8 100644 --- a/xen/arch/riscv/pt.c +++ b/xen/arch/riscv/pt.c @@ -421,6 +421,14 @@ int map_pages_to_xen(unsigned long virt, return pt_update(virt, mfn, nr_mfns, flags); } +int destroy_xen_mappings(unsigned long s, unsigned long e) +{ + ASSERT(IS_ALIGNED(s, PAGE_SIZE)); + ASSERT(IS_ALIGNED(e, PAGE_SIZE)); + ASSERT(s <= e); + return pt_update(s, INVALID_MFN, PFN_DOWN(e - s), 0); +} + int __init populate_pt_range(unsigned long virt, unsigned long nr_mfns) { return pt_update(virt, INVALID_MFN, nr_mfns, PTE_POPULATE); From patchwork Wed Nov 27 12:50:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksii Kurochko X-Patchwork-Id: 13886982 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 2EE45D6ACCA for ; Wed, 27 Nov 2024 12:50:41 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.844754.1260290 (Exim 4.92) (envelope-from ) id 1tGHUz-0005ds-WB; Wed, 27 Nov 2024 12:50:29 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 844754.1260290; Wed, 27 Nov 2024 12:50: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 1tGHUz-0005dk-T6; Wed, 27 Nov 2024 12:50:29 +0000 Received: by outflank-mailman (input) for mailman id 844754; Wed, 27 Nov 2024 12:50: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 1tGHUy-0004Yu-Ld for xen-devel@lists.xenproject.org; Wed, 27 Nov 2024 12:50: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 291205f9-acbe-11ef-99a3-01e77a169b0f; Wed, 27 Nov 2024 13:50:20 +0100 (CET) Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-53dde5262fdso4894834e87.2 for ; Wed, 27 Nov 2024 04:50:20 -0800 (PST) Received: from fedora.. ([94.75.70.14]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53dd8cb7f00sm2023267e87.7.2024.11.27.04.50.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Nov 2024 04:50:19 -0800 (PST) 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: 291205f9-acbe-11ef-99a3-01e77a169b0f X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjoxMzQiLCJoZWxvIjoibWFpbC1sZjEteDEzNC5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6IjI5MTIwNWY5LWFjYmUtMTFlZi05OWEzLTAxZTc3YTE2OWIwZiIsInRzIjoxNzMyNzExODIwLjU3ODIxOSwic2VuZGVyIjoib2xla3NpaS5rdXJvY2hrb0BnbWFpbC5jb20iLCJyZWNpcGllbnQiOiJ4ZW4tZGV2ZWxAbGlzdHMueGVucHJvamVjdC5vcmcifQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732711820; x=1733316620; 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=pFssf5rjB5zK7xWMEIyHt0mx4lOxs7souSKxYFyKhsg=; b=Lmjnu6XVo0HOK1Z2M40hEHrpzF8BsLOvCL9TXTkKnZ8dmuhumyKusrCQuStsmU2YqR +srk5oOB+ZYrEHWiuiDW9G95LCl8LlfAm00cXqzyAmDbzrKE8KM7238MwMWN14bkBuiU sqPk5qSEqGzfra2tAKerr7DVAzoSddSmDuLzRMn0DlJI+FQTWcoCRbGP67hl33xjnqf1 QZOyoDuBHxBhlHAX2HJsW7ax5ra6BjzsDdMD9sY+s9f0lNPd+SE8LS4u3ftcnVpANhL6 hWxGb4MLwSrt6VxJMS+xMGivPxvLcf6RVtJUnM2UbUFxl+sAB6Wl0J9pTRn4c5yVlNDr 5dHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732711820; x=1733316620; 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=pFssf5rjB5zK7xWMEIyHt0mx4lOxs7souSKxYFyKhsg=; b=XXv+ZFJ+zTxVNzcwYq5hVEqziJrnCalcrFhCtbZR9hinWfsaSjdq76oZ1FXNDZpKSl 3NYFYIQ0+GI9FJtawEbAB6MldCW/ElBhBY32w3XSSoFx6yvoOMg9h63IicleSx9EqDP9 P+mrkloirzcWA7KMCou62QdlNy9JYQMxLvHW93TzUyURAzrksBCmtTZSjW0ZYSwloz1h 5kyPME0GG/IUukXrazsfolkrPBY1DV/EQZqYl759tBVBHg+uaQnVkhAB++/GCLZBWEmc PVGiILuVWyCdL1n/xvOLNKU9gc1og4wZhNWOHJVZs4FG+iKz8cPA+ehgxhrmkVl9x0y7 Rinw== X-Gm-Message-State: AOJu0YzH1HaHgrdFgrX3vtzG9N4Z/Y9q4quRtzKrZOriL+dLelYxmTPo 90I7lqvRC/fSpiFGWcmABs2GXG+F3SaEshULFS6jSTg4WKU26EuT+3SXkg== X-Gm-Gg: ASbGncuLHE0uSru93mk14EsZQyu8UU68F0rXyk0y/1skA4mLQwt9ilY6l11xmGyYj0y IHFfY2UOEOPJ3Wu72IdTPtHx3spo5bmch1FhgqjFSdSfx8uSchaDqRtGW++Hw7Vp3Ksz01vDlKb LjzRoAjZ2rP8Tpy/4ptTv5cG1zuX7P9W9CissvWPEXxT9SYQk7zJNT+tyt3CvK8UF5rAAHCJ4tq 28GYnAjOELNWFHfZektmAucR4gNSXGSdm8kleyt+sehi6lCyPo= X-Google-Smtp-Source: AGHT+IHxWQrerUzX8OstxJxfpu0eDrJwhc4s7hxMC5R1C6DfUnvCNB6hs7z1V7Mn7fele0Xat9s46Q== X-Received: by 2002:a05:6512:2309:b0:53d:a883:5a3e with SMTP id 2adb3069b0e04-53df0108ff1mr1418457e87.39.1732711819589; Wed, 27 Nov 2024 04:50:19 -0800 (PST) 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/6] xen/riscv: reorder includes in asm/page.h alphabetically Date: Wed, 27 Nov 2024 13:50:11 +0100 Message-ID: <4b458dea207cc6f2c2ab5d5a3d67ca9f6d5958da.1732709650.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: MIME-Version: 1.0 Signed-off-by: Oleksii Kurochko --- xen/arch/riscv/include/asm/page.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xen/arch/riscv/include/asm/page.h b/xen/arch/riscv/include/asm/page.h index 91b1194b55..bf3f75e85d 100644 --- a/xen/arch/riscv/include/asm/page.h +++ b/xen/arch/riscv/include/asm/page.h @@ -5,8 +5,8 @@ #ifndef __ASSEMBLY__ -#include #include +#include #include #include From patchwork Wed Nov 27 12:50:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksii Kurochko X-Patchwork-Id: 13886980 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 DA039D6ACC4 for ; Wed, 27 Nov 2024 12:50:38 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.844752.1260270 (Exim 4.92) (envelope-from ) id 1tGHUv-00051F-IN; Wed, 27 Nov 2024 12:50:25 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 844752.1260270; Wed, 27 Nov 2024 12:50:25 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tGHUv-000518-Ew; Wed, 27 Nov 2024 12:50:25 +0000 Received: by outflank-mailman (input) for mailman id 844752; Wed, 27 Nov 2024 12:50:24 +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 1tGHUu-0004Yj-1T for xen-devel@lists.xenproject.org; Wed, 27 Nov 2024 12:50:24 +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 29814a79-acbe-11ef-a0cd-8be0dac302b0; Wed, 27 Nov 2024 13:50:21 +0100 (CET) Received: by mail-lf1-x132.google.com with SMTP id 2adb3069b0e04-53dde4f0f23so3989737e87.3 for ; Wed, 27 Nov 2024 04:50:21 -0800 (PST) Received: from fedora.. ([94.75.70.14]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53dd8cb7f00sm2023267e87.7.2024.11.27.04.50.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Nov 2024 04:50:20 -0800 (PST) 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: 29814a79-acbe-11ef-a0cd-8be0dac302b0 X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjoxMzIiLCJoZWxvIjoibWFpbC1sZjEteDEzMi5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6IjI5ODE0YTc5LWFjYmUtMTFlZi1hMGNkLThiZTBkYWMzMDJiMCIsInRzIjoxNzMyNzExODIxLjI1MzU2MSwic2VuZGVyIjoib2xla3NpaS5rdXJvY2hrb0BnbWFpbC5jb20iLCJyZWNpcGllbnQiOiJ4ZW4tZGV2ZWxAbGlzdHMueGVucHJvamVjdC5vcmcifQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732711820; x=1733316620; 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=pVDvF5YqyyLTl9nNm34usBBdPtMjgbaktt06G1afM/M=; b=O0gB0lBrGt0J8QHqUWjGh3sVSPMkrjWK/pLj29G0drKlFsqu6/xZfqr9bC4maPlfzk IP7yRMDsmOVfmMA0iQo4SWThIMd5RqYaF3XijJFUxHOIIS2W8kg1w9rMWFqK5eL2wIc6 49XG03wuoFkILmmlU2GBmeEvmB0ZW58IK2UhtRjRKFT0O7G0E11gIBCTJrLUq0L1PAzJ GMRJq3DQgeCe6oMoiucsiSHixny7q1bZLa8JjdLWVjpeEVs3fUX9Oknd0QsgO3mFWYEY hirB8fgQwXjDnVOuEOQvrPZD7GZBFrl7v09YrgVJl0yaMuFc3j9nzMAhkxQ7gF1ajsAy IkQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732711820; x=1733316620; 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=pVDvF5YqyyLTl9nNm34usBBdPtMjgbaktt06G1afM/M=; b=AwZ+oKuNOQQ1+zsSEGvj27wMC2iFpj+TMCA907cdnZAXCcZG5v2PZQE80GRDrAsC+C XkSWewpChJYibSfSLPM992h5o08QBHEtlWwNhkY434eyfqeE7vVAKb4nR2iQPsRPVf7u vRTJcMD0LLUJ+FZL7rVbjcGBJ1jVpoA23NrAHre6MJ3p94Rq4P+35vgYLp2ZY764IwPo QcUDtAfXtqL6Dypbv4A2/CksnpoL+CXD2tmjgdBHKcPWSc08WryLlSBsOttD3ROSQ1Bm WTy3g3zh8jQ1xUe2RQTTr09br9807OXwPmq9kXykIlKpJqwgw8R5gUfi+DDn6chxjSlz K2aQ== X-Gm-Message-State: AOJu0YyPMLf/9uszE9pgn1/98KKIUWJt2RX4Wn32I8JJIRY2mqK3WxMh hiiwCU3CIrRsWNYfk7aF2HgPQq9BAfms4RXElHaIjbA+wIR0laF3CyfGEA== X-Gm-Gg: ASbGncvUBRdOkVF4pb1upN8h1DpNQ3yqOtwDNw8ngTHOpJBZptVAnsOSd2A/Oh+14rt KMIjtcFdSfPfzDRj4anrpXgXziRuA0dIzoqpNgmjQr2vzntEBnTUdPwCoLmY/+bssgOJxB7tl84 32SaiQBq8/UADJMQq++lp/pS+ilNnFVai7aCXOD0UDJ3LTWXF8/P9PA6YBNBQg8qeRTWIzdBnPl K/7AW2cwnXlkmrBDjXua0PMRl9EQU+VNczvz76tW58QM3f4u94= X-Google-Smtp-Source: AGHT+IHrzpuEseSFO9gOn9yNkiZ71guV/3ErvZjDGwhl4x02Ued71294I6HeJfRHYSKswtxj+xcFyg== X-Received: by 2002:a05:6512:b1e:b0:53d:ecf6:aadc with SMTP id 2adb3069b0e04-53df0104754mr1896350e87.43.1732711820255; Wed, 27 Nov 2024 04:50:20 -0800 (PST) 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/6] xen/riscv: add {set,clear}_fixmap() functions for managing fixmap entries Date: Wed, 27 Nov 2024 13:50:12 +0100 Message-ID: <2badea2de39b7614d38a620d1b718478de1fc82c.1732709650.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: MIME-Version: 1.0 Introduce set_fixmap() and clear_fixmap() functions to manage mappings in the fixmap region. The set_fixmap() function maps a 4k page ( as only L0 is expected to be updated; look at setup_fixmap_mappings() ) at a specified fixmap entry using map_pages_to_xen(), while clear_fixmap() removes the mapping from a fixmap entry by calling destroy_xen_mappings(). Both functions ensure that the operations succeed by asserting that their respective calls (map_pages_to_xen() and destroy_xen_mappings()) return 0. A `BUG_ON` check is used to trigger a failure if any issues occur during the mapping or unmapping process. Signed-off-by: Oleksii Kurochko --- xen/arch/riscv/include/asm/fixmap.h | 5 +++++ xen/arch/riscv/pt.c | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/xen/arch/riscv/include/asm/fixmap.h b/xen/arch/riscv/include/asm/fixmap.h index 818c8ce07b..e399a15f53 100644 --- a/xen/arch/riscv/include/asm/fixmap.h +++ b/xen/arch/riscv/include/asm/fixmap.h @@ -32,6 +32,11 @@ */ extern pte_t xen_fixmap[]; +/* Map a page in a fixmap entry */ +void set_fixmap(unsigned int map, mfn_t mfn, unsigned int flags); +/* Remove a mapping from a fixmap entry */ +void clear_fixmap(unsigned int map); + #define fix_to_virt(slot) ((void *)FIXMAP_ADDR(slot)) static inline unsigned int virt_to_fix(vaddr_t vaddr) diff --git a/xen/arch/riscv/pt.c b/xen/arch/riscv/pt.c index 8d35ef5ca8..ed9a943d4c 100644 --- a/xen/arch/riscv/pt.c +++ b/xen/arch/riscv/pt.c @@ -8,6 +8,7 @@ #include #include +#include #include #include @@ -433,3 +434,21 @@ int __init populate_pt_range(unsigned long virt, unsigned long nr_mfns) { return pt_update(virt, INVALID_MFN, nr_mfns, PTE_POPULATE); } + +/* Map a 4k page in a fixmap entry */ +void set_fixmap(unsigned int map, mfn_t mfn, unsigned int flags) +{ + int res; + + res = map_pages_to_xen(FIXMAP_ADDR(map), mfn, 1, flags | PTE_SMALL); + BUG_ON(res != 0); +} + +/* Remove a mapping from a fixmap entry */ +void clear_fixmap(unsigned int map) +{ + int res; + + res = destroy_xen_mappings(FIXMAP_ADDR(map), FIXMAP_ADDR(map) + PAGE_SIZE); + BUG_ON(res != 0); +} From patchwork Wed Nov 27 12:50:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksii Kurochko X-Patchwork-Id: 13886979 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 66F5CD6ACC9 for ; Wed, 27 Nov 2024 12:50:38 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.844755.1260296 (Exim 4.92) (envelope-from ) id 1tGHV0-0005fx-DK; Wed, 27 Nov 2024 12:50:30 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 844755.1260296; Wed, 27 Nov 2024 12:50:30 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tGHV0-0005fm-48; Wed, 27 Nov 2024 12:50:30 +0000 Received: by outflank-mailman (input) for mailman id 844755; Wed, 27 Nov 2024 12:50: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 1tGHUy-0004Yu-Sa for xen-devel@lists.xenproject.org; Wed, 27 Nov 2024 12:50:28 +0000 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [2a00:1450:4864:20::12f]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 29e19c1b-acbe-11ef-99a3-01e77a169b0f; Wed, 27 Nov 2024 13:50:21 +0100 (CET) Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-53da6801c6dso6454463e87.0 for ; Wed, 27 Nov 2024 04:50:21 -0800 (PST) Received: from fedora.. ([94.75.70.14]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53dd8cb7f00sm2023267e87.7.2024.11.27.04.50.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Nov 2024 04:50:20 -0800 (PST) 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: 29e19c1b-acbe-11ef-99a3-01e77a169b0f X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjoxMmYiLCJoZWxvIjoibWFpbC1sZjEteDEyZi5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6IjI5ZTE5YzFiLWFjYmUtMTFlZi05OWEzLTAxZTc3YTE2OWIwZiIsInRzIjoxNzMyNzExODIxLjkzNjI1OSwic2VuZGVyIjoib2xla3NpaS5rdXJvY2hrb0BnbWFpbC5jb20iLCJyZWNpcGllbnQiOiJ4ZW4tZGV2ZWxAbGlzdHMueGVucHJvamVjdC5vcmcifQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732711821; x=1733316621; 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=dc9hH6WhqhqHo54EhAfa8e1CnnKH2P2ca7DkyeZFSPw=; b=PeR/TwUFh7EJ8vDpjg2fDy/I54/68TIH0amcTTta81sIkWtl1dSzbxVD70Sm2cmWCv WqTw6oy9bI7Mf7sk5N/7baeWV1viHOTssb4KM7kH4wDbCNSTDdsvPt36dE6lScAWJZbN tf7moN9xqIuLw/wDJmTcjwUDW5TGm8Onay//2/OhEvsuuYpaJjCrGngAGvEbItihz6Sm wkoNBMR96/7Y28oWMDpUNsP8YdcMQHUVl1weiRRKLbcodgylxI/l6iX+3uYaX8GMsMMW BCS4EJss9nyDtOHj6apNy1wbCoOw6G9KAdSM+uwlqriHxLyWkiPVwxhcLtbt0CJmcCDK hiWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732711821; x=1733316621; 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=dc9hH6WhqhqHo54EhAfa8e1CnnKH2P2ca7DkyeZFSPw=; b=hKz6yx0sxBBmCX1psqqYh3o1X1clbFIVIH9LYTpNd1ii/vnv67JYQ77JRia7K4hxDc syXBRrA//ht8gczBow6YPm0z29nMLVvqKHneYWLhERbuL5REiEAjiN45JDDCPs+YrRt3 4nYTRZ/qBLL3zFvkhwgkoHr3JHKc8fYXO7UTCsHnulOXT1M1/ngecTs+R0rpIixHIVXm MzMGabCRKAkmR2icZLOdEXyHXpA5NYvgqlEu5f/5dBQGPO39NnLB0+CUGUjImsDdv+hq Fw3O4ZQgPvGjE0giiZyfakQ7d0hSIr9a9TZowh8pTql8thXS7oM7VAjky+i1gdb1FCn/ QjaQ== X-Gm-Message-State: AOJu0YyUhOx/PE9ZAaJKo8Fo8hkq/UfxlxbJYR3z88VbSyX4puM+s32k SpzQbi1j3K0o0l9QabTNeDobwkqajraHGqwo+P1iS4/SpBO0YuByeeM6aw== X-Gm-Gg: ASbGnctGreru/Kb/2Eftw4L/pQXzOA4a8hkLFHoZCf+uiI7IIzW5tuEE10aM5kpEiXx kSAY6X4cVuDurAPCcymjfdAK9i49ZOZMLZf2sRQrN9IycnfdKOo9mm4bUdUSuYZMuh/erppO1hb I0RcjNAaIvg2YggjegkV4I1G9dpf9BGvuSeJrOFrEs3dMWDG7PAnCJOhEf/3WAQ17P5/4H8PPMc UQojI+s5iskUU/ZDIO+qoJjyR/OkSBwY2IE7Nl6xbrn2NgBKj8= X-Google-Smtp-Source: AGHT+IFAwkiwdzMyqIaGjcrY2cTAISxO2+97YFmGMwN/UNjalYU5bAzGY8tqg/B6yYfsgukoOAM0dQ== X-Received: by 2002:a05:6512:b8f:b0:53d:e52d:3373 with SMTP id 2adb3069b0e04-53df00ff242mr1685501e87.41.1732711820930; Wed, 27 Nov 2024 04:50:20 -0800 (PST) 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/6] xen/riscv: introduce cache management operations (CMO) Date: Wed, 27 Nov 2024 13:50:13 +0100 Message-ID: <1310a2fb3b9824ae66f850600925127fdfdb44fa.1732709650.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: MIME-Version: 1.0 KConfig HAS_CMO is introduced to handle if the platform has CMO related extenstions ( such as Zicbom, Zicboz, Zicbop etc ) or not. if HAS_CMO isn't set stubs for clean_and_invalidate_dcache_va_range() and clean_dcache_va_range() are implemented as just returning -EOPNOTSUPP. Our current platform is QEMU which doesn't model caches so it should be fine to follow implementations when HAS_CMO isn't set. invalidate_icache() is implemented using fence.i instruction as mentioned in the unpriv spec: The FENCE.I instruction was designed to support a wide variety of implementations. A simple implementation can flush the local instruction cache and the instruction pipeline when the FENCE.I is executed. A more complex implementation might snoop the instruction (data) cache on every data (instruction) cache miss, or use an inclusive unified private L2 cache to invalidate lines from the primary instruction cache when they are being written by a local store instruction. If instruction and data caches are kept coherent in this way, or if the memory system consists of only uncached RAMs, then just the fetch pipeline needs to be flushed at a FENCE.I. Signed-off-by: Oleksii Kurochko --- xen/arch/riscv/Kconfig | 3 +++ xen/arch/riscv/include/asm/page.h | 18 +++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/xen/arch/riscv/Kconfig b/xen/arch/riscv/Kconfig index 1858004676..4f1fcfd21a 100644 --- a/xen/arch/riscv/Kconfig +++ b/xen/arch/riscv/Kconfig @@ -14,6 +14,9 @@ config ARCH_DEFCONFIG string default "arch/riscv/configs/tiny64_defconfig" +config HAS_CMO # Cache Management Operations + bool + menu "Architecture Features" source "arch/Kconfig" diff --git a/xen/arch/riscv/include/asm/page.h b/xen/arch/riscv/include/asm/page.h index bf3f75e85d..0f297141d3 100644 --- a/xen/arch/riscv/include/asm/page.h +++ b/xen/arch/riscv/include/asm/page.h @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -148,9 +149,24 @@ static inline bool pte_is_mapping(pte_t p) return (p.pte & PTE_VALID) && (p.pte & PTE_ACCESS_MASK); } +#ifndef HAS_CMO +static inline int clean_and_invalidate_dcache_va_range(const void *p, unsigned long size) +{ + return -EOPNOTSUPP; +} + +static inline int clean_dcache_va_range(const void *p, unsigned long size) +{ + return -EOPNOTSUPP; +} +#else +int clean_and_invalidate_dcache_va_range(const void *p, unsigned long size); +int clean_dcache_va_range(const void *p, unsigned long size); +#endif + static inline void invalidate_icache(void) { - BUG_ON("unimplemented"); + asm volatile ( "fence.i" ::: "memory" ); } #define clear_page(page) memset((void *)(page), 0, PAGE_SIZE) From patchwork Wed Nov 27 12:50:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksii Kurochko X-Patchwork-Id: 13886985 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 9FCE0D6ACC4 for ; Wed, 27 Nov 2024 12:50:43 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.844756.1260310 (Exim 4.92) (envelope-from ) id 1tGHV1-00069a-M1; Wed, 27 Nov 2024 12:50:31 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 844756.1260310; Wed, 27 Nov 2024 12:50:31 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tGHV1-00069G-IK; Wed, 27 Nov 2024 12:50:31 +0000 Received: by outflank-mailman (input) for mailman id 844756; Wed, 27 Nov 2024 12:50:29 +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 1tGHUz-0004Yu-Sq for xen-devel@lists.xenproject.org; Wed, 27 Nov 2024 12:50:29 +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 2a4e90cb-acbe-11ef-99a3-01e77a169b0f; Wed, 27 Nov 2024 13:50:22 +0100 (CET) Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-53ded167ae3so2115686e87.0 for ; Wed, 27 Nov 2024 04:50:22 -0800 (PST) Received: from fedora.. ([94.75.70.14]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53dd8cb7f00sm2023267e87.7.2024.11.27.04.50.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Nov 2024 04:50:21 -0800 (PST) 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: 2a4e90cb-acbe-11ef-99a3-01e77a169b0f X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjoxMzYiLCJoZWxvIjoibWFpbC1sZjEteDEzNi5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6IjJhNGU5MGNiLWFjYmUtMTFlZi05OWEzLTAxZTc3YTE2OWIwZiIsInRzIjoxNzMyNzExODIyLjY1NTcxOSwic2VuZGVyIjoib2xla3NpaS5rdXJvY2hrb0BnbWFpbC5jb20iLCJyZWNpcGllbnQiOiJ4ZW4tZGV2ZWxAbGlzdHMueGVucHJvamVjdC5vcmcifQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732711822; x=1733316622; 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=uXt3gxcLfSewdGxxgtLt+uhH1+qMZe5HJDTdu4QBaWc=; b=Y4vys3ZzsxfNINTzYCENgnfx209sUtvXiGhtLGMZOU7ROySiZqqOwrLThmmS2y7rA+ fTXTxQN2ckdVe9te9SWbQl2X9cvWb8LTSW+dUMEnZgzmm+/BuVhomVzJhzJD6czbCohl hkk+1jzJgvAwtTkGdma+kUDW3XotqIbHz6b2oSmCLElQAstM0JQ2lXu5cQEyF0d/z0XO 5nc5tdlcF/B7N/I4Dw6VPJR2tKnsIJruU2n3BzHgjN1SpD9SrToE+z2ktOKUGkYlTncU s8OHcfaINfr+pSK9fB6U960YeJBhVnOaDxM96+4DqG2ZUl0RDrgNovdqHdCxhICwEwxZ I+fA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732711822; x=1733316622; 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=uXt3gxcLfSewdGxxgtLt+uhH1+qMZe5HJDTdu4QBaWc=; b=lnDq8mBIUmbwQwJt2l75zQkdjtxk8y+6YI2KlCtc6Ssu4E9CIjXShtiex6Bwk0DArn vLu+/RnoAzHDPJk1Du4WQ/lV5+Akva3T2m7MMsZEHcxX/6dJ6+7NGFWtZ79ksjt2aDr1 0nW7Z0qOVsW57Ul5IHMrsyotMum0fRkRyI+ZL5rjMrmtznSRoi4XVjRUq7Ah33NmVRtF gJlDap8OMwKFiliMTUpInTzgFa3/SGepAS4tB4WiDQog1/laqvLESpnBFbe83XJLe93B Eop14aAG5+uDQhV3Ab9PGBrqYR96cQOlwWnmff6UpZYd431jtnDZh7BI9xzmmD0e6rZ/ FmPA== X-Gm-Message-State: AOJu0YyxpjnlskMODLKkLAkX8BYJwbuwLhu/G0ahut4kw+O+Wu1eKTyc jkPYdfExd5JC9nCJefTobil/wpFbiuJQh95LhVY8ZvlET3OpH37BWjukTA== X-Gm-Gg: ASbGncv51+jbdBa4N6/jV27R/0N/321b3orGGcKmOvW6zJPKQ9gT1SpMW+9UtIrr656 WG5R7/eS1ByEmwlDYgFs0tnIsFoupmaCKYLoCcppSjdUFouQU+On/DvQ12dsCYTrmmqXmPUNQVi ksn4zPK8K/iLydyuI2VtoNzA9iY6YZPbN/B2gFT/vr4ACworssjs0IhRqzLr1CT5yR9WWV5E62+ mnERMXTBassW3NC5X+GTpdqFDDcPneJarN4xFeeyts12GkNCIw= X-Google-Smtp-Source: AGHT+IESECb2bmfgazPXddPxX+IKMj6wv/oqPxGegKktP50aiHa41a3AflK1U38r/m44ekdyq1RshA== X-Received: by 2002:a05:6512:b14:b0:53d:ecf2:3347 with SMTP id 2adb3069b0e04-53df00d1b4emr1395380e87.21.1732711821608; Wed, 27 Nov 2024 04:50:21 -0800 (PST) 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/6] xen/riscv: implement relocate_fdt() Date: Wed, 27 Nov 2024 13:50:14 +0100 Message-ID: X-Mailer: git-send-email 2.47.0 In-Reply-To: References: MIME-Version: 1.0 relocate_fdt() relocates FDT to Xen heap instead of using early mapping as it is expected that discard_initial_modules() ( is supposed to call in the future ) discards the FDT boot module and remove_early_mappings() destroys the early mapping. To implement that the following things are introduced as they are called by internals of xmalloc_bytes() which is used in relocate_fdt(): 1. As RISC-V may have non-coherent access for RAM ( f.e., in case of non-coherent IO devices ) flush_page_to_ram() is implemented to ensure that cache and RAM are consistent for such platforms. 2. copy_from_paddr() to copy FDT from a physical address to allocated by xmalloc_bytes() in Xen heap. 3. virt_to_page() to convert virtual address to page. Also introduce directmap_virt_end to check that VA argument of virt_to_page() is inside directmap region. Signed-off-by: Oleksii Kurochko --- xen/arch/riscv/include/asm/mm.h | 10 ++++++-- xen/arch/riscv/include/asm/page.h | 10 ++++++-- xen/arch/riscv/mm.c | 3 +++ xen/arch/riscv/setup.c | 41 +++++++++++++++++++++++++++++++ 4 files changed, 60 insertions(+), 4 deletions(-) diff --git a/xen/arch/riscv/include/asm/mm.h b/xen/arch/riscv/include/asm/mm.h index 699ed23f0d..25fd38531f 100644 --- a/xen/arch/riscv/include/asm/mm.h +++ b/xen/arch/riscv/include/asm/mm.h @@ -8,11 +8,13 @@ #include #include #include +#include #include #include extern vaddr_t directmap_virt_start; +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)) @@ -148,8 +150,12 @@ static inline void *page_to_virt(const struct page_info *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 = (unsigned long)v; + + ASSERT(va >= DIRECTMAP_VIRT_START); + ASSERT(va <= directmap_virt_end); + + return frametable_virt_start + PFN_DOWN(va - directmap_virt_start); } /* diff --git a/xen/arch/riscv/include/asm/page.h b/xen/arch/riscv/include/asm/page.h index 0f297141d3..c245a4273f 100644 --- a/xen/arch/riscv/include/asm/page.h +++ b/xen/arch/riscv/include/asm/page.h @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -172,10 +173,15 @@ 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) -/* TODO: Flush the dcache for an entire page. */ static inline void flush_page_to_ram(unsigned long mfn, bool sync_icache) { - BUG_ON("unimplemented"); + void *v = map_domain_page(_mfn(mfn)); + + clean_and_invalidate_dcache_va_range(v, PAGE_SIZE); + unmap_domain_page(v); + + if ( sync_icache ) + invalidate_icache(); } /* Write a pagetable entry. */ diff --git a/xen/arch/riscv/mm.c b/xen/arch/riscv/mm.c index f2bf279bac..c614d547a6 100644 --- a/xen/arch/riscv/mm.c +++ b/xen/arch/riscv/mm.c @@ -419,6 +419,7 @@ void * __init early_fdt_map(paddr_t fdt_paddr) } vaddr_t __ro_after_init directmap_virt_start = DIRECTMAP_VIRT_START; +vaddr_t __ro_after_init directmap_virt_end; struct page_info *__ro_after_init frametable_virt_start = frame_table; @@ -556,6 +557,8 @@ void __init setup_mm(void) setup_directmap_mappings(PFN_DOWN(bank_start), PFN_DOWN(bank_size)); } + directmap_virt_end = directmap_virt_start + ram_end - 1; + setup_frametable_mappings(ram_start, ram_end); max_page = PFN_DOWN(ram_end); } diff --git a/xen/arch/riscv/setup.c b/xen/arch/riscv/setup.c index 9680332fee..ff667260ec 100644 --- a/xen/arch/riscv/setup.c +++ b/xen/arch/riscv/setup.c @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -26,6 +27,46 @@ void arch_get_xen_caps(xen_capabilities_info_t *info) unsigned char __initdata cpu0_boot_stack[STACK_SIZE] __aligned(STACK_SIZE); +/** + * 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) +{ + void *src = (void *)FIXMAP_ADDR(FIX_MISC); + + while (len) { + unsigned long l, s; + + s = paddr & (PAGE_SIZE - 1); + l = min(PAGE_SIZE - s, len); + + set_fixmap(FIX_MISC, maddr_to_mfn(paddr), PAGE_HYPERVISOR_RW); + memcpy(dst, src + s, l); + clean_dcache_va_range(dst, l); + clear_fixmap(FIX_MISC); + + paddr += l; + dst += l; + len -= l; + } +} + +/* Relocate the FDT in Xen heap */ +static void * __init relocate_fdt(paddr_t dtb_paddr, size_t dtb_size) +{ + void *fdt = xmalloc_bytes(dtb_size); + + if ( !fdt ) + panic("Unable to allocate memory for relocating the Device-Tree.\n"); + + copy_from_paddr(fdt, dtb_paddr, dtb_size); + + return fdt; +} + void __init noreturn start_xen(unsigned long bootcpu_id, paddr_t dtb_addr) { From patchwork Wed Nov 27 12:50:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksii Kurochko X-Patchwork-Id: 13886983 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 44554D6ACCB for ; Wed, 27 Nov 2024 12:50:41 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.844753.1260280 (Exim 4.92) (envelope-from ) id 1tGHUw-0005Fk-Or; Wed, 27 Nov 2024 12:50:26 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 844753.1260280; Wed, 27 Nov 2024 12:50:26 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tGHUw-0005Fd-Lr; Wed, 27 Nov 2024 12:50:26 +0000 Received: by outflank-mailman (input) for mailman id 844753; Wed, 27 Nov 2024 12:50:25 +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 1tGHUv-0004Yj-DE for xen-devel@lists.xenproject.org; Wed, 27 Nov 2024 12:50:25 +0000 Received: from mail-lj1-x230.google.com (mail-lj1-x230.google.com [2a00:1450:4864:20::230]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 2aa996f1-acbe-11ef-a0cd-8be0dac302b0; Wed, 27 Nov 2024 13:50:23 +0100 (CET) Received: by mail-lj1-x230.google.com with SMTP id 38308e7fff4ca-2ffbf4580cbso37749101fa.2 for ; Wed, 27 Nov 2024 04:50:23 -0800 (PST) Received: from fedora.. ([94.75.70.14]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53dd8cb7f00sm2023267e87.7.2024.11.27.04.50.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Nov 2024 04:50:22 -0800 (PST) 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: 2aa996f1-acbe-11ef-a0cd-8be0dac302b0 X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjoyMzAiLCJoZWxvIjoibWFpbC1sajEteDIzMC5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6IjJhYTk5NmYxLWFjYmUtMTFlZi1hMGNkLThiZTBkYWMzMDJiMCIsInRzIjoxNzMyNzExODIzLjMxMTE4Mywic2VuZGVyIjoib2xla3NpaS5rdXJvY2hrb0BnbWFpbC5jb20iLCJyZWNpcGllbnQiOiJ4ZW4tZGV2ZWxAbGlzdHMueGVucHJvamVjdC5vcmcifQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732711822; x=1733316622; 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=Vrv773z0JqGv9oIsUDba+C5p6taAtv0iDKAnsKPcYoI=; b=LhytWryzAi2z1mUniaSy5r+NVQN3dgrEseq6ovCbxxAtW+jbEr/MYzBmHN5G6Orcdm bxGxB8NHvjx5QKioCTGPolYd346qz9fRON0tAAkAaPjzyQki6w6A0XqlUPAjTRIHNC+n dUFXy6PxiIMV3AKIduIx2t1t4E955jJuiRA19F1wqtJtcLBqw+Or+pWpcelDOkuuQA/h 0EYT6TTLT6+BFPnK6kFpKa0eMt9+FdSJatAb+skQxUenE7s14JJBUzuTUINVaekXO3WH ROX/6iz5zY/GZAz8Zj4IaLbblAGd1INo8BphaTvCexypyyfmAya7GztzlCbD6a/9c+hz KkhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732711822; x=1733316622; 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=Vrv773z0JqGv9oIsUDba+C5p6taAtv0iDKAnsKPcYoI=; b=I0ArdO0VOUbE26nZe0rtwpaycu76TWfzYPL9PRYUS3wPgZMSmeVLsn5xUmYbl0C4m7 wbRrf1rxPIi8XQXvnrAvsRYFPQ7Aq5ouuyYuJdRjbtQRk62IlFIUY44OiaajrtCi2WMI T98U/HrilazIbJKGr17ZtQNjxIvGSS7z88AsVZqMPSZr80O5D0tUJ9HXRO2b6vldD3iz yRXgWWOpP3ir5fPHt1n+c9cy04A8b5vThU/1buO5aQ1l+cfwCdcOR/EsAsbVu6IyUbD7 oZscNepn2ckEa7vJzgY0Y+C/k1oxSfo2GNGNxgX+jEI7yzJxhwaETPndLL7OC6VVbemy xKeQ== X-Gm-Message-State: AOJu0YyfbJi12W1Li88QpKJqVh9aZrhMVRQvN02pard87n1hU7qvi8Yu Nt6vG6t7/V+UC5RQpSsn+k7iomxOIF/JBy3fEhNb2FnFb3+p999MCbxJLw== X-Gm-Gg: ASbGncszydlCWDVprCKThX4BYxXV5xBL74VCBF15oO8FVuD0fMdi7/Ou14j8xv6Dt32 YIFIh5sDniL2KJTnhqv/+Kl0HMnnwdu9EtYqB+DIJJuXrPixS9jaPrEsjs/zaqsOMoIme1ljmYz pr2EkKLsV7mm/f9KolAs0/7C4QPDHhC3IGyc0fBVnswOSgAOW6msS95e2b7zBt8z50/hmPMO8fd 0eMjvji+lagoY1+92+hJFnrUSDq+wobOzWnyRelJp2zi5/P8IM= X-Google-Smtp-Source: AGHT+IE9bfCGlBS0Z97uejBtcSyuwPDsOaYmpPjkGjm194/zDDwgrAHW3K9bwnEofHxmK3t4h5eLeg== X-Received: by 2002:a05:6512:238c:b0:53c:759f:3b71 with SMTP id 2adb3069b0e04-53df00d9d87mr1397415e87.31.1732711822276; Wed, 27 Nov 2024 04:50:22 -0800 (PST) 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 6/6] xen/riscv: relocating and unflattening host device tree Date: Wed, 27 Nov 2024 13:50:15 +0100 Message-ID: X-Mailer: git-send-email 2.47.0 In-Reply-To: References: MIME-Version: 1.0 Relocate FDT to Xen heap instead of using early mapping as it is expected that discard_initial_modules() ( is supposed to call in the future ) discards the FDT boot module and remove_early_mappings() destroys the early mapping. Unflatten a device tree, creating the tree of struct device_node. It also fills the "name" and "type" pointers of the nodes so the normal device-tree walking functions can be used. Set device_tree_flattened to NULL in the case when acpi_disabled is equal to false. Signed-off-by: Oleksii Kurochko --- xen/arch/riscv/setup.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/xen/arch/riscv/setup.c b/xen/arch/riscv/setup.c index ff667260ec..41826f77fb 100644 --- a/xen/arch/riscv/setup.c +++ b/xen/arch/riscv/setup.c @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0-only */ +#include #include #include #include @@ -71,6 +72,7 @@ void __init noreturn start_xen(unsigned long bootcpu_id, paddr_t dtb_addr) { const char *cmdline; + size_t fdt_size; remove_identity_mapping(); @@ -95,7 +97,7 @@ void __init noreturn start_xen(unsigned long bootcpu_id, _end - _start, false) ) panic("Failed to add BOOTMOD_XEN\n"); - if ( !boot_fdt_info(device_tree_flattened, dtb_addr) ) + if ( !(fdt_size = boot_fdt_info(device_tree_flattened, dtb_addr)) ) BUG(); cmdline = boot_fdt_cmdline(device_tree_flattened); @@ -114,6 +116,18 @@ void __init noreturn start_xen(unsigned long bootcpu_id, */ system_state = SYS_STATE_boot; + if ( acpi_disabled ) + { + printk("Booting using Device Tree\n"); + device_tree_flattened = relocate_fdt(dtb_addr, fdt_size); + dt_unflatten_host_device_tree(); + } + else + { + device_tree_flattened = NULL; + panic("Booting using ACPI isn't supported\n"); + } + printk("All set up\n"); machine_halt();