All of lore.kernel.org
 help / color / mirror / Atom feed
From: Noam Camus <noamc@ezchip.com>
To: <linux-snps-arc@lists.infradead.org>
Cc: <linux-kernel@vger.kernel.org>, <cmetcalf@ezchip.com>,
	Noam Camus <noamc@ezchip.com>
Subject: [PATCH v3 06/18] ARC: rwlock: disable interrupts in !LLSC variant
Date: Tue, 1 Dec 2015 15:02:53 +0200	[thread overview]
Message-ID: <1448974985-11487-7-git-send-email-noamc@ezchip.com> (raw)
In-Reply-To: <1448974985-11487-1-git-send-email-noamc@ezchip.com>

From: Noam Camus <noamc@ezchip.com>

If we hold rwlock and interrupt occures we may
end up spinning on it for ever during softirq.
Note that this lock is an internal lock
and since the lock is free to be used from any context,
the lock needs to be IRQ-safe.

Below you may see an example for interrupt we get while
nl_table_lock is holding its rw->lock_mutex and we spinned
on it for ever.

The concept for the fix was taken from SPARC.

[2015-05-12 19:16:12] Stack Trace:
[2015-05-12 19:16:12]   arc_unwind_core+0xb8/0x11c
[2015-05-12 19:16:12]   dump_stack+0x68/0xac
[2015-05-12 19:16:12]   _raw_read_lock+0xa8/0xac
[2015-05-12 19:16:12]   netlink_broadcast_filtered+0x56/0x35c
[2015-05-12 19:16:12]   nlmsg_notify+0x42/0xa4
[2015-05-12 19:16:13]   neigh_update+0x1fe/0x44c
[2015-05-12 19:16:13]   neigh_event_ns+0x40/0xa4
[2015-05-12 19:16:13]   arp_process+0x46e/0x5a8
[2015-05-12 19:16:13]   __netif_receive_skb_core+0x358/0x500
[2015-05-12 19:16:13]   process_backlog+0x92/0x154
[2015-05-12 19:16:13]   net_rx_action+0xb8/0x188
[2015-05-12 19:16:13]   __do_softirq+0xda/0x1d8
[2015-05-12 19:16:14]   irq_exit+0x8a/0x8c
[2015-05-12 19:16:14]   arch_do_IRQ+0x6c/0xa8
[2015-05-12 19:16:14]   handle_interrupt_level1+0xe4/0xf0

Signed-off-by: Noam Camus <noamc@ezchip.com>
Acked-by: Peter Zijlstra <peterz@infradead.org>
---
 arch/arc/include/asm/spinlock.h |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/arch/arc/include/asm/spinlock.h b/arch/arc/include/asm/spinlock.h
