[PATCH RFC v3 00/35] Add support for arm64 MTE dynamic tag storage reuse

2024-01-25 Thread Alexandru Elisei
_STORAGE=y - system_supports_mte() returns true - kasan_hw_tags_enabled() returns false - correct DTB node. For an example that works with FVP, have a look at patch #35 ("HACK! Add fake tag storage to fvp-base-revc.dts") Check dmesg for the message "MTE tag storage region management en

[PATCH RFC v3 01/35] mm: page_alloc: Add gfp_flags parameter to arch_alloc_page()

2024-01-25 Thread Alexandru Elisei
Extend the usefulness of arch_alloc_page() by adding the gfp_flags parameter. Signed-off-by: Alexandru Elisei --- Changes since rfc v2: * New patch. arch/s390/include/asm/page.h | 2 +- arch/s390/mm/page-states.c | 2 +- include/linux/gfp.h | 2 +- mm/page_alloc.c | 2

[PATCH RFC v3 02/35] mm: page_alloc: Add an arch hook early in free_pages_prepare()

2024-01-25 Thread Alexandru Elisei
add an arch_free_pages_prepare() hook that is called before that page flags are cleared. The function arch_free_page() has also been considered for this purpose, but it is called after the flags are cleared. Signed-off-by: Alexandru Elisei --- Changes since rfc v2: * Expanded commit message

[PATCH RFC v3 03/35] mm: page_alloc: Add an arch hook to filter MIGRATE_CMA allocations

2024-01-25 Thread Alexandru Elisei
pages cannot be tagged. The filter will be used to deny using MIGRATE_CMA for __GFP_TAGGED allocations. Signed-off-by: Alexandru Elisei --- include/linux/pgtable.h | 7 +++ mm/page_alloc.c | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/include/linux/pgtable.h b

[PATCH RFC v3 04/35] mm: page_alloc: Partially revert "mm: page_alloc: remove stale CMA guard code"

2024-01-25 Thread Alexandru Elisei
, so bring back the filter. This is a partially revert because the stale comment remains removed. Signed-off-by: Alexandru Elisei --- mm/page_alloc.c | 15 +++ 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index a96d47a6393e..0f

[PATCH RFC v3 05/35] mm: cma: Don't append newline when generating CMA area name

2024-01-25 Thread Alexandru Elisei
cma->name is displayed in several CMA messages. When the name is generated by the CMA code, don't append a newline to avoid breaking the text across two lines. Signed-off-by: Alexandru Elisei --- Changes since rfc v2: * New patch. This is a fix, and can be merged independently of t

[PATCH RFC v3 06/35] mm: cma: Make CMA_ALLOC_SUCCESS/FAIL count the number of pages

2024-01-25 Thread Alexandru Elisei
led to allocate. For users that wish to track the number of cma_alloc() calls, there are tracepoints for that already implemented. Signed-off-by: Alexandru Elisei --- mm/cma.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/cma.c b/mm/cma.c index f49c95f8ee37..dbf7

[PATCH RFC v3 07/35] mm: cma: Add CMA_RELEASE_{SUCCESS,FAIL} events

2024-01-25 Thread Alexandru Elisei
Similar to the two events that relate to CMA allocations, add the CMA_RELEASE_SUCCESS and CMA_RELEASE_FAIL events that count when CMA pages are freed. Signed-off-by: Alexandru Elisei --- Changes since rfc v2: * New patch. include/linux/vm_event_item.h | 2 ++ mm/cma.c

[PATCH RFC v3 08/35] mm: cma: Introduce cma_alloc_range()

2024-01-25 Thread Alexandru Elisei
storage associated with a tagged page. Signed-off-by: Alexandru Elisei --- Changes since rfc v2: * New patch. include/linux/cma.h| 2 + include/trace/events/cma.h | 59 ++ mm/cma.c | 86 ++ 3 files changed

[PATCH RFC v3 09/35] mm: cma: Introduce cma_remove_mem()

2024-01-25 Thread Alexandru Elisei
page allocator. Signed-off-by: Alexandru Elisei --- Changes since rfc v2: * New patch. include/linux/cma.h | 1 + mm/cma.c| 30 +- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/include/linux/cma.h b/include/linux/cma.h index e32559d

[PATCH RFC v3 10/35] mm: cma: Fast track allocating memory when the pages are free

2024-01-25 Thread Alexandru Elisei
long. Signed-off-by: Alexandru Elisei --- Changes since rfc v2: * New patch. Reworked from the rfc v2 patch #26 ("arm64: mte: Fast track reserving tag storage when the block is free") (David Hildenbrand). include/linux/page-flags.h | 15 -- mm/Kconfig | 5

[PATCH RFC v3 11/35] mm: Allow an arch to hook into folio allocation when VMA is known

2024-01-25 Thread Alexandru Elisei
a need to do so. Signed-off-by: Alexandru Elisei --- arch/arm64/include/asm/page.h| 5 ++--- arch/arm64/include/asm/pgtable.h | 3 +++ arch/arm64/mm/fault.c| 19 ++- include/linux/pgtable.h | 7 +++ mm/mempolicy.c |

[PATCH RFC v3 12/35] mm: Call arch_swap_prepare_to_restore() before arch_swap_restore()

2024-01-25 Thread Alexandru Elisei
will be used by arm64 to allocate a buffer in memory where to temporarily save tags if tag storage is not available for the page being swapped in. Signed-off-by: Alexandru Elisei --- include/linux/pgtable.h | 7 +++ mm/memory.c | 4 mm/shmem.c | 9

[PATCH RFC v3 13/35] mm: memory: Introduce fault-on-access mechanism for pages

