Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp6905055ybp; Wed, 16 Oct 2019 00:22:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqzDhzKdj/YYWV4KhXNh4M3dNHQF6PLKHnrJeeFf2QqNzI9eS+1Cl18nV2U4tluNflb8vWth X-Received: by 2002:a17:906:360c:: with SMTP id q12mr38040851ejb.168.1571210527966; Wed, 16 Oct 2019 00:22:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571210527; cv=none; d=google.com; s=arc-20160816; b=wNC7HAfsRP99hFXGF/6rUZRajxSlzrQakCTYIUfPO8oa31p6zLCT7hMm+Wpg5bdLbW bAvNdM+DpZ6wSNlvPux7VASAhEzCJgddtuUhcLzxparGAJe+VIef/Fjn9rn65IcWzwgC zBg7NKd/+L3EhRj7l/QOzz+0M4jeBiRyoGgYnLhXtNE+QN7cc3f6ge6j4Dd2dYvaiwHP ZZZnfleid4GA6oCIYoMQWu82E+AcpZ3RDuNvw/8StaIDD+jL7Pvr25DbnvLyFQsERbKP AkRVvu54PktwUt7plW4bTGqWWY0+GUgO1xLn5Xtd0hCpl74YtmCgmc+AoJsSossTU1CM fGEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:organization; bh=o1qLuvWgnY9gVqpRyU9DWaFso5G0qeJulI1tx7WBojw=; b=AbYTEafmLdJiADwhqnXUHVhYtOQAu3Gphf4jqTYvByhIkg/qEiJZcVYI3dQZ2q4vi5 l0qH2BtOuqmsFjpH2rxs2MT1RdWQqXrD/VYu+hS/6zcapg1ki01yZlVQzu6kyf2kdUgd wIyVPjd2OoEITk4nwhifa9x9vWbJmOt/kwAVx+M4Z0oTGURNBHg/ADEFj4sJPdRtq02o E37kQbslkfz14Xlyw87UN1pEmFLfAtYzuSh24VgAkkMEiKKzuPlz/u+Ve8zX+VP5GlRM m5KKg7q6ulCucG9bkQd/h0GuiG6k/2fkQzTCQL+8s4WZyDbJI1MwRh/YUCR1Q1pNT9HG KvZw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w2si17117230edc.386.2019.10.16.00.21.44; Wed, 16 Oct 2019 00:22:07 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388784AbfJOVuK (ORCPT + 99 others); Tue, 15 Oct 2019 17:50:10 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40962 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726719AbfJOVuJ (ORCPT ); Tue, 15 Oct 2019 17:50:09 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8271E10CC202; Tue, 15 Oct 2019 21:50:08 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-121-84.rdu2.redhat.com [10.10.121.84]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5894E6CE40; Tue, 15 Oct 2019 21:50:03 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 Subject: [RFC PATCH 15/21] pipe: Allow buffers to be marked read-whole-or-error for notifications From: David Howells To: torvalds@linux-foundation.org Cc: dhowells@redhat.com, Casey Schaufler , Stephen Smalley , Greg Kroah-Hartman , nicolas.dichtel@6wind.com, raven@themaw.net, Christian Brauner , dhowells@redhat.com, keyrings@vger.kernel.org, linux-usb@vger.kernel.org, linux-block@vger.kernel.org, linux-security-module@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org Date: Tue, 15 Oct 2019 22:50:02 +0100 Message-ID: <157117620241.15019.14840217828666282360.stgit@warthog.procyon.org.uk> In-Reply-To: <157117606853.15019.15459271147790470307.stgit@warthog.procyon.org.uk> References: <157117606853.15019.15459271147790470307.stgit@warthog.procyon.org.uk> User-Agent: StGit/unknown-version MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.65]); Tue, 15 Oct 2019 21:50:08 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Allow a buffer to be marked such that read() must return the entire buffer in one go or return ENOBUFS. Multiple buffers can be amalgamated into a single read, but a short read will occur if the next "whole" buffer won't fit. This is useful for watch queue notifications to make sure we don't split a notification across multiple reads, especially given that we need to fabricate an overrun record under some circumstances - and that isn't in the buffers. Signed-off-by: David Howells --- fs/pipe.c | 8 +++++++- include/linux/pipe_fs_i.h | 1 + kernel/watch_queue.c | 2 +- samples/watch_queue/watch_test.c | 2 +- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/fs/pipe.c b/fs/pipe.c index d385e3a5492e..f4c9d5480636 100644 --- a/fs/pipe.c +++ b/fs/pipe.c @@ -297,8 +297,14 @@ pipe_read(struct kiocb *iocb, struct iov_iter *to) size_t written; int error; - if (chars > total_len) + if (chars > total_len) { + if (buf->flags & PIPE_BUF_FLAG_WHOLE) { + if (ret == 0) + ret = -ENOBUFS; + break; + } chars = total_len; + } error = pipe_buf_confirm(pipe, buf); if (error) { diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h index e42a98d98c3d..58583ba056e8 100644 --- a/include/linux/pipe_fs_i.h +++ b/include/linux/pipe_fs_i.h @@ -8,6 +8,7 @@ #define PIPE_BUF_FLAG_ATOMIC 0x02 /* was atomically mapped */ #define PIPE_BUF_FLAG_GIFT 0x04 /* page is a gift */ #define PIPE_BUF_FLAG_PACKET 0x08 /* read() as a packet */ +#define PIPE_BUF_FLAG_WHOLE 0x10 /* read() must return entire buffer or error */ /** * struct pipe_buffer - a linux kernel pipe buffer diff --git a/kernel/watch_queue.c b/kernel/watch_queue.c index 40dae7dda6d6..f1d78da5309d 100644 --- a/kernel/watch_queue.c +++ b/kernel/watch_queue.c @@ -115,7 +115,7 @@ static bool post_one_notification(struct watch_queue *wqueue, buf->ops = &watch_queue_pipe_buf_ops; buf->offset = offset; buf->len = len; - buf->flags = 0; + buf->flags = PIPE_BUF_FLAG_WHOLE; pipe_commit_write(pipe, head + 1); if (!test_and_clear_bit(note, wqueue->notes_bitmap)) { diff --git a/samples/watch_queue/watch_test.c b/samples/watch_queue/watch_test.c index 19b82e9b0853..363f1d77386f 100644 --- a/samples/watch_queue/watch_test.c +++ b/samples/watch_queue/watch_test.c @@ -64,7 +64,7 @@ static void saw_key_change(struct watch_notification *n, size_t len) */ static void consumer(int fd) { - unsigned char buffer[4096], *p, *end; + unsigned char buffer[433], *p, *end; union { struct watch_notification n; unsigned char buf1[128];