pipe: Allow pipes to have kernel-reserved slots
Split pipe->ring_size into two numbers: (1) pipe->ring_size - indicates the hard size of the pipe ring. (2) pipe->max_usage - indicates the maximum number of pipe ring slots that userspace orchestrated events can fill. This allows for a pipe that is both writable by the general kernel notification facility and by userspace, allowing plenty of ring space for notifications to be added whilst preventing userspace from being able to pin too much unswappable kernel space. Signed-off-by: David Howells <dhowells@redhat.com>
This commit is contained in:
@@ -703,7 +703,7 @@ static int fuse_copy_fill(struct fuse_copy_state *cs)
|
||||
cs->pipebufs++;
|
||||
cs->nr_segs--;
|
||||
} else {
|
||||
if (cs->nr_segs >= cs->pipe->ring_size)
|
||||
if (cs->nr_segs >= cs->pipe->max_usage)
|
||||
return -EIO;
|
||||
|
||||
page = alloc_page(GFP_HIGHUSER);
|
||||
@@ -879,7 +879,7 @@ static int fuse_ref_page(struct fuse_copy_state *cs, struct page *page,
|
||||
struct pipe_buffer *buf;
|
||||
int err;
|
||||
|
||||
if (cs->nr_segs >= cs->pipe->ring_size)
|
||||
if (cs->nr_segs >= cs->pipe->max_usage)
|
||||
return -EIO;
|
||||
|
||||
err = unlock_request(cs->req);
|
||||
@@ -1341,7 +1341,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
|
||||
if (!fud)
|
||||
return -EPERM;
|
||||
|
||||
bufs = kvmalloc_array(pipe->ring_size, sizeof(struct pipe_buffer),
|
||||
bufs = kvmalloc_array(pipe->max_usage, sizeof(struct pipe_buffer),
|
||||
GFP_KERNEL);
|
||||
if (!bufs)
|
||||
return -ENOMEM;
|
||||
@@ -1353,7 +1353,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
|
||||
if (ret < 0)
|
||||
goto out;
|
||||
|
||||
if (pipe_occupancy(pipe->head, pipe->tail) + cs.nr_segs > pipe->ring_size) {
|
||||
if (pipe_occupancy(pipe->head, pipe->tail) + cs.nr_segs > pipe->max_usage) {
|
||||
ret = -EIO;
|
||||
goto out;
|
||||
}
|
||||
|
Reference in New Issue
Block a user