diff options
Diffstat (limited to 'net/socket.c')
-rw-r--r-- | net/socket.c | 55 |
1 files changed, 40 insertions, 15 deletions
diff --git a/net/socket.c b/net/socket.c index f10f1d947c78..2d752e9eb3f9 100644 --- a/net/socket.c +++ b/net/socket.c | |||
@@ -117,8 +117,10 @@ static ssize_t sock_write_iter(struct kiocb *iocb, struct iov_iter *from); | |||
117 | static int sock_mmap(struct file *file, struct vm_area_struct *vma); | 117 | static int sock_mmap(struct file *file, struct vm_area_struct *vma); |
118 | 118 | ||
119 | static int sock_close(struct inode *inode, struct file *file); | 119 | static int sock_close(struct inode *inode, struct file *file); |
120 | static __poll_t sock_poll(struct file *file, | 120 | static struct wait_queue_head *sock_get_poll_head(struct file *file, |
121 | struct poll_table_struct *wait); | 121 | __poll_t events); |
122 | static __poll_t sock_poll_mask(struct file *file, __poll_t); | ||
123 | static __poll_t sock_poll(struct file *file, struct poll_table_struct *wait); | ||
122 | static long sock_ioctl(struct file *file, unsigned int cmd, unsigned long arg); | 124 | static long sock_ioctl(struct file *file, unsigned int cmd, unsigned long arg); |
123 | #ifdef CONFIG_COMPAT | 125 | #ifdef CONFIG_COMPAT |
124 | static long compat_sock_ioctl(struct file *file, | 126 | static long compat_sock_ioctl(struct file *file, |
@@ -141,6 +143,8 @@ static const struct file_operations socket_file_ops = { | |||
141 | .llseek = no_llseek, | 143 | .llseek = no_llseek, |
142 | .read_iter = sock_read_iter, | 144 | .read_iter = sock_read_iter, |
143 | .write_iter = sock_write_iter, | 145 | .write_iter = sock_write_iter, |
146 | .get_poll_head = sock_get_poll_head, | ||
147 | .poll_mask = sock_poll_mask, | ||
144 | .poll = sock_poll, | 148 | .poll = sock_poll, |
145 | .unlocked_ioctl = sock_ioctl, | 149 | .unlocked_ioctl = sock_ioctl, |
146 | #ifdef CONFIG_COMPAT | 150 | #ifdef CONFIG_COMPAT |
@@ -1114,27 +1118,48 @@ out_release: | |||
1114 | } | 1118 | } |
1115 | EXPORT_SYMBOL(sock_create_lite); | 1119 | EXPORT_SYMBOL(sock_create_lite); |
1116 | 1120 | ||
1117 | /* No kernel lock held - perfect */ | 1121 | static struct wait_queue_head *sock_get_poll_head(struct file *file, |
1118 | static __poll_t sock_poll(struct file *file, poll_table *wait) | 1122 | __poll_t events) |
1119 | { | 1123 | { |
1120 | __poll_t busy_flag = 0; | 1124 | struct socket *sock = file->private_data; |
1121 | struct socket *sock; | 1125 | |
1126 | if (!sock->ops->poll_mask) | ||
1127 | return NULL; | ||
1128 | sock_poll_busy_loop(sock, events); | ||
1129 | return sk_sleep(sock->sk); | ||
1130 | } | ||
1131 | |||
1132 | static __poll_t sock_poll_mask(struct file *file, __poll_t events) | ||
1133 | { | ||
1134 | struct socket *sock = file->private_data; | ||
1122 | 1135 | ||
1123 | /* | 1136 | /* |
1124 | * We can't return errors to poll, so it's either yes or no. | 1137 | * We need to be sure we are in sync with the socket flags modification. |
1138 | * | ||
1139 | * This memory barrier is paired in the wq_has_sleeper. | ||
1125 | */ | 1140 | */ |
1126 | sock = file->private_data; | 1141 | smp_mb(); |
1142 | |||
1143 | /* this socket can poll_ll so tell the system call */ | ||
1144 | return sock->ops->poll_mask(sock, events) | | ||
1145 | (sk_can_busy_loop(sock->sk) ? POLL_BUSY_LOOP : 0); | ||
1146 | } | ||
1127 | 1147 | ||
1128 | if (sk_can_busy_loop(sock->sk)) { | 1148 | /* No kernel lock held - perfect */ |
1129 | /* this socket can poll_ll so tell the system call */ | 1149 | static __poll_t sock_poll(struct file *file, poll_table *wait) |
1130 | busy_flag = POLL_BUSY_LOOP; | 1150 | { |
1151 | struct socket *sock = file->private_data; | ||
1152 | __poll_t events = poll_requested_events(wait), mask = 0; | ||
1131 | 1153 | ||
1132 | /* once, only if requested by syscall */ | 1154 | if (sock->ops->poll) { |
1133 | if (wait && (wait->_key & POLL_BUSY_LOOP)) | 1155 | sock_poll_busy_loop(sock, events); |
1134 | sk_busy_loop(sock->sk, 1); | 1156 | mask = sock->ops->poll(file, sock, wait); |
1157 | } else if (sock->ops->poll_mask) { | ||
1158 | sock_poll_wait(file, sock_get_poll_head(file, events), wait); | ||
1159 | mask = sock->ops->poll_mask(sock, events); | ||
1135 | } | 1160 | } |
1136 | 1161 | ||
1137 | return busy_flag | sock->ops->poll(file, sock, wait); | 1162 | return mask | sock_poll_busy_flag(sock); |
1138 | } | 1163 | } |
1139 | 1164 | ||
1140 | static int sock_mmap(struct file *file, struct vm_area_struct *vma) | 1165 | static int sock_mmap(struct file *file, struct vm_area_struct *vma) |