[PATCH 4/9] linux/const.h: Upgrade & Merge vDSO and uAPI

Pierre-Clément Tosi ptosi at google.com
Thu Mar 17 12:00:29 CET 2022


On Wed, Mar 16, 2022 at 01:23:44PM -0600, Simon Glass wrote:
> Hi Pierre-Clément,
> 
> On Wed, 16 Mar 2022 at 09:40, Pierre-Clément Tosi <ptosi at google.com> wrote:
> >
> > Import the header from version 5.16 of the kernel:
> >
> >     commit df0cc57e057f18e44dac8e6c18aba47ab53202f9
> >
> > Inline <vdso/const.h> and <uapi/linux/const.h>. This is wrapped in
> > "#ifndef __UBOOT__/#include/#else/{inline}" to better document the
> > origin of the code being added to the U-Boot header (but not present in
> > the original header) and make diff tools happier when comparing the file
> > with its reference, which should be useful when porting future changes
> > from the Linux header and/or if we decide to also import those included
> > headers into the U-Boot codebase.
> >
> > Signed-off-by: Pierre-Clément Tosi <ptosi at google.com>
> > Cc: Simon Glass <sjg at chromium.org>
> > Cc: Tom Rini <trini at konsulko.com>
> > ---
> >  include/linux/const.h | 22 +++++++++++++++++++++-
> >  1 file changed, 21 insertions(+), 1 deletion(-)
> >
> > diff --git a/include/linux/const.h b/include/linux/const.h
> > index 379c889232..3e3803d767 100644
> > --- a/include/linux/const.h
> > +++ b/include/linux/const.h
> > @@ -2,8 +2,13 @@
> >  #ifndef _LINUX_CONST_H
> >  #define _LINUX_CONST_H
> >
> > -/* const.h: Macros for dealing with constants.  */
> > +#ifndef __UBOOT__
> > +#include <vdso/const.h>
> > +#else
> >
> > +#ifndef __UBOOT__
> > +#include <uapi/linux/const.h>
> > +#else
> >  /* Some constant macros are used in both assembler and
> >   * C code.  Therefore we cannot annotate them always with
> >   * 'UL' and other type specifiers unilaterally.  We
> > @@ -28,7 +33,22 @@
> >  #define _BITUL(x)      (_UL(1) << (x))
> >  #define _BITULL(x)     (_ULL(1) << (x))
> >
> > +#define __ALIGN_KERNEL(x, a)           __ALIGN_KERNEL_MASK(x, (typeof(x))(a) - 1)
> > +#define __ALIGN_KERNEL_MASK(x, mask)   (((x) + (mask)) & ~(mask))
> 
> How does this compare to the existing ALIGN()? It looks the same to me.
> 

__ALIGN_KERNEL() is the uAPI counterpart to the ALIGN() kernel macro (or is it
the other way around?) so they're intended to be similar in implementation; the
key difference being the double-leading-underscore notation, which bears a
special meaning as per the C Standard, and allows __ALIGN_KERNEL() to be
considerably easier to export. In fact, the kernel currently defines

    #define ALIGN(x, a)        __ALIGN_KERNEL((x), (a))

For the reason why this patch introduces it here, I've taken the conservative
approach of meticulously copying the original headers over, in their entirety
(as far as feasible), in order to make future upgrades as smooth as possible.

This patch inlines those vDSO and uAPI headers instead of bringing them as the
stand-alone files they are in the kernel as it looks like no other kernel header
of that kind has been imported but IMO, it would make more sense to do the
later. What do you think?

> > +
> > +#define __KERNEL_DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
> > +#endif
> > +
> >  #define UL(x)          (_UL(x))
> >  #define ULL(x)         (_ULL(x))
> > +#endif
> > +
> > +/*
> > + * This returns a constant expression while determining if an argument is
> > + * a constant expression, most importantly without evaluating the argument.
> > + * Glory to Martin Uecker <Martin.Uecker at med.uni-goettingen.de>
> > + */
> > +#define __is_constexpr(x) \
> > +       (sizeof(int) == sizeof(*(8 ? ((void *)((long)(x) * 0l)) : (int *)8)))
> >
> >  #endif /* _LINUX_CONST_H */
> > --
> > 2.35.1.723.g4982287a31-goog
> >
> 
> REgards,
> Simon

-- 
Pierre


More information about the U-Boot mailing list