Re: [PATCH 1/2] compiler.h: Introduce ptr_eq() to preserve address dependency

2024-10-07 Thread Jonas Oberhauser
Am 10/7/2024 um 3:18 PM schrieb David Laight: From: Jonas Oberhauser Sent: 07 October 2024 12:55 Am 10/3/2024 um 3:23 PM schrieb Mathieu Desnoyers: What _does_ work however are the following two approaches: 1) Perform the equality check on the original variables, creating new versions

Re: [PATCH 1/2] compiler.h: Introduce ptr_eq() to preserve address dependency

2024-10-07 Thread Jonas Oberhauser
Am 10/3/2024 um 3:23 PM schrieb Mathieu Desnoyers: What _does_ work however are the following two approaches: 1) Perform the equality check on the original variables, creating new versions (with OPTIMIZER_HIDE_VAR) of both variables for the rest of their use, therefore making sure the pointer

Re: [PATCH 1/2] compiler.h: Introduce ptr_eq() to preserve address dependency

2024-09-30 Thread Jonas Oberhauser
Am 9/30/2024 um 6:43 PM schrieb Alan Stern: On Mon, Sep 30, 2024 at 01:26:53PM +0200, Jonas Oberhauser wrote: Am 9/28/2024 um 4:49 PM schrieb Alan Stern: On Sat, Sep 28, 2024 at 09:51:27AM -0400, Mathieu Desnoyers wrote: Compiler CSE and SSA GVN optimizations can cause the address

Re: [PATCH 1/2] compiler.h: Introduce ptr_eq() to preserve address dependency

2024-09-30 Thread Jonas Oberhauser
Am 9/30/2024 um 1:04 PM schrieb Paul E. McKenney: On Mon, Sep 30, 2024 at 11:42:11AM +0200, Jonas Oberhauser wrote: I also currently don't see any major difference between the constant and register case. The point is that the address is known before loading into b, and hence the com

Re: [PATCH 1/2] compiler.h: Introduce ptr_eq() to preserve address dependency

2024-09-30 Thread Jonas Oberhauser
Am 9/28/2024 um 4:49 PM schrieb Alan Stern: On Sat, Sep 28, 2024 at 09:51:27AM -0400, Mathieu Desnoyers wrote: Compiler CSE and SSA GVN optimizations can cause the address dependency of addresses returned by rcu_dereference to be lost when comparing those pointers with either constants or pre

Re: [PATCH 1/2] compiler.h: Introduce ptr_eq() to preserve address dependency

2024-09-30 Thread Jonas Oberhauser
Am 9/28/2024 um 11:15 PM schrieb Alan Stern: On Sat, Sep 28, 2024 at 11:55:22AM -0400, Mathieu Desnoyers wrote: On 2024-09-28 17:49, Alan Stern wrote: Isn't it true that on strongly ordered CPUs, a compiler barrier is sufficient to prevent the rcu_dereference() problem? So the whole idea be

Re: [PATCH 1/2] compiler.h: Introduce ptr_eq() to preserve address dependency

2024-09-30 Thread Jonas Oberhauser
Am 9/30/2024 um 11:27 AM schrieb Alan Huang: 2024年9月30日 17:15,Alan Huang 写道: 2024年9月30日 16:57,Jonas Oberhauser 写道: Am 9/29/2024 um 12:26 AM schrieb Alan Huang: 2024年9月28日 23:55,Mathieu Desnoyers wrote: The motivation for introducing ptr_eq() is indeed because the compiler barrier

Re: [PATCH 1/2] compiler.h: Introduce ptr_eq() to preserve address dependency

2024-09-30 Thread Jonas Oberhauser
Am 9/29/2024 um 12:26 AM schrieb Alan Huang: 2024年9月28日 23:55,Mathieu Desnoyers wrote: On 2024-09-28 17:49, Alan Stern wrote: On Sat, Sep 28, 2024 at 11:32:18AM -0400, Mathieu Desnoyers wrote: On 2024-09-28 16:49, Alan Stern wrote: On Sat, Sep 28, 2024 at 09:51:27AM -0400, Mathieu Desnoy

