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 B6A99C0219D for ; Mon, 10 Feb 2025 08:46:30 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.884417.1294118 (Exim 4.92) (envelope-from ) id 1thPQt-0005ZE-85; Mon, 10 Feb 2025 08:46:23 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 884417.1294118; Mon, 10 Feb 2025 08:46:23 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1thPQt-0005Z7-5D; Mon, 10 Feb 2025 08:46:23 +0000 Received: by outflank-mailman (input) for mailman id 884417; Mon, 10 Feb 2025 08:46:21 +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 1thPQr-0005Yz-NJ for xen-devel@lists.xenproject.org; Mon, 10 Feb 2025 08:46:21 +0000 Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [2a00:1450:4864:20::134]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 80302715-e78b-11ef-a075-877d107080fb; Mon, 10 Feb 2025 09:46:20 +0100 (CET) Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-54504f5cfe9so1606557e87.0 for ; Mon, 10 Feb 2025 00:46:20 -0800 (PST) Received: from [192.168.209.66] ([94.75.70.14]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5450b29eff6sm322829e87.191.2025.02.10.00.46.19 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 10 Feb 2025 00:46: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: 80302715-e78b-11ef-a075-877d107080fb DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739177180; x=1739781980; darn=lists.xenproject.org; h=in-reply-to:from:content-language:references:cc:to:subject :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=hEebn1ngqTdBDgjie4K+90PEvpvvHcWRH9GxQ5O8rUE=; b=DoHYyh81VdAx1u2o3RbPV5/ZtzcV/LOikJTefTX0R5r1uNEg49JB5u/0I7jn/kqOWQ mkUTnVeVu0KBPngObzYD+ml1VlaMiIoJy3njtlDEQ1WCXKQi1OAeKmhUyJIFNJu+0PQW uwa+8lIs1fApuQq3LACBlOxTIqlhnI+a3ZHBq2ogWOPt6FKtobsa1GC9LAI3UTUpXtsJ 0KVExvlAnH5ZBV3M7zePZNsqsMm8wh64W6phyTU1C+Gs88EdijwPs4vDbfZ5X0VQi8lg Yc8YN1Y5culsjUmu2B6DupSRGB3Rw86QyXUwNNA+2pW5awSmwfmTdfHHWNqZiAhmEPV9 sNjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739177180; x=1739781980; h=in-reply-to:from:content-language:references:cc:to:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=hEebn1ngqTdBDgjie4K+90PEvpvvHcWRH9GxQ5O8rUE=; b=rUEnpOCFixiHR2Ga/ncBcxOWF+AZTVPPcuEyxdrQiiO1OtHwDGH9TeqzfZt0r2FYSV 4q4/42aA22uMzP1iuv1mYD8GufLtc7EfUXDFgeYa+StroCxev6OHu/0CUio1r6sq18lA Wv5gRjoSPDrlNCiwOAjdusql9wCddSHl7ULywvzqA+cZRRJNmXlZia+7bWvBTeojQbJv aK1fqcNf8bvoVjCn1rL5D90ws0EKeTXmL9KeHiwVpY9jRtWwDU6bIqHd0bdF3pBu0/MP 5o8jk3I9u4GWUF15pjd7hqTOmyfFnP5+nn4tW9uX9wJO64mUX2QhBrj6pAvQiqGaf56a PNRg== X-Forwarded-Encrypted: i=1; AJvYcCW/N0B3LWkX4AsmKcGgBbdSppSXYJ71ueJfmcT7GUXHFUgjCtLTv9LVWH3UK98eWsXMFy3KJC6l3m0=@lists.xenproject.org X-Gm-Message-State: AOJu0YzAm9cAF49z2P8WHaRhV4WhFjwkG8fBXBYvFhwu/0lkN2DcSHDL LkmA3bohy7Bu1wV/tdi7/BEx2V+P6EppfUL2K3oZxH9fjryvNMlT X-Gm-Gg: ASbGnctvsJbN0uRTgd3xcKGizIlNrCZrLt9df29lG8Omj924Al9aY+SP7oUO7YKoBA9 3fS/VcHNUXxfkwzkqL7RVhRjwbHEgLAY0cqkybdIX978flRHi7BDP5kG0ZjLqxLyHlSiYCmV433 UOLs4nAZhtK4k/4FUjyQN8u0oFBFVa7WuXgyyAsbtrRN9Bi8mIz3GHRE7uz116Y5fY+md+w9tgP A4GPgMUa1S4egtVbrTy1f66bONYoCozi2KX+moAtLqF0EbWMT58wGCDs74ZzB3wcFW6QWDioSps I7VMeLA8uGuSfwvnSOv1xcX44YI= X-Google-Smtp-Source: AGHT+IFu1sBRFdexNvQpat/byr63FSh7VJedK1k/8Vkz4v59S5nHB1ODCw52YCkSJcZC/cq1QS67uw== X-Received: by 2002:a05:6512:10cf:b0:545:ec1:9fd3 with SMTP id 2adb3069b0e04-5450ec1a033mr402013e87.9.1739177180003; Mon, 10 Feb 2025 00:46:20 -0800 (PST) Content-Type: multipart/alternative; boundary="------------k0PR9etEMrto89tCj6YZ9BCZ" Message-ID: Date: Mon, 10 Feb 2025 09:46:19 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH for 4.20? v3 2/3] xen/riscv: update defintion of vmap_to_mfn() To: Jan Beulich Cc: Alistair Francis , Bob Eshleman , Connor Davis , Andrew Cooper , Anthony PERARD , Michal Orzel , Julien Grall , =?UTF-8?Q?Roger_Pau_Monn=C3=A9?= , Stefano Stabellini , xen-devel@lists.xenproject.org References: <26deedab-b48c-4000-9937-b6b168fd590b@suse.com> Content-Language: en-US From: Oleksii Kurochko In-Reply-To: <26deedab-b48c-4000-9937-b6b168fd590b@suse.com> This is a multi-part message in MIME format. --------------k0PR9etEMrto89tCj6YZ9BCZ Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 2/7/25 2:30 PM, Jan Beulich wrote: > On 07.02.2025 14:13, Oleksii Kurochko wrote: >> vmap_to_mfn() uses virt_to_maddr(), which is designed to work with VA from >> either the direct map region or Xen's linkage region (XEN_VIRT_START). >> An assertion will occur if it is used with other regions, in particular for >> the VMAP region. >> >> Since RISC-V lacks a hardware feature to request the MMU to translate a VA to >> a PA (as Arm does, for example), software page table walking (pt_walk()) is >> used for the VMAP region to obtain the mfn from pte_t. >> >> To avoid introduce a circular dependency between asm/mm.h and asm/page.h by >> including each other, the macro _vmap_to_mfn() is introduced in asm/page.h, >> as it uses struct pte_t and pte_is_mapping() from asm/page.h. _vmap_to_mfn() >> macro is then reused in the definition of vmap_to_mfn() macro in asm/mm.h. >> >> Fixes: 7db8d2bd9b ("xen/riscv: add minimal stuff to mm.h to build full Xen") >> Signed-off-by: Oleksii Kurochko >> --- >> Changes in v3: >> - Move vmap_to_mfn_ to asm/page.h to deal with circular dependency. >> - Convert vmap_to_mfn_() to macros. > Why both? Just for consistency. vmap_to_mfn_() could be defined as static inline, I can send the new patch version with such changes, probably, static inline would be better in this case. >> --- a/xen/arch/riscv/include/asm/page.h >> +++ b/xen/arch/riscv/include/asm/page.h >> @@ -210,6 +210,13 @@ static inline pte_t pte_from_mfn(mfn_t mfn, unsigned int flags) >> >> pte_t pt_walk(vaddr_t va, unsigned int *pte_level); >> >> +#define _vmap_to_mfn(va) \ >> +({ \ >> + pte_t entry = pt_walk((va), NULL); \ > If this is to remain a macro, va doesn't need parenthesizing (as the argument > passed is just the identifier, not an expression. > > Be careful with the naming of macro local variables. Consider a use size (for > whatever reason) having > > unsigned long entry; > ... > mfn = vmap_to_mfn(entry); > > This is where appending an underscore comes into play. This could be another reason to use|static inline _vmap_to_mfn(...)| instead of a macro. I think I will rewrite the|_vmap_to_mfn()| macro as a|static inline| function in the next patch series version. I'll send it after receiving comments on the entire patch series. Thanks. ~ Oleksii --------------k0PR9etEMrto89tCj6YZ9BCZ Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit


On 2/7/25 2:30 PM, Jan Beulich wrote:
On 07.02.2025 14:13, Oleksii Kurochko wrote:
vmap_to_mfn() uses virt_to_maddr(), which is designed to work with VA from
either the direct map region or Xen's linkage region (XEN_VIRT_START).
An assertion will occur if it is used with other regions, in particular for
the VMAP region.

Since RISC-V lacks a hardware feature to request the MMU to translate a VA to
a PA (as Arm does, for example), software page table walking (pt_walk()) is
used for the VMAP region to obtain the mfn from pte_t.

To avoid introduce a circular dependency between asm/mm.h and asm/page.h by
including each other, the macro _vmap_to_mfn() is introduced in asm/page.h,
as it uses struct pte_t and pte_is_mapping() from asm/page.h. _vmap_to_mfn()
macro is then reused in the definition of vmap_to_mfn() macro in asm/mm.h.

Fixes: 7db8d2bd9b ("xen/riscv: add minimal stuff to mm.h to build full Xen")
Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
---
Changes in v3:
- Move vmap_to_mfn_ to asm/page.h to deal with circular dependency.
- Convert vmap_to_mfn_() to macros.
Why both?
Just for consistency. vmap_to_mfn_() could be defined as static inline, I can
send the new patch version with such changes, probably, static inline would be
better in this case.


      
--- a/xen/arch/riscv/include/asm/page.h
+++ b/xen/arch/riscv/include/asm/page.h
@@ -210,6 +210,13 @@ static inline pte_t pte_from_mfn(mfn_t mfn, unsigned int flags)
 
 pte_t pt_walk(vaddr_t va, unsigned int *pte_level);
 
+#define _vmap_to_mfn(va)                \
+({                                      \
+    pte_t entry = pt_walk((va), NULL);  \
If this is to remain a macro, va doesn't need parenthesizing (as the argument
passed is just the identifier, not an expression.

Be careful with the naming of macro local variables. Consider a use size (for
whatever reason) having

    unsigned long entry;
    ...
    mfn = vmap_to_mfn(entry);

This is where appending an underscore comes into play.
This could be another reason to use static inline _vmap_to_mfn(...) instead of a macro.

I think I will rewrite the _vmap_to_mfn() macro as a static inline function in the next
patch series version. I'll send it after receiving comments on the entire patch series.

Thanks.

~ Oleksii
--------------k0PR9etEMrto89tCj6YZ9BCZ--