Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1376295
| Path | csiph.com!aioe.org!bofh.it!news.nic.it!robomod |
|---|---|
| From | Cyrill Gorcunov <gorcunov@gmail.com> |
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH resend v2] tty: n_tty -- Add new TIOCPEEKRAW ioctl to peek unread data |
| Date | Mon, 11 Apr 2016 23:50:01 +0200 |
| Message-ID | <rmRSx-463-1@gated-at.bofh.it> (permalink) |
| References | <rlhHs-3TE-13@gated-at.bofh.it> <rmCTw-LE-1@gated-at.bofh.it> <rmG14-3kL-15@gated-at.bofh.it> <rmNOW-11s-9@gated-at.bofh.it> |
| Dkim-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=A85GZeQhdxn07yQ7+ulBXz9+jre7KpZD/O3EWyZGl+o=; b=c/jyoDyvtaYi5wr5FKpHvwa7dho0ypW5GucuABljqp9FWz540a5lCy8vV3NKxheZNQ NFEQRiQemuk8b9I/EHZUxqJACi6ypQnHFjZnSc3P1WLZMGM7jd/eSjRxZ77O6kPZsDXY wOVp1RLsu91XHtmHPjVJMXNFjftp8qjsWsSABGKJTFokT82cVkrcq8bvXEHXy0Vdh9Ps Ih7vYLXr3KjSaGDrGL50Fl6uW7Y8iOFmrrGNOWaeuP8uNJ1ESnsjoYG/GMDTp3OC4FUy IeoHAj4XO4p9rfZA53P0R4idyrNX3mrfuzh8GHA5u3i3lAyluxhhC/eq+DziVBkVpQBK JJDg== |
| X-Google-Dkim-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=A85GZeQhdxn07yQ7+ulBXz9+jre7KpZD/O3EWyZGl+o=; b=DByNVskSdYRMc/itm2yTRfE4EUAWlkzGID1/hX0H1DTHwICff4TsW3APi/90Y0IxIi JeuE4EOUY3QW7blXps2sCH6K9N97xJ5lA236D3io9LLWzmHFp3L04fbs2sZ3Fu2l7CA7 LgQrBWVqiSByMTKNN1k+8qoXEIWWHt213MxUuoLXjTtCMHknVoMbm5OhBTnqoMdFAMqh tn+R2z9GhnvpQiQ2pvydfy4Y3EaoQqiWpmk6QzWIw47zs8e3GclDsW1stwyVvJ3zSXZd lK41SUagZ5GLq4Z/u51XuR/9jQ6sIHo7994fPCkI2nrYJ2pcJJg4+bk/oPB2wB5eNAl5 1mhA== |
| X-Gm-Message-State | AD7BkJK9YbCLV9NaajwuFokLT+UqTEbckyYDLSxyYRTkhcXIkcNQvowXgchhczv/MtY5Sg== |
| X-Received | by 10.25.21.231 with SMTP id 100mr9297965lfv.146.1460410933448; Mon, 11 Apr 2016 14:42:13 -0700 (PDT) |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| 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 | 109 |
| Organization | linux.* mail to news gateway |
| X-Original-Cc | LKML <linux-kernel@vger.kernel.org>, Jiri Slaby <jslaby@suse.com>, Greg Kroah-Hartman <gregkh@linuxfoundation.org>, Andrey Vagin <avagin@virtuozzo.com>, Pavel Emelianov <xemul@virtuozzo.com>, Vladimir Davydov <vdavydov@virtuozzo.com>, Konstantin Khorenko <khorenko@virtuozzo.com> |
| X-Original-Date | Tue, 12 Apr 2016 00:42:11 +0300 |
| X-Original-Message-ID | <20160411214211.GT2000@uranus.lan> |
| X-Original-References | <20160407125326.GH2258@uranus.lan> <570B3980.4040301@hurleysoftware.com> <20160411090149.GA2000@uranus.lan> <570BDCC8.5060104@hurleysoftware.com> |
| X-Original-Sender | linux-kernel-owner@vger.kernel.org |
| Xref | csiph.com linux.kernel:1376295 |
Show key headers only | View raw
On Mon, Apr 11, 2016 at 10:20:08AM -0700, Peter Hurley wrote:
...
>
> My thoughts here are two-fold.
>
> 1. I'd like whatever functionality is to be added to support checkpoint/
> restore to be a restrictive as possible while still accomplishing your
> objectives _exactly because I don't want it to grow other uses_.
> That's why I suggested asserting the task state (and maybe adding
> ptrace state checks) so that the interface can only be used for this
> purpose.
>
> 2. If we want to make changes because the existing read()/write()
> interface is inadequate, let's add a complete interface.
I completely agree!
> > Strictly speaking saving complete state would be ideal but this require
> > exporting internal n_tty structure into user space as api (sure we
> > can name the members in any way we like, but this would force then
> > to keep backward compatibility when n_tty code get changed in future).
> > I think loosing some information like column and marker is acceptable
> > and fetching unread buffers is more general. I can try to implement
> > c/r'ing ioctl though which would not only fetch buffers but column
> > and such, and see how it goes, sounds ok?
>
> My thinking here was to use an opaque buffer; it could be sized in the
> same manner as the peek interface; ie., provide a buffer address with
> size, and the call fails with an updated size required if inadequate
> (or whatever, but I think you get the idea).
Yeah, got it.
> >> A generic peek() may find other uses which could make future improvements
> >> difficult.
> >>
> >> Plus this ioctl() is only reading the 4k line discipline read buffer, and
> >> not the tty buffers which could contain up to another 8k of unprocessed
> >> input.
> >
> > Which is scheduled for flush into port and then landed into ld when
> > write() called. True, I managed to miss this moment, thanks! So the
> > proper general peek() handling should be implemented on tty code level
> > rather than ld, and fetch both -- start with tty buffer and proceed with
> > ld buffer then, right?
>
> To safely copy the tty buffers, it needs to be implemented like
> tty_buffer_flush():
...
> 6. Release ldisc reference
>
> tty_ldisc_deref(ld);
>
Thanks a huge, got it!
...
> >>> +{
> >>> + struct n_tty_data *ldata = tty->disc_data;
> >>> + ssize_t retval;
> >>> +
> >>> + if (!mutex_trylock(&ldata->atomic_read_lock))
> >>> + return -EAGAIN;
> >>> +
> >>> + down_read(&tty->termios_rwsem);
> >>
> >> Why take these two locks if parallel operations are not expected?
> >> Conversely, I would expect this to assert current state is TASK_TRACED.
> >
> > If someone is already reading the data it will either exit soon with
> > data read or will sit here waiting for data to appear. So I thought
> > if we're fetching unread data we should not interfere with any other
> > readers? If someone is sitting in read procedure it implies that there
> > either no data on buffer and reader is waiting for it, or the read
> > procedure will complete soon, but indeed I rather should be checking
> > for read_cnt locklessly and return -EAGAIN if > 0 and can't lock
> > the atomic_read_lock. I implied that task can be in non-traced state.
> > If require traced indeed we won't need the lock. For criu lockless
> > + tracing state is fine but i thought someone else might be needing
> > to peek data without tracing the task. Hm?
>
> Well, I'd rather not have other uses for peeking data. In fact, I need
> to check if this interface needs to be CAP_SYSADMIN; I'm pretty sure
> that ioctl() ignores file permissions and write-only file permissions
> (used by /usr/bin/write to send messages to other users) should not
> allow tty reads.
>
> Ok, so we want to defend against parallel operations in case not
> all tty users are currently stopped by ptrace (such as when unrelated
> tasks are potentially reading or writing to either end and were not
> specified for dumping)?
I think so. At least this gives some kind of consistensy while we're
fetching data. Something close to peeking data from pipes/sockets.
> In that case, I think just write trylocking the termios rwsem should
> prevent any parallel i/o, at least for the N_TTY line discipline.
>
> This should only interfere with processes not being dumped because
> ptrace signalling should have ejected any process to be dumped out
> of their i/o loops (readers or writers).
>
> Also, I think we should further limit the interface based on what is
> supported currently; IOW, check that the driver is either pty or vt,
> assert that the line discipline is N_TTY at both ends, etc.
Thats a good idea, thanks, will do!
Back to linux.kernel | Previous | Next — Previous in thread | Find similar | Unroll thread
[PATCH resend v2] tty: n_tty -- Add new TIOCPEEKRAW ioctl to peek unread data Cyrill Gorcunov <gorcunov@gmail.com> - 2016-04-07 15:00 +0200
Re: [PATCH resend v2] tty: n_tty -- Add new TIOCPEEKRAW ioctl to peek unread data Peter Hurley <peter@hurleysoftware.com> - 2016-04-11 07:50 +0200
Re: [PATCH resend v2] tty: n_tty -- Add new TIOCPEEKRAW ioctl to peek unread data Cyrill Gorcunov <gorcunov@gmail.com> - 2016-04-11 11:10 +0200
Re: [PATCH resend v2] tty: n_tty -- Add new TIOCPEEKRAW ioctl to peek unread data Peter Hurley <peter@hurleysoftware.com> - 2016-04-11 19:30 +0200
Re: [PATCH resend v2] tty: n_tty -- Add new TIOCPEEKRAW ioctl to peek unread data Cyrill Gorcunov <gorcunov@gmail.com> - 2016-04-11 23:50 +0200
csiph-web