index db8c59d..800e7c4 100644
--- a/arch/arc/include/asm/spinlock.h
+++ b/arch/arc/include/asm/spinlock.h
@@ -610,7 +610,9 @@ static inline void arch_spin_unlock(arch_spinlock_t *lock)
 static inline int arch_read_trylock(arch_rwlock_t *rw)
 {
 	int ret = 0;
+	unsigned long flags;
 
+	local_irq_save(flags);
 	arch_spin_lock(&(rw->lock_mutex));
 
 	/*
@@ -623,6 +625,7 @@ static inline int arch_read_trylock(arch_rwlock_t *rw)
 	}
 
 	arch_spin_unlock(&(rw->lock_mutex));
+	local_irq_restore(flags);
 
 	smp_mb();
 	return ret;
@@ -632,7 +635,9 @@ static inline int arch_read_trylock(arch_rwlock_t *rw)
 static inline int arch_write_trylock(arch_rwlock_t *rw)
 {
 	int ret = 0;
+	unsigned long flags;
 
+	local_irq_save(flags);
 	arch_spin_lock(&(rw->lock_mutex));
 
 	/*
@@ -646,6 +651,7 @@ static inline int arch_write_trylock(arch_rwlock_t *rw)
 		ret = 1;
 	}
 	arch_spin_unlock(&(rw->lock_mutex));
+	local_irq_restore(flags);
 
 	return ret;
 }
@@ -664,16 +670,24 @@ static inline void arch_write_lock(arch_rwlock_t *rw)
 
 static inline void arch_read_unlock(arch_rwlock_t *rw)
 {
+	unsigned long flags;
+
+	local_irq_save(flags);
 	arch_spin_lock(&(rw->lock_mutex));
 	rw->counter++;
 	arch_spin_unlock(&(rw->lock_mutex));
+	local_irq_restore(flags);
 }
 
 static inline void arch_write_unlock(arch_rwlock_t *rw)
 {
+	unsigned long flags;
+
+	local_irq_save(flags);
 	arch_spin_lock(&(rw->lock_mutex));
 	rw->counter = __ARCH_RW_LOCK_UNLOCKED__;
 	arch_spin_unlock(&(rw->lock_mutex));
+	local_irq_restore(flags);
 }
 
 #endif
-- 
1.7.1


WARNING: multiple messages have this Message-ID (diff)
From: noamc@ezchip.com (Noam Camus)
To: linux-snps-arc@lists.infradead.org
Subject: [PATCH v3 06/18] ARC: rwlock: disable interrupts in !LLSC variant
Date: Tue, 1 Dec 2015 15:02:53 +0200	[thread overview]
Message-ID: <1448974985-11487-7-git-send-email-noamc@ezchip.com> (raw)
In-Reply-To: <1448974985-11487-1-git-send-email-noamc@ezchip.com>

From: Noam Camus <noamc@ezchip.com>

If we hold rwlock and interrupt occures we may
end up spinning on it for ever during softirq.
Note that this lock is an internal lock
and since the lock is free to be used from any context,
the lock needs to be IRQ-safe.

Below you may see an example for interrupt we get while
nl_table_lock is holding its rw->lock_mutex and we spinned
on it for ever.

The concept for the fix was taken from SPARC.

[2015-05-12 19:16:12] Stack Trace:
[2015-05-12 19:16:12]   arc_unwind_core+0xb8/0x11c
[2015-05-12 19:16:12]   dump_stack+0x68/0xac
[2015-05-12 19:16:12]   _raw_read_lock+0xa8/0xac
[2015-05-12 19:16:12]   netlink_broadcast_filtered+0x56/0x35c
[2015-05-12 19:16:12]   nlmsg_notify+0x42/0xa4
[2015-05-12 19:16:13]   neigh_update+0x1fe/0x44c
[2015-05-12 19:16:13]   neigh_event_ns+0x40/0xa4
[2015-05-12 19:16:13]   arp_process+0x46e/0x5a8
[2015-05-12 19:16:13]   __netif_receive_skb_core+0x358/0x500
[2015-05-12 19:16:13]   process_backlog+0x92/0x154
[2015-05-12 19:16:13]   net_rx_action+0xb8/0x188
[2015-05-12 19:16:13]   __do_softirq+0xda/0x1d8
[2015-05-12 19:16:14]   irq_exit+0x8a/0x8c
[2015-05-12 19:16:14]   arch_do_IRQ+0x6c/0xa8
[2015-05-12 19:16:14]   handle_interrupt_level1+0xe4/0xf0

Signed-off-by: Noam Camus <noamc at ezchip.com>
Acked-by: Peter Zijlstra <peterz at infradead.org>
---
 arch/arc/include/asm/spinlock.h |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/arch/arc/include/asm/spinlock.h b/arch/arc/include/asm/spinlock.h
index db8c59d..800e7c4 100644
--- a/arch/arc/include/asm/spinlock.h
+++ b/arch/arc/include/asm/spinlock.h
@@ -610,7 +610,9 @@ static inline void arch_spin_unlock(arch_spinlock_t *lock)
 static inline int arch_read_trylock(arch_rwlock_t *rw)
 {
 	int ret = 0;
+	unsigned long flags;
 
+	local_irq_save(flags);
 	arch_spin_lock(&(rw->lock_mutex));
 
 	/*
@@ -623,6 +625,7 @@ static inline int arch_read_trylock(arch_rwlock_t *rw)
 	}
 
 	arch_spin_unlock(&(rw->lock_mutex));
+	local_irq_restore(flags);
 
 	smp_mb();
 	return ret;
@@ -632,7 +635,9 @@ static inline int arch_read_trylock(arch_rwlock_t *rw)
 static inline int arch_write_trylock(arch_rwlock_t *rw)
 {
 	int ret = 0;
+	unsigned long flags;
 
+	local_irq_save(flags);
 	arch_spin_lock(&(rw->lock_mutex));
 
 	/*
@@ -646,6 +651,7 @@ static inline int arch_write_trylock(arch_rwlock_t *rw)
 		ret = 1;
 	}
 	arch_spin_unlock(&(rw->lock_mutex));
+	local_irq_restore(flags);
 
 	return ret;
 }
@@ -664,16 +670,24 @@ static inline void arch_write_lock(arch_rwlock_t *rw)
 
 static inline void arch_read_unlock(arch_rwlock_t *rw)
 {
+	unsigned long flags;
+
+	local_irq_save(flags);
 	arch_spin_lock(&(rw->lock_mutex));
 	rw->counter++;
 	arch_spin_unlock(&(rw->lock_mutex));
+	local_irq_restore(flags);
 }
 
 static inline void arch_write_unlock(arch_rwlock_t *rw)
 {
+	unsigned long flags;
+
+	local_irq_save(flags);
 	arch_spin_lock(&(rw->lock_mutex));
 	rw->counter = __ARCH_RW_LOCK_UNLOCKED__;
 	arch_spin_unlock(&(rw->lock_mutex));
+	local_irq_restore(flags);
 }
 
 #endif
-- 
1.7.1

  parent reply	other threads:[~2015-12-01 13:16 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-01 13:02 [PATCH v3 00/18] *** SUBJECT HERE *** Noam Camus
2015-12-01 13:02 ` Noam Camus
2015-12-01 13:02 ` [PATCH v3 01/18] Documentation: Add EZchip vendor to binding list Noam Camus
2015-12-01 13:02   ` Noam Camus
2015-12-04  8:07   ` Daniel Lezcano
2015-12-04  8:07     ` Daniel Lezcano
2015-12-04 11:46     ` Noam Camus
2015-12-04 11:46       ` Noam Camus
2015-12-01 13:02 ` [PATCH v3 02/18] ARC: [plat-eznps] define IPI_IRQ Noam Camus
2015-12-01 13:02   ` Noam Camus
2015-12-01 13:02 ` [PATCH v3 03/18] clocksource: Add NPS400 timers driver Noam Camus
2015-12-01 13:02   ` Noam Camus
2015-12-04  9:13   ` Daniel Lezcano
2015-12-04  9:13     ` Daniel Lezcano
2015-12-04 12:26     ` Noam Camus
2015-12-04 12:26       ` Noam Camus
2015-12-04 12:52       ` Daniel Lezcano
2015-12-04 12:52         ` Daniel Lezcano
2015-12-08 13:00     ` Noam Camus
2015-12-08 13:00       ` Noam Camus
2015-12-01 13:02 ` [PATCH v3 04/18] irqchip: add nps Internal and external irqchips Noam Camus
2015-12-01 13:02   ` Noam Camus
2015-12-01 13:29   ` Marc Zyngier
2015-12-01 13:29     ` Marc Zyngier
2015-12-02 15:08     ` Noam Camus
2015-12-02 15:08       ` Noam Camus
2015-12-03 18:33       ` Marc Zyngier
2015-12-03 18:33         ` Marc Zyngier
2015-12-07 11:19         ` Noam Camus
2015-12-07 11:19           ` Noam Camus
2015-12-11  7:58     ` Vineet Gupta
2015-12-11  7:58       ` Vineet Gupta
2015-12-01 13:02 ` [PATCH v3 05/18] ARC: Set vmalloc size from configuration Noam Camus
2015-12-01 13:02   ` Noam Camus
2015-12-01 13:02 ` Noam Camus [this message]
2015-12-01 13:02   ` [PATCH v3 06/18] ARC: rwlock: disable interrupts in !LLSC variant Noam Camus
2015-12-01 13:02 ` [PATCH v3 07/18] ARC: rename smp operation init_irq_cpu() to init_per_cpu() Noam Camus
2015-12-01 13:02   ` Noam Camus
2015-12-01 13:02 ` [PATCH v3 08/18] ARC: Mark secondary cpu online only after all HW setup is done Noam Camus
2015-12-01 13:02   ` Noam Camus
2015-12-01 13:02 ` [PATCH v3 09/18] ARC: add CONFIG_CLKSRC_OF support to time_init() Noam Camus
2015-12-01 13:02   ` Noam Camus
2015-12-01 13:02 ` [PATCH v3 10/18] ARC: [plat-eznps] Add eznps board defconfig and dts Noam Camus
2015-12-01 13:02   ` Noam Camus
2015-12-01 13:02 ` [PATCH v3 11/18] ARC: [plat-eznps] Add eznps platform Noam Camus
2015-12-01 13:02   ` Noam Camus
2015-12-01 13:02 ` [PATCH v3 12/18] ARC: [plat-eznps] Use dedicated user stack top Noam Camus
2015-12-01 13:02   ` Noam Camus
2015-12-01 13:03 ` [PATCH v3 13/18] ARC: [plat-eznps] Use dedicated atomic/bitops/cmpxchg Noam Camus
2015-12-01 13:03   ` Noam Camus
2015-12-01 13:03 ` [PATCH v3 14/18] ARC: [plat-eznps] Use dedicated SMP barriers Noam Camus
2015-12-01 13:03   ` Noam Camus
2015-12-01 13:03 ` [PATCH v3 15/18] ARC: [plat-eznps] Use dedicated identity auxiliary register Noam Camus
2015-12-01 13:03   ` Noam Camus
2015-12-01 13:03 ` [PATCH v3 16/18] ARC: [plat-eznps] Use dedicated cpu_relax() Noam Camus
2015-12-01 13:03   ` Noam Camus
2015-12-01 13:03 ` [PATCH v3 17/18] ARC: [plat-eznps] Use dedicated COMMAND_LINE_SIZE Noam Camus
2015-12-01 13:03   ` Noam Camus
2015-12-01 13:03 ` [PATCH v3 18/18] ARC: Add eznps platform to Kconfig and Makefile Noam Camus
2015-12-01 13:03   ` Noam Camus

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1448974985-11487-7-git-send-email-noamc@ezchip.com \
    --to=noamc@ezchip.com \
    --cc=cmetcalf@ezchip.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-snps-arc@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.