From: Tom Rini <trini@konsulko.com>
To: Simon Glass <sjg@chromium.org>
Cc: "Ilias Apalodimas" <ilias.apalodimas@linaro.org>,
"Heinrich Schuchardt" <xypron.glpk@gmx.de>,
"Alexey Brodkin" <alexey.brodkin@synopsys.com>,
"Eugeniy Paltsev" <Eugeniy.Paltsev@synopsys.com>,
"Caleb Connolly" <caleb.connolly@linaro.org>,
"Neil Armstrong" <neil.armstrong@linaro.org>,
"Sumit Garg" <sumit.garg@linaro.org>,
"Huan Wang" <alison.wang@nxp.com>,
"Angelo Dureghello" <angelo@kernel-space.org>,
"Thomas Chou" <thomas@wytron.com.tw>,
"Rick Chen" <rick@andestech.com>, Leo <ycliang@andestech.com>,
"Marek Vasut" <marex@denx.de>,
"Nobuhiro Iwamatsu" <iwamatsu@nigauri.org>,
"Max Filippov" <jcmvbkbc@gmail.com>,
"Sughosh Ganu" <sughosh.ganu@linaro.org>,
"Sam Protsenko" <semen.protsenko@linaro.org>,
"Pierre-Clément Tosi" <ptosi@google.com>,
"Peng Fan" <peng.fan@nxp.com>,
"Richard Henderson" <richard.henderson@linaro.org>,
"Sam Edwards" <CFSworks@gmail.com>,
"Jerome Forissier" <jerome.forissier@linaro.org>,
"Andre Przywara" <andre.przywara@arm.com>,
"Peter Hoyes" <Peter.Hoyes@arm.com>,
"Patrick Rudolph" <patrick.rudolph@9elements.com>,
"Sam Day" <me@samcday.com>,
"Mayuresh Chitale" <mchitale@ventanamicro.com>,
"Mattijs Korpershoek" <mkorpershoek@baylibre.com>,
"Stefan Roese" <sr@denx.de>,
"Alex Shumsky" <alexthreed@gmail.com>,
"Jiaxun Yang" <jiaxun.yang@flygoat.com>,
"Joshua Watt" <jpewhacker@gmail.com>,
"Jagan Teki" <jagan@amarulasolutions.com>,
"Evgeny Bachinin" <EABachinin@salutedevices.com>,
"Peter Robinson" <pbrobinson@gmail.com>,
"Christian Marangi" <ansuelsmth@gmail.com>,
"Michal Simek" <michal.simek@amd.com>,
"Jonas Jelonek" <jelonek.jonas@gmail.com>,
uboot-snps-arc@synopsys.com, u-boot@lists.denx.de,
u-boot-qcom@groups.io
Subject: Re: [PATCH v1 5/6] treewide: Add a function to change page permissions
Date: Sun, 9 Feb 2025 10:37:57 -0600 [thread overview]
Message-ID: <20250209163757.GL1233568@bill-the-cat> (raw)
In-Reply-To: <CAFLszTiESUm8bqdqZdaLDTz65UXpyTLxm+rCoViZMchO4QWY4g@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 5692 bytes --]
On Thu, Feb 06, 2025 at 05:30:43AM -0700, Simon Glass wrote:
> Hi Ilias,
>
> On Wed, 5 Feb 2025 at 09:54, Ilias Apalodimas
> <ilias.apalodimas@linaro.org> wrote:
> >
> > Hi Heinrich,
> >
> > On Wed, 5 Feb 2025 at 18:48, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
> > >
> > > On 2/5/25 08:16, Ilias Apalodimas wrote:
> > > > For armv8 we are adding proper page permissions for the relocated U-Boot
> > > > binary. Add a weak function that can be used across architectures to change
> > > > the page permissions
> > > >
> > > > Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
> > > > ---
> > > > arch/arc/lib/cache.c | 2 ++
> > > > arch/arm/cpu/arm926ejs/cache.c | 2 ++
> > > > arch/arm/cpu/armv7/cache_v7.c | 1 +
> > > > arch/arm/cpu/armv7m/cache.c | 2 ++
> > > > arch/arm/cpu/armv8/cache_v8.c | 22 ++++++++++++++++++++++
> > > > arch/arm/lib/cache.c | 2 ++
> > > > arch/m68k/lib/cache.c | 2 ++
> > > > arch/nios2/lib/cache.c | 2 ++
> > > > arch/powerpc/lib/cache.c | 2 ++
> > > > arch/riscv/lib/cache.c | 2 ++
> > > > arch/sh/cpu/sh4/cache.c | 2 ++
> > > > arch/xtensa/lib/cache.c | 2 ++
> > > > include/cpu_func.h | 16 ++++++++++++++++
> > > > 13 files changed, 59 insertions(+)
> > > >
> > > > diff --git a/arch/arc/lib/cache.c b/arch/arc/lib/cache.c
> > > > index 5169fc627fa5..5c79243d7223 100644
> > > > --- a/arch/arc/lib/cache.c
> > > > +++ b/arch/arc/lib/cache.c
> > > > @@ -819,3 +819,5 @@ void sync_n_cleanup_cache_all(void)
> > > >
> > > > __ic_entire_invalidate();
> > > > }
> > > > +
> > > > +void __weak pgprot_set_attrs(phys_addr_t addr, size_t size, u64 perm) {}
> > > > diff --git a/arch/arm/cpu/arm926ejs/cache.c b/arch/arm/cpu/arm926ejs/cache.c
> > > > index 5b87a3af91b2..857311b3dfad 100644
> > > > --- a/arch/arm/cpu/arm926ejs/cache.c
> > > > +++ b/arch/arm/cpu/arm926ejs/cache.c
> > > > @@ -88,3 +88,5 @@ void enable_caches(void)
> > > > dcache_enable();
> > > > #endif
> > > > }
> > > > +
> > > > +void __weak pgprot_set_attrs(phys_addr_t addr, size_t size, u64 perm) {}
> > > > diff --git a/arch/arm/cpu/armv7/cache_v7.c b/arch/arm/cpu/armv7/cache_v7.c
> > > > index d11420d2fdd0..14c9be77db8d 100644
> > > > --- a/arch/arm/cpu/armv7/cache_v7.c
> > > > +++ b/arch/arm/cpu/armv7/cache_v7.c
> > > > @@ -209,3 +209,4 @@ __weak void v7_outer_cache_flush_all(void) {}
> > > > __weak void v7_outer_cache_inval_all(void) {}
> > > > __weak void v7_outer_cache_flush_range(u32 start, u32 end) {}
> > > > __weak void v7_outer_cache_inval_range(u32 start, u32 end) {}
> > > > +__weak void pgprot_set_attrs(phys_addr_t addr, size_t size, u64 perm) {}
> > > > diff --git a/arch/arm/cpu/armv7m/cache.c b/arch/arm/cpu/armv7m/cache.c
> > > > index b6d08b7aad73..458a214e9577 100644
> > > > --- a/arch/arm/cpu/armv7m/cache.c
> > > > +++ b/arch/arm/cpu/armv7m/cache.c
> > > > @@ -370,3 +370,5 @@ void enable_caches(void)
> > > > dcache_enable();
> > > > #endif
> > > > }
> > > > +
> > > > +void __weak pgprot_set_attrs(phys_addr_t addr, size_t size, u64 perm) {}
> > > > diff --git a/arch/arm/cpu/armv8/cache_v8.c b/arch/arm/cpu/armv8/cache_v8.c
> > > > index 670379e17b7a..1cf3870177ee 100644
> > > > --- a/arch/arm/cpu/armv8/cache_v8.c
> > > > +++ b/arch/arm/cpu/armv8/cache_v8.c
> > > > @@ -1028,6 +1028,28 @@ skip_break:
> > > > __asm_invalidate_tlb_all();
> > > > }
> > > >
> > > > +void pgprot_set_attrs(phys_addr_t addr, size_t size, u64 perm)
> > > > +{
> > > > + u64 attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | PTE_BLOCK_INNER_SHARE | PTE_TYPE_VALID;
> > > > +
> > > > + switch (perm) {
> > > > + case MMU_ATTR_RO:
> > > > + attrs |= PTE_BLOCK_PXN | PTE_BLOCK_UXN | PTE_BLOCK_RO;
> > > > + break;
> > > > + case MMU_ATTR_RX:
> > > > + attrs |= PTE_BLOCK_RO;
> > > > + break;
> > > > + case MMU_ATTR_RW:
> > > > + attrs |= PTE_BLOCK_PXN | PTE_BLOCK_UXN;
> > > > + break;
> > > > + default:
> > > > + log_err("Unknown attribute %llx\n", perm);
> > > > + return;
> > > > + }
> > > > +
> > > > + mmu_change_region_attr(addr, size, attrs, false);
> > > > +}
> > > > +
> > > > #else /* !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */
> > > >
> > > > /*
> > > > diff --git a/arch/arm/lib/cache.c b/arch/arm/lib/cache.c
> > > > index 516754caeaf9..c7704d8ee354 100644
> > > > --- a/arch/arm/lib/cache.c
> > > > +++ b/arch/arm/lib/cache.c
> > > > @@ -170,3 +170,5 @@ __weak int arm_reserve_mmu(void)
> > > >
> > > > return 0;
> > > > }
> > > > +
> > > > +void __weak pgprot_set_attrs(phys_addr_t addr, size_t size, u64 perm) {}
> > >
> > > I would prefer if the weak function would return -ENOSYS indicating the
> > > missing implementation and the real function would return 0 in case of
> > > success or an error code on failure. This way the EFI protocol could set
> > > the return code if the architecture does not provide support for setting
> > > the attributes the passed addresses are invalid.
> >
> > Sure I'll change that in v2
>
> Instead of a weak function could you define an API for it, including
> structs for the information, a command to adjust it, tests, etc? This
> needs a little more thought.
This is an API. It's just not part of DM because it's frankly
inappropriate to be configuring part of the MMU ASAP only once we've got
our device tree parsed. DM and a uclass is not always the right
abstraction.
--
Tom
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]
next prev parent reply other threads:[~2025-02-09 21:36 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-05 7:16 [PATCH v1 0/6] Fix page permission on arm64 architectures Ilias Apalodimas
2025-02-05 7:16 ` [PATCH v1 1/6] meminfo: add memory details for armv8 Ilias Apalodimas
2025-02-05 9:27 ` Jerome Forissier
2025-02-05 10:32 ` Ilias Apalodimas
2025-02-11 21:08 ` Caleb Connolly
2025-02-05 7:16 ` [PATCH v1 2/6] doc: update meminfo with arch specific information Ilias Apalodimas
2025-02-05 17:22 ` Tom Rini
2025-02-05 17:35 ` Ilias Apalodimas
2025-02-06 12:31 ` Simon Glass
2025-02-06 12:32 ` Ilias Apalodimas
2025-02-05 7:16 ` [PATCH v1 3/6] arm: Prepare linker scripts for memory permissions Ilias Apalodimas
2025-02-05 8:22 ` Ilias Apalodimas
2025-02-05 12:41 ` Michal Simek
2025-02-05 13:11 ` Ilias Apalodimas
2025-02-05 19:03 ` Tom Rini
2025-02-05 17:23 ` Richard Henderson
2025-02-05 17:34 ` Ilias Apalodimas
2025-02-05 17:33 ` Tom Rini
2025-02-05 19:18 ` Ilias Apalodimas
2025-02-05 19:25 ` Tom Rini
2025-02-05 21:35 ` Ilias Apalodimas
2025-02-05 7:16 ` [PATCH v1 4/6] arm64: mmu_change_region_attr() add an option not to break PTEs Ilias Apalodimas
2025-02-05 7:16 ` [PATCH v1 5/6] treewide: Add a function to change page permissions Ilias Apalodimas
2025-02-05 16:47 ` Heinrich Schuchardt
2025-02-05 16:54 ` Ilias Apalodimas
2025-02-06 9:42 ` Ilias Apalodimas
2025-02-06 10:38 ` Heinrich Schuchardt
2025-02-06 12:30 ` Simon Glass
2025-02-06 12:51 ` Ilias Apalodimas
2025-02-06 12:58 ` Simon Glass
2025-02-06 15:15 ` Ilias Apalodimas
2025-02-06 15:47 ` Simon Glass
2025-02-06 16:21 ` Ilias Apalodimas
2025-02-09 14:35 ` Simon Glass
2025-02-09 16:36 ` Tom Rini
2025-02-09 16:39 ` Tom Rini
2025-02-09 20:15 ` Simon Glass
2025-02-09 20:27 ` Heinrich Schuchardt
2025-02-20 9:22 ` Ilias Apalodimas
2025-02-09 16:37 ` Tom Rini [this message]
2025-02-05 7:16 ` [PATCH v1 6/6] arm64: Enable RW, RX and RO mappings for the relocated binary Ilias Apalodimas
2025-02-05 9:57 ` Jerome Forissier
2025-02-05 10:31 ` Ilias Apalodimas
2025-02-05 19:17 ` Tom Rini
2025-02-06 8:33 ` [PATCH v1 0/6] Fix page permission on arm64 architectures Neil Armstrong
2025-02-06 12:33 ` Simon Glass
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=20250209163757.GL1233568@bill-the-cat \
--to=trini@konsulko.com \
--cc=CFSworks@gmail.com \
--cc=EABachinin@salutedevices.com \
--cc=Eugeniy.Paltsev@synopsys.com \
--cc=Peter.Hoyes@arm.com \
--cc=alexey.brodkin@synopsys.com \
--cc=alexthreed@gmail.com \
--cc=alison.wang@nxp.com \
--cc=andre.przywara@arm.com \
--cc=angelo@kernel-space.org \
--cc=ansuelsmth@gmail.com \
--cc=caleb.connolly@linaro.org \
--cc=ilias.apalodimas@linaro.org \
--cc=iwamatsu@nigauri.org \
--cc=jagan@amarulasolutions.com \
--cc=jcmvbkbc@gmail.com \
--cc=jelonek.jonas@gmail.com \
--cc=jerome.forissier@linaro.org \
--cc=jiaxun.yang@flygoat.com \
--cc=jpewhacker@gmail.com \
--cc=marex@denx.de \
--cc=mchitale@ventanamicro.com \
--cc=me@samcday.com \
--cc=michal.simek@amd.com \
--cc=mkorpershoek@baylibre.com \
--cc=neil.armstrong@linaro.org \
--cc=patrick.rudolph@9elements.com \
--cc=pbrobinson@gmail.com \
--cc=peng.fan@nxp.com \
--cc=ptosi@google.com \
--cc=richard.henderson@linaro.org \
--cc=rick@andestech.com \
--cc=semen.protsenko@linaro.org \
--cc=sjg@chromium.org \
--cc=sr@denx.de \
--cc=sughosh.ganu@linaro.org \
--cc=sumit.garg@linaro.org \
--cc=thomas@wytron.com.tw \
--cc=u-boot-qcom@groups.io \
--cc=u-boot@lists.denx.de \
--cc=uboot-snps-arc@synopsys.com \
--cc=xypron.glpk@gmx.de \
--cc=ycliang@andestech.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;
as well as URLs for NNTP newsgroup(s).