2024-01-25 Thread Alexandru Elisei
otect(PROT_MTE) call on a VMA with existing pages). Signed-off-by: Alexandru Elisei --- Changes since rfc v2: * New patch. Split from patch #19 ("mm: mprotect: Introduce PAGE_FAULT_ON_ACCESS for mprotect(PROT_MTE)") (David Hildenbrand). include/linux/huge_mm.h | 4 ++-- include/linux

[PATCH RFC v3 14/35] of: fdt: Return the region size in of_flat_dt_translate_address()

2024-01-25 Thread Alexandru Elisei
Alongside the base address, arm64 will also need to know the size of a tag storage region. Teach of_flat_dt_translate_address() to parse and return the size. Signed-off-by: Alexandru Elisei --- Changes since rfc v2: * New patch, suggested by Rob Herring. arch/sh/kernel/cpu/sh2/probe.c | 2

[PATCH RFC v3 15/35] of: fdt: Add of_flat_read_u32()

2024-01-25 Thread Alexandru Elisei
Add the function of_flat_read_u32() to return the value of a property as an u32. Signed-off-by: Alexandru Elisei --- Changes since rfc v2: * New patch, suggested by Rob Herring. drivers/of/fdt.c | 21 + include/linux/of_fdt.h | 2 ++ 2 files changed, 23 insertions

[PATCH RFC v3 16/35] KVM: arm64: Don't deny VM_PFNMAP VMAs when kvm_has_mte()

2024-01-25 Thread Alexandru Elisei
after the memslot has been created, the virtual machine will run without errors. Change kvm_arch_prepare_memory_region() to allow VM_PFNMAP VMAs when the VM has the MTE capability enabled. Signed-off-by: Alexandru Elisei --- Changes from rfc v2: * New patch. It's a fix, and can be taken i

[PATCH RFC v3 17/35] arm64: mte: Rework naming for tag manipulation functions

2024-01-25 Thread Alexandru Elisei
e size of the memory needed to save the tags for a page. Oportunistically rename MTE_TAG_SIZE to MTE_TAG_SIZE_BITS to make it clear it is measured in bits, not bytes, like the rest of the size variable from the same header file. Signed-off-by: Alexandru Elisei --- arch/arm64/include/asm/mte-d

[PATCH RFC v3 18/35] arm64: mte: Rename __GFP_ZEROTAGS to __GFP_TAGGED

2024-01-25 Thread Alexandru Elisei
frame is also zeroed (either __GFP_ZERO is set or init_on_alloc is 1). Rename it to __GFP_TAGGED, in preparation for it to be used by the page allocator to recognize when an allocation is tagged (has metadata). Signed-off-by: Alexandru Elisei --- arch/arm64/mm/fault.c | 2 +- include/

[PATCH RFC v3 19/35] arm64: mte: Discover tag storage memory

2024-01-25 Thread Alexandru Elisei
data (non-tagged) allocations. Signed-off-by: Alexandru Elisei --- Changes since rfc v2: * Reworked from rfc v2 patch #11 ("arm64: mte: Reserve tag storage memory"). * Added device tree schema (Rob Herring) * Tag storage memory is now described in the "reserved-memory&quo

[PATCH RFC v3 20/35] arm64: mte: Add tag storage memory to CMA

2024-01-25 Thread Alexandru Elisei
explicitely by using their PFN (with alloc_cma_range()) when they are needed to store tags. Signed-off-by: Alexandru Elisei --- Changes since v2: * Reworked from rfc v2 patch #12 ("arm64: mte: Add tag storage pages to the MIGRATE_CMA migratetype"). * Tag storage memory is now added to the

[PATCH RFC v3 21/35] arm64: mte: Disable dynamic tag storage management if HW KASAN is enabled

2024-01-25 Thread Alexandru Elisei
don't use tag storage pages if HW KASAN is enabled. Signed-off-by: Alexandru Elisei --- Changes since rfc v2: * Expanded commit message (David Hildenbrand) arch/arm64/kernel/mte_tag_storage.c | 10 ++ 1 file changed, 10 insertions(+) diff --git a/arch/arm64/kernel/mte_tag_storage

[PATCH RFC v3 22/35] arm64: mte: Enable tag storage if CMA areas have been activated

2024-01-25 Thread Alexandru Elisei
some of the memory, but not for all memory, and that would make the code unreasonably complicated. Choose to disable tag storage management altogether if a CMA area fails to be activated. Signed-off-by: Alexandru Elisei --- Changes since v2: * New patch. arch/arm64/include/asm/mte_tag_storage.h

[PATCH RFC v3 23/35] arm64: mte: Try to reserve tag storage in arch_alloc_page()

2024-01-25 Thread Alexandru Elisei
allocations. Signed-off-by: Alexandru Elisei --- Changes since rfc v2: * Based on rfc v2 patch #16 ("arm64: mte: Manage tag storage on page allocation"). * Fixed calculation of the number of associated tag storage blocks (Hyesoo Yu). * Tag storage is reserved in arch_alloc_page()

[PATCH RFC v3 24/35] arm64: mte: Perform CMOs for tag blocks

2024-01-25 Thread Alexandru Elisei
when the tag storage block is being reserved, to ensure that no dirty data cache lines are present, which would trigger a writeback that could corrupt the tags stored in the block. Signed-off-by: Alexandru Elisei --- arch/arm64/include/asm/assembler.h | 10 ++ arch/arm64/in

[PATCH RFC v3 25/35] arm64: mte: Reserve tag block for the zero page

2024-01-25 Thread Alexandru Elisei
yet enabled. Reserve tag storage for the page immediately after tag storage management becomes enabled. Note that zeroing tags before tag storage management is enabled is safe to do because the tag storage pages are reserved at that point. Signed-off-by: Alexandru Elisei --- Changes since rfc v2

[PATCH RFC v3 26/35] arm64: mte: Use fault-on-access to reserve missing tag storage

