Commit bb523b40 authored by Andreas Gruenbacher's avatar Andreas Gruenbacher
Browse files

gup: Turn fault_in_pages_{readable,writeable} into fault_in_{readable,writeable}



Turn fault_in_pages_{readable,writeable} into versions that return the
number of bytes not faulted in, similar to copy_to_user, instead of
returning a non-zero value when any of the requested pages couldn't be
faulted in.  This supports the existing users that require all pages to
be faulted in as well as new users that are happy if any pages can be
faulted in.

Rename the functions to fault_in_{readable,writeable} to make sure
this change doesn't silently break things.

Neither of these functions is entirely trivial and it doesn't seem
useful to inline them, so move them to mm/gup.c.

Signed-off-by: default avatarAndreas Gruenbacher <agruenba@redhat.com>
parent 0c8eb288
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -669,7 +669,8 @@ static void __init kvm_use_magic_page(void)
	on_each_cpu(kvm_map_magic_page, &features, 1);
	on_each_cpu(kvm_map_magic_page, &features, 1);


	/* Quick self-test to see if the mapping works */
	/* Quick self-test to see if the mapping works */
	if (fault_in_pages_readable((const char *)KVM_MAGIC_PAGE, sizeof(u32))) {
	if (fault_in_readable((const char __user *)KVM_MAGIC_PAGE,
			      sizeof(u32))) {
		kvm_patching_worked = false;
		kvm_patching_worked = false;
		return;
		return;
	}
	}
+2 −2
Original line number Original line Diff line number Diff line
@@ -1048,7 +1048,7 @@ SYSCALL_DEFINE3(swapcontext, struct ucontext __user *, old_ctx,
	if (new_ctx == NULL)
	if (new_ctx == NULL)
		return 0;
		return 0;
	if (!access_ok(new_ctx, ctx_size) ||
	if (!access_ok(new_ctx, ctx_size) ||
	    fault_in_pages_readable((u8 __user *)new_ctx, ctx_size))
	    fault_in_readable((char __user *)new_ctx, ctx_size))
		return -EFAULT;
		return -EFAULT;


	/*
	/*
@@ -1237,7 +1237,7 @@ SYSCALL_DEFINE3(debug_setcontext, struct ucontext __user *, ctx,
#endif
#endif


	if (!access_ok(ctx, sizeof(*ctx)) ||
	if (!access_ok(ctx, sizeof(*ctx)) ||
	    fault_in_pages_readable((u8 __user *)ctx, sizeof(*ctx)))
	    fault_in_readable((char __user *)ctx, sizeof(*ctx)))
		return -EFAULT;
		return -EFAULT;


	/*
	/*
+1 −1
Original line number Original line Diff line number Diff line
@@ -688,7 +688,7 @@ SYSCALL_DEFINE3(swapcontext, struct ucontext __user *, old_ctx,
	if (new_ctx == NULL)
	if (new_ctx == NULL)
		return 0;
		return 0;
	if (!access_ok(new_ctx, ctx_size) ||
	if (!access_ok(new_ctx, ctx_size) ||
	    fault_in_pages_readable((u8 __user *)new_ctx, ctx_size))
	    fault_in_readable((char __user *)new_ctx, ctx_size))
		return -EFAULT;
		return -EFAULT;


	/*
	/*
+3 −4
Original line number Original line Diff line number Diff line
@@ -205,7 +205,7 @@ int copy_fpstate_to_sigframe(void __user *buf, void __user *buf_fx, int size)
	fpregs_unlock();
	fpregs_unlock();


	if (ret) {
	if (ret) {
		if (!fault_in_pages_writeable(buf_fx, fpu_user_xstate_size))
		if (!fault_in_writeable(buf_fx, fpu_user_xstate_size))
			goto retry;
			goto retry;
		return -EFAULT;
		return -EFAULT;
	}
	}
@@ -278,10 +278,9 @@ static int restore_fpregs_from_user(void __user *buf, u64 xrestore,
		if (ret != -EFAULT)
		if (ret != -EFAULT)
			return -EINVAL;
			return -EINVAL;


		ret = fault_in_pages_readable(buf, size);
		if (!fault_in_readable(buf, size))
		if (!ret)
			goto retry;
			goto retry;
		return ret;
		return -EFAULT;
	}
	}


	/*
	/*
+3 −4
Original line number Original line Diff line number Diff line
@@ -336,7 +336,7 @@ int armada_gem_pwrite_ioctl(struct drm_device *dev, void *data,
	struct drm_armada_gem_pwrite *args = data;
	struct drm_armada_gem_pwrite *args = data;
	struct armada_gem_object *dobj;
	struct armada_gem_object *dobj;
	char __user *ptr;
	char __user *ptr;
	int ret;
	int ret = 0;


	DRM_DEBUG_DRIVER("handle %u off %u size %u ptr 0x%llx\n",
	DRM_DEBUG_DRIVER("handle %u off %u size %u ptr 0x%llx\n",
		args->handle, args->offset, args->size, args->ptr);
		args->handle, args->offset, args->size, args->ptr);
@@ -349,9 +349,8 @@ int armada_gem_pwrite_ioctl(struct drm_device *dev, void *data,
	if (!access_ok(ptr, args->size))
	if (!access_ok(ptr, args->size))
		return -EFAULT;
		return -EFAULT;


	ret = fault_in_pages_readable(ptr, args->size);
	if (fault_in_readable(ptr, args->size))
	if (ret)
		return -EFAULT;
		return ret;


	dobj = armada_gem_object_lookup(file, args->handle);
	dobj = armada_gem_object_lookup(file, args->handle);
	if (dobj == NULL)
	if (dobj == NULL)
Loading