linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Feng Tang <feng.tang@intel.com>
To: Michael Ellerman <mpe@ellerman.id.au>
Cc: linuxppc-dev@lists.ozlabs.org
Subject: Re: [PATCH] powerpc/4xx: Fix build errors from mfdcr()
Date: Thu, 18 Feb 2021 21:04:34 +0800	[thread overview]
Message-ID: <20210218130434.GA47750@shbuild999.sh.intel.com> (raw)
In-Reply-To: <20210218123058.748882-1-mpe@ellerman.id.au>

On Thu, Feb 18, 2021 at 11:30:58PM +1100, Michael Ellerman wrote:
> lkp reported a build error in fsp2.o:
> 
>   CC      arch/powerpc/platforms/44x/fsp2.o
>   {standard input}:577: Error: unsupported relocation against base
> 
> Which comes from:
> 
>   pr_err("GESR0: 0x%08x\n", mfdcr(base + PLB4OPB_GESR0));
> 
> Where our mfdcr() macro is stringifying "base + PLB4OPB_GESR0", and
> passing that to the assembler, which obviously doesn't work.
> 
> The mfdcr() macro already checks that the argument is constant using
> __builtin_constant_p(), and if not calls the out-of-line version of
> mfdcr(). But in this case GCC is smart enough to notice that "base +
> PLB4OPB_GESR0" will be constant, even though it's not something we can
> immediately stringify into a register number.
> 
> Segher pointed out that passing the register number to the inline asm
> as a constant would be better, and in fact it fixes the build error,
> presumably because it gives GCC a chance to resolve the value.
> 
> While we're at it, change mtdcr() similarly.
> 
> Reported-by: kernel test robot <lkp@intel.com>
> Suggested-by: Segher Boessenkool <segher@kernel.crashing.org>
> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>

Acked-by: Feng Tang <feng.tang@intel.com>

Thanks!

> ---
>  arch/powerpc/include/asm/dcr-native.h | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/arch/powerpc/include/asm/dcr-native.h b/arch/powerpc/include/asm/dcr-native.h
> index 7141ccea8c94..a92059964579 100644
> --- a/arch/powerpc/include/asm/dcr-native.h
> +++ b/arch/powerpc/include/asm/dcr-native.h
> @@ -53,8 +53,8 @@ static inline void mtdcrx(unsigned int reg, unsigned int val)
>  #define mfdcr(rn)						\
>  	({unsigned int rval;					\
>  	if (__builtin_constant_p(rn) && rn < 1024)		\
> -		asm volatile("mfdcr %0," __stringify(rn)	\
> -		              : "=r" (rval));			\
> +		asm volatile("mfdcr %0, %1" : "=r" (rval)	\
> +			      : "n" (rn));			\
>  	else if (likely(cpu_has_feature(CPU_FTR_INDEXED_DCR)))	\
>  		rval = mfdcrx(rn);				\
>  	else							\
> @@ -64,8 +64,8 @@ static inline void mtdcrx(unsigned int reg, unsigned int val)
>  #define mtdcr(rn, v)						\
>  do {								\
>  	if (__builtin_constant_p(rn) && rn < 1024)		\
> -		asm volatile("mtdcr " __stringify(rn) ",%0"	\
> -			      : : "r" (v)); 			\
> +		asm volatile("mtdcr %0, %1"			\
> +			      : : "n" (rn), "r" (v));		\
>  	else if (likely(cpu_has_feature(CPU_FTR_INDEXED_DCR)))	\
>  		mtdcrx(rn, v);					\
>  	else							\
> -- 
> 2.25.1

  reply	other threads:[~2021-02-18 20:28 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-18 12:30 [PATCH] powerpc/4xx: Fix build errors from mfdcr() Michael Ellerman
2021-02-18 13:04 ` Feng Tang [this message]
2021-03-14 10:01 ` Michael Ellerman

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=20210218130434.GA47750@shbuild999.sh.intel.com \
    --to=feng.tang@intel.com \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mpe@ellerman.id.au \
    /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).