Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp6488595ybl; Wed, 15 Jan 2020 05:34:38 -0800 (PST) X-Google-Smtp-Source: APXvYqwzdyA02ljhN7qAr8fGfU75sC8zLbTLsbxnPfnjS1aoe/RQdridzPrI6uIiR9oUrNXH5JRr X-Received: by 2002:a9d:5784:: with SMTP id q4mr2781363oth.278.1579095277939; Wed, 15 Jan 2020 05:34:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579095277; cv=none; d=google.com; s=arc-20160816; b=F9fk3LvIlgHK+3eVwanRspzmsxetrG3zsyyvTIYhRWXr+Rxt97rOJzvxsqhlvkGNwX XFsmoGIMRP+Vi2yqajt2tlgRcmfT+4f3GkBIZJRdrKxCQ5xzr4HLglUIP/s6GarGD43R NURkd2GQLBZvtctRDPIKdW4dGut4aMJM6uoQEIAjB28HS/KAsUn8oWuCmHpJVgPOmcvz wKKt6AUN1oQ4bHvjBzJ6sJhhGgfevUSAGi196X5Yp7bhIUR2yTMQ6tbcMiZkS3s8iWSt 3w7kOwQAQqJLJqgdCH5agR4CRsmZdxrFl1If7gpFAlsH9oGxVAsL1zQbuf89HBDvYRjb xwwQ== 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:dkim-signature; bh=aLbSI/rR07jJHm9W2nydjRJdvzW57RsOGXFqe8WgN20=; b=nOuZGMikQ+p/mSs0wH64NjxoC7fBeAldD2JnndPK1Kq3ohKS2UXTP/HISEjecVVPwp V92U3HA7rd+VkB2oVDY55blWKjuHPqWm5B2LJoZWiS+uaC7UX7Xmh7+05BZUnoqtvNTy MD+nAWIn0S+xlZwiekLbCQUBkXR+64KP85SIc26SprO1iBMKYB19i1l668GO8/oGz6i/ BcoFg/CPZBck081fvCyVGOoxzgqdCUaQ4iJwtShVTHS2Ig7MfzwXbZqLEL3SbDxoCKwJ UiwmAPTmyqHdJTzShkiSSOn6q0emR6uukIu1x66DVA5WUeU2olbZgOeqHn1KzB3c02C/ 7WNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Wmz4f+iZ; 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=pass (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 v24si1304126otq.87.2020.01.15.05.34.24; Wed, 15 Jan 2020 05:34:37 -0800 (PST) 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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Wmz4f+iZ; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729285AbgAONb6 (ORCPT + 99 others); Wed, 15 Jan 2020 08:31:58 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:43602 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728896AbgAONb5 (ORCPT ); Wed, 15 Jan 2020 08:31:57 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579095116; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aLbSI/rR07jJHm9W2nydjRJdvzW57RsOGXFqe8WgN20=; b=Wmz4f+iZR2zxJkft+MhEOiL1/bK/EsnU1wqnJ/+/7bDynlNI6FBi6iAAdzK+SM4bvo++3a Muq/A2FuVswA5Ps2T+zjE2OcwM6K/x/t43qEPwRed+FpMydVHxy9j2FEwXNn4hZ8HgMRBI j9nt79MoiV+LOcvsCd8BCCx2xUQII2I= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-267-8aU0EB0XOB-wSu2X6ekgtg-1; Wed, 15 Jan 2020 08:31:53 -0500 X-MC-Unique: 8aU0EB0XOB-wSu2X6ekgtg-1 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id CCEA6107ACE8; Wed, 15 Jan 2020 13:31:50 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-120-52.rdu2.redhat.com [10.10.120.52]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6C44360E1C; Wed, 15 Jan 2020 13:31:48 +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 08/14] pipe: Allow buffers to be marked read-whole-or-error for notifications [ver #3] From: David Howells To: torvalds@linux-foundation.org Cc: dhowells@redhat.com, Greg Kroah-Hartman , Casey Schaufler , Stephen Smalley , 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: Wed, 15 Jan 2020 13:31:47 +0000 Message-ID: <157909510770.20155.5306257642437087029.stgit@warthog.procyon.org.uk> In-Reply-To: <157909503552.20155.3030058841911628518.stgit@warthog.procyon.org.uk> References: <157909503552.20155.3030058841911628518.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 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 5352c07be47f..05d0b02ed08d 100644 --- a/fs/pipe.c +++ b/fs/pipe.c @@ -317,8 +317,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 cef70acd99bf..f86ae087aaca 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 e2e3344a2586..a01f2fed0983 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->head = 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 9bf60abf5c7e..924e13a49c37 100644 --- a/samples/watch_queue/watch_test.c +++ b/samples/watch_queue/watch_test.c @@ -63,7 +63,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];