public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Yury Norov <ynorov@nvidia.com>
To: Arnd Bergmann <arnd@arndb.de>
Cc: Paul Walmsley <pjw@kernel.org>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	Albert Ou <aou@eecs.berkeley.edu>,
	Alexandre Ghiti <alex@ghiti.fr>,
	Yury Norov <yury.norov@gmail.com>,
	Rasmus Villemoes <linux@rasmusvillemoes.dk>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S . Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Jesper Dangaard Brouer <hawk@kernel.org>,
	John Fastabend <john.fastabend@gmail.com>,
	Stanislav Fomichev <sdf@fomichev.me>,
	Ruan Jinjie <ruanjinjie@huawei.com>,
	linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org,
	Linux-Arch <linux-arch@vger.kernel.org>,
	Netdev <netdev@vger.kernel.org>,
	bpf@vger.kernel.org, Nathan Chancellor <nathan@kernel.org>
Subject: Re: [PATCH 1/6] lib: include crc32.h conditionally on CONFIG_CRC32
Date: Mon, 4 May 2026 14:32:00 -0400	[thread overview]
Message-ID: <afjmIK4mlCWeywuS@yury> (raw)
In-Reply-To: <9d45acd1-667b-4acf-9e2e-bcd79630d726@app.fastmail.com>

On Mon, May 04, 2026 at 07:18:49PM +0200, Arnd Bergmann wrote:
> On Mon, May 4, 2026, at 18:46, Yury Norov wrote:
> > On Mon, May 04, 2026 at 10:03:10AM +0200, Arnd Bergmann wrote:
> >> On Thu, Apr 30, 2026, at 23:13, Yury Norov wrote:
> >> I'm not following that description. Why is it an error to declare
> >> a funtion that is not implemented? Isn't that how optional interfaces
> >> tend to work in general?
> >
> > Never heard about such a thing like "optional interface". And git grep
> > tends to second that...
> 
> I meant any library interface that can be turned on or off

So? If I disable CRC32, can I use the either_crc()? In case of that
networking header, the answer is yes. In some other piece of code
the answer is no. Is that correct?
  
> >> > The only header requiring the crc32 and bitreverse prototypes is
> >> > include/linux/etherdevice.h. Thus, protect inclusion of corresponding
> >> > headers in the etherdevice with CONFIG_CRC32, together with the only
> >> > function depending on it.
> >> ...
> >> >  #include <linux/if_ether.h>
> >> >  #include <linux/netdevice.h>
> >> >  #include <linux/random.h>
> >> > +#ifdef CONFIG_CRC32
> >> >  #include <linux/crc32.h>
> >> > +#endif
> >> >  #include <linux/unaligned.h>
> >> >  #include <asm/bitsperlong.h>
> >> 
> >> Don't add #ifdef blocks around headers. If the header cannot
> >> be included without side-effects, change the linux/crc32.h
> >> file instead of its users.
> >
> > linux/acpi.h does that like many othes. What exactly is wrong with
> > protecting headers inclusion?
> 
> There is no "protecting" here, you just add complexity to the
> build when headers are sometimes included indirectly and but
> other times are not, depending on kernel configuration.

Sorry, don't understand... I use the 'protecting' term with the meaning:
the functionality that is explicitly disabled should be never used.
Otherwise, what for we disable it?

This comes with the cost of increasing the config space, but that's
how it works.

In terms of build complexity, I guess that the more you disable on
preprocessing stage, the less a compiler should actually process.

