* [PATCH 1/2] tile: fix put_user sparse errors
@ 2015-01-13 19:39 Chris Metcalf
2015-01-13 19:39 ` Chris Metcalf
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Chris Metcalf @ 2015-01-13 19:39 UTC (permalink / raw)
To: linux-kernel; +Cc: Arnd Bergmann, linux-arch, Michael S. Tsirkin
Use x86's __inttype macro instead of using the typeof(x-x) trick to
generate a suitable integer size type. This avoids a sparse warning
when examining the x-x type with a bitwise type.
Signed-off-by: Chris Metcalf <cmetcalf@ezchip.com>
---
arch/tile/include/asm/uaccess.h | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
index b6cde3209b96..b81b24a8489b 100644
--- a/arch/tile/include/asm/uaccess.h
+++ b/arch/tile/include/asm/uaccess.h
@@ -114,14 +114,14 @@ struct exception_table_entry {
extern int fixup_exception(struct pt_regs *regs);
/*
+ * This is a type: either unsigned long, if the argument fits into
+ * that type, or otherwise unsigned long long.
+ */
+#define __inttype(x) \
+ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
+
+/*
* Support macros for __get_user().
- *
- * Implementation note: The "case 8" logic of casting to the type of
- * the result of subtracting the value from itself is basically a way
- * of keeping all integer types the same, but casting any pointers to
- * ptrdiff_t, i.e. also an integer type. This way there are no
- * questionable casts seen by the compiler on an ILP32 platform.
- *
* Note that __get_user() and __put_user() assume proper alignment.
*/
@@ -178,7 +178,7 @@ extern int fixup_exception(struct pt_regs *regs);
"9:" \
: "=r" (ret), "=r" (__a), "=&r" (__b) \
: "r" (ptr), "i" (-EFAULT)); \
- (x) = (__typeof(x))(__typeof((x)-(x))) \
+ (x) = (__force __typeof(x))(__inttype(x)) \
(((u64)__hi32(__a, __b) << 32) | \
__lo32(__a, __b)); \
})
@@ -246,7 +246,7 @@ extern int __get_user_bad(void)
#define __put_user_4(x, ptr, ret) __put_user_asm(sw, x, ptr, ret)
#define __put_user_8(x, ptr, ret) \
({ \
- u64 __x = (__typeof((x)-(x)))(x); \
+ u64 __x = (__force __inttype(x))(x); \
int __lo = (int) __x, __hi = (int) (__x >> 32); \
asm volatile("1: { sw %1, %2; addi %0, %1, 4 }\n" \
"2: { sw %0, %3; movei %0, 0 }\n" \
--
2.1.2
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 1/2] tile: fix put_user sparse errors
2015-01-13 19:39 [PATCH 1/2] tile: fix put_user sparse errors Chris Metcalf
@ 2015-01-13 19:39 ` Chris Metcalf
2015-01-13 19:41 ` [PATCH 2/2] tile: enable sparse checks for get/put_user Chris Metcalf
2015-01-13 22:29 ` [PATCH 1/2] tile: fix put_user sparse errors Michael S. Tsirkin
2 siblings, 0 replies; 7+ messages in thread
From: Chris Metcalf @ 2015-01-13 19:39 UTC (permalink / raw)
To: linux-kernel; +Cc: Arnd Bergmann, linux-arch, Michael S. Tsirkin
Use x86's __inttype macro instead of using the typeof(x-x) trick to
generate a suitable integer size type. This avoids a sparse warning
when examining the x-x type with a bitwise type.
Signed-off-by: Chris Metcalf <cmetcalf@ezchip.com>
---
arch/tile/include/asm/uaccess.h | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
index b6cde3209b96..b81b24a8489b 100644
--- a/arch/tile/include/asm/uaccess.h
+++ b/arch/tile/include/asm/uaccess.h
@@ -114,14 +114,14 @@ struct exception_table_entry {
extern int fixup_exception(struct pt_regs *regs);
/*
+ * This is a type: either unsigned long, if the argument fits into
+ * that type, or otherwise unsigned long long.
+ */
+#define __inttype(x) \
+ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
+
+/*
* Support macros for __get_user().
- *
- * Implementation note: The "case 8" logic of casting to the type of
- * the result of subtracting the value from itself is basically a way
- * of keeping all integer types the same, but casting any pointers to
- * ptrdiff_t, i.e. also an integer type. This way there are no
- * questionable casts seen by the compiler on an ILP32 platform.
- *
* Note that __get_user() and __put_user() assume proper alignment.
*/
@@ -178,7 +178,7 @@ extern int fixup_exception(struct pt_regs *regs);
"9:" \
: "=r" (ret), "=r" (__a), "=&r" (__b) \
: "r" (ptr), "i" (-EFAULT)); \
- (x) = (__typeof(x))(__typeof((x)-(x))) \
+ (x) = (__force __typeof(x))(__inttype(x)) \
(((u64)__hi32(__a, __b) << 32) | \
__lo32(__a, __b)); \
})
@@ -246,7 +246,7 @@ extern int __get_user_bad(void)
#define __put_user_4(x, ptr, ret) __put_user_asm(sw, x, ptr, ret)
#define __put_user_8(x, ptr, ret) \
({ \
- u64 __x = (__typeof((x)-(x)))(x); \
+ u64 __x = (__force __inttype(x))(x); \
int __lo = (int) __x, __hi = (int) (__x >> 32); \
asm volatile("1: { sw %1, %2; addi %0, %1, 4 }\n" \
"2: { sw %0, %3; movei %0, 0 }\n" \
--
2.1.2
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/2] tile: enable sparse checks for get/put_user
2015-01-13 19:39 [PATCH 1/2] tile: fix put_user sparse errors Chris Metcalf
2015-01-13 19:39 ` Chris Metcalf
@ 2015-01-13 19:41 ` Chris Metcalf
2015-01-13 19:41 ` Chris Metcalf
2015-01-13 22:29 ` Michael S. Tsirkin
2015-01-13 22:29 ` [PATCH 1/2] tile: fix put_user sparse errors Michael S. Tsirkin
2 siblings, 2 replies; 7+ messages in thread
From: Chris Metcalf @ 2015-01-13 19:41 UTC (permalink / raw)
To: linux-kernel; +Cc: Arnd Bergmann, linux-arch, Michael S. Tsirkin
Add an extra intermediate variable to __get_user and __put_user
to give sparse an opportunity to detect mismatches.
Signed-off-by: Chris Metcalf <cmetcalf@ezchip.com>
---
arch/tile/include/asm/uaccess.h | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
index b81b24a8489b..f41cb53cf645 100644
--- a/arch/tile/include/asm/uaccess.h
+++ b/arch/tile/include/asm/uaccess.h
@@ -210,14 +210,16 @@ extern int __get_user_bad(void)
#define __get_user(x, ptr) \
({ \
int __ret; \
+ typeof(x) _x; \
__chk_user_ptr(ptr); \
switch (sizeof(*(ptr))) { \
- case 1: __get_user_1(x, ptr, __ret); break; \
- case 2: __get_user_2(x, ptr, __ret); break; \
- case 4: __get_user_4(x, ptr, __ret); break; \
- case 8: __get_user_8(x, ptr, __ret); break; \
+ case 1: __get_user_1(_x, ptr, __ret); break; \
+ case 2: __get_user_2(_x, ptr, __ret); break; \
+ case 4: __get_user_4(_x, ptr, __ret); break; \
+ case 8: __get_user_8(_x, ptr, __ret); break; \
default: __ret = __get_user_bad(); break; \
} \
+ (x) = (typeof(*(ptr))) _x; \
__ret; \
})
@@ -289,12 +291,13 @@ extern int __put_user_bad(void)
#define __put_user(x, ptr) \
({ \
int __ret; \
+ typeof(*(ptr)) _x = (x); \
__chk_user_ptr(ptr); \
switch (sizeof(*(ptr))) { \
- case 1: __put_user_1(x, ptr, __ret); break; \
- case 2: __put_user_2(x, ptr, __ret); break; \
- case 4: __put_user_4(x, ptr, __ret); break; \
- case 8: __put_user_8(x, ptr, __ret); break; \
+ case 1: __put_user_1(_x, ptr, __ret); break; \
+ case 2: __put_user_2(_x, ptr, __ret); break; \
+ case 4: __put_user_4(_x, ptr, __ret); break; \
+ case 8: __put_user_8(_x, ptr, __ret); break; \
default: __ret = __put_user_bad(); break; \
} \
__ret; \
--
2.1.2
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/2] tile: enable sparse checks for get/put_user
2015-01-13 19:41 ` [PATCH 2/2] tile: enable sparse checks for get/put_user Chris Metcalf
@ 2015-01-13 19:41 ` Chris Metcalf
2015-01-13 22:29 ` Michael S. Tsirkin
1 sibling, 0 replies; 7+ messages in thread
From: Chris Metcalf @ 2015-01-13 19:41 UTC (permalink / raw)
To: linux-kernel; +Cc: Arnd Bergmann, linux-arch, Michael S. Tsirkin
Add an extra intermediate variable to __get_user and __put_user
to give sparse an opportunity to detect mismatches.
Signed-off-by: Chris Metcalf <cmetcalf@ezchip.com>
---
arch/tile/include/asm/uaccess.h | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
index b81b24a8489b..f41cb53cf645 100644
--- a/arch/tile/include/asm/uaccess.h
+++ b/arch/tile/include/asm/uaccess.h
@@ -210,14 +210,16 @@ extern int __get_user_bad(void)
#define __get_user(x, ptr) \
({ \
int __ret; \
+ typeof(x) _x; \
__chk_user_ptr(ptr); \
switch (sizeof(*(ptr))) { \
- case 1: __get_user_1(x, ptr, __ret); break; \
- case 2: __get_user_2(x, ptr, __ret); break; \
- case 4: __get_user_4(x, ptr, __ret); break; \
- case 8: __get_user_8(x, ptr, __ret); break; \
+ case 1: __get_user_1(_x, ptr, __ret); break; \
+ case 2: __get_user_2(_x, ptr, __ret); break; \
+ case 4: __get_user_4(_x, ptr, __ret); break; \
+ case 8: __get_user_8(_x, ptr, __ret); break; \
default: __ret = __get_user_bad(); break; \
} \
+ (x) = (typeof(*(ptr))) _x; \
__ret; \
})
@@ -289,12 +291,13 @@ extern int __put_user_bad(void)
#define __put_user(x, ptr) \
({ \
int __ret; \
+ typeof(*(ptr)) _x = (x); \
__chk_user_ptr(ptr); \
switch (sizeof(*(ptr))) { \
- case 1: __put_user_1(x, ptr, __ret); break; \
- case 2: __put_user_2(x, ptr, __ret); break; \
- case 4: __put_user_4(x, ptr, __ret); break; \
- case 8: __put_user_8(x, ptr, __ret); break; \
+ case 1: __put_user_1(_x, ptr, __ret); break; \
+ case 2: __put_user_2(_x, ptr, __ret); break; \
+ case 4: __put_user_4(_x, ptr, __ret); break; \
+ case 8: __put_user_8(_x, ptr, __ret); break; \
default: __ret = __put_user_bad(); break; \
} \
__ret; \
--
2.1.2
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] tile: fix put_user sparse errors
2015-01-13 19:39 [PATCH 1/2] tile: fix put_user sparse errors Chris Metcalf
2015-01-13 19:39 ` Chris Metcalf
2015-01-13 19:41 ` [PATCH 2/2] tile: enable sparse checks for get/put_user Chris Metcalf
@ 2015-01-13 22:29 ` Michael S. Tsirkin
2015-01-13 22:29 ` Michael S. Tsirkin
2 siblings, 1 reply; 7+ messages in thread
From: Michael S. Tsirkin @ 2015-01-13 22:29 UTC (permalink / raw)
To: Chris Metcalf; +Cc: linux-kernel, Arnd Bergmann, linux-arch
On Tue, Jan 13, 2015 at 02:39:05PM -0500, Chris Metcalf wrote:
> Use x86's __inttype macro instead of using the typeof(x-x) trick to
> generate a suitable integer size type. This avoids a sparse warning
> when examining the x-x type with a bitwise type.
>
> Signed-off-by: Chris Metcalf <cmetcalf@ezchip.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
> ---
> arch/tile/include/asm/uaccess.h | 18 +++++++++---------
> 1 file changed, 9 insertions(+), 9 deletions(-)
>
> diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
> index b6cde3209b96..b81b24a8489b 100644
> --- a/arch/tile/include/asm/uaccess.h
> +++ b/arch/tile/include/asm/uaccess.h
> @@ -114,14 +114,14 @@ struct exception_table_entry {
> extern int fixup_exception(struct pt_regs *regs);
>
> /*
> + * This is a type: either unsigned long, if the argument fits into
> + * that type, or otherwise unsigned long long.
> + */
> +#define __inttype(x) \
> + __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
> +
> +/*
> * Support macros for __get_user().
> - *
> - * Implementation note: The "case 8" logic of casting to the type of
> - * the result of subtracting the value from itself is basically a way
> - * of keeping all integer types the same, but casting any pointers to
> - * ptrdiff_t, i.e. also an integer type. This way there are no
> - * questionable casts seen by the compiler on an ILP32 platform.
> - *
> * Note that __get_user() and __put_user() assume proper alignment.
> */
>
> @@ -178,7 +178,7 @@ extern int fixup_exception(struct pt_regs *regs);
> "9:" \
> : "=r" (ret), "=r" (__a), "=&r" (__b) \
> : "r" (ptr), "i" (-EFAULT)); \
> - (x) = (__typeof(x))(__typeof((x)-(x))) \
> + (x) = (__force __typeof(x))(__inttype(x)) \
> (((u64)__hi32(__a, __b) << 32) | \
> __lo32(__a, __b)); \
> })
> @@ -246,7 +246,7 @@ extern int __get_user_bad(void)
> #define __put_user_4(x, ptr, ret) __put_user_asm(sw, x, ptr, ret)
> #define __put_user_8(x, ptr, ret) \
> ({ \
> - u64 __x = (__typeof((x)-(x)))(x); \
> + u64 __x = (__force __inttype(x))(x); \
> int __lo = (int) __x, __hi = (int) (__x >> 32); \
> asm volatile("1: { sw %1, %2; addi %0, %1, 4 }\n" \
> "2: { sw %0, %3; movei %0, 0 }\n" \
> --
> 2.1.2
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] tile: fix put_user sparse errors
2015-01-13 22:29 ` [PATCH 1/2] tile: fix put_user sparse errors Michael S. Tsirkin
@ 2015-01-13 22:29 ` Michael S. Tsirkin
0 siblings, 0 replies; 7+ messages in thread
From: Michael S. Tsirkin @ 2015-01-13 22:29 UTC (permalink / raw)
To: Chris Metcalf; +Cc: linux-kernel, Arnd Bergmann, linux-arch
On Tue, Jan 13, 2015 at 02:39:05PM -0500, Chris Metcalf wrote:
> Use x86's __inttype macro instead of using the typeof(x-x) trick to
> generate a suitable integer size type. This avoids a sparse warning
> when examining the x-x type with a bitwise type.
>
> Signed-off-by: Chris Metcalf <cmetcalf@ezchip.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
> ---
> arch/tile/include/asm/uaccess.h | 18 +++++++++---------
> 1 file changed, 9 insertions(+), 9 deletions(-)
>
> diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
> index b6cde3209b96..b81b24a8489b 100644
> --- a/arch/tile/include/asm/uaccess.h
> +++ b/arch/tile/include/asm/uaccess.h
> @@ -114,14 +114,14 @@ struct exception_table_entry {
> extern int fixup_exception(struct pt_regs *regs);
>
> /*
> + * This is a type: either unsigned long, if the argument fits into
> + * that type, or otherwise unsigned long long.
> + */
> +#define __inttype(x) \
> + __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
> +
> +/*
> * Support macros for __get_user().
> - *
> - * Implementation note: The "case 8" logic of casting to the type of
> - * the result of subtracting the value from itself is basically a way
> - * of keeping all integer types the same, but casting any pointers to
> - * ptrdiff_t, i.e. also an integer type. This way there are no
> - * questionable casts seen by the compiler on an ILP32 platform.
> - *
> * Note that __get_user() and __put_user() assume proper alignment.
> */
>
> @@ -178,7 +178,7 @@ extern int fixup_exception(struct pt_regs *regs);
> "9:" \
> : "=r" (ret), "=r" (__a), "=&r" (__b) \
> : "r" (ptr), "i" (-EFAULT)); \
> - (x) = (__typeof(x))(__typeof((x)-(x))) \
> + (x) = (__force __typeof(x))(__inttype(x)) \
> (((u64)__hi32(__a, __b) << 32) | \
> __lo32(__a, __b)); \
> })
> @@ -246,7 +246,7 @@ extern int __get_user_bad(void)
> #define __put_user_4(x, ptr, ret) __put_user_asm(sw, x, ptr, ret)
> #define __put_user_8(x, ptr, ret) \
> ({ \
> - u64 __x = (__typeof((x)-(x)))(x); \
> + u64 __x = (__force __inttype(x))(x); \
> int __lo = (int) __x, __hi = (int) (__x >> 32); \
> asm volatile("1: { sw %1, %2; addi %0, %1, 4 }\n" \
> "2: { sw %0, %3; movei %0, 0 }\n" \
> --
> 2.1.2
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] tile: enable sparse checks for get/put_user
2015-01-13 19:41 ` [PATCH 2/2] tile: enable sparse checks for get/put_user Chris Metcalf
2015-01-13 19:41 ` Chris Metcalf
@ 2015-01-13 22:29 ` Michael S. Tsirkin
1 sibling, 0 replies; 7+ messages in thread
From: Michael S. Tsirkin @ 2015-01-13 22:29 UTC (permalink / raw)
To: Chris Metcalf; +Cc: linux-kernel, Arnd Bergmann, linux-arch
On Tue, Jan 13, 2015 at 02:41:20PM -0500, Chris Metcalf wrote:
> Add an extra intermediate variable to __get_user and __put_user
> to give sparse an opportunity to detect mismatches.
>
> Signed-off-by: Chris Metcalf <cmetcalf@ezchip.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
> ---
> arch/tile/include/asm/uaccess.h | 19 +++++++++++--------
> 1 file changed, 11 insertions(+), 8 deletions(-)
>
> diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
> index b81b24a8489b..f41cb53cf645 100644
> --- a/arch/tile/include/asm/uaccess.h
> +++ b/arch/tile/include/asm/uaccess.h
> @@ -210,14 +210,16 @@ extern int __get_user_bad(void)
> #define __get_user(x, ptr) \
> ({ \
> int __ret; \
> + typeof(x) _x; \
> __chk_user_ptr(ptr); \
> switch (sizeof(*(ptr))) { \
> - case 1: __get_user_1(x, ptr, __ret); break; \
> - case 2: __get_user_2(x, ptr, __ret); break; \
> - case 4: __get_user_4(x, ptr, __ret); break; \
> - case 8: __get_user_8(x, ptr, __ret); break; \
> + case 1: __get_user_1(_x, ptr, __ret); break; \
> + case 2: __get_user_2(_x, ptr, __ret); break; \
> + case 4: __get_user_4(_x, ptr, __ret); break; \
> + case 8: __get_user_8(_x, ptr, __ret); break; \
> default: __ret = __get_user_bad(); break; \
> } \
> + (x) = (typeof(*(ptr))) _x; \
> __ret; \
> })
>
> @@ -289,12 +291,13 @@ extern int __put_user_bad(void)
> #define __put_user(x, ptr) \
> ({ \
> int __ret; \
> + typeof(*(ptr)) _x = (x); \
> __chk_user_ptr(ptr); \
> switch (sizeof(*(ptr))) { \
> - case 1: __put_user_1(x, ptr, __ret); break; \
> - case 2: __put_user_2(x, ptr, __ret); break; \
> - case 4: __put_user_4(x, ptr, __ret); break; \
> - case 8: __put_user_8(x, ptr, __ret); break; \
> + case 1: __put_user_1(_x, ptr, __ret); break; \
> + case 2: __put_user_2(_x, ptr, __ret); break; \
> + case 4: __put_user_4(_x, ptr, __ret); break; \
> + case 8: __put_user_8(_x, ptr, __ret); break; \
> default: __ret = __put_user_bad(); break; \
> } \
> __ret; \
> --
> 2.1.2
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2015-01-13 22:29 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-13 19:39 [PATCH 1/2] tile: fix put_user sparse errors Chris Metcalf
2015-01-13 19:39 ` Chris Metcalf
2015-01-13 19:41 ` [PATCH 2/2] tile: enable sparse checks for get/put_user Chris Metcalf
2015-01-13 19:41 ` Chris Metcalf
2015-01-13 22:29 ` Michael S. Tsirkin
2015-01-13 22:29 ` [PATCH 1/2] tile: fix put_user sparse errors Michael S. Tsirkin
2015-01-13 22:29 ` Michael S. Tsirkin
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).