Re: [RFC PATCH 1/1] hpref: Hazard Pointers with Reference Counter

2024-09-28 Thread Jonas Oberhauser
Thanks for your response, Am 9/28/2024 um 1:33 PM schrieb Mathieu Desnoyers: This is a userspace prototype. This will behave similarly to a userspace spinlock in that case, which is not great in terms of CPU usage, but should eventually unblock the waiter, unless it has a RT priority that reall

Re: [RFC PATCH 1/1] hpref: Hazard Pointers with Reference Counter

2024-09-28 Thread Jonas Oberhauser
Two more questions below: Am 9/21/2024 um 6:42 PM schrieb Mathieu Desnoyers: +#define NR_PERCPU_SLOTS_BITS 3 Have you measured any advantage of this multi-slot version vs a version with just one normal slot and one emergency slot? With just one normal slot, the normal slot version would alw

Re: [RFC PATCH 1/4] hazptr: Add initial implementation of hazard pointers

2024-09-27 Thread Jonas Oberhauser
Am 9/27/2024 um 10:10 PM schrieb Mathieu Desnoyers: On 2024-09-27 21:23, Jonas Oberhauser wrote: [...] That idea seems to be confirmed by this (atrocious, not to be copied!) example: int fct_escape_address_of_b(void) { int *a, *b; do { a = READ_ONCE(p); asm

Re: [RFC PATCH 1/4] hazptr: Add initial implementation of hazard pointers

2024-09-27 Thread Jonas Oberhauser
Two comments inline, Am 9/27/2024 um 6:38 AM schrieb Boqun Feng: compilers can replace 'ptr' with 'head' because of the equality, and even putting barrier() here cannot prevent compiler to rewrite the else branch into: else { barrier(); return head;

Re: [RFC PATCH 1/4] hazptr: Add initial implementation of hazard pointers

2024-09-27 Thread Jonas Oberhauser
Am 9/27/2024 um 8:13 PM schrieb Linus Torvalds: Because even hiding the value one from the compiler will mean that it can't use the comparison to decide that the originals are equal, even if one of them is unhidden. No? Linus I think it depends on which one you hide. If yo

Re: [RFC PATCH 1/4] hazptr: Add initial implementation of hazard pointers

2024-09-26 Thread Jonas Oberhauser
Am 9/26/2024 um 6:12 PM schrieb Linus Torvalds: On Thu, 26 Sept 2024 at 08:54, Jonas Oberhauser wrote: No, the issue introduced by the compiler optimization (or by your original patch) is that the CPU can speculatively load from the first pointer as soon as it has completed the load of

Re: [RFC PATCH 1/4] hazptr: Add initial implementation of hazard pointers

2024-09-26 Thread Jonas Oberhauser
Am 9/26/2024 um 8:16 AM schrieb Mathieu Desnoyers: On 2024-09-25 15:20, Mathieu Desnoyers wrote: [...] static inline bool same_ptr(void *a, void *b) { asm goto ( "cmpq %[a], %[b]\n\t" "jne %l[ne]\n\t" : : [a] "r" (a), [b] "r" (b) : : ne); return t

Re: [RFC PATCH 1/4] hazptr: Add initial implementation of hazard pointers

2024-09-25 Thread Jonas Oberhauser
Am 9/25/2024 um 1:59 PM schrieb Mathieu Desnoyers: On 2024-09-25 12:45, Boqun Feng wrote: On Wed, Sep 25, 2024 at 12:11:52PM +0200, Jonas Oberhauser wrote: Am 9/25/2024 um 12:02 PM schrieb Boqun Feng: Hi Jonas, Of course, if we are really worried about compilers being too "smart&

Re: [RFC PATCH 1/1] hpref: Hazard Pointers with Reference Counter

2024-09-25 Thread Jonas Oberhauser
Am 9/25/2024 um 1:36 PM schrieb Mathieu Desnoyers: On 2024-09-25 12:06, Jonas Oberhauser wrote: Am 9/25/2024 um 8:35 AM schrieb Mathieu Desnoyers: On 2024-09-25 07:57, Jonas Oberhauser wrote: Hi Mathieu, I haven't read your code in detail but it seems to me you have an ABA bug:

Re: [RFC PATCH 1/4] hazptr: Add initial implementation of hazard pointers

2024-09-25 Thread Jonas Oberhauser
Am 9/25/2024 um 12:02 PM schrieb Boqun Feng: Hi Jonas, Of course, if we are really worried about compilers being too "smart" Ah, I see you know me better and better... we can always do the comparison in asm code, then compilers don't know anything of the equality between 'ptr' and 'head -

Re: [RFC PATCH 1/1] hpref: Hazard Pointers with Reference Counter

2024-09-25 Thread Jonas Oberhauser
Am 9/25/2024 um 8:35 AM schrieb Mathieu Desnoyers: On 2024-09-25 07:57, Jonas Oberhauser wrote: Hi Mathieu, I haven't read your code in detail but it seems to me you have an ABA bug: as I explained elsewhere, you could read the same pointer after ABA but you don't synchroniz

Re: [RFC PATCH 1/1] hpref: Hazard Pointers with Reference Counter

2024-09-24 Thread Jonas Oberhauser
Hi Mathieu, interesting idea. Conceptually it looks good. There's another approach of using hazard pointer to optimize shared reference counting (to make it lock-free in common cases). https://github.com/cmuparlay/concurrent_deferred_rc It doesn't go as far as what you're doing, but they als

Re: [RFC PATCH 1/4] hazptr: Add initial implementation of hazard pointers

2024-09-20 Thread Jonas Oberhauser
Am 9/19/2024 um 10:30 PM schrieb Jonas Oberhauser: Am 9/19/2024 um 2:12 AM schrieb Jann Horn: On Tue, Sep 17, 2024 at 4:33 PM Boqun Feng wrote: Hazard pointers [1] provide a way to dynamically distribute refcounting and can be used to improve the scalability of refcounting without

Re: [RFC PATCH 1/4] hazptr: Add initial implementation of hazard pointers

2024-09-20 Thread Jonas Oberhauser
Am 9/17/2024 um 4:33 PM schrieb Boqun Feng: +static inline void *__hazptr_tryprotect(hazptr_t *hzp, + void *const *p, + unsigned long head_offset) +{ + void *ptr; + struct callback_head *head; + + ptr

Re: [RFC PATCH 1/4] hazptr: Add initial implementation of hazard pointers

2024-09-19 Thread Jonas Oberhauser
Am 9/19/2024 um 2:12 AM schrieb Jann Horn: On Tue, Sep 17, 2024 at 4:33 PM Boqun Feng wrote: Hazard pointers [1] provide a way to dynamically distribute refcounting and can be used to improve the scalability of refcounting without significant space cost. +static inline void *__hazptr_try

Re: [RFC PATCH 1/4] hazptr: Add initial implementation of hazard pointers

2024-09-19 Thread Jonas Oberhauser
Am 9/19/2024 um 8:56 AM schrieb Boqun Feng: On Wed, Sep 18, 2024 at 11:17:37PM +0800, Alan Huang wrote: [...] +#define hazptr_tryprotect(hzp, gp, field) (typeof(gp))__hazptr_tryprotect(hzp, (void **)&(gp), offsetof(typeof(*gp), field)) +#define hazptr_protect(hzp, gp, field) ({ \ + typeof(gp

Re: [RFC PATCH 1/4] hazptr: Add initial implementation of hazard pointers

2024-09-19 Thread Jonas Oberhauser
Am 9/17/2024 um 4:33 PM schrieb Boqun Feng: +#define hazptr_protect(hzp, gp, field) ({ \ + typeof(gp) ___p;\ + \ + ___p = hazptr_trypro