All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@domain.hid>
To: Andreas Glatz <andreasglatz@domain.hid>
Cc: xenomai@xenomai.org
Subject: Re: [Xenomai-core] nucleus/pipe.c patch: check for lingering close at xnpipe_connect()
Date: Thu, 10 Sep 2009 00:34:22 +0200	[thread overview]
Message-ID: <4AA82D6E.8070909@domain.hid> (raw)
In-Reply-To: <1252532920.10115.9.camel@domain.hid>

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

Andreas Glatz wrote:
> Hi,
> 
> Currently, you can destroy RT_PIPE while a non-rt application is
> connected. If that happens the pipe won't be fully closed but
> some parts will be leftover for cleanup when closing the RT_PIPE
> from the non-rt application (lingering close).
> 
> For us it would be very convenient if we didn't have to close
> the non-rt side before restarting the rt-side (currently, the 
> rt-side complains bc the non-rt side didn't resolve the lingering
> close).
> 
> Here is a patch where the rt-side resolves the lingering close
> when connecting to the RT_PIPE. I tested it and it seems to work 
> fine. Do you have any concerns?
> 
> Andreas
> 

Whenever possible, please post patches inline (I had to manually copy it
to allow commenting).

> --- pipe.orig.c	2009-09-09 17:23:10.000000000 -0400
> +++ pipe.c	2009-09-09 17:32:48.000000000 -0400
> @@ -309,17 +309,35 @@
>  int xnpipe_connect(int minor, struct xnpipe_operations *ops, void *xstate)
>  {
>  	struct xnpipe_state *state;
> -	int need_sched = 0, ret;
> +	int need_sched = 0, test_lclose = 0, ret;
>  	spl_t s;
>  
> -	minor = xnpipe_minor_alloc(minor);
> -	if (minor < 0)
> +	ret = xnpipe_minor_alloc(minor);
> +	if (ret >= 0)
> +		minor = ret;
> +	else 
> +	if(ret == -EBUSY)
> +		test_lclose = 1;
> +	else 
>  		return minor;
>  
>  	state = &xnpipe_states[minor];
>  
>  	xnlock_get_irqsave(&nklock, s);
>  
> +	if(test_lclose) {
> +		if(testbits(state->status, XNPIPE_KERN_LCLOSE)) {
> +			clrbits(state->status, XNPIPE_KERN_LCLOSE);
> +			xnlock_put_irqrestore(&nklock, s);
> +			state->ops.release(state->xstate);

You cannot bluntly call release() here. You may not run in Linux context
while that handler demands this. Moreover, releasing the state is the
job of the NRT user that opened it and obviously still has a hand on it.

(And the locking is imbalanced here, but that is shadowed by the other
flaws.)

> +		} else {
> +			xnlock_put_irqrestore(&nklock, s);
> +			return -EBUSY;
> +		}
> +	}
> +			
> +	xnlock_get_irqsave(&nklock, s);
> +
>  	ret = xnpipe_set_ops(state, ops);
>  	if (ret) {
>  		xnlock_put_irqrestore(&nklock, s);

IIUC, you are looking for a way to keep a pipe open on the NRT side
while the RT user is disappearing and re-appearing? Not sure if this is
feasible at all with current xnpipe. But if it is, I think you rather
have to introduce some kind of reset on the affected xnpipe_state.

Jan


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 257 bytes --]

  reply	other threads:[~2009-09-09 22:34 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-09 21:48 [Xenomai-core] nucleus/pipe.c patch: check for lingering close at xnpipe_connect() Andreas Glatz
2009-09-09 22:34 ` Jan Kiszka [this message]
2009-09-10 16:49   ` Andreas Glatz
2009-09-11  7:46     ` Philippe Gerum

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=4AA82D6E.8070909@domain.hid \
    --to=jan.kiszka@domain.hid \
    --cc=andreasglatz@domain.hid \
    --cc=xenomai@xenomai.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.