public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Manfred Spraul <manfred@colorfullife.com>
To: paulmck@us.ibm.com
Cc: Linus Torvalds <torvalds@osdl.org>,
	Falk Hueffner <falk@debian.org>, Ingo Molnar <mingo@elte.hu>,
	Andrew Morton <akpm@osdl.org>,
	linux-kernel@vger.kernel.org
Subject: Re: ipc/msg.c "cleanup" breaks fakeroot on Alpha
Date: Mon, 06 Nov 2006 07:23:38 +0100	[thread overview]
Message-ID: <454ED4EA.5070701@colorfullife.com> (raw)
In-Reply-To: <20061106055745.GA4080@us.ibm.com>

Paul E. McKenney wrote:

>I also don't understand why the code in sys_msgrcv() doesn't have
>to remap the msqid, similar to the way it is done in sys_semtimedop().
>
>  
>
What do you mean with remap?

>So, what am I missing here?  How does a msgrcv() racing with an rmid()
>avoid taking a lock on a message queue that just got freed?  (The
>ipc_lock_by_ptr() in "Lockless receive, part 3".)  My concern is the
>following sequence of steps:
>
>o	expunge_all() invokes wake_up_process() and sets r_msg.
>
>o	sys_msgrcv() is awakened, but for whatever reason does
>	not actually start executing (e.g., lots of other busy
>	processes at higher priority).
>
>o	expunge_all() returns to freeque(), which runs through the
>	rest of its processing, finally calling ipc_rcu_putref().
>
>o	ipc_rcu_putref() invokes call_rcu() to free the message
>	queue after a grace period.
>
>o	ipc_immediate_free() is invoked at the end of a grace
>	period, freeing the message queue.
>
>o	sys_msgrcv() finally gets a chance to run, and does an
>	rcu_read_lock() -- but too late!!!
>
>  
>
Not too late:
sys_msgrcv() checks msr_d.r_msr, notices that the value is -EIDRM and
returns to user space with -EIDRM immediately. This codepath
doesn't touch the message queue pointer, thus it doesn't matter that the
message queue is already freed.
The code only touches the message queue pointer if msr_d.r_msr
is -EAGAIN - and the rcu_read_lock() guarantees there is no rcu grace
period between the test for -EAGAIN and the ipc_lock_by_ptr.
Thus this should be safe.

But back to the oops:
The oops happens in expunge_all, called from sys_msgctl.
Thus it must be an msgctl(IPC_SET).
IPC_SET is special: it calls expunge_all(-EAGAIN): that's necessary
because IPC_SET can change the permissions.
Unfortunately, faked doesn't use IPC_SET at all :-(

Falk - could you strace your "fakeroot ls" test? Are there any IPC_SET 
calls?
Which gcc version do you use? Is it possible that gcc auto-inlined 
something?

--
    Manfred

  reply	other threads:[~2006-11-06  6:24 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-11-04 16:49 ipc/msg.c "cleanup" breaks fakeroot on Alpha Falk Hueffner
2006-11-04 17:29 ` Ingo Molnar
2006-11-04 17:41   ` Linus Torvalds
2006-11-04 18:12     ` Falk Hueffner
     [not found]       ` <Pine.LNX.4.64.0611041019180.25218@g5.osdl.org>
2006-11-05 16:02         ` Manfred Spraul
2006-11-06  5:57           ` Paul E. McKenney
2006-11-06  6:23             ` Manfred Spraul [this message]
2006-11-06 16:18               ` Paul E. McKenney

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=454ED4EA.5070701@colorfullife.com \
    --to=manfred@colorfullife.com \
    --cc=akpm@osdl.org \
    --cc=falk@debian.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=paulmck@us.ibm.com \
    --cc=torvalds@osdl.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox