Re: [PATCH v2 3/5] mm: madvise: implement lightweight guard page mechanism

2024-10-21 Thread Lorenzo Stoakes
On Mon, Oct 21, 2024 at 11:35:24PM +0200, Vlastimil Babka wrote: > On 10/21/24 23:20, David Hildenbrand wrote: > >> I don't think there's really any value in that. There's just no sensible > >> situation in which a user would care about this I don't think. > > > > Making sure nobody touches an area

Re: [PATCH v2 3/5] mm: madvise: implement lightweight guard page mechanism

2024-10-21 Thread Vlastimil Babka
On 10/21/24 23:20, David Hildenbrand wrote: >> I don't think there's really any value in that. There's just no sensible >> situation in which a user would care about this I don't think. > > Making sure nobody touches an area, and wile doing that somebody already > touched that area? I guess it co

Re: [PATCH v2 3/5] mm: madvise: implement lightweight guard page mechanism

2024-10-21 Thread Lorenzo Stoakes
On Mon, Oct 21, 2024 at 11:20:03PM +0200, David Hildenbrand wrote: > > > Yes, I see from Lorenzo's reply that there is apparently some history to > > > this (maybe it's all nicely summarized in the cover letter / this patch, > > > have to dig further). > > > > > > Not sure yet what the problem is,

Re: [PATCH v2 5/5] selftests/mm: add self tests for guard page feature

2024-10-21 Thread Shuah Khan
On 10/20/24 10:20, Lorenzo Stoakes wrote: Utilise the kselftest harmness to implement tests for the guard page implementation. We start by implement basic tests asserting that guard pages can be established (poisoned), cleared (remedied) and that touching poisoned pages result in SIGSEGV. We als

Re: [PATCH v2 2/5] mm: add PTE_MARKER_GUARD PTE marker

2024-10-21 Thread Dave Hansen
On 10/21/24 14:13, Lorenzo Stoakes wrote: >> Do you think there's enough value int his to warrant digging in? And indeed >> I imagine bits are in short supply for this and would need a strong >> argument to get... so yeah I don't think too worthwhile most likely! >> >> Thanks for the suggestion tho

Re: [PATCH v2 3/5] mm: madvise: implement lightweight guard page mechanism

2024-10-21 Thread David Hildenbrand
Yes, I see from Lorenzo's reply that there is apparently some history to this (maybe it's all nicely summarized in the cover letter / this patch, have to dig further). Not sure yet what the problem is, I would have thought it's all protected by the PTL, and concurrent faults are user space doing

Re: [PATCH v2 2/5] mm: add PTE_MARKER_GUARD PTE marker

2024-10-21 Thread Lorenzo Stoakes
+cc Dave Hansen On Mon, Oct 21, 2024 at 09:42:53PM +0100, Lorenzo Stoakes wrote: > On Mon, Oct 21, 2024 at 03:45:31PM +0200, Vlastimil Babka wrote: > > On 10/20/24 18:20, Lorenzo Stoakes wrote: > > > Add a new PTE marker that results in any access causing the accessing > > > process to segfault. >

Re: [PATCH v2 3/5] mm: madvise: implement lightweight guard page mechanism

2024-10-21 Thread Lorenzo Stoakes
On Mon, Oct 21, 2024 at 10:37:39PM +0200, David Hildenbrand wrote: > On 21.10.24 22:25, Vlastimil Babka wrote: > > On 10/21/24 22:17, David Hildenbrand wrote: > > > On 21.10.24 22:11, Vlastimil Babka wrote: > > > > On 10/20/24 18:20, Lorenzo Stoakes wrote: > > > > > > > > > > > > > > > > > +static

Re: [PATCH v2 3/5] mm: madvise: implement lightweight guard page mechanism

2024-10-21 Thread Vlastimil Babka
On 10/21/24 22:27, Lorenzo Stoakes wrote: > On Mon, Oct 21, 2024 at 10:11:29PM +0200, Vlastimil Babka wrote: >> On 10/20/24 18:20, Lorenzo Stoakes wrote: >> > Implement a new lightweight guard page feature, that is regions of userland >> > virtual memory that, when accessed, cause a fatal signal to

Re: [PATCH v2 2/5] mm: add PTE_MARKER_GUARD PTE marker

2024-10-21 Thread Lorenzo Stoakes
On Mon, Oct 21, 2024 at 03:45:31PM +0200, Vlastimil Babka wrote: > On 10/20/24 18:20, Lorenzo Stoakes wrote: > > Add a new PTE marker that results in any access causing the accessing > > process to segfault. > > Should we distinguish it from other segfaults? Is there a way? I can see > memory prote

Re: [PATCH v2 3/5] mm: madvise: implement lightweight guard page mechanism

