Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1213894 > unrolled thread

[PATCH 01/11] tools: Add err.h with ERR_PTR PTR_ERR interface

Started byJiri Olsa <jolsa@kernel.org>
First post2015-08-26 15:50 +0200
Last post2015-08-31 17:30 +0200
Articles 4 — 3 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH 01/11] tools: Add err.h with ERR_PTR PTR_ERR interface Jiri Olsa <jolsa@kernel.org> - 2015-08-26 15:50 +0200
    Re: [PATCH 01/11] tools: Add err.h with ERR_PTR PTR_ERR interface Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-08-28 18:30 +0200
      Re: [PATCH 01/11] tools: Add err.h with ERR_PTR PTR_ERR interface Jiri Olsa <jolsa@redhat.com> - 2015-08-31 09:40 +0200
        Re: [PATCH 01/11] tools: Add err.h with ERR_PTR PTR_ERR interface Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-08-31 17:30 +0200

#1213894 — [PATCH 01/11] tools: Add err.h with ERR_PTR PTR_ERR interface

FromJiri Olsa <jolsa@kernel.org>
Date2015-08-26 15:50 +0200
Subject[PATCH 01/11] tools: Add err.h with ERR_PTR PTR_ERR interface
Message-ID<q1Jft-7l6-39@gated-at.bofh.it>
Adding part of the kernel's <linux/err.h> interface:
  inline void * __must_check ERR_PTR(long error);
  inline long   __must_check PTR_ERR(__force const void *ptr);
  inline bool   __must_check IS_ERR(__force const void *ptr);

it will be used to propagate error through pointers
in following patches.

Link: http://lkml.kernel.org/n/tip-ufgnyf683uab69anmmrabgdf@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/include/linux/err.h | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
 create mode 100644 tools/include/linux/err.h

diff --git a/tools/include/linux/err.h b/tools/include/linux/err.h
new file mode 100644
index 000000000000..2df92df55cfe
--- /dev/null
+++ b/tools/include/linux/err.h
@@ -0,0 +1,28 @@
+#ifndef __TOOLS_LINUX_ERR_H
+#define __TOOLS_LINUX_ERR_H
+
+#include <linux/compiler.h>
+#include <linux/types.h>
+
+#include <asm/errno.h>
+
+#define MAX_ERRNO	4095
+
+#define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
+
+static inline void * __must_check ERR_PTR(long error)
+{
+	return (void *) error;
+}
+
+static inline long __must_check PTR_ERR(__force const void *ptr)
+{
+	return (long) ptr;
+}
+
+static inline bool __must_check IS_ERR(__force const void *ptr)
+{
+	return IS_ERR_VALUE((unsigned long)ptr);
+}
+
+#endif /* _LINUX_ERR_H */
-- 
2.4.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [next] | [standalone]


#1215434

FromArnaldo Carvalho de Melo <acme@kernel.org>
Date2015-08-28 18:30 +0200
Message-ID<q2uHo-7g-7@gated-at.bofh.it>
In reply to#1213894
Em Wed, Aug 26, 2015 at 03:46:43PM +0200, Jiri Olsa escreveu:
> Adding part of the kernel's <linux/err.h> interface:
>   inline void * __must_check ERR_PTR(long error);
>   inline long   __must_check PTR_ERR(__force const void *ptr);
>   inline bool   __must_check IS_ERR(__force const void *ptr);
> 
> it will be used to propagate error through pointers
> in following patches.
> 
> Link: http://lkml.kernel.org/n/tip-ufgnyf683uab69anmmrabgdf@git.kernel.org
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> ---
>  tools/include/linux/err.h | 28 ++++++++++++++++++++++++++++
>  1 file changed, 28 insertions(+)
>  create mode 100644 tools/include/linux/err.h
> 
> diff --git a/tools/include/linux/err.h b/tools/include/linux/err.h
> new file mode 100644
> index 000000000000..2df92df55cfe
> --- /dev/null
> +++ b/tools/include/linux/err.h
> @@ -0,0 +1,28 @@
> +#ifndef __TOOLS_LINUX_ERR_H
> +#define __TOOLS_LINUX_ERR_H
> +
> +#include <linux/compiler.h>
> +#include <linux/types.h>
> +
> +#include <asm/errno.h>
> +

You deleted the comment in the kernel sources at this point:

/*
 * Kernel pointers have redundant information, so we can use a
 * scheme where we can return either an error code or a normal
 * pointer with the same return value.
 *
 * This should be a per-architecture thing, to allow different
 * error and pointer decisions.
 */

> +#define MAX_ERRNO	4095

Now we're dealing with user pointers, are we completely sure we can use
this trick here?

- Arnaldo

