Received: by 10.223.176.46 with SMTP id f43csp3339386wra; Mon, 22 Jan 2018 12:24:00 -0800 (PST) X-Google-Smtp-Source: AH8x227Im6YB8HaMioqO5jbla8caRm0GgfcfeGD8aVsP3hsni/eoLw4uLLO7oH9HWqEzR4RrqNgy X-Received: by 10.36.23.78 with SMTP id 75mr88492ith.24.1516652640318; Mon, 22 Jan 2018 12:24:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516652640; cv=none; d=google.com; s=arc-20160816; b=UHvFNSzPjcJmTZQczgi8rmIQITL04Dnvo7i3TR17HD2GXYI/si3HSZC88JHRU8u/8L xhLHlismhL/xnghphlzL3IcQx0g/Q42EPJfUTgm8jIQzqgM6UfO5iGnat+OgVU4PnTiC Lg7N1XMM326wlXDmOvXUHtyBX2QdokTnRUqKubK79Rtyf6YTL7HBtVkHnM1ZV83cud4f /T5rR+WIiKEgUVtUOB75LKiJI/jRbvYdOnvNE6tJ9rKID42U9WWoYWCFxB+Vi9K8qyQM kSTLv6DvNdaRjxZFr8/oCEJNfnPDCScMEfejx9ULsJP39RLm1wEYON82RBzXjhYEnoKs DJhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=k5cdI7oyYhiNuR8QlvxcOJ70G06XdPuVNmNDJSPuENw=; b=S13a/dZFXzymZ/16RdEZN8AX8SW5uIwuLfx9WhaUJ0JxIEzX4Z+gP//NaUBRIA3NKc SER8S0KRhWiisQckSfXSHaY7E8UkMdJ/sN9HCdoQvw8o4AA74g4lSfRdea+zta7gPvZ3 HWT20Cj3/MXwQaqYcllV5G+G+Jshf9M6DcyTig/pZhDA/vYV86nrt3siFQbf5OfykS/X Lpcg+tBsR51odTDQi4MYGhbWGtSvhpVy6tb/bBLW9H3xg3ZqZTr2txCQKTZU2ZDMpQ40 ij4EYssitS2mWE1vJpTUXz5PXuuxpAPkF3zdn//IenzrFKYUnxuIDMekQD+MKtzJrQlo xkQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=eEscJQ58; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g194si6549831itb.32.2018.01.22.12.23.47; Mon, 22 Jan 2018 12:24:00 -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=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=eEscJQ58; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751615AbeAVUNo (ORCPT + 99 others); Mon, 22 Jan 2018 15:13:44 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:38085 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751567AbeAVUNk (ORCPT ); Mon, 22 Jan 2018 15:13:40 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=k5cdI7oyYhiNuR8QlvxcOJ70G06XdPuVNmNDJSPuENw=; b=eEscJQ582DC4AsSq/USW9BrGC Z/Lb8fi97AOy4KJzdncyImqZkG/MfSZ6YqL4SiobbPgEhYwK61CBRV4ke0owVY4Nt0/iUtSZqWDg0 WVlQoGbBKI3Q6GtVW67A+1yE0fcS9Jzcr8rlfasp26cdisquRK7ZZ34svF41xjWnMaaK/4tHAZkZs 30+IAC8sO7iK/Jnq7UGAeu0UxKYR95p97MK8b3ML5UpzKtx4yW7piJtSHeMA7p5+Y8XixA5SAaNV2 z/bfPphRXAtH7xxedn7Qvzd8BoLKxvYH8LIcViNCVpcKtw3G22l8WMU7M/1w4SGmq2L9pb6C0w2bQ BsF06z/uA==; Received: from 178.114.226.247.wireless.dyn.drei.com ([178.114.226.247] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.89 #1 (Red Hat Linux)) id 1ediTK-0007cz-Hb; Mon, 22 Jan 2018 20:13:38 +0000 From: Christoph Hellwig To: viro@zeniv.linux.org.uk Cc: Avi Kivity , linux-aio@kvack.org, linux-fsdevel@vger.kernel.org, netdev@vger.kernel.org, linux-api@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 16/36] net: add support for ->poll_mask in proto_ops Date: Mon, 22 Jan 2018 21:12:23 +0100 Message-Id: <20180122201243.31610-17-hch@lst.de> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20180122201243.31610-1-hch@lst.de> References: <20180122201243.31610-1-hch@lst.de> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The socket file operations still implement ->poll until all protocols are switched over. Signed-off-by: Christoph Hellwig --- include/linux/net.h | 3 +++ net/socket.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 49 insertions(+), 5 deletions(-) diff --git a/include/linux/net.h b/include/linux/net.h index c2d468cb9821..2d58d583d29a 100644 --- a/include/linux/net.h +++ b/include/linux/net.h @@ -147,6 +147,9 @@ struct proto_ops { int (*getname) (struct socket *sock, struct sockaddr *addr, int *sockaddr_len, int peer); + struct wait_queue_head *(*get_poll_head)(struct socket *sock, + __poll_t events); + __poll_t (*poll_mask) (struct socket *sock, __poll_t events); __poll_t (*poll) (struct file *file, struct socket *sock, struct poll_table_struct *wait); int (*ioctl) (struct socket *sock, unsigned int cmd, diff --git a/net/socket.c b/net/socket.c index db11e48a375b..21d50c5d4af4 100644 --- a/net/socket.c +++ b/net/socket.c @@ -118,8 +118,10 @@ static ssize_t sock_write_iter(struct kiocb *iocb, struct iov_iter *from); static int sock_mmap(struct file *file, struct vm_area_struct *vma); static int sock_close(struct inode *inode, struct file *file); -static __poll_t sock_poll(struct file *file, - struct poll_table_struct *wait); +static struct wait_queue_head *sock_get_poll_head(struct file *file, + __poll_t events); +static __poll_t sock_poll_mask(struct file *file, __poll_t); +static __poll_t sock_poll(struct file *file, struct poll_table_struct *wait); static long sock_ioctl(struct file *file, unsigned int cmd, unsigned long arg); #ifdef CONFIG_COMPAT static long compat_sock_ioctl(struct file *file, @@ -142,6 +144,8 @@ static const struct file_operations socket_file_ops = { .llseek = no_llseek, .read_iter = sock_read_iter, .write_iter = sock_write_iter, + .get_poll_head = sock_get_poll_head, + .poll_mask = sock_poll_mask, .poll = sock_poll, .unlocked_ioctl = sock_ioctl, #ifdef CONFIG_COMPAT @@ -1094,14 +1098,51 @@ int sock_create_lite(int family, int type, int protocol, struct socket **res) } EXPORT_SYMBOL(sock_create_lite); +static struct wait_queue_head *sock_get_poll_head(struct file *file, + __poll_t events) +{ + struct socket *sock = file->private_data; + + if (!sock->ops->poll_mask) + return NULL; + if (sock->ops->get_poll_head) + return sock->ops->get_poll_head(sock, events); + + sock_poll_busy_loop(sock, events); + return sk_sleep(sock->sk); +} + +static __poll_t sock_poll_mask(struct file *file, __poll_t events) +{ + struct socket *sock = file->private_data; + + /* + * We need to be sure we are in sync with the socket flags modification. + * + * This memory barrier is paired in the wq_has_sleeper. + */ + smp_mb(); + + /* this socket can poll_ll so tell the system call */ + return sock->ops->poll_mask(sock, events) | + (sk_can_busy_loop(sock->sk) ? POLL_BUSY_LOOP : 0); +} + /* No kernel lock held - perfect */ static __poll_t sock_poll(struct file *file, poll_table *wait) { struct socket *sock = file->private_data; - __poll_t events = poll_requested_events(wait); + __poll_t events = poll_requested_events(wait), mask = 0; - sock_poll_busy_loop(sock, events); - return sock->ops->poll(file, sock, wait) | sock_poll_busy_flag(sock); + if (sock->ops->poll) { + sock_poll_busy_loop(sock, events); + mask = sock->ops->poll(file, sock, wait); + } else if (sock->ops->poll_mask) { + sock_poll_wait(file, sock_get_poll_head(file, events), wait); + mask = sock->ops->poll_mask(sock, events); + } + + return mask | sock_poll_busy_flag(sock); } static int sock_mmap(struct file *file, struct vm_area_struct *vma) -- 2.14.2