mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Manfred Spraul <manfred@colorfullife.com>
To: "Felix Hübner" <felixh@informatik.uni-bremen.de>,
	linux-kernel@vger.kernel.org
Cc: bitbucket@online.de, riel@redhat.com, dbueso@suse.de,
	Andrew Morton <akpm@linux-foundation.org>
Subject: Re: PROBLEM: Concurrency issue in sem_lock
Date: Sat, 10 Oct 2015 08:50:22 +0200	[thread overview]
Message-ID: <5618B52E.8070601@colorfullife.com> (raw)
In-Reply-To: <561779AC.6080106@informatik.uni-bremen.de>

[-- Attachment #1: Type: text/plain, Size: 827 bytes --]

Hi,

On 10/09/2015 10:24 AM, Felix Hübner wrote:
> Hi all,
>
> I have just reported a concurrency issue in the implementation of
> sem_lock, see https://bugzilla.kernel.org/show_bug.cgi?id=105651
>
> [...]
> # P0 does spin_lock(&sem->lock); in line 336.
>
> 		spin_lock(&sem->lock);
[...]
> # P2 performs rest of semtimedop, increments complex_count and ends up
> in line 1961 and starts to sleep.
>
> 		return -1;
> 	}
That is the problem: semtimedop() increments complex_count - thus 
sem_wait_array() returns without a spin_unlock_wait() loop - but P0 
already owns spin_lock(&sem->lock).

How do we want to fix it?
- revert my patch (simplify code, but slower for one corner case)
- add the missing sem_wait_array (more complex, but also better for 
complex semops).

what do you think?

(patch untested)

--
     Manfred

[-- Attachment #2: 0001-ipc-sem.c-Alternative-for-fixing-Concurrency-bug.patch --]
[-- Type: text/x-patch, Size: 1359 bytes --]

>From 0ce84d118e2ee7ebc98ad4a8cfd23f04ad45115c Mon Sep 17 00:00:00 2001
From: Manfred Spraul <manfred@colorfullife.com>
Date: Sat, 10 Oct 2015 08:37:22 +0200
Subject: [PATCH] ipc/sem.c: Alternative for fixing Concurrency bug

Two ideas for fixing the bug found by Felix:
- Revert my initial patch.
	Problem: Significant slowdown for application that use large sem
	arrays and complex operations: Every semop() does a loop
	with spin_lock() on all semaphores.

- Add another sem_wait_array() that catches operations that are in
  the middle of sem_lock().

What do you think? Is it worth to optimize for complex ops?

Reported-by: felixh@informatik.uni-bremen.de
Signed-off-by: Manfred Spraul <manfred@colorfullife.com>
---
 ipc/sem.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/ipc/sem.c b/ipc/sem.c
index b471e5a..9a55cfb 100644
--- a/ipc/sem.c
+++ b/ipc/sem.c
@@ -1936,9 +1936,16 @@ SYSCALL_DEFINE4(semtimedop, int, semid, struct sembuf __user *, tsops,
 			list_add_tail(&queue.list, &curr->pending_const);
 		}
 	} else {
-		if (!sma->complex_count)
+		if (!sma->complex_count) {
 			merge_queues(sma);
 
+			/*
+			 * squeeze out any simple operations that are in the middle
+			 * of sem_lock()
+			 */
+			sem_wait_array(sma);
+		}
+
 		if (alter)
 			list_add_tail(&queue.list, &sma->pending_alter);
 		else
-- 
2.4.3


  reply	other threads:[~2015-10-10  6:50 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-09  8:24 Felix Hübner
2015-10-10  6:50 ` Manfred Spraul [this message]
  -- strict thread matches above, loose matches on Subject: below --
2015-10-09  8:16 Felix Hübner

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=5618B52E.8070601@colorfullife.com \
    --to=manfred@colorfullife.com \
    --cc=akpm@linux-foundation.org \
    --cc=bitbucket@online.de \
    --cc=dbueso@suse.de \
    --cc=felixh@informatik.uni-bremen.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=riel@redhat.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®