@@ -117,8 +117,10 @@ static ssize_t sock_write_iter(struct kiocb *iocb, struct iov_iter *from);
117
117
static int sock_mmap (struct file * file , struct vm_area_struct * vma );
118
118
119
119
static int sock_close (struct inode * inode , struct file * file );
120
- static __poll_t sock_poll (struct file * file ,
121
- struct poll_table_struct * wait );
120
+ static struct wait_queue_head * sock_get_poll_head (struct file * file ,
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
124
static long sock_ioctl (struct file * file , unsigned int cmd , unsigned long arg );
123
125
#ifdef CONFIG_COMPAT
124
126
static long compat_sock_ioctl (struct file * file ,
@@ -141,6 +143,8 @@ static const struct file_operations socket_file_ops = {
141
143
.llseek = no_llseek ,
142
144
.read_iter = sock_read_iter ,
143
145
.write_iter = sock_write_iter ,
146
+ .get_poll_head = sock_get_poll_head ,
147
+ .poll_mask = sock_poll_mask ,
144
148
.poll = sock_poll ,
145
149
.unlocked_ioctl = sock_ioctl ,
146
150
#ifdef CONFIG_COMPAT
@@ -1114,14 +1118,48 @@ int sock_create_lite(int family, int type, int protocol, struct socket **res)
1114
1118
}
1115
1119
EXPORT_SYMBOL (sock_create_lite );
1116
1120
1121
+ static struct wait_queue_head * sock_get_poll_head (struct file * file ,
1122
+ __poll_t events )
1123
+ {
1124
+ struct socket * sock = file -> private_data ;
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 ;
1135
+
1136
+ /*
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.
1140
+ */
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
+ }
1147
+
1117
1148
/* No kernel lock held - perfect */
1118
1149
static __poll_t sock_poll (struct file * file , poll_table * wait )
1119
1150
{
1120
1151
struct socket * sock = file -> private_data ;
1121
- __poll_t events = poll_requested_events (wait );
1152
+ __poll_t events = poll_requested_events (wait ), mask = 0 ;
1122
1153
1123
- sock_poll_busy_loop (sock , events );
1124
- return sock -> ops -> poll (file , sock , wait ) | sock_poll_busy_flag (sock );
1154
+ if (sock -> ops -> poll ) {
1155
+ sock_poll_busy_loop (sock , events );
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 );
1160
+ }
1161
+
1162
+ return mask | sock_poll_busy_flag (sock );
1125
1163
}
1126
1164
1127
1165
static int sock_mmap (struct file * file , struct vm_area_struct * vma )
0 commit comments