Commit 6dcc27fd authored by Pavel Emelyanov's avatar Pavel Emelyanov Committed by Linus Torvalds
Browse files

userfaultfd: non-cooperative: Split the find_userfault() routine

I will need one to lookup for userfaultfd_wait_queue-s in different
wait queue

Link: http://lkml.kernel.org/r/20161216144821.5183-6-aarcange@redhat.com


Signed-off-by: default avatarPavel Emelyanov <xemul@parallels.com>
Signed-off-by: default avatarMike Rapoport <rppt@linux.vnet.ibm.com>
Signed-off-by: default avatarAndrea Arcangeli <aarcange@redhat.com>
Cc: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
Cc: Hillf Danton <hillf.zj@alibaba-inc.com>
Cc: Michael Rapoport <RAPOPORT@il.ibm.com>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent a94720bf
Loading
Loading
Loading
Loading
+11 −6
Original line number Original line Diff line number Diff line
@@ -522,25 +522,30 @@ wakeup:
}
}


/* fault_pending_wqh.lock must be hold by the caller */
/* fault_pending_wqh.lock must be hold by the caller */
static inline struct userfaultfd_wait_queue *find_userfault(
static inline struct userfaultfd_wait_queue *find_userfault_in(
	struct userfaultfd_ctx *ctx)
		wait_queue_head_t *wqh)
{
{
	wait_queue_t *wq;
	wait_queue_t *wq;
	struct userfaultfd_wait_queue *uwq;
	struct userfaultfd_wait_queue *uwq;


	VM_BUG_ON(!spin_is_locked(&ctx->fault_pending_wqh.lock));
	VM_BUG_ON(!spin_is_locked(&wqh->lock));


	uwq = NULL;
	uwq = NULL;
	if (!waitqueue_active(&ctx->fault_pending_wqh))
	if (!waitqueue_active(wqh))
		goto out;
		goto out;
	/* walk in reverse to provide FIFO behavior to read userfaults */
	/* walk in reverse to provide FIFO behavior to read userfaults */
	wq = list_last_entry(&ctx->fault_pending_wqh.task_list,
	wq = list_last_entry(&wqh->task_list, typeof(*wq), task_list);
			     typeof(*wq), task_list);
	uwq = container_of(wq, struct userfaultfd_wait_queue, wq);
	uwq = container_of(wq, struct userfaultfd_wait_queue, wq);
out:
out:
	return uwq;
	return uwq;
}
}


static inline struct userfaultfd_wait_queue *find_userfault(
		struct userfaultfd_ctx *ctx)
{
	return find_userfault_in(&ctx->fault_pending_wqh);
}

static unsigned int userfaultfd_poll(struct file *file, poll_table *wait)
static unsigned int userfaultfd_poll(struct file *file, poll_table *wait)
{
{
	struct userfaultfd_ctx *ctx = file->private_data;
	struct userfaultfd_ctx *ctx = file->private_data;