Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1444717
| Path | csiph.com!aioe.org!bofh.it!news.nic.it!robomod |
|---|---|
| From | Davidlohr Bueso <dave@stgolabs.net> |
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH 1/2] ipc/sem.c: Fix complex_count vs. simple op race |
| Date | Sat, 16 Jul 2016 03:30:01 +0200 |
| Message-ID | <rVmAx-5Os-1@gated-at.bofh.it> (permalink) |
| References | <rUkAN-6XH-3@gated-at.bofh.it> <rUkAN-6XH-5@gated-at.bofh.it> |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii; format=flowed |
| Content-Disposition | inline |
| User-Agent | Mutt/1.5.24 (2015-08-30) |
| Sender | robomod@news.nic.it |
| List-ID | <linux-kernel.vger.kernel.org> |
| X-Mailing-List | linux-kernel@vger.kernel.org |
| Approved | robomod@news.nic.it |
| Lines | 48 |
| Organization | linux.* mail to news gateway |
| X-Original-Cc | "H. Peter Anvin" <hpa@zytor.com>, Peter Zijlstra <peterz@infradead.org>, Andrew Morton <akpm@linux-foundation.org>, LKML <linux-kernel@vger.kernel.org>, Thomas Gleixner <tglx@linutronix.de>, Ingo Molnar <mingo@elte.hu>, 1vier1@web.de, felixh@informatik.uni-bremen.de, stable@vger.kernel.org |
| X-Original-Date | Fri, 15 Jul 2016 18:27:12 -0700 |
| X-Original-Message-ID | <20160716012712.GB2271@linux-80c1.suse> |
| X-Original-References | <1468386412-3608-1-git-send-email-manfred@colorfullife.com> <1468386412-3608-2-git-send-email-manfred@colorfullife.com> |
| X-Original-Sender | linux-kernel-owner@vger.kernel.org |
| Xref | csiph.com linux.kernel:1444717 |
Show key headers only | View raw
On Wed, 13 Jul 2016, Manfred Spraul wrote:
>-static void sem_wait_array(struct sem_array *sma)
>+static void complexmode_enter(struct sem_array *sma)
> {
> int i;
> struct sem *sem;
>
>- if (sma->complex_count) {
>- /* The thread that increased sma->complex_count waited on
>- * all sem->lock locks. Thus we don't need to wait again.
>- */
>+ if (sma->complex_mode) {
>+ /* We are already in complex_mode. Nothing to do */
> return;
> }
>+ WRITE_ONCE(sma->complex_mode, true);
So we can actually save those READ/WRITE_ONCE calls for complex_mode as it's
a bool and therefore tearing is not an issue.
>+
>+ /* We need a full barrier:
>+ * The write to complex_mode must be visible
>+ * before we read the first sem->lock spinlock state.
>+ */
>+ smp_mb();
smp_store_mb()?
> /*
>@@ -300,56 +338,40 @@ static inline int sem_lock(struct sem_array *sma, struct sembuf *sops,
> /* Complex operation - acquire a full lock */
> ipc_lock_object(&sma->sem_perm);
>
>- /* And wait until all simple ops that are processed
>- * right now have dropped their locks.
>- */
>- sem_wait_array(sma);
>+ /* Prevent parallel simple ops */
>+ complexmode_enter(sma);
> return -1;
nit and unrelated: we should probably use some better label here than a raw
-1 (although I don't see it changing, just for nicer reading), ie: SEM_OBJECT_LOCKED
Thanks,
Davidlohr
Back to linux.kernel | Previous | Next — Previous in thread | Find similar | Unroll thread
[PATCH 1/2] ipc/sem.c: Fix complex_count vs. simple op race Manfred Spraul <manfred@colorfullife.com> - 2016-07-13 07:10 +0200 Re: [PATCH 1/2] ipc/sem.c: Fix complex_count vs. simple op race Davidlohr Bueso <dave@stgolabs.net> - 2016-07-16 03:30 +0200
csiph-web