> It's unlikely to cause problems for the crc32.h header, but
> the acpi example definitely risks running into circular
> inclusions when you end up with some other header that depending
> on configuration ends up including linux/acpi.h while also
> bring included indirectly from that one.
> 
> >> It looks like the problem is the check for CONFIG_GENERIC_BITREVERSE
> >> in include/asm-generic/bitops/__bitrev.h, which ends up
> >> hinding the generic___bitrev32() helper without need.
> >> 
> >> Simply removing the #ifdef there should avoid the build failure.
> >
> > OK, it seems like this is what I don't understand.
> >
> > We've got an optional feature, like CRC32, which is enabled by
> > CONFIG_CRC32. The most conservative way is to declare everything
> > CRC32-related in the corresponding header, and then protect the header
> > with IS_ENABLED(CONFIG_CRC32).
> >
> > I understand that from practical perspective, we can declare some simple
> > macros, like header size, unprotected. But what we've got now is a sort
> > of mess: all CRC32-related functions are declared unprotected, and
> > generic headers are good to use them. Compiler is happy while those
> > functions are actually unused. Next, CRC32 depends on BITREVERSE, which
> > is again unprotected, and it may optionally have an arch implementation.
> >
> > So if arch bitrev() is implemented, you can use part of bitreverse and
> > crc32 APIs despite that they are explicitly disabled - just because they
> > are implemented as macros in unprotected headers. And you cannot use some
> > others - because they are implemented differently, as a real functions.
> 
> I think you trying to solve a non-problem here.

This was reported by Nathan for tinyconfig. At least x86 and s390 are
affected.

https://lore.kernel.org/all/20260429202922.GA3575295@ax162/

Is tinyconfig important?

> It is extremely rare
> for any kernel to be built without crc32 or bitrev. Even in randconfig
> builds, both are usually selected by some driver. The behavior
> we've always had here is that in the rare one randconfig in 10000
> that hits the one driver missing 'select BITREVERSE', we get a link
> failure with an obvious fix. If you add the extra #ifdef, it gets
> a little more likely to actually run into the bug, and it shows
> up a little earlier as a compile failure instead of a link failure,
> but otherwise, nothing changes.

Except that it fixes the tinyconfig build.

The above argument sounds to me like you believe that CRC32 config is
really useless because it's enabled for any practical configuration.
And the same for BITREVERSE. Would it be better to get rid of them?
Would simplification of config space overweights the bloat of the
tinyconfig?

On the context: CONFIG_CRC32 is pre-historic, and BITREVERSE is 2006.

Right now half CRC32 is available if CONFIG_CRC32 is on, and half is
not available. The bitreverse is the same. If HAVE_ARCH_BITREVERSE is
enabled, one can use the API, bypassing the BITREVERSE. This doesn't
sound right to me long-term.

Whatever this ends up, let's figure out a consistent solution please?

Thanks,
Yury

  reply	other threads:[~2026-05-04 18:32 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-30 21:13 [PATCH 0/6] lib: rework bitreverse Yury Norov
2026-04-30 21:13 ` [PATCH 1/6] lib: include crc32.h conditionally on CONFIG_CRC32 Yury Norov
2026-05-04  8:03   ` Arnd Bergmann
2026-05-04 12:43     ` David Laight
2026-05-04 16:46     ` Yury Norov
2026-05-04 17:18       ` Arnd Bergmann
2026-05-04 18:32         ` Yury Norov [this message]
2026-05-04 19:05           ` Arnd Bergmann
2026-04-30 21:13 ` [PATCH 2/6] lib/bitrev: Introduce GENERIC_BITREVERSE and cleanup Kconfig Yury Norov
2026-04-30 21:13 ` [PATCH 3/6] bitops: Define generic __bitrev8/16/32 for reuse Yury Norov
2026-04-30 21:13 ` [PATCH 4/6] arch/riscv: Add bitrev.h file to support rev8 and brev8 Yury Norov
2026-04-30 21:13 ` [PATCH 5/6] lib: compile generic bitrev.c conditionally on GENERIC_BITREVERSE Yury Norov
2026-04-30 21:13 ` [PATCH 6/6] MAINTAINERS: BITOPS: include bitrev.[ch] Yury Norov
2026-05-02  1:40 ` [PATCH 0/6] lib: rework bitreverse Yury Norov

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=afjmIK4mlCWeywuS@yury \
    --to=ynorov@nvidia.com \
    --cc=akpm@linux-foundation.org \
    --cc=alex@ghiti.fr \
    --cc=andrew+netdev@lunn.ch \
    --cc=aou@eecs.berkeley.edu \
    --cc=arnd@arndb.de \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=hawk@kernel.org \
    --cc=john.fastabend@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=nathan@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=palmer@dabbelt.com \
    --cc=pjw@kernel.org \
    --cc=ruanjinjie@huawei.com \
    --cc=sdf@fomichev.me \
    --cc=yury.norov@gmail.com \
    /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