linux-mips.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Paul Burton <paul.burton@mips.com>
To: Serge Semin <fancer.lancer@gmail.com>,
	"Maciej W. Rozycki" <macro@linux-mips.org>
Cc: Ralf Baechle <ralf@linux-mips.org>,
	James Hogan <jhogan@kernel.org>,
	Serge Semin <Sergey.Semin@t-platforms.ru>,
	Arnd Bergmann <arnd@arndb.de>,
	"Vadim V . Vlasov" <vadim.vlasov@t-platforms.ru>,
	"linux-mips@vger.kernel.org" <linux-mips@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] mips: Remove q-accessors from non-64bit platforms
Date: Thu, 20 Jun 2019 17:40:04 +0000	[thread overview]
Message-ID: <20190620174002.tgayzon7dc5d57fh@pburton-laptop> (raw)
In-Reply-To: <20190614063341.1672-1-fancer.lancer@gmail.com>

Hi Serge,

On Fri, Jun 14, 2019 at 09:33:42AM +0300, Serge Semin wrote:
> There are some generic drivers in the kernel, which make use of the
> q-accessors or their derivatives. While at current asm/io.h the accessors
> are defined, their implementation is only applicable either for 64bit
> systems, or for systems with cpu_has_64bits flag set. Obviously there
> are MIPS systems which are neither of these, but still need to have
> those drivers supported. In this case the solution is to define some
> generic versions of the q-accessors, but with a limitation to be
> non-atomic. Such accessors are defined in the
> io-64-nonatomic-{hi-lo,lo-hi}.h file. The drivers which utilize the
> q-suffixed IO-methods are supposed to include the header file, so
> in case if these accessors aren't defined for the platform, the generic
> non-atomic versions are utilized. Currently the MIPS-specific asm/io.h
> file provides the q-accessors for any MIPS system even for ones, which
> in fact don't support them and raise BUG() in case if any of them is
> called. Due to this the generic versions of the accessors are never
> used while an attempt to call the IO-methods causes the kernel BUG().
> In order to fix this we need to define the q-accessors only for
> the MIPS systems, which actually support them, and don't define them
> otherwise, so to let the corresponding drivers to use the non-atomic
> q-suffixed accessors.
> 
> Signed-off-by: Serge Semin <fancer.lancer@gmail.com>
> Suggested-by: Arnd Bergmann <arnd@arndb.de>
> Cc: Vadim V. Vlasov <vadim.vlasov@t-platforms.ru>
> ---
>  arch/mips/include/asm/io.h | 11 +++++++++++
>  1 file changed, 11 insertions(+)

So this seems pretty reasonable. Build testing all our defconfigs only
showed up one issue for decstation_defconfig & decstation_r4k_defconfig:

  drivers/net/fddi/defza.c: In function 'fza_reads':
  drivers/net/fddi/defza.c:88:17: error: implicit declaration of
    function 'readq_relaxed'; did you mean 'readw_relaxed'?
    [-Werror=implicit-function-declaration]
   #define readq_u readq_relaxed
                   ^~~~~~~~~~~~~
  drivers/net/fddi/defza.c:126:13: note: in expansion of macro 'readq_u'
      *dst++ = readq_u(src++);
               ^~~~~~~
  drivers/net/fddi/defza.c: In function 'fza_writes':
  drivers/net/fddi/defza.c:92:18: error: implicit declaration of
    function 'writeq_relaxed'; did you mean 'writel_relaxed'?
    [-Werror=implicit-function-declaration]
   #define writeq_u writeq_relaxed
                    ^~~~~~~~~~~~~~
  drivers/net/fddi/defza.c:151:4: note: in expansion of macro 'writeq_u'
      writeq_u(*src++, dst++);
      ^~~~~~~~
    CC      net/core/scm.o
  cc1: some warnings being treated as errors
  make[4]: *** [scripts/Makefile.build:279: drivers/net/fddi/defza.o] Error 1

These uses of readq_relaxed & writeq_relaxed are both conditional upon
sizeof(unsigned long) == 8, ie. upon CONFIG_64BIT=y so they're not going
to present a runtime issue but we need to provide some implementation of
the *q accessors to keep the compiler happy.

I see a few options:

1) We could just have defza.c include <io-64-nonatomic-lo-hi.h> to get
   the appropriate declarations, which should then get optimized away by
   the compiler anyway & never actually be used.

2) We could have defza.h #define its readq_u & writeq_u macros
   differently for CONFIG_32BIT=y kernels, perhaps using
   __compiletime_error to catch any bogus use of them.

3) We could do the same in a generic header, though if nobody else has
   needed it so far & this is the only place we need it then maybe it's
   not worth it.

So I'm thinking option 2 might be best, as below. Having said that I
don't mind option 1 either - it's simple. Maciej do you have any
preference?

Thanks,
    Paul

---
diff --git a/drivers/net/fddi/defza.c b/drivers/net/fddi/defza.c
index c5cae8e74dc4..85d6a7f22fe7 100644
--- a/drivers/net/fddi/defza.c
+++ b/drivers/net/fddi/defza.c
@@ -85,11 +85,21 @@ static u8 hw_addr_beacon[8] = { 0x01, 0x80, 0xc2, 0x00, 0x01, 0x00 };
  */
 #define readw_u readw_relaxed
 #define readl_u readl_relaxed
-#define readq_u readq_relaxed
 
 #define writew_u writew_relaxed
 #define writel_u writel_relaxed
-#define writeq_u writeq_relaxed
+
+#ifdef CONFIG_32BIT
+extern u64 defza_readq_u(const void *ptr)
+	__compiletime_error("readq_u should not be used by 32b kernels");
+extern void defza_writeq_u(u64 val, void *ptr)
+	__compiletime_error("writeq_u should not be used by 32b kernels");
+# define readq_u defza_readq_u
+# define writeq_u defza_writeq_u
+#else
+# define readq_u readq_relaxed
+# define writeq_u writeq_relaxed
+#endif
 
 static inline struct sk_buff *fza_alloc_skb_irq(struct net_device *dev,
 						unsigned int length)


  reply	other threads:[~2019-06-20 17:40 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-14  6:33 [PATCH] mips: Remove q-accessors from non-64bit platforms Serge Semin
2019-06-20 17:40 ` Paul Burton [this message]
2019-06-20 18:19   ` Maciej W. Rozycki
2019-06-21  9:25     ` Arnd Bergmann
2019-06-21 10:09       ` Maciej W. Rozycki
2019-06-21 11:09         ` Arnd Bergmann
2019-06-21 12:24           ` Maciej W. Rozycki
2019-06-21 14:01             ` Arnd Bergmann
2019-06-24 19:13               ` Maciej W. Rozycki
2019-06-21  6:06   ` Serge Semin
2019-06-24 21:16 ` Paul Burton

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=20190620174002.tgayzon7dc5d57fh@pburton-laptop \
    --to=paul.burton@mips.com \
    --cc=Sergey.Semin@t-platforms.ru \
    --cc=arnd@arndb.de \
    --cc=fancer.lancer@gmail.com \
    --cc=jhogan@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@vger.kernel.org \
    --cc=macro@linux-mips.org \
    --cc=ralf@linux-mips.org \
    --cc=vadim.vlasov@t-platforms.ru \
    /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).