2024-01-25 Thread Alexandru Elisei
If tag storage cannot be reserved, then the page is migrated out of the VMA. Tag storage pages (which cannot be tagged) mapped in an MTE enabled MTE will be handled in a subsequent patch. Signed-off-by: Alexandru Elisei --- Changes since rfc v2: * New patch, loosely based on the arm64 code

[PATCH RFC v3 27/35] arm64: mte: Handle tag storage pages mapped in an MTE VMA

2024-01-25 Thread Alexandru Elisei
Tag stoarge pages cannot be tagged. When such a page is mapped in a MTE-enabled VMA, migrate it out directly and don't try to reserve tag storage for it. Signed-off-by: Alexandru Elisei --- arch/arm64/include/asm/mte_tag_storage.h | 1 + arch/arm64/kernel/mte_tag_storage.c

[PATCH RFC v3 28/35] arm64: mte: swap: Handle tag restoring when missing tag storage

2024-01-25 Thread Alexandru Elisei
around this issue by saving the tags in a new xarray, this time indexed by the page pfn, and then restoring them when tag storage is reserved for the page. Signed-off-by: Alexandru Elisei --- Changes since rfc v2: * Restore saved tags **before** setting the PG_tag_storage_reserved bit to

[PATCH RFC v3 29/35] arm64: mte: copypage: Handle tag restoring when missing tag storage

2024-01-25 Thread Alexandru Elisei
d when the replacement huge page is a tag storage page. The tag storage huge page will be migrated after a fault on access, but the tags from the original pages must be copied over to the huge page that will be replacing the tag storage huge page. Signed-off-by: Alexandru Elisei --- arch/arm64/mm/copyp

[PATCH RFC v3 30/35] arm64: mte: ptrace: Handle pages with missing tag storage

2024-01-25 Thread Alexandru Elisei
ptrace accesses like a fault. Signed-off-by: Alexandru Elisei --- Changes since rfc v2: * New patch, issue reported by Peter Collingbourne. arch/arm64/kernel/mte.c | 26 -- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kernel/mte.c b/arch/arm64

[PATCH RFC v3 31/35] khugepaged: arm64: Don't collapse MTE enabled VMAs

2024-01-25 Thread Alexandru Elisei
_page_copy() -> .. -> copy_user_highpage() with the RCU lock held, which means that copy_user_highpage() can only allocate memory using GFP_ATOMIC or equivalent. Get around this by refusing to collapse pages into a transparent huge page if the VMA is MTE-enabled. Signed-off-by: Alexandru Elisei --- Changes sinc

[PATCH RFC v3 32/35] KVM: arm64: mte: Reserve tag storage for virtual machines with MTE

2024-01-25 Thread Alexandru Elisei
ges mapped without tag storage in an MTE VMA are handled. Signed-off-by: Alexandru Elisei --- Changes since rfc v2: * New patch. arch/arm64/include/asm/mte_tag_storage.h | 10 ++ arch/arm64/include/asm/pgtable.h | 7 +++- arch/arm64/kvm/mmu.c

[PATCH RFC v3 33/35] KVM: arm64: mte: Introduce VM_MTE_KVM VMA flag

2024-01-25 Thread Alexandru Elisei
emu and kvmtool will benefit from this change because the guest image is copied after the memslot is created. Signed-off-by: Alexandru Elisei --- Changes since rfc v2: * New patch. arch/arm64/kvm/mmu.c | 77 ++- arch/arm64/mm/fault.c | 2 +- includ

[PATCH RFC v3 34/35] arm64: mte: Enable dynamic tag storage management

2024-01-25 Thread Alexandru Elisei
Everything is in place, enable tag storage management. Signed-off-by: Alexandru Elisei --- arch/arm64/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 088e30fc6d12..95c153705a2c 100644 --- a/arch/arm64/Kconfig +++ b/arch

[PATCH RFC v3 35/35] HACK! arm64: dts: Add fake tag storage to fvp-base-revc.dts

2024-01-25 Thread Alexandru Elisei
Faking a tag storage region for FVP is useful for testing. Signed-off-by: Alexandru Elisei --- Changes since rfc v2: * New patch, not intended to be merged. arch/arm64/boot/dts/arm/fvp-base-revc.dts | 42 +-- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a

Re: [PATCH RFC v3 19/35] arm64: mte: Discover tag storage memory

2024-01-26 Thread Alexandru Elisei
Hi Krzysztof, On Fri, Jan 26, 2024 at 09:50:58AM +0100, Krzysztof Kozlowski wrote: > On 25/01/2024 17:42, Alexandru Elisei wrote: > > Allow the kernel to get the base address, size, block size and associated > > memory node for tag storage from the device tree blob. > > &g

Re: [PATCH RFC v3 01/35] mm: page_alloc: Add gfp_flags parameter to arch_alloc_page()

2024-01-29 Thread Alexandru Elisei
Hi, On Mon, Jan 29, 2024 at 11:18:59AM +0530, Anshuman Khandual wrote: > > On 1/25/24 22:12, Alexandru Elisei wrote: > > Extend the usefulness of arch_alloc_page() by adding the gfp_flags > > parameter. > > Although the change here is harmless in itself, it will defini

Re: [PATCH RFC v3 02/35] mm: page_alloc: Add an arch hook early in free_pages_prepare()

2024-01-29 Thread Alexandru Elisei
Hi, On Mon, Jan 29, 2024 at 01:49:44PM +0530, Anshuman Khandual wrote: > > > On 1/25/24 22:12, Alexandru Elisei wrote: > > The arm64 MTE code uses the PG_arch_2 page flag, which it renames to > > PG_mte_tagged, to track if a page has been mapped with tagging enabled. > &

