Path: csiph.com!aioe.org!bofh.it!news.nic.it!robomod From: Peter Hurley Newsgroups: linux.kernel Subject: Re: [BUG] drivers/tty: read() on a noncanonical blocking tty randomly fails when VMIN > received >= buf Date: Thu, 05 May 2016 03:00:02 +0200 Message-ID: References: Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hurleysoftware-com.20150623.gappssmtp.com; s=20150623; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=+VsrrNqOkCwtsUkYSip0ucYQEuB3BUWQcEWL4ZJSg5A=; b=CVyc8ac0WalKgOKTDQpTC1O0wgYwcvgJJiC+eLmpn+GSjewZ9bjfse9FreyCAFGG+4 O+VQK/uTipRf0vA/+q5YEpN8MF7Xnb6ZVTDbrJml6S3b9F8h1uM7cL6hSZWIzmigBlKi 0PE8jRKb3smOy/9e56FbOBPgox8/q95P03f7PWBfOI5Ou5JtvvIXpjZxkq7GtkInxueS bQM2M4voDvoN7G2XW2PrDqLgBHV8HTsYBinlMIX5C9MYEjqkV09nlTVhHjTXMQnsQN3d +qieAecrsYmE99Q3o2FYHpEnogPs1Z9bcEjyBzNmG1G6aiYlKaBowInDq+aDZDKwm95d 3J0g== X-Google-Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=+VsrrNqOkCwtsUkYSip0ucYQEuB3BUWQcEWL4ZJSg5A=; b=DMVD0HaUYlUHXorjQjCGz49oSES8rHm3HwkKM6vUUn5hTY1ILS1NYfsttcNBAVK66R MvadDNW7gVuZo27ns3Muu6/4yPMsmTFmjX2gDvpJHd5GoDs/87yGiFxaiQFqQ30A/2GG n4g875GC1nq8f6RwZ+WHIr/L1AZ2+IcC+62Pmh8gs5FRz2ffsctkJ1vX13cCYSXzubyY ig+csqbspTIjaZAkO+F/C4FP/1wMM9mrU3JRaNUbNqxPeNwYcGBGZtKMxp6eyCezGTw5 Ilr6QZnc5oSiaQxZrYRNdl2TnTIL61GjdkZCdEymsCahFZP1wzE3F9WV/VUMXyJQznnE WUVw== X-Gm-Message-State: AOPr4FUfkhhl6TZolM3/y65P/p0ew8l7CvVoBb3lJkNaLyCCnXWzouhtBKpkYYbzLOkdXQ== X-Received: by 10.66.62.106 with SMTP id x10mr16477490par.136.1462409458732; Wed, 04 May 2016 17:50:58 -0700 (PDT) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.2 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Sender: robomod@news.nic.it List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Approved: robomod@news.nic.it Lines: 27 Organization: linux.* mail to news gateway X-Original-Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org X-Original-Date: Wed, 4 May 2016 17:50:56 -0700 X-Original-Message-ID: <572A98F0.3040306@hurleysoftware.com> X-Original-References: <16504442-9e91-aaab-1f2b-9b4aa9c219f5@farjump.io> <572A80C0.4080704@hurleysoftware.com> <3319f492-9b1b-d006-e903-7de761a87a53@farjump.io> X-Original-Sender: linux-kernel-owner@vger.kernel.org Xref: csiph.com linux.kernel:1394812 On 05/04/2016 04:27 PM, Julio Guerra wrote: >>> When a tty (here a slave pty) is set in noncanonical input and blocking read modes, a read() randomly blocks when: >>> "VMIN > kernel received >= user buffer size > 0". >>> >>> The standard says that read() should block until VMIN bytes are received [1][2]. Whether this is an implementation defined case not really specified by POSIX or not, it should not behave randomly (otherwise it really should be documented in termios manpage). >> >> This is not a bug. >> >> From the termios(3) man page: >> >> * MIN > 0; TIME == 0: read(2) blocks until the lesser of MIN bytes or the number of bytes requested are avail‐ >> able, and returns the lesser of these two values. >> > > This does not appear in my man... > > Anyway, how do you explain the random behavior then? A long standing bug in this read mode allows the asynchronous input processing thread to race with the read() thread and become confused about how much data remains. I fixed this in 4.6; when I run your test on 4.6, it consistently returns the full user buffer. Regards, Peter Hurley