diff mbox

[2/3] xen/err: Support an optional per-arch slide for the error region

Message ID 1477997170-7795-3-git-send-email-andrew.cooper3@citrix.com (mailing list archive)
State New, archived
Headers show

Commit Message

Andrew Cooper Nov. 1, 2016, 10:46 a.m. UTC
No functional change.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
---
 xen/include/xen/err.h | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

Comments

Jan Beulich Nov. 2, 2016, 11:37 a.m. UTC | #1
>>> On 01.11.16 at 11:46, <andrew.cooper3@citrix.com> wrote:
> --- a/xen/include/xen/err.h
> +++ b/xen/include/xen/err.h
> @@ -15,19 +15,28 @@
>   */
>  #define MAX_ERRNO	4095
>  
> +/*
> + * Individual architectures may wish to slide the error region away from its
> + * default position at the very top of virtual address space.  (e.g. if Xen
> + * doesn't own the range).
> + */
> +#ifndef ARCH_ERR_PTR_SLIDE
> +#define ARCH_ERR_PTR_SLIDE 0
> +#endif
> +
>  static inline bool IS_ERR_VALUE(unsigned long x)
>  {
> -	return x >= (unsigned long)-MAX_ERRNO;
> +	return (x + ARCH_ERR_PTR_SLIDE) >= (unsigned long)-MAX_ERRNO;
>  }
>  
>  static inline void *__must_check ERR_PTR(long error)
>  {
> -	return (void *)error;
> +	return (void *)((unsigned long)error - ARCH_ERR_PTR_SLIDE);

I don't see the need for the inner cast here and ...

>  }
>  
>  static inline long __must_check PTR_ERR(const void *ptr)
>  {
> -	return (long)ptr;
> +	return (long)((unsigned long)ptr + ARCH_ERR_PTR_SLIDE);

... the outer one here.

And then of course this change is pointless without patch 3, which
I have reservations against (will reply there).

Jan
diff mbox

Patch

diff --git a/xen/include/xen/err.h b/xen/include/xen/err.h
index ef77992..bea7fa3 100644
--- a/xen/include/xen/err.h
+++ b/xen/include/xen/err.h
@@ -15,19 +15,28 @@ 
  */
 #define MAX_ERRNO	4095
 
+/*
+ * Individual architectures may wish to slide the error region away from its
+ * default position at the very top of virtual address space.  (e.g. if Xen
+ * doesn't own the range).
+ */
+#ifndef ARCH_ERR_PTR_SLIDE
+#define ARCH_ERR_PTR_SLIDE 0
+#endif
+
 static inline bool IS_ERR_VALUE(unsigned long x)
 {
-	return x >= (unsigned long)-MAX_ERRNO;
+	return (x + ARCH_ERR_PTR_SLIDE) >= (unsigned long)-MAX_ERRNO;
 }
 
 static inline void *__must_check ERR_PTR(long error)
 {
-	return (void *)error;
+	return (void *)((unsigned long)error - ARCH_ERR_PTR_SLIDE);
 }
 
 static inline long __must_check PTR_ERR(const void *ptr)
 {
-	return (long)ptr;
+	return (long)((unsigned long)ptr + ARCH_ERR_PTR_SLIDE);
 }
 
 static inline bool __must_check IS_ERR(const void *ptr)