Re: [PATCH RFC v3 03/35] mm: page_alloc: Add an arch hook to filter MIGRATE_CMA allocations

2024-01-29 Thread Alexandru Elisei
Hi, On Mon, Jan 29, 2024 at 02:14:16PM +0530, Anshuman Khandual wrote: > > > On 1/25/24 22:12, Alexandru Elisei wrote: > > As an architecture might have specific requirements around the allocation > > of CMA pages, add an arch hook that can disable allocations from &g

Re: [PATCH RFC v3 04/35] mm: page_alloc: Partially revert "mm: page_alloc: remove stale CMA guard code"

2024-01-29 Thread Alexandru Elisei
Hi, On Mon, Jan 29, 2024 at 02:31:23PM +0530, Anshuman Khandual wrote: > > > On 1/25/24 22:12, Alexandru Elisei wrote: > > The patch f945116e4e19 ("mm: page_alloc: remove stale CMA guard code") > > removed the CMA filter when allocating from the MIGRATE_MOVA

Re: [PATCH RFC v3 05/35] mm: cma: Don't append newline when generating CMA area name

2024-01-29 Thread Alexandru Elisei
Hi, On Mon, Jan 29, 2024 at 02:43:08PM +0530, Anshuman Khandual wrote: > > On 1/25/24 22:12, Alexandru Elisei wrote: > > cma->name is displayed in several CMA messages. When the name is generated > > by the CMA code, don't append a newline to avoid breaking the text acr

Re: [PATCH RFC v3 06/35] mm: cma: Make CMA_ALLOC_SUCCESS/FAIL count the number of pages

