linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: tip-bot for Ingo Molnar <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: peterz@infradead.org, oleg@redhat.com,
	dave.hansen@linux.intel.com, yu-cheng.yu@intel.com,
	luto@kernel.org, bp@alien8.de, linux-kernel@vger.kernel.org,
	tglx@linutronix.de, hpa@zytor.com, akpm@linux-foundation.org,
	luto@amacapital.net, fenghua.yu@intel.com, ebiggers3@gmail.com,
	torvalds@linux-foundation.org, mingo@kernel.org, riel@redhat.com
Subject: [tip:x86/fpu] x86/fpu: Clarify parameter names in the copy_xstate_to_*() methods
Date: Tue, 26 Sep 2017 01:24:40 -0700	[thread overview]
Message-ID: <tip-56583c9a1400fe1935edd55b24b4fbbc779b59cb@git.kernel.org> (raw)
In-Reply-To: <20170923130016.21448-9-mingo@kernel.org>

Commit-ID:  56583c9a1400fe1935edd55b24b4fbbc779b59cb
Gitweb:     http://git.kernel.org/tip/56583c9a1400fe1935edd55b24b4fbbc779b59cb
Author:     Ingo Molnar <mingo@kernel.org>
AuthorDate: Sat, 23 Sep 2017 14:59:51 +0200
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Sun, 24 Sep 2017 13:04:32 +0200

x86/fpu: Clarify parameter names in the copy_xstate_to_*() methods

Right now there's a confusing mixture of 'offset' and 'size' parameters:

 - __copy_xstate_to_*() input parameter 'end_pos' not not really an offset,
   but the full size of the copy to be performed.

 - input parameter 'count' to copy_xstate_to_*() shadows that of
   __copy_xstate_to_*()'s 'count' parameter name - but the roles
   are different: the first one is the total number of bytes to
   be copied, while the second one is a partial copy size.

To unconfuse all this, use a consistent set of parameter names:

 - 'size' is the partial copy size within a single xstate component
 - 'size_total' is the total copy requested
 - 'offset_start' is the requested starting offset.
 - 'offset' is the offset within an xstate component.

No change in functionality.

Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Eric Biggers <ebiggers3@gmail.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rik van Riel <riel@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Yu-cheng Yu <yu-cheng.yu@intel.com>
Link: http://lkml.kernel.org/r/20170923130016.21448-9-mingo@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/include/asm/fpu/xstate.h |  4 ++--
 arch/x86/kernel/fpu/xstate.c      | 44 +++++++++++++++++++--------------------
 2 files changed, 24 insertions(+), 24 deletions(-)

diff --git a/arch/x86/include/asm/fpu/xstate.h b/arch/x86/include/asm/fpu/xstate.h
index e4430b8..fed6617 100644
--- a/arch/x86/include/asm/fpu/xstate.h
+++ b/arch/x86/include/asm/fpu/xstate.h
@@ -48,8 +48,8 @@ void fpu__xstate_clear_all_cpu_caps(void);
 void *get_xsave_addr(struct xregs_state *xsave, int xstate);
 const void *get_xsave_field_ptr(int xstate_field);
 int using_compacted_format(void);
-int copy_xstate_to_kernel(void *kbuf, struct xregs_state *xsave, unsigned int pos, unsigned int count);
-int copy_xstate_to_user(void __user *ubuf, struct xregs_state *xsave, unsigned int pos, unsigned int count);
+int copy_xstate_to_kernel(void *kbuf, struct xregs_state *xsave, unsigned int offset, unsigned int size);
+int copy_xstate_to_user(void __user *ubuf, struct xregs_state *xsave, unsigned int offset, unsigned int size);
 int copy_user_to_xstate(const void *kbuf, const void __user *ubuf,
 		     struct xregs_state *xsave);
 #endif
diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c
index 1f50fda..c130835 100644
--- a/arch/x86/kernel/fpu/xstate.c
+++ b/arch/x86/kernel/fpu/xstate.c
@@ -927,15 +927,15 @@ int arch_set_user_pkey_access(struct task_struct *tsk, int pkey,
 static inline int
 __copy_xstate_to_kernel(void *kbuf,
 			const void *data,
-			unsigned int pos, unsigned int count, int end_pos)
+			unsigned int offset, unsigned int size, int size_total)
 {
-	if (!count)
+	if (!size)
 		return 0;
 
-	if (end_pos < 0 || pos < end_pos) {
-		unsigned int copy = end_pos < 0 ? count : min(count, end_pos - pos);
+	if (size_total < 0 || offset < size_total) {
+		unsigned int copy = size_total < 0 ? size : min(size, size_total - offset);
 
-		memcpy(kbuf + pos, data, copy);
+		memcpy(kbuf + offset, data, copy);
 	}
 	return 0;
 }
@@ -947,7 +947,7 @@ __copy_xstate_to_kernel(void *kbuf,
  * It supports partial copy but pos always starts from zero. This is called
  * from xstateregs_get() and there we check the CPU has XSAVES.
  */
-int copy_xstate_to_kernel(void *kbuf, struct xregs_state *xsave, unsigned int pos, unsigned int count)
+int copy_xstate_to_kernel(void *kbuf, struct xregs_state *xsave, unsigned int offset_start, unsigned int size_total)
 {
 	unsigned int offset, size;
 	int ret, i;
@@ -956,7 +956,7 @@ int copy_xstate_to_kernel(void *kbuf, struct xregs_state *xsave, unsigned int po
 	/*
 	 * Currently copy_regset_to_user() starts from pos 0:
 	 */
-	if (unlikely(pos != 0))
+	if (unlikely(offset_start != 0))
 		return -EFAULT;
 
 	/*
@@ -972,7 +972,7 @@ int copy_xstate_to_kernel(void *kbuf, struct xregs_state *xsave, unsigned int po
 	offset = offsetof(struct xregs_state, header);
 	size = sizeof(header);
 
-	ret = __copy_xstate_to_kernel(kbuf, &header, offset, size, count);
+	ret = __copy_xstate_to_kernel(kbuf, &header, offset, size, size_total);
 	if (ret)
 		return ret;
 
@@ -986,11 +986,11 @@ int copy_xstate_to_kernel(void *kbuf, struct xregs_state *xsave, unsigned int po
 			offset = xstate_offsets[i];
 			size = xstate_sizes[i];
 
-			ret = __copy_xstate_to_kernel(kbuf, src, offset, size, count);
+			ret = __copy_xstate_to_kernel(kbuf, src, offset, size, size_total);
 			if (ret)
 				return ret;
 
-			if (offset + size >= count)
+			if (offset + size >= size_total)
 				break;
 		}
 
@@ -1002,7 +1002,7 @@ int copy_xstate_to_kernel(void *kbuf, struct xregs_state *xsave, unsigned int po
 	offset = offsetof(struct fxregs_state, sw_reserved);
 	size = sizeof(xstate_fx_sw_bytes);
 
-	ret = __copy_xstate_to_kernel(kbuf, xstate_fx_sw_bytes, offset, size, count);
+	ret = __copy_xstate_to_kernel(kbuf, xstate_fx_sw_bytes, offset, size, size_total);
 	if (ret)
 		return ret;
 
@@ -1010,15 +1010,15 @@ int copy_xstate_to_kernel(void *kbuf, struct xregs_state *xsave, unsigned int po
 }
 
 static inline int
-__copy_xstate_to_user(void __user *ubuf, const void *data, unsigned int pos, unsigned int count, int end_pos)
+__copy_xstate_to_user(void __user *ubuf, const void *data, unsigned int offset, unsigned int size, int size_total)
 {
-	if (!count)
+	if (!size)
 		return 0;
 
-	if (end_pos < 0 || pos < end_pos) {
-		unsigned int copy = end_pos < 0 ? count : min(count, end_pos - pos);
+	if (size_total < 0 || offset < size_total) {
+		unsigned int copy = size_total < 0 ? size : min(size, size_total - offset);
 
-		if (__copy_to_user(ubuf + pos, data, copy))
+		if (__copy_to_user(ubuf + offset, data, copy))
 			return -EFAULT;
 	}
 	return 0;
@@ -1030,7 +1030,7 @@ __copy_xstate_to_user(void __user *ubuf, const void *data, unsigned int pos, uns
  * zero. This is called from xstateregs_get() and there we check the CPU
  * has XSAVES.
  */
-int copy_xstate_to_user(void __user *ubuf, struct xregs_state *xsave, unsigned int pos, unsigned int count)
+int copy_xstate_to_user(void __user *ubuf, struct xregs_state *xsave, unsigned int offset_start, unsigned int size_total)
 {
 	unsigned int offset, size;
 	int ret, i;
@@ -1039,7 +1039,7 @@ int copy_xstate_to_user(void __user *ubuf, struct xregs_state *xsave, unsigned i
 	/*
 	 * Currently copy_regset_to_user() starts from pos 0:
 	 */
-	if (unlikely(pos != 0))
+	if (unlikely(offset_start != 0))
 		return -EFAULT;
 
 	/*
@@ -1055,7 +1055,7 @@ int copy_xstate_to_user(void __user *ubuf, struct xregs_state *xsave, unsigned i
 	offset = offsetof(struct xregs_state, header);
 	size = sizeof(header);
 
-	ret = __copy_xstate_to_user(ubuf, &header, offset, size, count);
+	ret = __copy_xstate_to_user(ubuf, &header, offset, size, size_total);
 	if (ret)
 		return ret;
 
@@ -1069,11 +1069,11 @@ int copy_xstate_to_user(void __user *ubuf, struct xregs_state *xsave, unsigned i
 			offset = xstate_offsets[i];
 			size = xstate_sizes[i];
 
-			ret = __copy_xstate_to_user(ubuf, src, offset, size, count);
+			ret = __copy_xstate_to_user(ubuf, src, offset, size, size_total);
 			if (ret)
 				return ret;
 
-			if (offset + size >= count)
+			if (offset + size >= size_total)
 				break;
 		}
 
@@ -1085,7 +1085,7 @@ int copy_xstate_to_user(void __user *ubuf, struct xregs_state *xsave, unsigned i
 	offset = offsetof(struct fxregs_state, sw_reserved);
 	size = sizeof(xstate_fx_sw_bytes);
 
-	ret = __copy_xstate_to_user(ubuf, xstate_fx_sw_bytes, offset, size, count);
+	ret = __copy_xstate_to_user(ubuf, xstate_fx_sw_bytes, offset, size, size_total);
 	if (ret)
 		return ret;
 

  parent reply	other threads:[~2017-09-26  8:32 UTC|newest]

Thread overview: 94+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-23 12:59 [PATCH 00/33] x86 FPU fixes and cleanups for v4.14 Ingo Molnar
2017-09-23 12:59 ` [PATCH 01/33] x86/fpu: Rename copyin_to_xsaves()/copyout_from_xsaves() to copy_user_to_xstate()/copy_xstate_to_user() Ingo Molnar
2017-09-26  8:21   ` [tip:x86/fpu] " tip-bot for Ingo Molnar
2017-09-23 12:59 ` [PATCH 02/33] x86/fpu: Split copy_xstate_to_user() into copy_xstate_to_kernel() & copy_xstate_to_user() Ingo Molnar
2017-09-26  8:22   ` [tip:x86/fpu] " tip-bot for Ingo Molnar
2017-09-23 12:59 ` [PATCH 03/33] x86/fpu: Remove 'ubuf' parameter from the copy_xstate_to_kernel() APIs Ingo Molnar
2017-09-26  8:22   ` [tip:x86/fpu] " tip-bot for Ingo Molnar
2017-09-23 12:59 ` [PATCH 04/33] x86/fpu: Remove 'kbuf' parameter from the copy_xstate_to_user() APIs Ingo Molnar
2017-09-26  8:23   ` [tip:x86/fpu] " tip-bot for Ingo Molnar
2017-09-23 12:59 ` [PATCH 05/33] x86/fpu: Clean up parameter order in the copy_xstate_to_*() APIs Ingo Molnar
2017-09-26  8:23   ` [tip:x86/fpu] " tip-bot for Ingo Molnar
2017-09-23 12:59 ` [PATCH 06/33] x86/fpu: Clean up the parameter definitions of copy_xstate_to_*() Ingo Molnar
2017-09-26  8:23   ` [tip:x86/fpu] " tip-bot for Ingo Molnar
2017-09-23 12:59 ` [PATCH 07/33] x86/fpu: Remove the 'start_pos' parameter from the __copy_xstate_to_*() functions Ingo Molnar
2017-09-26  8:24   ` [tip:x86/fpu] " tip-bot for Ingo Molnar
2017-09-23 12:59 ` [PATCH 08/33] x86/fpu: Clarify parameter names in the copy_xstate_to_*() methods Ingo Molnar
2017-09-25 19:56   ` Thomas Gleixner
2017-09-25 20:01     ` Thomas Gleixner
2017-09-26  8:24   ` tip-bot for Ingo Molnar [this message]
2017-09-23 12:59 ` [PATCH 09/33] x86/fpu: Change 'size_total' parameter to unsigned and standardize the size checks in copy_xstate_to_*() Ingo Molnar
2017-09-26  8:25   ` [tip:x86/fpu] " tip-bot for Ingo Molnar
2017-09-23 12:59 ` [PATCH 10/33] x86/fpu: Simplify __copy_xstate_to_kernel() return values Ingo Molnar
2017-09-26  8:25   ` [tip:x86/fpu] " tip-bot for Ingo Molnar
2017-09-23 12:59 ` [PATCH 11/33] x86/fpu: Split copy_user_to_xstate() into copy_kernel_to_xstate() & copy_user_to_xstate() Ingo Molnar
2017-09-26  8:25   ` [tip:x86/fpu] " tip-bot for Ingo Molnar
2017-09-23 12:59 ` [PATCH 12/33] x86/fpu: Remove 'ubuf' parameter from the copy_kernel_to_xstate() API Ingo Molnar
2017-09-26  8:26   ` [tip:x86/fpu] " tip-bot for Ingo Molnar
2017-09-23 12:59 ` [PATCH 13/33] x86/fpu: Remove 'kbuf' parameter from the copy_user_to_xstate() API Ingo Molnar
2017-09-26  8:26   ` [tip:x86/fpu] " tip-bot for Ingo Molnar
2017-09-23 12:59 ` [PATCH 14/33] x86/fpu: Flip the parameter order in copy_*_to_xstate() Ingo Molnar
2017-09-26  8:27   ` [tip:x86/fpu] " tip-bot for Ingo Molnar
2017-09-23 12:59 ` [PATCH 15/33] x86/fpu: Simplify fpu->fpregs_active use Ingo Molnar
2017-09-26  8:27   ` [tip:x86/fpu] " tip-bot for Ingo Molnar
2017-09-23 12:59 ` [PATCH 16/33] x86/fpu: Make the fpu state change in fpu__clear() scheduler-atomic Ingo Molnar
2017-09-26  8:27   ` [tip:x86/fpu] " tip-bot for Ingo Molnar
2017-09-23 13:00 ` [PATCH 17/33] x86/fpu: Split the state handling in fpu__drop() Ingo Molnar
2017-09-26  8:28   ` [tip:x86/fpu] " tip-bot for Ingo Molnar
2017-09-23 13:00 ` [PATCH 18/33] x86/fpu: Change fpu->fpregs_active users to fpu->fpstate_active Ingo Molnar
2017-09-26  8:28   ` [tip:x86/fpu] " tip-bot for Ingo Molnar
2017-09-23 13:00 ` [PATCH 19/33] x86/fpu: Decouple fpregs_activate()/fpregs_deactivate() from fpu->fpregs_active Ingo Molnar
2017-09-26  8:28   ` [tip:x86/fpu] " tip-bot for Ingo Molnar
2017-09-23 13:00 ` [PATCH 20/33] x86/fpu: Remove struct fpu::fpregs_active Ingo Molnar
2017-09-26  8:29   ` [tip:x86/fpu] " tip-bot for Ingo Molnar
2017-09-23 13:00 ` [PATCH 21/33] x86/fpu: Add FPU state copying quirk to handle XRSTOR failure on Intel Skylake CPUs Ingo Molnar
2017-09-26  8:29   ` [tip:x86/fpu] " tip-bot for Rik van Riel
2017-09-23 13:00 ` [PATCH 22/33] x86/fpu: Fix boolreturn.cocci warnings Ingo Molnar
2017-09-26  8:30   ` [tip:x86/fpu] " tip-bot for kbuild test robot
2017-09-23 13:00 ` [PATCH 23/33] x86/fpu: Turn WARN_ON() in context switch into WARN_ON_FPU() Ingo Molnar
2017-09-26  8:30   ` [tip:x86/fpu] " tip-bot for Andi Kleen
2017-09-23 13:00 ` [PATCH 24/33] x86/fpu: Don't let userspace set bogus xcomp_bv Ingo Molnar
2017-09-26  8:30   ` [tip:x86/fpu] " tip-bot for Eric Biggers
2017-09-23 13:00 ` [PATCH 25/33] x86/fpu: Tighten validation of user-supplied xstate_header Ingo Molnar
2017-09-23 13:00 ` [PATCH 26/33] x86/fpu: Reinitialize FPU registers if restoring FPU state fails Ingo Molnar
2017-09-26  8:31   ` [tip:x86/fpu] " tip-bot for Eric Biggers
2017-09-23 13:00 ` [PATCH 27/33] x86/fpu: Simplify fpu__activate_fpstate_read() Ingo Molnar
2017-09-26  8:31   ` [tip:x86/fpu] x86/fpu: Fix fpu__activate_fpstate_read() and update comments tip-bot for Ingo Molnar
2017-09-23 13:00 ` [PATCH 28/33] x86/fpu: Remove fpu__current_fpstate_write_begin/end() Ingo Molnar
2017-09-26  8:32   ` [tip:x86/fpu] " tip-bot for Ingo Molnar
2017-09-23 13:00 ` [PATCH 29/33] x86/fpu: Rename fpu::fpstate_active to fpu::initialized Ingo Molnar
2017-09-26  8:32   ` [tip:x86/fpu] " tip-bot for Ingo Molnar
2017-09-23 13:00 ` [PATCH 30/33] x86/fpu: Fix stale comments about lazy FPU logic Ingo Molnar
2017-09-26  8:32   ` [tip:x86/fpu] " tip-bot for Ingo Molnar
2017-09-23 13:00 ` [PATCH 31/33] x86/fpu: Simplify and speed up fpu__copy() Ingo Molnar
2017-09-26  8:33   ` [tip:x86/fpu] " tip-bot for Ingo Molnar
2017-09-23 13:00 ` [PATCH 32/33] x86/fpu: Rename fpu__activate_curr() to fpu__initialize() Ingo Molnar
2017-09-26  8:33   ` [tip:x86/fpu] " tip-bot for Ingo Molnar
2017-09-23 13:00 ` [PATCH 33/33] x86/fpu: Rename fpu__activate_fpstate_read/write() to fpu__read/write() Ingo Molnar
2017-09-23 13:02 ` [PATCH 00/33] x86 FPU fixes and cleanups for v4.14 Ingo Molnar
2017-09-23 15:03   ` Juergen Gross
2017-09-23 23:27     ` Ingo Molnar
  -- strict thread matches above, loose matches on Subject: below --
2017-09-22 17:41 [PATCH v4 0/3] x86/fpu: prevent leaking FPU registers via invalid FPU state Eric Biggers
2017-09-22 17:41 ` [PATCH v4 1/3] x86/fpu: don't let userspace set bogus xcomp_bv Eric Biggers
2017-09-22 17:41 ` [PATCH v4 2/3] x86/fpu: tighten validation of user-supplied xstate_header Eric Biggers
2017-09-22 17:41 ` [PATCH v4 3/3] x86/fpu: reinitialize FPU registers if restoring FPU state fails Eric Biggers
2017-09-23  9:09 ` [PATCH v4 0/3] x86/fpu: prevent leaking FPU registers via invalid FPU state Ingo Molnar
2017-03-29  6:26 [PATCH] x86/fpu: Turn WARN_ON in context switch into WARN_ON_FPU Andi Kleen
2017-04-24 21:00 ` [tip:perf/core] x86/fpu: Turn WARN_ON() in context switch into WARN_ON_FPU() tip-bot for Andi Kleen
2017-03-06  0:45 [tip:WIP.x86/fpu 31/31] arch/x86/kernel/fpu/xstate.c:931:9-10: WARNING: return of 0/1 in function 'xfeatures_mxcsr_quirk' with return type bool kbuild test robot
2017-03-06  0:45 ` [PATCH] x86/fpu: fix boolreturn.cocci warnings kbuild test robot
2017-03-07  7:23   ` Ingo Molnar
2017-03-07  8:33     ` Thomas Gleixner
2017-03-07  9:01       ` Ingo Molnar
2017-03-07 12:01         ` Joe Perches
2017-04-24 20:54   ` [tip:perf/core] x86/fpu: Fix " tip-bot for kbuild test robot
2017-02-09 23:43 [PATCH v2] x86/fpu: copy MXCSR & MXCSR_FLAGS with SSE/YMM state Rik van Riel
2017-02-10  0:02 ` Borislav Petkov
2017-02-10  0:51   ` Rik van Riel
2017-02-10  8:00     ` Ingo Molnar
2017-02-10 13:54       ` [PATCH v3] " Rik van Riel
2017-02-11 10:02         ` Ingo Molnar
2017-04-24 20:54         ` [tip:perf/core] x86/fpu: Add FPU state copying quirk to handle XRSTOR failure on Intel Skylake CPUs tip-bot for Rik van Riel
2017-02-10  0:45 ` [PATCH v2] x86/fpu: copy MXCSR & MXCSR_FLAGS with SSE/YMM state Yu-cheng Yu
2017-02-10  1:00   ` Rik van Riel
2017-02-10 17:18     ` Yu-cheng Yu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tip-56583c9a1400fe1935edd55b24b4fbbc779b59cb@git.kernel.org \
    --to=tipbot@zytor.com \
    --cc=akpm@linux-foundation.org \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=ebiggers3@gmail.com \
    --cc=fenghua.yu@intel.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=luto@kernel.org \
    --cc=mingo@kernel.org \
    --cc=oleg@redhat.com \
    --cc=peterz@infradead.org \
    --cc=riel@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    --cc=yu-cheng.yu@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).