All of lore.kernel.org
 help / color / mirror / Atom feed
From: Catalin Marinas <catalin.marinas@arm.com>
To: Jinjiang Tu <tujinjiang@huawei.com>
Cc: akpm@linux-foundation.org, david@kernel.org, will@kernel.org,
	zengheng4@huawei.com, ryan.roberts@arm.com,
	anshuman.khandual@arm.com, wangkefeng.wang@huawei.com,
	linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org
Subject: Re: [PATCH v2] arm64: mm: fix pass user prot to ioremap_prot in generic_access_phys
Date: Thu, 29 Jan 2026 18:22:27 +0000	[thread overview]
Message-ID: <aXulY16Q16TYO06l@arm.com> (raw)
In-Reply-To: <c78b76c5-8709-44d0-85c3-feccd41b2ddd@huawei.com>

On Wed, Jan 28, 2026 at 03:12:56PM +0800, Jinjiang Tu wrote:
> 在 2026/1/27 17:01, Jinjiang Tu 写道:
> > diff --git a/arch/arm64/include/asm/io.h b/arch/arm64/include/asm/io.h
> > index 83e03abbb2ca..fe8607eafab6 100644
> > --- a/arch/arm64/include/asm/io.h
> > +++ b/arch/arm64/include/asm/io.h
> > @@ -267,6 +267,17 @@ int arm64_ioremap_prot_hook_register(const ioremap_prot_hook_t hook);
> >   #define ioremap_prot ioremap_prot
> > +#define arch_mk_kernel_prot arch_mk_kernel_prot
> > +static inline pgprot_t arch_mk_kernel_prot(pgprot_t user_prot)
> > +{
> > +	unsigned long kernel_prot_val;
> > +
> > +	kernel_prot_val = _PAGE_KERNEL & ~(PTE_WRITE | PTE_ATTRINDX_MASK);
> > +	kernel_prot_val |= pgprot_val(user_prot) & (PTE_WRITE | PTE_ATTRINDX_MASK);
> > +
> > +	return __pgprot(kernel_prot_val);
> > +}
> 
> I found I misunderstand the READ/WRITE permisson here.
> If the pte is writeale, the PTE_WRITE is 1, and PTE_RDONLY means dirty or not (With DBM).
> If the pte is read-only, the PTE_WRITE is 0, and PTE_RDONLY is 1.
> 
> Since generic_access_phys() have checked if the user can write with:
> 
> 		if ((write & FOLL_WRITE) && !pte_write(pte))
> 		return -EINVAL;
> 
> So, maybe we could always grant writable permission, just as x86's ioremap() does?

Yes, it gets tricky with the dirty/writeable bits and we may change this
in the future. We have follow_pfnmap_start() already checking the
permissions, so going for read/write access for the kernel mapping I
think makes sense. Just do something like:

	ptdesc_t mem_type = pgprot_val(user_prot) & PTE_ATTRINDX_MASK;

	return __pgprot_modify(PAGE_KERNEL, PTE_ATTRINDX_MASK, mem_type);

-- 
Catalin


      reply	other threads:[~2026-01-29 18:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-27  9:01 [PATCH v2] arm64: mm: fix pass user prot to ioremap_prot in generic_access_phys Jinjiang Tu
2026-01-27 21:10 ` Andrew Morton
2026-01-28  7:12 ` Jinjiang Tu
2026-01-29 18:22   ` Catalin Marinas [this message]

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=aXulY16Q16TYO06l@arm.com \
    --to=catalin.marinas@arm.com \
    --cc=akpm@linux-foundation.org \
    --cc=anshuman.khandual@arm.com \
    --cc=david@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-mm@kvack.org \
    --cc=ryan.roberts@arm.com \
    --cc=tujinjiang@huawei.com \
    --cc=wangkefeng.wang@huawei.com \
    --cc=will@kernel.org \
    --cc=zengheng4@huawei.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.