2024-01-29 Thread Alexandru Elisei
Hi, On Mon, Jan 29, 2024 at 02:54:20PM +0530, Anshuman Khandual wrote: > > > On 1/25/24 22:12, Alexandru Elisei wrote: > > The CMA_ALLOC_SUCCESS, respectively CMA_ALLOC_FAIL, are increased by one > > after each cma_alloc() function call. This is done even though cma_alloc(

Re: [PATCH RFC v3 07/35] mm: cma: Add CMA_RELEASE_{SUCCESS,FAIL} events

2024-01-29 Thread Alexandru Elisei
Hi, On Mon, Jan 29, 2024 at 03:01:24PM +0530, Anshuman Khandual wrote: > > > On 1/25/24 22:12, Alexandru Elisei wrote: > > Similar to the two events that relate to CMA allocations, add the > > CMA_RELEASE_SUCCESS and CMA_RELEASE_FAIL events that count when CMA pages >

Re: [PATCH RFC v3 11/35] mm: Allow an arch to hook into folio allocation when VMA is known

2024-01-29 Thread Alexandru Elisei
Hi Peter, On Fri, Jan 26, 2024 at 12:00:36PM -0800, Peter Collingbourne wrote: > On Thu, Jan 25, 2024 at 8:43 AM Alexandru Elisei > wrote: > > > > arm64 uses VM_HIGH_ARCH_0 and VM_HIGH_ARCH_1 for enabling MTE for a VMA. > > When VM_HIGH_ARCH_0, which arm64 renames to

Re: [PATCH RFC v3 09/35] mm: cma: Introduce cma_remove_mem()

2024-01-30 Thread Alexandru Elisei
case of error. Does that make more sense now? Ok Tue, Jan 30, 2024 at 11:20:56AM +0530, Anshuman Khandual wrote: > > > On 1/25/24 22:12, Alexandru Elisei wrote: > > Memory is added to CMA with cma_declare_contiguous_nid() and > > cma_init_reserved_mem(). This memory is then p

Re: [PATCH RFC v3 10/35] mm: cma: Fast track allocating memory when the pages are free

2024-01-30 Thread Alexandru Elisei
Hi, On Tue, Jan 30, 2024 at 02:48:53PM +0530, Anshuman Khandual wrote: > > > On 1/25/24 22:12, Alexandru Elisei wrote: > > If the pages to be allocated are free, take them directly off the buddy > > allocator, instead of going through alloc_contig_range() and avoidin

Re: [PATCH RFC v3 11/35] mm: Allow an arch to hook into folio allocation when VMA is known

2024-01-30 Thread Alexandru Elisei
Hi, On Tue, Jan 30, 2024 at 03:25:20PM +0530, Anshuman Khandual wrote: > > > On 1/25/24 22:12, Alexandru Elisei wrote: > > arm64 uses VM_HIGH_ARCH_0 and VM_HIGH_ARCH_1 for enabling MTE for a VMA. > > When VM_HIGH_ARCH_0, which arm64 renames to VM_MTE, is set for a VMA,

Re: [PATCH RFC v3 08/35] mm: cma: Introduce cma_alloc_range()

2024-01-30 Thread Alexandru Elisei
Hi, On Tue, Jan 30, 2024 at 10:50:00AM +0530, Anshuman Khandual wrote: > > > On 1/25/24 22:12, Alexandru Elisei wrote: > > Today, cma_alloc() is used to allocate a contiguous memory region. The > > function allows the caller to specify the number of pages to allocate, but

Re: [PATCH RFC v3 23/35] arm64: mte: Try to reserve tag storage in arch_alloc_page()

2024-01-30 Thread Alexandru Elisei
Hi Peter, On Mon, Jan 29, 2024 at 04:04:18PM -0800, Peter Collingbourne wrote: > On Thu, Jan 25, 2024 at 8:45 AM Alexandru Elisei > wrote: > > > > Reserve tag storage for a page that is being allocated as tagged. This > > is a best effort approach, and failing t

Re: [PATCH RFC v3 01/35] mm: page_alloc: Add gfp_flags parameter to arch_alloc_page()

2024-01-30 Thread Alexandru Elisei
Hi, On Tue, Jan 30, 2024 at 09:56:10AM +0530, Anshuman Khandual wrote: > > > On 1/29/24 17:11, Alexandru Elisei wrote: > > Hi, > > > > On Mon, Jan 29, 2024 at 11:18:59AM +0530, Anshuman Khandual wrote: > >> On 1/25/24 22:12, Alexandru Elisei w

Re: [PATCH RFC v3 04/35] mm: page_alloc: Partially revert "mm: page_alloc: remove stale CMA guard code"

2024-01-30 Thread Alexandru Elisei
Hi, On Tue, Jan 30, 2024 at 10:04:02AM +0530, Anshuman Khandual wrote: > > > On 1/29/24 17:16, Alexandru Elisei wrote: > > Hi, > > > > On Mon, Jan 29, 2024 at 02:31:23PM +0530, Anshuman Khandual wrote: > >> > >> > >> On 1/25/24 22:12, Ale

Re: [PATCH RFC v3 06/35] mm: cma: Make CMA_ALLOC_SUCCESS/FAIL count the number of pages

2024-01-30 Thread Alexandru Elisei
Hi, On Tue, Jan 30, 2024 at 10:22:11AM +0530, Anshuman Khandual wrote: > > > On 1/29/24 17:21, Alexandru Elisei wrote: > > Hi, > > > > On Mon, Jan 29, 2024 at 02:54:20PM +0530, Anshuman Khandual wrote: > >> > >> > >> On 1/25/24 22:1

Re: [PATCH RFC v3 11/35] mm: Allow an arch to hook into folio allocation when VMA is known

2024-01-31 Thread Alexandru Elisei
Hi, On Wed, Jan 31, 2024 at 12:23:51PM +0530, Anshuman Khandual wrote: > > > On 1/30/24 17:04, Alexandru Elisei wrote: > > Hi, > > > > On Tue, Jan 30, 2024 at 03:25:20PM +0530, Anshuman Khandual wrote: > >> > >> On 1/25/24 22:12, Alexandru Elis

Re: [PATCH RFC v3 06/35] mm: cma: Make CMA_ALLOC_SUCCESS/FAIL count the number of pages

2024-01-31 Thread Alexandru Elisei
Hi, On Wed, Jan 31, 2024 at 10:10:05AM +0530, Anshuman Khandual wrote: > > > On 1/30/24 17:28, Alexandru Elisei wrote: > > Hi, > > > > On Tue, Jan 30, 2024 at 10:22:11AM +0530, Anshuman Khandual wrote: > >> > >> On 1/29/24 17:21, Alexandru Elise

Re: [PATCH RFC v3 09/35] mm: cma: Introduce cma_remove_mem()

2024-01-31 Thread Alexandru Elisei
Hi, On Wed, Jan 31, 2024 at 06:49:34PM +0530, Anshuman Khandual wrote: > On 1/30/24 17:03, Alexandru Elisei wrote: > > Hi, > > > > I really appreciate the feedback you have given me so far. I believe the > > commit message isn't clear enough and there has been

Re: [PATCH RFC v3 08/35] mm: cma: Introduce cma_alloc_range()

2024-01-31 Thread Alexandru Elisei
Hi, On Wed, Jan 31, 2024 at 11:54:17AM +0530, Anshuman Khandual wrote: > > > On 1/30/24 17:05, Alexandru Elisei wrote: > > Hi, > > > > On Tue, Jan 30, 2024 at 10:50:00AM +0530, Anshuman Khandual wrote: > >> > >> On 1/25/24 22:12, Alexandru Elis

Re: [PATCH RFC v3 12/35] mm: Call arch_swap_prepare_to_restore() before arch_swap_restore()

2024-02-01 Thread Alexandru Elisei
Hi, On Thu, Feb 01, 2024 at 09:00:23AM +0530, Anshuman Khandual wrote: > > > On 1/25/24 22:12, Alexandru Elisei wrote: > > arm64 uses arch_swap_restore() to restore saved tags before the page is > > swapped in and it's called in atomic context (with the ptl lock

Re: [PATCH RFC v3 13/35] mm: memory: Introduce fault-on-access mechanism for pages

2024-02-01 Thread Alexandru Elisei
Hi, On Thu, Feb 01, 2024 at 11:22:13AM +0530, Anshuman Khandual wrote: > On 1/25/24 22:12, Alexandru Elisei wrote: > > Introduce a mechanism that allows an architecture to trigger a page fault, > > and add the infrastructure to handle that fault accordingly. To use make> > &

Re: [PATCH RFC v3 30/35] arm64: mte: ptrace: Handle pages with missing tag storage

2024-02-01 Thread Alexandru Elisei
Hi, On Thu, Feb 01, 2024 at 02:51:39PM +0530, Anshuman Khandual wrote: > > > On 1/25/24 22:12, Alexandru Elisei wrote: > > A page can end up mapped in a MTE enabled VMA without the corresponding tag > > storage block reserved. Tag accesses made by ptrace in this case can

Re: [PATCH RFC v3 31/35] khugepaged: arm64: Don't collapse MTE enabled VMAs

2024-02-01 Thread Alexandru Elisei
On Thu, Feb 01, 2024 at 01:42:08PM +0530, Anshuman Khandual wrote: > > > On 1/25/24 22:12, Alexandru Elisei wrote: > > copy_user_highpage() will do memory allocation if there are saved tags for > > the destination page, and the page is missing tag storage. > > > &g

Re: [PATCH RFC v3 28/35] arm64: mte: swap: Handle tag restoring when missing tag storage

2024-02-02 Thread Alexandru Elisei
Hi Peter, On Thu, Feb 01, 2024 at 08:02:40PM -0800, Peter Collingbourne wrote: > On Thu, Jan 25, 2024 at 8:45 AM Alexandru Elisei > wrote: > > > > Linux restores tags when a page is swapped in and there are tags associated > > with the swap entry which the new page will

Re: [PATCH RFC v3 22/35] arm64: mte: Enable tag storage if CMA areas have been activated

2024-02-05 Thread Alexandru Elisei
Hi Evgenii, On Fri, Feb 02, 2024 at 02:30:00PM -0800, Evgenii Stepanov wrote: > On Thu, Jan 25, 2024 at 8:44 AM Alexandru Elisei > wrote: > > > > Before enabling MTE tag storage management, make sure that the CMA areas > > have been successfully activated. If a CMA ar

Re: [PATCH RFC 04/37] mm: Add MIGRATE_METADATA allocation policy

2023-10-16 Thread Alexandru Elisei
Hello, On Thu, Oct 12, 2023 at 10:28:24AM +0900, Hyesoo Yu wrote: > On Wed, Aug 23, 2023 at 02:13:17PM +0100, Alexandru Elisei wrote: > > Some architectures implement hardware memory coloring to catch incorrect > > usage of memory allocation. One such architecture is arm64,

Re: [PATCH RFC 06/37] mm: page_alloc: Allocate from movable pcp lists only if ALLOC_FROM_METADATA

2023-10-16 Thread Alexandru Elisei
Hi, On Thu, Oct 12, 2023 at 10:25:11AM +0900, Hyesoo Yu wrote: > On Wed, Aug 23, 2023 at 02:13:19PM +0100, Alexandru Elisei wrote: > > pcp lists keep MIGRATE_METADATA pages on the MIGRATE_MOVABLE list. Make > > sure pages from the movable list are allocated only when the > >

Re: [PATCH RFC 17/37] arm64: mte: Disable dynamic tag storage management if HW KASAN is enabled

2023-10-16 Thread Alexandru Elisei
Hi, On Thu, Oct 12, 2023 at 10:35:05AM +0900, Hyesoo Yu wrote: > On Wed, Aug 23, 2023 at 02:13:30PM +0100, Alexandru Elisei wrote: > > Reserving the tag storage associated with a tagged page requires the > > ability to migrate existing data if the tag storage is in use for dat

Re: [PATCH RFC 00/37] Add support for arm64 MTE dynamic tag storage reuse

2023-10-25 Thread Alexandru Elisei
p 06, 2023 at 12:23:21PM +0100, Alexandru Elisei wrote: > > > > > On Thu, Aug 24, 2023 at 04:24:30PM +0100, Catalin Marinas wrote: > > > > > > On Thu, Aug 24, 2023 at 01:25:41PM +0200, David Hildenbrand wrote: > > > > > > > On 24.08.23 13:06, Da

[PATCH RFC v2 00/27] Add support for arm64 MTE dynamic tag storage reuse

2023-11-19 Thread Alexandru Elisei
torage@8fc00 { +compatible = "arm,mte-tag-storage"; +reg = <0x0008 0xfc00 0 0x3c0>; +block-size = <0x1000>; + memory = <&memory1>; +}; + reserved-memory { #address-cells = &l

[PATCH RFC v2 01/27] arm64: mte: Rework naming for tag manipulation functions

2023-11-19 Thread Alexandru Elisei
e size of the memory needed to save the tags for a page. Oportunistically rename MTE_TAG_SIZE to MTE_TAG_SIZE_BITS to make it clear it is measured in bits, not bytes, like the rest of the size variable from the same header file. Signed-off-by: Alexandru Elisei --- arch/arm64/include/asm/mte-d

[PATCH RFC v2 02/27] arm64: mte: Rename __GFP_ZEROTAGS to __GFP_TAGGED

2023-11-19 Thread Alexandru Elisei
frame is also zeroed (either __GFP_ZERO is set or init_on_alloc is 1). Rename it to __GFP_TAGGED, in preparation for it to be used by the page allocator to recognize when an allocation is tagged (has metadata). Signed-off-by: Alexandru Elisei --- arch/arm64/mm/fault.c | 2 +- include/

[PATCH RFC v2 03/27] mm: cma: Make CMA_ALLOC_SUCCESS/FAIL count the number of pages

2023-11-19 Thread Alexandru Elisei
led to allocate. For users that wish to track the number of cma_alloc() calls, there are tracepoints for that already implemented. Signed-off-by: Alexandru Elisei --- mm/cma.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/cma.c b/mm/cma.c index 2b2494fd6b59..2b74db5116

[PATCH RFC v2 04/27] mm: migrate/mempolicy: Add hook to modify migration target gfp

2023-11-19 Thread Alexandru Elisei
can request that the destination page similarly has storage for tags already allocated. No functional change. Signed-off-by: Alexandru Elisei --- include/linux/migrate.h | 4 mm/mempolicy.c | 2 ++ mm/migrate.c| 3 +++ 3 files changed, 9 insertions(+) diff --git a

[PATCH RFC v2 05/27] mm: page_alloc: Add an arch hook to allow prep_new_page() to fail

2023-11-19 Thread Alexandru Elisei
rom post_alloc_hook(), has been considered as an alternative to adding yet another arch hook, but post_alloc_hook() cannot fail, as it's also called when free pages are isolated. Signed-off-by: Alexandru Elisei --- include/linux/pgtable.h | 7 mm/page_alloc.c

[PATCH RFC v2 06/27] mm: page_alloc: Allow an arch to hook early into free_pages_prepare()

2023-11-19 Thread Alexandru Elisei
Add arch_free_pages_prepare() hook that is called before that page flags are cleared. This will be used by arm64 when explicit management of tag storage pages is enabled. Signed-off-by: Alexandru Elisei --- include/linux/pgtable.h | 4 mm/page_alloc.c | 4 +++- 2 files changed, 7

[PATCH RFC v2 07/27] mm: page_alloc: Add an arch hook to filter MIGRATE_CMA allocations

2023-11-19 Thread Alexandru Elisei
specific limitations. Signed-off-by: Alexandru Elisei --- include/linux/pgtable.h | 7 +++ mm/page_alloc.c | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h index 3f34f00ced62..b7a9ab818f6d 100644 --- a/include

[PATCH RFC v2 08/27] mm: page_alloc: Partially revert "mm: page_alloc: remove stale CMA guard code"

2023-11-19 Thread Alexandru Elisei
, so bring back the filter. This is a partially revert because the stale comment remains removed. Signed-off-by: Alexandru Elisei --- mm/page_alloc.c | 15 +++ 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 0f508070c404..13

[PATCH RFC v2 09/27] mm: Allow an arch to hook into folio allocation when VMA is known

2023-11-19 Thread Alexandru Elisei
being performed separately, in set_pte_at() -> mte_sync_tags(). Its usage will be expanded when the storage for the tags will have to be explicitely managed by the kernel. Signed-off-by: Alexandru Elisei --- arch/arm64/include/asm/page.h| 5 ++--- arch/arm64/include/asm/pgtable.h | 3 +++ a

[PATCH RFC v2 10/27] mm: Call arch_swap_prepare_to_restore() before arch_swap_restore()

2023-11-19 Thread Alexandru Elisei
igned-off-by: Alexandru Elisei --- include/linux/pgtable.h | 7 +++ mm/memory.c | 4 mm/shmem.c | 9 + mm/swapfile.c | 7 +++ 4 files changed, 27 insertions(+) diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h index b1001ce

[PATCH RFC v2 11/27] arm64: mte: Reserve tag storage memory

2023-11-19 Thread Alexandru Elisei
e), then the correct value for "block-size" is 0x2000. This value is a hardware property, independent of the selected kernel page size. Signed-off-by: Alexandru Elisei --- arch/arm64/Kconfig | 12 ++ arch/arm64/include/asm/mte_tag_storage.h | 15 ++ arch/arm64/kern

[PATCH RFC v2 12/27] arm64: mte: Add tag storage pages to the MIGRATE_CMA migratetype

2023-11-19 Thread Alexandru Elisei
explicitely by using their PFN (with alloc_contig_range()) when they are needed to store tags. Signed-off-by: Alexandru Elisei --- arch/arm64/Kconfig | 1 + arch/arm64/kernel/mte_tag_storage.c | 68 + include/linux/mmzone.h | 5 +++ mm

[PATCH RFC v2 13/27] arm64: mte: Make tag storage depend on ARCH_KEEP_MEMBLOCK

2023-11-19 Thread Alexandru Elisei
onfig option required for it to work correctly. Signed-off-by: Alexandru Elisei --- arch/arm64/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 047487046e8f..efa5b7958169 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -2065,6 +2

[PATCH RFC v2 15/27] arm64: mte: Check that tag storage blocks are in the same zone

2023-11-19 Thread Alexandru Elisei
alloc_contig_range() requires that the requested pages are in the same zone. Check that this is indeed the case before initializing the tag storage blocks. Signed-off-by: Alexandru Elisei --- arch/arm64/kernel/mte_tag_storage.c | 33 + 1 file changed, 33 insertions

[PATCH RFC v2 14/27] arm64: mte: Disable dynamic tag storage management if HW KASAN is enabled

2023-11-19 Thread Alexandru Elisei
storage pages reserved if HW KASAN is enabled. Signed-off-by: Alexandru Elisei --- arch/arm64/kernel/mte_tag_storage.c | 13 + 1 file changed, 13 insertions(+) diff --git a/arch/arm64/kernel/mte_tag_storage.c b/arch/arm64/kernel/mte_tag_storage.c index 427f4f1909f3..8b9bedf7575d

[PATCH RFC v2 16/27] arm64: mte: Manage tag storage on page allocation

2023-11-19 Thread Alexandru Elisei
allocator, where they can be used again for data allocations. Tag storage pages cannot be tagged, so disallow allocations from MIGRATE_CMA when the allocation is tagged. Signed-off-by: Alexandru Elisei --- arch/arm64/include/asm/mte.h | 16 +- arch/arm64/include/asm/mte_tag_storage.h

[PATCH RFC v2 17/27] arm64: mte: Perform CMOs for tag blocks on tagged page allocation/free

2023-11-19 Thread Alexandru Elisei
when the tag storage block is being reserved, to ensure that no dirty data cache lines are present, which would trigger a writeback that could corrupt the tags stored in the block. Signed-off-by: Alexandru Elisei --- arch/arm64/include/asm/assembler.h | 10 ++ arch/arm64/in

[PATCH RFC v2 18/27] arm64: mte: Reserve tag block for the zero page

2023-11-19 Thread Alexandru Elisei
On arm64, the zero page receives special treatment by having the tagged flag set on MTE initialization, not when the page is mapped in a process address space. Reserve the corresponding tag block when tag storage management is being activated. Signed-off-by: Alexandru Elisei --- arch/arm64

[PATCH RFC v2 20/27] mm: hugepage: Handle huge page fault on access

2023-11-19 Thread Alexandru Elisei
Handle PAGE_FAULT_ON_ACCESS faults for huge pages in a similar way to regular pages. Signed-off-by: Alexandru Elisei --- arch/arm64/include/asm/mte_tag_storage.h | 1 + arch/arm64/include/asm/pgtable.h | 7 ++ arch/arm64/mm/fault.c| 81

[PATCH RFC v2 19/27] mm: mprotect: Introduce PAGE_FAULT_ON_ACCESS for mprotect(PROT_MTE)

2023-11-19 Thread Alexandru Elisei
or PTE mappings; PMD mappings will follow. Signed-off-by: Alexandru Elisei --- arch/arm64/Kconfig | 1 + arch/arm64/include/asm/mte.h | 4 +- arch/arm64/include/asm/mte_tag_storage.h | 2 + arch/arm64/include/asm/pgtable-prot.h| 2 + arch/arm64/includ

[PATCH RFC v2 21/27] mm: arm64: Handle tag storage pages mapped before mprotect(PROT_MTE)

2023-11-19 Thread Alexandru Elisei
Signed-off-by: Alexandru Elisei --- arch/arm64/include/asm/mte_tag_storage.h | 1 + arch/arm64/kernel/mte_tag_storage.c | 15 +++ arch/arm64/mm/fault.c| 55 include/linux/migrate.h | 8 +++- include/linux/migrate_mode.h

[PATCH RFC v2 22/27] arm64: mte: swap: Handle tag restoring when missing tag storage

2023-11-19 Thread Alexandru Elisei
around this issue by saving the tags in a new xarray, this time indexed by the page pfn, and then restoring them when tag storage is reserved for the page. Signed-off-by: Alexandru Elisei --- arch/arm64/include/asm/mte_tag_storage.h | 9 ++ arch/arm64/include/asm/pgtable.h | 11

[PATCH RFC v2 23/27] arm64: mte: copypage: Handle tag restoring when missing tag storage

2023-11-19 Thread Alexandru Elisei
d when the replacement huge page is a tag storage page. The tag storage huge page will be migrated after a fault on access, but the tags from the original pages must be copied over to the huge page that will be replacing the tag storage huge page. Signed-off-by: Alexandru Elisei --- arch/arm64/mm/copyp

[PATCH RFC v2 25/27] KVM: arm64: Disable MTE if tag storage is enabled

2023-11-19 Thread Alexandru Elisei
. Signed-off-by: Alexandru Elisei --- arch/arm64/kvm/arm.c | 6 -- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index e5f75f1f1085..5b33c532c62a 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -29,6 +29,7 @@ #include

[PATCH RFC v2 24/27] arm64: mte: Handle fatal signal in reserve_tag_storage()

2023-11-19 Thread Alexandru Elisei
allocator to make progress. set_pte_at() will map it with PAGE_FAULT_ON_ACCESS and subsequent accesses from different threads will cause a fault until the signal is delivered. Signed-off-by: Alexandru Elisei --- arch/arm64/kernel/mte_tag_storage.c | 17 + arch/arm64/mm/fault.c

[PATCH RFC v2 26/27] arm64: mte: Fast track reserving tag storage when the block is free

2023-11-19 Thread Alexandru Elisei
taking the storage block directly from the freelist if it's free, thus sidestepping the costly function call. Note that at the moment this is implemented only when the block size is 1 (the block is one page); larger block sizes could be added later if necessary. Signed-off-by: Alexandru E

[PATCH RFC v2 27/27] arm64: mte: Enable dynamic tag storage reuse

2023-11-19 Thread Alexandru Elisei
Everything is in place, enable tag storage management. Signed-off-by: Alexandru Elisei --- arch/arm64/kernel/mte_tag_storage.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/arm64/kernel/mte_tag_storage.c b/arch/arm64/kernel/mte_tag_storage.c index 11961587382d..9f60e952a814

Re: [PATCH RFC 20/37] mm: compaction: Reserve metadata storage in compaction_alloc()

2023-11-21 Thread Alexandru Elisei
Hi Peter, On Mon, Nov 20, 2023 at 08:49:32PM -0800, Peter Collingbourne wrote: > Hi Alexandru, > > On Wed, Aug 23, 2023 at 6:16 AM Alexandru Elisei > wrote: > > > > If the source page being migrated has metadata associated with it, make > > sure to reserve the me

Re: [PATCH RFC v2 20/27] mm: hugepage: Handle huge page fault on access

2023-11-22 Thread Alexandru Elisei
Hi Peter, On Tue, Nov 21, 2023 at 05:28:49PM -0800, Peter Collingbourne wrote: > On Sun, Nov 19, 2023 at 8:59 AM Alexandru Elisei > wrote: > > > > Handle PAGE_FAULT_ON_ACCESS faults for huge pages in a similar way to > > regular pages. > > > > Signed-off-by:

Re: [PATCH RFC v2 04/27] mm: migrate/mempolicy: Add hook to modify migration target gfp

2023-11-27 Thread Alexandru Elisei
Hi Mike, I really appreciate you having a look! On Sat, Nov 25, 2023 at 12:03:22PM +0200, Mike Rapoport wrote: > On Sun, Nov 19, 2023 at 04:56:58PM +0000, Alexandru Elisei wrote: > > It might be desirable for an architecture to modify the gfp flags used to > > allocate the desti

Re: [PATCH RFC v2 05/27] mm: page_alloc: Add an arch hook to allow prep_new_page() to fail

2023-11-27 Thread Alexandru Elisei
Hi, Thank you so much for your comments, there are genuinely useful. On Fri, Nov 24, 2023 at 08:35:47PM +0100, David Hildenbrand wrote: > On 19.11.23 17:56, Alexandru Elisei wrote: > > Introduce arch_prep_new_page(), which will be used by arm64 to reserve tag > > storage for an

Re: [PATCH RFC v2 06/27] mm: page_alloc: Allow an arch to hook early into free_pages_prepare()

2023-11-27 Thread Alexandru Elisei
Hi, On Fri, Nov 24, 2023 at 08:36:52PM +0100, David Hildenbrand wrote: > On 19.11.23 17:57, Alexandru Elisei wrote: > > Add arch_free_pages_prepare() hook that is called before that page flags > > are cleared. This will be used by arm64 when explicit management of tag > > sto

  1   2   3   >