> +#define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
> +
> +static inline void * __must_check ERR_PTR(long error)
> +{
> +	return (void *) error;
> +}
> +
> +static inline long __must_check PTR_ERR(__force const void *ptr)
> +{
> +	return (long) ptr;
> +}
> +
> +static inline bool __must_check IS_ERR(__force const void *ptr)
> +{
> +	return IS_ERR_VALUE((unsigned long)ptr);
> +}
> +
> +#endif /* _LINUX_ERR_H */
> -- 
> 2.4.3
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1216065

FromJiri Olsa <jolsa@redhat.com>
Date2015-08-31 09:40 +0200
Message-ID<q3rR9-14k-51@gated-at.bofh.it>
In reply to#1215434
On Fri, Aug 28, 2015 at 01:21:39PM -0300, Arnaldo Carvalho de Melo wrote:
> Em Wed, Aug 26, 2015 at 03:46:43PM +0200, Jiri Olsa escreveu:
> > Adding part of the kernel's <linux/err.h> interface:
> >   inline void * __must_check ERR_PTR(long error);
> >   inline long   __must_check PTR_ERR(__force const void *ptr);
> >   inline bool   __must_check IS_ERR(__force const void *ptr);
> > 
> > it will be used to propagate error through pointers
> > in following patches.
> > 
> > Link: http://lkml.kernel.org/n/tip-ufgnyf683uab69anmmrabgdf@git.kernel.org
> > Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> > ---
> >  tools/include/linux/err.h | 28 ++++++++++++++++++++++++++++
> >  1 file changed, 28 insertions(+)
> >  create mode 100644 tools/include/linux/err.h
> > 
> > diff --git a/tools/include/linux/err.h b/tools/include/linux/err.h
> > new file mode 100644
> > index 000000000000..2df92df55cfe
> > --- /dev/null
> > +++ b/tools/include/linux/err.h
> > @@ -0,0 +1,28 @@
> > +#ifndef __TOOLS_LINUX_ERR_H
> > +#define __TOOLS_LINUX_ERR_H
> > +
> > +#include <linux/compiler.h>
> > +#include <linux/types.h>
> > +
> > +#include <asm/errno.h>
> > +
> 
> You deleted the comment in the kernel sources at this point:

right.. I did not want to bring too much attention :-))

> 
> /*
>  * Kernel pointers have redundant information, so we can use a
>  * scheme where we can return either an error code or a normal
>  * pointer with the same return value.
>  *
>  * This should be a per-architecture thing, to allow different
>  * error and pointer decisions.
>  */
> 
> > +#define MAX_ERRNO	4095
> 
> Now we're dealing with user pointers, are we completely sure we can use
> this trick here?

it's safe for user as well, because 'error' pointers
fall down to the unused hole:

Documentation/x86/x86_64/mm.txt:
ffffffffffe00000 - ffffffffffffffff (=2 MB) unused hole

haven't checked for other archs, but since it's used
within generic code, it should be ok

I'll put the comment back with additional explanation
wrt user space in v2

jirka
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1216266

FromArnaldo Carvalho de Melo <acme@kernel.org>
Date2015-08-31 17:30 +0200
Message-ID<q3zbY-3fy-19@gated-at.bofh.it>
In reply to#1216065
Em Mon, Aug 31, 2015 at 09:37:18AM +0200, Jiri Olsa escreveu:
> On Fri, Aug 28, 2015 at 01:21:39PM -0300, Arnaldo Carvalho de Melo wrote:
> > Em Wed, Aug 26, 2015 at 03:46:43PM +0200, Jiri Olsa escreveu:
> > > +++ b/tools/include/linux/err.h
> > > @@ -0,0 +1,28 @@
> > > +#ifndef __TOOLS_LINUX_ERR_H
> > > +#define __TOOLS_LINUX_ERR_H
> > > +
> > > +#include <linux/compiler.h>
> > > +#include <linux/types.h>
> > > +
> > > +#include <asm/errno.h>

> > You deleted the comment in the kernel sources at this point:
 
> right.. I did not want to bring too much attention :-))

:-)

Please get the explanation about why it is safe (the unused hole bits)
and merge it with the bits from the kernel comment that make sense,
well, I think we can just do a s/Kernel//g and explain why that is so.
 
> > /*
> >  * Kernel pointers have redundant information, so we can use a
> >  * scheme where we can return either an error code or a normal
> >  * pointer with the same return value.
> >  *
> >  * This should be a per-architecture thing, to allow different
> >  * error and pointer decisions.
> >  */

> > > +#define MAX_ERRNO	4095

> > Now we're dealing with user pointers, are we completely sure we can use
> > this trick here?

> it's safe for user as well, because 'error' pointers
> fall down to the unused hole:
> 
> Documentation/x86/x86_64/mm.txt:
> ffffffffffe00000 - ffffffffffffffff (=2 MB) unused hole
> 
> haven't checked for other archs, but since it's used
> within generic code, it should be ok
> 
> I'll put the comment back with additional explanation
> wrt user space in v2

Thanks!

- Arnaldo
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web