Replace smp_read_barrier_depends() with lockless_derefrence()
Subsystems (14)
v2 cover Replace smp_read_barrier_depends() with lockless_derefrence()
Recently lockless_dereference() was added which can be used in place of hard-coding smp_read_barrier_depends().
http://lkml.iu.edu/hypermail/linux/kernel/1410.3/04561.html
The following series tries to do this.
There are still some hard-coded locations which I was not sure how to replace with. I will send in separate patches/questions regarding them.
Pranith Kumar (9):
doc: memory-barriers.txt: Document use of lockless_dereference()
drivers: dma: Replace smp_read_barrier_depends() with
lockless_dereference()
dcache: Replace smp_read_barrier_depends() with lockless_dereference()
hyperv: Replace smp_read_barrier_depends() with lockless_dereference()
percpu: Replace smp_read_barrier_depends() with lockless_dereference()
perf: Replace smp_read_barrier_depends() with lockless_dereference()
seccomp: Replace smp_read_barrier_depends() with
lockless_dereference()
task_work: Replace smp_read_barrier_depends() with
lockless_dereference()
netfilter: Replace smp_read_barrier_depends() with
lockless_dereference()
Documentation/memory-barriers.txt | 4 ++-- drivers/dma/ioat/dma_v2.c | 3 +-- drivers/dma/ioat/dma_v3.c | 3 +-- fs/dcache.c | 7 ++----- include/linux/hyperv.h | 9 ++++----- include/linux/percpu-refcount.h | 4 +--- kernel/events/core.c | 3 +-- kernel/events/uprobes.c | 8 ++++---- kernel/seccomp.c | 7 +++---- kernel/task_work.c | 3 +-- net/ipv4/netfilter/arp_tables.c | 3 +-- net/ipv4/netfilter/ip_tables.c | 3 +-- net/ipv6/netfilter/ip6_tables.c | 3 +-- 13 files changed, 23 insertions(+), 37 deletions(-)
Signature · 7 lines
1.9.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v2 1/9 doc: memory-barriers.txt: Document use of lockless_dereference()
Recently lockless_dereference() was added which can be used in place of hard-coding smp_read_barrier_depends(). The following PATCH makes the change.
--- Documentation/memory-barriers.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Documentation/memory-barriers.txt +2 -2
@@ -203,8 +203,8 @@ There are some minimal guarantees that may be expected of a CPU: and always in that order. On most systems, smp_read_barrier_depends() does nothing, but it is required for DEC Alpha. The ACCESS_ONCE() is required to prevent compiler mischief. Please note that you - should normally use something like rcu_dereference() instead of - open-coding smp_read_barrier_depends(). + should normally use something like rcu_dereference() or + lockless_dereference() instead of open-coding smp_read_barrier_depends(). (*) Overlapping loads and stores within a particular CPU will appear to be ordered within that CPU. This means that for:
Signature · 1 line
1.9.1
PATCH v2 2/9 drivers: dma: Replace smp_read_barrier_depends() with lockless_dereference()
In reply to Pranith KumarRecently lockless_dereference() was added which can be used in place of hard-coding smp_read_barrier_depends(). The following PATCH makes the change.
--- drivers/dma/ioat/dma_v2.c | 3 +-- drivers/dma/ioat/dma_v3.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-)
drivers/dma/ioat/dma_v2.c +1 -2
@@ -142,10 +142,9 @@ static void __cleanup(struct ioat2_dma_chan *ioat, dma_addr_t phys_complete) active =ioat2_ring_active (ioat);for (i =0 ; i < active && !seen_current; i++) { -smp_read_barrier_depends ();prefetch (ioat2_get_ring_ent (ioat, idx + i +1 )); desc =ioat2_get_ring_ent (ioat, idx + i); - tx = &desc->txd; + tx = &lockless_dereference (desc)->txd;dump_desc_dbg (ioat, desc);if (tx->cookie) {dma_descriptor_unmap (tx);
drivers/dma/ioat/dma_v3.c +1 -2
@@ -389,7 +389,6 @@ static void __cleanup(struct ioat2_dma_chan *ioat, dma_addr_t phys_complete)for (i =0 ; i < active && !seen_current; i++) {struct dma_async_tx_descriptor *tx; -smp_read_barrier_depends ();prefetch (ioat2_get_ring_ent (ioat, idx + i +1 )); desc =ioat2_get_ring_ent (ioat, idx + i);dump_desc_dbg (ioat, desc);
@@ -398,7 +397,7 @@ static void __cleanup(struct ioat2_dma_chan *ioat, dma_addr_t phys_complete)if (device->cap &IOAT_CAP_DWBES )desc_get_errstat (ioat, desc); - tx = &desc->txd; + tx = &lockless_dereference (desc)->txd;if (tx->cookie) {dma_cookie_complete (tx);dma_descriptor_unmap (tx);
Signature · 1 line
1.9.1
PATCH v2 3/9 dcache: Replace smp_read_barrier_depends() with lockless_dereference()
In reply to Pranith KumarRecently lockless_dereference() was added which can be used in place of hard-coding smp_read_barrier_depends(). The following PATCH makes the change.
--- fs/dcache.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
fs/dcache.c +2 -5
@@ -230,8 +230,7 @@ static inline int dentry_cmp(const struct dentry *dentry, const unsigned char *c* early because the data cannot match (there can * be no NUL in the ct/tcount data) */ - cs =ACCESS_ONCE (dentry->d_name.name); -smp_read_barrier_depends (); + cs =lockless_dereference (dentry->d_name.name);return dentry_string_cmp (cs, ct, tcount); }
@@ -2714,10 +2713,8 @@ static int prepend(char **buffer, int *buflen, const char *str, int namelen)static int prepend_name (char **buffer,int *buflen,struct qstr *name) {const char *dname =ACCESS_ONCE (name->name); -u32 dlen =ACCESS_ONCE (name->len);char *p; - -smp_read_barrier_depends (); +u32 dlen =lockless_dereference (name->len); *buflen -= dlen +1 ;if (*buflen <0 )
Signature · 1 line
1.9.1
PATCH v2 4/9 hyperv: Replace smp_read_barrier_depends() with lockless_dereference()
In reply to Pranith KumarRecently lockless_dereference() was added which can be used in place of hard-coding smp_read_barrier_depends(). The following PATCH makes the change.
--- include/linux/hyperv.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
include/linux/hyperv.h +4 -5
@@ -127,13 +127,12 @@ hv_get_ringbuffer_availbytes(struct hv_ring_buffer_info *rbi, u32 *read, u32 *write) {u32 read_loc, write_loc, dsize; - -smp_read_barrier_depends (); +struct hv_ring_buffer_info *rbi_p =lockless_dereference (rbi);/* Capture the read/write indices before they changed */ - read_loc = rbi->ring_buffer->read_index; - write_loc = rbi->ring_buffer->write_index; - dsize = rbi->ring_datasize; + read_loc = rbi_p->ring_buffer->read_index; + write_loc = rbi_p->ring_buffer->write_index; + dsize = rbi_p->ring_datasize; *write = write_loc >= read_loc ? dsize - (write_loc - read_loc) : read_loc - write_loc;
Signature · 1 line
1.9.1
PATCH v2 5/9 percpu: Replace smp_read_barrier_depends() with lockless_dereference()
In reply to Pranith KumarRecently lockless_dereference() was added which can be used in place of hard-coding smp_read_barrier_depends(). The following PATCH makes the change.
--- include/linux/percpu-refcount.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
include/linux/percpu-refcount.h +1 -3
@@ -128,10 +128,8 @@ static inline void percpu_ref_kill(struct percpu_ref *ref)static inline bool __ref_is_percpu (struct percpu_ref *ref,unsigned long __percpu **percpu_countp) { -unsigned long percpu_ptr =ACCESS_ONCE (ref->percpu_count_ptr); -/* paired with smp_store_release() in percpu_ref_reinit() */ -smp_read_barrier_depends (); +unsigned long percpu_ptr =lockless_dereference (ref->percpu_count_ptr);if (unlikely (percpu_ptr & __PERCPU_REF_ATOMIC))return false;
Signature · 1 line
1.9.1
Re: [PATCH v2 5/9] percpu: Replace smp_read_barrier_depends() with lockless_dereference()
Quoted 4 lines · Pranith Kumar
Recently
lockless_dereference()was added which can be used in place of hard-codingsmp_read_barrier_depends(). The following PATCH makes the change.Signed-off-by Pranith Kumar <[email protected]>
Applied to percpu/for-3.19.
Thanks.
Signature · 1 line
tejun
Re: [PATCH v2 5/9] percpu: Replace smp_read_barrier_depends() with lockless_dereference()
In reply to Pranith KumarQuoted 4 lines · Pranith Kumar
Recently
lockless_dereference()was added which can be used in place of hard-codingsmp_read_barrier_depends(). The following PATCH makes the change.Signed-off-by Pranith Kumar <[email protected]>
Applied to percpu/for-3.19.
Thanks.
Signature · 1 line
tejun
PATCH v2 6/9 perf: Replace smp_read_barrier_depends() with lockless_dereference()
In reply to Pranith KumarRecently lockless_dereference() was added which can be used in place of hard-coding smp_read_barrier_depends(). The following PATCH makes the change.
--- kernel/events/core.c | 3 +-- kernel/events/uprobes.c | 8 ++++---- 2 files changed, 5 insertions(+), 6 deletions(-)
kernel/events/core.c +1 -2
@@ -3400,14 +3400,13 @@ static void perf_remove_from_owner(struct perf_event *event)struct task_struct *owner;rcu_read_lock (); - owner =ACCESS_ONCE (event->owner);/* * Matches the smp_wmb() in perf_event_exit_task(). If we observe * !owner it means the list deletion is complete and we can indeed * free this event, otherwise we need to serialize on * owner->perf_event_mutex. */ -smp_read_barrier_depends (); + owner =lockless_dereference (event->owner);if (owner) {/* * Since delayed_put_task_struct() also drops the last
kernel/events/uprobes.c +4 -4
@@ -1212,8 +1212,8 @@ static struct xol_area *get_xol_area(void)if (!mm->uprobes_state.xol_area)__create_xol_area (0 ); - area = mm->uprobes_state.xol_area; -smp_read_barrier_depends ();/* pairs with wmb in xol_add_vma() */ +/* pairs with wmb in xol_add_vma() */ + area =lockless_dereference (mm->uprobes_state.xol_area);return area; }
@@ -1507,8 +1507,8 @@ static unsigned long get_trampoline_vaddr(void)struct xol_area *area;unsigned long trampoline_vaddr =-1 ; - area = current->mm->uprobes_state.xol_area; -smp_read_barrier_depends (); + area =lockless_dereference (current->mm->uprobes_state.xol_area); +if (area) trampoline_vaddr = area->vaddr;
Signature · 1 line
1.9.1
PATCH v2 7/9 seccomp: Replace smp_read_barrier_depends() with lockless_dereference()
In reply to Pranith KumarRecently lockless_dereference() was added which can be used in place of hard-coding smp_read_barrier_depends(). The following PATCH makes the change.
--- kernel/seccomp.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
kernel/seccomp.c +3 -4
@@ -175,17 +175,16 @@ static int seccomp_check_filter(struct sock_filter *filter, unsigned int flen)*/ static u32 seccomp_run_filters (struct seccomp_data *sd) { -struct seccomp_filter *f =ACCESS_ONCE (current->seccomp.filter);struct seccomp_data sd_local;u32 ret =SECCOMP_RET_ALLOW ; +/* Make sure cross-thread synced filter points somewhere sane. */ +struct seccomp_filter *f = +lockless_dereference (current->seccomp.filter);/* Ensure unexpected behavior doesn't result in failing open. */ if (unlikely (WARN_ON (f ==NULL )))return SECCOMP_RET_KILL ; -/* Make sure cross-thread synced filter points somewhere sane. */ -smp_read_barrier_depends (); -if (!sd) {populate_seccomp_data (&sd_local); sd = &sd_local;
Signature · 1 line
1.9.1
Re: [PATCH v2 7/9] seccomp: Replace smp_read_barrier_depends() with lockless_dereference()
Quoted 7 lines · Pranith Kumar
Recently
lockless_dereference()was added which can be used in place of hard-codingsmp_read_barrier_depends(). The following PATCH makes the change.Signed-off-by Pranith Kumar <[email protected]>--- kernel/seccomp.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
Thanks!
Do you need me to carry this patch in the seccomp tree, or will someone else be taking your entire series?
-Kees
Quoted 29 lines
kernel/seccomp.c +3
-5@@ -175,17 +175,16 @@ static int seccomp_check_filter(struct sock_filter *filter, unsigned int flen)*/ static u32 seccomp_run_filters (struct seccomp_data *sd) { -struct seccomp_filter *f =ACCESS_ONCE (current->seccomp.filter);struct seccomp_data sd_local;u32 ret =SECCOMP_RET_ALLOW ; +/* Make sure cross-thread synced filter points somewhere sane. */ +struct seccomp_filter *f = +lockless_dereference (current->seccomp.filter);/* Ensure unexpected behavior doesn't result in failing open. */ if (unlikely (WARN_ON (f ==NULL )))return SECCOMP_RET_KILL ; -/* Make sure cross-thread synced filter points somewhere sane. */ -smp_read_barrier_depends (); -if (!sd) {populate_seccomp_data (&sd_local); sd = &sd_local; --1.9.1
Signature · 2 lines
Kees Cook Chrome OS Security
Re: [PATCH v2 7/9] seccomp: Replace smp_read_barrier_depends() with lockless_dereference()
Quoted 8 lines · Kees Cook
Quoted 7 lines · Pranith Kumar
Recently
lockless_dereference()was added which can be used in place of hard-codingsmp_read_barrier_depends(). The following PATCH makes the change.Signed-off-by Pranith Kumar <[email protected]>--- kernel/seccomp.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
Quoted 8 lines
Thanks!
Acked-by Kees Cook <[email protected]>Do you need me to carry this patch in the seccomp tree, or will someone else be taking your entire series?
-Kees
Please take this patch individually into your tree. There are discussions about the other patches and I will drop the accepted patches and iterate for the next version.
Thanks!
Quoted 30 lines
Quoted 28 lines
kernel/seccomp.c +3
-5@@ -175,17 +175,16 @@ static int seccomp_check_filter(struct sock_filter *filter, unsigned int flen)*/ static u32 seccomp_run_filters (struct seccomp_data *sd) { -struct seccomp_filter *f =ACCESS_ONCE (current->seccomp.filter);struct seccomp_data sd_local;u32 ret =SECCOMP_RET_ALLOW ; +/* Make sure cross-thread synced filter points somewhere sane. */ +struct seccomp_filter *f = +lockless_dereference (current->seccomp.filter);/* Ensure unexpected behavior doesn't result in failing open. */ if (unlikely (WARN_ON (f ==NULL )))return SECCOMP_RET_KILL ; -/* Make sure cross-thread synced filter points somewhere sane. */ -smp_read_barrier_depends (); -if (!sd) {populate_seccomp_data (&sd_local); sd = &sd_local; --1.9.1
PATCH v2 8/9 task_work: Replace smp_read_barrier_depends() with lockless_dereference()
In reply to Pranith KumarRecently lockless_dereference() was added which can be used in place of hard-coding smp_read_barrier_depends(). The following PATCH makes the change.
--- kernel/task_work.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
kernel/task_work.c +1 -2
@@ -62,8 +62,7 @@ task_work_cancel(struct task_struct *task, task_work_func_t func)* we raced with task_work_run(), *pprev == NULL/exited. */ raw_spin_lock_irqsave (&task->pi_lock, flags); -while ((work =ACCESS_ONCE (*pprev))) { -smp_read_barrier_depends (); +while ((work =lockless_dereference (*pprev))) {if (work->func != func) pprev = &work->next;else if (cmpxchg (pprev, work, work->next) == work)
Signature · 1 line
1.9.1
PATCH v2 9/9 netfilter: Replace smp_read_barrier_depends() with lockless_dereference()
In reply to Pranith KumarRecently lockless_dereference() was added which can be used in place of hard-coding smp_read_barrier_depends(). The following PATCH makes the change.
--- net/ipv4/netfilter/arp_tables.c | 3 +-- net/ipv4/netfilter/ip_tables.c | 3 +-- net/ipv6/netfilter/ip6_tables.c | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-)
net/ipv4/netfilter/arp_tables.c +1 -2
@@ -270,12 +270,11 @@ unsigned int arpt_do_table(struct sk_buff *skb,local_bh_disable (); addend =xt_write_recseq_begin (); - private = table->private;/* * Ensure we load private-> members after we've fetched the base * pointer. */ -smp_read_barrier_depends (); + private =lockless_dereference (table->private); table_base = private->entries[smp_processor_id ()]; e =get_entry (table_base, private->hook_entry[hook]);
net/ipv4/netfilter/ip_tables.c +1 -2
@@ -325,13 +325,12 @@ ipt_do_table(struct sk_buff *skb,IP_NF_ASSERT (table->valid_hooks & (1 << hook));local_bh_disable (); addend =xt_write_recseq_begin (); - private = table->private; cpu =smp_processor_id ();/* * Ensure we load private-> members after we've fetched the base * pointer. */ -smp_read_barrier_depends (); + private =lockless_dereference (table->private); table_base = private->entries[cpu]; jumpstack = (struct ipt_entry **)private->jumpstack[cpu]; stackptr =per_cpu_ptr (private->stackptr, cpu);
net/ipv6/netfilter/ip6_tables.c +1 -2
@@ -348,12 +348,11 @@ ip6t_do_table(struct sk_buff *skb,local_bh_disable (); addend =xt_write_recseq_begin (); - private = table->private;/* * Ensure we load private-> members after we've fetched the base * pointer. */ -smp_read_barrier_depends (); + private =lockless_dereference (table->private); cpu =smp_processor_id (); table_base = private->entries[cpu]; jumpstack = (struct ip6t_entry **)private->jumpstack[cpu];
Signature · 1 line
1.9.1
Re: [PATCH v2 9/9] netfilter: Replace smp_read_barrier_depends() with lockless_dereference()
Quoted 17 lines · Pranith Kumar
Recently
lockless_dereference()was added which can be used in place of hard-codingsmp_read_barrier_depends(). The following PATCH makes the change.Signed-off-by Pranith Kumar <[email protected]>--- net/ipv4/netfilter/arp_tables.c | 3 +-- net/ipv4/netfilter/ip_tables.c | 3 +-- net/ipv6/netfilter/ip6_tables.c | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-)net/ipv4/netfilter/arp_tables.c +0
-0@@ -270,12 +270,11 @@ unsigned int arpt_do_table(struct sk_buff *skb,local_bh_disable ();
net/ipv4/netfilter/arp_tables.c unsigned int arpt_do_table(struct sk_buff *skb, · line 279
Quoted 10 lines
net/ipv4/netfilter/arp_tables.c +1
-2addend =xt_write_recseq_begin (); - private = table->private;/* * Ensure we load private-> members after we've fetched the base * pointer. */ -smp_read_barrier_depends (); + private =lockless_dereference (table->private); table_base = private->entries[smp_processor_id ()];
Please carefully read the code, before and after your change, then you'll see this change broke the code.
Problem is that a bug like that can be really hard to diagnose and fix later, so really you have to be very careful doing these mechanical changes.
IMO, current code+comment is better than with this lockless_dereference() which in this particular case obfuscates the code. more than anything.
In this case we do have a lock (sort of), so lockless_dereference() is quite misleading.
Re: [PATCH v2 9/9] netfilter: Replace smp_read_barrier_depends() with lockless_dereference()
Quoted 37 lines · Eric Dumazet
Quoted 17 lines · Pranith Kumar
Recently
lockless_dereference()was added which can be used in place of hard-codingsmp_read_barrier_depends(). The following PATCH makes the change.Signed-off-by Pranith Kumar <[email protected]>--- net/ipv4/netfilter/arp_tables.c | 3 +-- net/ipv4/netfilter/ip_tables.c | 3 +-- net/ipv6/netfilter/ip6_tables.c | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-)net/ipv4/netfilter/arp_tables.c +0
-0@@ -270,12 +270,11 @@ unsigned int arpt_do_table(struct sk_buff *skb,local_bh_disable ();net/ipv4/netfilter/arp_tables.c unsigned int arpt_do_table(struct sk_buff *skb, · line 279
Quoted 10 lines
net/ipv4/netfilter/arp_tables.c +1
-2addend =xt_write_recseq_begin (); - private = table->private;/* * Ensure we load private-> members after we've fetched the base * pointer. */ -smp_read_barrier_depends (); + private =lockless_dereference (table->private); table_base = private->entries[smp_processor_id ()];Please carefully read the code, before and after your change, then you'll see this change broke the code.
Problem is that a bug like that can be really hard to diagnose and fix later, so really you have to be very careful doing these mechanical changes.
Quoted 7 lines
IMO, current code+comment is better than with this
lockless_dereference()which in this particular case obfuscates the code. more than anything.In this case we do have a lock (sort of), so
lockless_dereference()is quite misleading.
Hi Eric,
Thanks for looking at this patch.
I've been scratching my head since morning trying to find out what was so obviously wrong with this patch. Alas, I don't see what you do.
Could you point it out and show me how incompetent I am, please?
Thanks!
Signature · 1 line
Pranith
Re: [PATCH v2 9/9] netfilter: Replace smp_read_barrier_depends() with lockless_dereference()
Quoted 10 lines · Pranith Kumar
Hi Eric,
Thanks for looking at this patch.
I've been scratching my head since morning trying to find out what was so obviously wrong with this patch. Alas, I don't see what you do.
Could you point it out and show me how incompetent I am, please?
Thanks!
Well, even it the code is _not_ broken, I don't see any value with this patch.
If I use git blame on current code, line containing smp_read_barrier_depends() exactly points to the relevant commit [1]
After your change, it will point to some cleanup, which makes little sense to me, considering you did not change the smp_wmb() in xt_replace_table().
I, as a netfilter contributor would like to keep current code as is, because it is how I feel safe with it.
We have a proliferation of interfaces, but this does not help to understand the issues and code maintenance.
smp_read_barrier_depends() better documents the read barrier than lockless_dereference().
The point of having a lock or not is irrelevant here.
Re: [PATCH v2 9/9] netfilter: Replace smp_read_barrier_depends() with lockless_dereference()
Quoted 10 lines · Eric Dumazet
Quoted 7 lines · Pranith Kumar
Hi Eric,
Thanks for looking at this patch.
I've been scratching my head since morning trying to find out what was so obviously wrong with this patch. Alas, I don't see what you do.
Quoted 6 lines
Quoted 3 lines
Could you point it out and show me how incompetent I am, please?
Thanks!
Well, even it the code is _not_ broken, I don't see any value with this patch.
Phew. Not being broken itself is a win :)
Quoted 3 lines
If I use git blame on current code, line containing
smp_read_barrier_depends()exactly points to the relevant commit [1]
And that is an opinion I will respect. I don't want to muck the git history where it is significant.
This effort is to eventually replace the uses of smp_read_barrier_depends() and to use either rcu or lockless_dereference() as documented in memory-barriers.txt.
Quoted 4 lines
After your change, it will point to some cleanup, which makes little sense to me, considering you did not change the
smp_wmb()inxt_replace_table().
That does not need to change as it is fine as it is. It still pairs with the smp_read_barrier_depends() in lockless_dereference().
Quoted 9 lines
I, as a netfilter contributor would like to keep current code as is, because it is how I feel safe with it.
We have a proliferation of interfaces, but this does not help to understand the issues and code maintenance.
smp_read_barrier_depends()better documents the read barrier thanlockless_dereference().
I think this is a matter of opinion. But in the current effort I've seen cases where it is not clear what the barrier is actually guaranteeing. I am glad that the current code is not one of those and it has reasonable comments.
lockless_dereference() on the other hand makes the dependency explicit.
Quoted 9 lines
The point of having a lock or not is irrelevant here.
Thanks!
Signature · 1 line
Pranith
Re: [PATCH v2 9/9] netfilter: Replace smp_read_barrier_depends() with lockless_dereference()
In reply to Pranith KumarHi,
Quoted 46 lines · Pranith Kumar
Quoted 37 lines · Eric Dumazet
Quoted 17 lines · Pranith Kumar
Recently
lockless_dereference()was added which can be used in place of hard-codingsmp_read_barrier_depends(). The following PATCH makes the change.Signed-off-by Pranith Kumar <[email protected]>--- net/ipv4/netfilter/arp_tables.c | 3 +-- net/ipv4/netfilter/ip_tables.c | 3 +-- net/ipv6/netfilter/ip6_tables.c | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-)net/ipv4/netfilter/arp_tables.c +0
-0@@ -270,12 +270,11 @@ unsigned int arpt_do_table(struct sk_buff *skb,local_bh_disable ();net/ipv4/netfilter/arp_tables.c unsigned int arpt_do_table(struct sk_buff *skb, · line 279
Quoted 10 lines
net/ipv4/netfilter/arp_tables.c +1
-2addend =xt_write_recseq_begin (); - private = table->private;/* * Ensure we load private-> members after we've fetched the base * pointer. */ -smp_read_barrier_depends (); + private =lockless_dereference (table->private); table_base = private->entries[smp_processor_id ()];Please carefully read the code, before and after your change, then you'll see this change broke the code.
Problem is that a bug like that can be really hard to diagnose and fix later, so really you have to be very careful doing these mechanical changes.
Quoted 7 lines
IMO, current code+comment is better than with this
lockless_dereference()which in this particular case obfuscates the code. more than anything.In this case we do have a lock (sort of), so
lockless_dereference()is quite misleading.
Quoted 6 lines
Hi Eric,
Thanks for looking at this patch.
I've been scratching my head since morning trying to find out what was so obviously wrong with this patch. Alas, I don't see what you do.
Afaics the read_barrier_depends protected the load from private->entries[x] earlier, not the load of table->private itself.
Greetings,
Andres Freund