From: Conor Dooley <conor@kernel.org>
To: Alexandre Ghiti <alex@ghiti.fr>
Cc: Yunhui Cui <cuiyunhui@bytedance.com>,
paul.walmsley@sifive.com, palmer@dabbelt.com,
aou@eecs.berkeley.edu, ajones@ventanamicro.com,
alexghiti@rivosinc.com, anup@brainfault.org,
samitolvanen@google.com, rppt@kernel.org,
panqinglin2020@iscas.ac.cn, linux-riscv@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] riscv: put va_kernel_xip_pa_offset into CONFIG_XIP_KERNEL
Date: Wed, 20 Dec 2023 22:34:50 +0000 [thread overview]
Message-ID: <20231220-bash-booting-2dc46e8c41f7@spud> (raw)
In-Reply-To: <594df6bc-0207-46f6-aa81-dcf1f3665917@ghiti.fr>
[-- Attachment #1.1: Type: text/plain, Size: 3535 bytes --]
On Wed, Dec 20, 2023 at 10:14:59PM +0100, Alexandre Ghiti wrote:
> Hi Yunhui,
>
> On 20/12/2023 11:34, Yunhui Cui wrote:
> > opitmize the kernel_mapping_pa_to_va() and kernel_mapping_va_to_pa().
> >
> > Signed-off-by: Yunhui Cui <cuiyunhui@bytedance.com>
> > ---
> > arch/riscv/include/asm/page.h | 33 ++++++++++++++++++++-------------
> > 1 file changed, 20 insertions(+), 13 deletions(-)
> >
> > diff --git a/arch/riscv/include/asm/page.h b/arch/riscv/include/asm/page.h
> > index 5488ecc337b6..0d2b479d02cd 100644
> > --- a/arch/riscv/include/asm/page.h
> > +++ b/arch/riscv/include/asm/page.h
> > @@ -113,8 +113,8 @@ struct kernel_mapping {
> > unsigned long va_pa_offset;
> > /* Offset between kernel mapping virtual address and kernel load address */
> > unsigned long va_kernel_pa_offset;
> > - unsigned long va_kernel_xip_pa_offset;
> > #ifdef CONFIG_XIP_KERNEL
> > + unsigned long va_kernel_xip_pa_offset;
> > uintptr_t xiprom;
> > uintptr_t xiprom_sz;
> > #endif
> > @@ -134,12 +134,25 @@ extern phys_addr_t phys_ram_base;
> > #else
> > void *linear_mapping_pa_to_va(unsigned long x);
> > #endif
> > -#define kernel_mapping_pa_to_va(y) ({ \
> > - unsigned long _y = (unsigned long)(y); \
> > - (IS_ENABLED(CONFIG_XIP_KERNEL) && _y < phys_ram_base) ? \
> > - (void *)(_y + kernel_map.va_kernel_xip_pa_offset) : \
> > - (void *)(_y + kernel_map.va_kernel_pa_offset + XIP_OFFSET); \
> > - })
> > +
> > +#ifdef CONFIG_XIP_KERNEL
> > +#define kernel_mapping_pa_to_va(y) \
> > + (((unsigned long)(y) < phys_ram_base) ? \
> > + (void *)((unsigned long)(y) + kernel_map.va_kernel_xip_pa_offset) : \
> > + (void *)((unsigned long)(y) + kernel_map.va_kernel_pa_offset + XIP_OFFSET))
> > +
> > +#define kernel_mapping_va_to_pa(y) \
> > + (((unsigned long)(y) < kernel_map.virt_addr + XIP_OFFSET) ? \
> > + ((unsigned long)(y) - kernel_map.va_kernel_xip_pa_offset) : \
> > + ((unsigned long)(y) - kernel_map.va_kernel_pa_offset - XIP_OFFSET))
> > +#else
> > +#define kernel_mapping_pa_to_va(y) \
> > + ((void *)((unsigned long)(y) + kernel_map.va_kernel_pa_offset + XIP_OFFSET))
> > +
> > +#define kernel_mapping_va_to_pa(y) \
> > + ((unsigned long)(y) - kernel_map.va_kernel_pa_offset - XIP_OFFSET)
> > +#endif
> > +
> > #define __pa_to_va_nodebug(x) linear_mapping_pa_to_va(x)
> > #ifndef CONFIG_DEBUG_VIRTUAL
> > @@ -147,12 +160,6 @@ void *linear_mapping_pa_to_va(unsigned long x);
> > #else
> > phys_addr_t linear_mapping_va_to_pa(unsigned long x);
> > #endif
> > -#define kernel_mapping_va_to_pa(y) ({ \
> > - unsigned long _y = (unsigned long)(y); \
> > - (IS_ENABLED(CONFIG_XIP_KERNEL) && _y < kernel_map.virt_addr + XIP_OFFSET) ? \
> > - (_y - kernel_map.va_kernel_xip_pa_offset) : \
> > - (_y - kernel_map.va_kernel_pa_offset - XIP_OFFSET); \
> > - })
> > #define __va_to_pa_nodebug(x) ({ \
> > unsigned long _x = x; \
>
>
> Not sure using #ifdef optimizes anything since the compiler should do the
> same with the IS_ENABLED(CONFIG_XIP_KERNEL) and it does not really improve
> the readability of this file which is already overloaded with #ifdef, so I
> don't think this change is needed.
I would say that we explicitly do not want to move things that are
guarded by IS_ENABLED() to ifdeffery. In fact, we should move things in
the other direction if possible, especially for stuff like XIP_KERNEL
that nobody ever build tests.
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
[-- Attachment #2: Type: text/plain, Size: 161 bytes --]
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
next prev parent reply other threads:[~2023-12-20 22:35 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-20 10:34 [PATCH] riscv: put va_kernel_xip_pa_offset into CONFIG_XIP_KERNEL Yunhui Cui
2023-12-20 21:14 ` Alexandre Ghiti
2023-12-20 22:34 ` Conor Dooley [this message]
2023-12-21 1:51 ` [External] " yunhui cui
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231220-bash-booting-2dc46e8c41f7@spud \
--to=conor@kernel.org \
--cc=ajones@ventanamicro.com \
--cc=alex@ghiti.fr \
--cc=alexghiti@rivosinc.com \
--cc=anup@brainfault.org \
--cc=aou@eecs.berkeley.edu \
--cc=cuiyunhui@bytedance.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=palmer@dabbelt.com \
--cc=panqinglin2020@iscas.ac.cn \
--cc=paul.walmsley@sifive.com \
--cc=rppt@kernel.org \
--cc=samitolvanen@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox