[PATCH v9 07/10] arm64: Implement __set_direct_map*()

Thierry Reding thierry.reding at kernel.org
Tue Sep 8 02:27:23 PDT 2026


On Wed, Sep 02, 2026 at 11:47:09AM +0100, Vincent Donnefort wrote:
> Add implementation for the unsafe functions __set_direct_map*(). They do
> not verify for can_set_direct_map() and expect the caller to do so
> beforehand.
> 
> Signed-off-by: Vincent Donnefort <vdonnefort at google.com>
> 
> diff --git a/arch/arm64/include/asm/set_memory.h b/arch/arm64/include/asm/set_memory.h
> index 1a37f4ef130b..080a40846bbe 100644
> --- a/arch/arm64/include/asm/set_memory.h
> +++ b/arch/arm64/include/asm/set_memory.h
> @@ -16,6 +16,10 @@ int set_memory_valid(unsigned long addr, int numpages, int enable);
>  
>  int set_direct_map_invalid_noflush(struct page *page);
>  int set_direct_map_default_noflush(struct page *page);
> +int __set_direct_map_invalid_noflush(struct page *page);
> +#define __set_direct_map_invalid_noflush __set_direct_map_invalid_noflush
> +int __set_direct_map_default_noflush(struct page *page);
> +#define __set_direct_map_default_noflush __set_direct_map_default_noflush
>  int set_direct_map_valid_noflush(struct page *page, unsigned nr, bool valid);
>  bool kernel_page_present(struct page *page);
>  
> diff --git a/arch/arm64/mm/pageattr.c b/arch/arm64/mm/pageattr.c
> index c59ef17eb0d0..28adab0edace 100644
> --- a/arch/arm64/mm/pageattr.c
> +++ b/arch/arm64/mm/pageattr.c
> @@ -294,28 +294,38 @@ int set_memory_valid(unsigned long addr, int numpages, int enable)
>  					__pgprot(PTE_PRESENT_VALID_KERNEL));
>  }
>  
> -int set_direct_map_invalid_noflush(struct page *page)
> +int __set_direct_map_invalid_noflush(struct page *page)
>  {
>  	pgprot_t clear_mask = __pgprot(PTE_PRESENT_VALID_KERNEL);
>  	pgprot_t set_mask = __pgprot(PTE_PRESENT_INVALID);
>  
> +	return update_range_prot((unsigned long)page_address(page),
> +				 PAGE_SIZE, set_mask, clear_mask);
> +}

I think these would work quite nicely if you rebase the series onto
linux-next, which contains the patches that add the number of pages to
these functions.

You can then keep can_set_direct_map_range() from the previous patch and
call that from the set_direct_map_*_noflush() functions instead of the
simple can_set_direct_map() (which is a shortcut path in the _range
check anyway.

I've used that locally in my tree and it seems to be working just fine.

Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20260908/313398af/attachment-0001.sig>


More information about the linux-arm-kernel mailing list