2024-10-21 Thread David Hildenbrand
On 21.10.24 22:25, Vlastimil Babka wrote: On 10/21/24 22:17, David Hildenbrand wrote: On 21.10.24 22:11, Vlastimil Babka wrote: On 10/20/24 18:20, Lorenzo Stoakes wrote: +static long madvise_guard_poison(struct vm_area_struct *vma, +struct vm_area_struct **pr

Re: [PATCH v2 3/5] mm: madvise: implement lightweight guard page mechanism

2024-10-21 Thread Vlastimil Babka
On 10/21/24 22:17, David Hildenbrand wrote: > On 21.10.24 22:11, Vlastimil Babka wrote: >> On 10/20/24 18:20, Lorenzo Stoakes wrote: >> >> >> >>> +static long madvise_guard_poison(struct vm_area_struct *vma, >>> +struct vm_area_struct **prev, >>> +

Re: [PATCH v2 3/5] mm: madvise: implement lightweight guard page mechanism

2024-10-21 Thread Lorenzo Stoakes
On Mon, Oct 21, 2024 at 10:25:06PM +0200, Vlastimil Babka wrote: > On 10/21/24 22:17, David Hildenbrand wrote: > > On 21.10.24 22:11, Vlastimil Babka wrote: > >> On 10/20/24 18:20, Lorenzo Stoakes wrote: > >> > >> > >> > >>> +static long madvise_guard_poison(struct vm_area_struct *vma, > >>> +

Re: [PATCH v2 3/5] mm: madvise: implement lightweight guard page mechanism

2024-10-21 Thread Lorenzo Stoakes
On Mon, Oct 21, 2024 at 10:11:29PM +0200, Vlastimil Babka wrote: > On 10/20/24 18:20, Lorenzo Stoakes wrote: > > Implement a new lightweight guard page feature, that is regions of userland > > virtual memory that, when accessed, cause a fatal signal to arise. > > > > Currently users must establish

Re: [PATCH v2 3/5] mm: madvise: implement lightweight guard page mechanism

2024-10-21 Thread David Hildenbrand
On 21.10.24 21:39, Lorenzo Stoakes wrote: On Mon, Oct 21, 2024 at 12:25:08PM -0700, John Hubbard wrote: On 10/21/24 10:23 AM, David Hildenbrand wrote: [snip] Just to raise it here: MADV_GUARD_INSTALL / MADV_GUARD_REMOVE or sth. like that would have been even clearer, at least to me. Yes, I t

Re: [PATCH v2 3/5] mm: madvise: implement lightweight guard page mechanism

2024-10-21 Thread David Hildenbrand
On 21.10.24 22:11, Vlastimil Babka wrote: On 10/20/24 18:20, Lorenzo Stoakes wrote: Implement a new lightweight guard page feature, that is regions of userland virtual memory that, when accessed, cause a fatal signal to arise. Currently users must establish PROT_NONE ranges to achieve this. Ho

Re: [PATCH v2 3/5] mm: madvise: implement lightweight guard page mechanism

2024-10-21 Thread Vlastimil Babka
On 10/20/24 18:20, Lorenzo Stoakes wrote: > Implement a new lightweight guard page feature, that is regions of userland > virtual memory that, when accessed, cause a fatal signal to arise. > > Currently users must establish PROT_NONE ranges to achieve this. > > However this is very costly memory-

Re: [PATCH v2 2/5] mm: add PTE_MARKER_GUARD PTE marker

2024-10-21 Thread Lorenzo Stoakes
On Mon, Oct 21, 2024 at 03:45:31PM +0200, Vlastimil Babka wrote: [snip] > > Signed-off-by: Lorenzo Stoakes > > Acked-by: Vlastimil Babka Thanks! > > A nit below: > > > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > > index 906294ac85dc..50e3f6ed73ac 100644 > > --- a/mm/hugetlb.c > > +++ b/mm/hugetl

Re: [PATCH v2 3/5] mm: madvise: implement lightweight guard page mechanism

2024-10-21 Thread Lorenzo Stoakes
On Mon, Oct 21, 2024 at 12:25:08PM -0700, John Hubbard wrote: > On 10/21/24 10:23 AM, David Hildenbrand wrote: [snip] > > > > Just to raise it here: MADV_GUARD_INSTALL / MADV_GUARD_REMOVE or sth. > > > > like > > > > that would have been even clearer, at least to me. > > Yes, I think so. > > > > >

Re: [PATCH v2 3/5] mm: madvise: implement lightweight guard page mechanism

2024-10-21 Thread John Hubbard
On 10/21/24 10:23 AM, David Hildenbrand wrote: On 21.10.24 19:15, Lorenzo Stoakes wrote: On Mon, Oct 21, 2024 at 07:05:27PM +0200, David Hildenbrand wrote: On 20.10.24 18:20, Lorenzo Stoakes wrote: Implement a new lightweight guard page feature, that is regions of userland virtual memory that,

Re: [PATCH v2 2/5] mm: add PTE_MARKER_GUARD PTE marker

2024-10-21 Thread Vlastimil Babka
On 10/21/24 19:14, Lorenzo Stoakes wrote: > On Mon, Oct 21, 2024 at 07:00:53PM +0200, David Hildenbrand wrote: >> >> > >> > > >> > > > >> > > > Also the existing logic is that existing markers (HW poison, >> > > > uffd-simulated HW >> > > > poison, uffd wp marker) are retained and no error raised

Re: [PATCH v2 3/5] mm: madvise: implement lightweight guard page mechanism

2024-10-21 Thread David Hildenbrand
On 21.10.24 19:15, Lorenzo Stoakes wrote: On Mon, Oct 21, 2024 at 07:05:27PM +0200, David Hildenbrand wrote: On 20.10.24 18:20, Lorenzo Stoakes wrote: Implement a new lightweight guard page feature, that is regions of userland virtual memory that, when accessed, cause a fatal signal to arise.

Re: [PATCH v2 2/5] mm: add PTE_MARKER_GUARD PTE marker

2024-10-21 Thread David Hildenbrand
Also the existing logic is that existing markers (HW poison, uffd-simulated HW poison, uffd wp marker) are retained and no error raised on MADV_DONTNEED, and no error on MADV_FREE either, so it'd be consistent with existing behaviour. HW poison / uffd-simulated HW poison are expected to

Re: [PATCH v2 3/5] mm: madvise: implement lightweight guard page mechanism

2024-10-21 Thread Lorenzo Stoakes
On Mon, Oct 21, 2024 at 07:05:27PM +0200, David Hildenbrand wrote: > On 20.10.24 18:20, Lorenzo Stoakes wrote: > > Implement a new lightweight guard page feature, that is regions of userland > > virtual memory that, when accessed, cause a fatal signal to arise. > > > > Currently users must establis

Re: [PATCH v2 2/5] mm: add PTE_MARKER_GUARD PTE marker

2024-10-21 Thread Lorenzo Stoakes
On Mon, Oct 21, 2024 at 07:00:53PM +0200, David Hildenbrand wrote: > On 21.10.24 18:51, Lorenzo Stoakes wrote: > > On Mon, Oct 21, 2024 at 06:44:04PM +0200, David Hildenbrand wrote: > > > On 21.10.24 18:23, Lorenzo Stoakes wrote: > > > > On Mon, Oct 21, 2024 at 06:00:20PM +0200, David Hildenbrand w

Re: [PATCH v2 3/5] mm: madvise: implement lightweight guard page mechanism

2024-10-21 Thread David Hildenbrand
On 20.10.24 18:20, Lorenzo Stoakes wrote: Implement a new lightweight guard page feature, that is regions of userland virtual memory that, when accessed, cause a fatal signal to arise. Currently users must establish PROT_NONE ranges to achieve this. However this is very costly memory-wise - we

Re: [PATCH v2 2/5] mm: add PTE_MARKER_GUARD PTE marker

2024-10-21 Thread David Hildenbrand
On 21.10.24 18:51, Lorenzo Stoakes wrote: On Mon, Oct 21, 2024 at 06:44:04PM +0200, David Hildenbrand wrote: On 21.10.24 18:23, Lorenzo Stoakes wrote: On Mon, Oct 21, 2024 at 06:00:20PM +0200, David Hildenbrand wrote: [snip] To summarise for on-list: * MADV_FREE, while ostensibly being a 'la

Re: [PATCH v2 2/5] mm: add PTE_MARKER_GUARD PTE marker

2024-10-21 Thread Lorenzo Stoakes
On Mon, Oct 21, 2024 at 06:44:04PM +0200, David Hildenbrand wrote: > On 21.10.24 18:23, Lorenzo Stoakes wrote: > > On Mon, Oct 21, 2024 at 06:00:20PM +0200, David Hildenbrand wrote: > > [snip] > > > > > > > > To summarise for on-list: > > > > > > > > * MADV_FREE, while ostensibly being a 'lazy free

Re: [PATCH v2 2/5] mm: add PTE_MARKER_GUARD PTE marker

2024-10-21 Thread David Hildenbrand
On 21.10.24 18:23, Lorenzo Stoakes wrote: On Mon, Oct 21, 2024 at 06:00:20PM +0200, David Hildenbrand wrote: [snip] To summarise for on-list: * MADV_FREE, while ostensibly being a 'lazy free' mechanism, has the ability to be 'cancelled' if you write to the memory. Also, after the freei

Re: [PATCH v2 2/5] mm: add PTE_MARKER_GUARD PTE marker

2024-10-21 Thread Lorenzo Stoakes
On Mon, Oct 21, 2024 at 06:00:20PM +0200, David Hildenbrand wrote: [snip] > > > > To summarise for on-list: > > > > * MADV_FREE, while ostensibly being a 'lazy free' mechanism, has the > >ability to be 'cancelled' if you write to the memory. Also, after the > >freeing is complete, you can w

Re: [PATCH v2 2/5] mm: add PTE_MARKER_GUARD PTE marker

2024-10-21 Thread David Hildenbrand
On 21.10.24 17:33, Lorenzo Stoakes wrote: On Mon, Oct 21, 2024 at 04:54:06PM +0200, Vlastimil Babka wrote: On 10/21/24 16:33, Lorenzo Stoakes wrote: On Mon, Oct 21, 2024 at 04:13:34PM +0200, Vlastimil Babka wrote: On 10/20/24 18:20, Lorenzo Stoakes wrote: Add a new PTE marker that results in

Re: [PATCH v2 2/5] mm: add PTE_MARKER_GUARD PTE marker

2024-10-21 Thread Lorenzo Stoakes
On Mon, Oct 21, 2024 at 04:33:19PM +0100, Lorenzo Stoakes wrote: [snip] > * For hardware poison markers it makes sense to drop them as you're > effectively saying 'I am done with this range that is now unbacked and > expect to get an empty page should I use it now'. UFFD WP I am not sure >

Re: [PATCH v2 2/5] mm: add PTE_MARKER_GUARD PTE marker

2024-10-21 Thread Lorenzo Stoakes
On Mon, Oct 21, 2024 at 04:54:06PM +0200, Vlastimil Babka wrote: > On 10/21/24 16:33, Lorenzo Stoakes wrote: > > On Mon, Oct 21, 2024 at 04:13:34PM +0200, Vlastimil Babka wrote: > >> On 10/20/24 18:20, Lorenzo Stoakes wrote: > >> > Add a new PTE marker that results in any access causing the accessi

Re: [PATCH v2 2/5] mm: add PTE_MARKER_GUARD PTE marker

2024-10-21 Thread Vlastimil Babka
On 10/21/24 16:33, Lorenzo Stoakes wrote: > On Mon, Oct 21, 2024 at 04:13:34PM +0200, Vlastimil Babka wrote: >> On 10/20/24 18:20, Lorenzo Stoakes wrote: >> > Add a new PTE marker that results in any access causing the accessing >> > process to segfault. >> > >> > This is preferable to PTE_MARKER_P

Re: [PATCH v2 2/5] mm: add PTE_MARKER_GUARD PTE marker

2024-10-21 Thread Lorenzo Stoakes
On Mon, Oct 21, 2024 at 04:13:34PM +0200, Vlastimil Babka wrote: > On 10/20/24 18:20, Lorenzo Stoakes wrote: > > Add a new PTE marker that results in any access causing the accessing > > process to segfault. > > > > This is preferable to PTE_MARKER_POISONED, which results in the same > > handling a

Re: [PATCH v2 2/5] mm: add PTE_MARKER_GUARD PTE marker

2024-10-21 Thread Vlastimil Babka
On 10/20/24 18:20, Lorenzo Stoakes wrote: > Add a new PTE marker that results in any access causing the accessing > process to segfault. > > This is preferable to PTE_MARKER_POISONED, which results in the same > handling as hardware poisoned memory, and is thus undesirable for cases > where we sim

Re: [PATCH v2 1/5] mm: pagewalk: add the ability to install PTEs

2024-10-21 Thread Lorenzo Stoakes
On Mon, Oct 21, 2024 at 03:27:55PM +0200, Vlastimil Babka wrote: > On 10/20/24 18:20, Lorenzo Stoakes wrote: > > The existing generic pagewalk logic permits the walking of page tables, > > invoking callbacks at individual page table levels via user-provided > > mm_walk_ops callbacks. > > > > This i

Re: [PATCH v2 2/5] mm: add PTE_MARKER_GUARD PTE marker

2024-10-21 Thread Vlastimil Babka
On 10/20/24 18:20, Lorenzo Stoakes wrote: > Add a new PTE marker that results in any access causing the accessing > process to segfault. Should we distinguish it from other segfaults? Is there a way? I can see memory protection keys use SEGV_PKUERR, but no idea if we have any free values. > This

Re: [PATCH v2 1/5] mm: pagewalk: add the ability to install PTEs

2024-10-21 Thread Vlastimil Babka
On 10/20/24 18:20, Lorenzo Stoakes wrote: > The existing generic pagewalk logic permits the walking of page tables, > invoking callbacks at individual page table levels via user-provided > mm_walk_ops callbacks. > > This is useful for traversing existing page table entries, but precludes > the abi