Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp2689933ybl; Thu, 29 Aug 2019 11:31:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqxCPgeAZ8/E2zPrfBLZCWa0WvPrMhHfIlYrqgEw09NWQ4CT/ZSEPXg1gy2I9XyTgMG+IggO X-Received: by 2002:a17:90a:a897:: with SMTP id h23mr11533343pjq.44.1567103469376; Thu, 29 Aug 2019 11:31:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567103469; cv=none; d=google.com; s=arc-20160816; b=0C/fPCj/x5jCiPy7oRUXCN4zGci613iZtzKVw64KlUuuS/i5cnUp9rGZmoocvh3MK7 qmiftSP0GU3uFT138txCiv2DGhVQ7YmOSMUK6gpyGojV7tE7JPc1/CZ13C5Hyhk0zaqg kmy9Y+iM44bl568ii9e0hVFc647Fz3/9m5TglBW4SzWrmVLgiNvPRMurEZ9Es2UrHtAU JOJqGCo3a+B4cnAWoiqmDgtwBRMjqdTEMCSze6RaWYpYOYLbxO0zSOJ2PPHrD6Cewyt6 RcrZj9e55FGuP9GaFOizjHFldhz/up/Hkt8wpQxUUZ6X6KW1tnuqxnkbkKRm7NbqRX0b XZiA== 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=our1exiiKIouTgNsTfQazd2wtGYq0J8MAwf6ne4MGwY=; b=fiWEHdrF+upT3S1xGeUp5qclWTZYYmlKorxj9pT1+6Ynrpd2EMz6ZhNgQ7QgtNxkV8 E1yYfkMtqc7zKbA+y7nK7p46gYXfT3s5qpejcJuwBQryHsTeIvZkxMl4MZtHJeXCzoVi /htAqAPjj/KeKVoIvgAGef8fHBbnuEBkxfcm1IKTUMFGpYDUzZsuyCxZwleIkAHhUhLx cFiBy8ttWu8SxaVoSVlBLO2ZM+xikzIIwl7T7HmYrwyx0GBXZ6pFfiz+KcTwtQ948t+a JDyRNmRo/DkdU4EKRu0QLj41b+FxWzBdIdtBbVMjD6dA+VqJqK7T+gCJUNqAs8Y2ZKyO 2s/A== 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 60si2550570plb.16.2019.08.29.11.30.54; Thu, 29 Aug 2019 11:31:09 -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 S1729847AbfH2SaF (ORCPT + 99 others); Thu, 29 Aug 2019 14:30:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47228 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728826AbfH2SaD (ORCPT ); Thu, 29 Aug 2019 14:30:03 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 268188CF1A5; Thu, 29 Aug 2019 18:30:02 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-120-255.rdu2.redhat.com [10.10.120.255]) by smtp.corp.redhat.com (Postfix) with ESMTP id 540D754527; Thu, 29 Aug 2019 18:29:59 +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: [PATCH 01/11] uapi: General notification ring definitions [ver #6] From: David Howells To: viro@zeniv.linux.org.uk 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-security-module@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, linux-block@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org Date: Thu, 29 Aug 2019 19:29:58 +0100 Message-ID: <156710339856.10009.1556595458056359912.stgit@warthog.procyon.org.uk> In-Reply-To: <156710338860.10009.12524626894838499011.stgit@warthog.procyon.org.uk> References: <156710338860.10009.12524626894838499011.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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.69]); Thu, 29 Aug 2019 18:30:02 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add UAPI definitions for the general notification ring, including the following pieces: (1) struct watch_notification. This is the metadata header for each entry in the ring. It includes a type and subtype that indicate the source of the message (eg. WATCH_TYPE_MOUNT_NOTIFY) and the kind of the message (eg. NOTIFY_MOUNT_NEW_MOUNT). The header also contains an information field that conveys the following information: - WATCH_INFO_LENGTH. The size of the entry (entries are variable length). - WATCH_INFO_ID. The watch ID specified when the watchpoint was set. - WATCH_INFO_TYPE_INFO. (Sub)type-specific information. - WATCH_INFO_FLAG_*. Flag bits overlain on the type-specific information. For use by the type. All the information in the header can be used in filtering messages at the point of writing into the buffer. (2) struct watch_queue_buffer. This describes the layout of the ring. Note that the first slots in the ring contain a special metadata entry that contains the ring pointers. The producer in the kernel knows to skip this and it has a proper header (WATCH_TYPE_META, WATCH_META_SKIP_NOTIFICATION) that indicates the size so that the ring consumer can handle it the same as any other record and just skip it. Note that this means that ring entries can never be split over the end of the ring, so if an entry would need to be split, a skip record is inserted to wrap the ring first; this is also WATCH_TYPE_META, WATCH_META_SKIP_NOTIFICATION. (3) WATCH_INFO_NOTIFICATIONS_LOST. This is a flag that can be set in the metadata header by the kernel to indicate that at least one message was lost since it was last cleared by userspace. Signed-off-by: David Howells Reviewed-by: Greg Kroah-Hartman --- include/uapi/linux/watch_queue.h | 67 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 include/uapi/linux/watch_queue.h diff --git a/include/uapi/linux/watch_queue.h b/include/uapi/linux/watch_queue.h new file mode 100644 index 000000000000..70f575099968 --- /dev/null +++ b/include/uapi/linux/watch_queue.h @@ -0,0 +1,67 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +#ifndef _UAPI_LINUX_WATCH_QUEUE_H +#define _UAPI_LINUX_WATCH_QUEUE_H + +#include + +enum watch_notification_type { + WATCH_TYPE_META = 0, /* Special record */ + WATCH_TYPE___NR = 1 +}; + +enum watch_meta_notification_subtype { + WATCH_META_SKIP_NOTIFICATION = 0, /* Just skip this record */ + WATCH_META_REMOVAL_NOTIFICATION = 1, /* Watched object was removed */ +}; + +#define WATCH_LENGTH_GRANULARITY sizeof(__u64) + +/* + * Notification record header. This is aligned to 64-bits so that subclasses + * can contain __u64 fields. + */ +struct watch_notification { + __u32 type:24; /* enum watch_notification_type */ + __u32 subtype:8; /* Type-specific subtype (filterable) */ + __u32 info; +#define WATCH_INFO_LENGTH 0x0000003f /* Length of record / sizeof(watch_notification) */ +#define WATCH_INFO_LENGTH__SHIFT 0 +#define WATCH_INFO_ID 0x0000ff00 /* ID of watchpoint, if type-appropriate */ +#define WATCH_INFO_ID__SHIFT 8 +#define WATCH_INFO_TYPE_INFO 0xffff0000 /* Type-specific info */ +#define WATCH_INFO_TYPE_INFO__SHIFT 16 +#define WATCH_INFO_FLAG_0 0x00010000 /* Type-specific info, flag bit 0 */ +#define WATCH_INFO_FLAG_1 0x00020000 /* ... */ +#define WATCH_INFO_FLAG_2 0x00040000 +#define WATCH_INFO_FLAG_3 0x00080000 +#define WATCH_INFO_FLAG_4 0x00100000 +#define WATCH_INFO_FLAG_5 0x00200000 +#define WATCH_INFO_FLAG_6 0x00400000 +#define WATCH_INFO_FLAG_7 0x00800000 +} __attribute__((aligned(WATCH_LENGTH_GRANULARITY))); + +struct watch_queue_buffer { + union { + /* The first few entries are special, containing the + * ring management variables. + */ + struct { + struct watch_notification watch; /* WATCH_TYPE_META */ + __u32 head; /* Ring head index */ + __u32 tail; /* Ring tail index */ + __u32 mask; /* Ring index mask */ + __u32 __reserved; + } meta; + struct watch_notification slots[0]; + }; +}; + +/* + * The Metadata pseudo-notification message uses a flag bits in the information + * field to convey the fact that messages have been lost. We can only use a + * single bit in this manner per word as some arches that support SMP + * (eg. parisc) have no kernel<->user atomic bit ops. + */ +#define WATCH_INFO_NOTIFICATIONS_LOST WATCH_INFO_FLAG_0 + +#endif /* _UAPI_LINUX_WATCH_QUEUE_H */