|
38 | 38 |
|
39 | 39 | #include "internal.h"
|
40 | 40 |
|
| 41 | +/* |
| 42 | + * Splice doesn't support FMODE_NOWAIT. Since pipes may set this flag to |
| 43 | + * indicate they support non-blocking reads or writes, we must clear it |
| 44 | + * here if set to avoid blocking other users of this pipe if splice is |
| 45 | + * being done on it. |
| 46 | + */ |
| 47 | +static noinline void noinline pipe_clear_nowait(struct file *file) |
| 48 | +{ |
| 49 | + fmode_t fmode = READ_ONCE(file->f_mode); |
| 50 | + |
| 51 | + do { |
| 52 | + if (!(fmode & FMODE_NOWAIT)) |
| 53 | + break; |
| 54 | + } while (!try_cmpxchg(&file->f_mode, &fmode, fmode & ~FMODE_NOWAIT)); |
| 55 | +} |
| 56 | + |
41 | 57 | /*
|
42 | 58 | * Attempt to steal a page from a pipe buffer. This should perhaps go into
|
43 | 59 | * a vm helper function, it's already simplified quite a bit by the
|
@@ -1219,10 +1235,16 @@ static long __do_splice(struct file *in, loff_t __user *off_in,
|
1219 | 1235 | ipipe = get_pipe_info(in, true);
|
1220 | 1236 | opipe = get_pipe_info(out, true);
|
1221 | 1237 |
|
1222 |
| - if (ipipe && off_in) |
1223 |
| - return -ESPIPE; |
1224 |
| - if (opipe && off_out) |
1225 |
| - return -ESPIPE; |
| 1238 | + if (ipipe) { |
| 1239 | + if (off_in) |
| 1240 | + return -ESPIPE; |
| 1241 | + pipe_clear_nowait(in); |
| 1242 | + } |
| 1243 | + if (opipe) { |
| 1244 | + if (off_out) |
| 1245 | + return -ESPIPE; |
| 1246 | + pipe_clear_nowait(out); |
| 1247 | + } |
1226 | 1248 |
|
1227 | 1249 | if (off_out) {
|
1228 | 1250 | if (copy_from_user(&offset, off_out, sizeof(loff_t)))
|
@@ -1319,6 +1341,8 @@ static long vmsplice_to_user(struct file *file, struct iov_iter *iter,
|
1319 | 1341 | if (!pipe)
|
1320 | 1342 | return -EBADF;
|
1321 | 1343 |
|
| 1344 | + pipe_clear_nowait(file); |
| 1345 | + |
1322 | 1346 | if (sd.total_len) {
|
1323 | 1347 | pipe_lock(pipe);
|
1324 | 1348 | ret = __splice_from_pipe(pipe, &sd, pipe_to_user);
|
@@ -1347,6 +1371,8 @@ static long vmsplice_to_pipe(struct file *file, struct iov_iter *iter,
|
1347 | 1371 | if (!pipe)
|
1348 | 1372 | return -EBADF;
|
1349 | 1373 |
|
| 1374 | + pipe_clear_nowait(file); |
| 1375 | + |
1350 | 1376 | pipe_lock(pipe);
|
1351 | 1377 | ret = wait_for_space(pipe, flags);
|
1352 | 1378 | if (!ret)
|
|
0 commit comments