Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drivers/char/mem: implement splice() for /dev/zero, /dev/full

This allows splicing zeroed pages into a pipe, and allows discarding
pages from a pipe by splicing them to /dev/zero. Writing to /dev/zero
should have the same effect as writing to /dev/null, and a
"splice_write" implementation exists only for /dev/null.

(The /dev/zero splice_read implementation could be optimized by
pushing references to the global zero page to the pipe, but that's an
optimization for another day.)

Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
Link: https://lore.kernel.org/r/20230919073743.1066313-1-max.kellermann@ionos.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Max Kellermann and committed by
Greg Kroah-Hartman
1b057bd8 19e3e6cd

+4
+4
drivers/char/mem.c
··· 640 640 #define full_lseek null_lseek 641 641 #define write_zero write_null 642 642 #define write_iter_zero write_iter_null 643 + #define splice_write_zero splice_write_null 643 644 #define open_mem open_port 644 645 645 646 static const struct file_operations __maybe_unused mem_fops = { ··· 678 677 .read_iter = read_iter_zero, 679 678 .read = read_zero, 680 679 .write_iter = write_iter_zero, 680 + .splice_read = copy_splice_read, 681 + .splice_write = splice_write_zero, 681 682 .mmap = mmap_zero, 682 683 .get_unmapped_area = get_unmapped_area_zero, 683 684 #ifndef CONFIG_MMU ··· 691 688 .llseek = full_lseek, 692 689 .read_iter = read_iter_zero, 693 690 .write = write_full, 691 + .splice_read = copy_splice_read, 694 692 }; 695 693 696 694 static const struct memdev {