linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Masahiro Yamada <masahiroy@kernel.org>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Miroslav Benes <mbenes@suse.cz>,
	Emil Velikov <emil.l.velikov@gmail.com>,
	Jessica Yu <jeyu@kernel.org>, Quentin Perret <qperret@google.com>,
	Matthias Maennich <maennich@google.com>
Subject: Re: [PATCH v2] export: fix string handling of namespace in EXPORT_SYMBOL_NS
Date: Tue, 31 May 2022 16:44:21 +0900	[thread overview]
Message-ID: <CAK7LNASMi3MHPf4aOMhWbPgDiWnNBU-MEdMs0UV1qf=1GW-i_A@mail.gmail.com> (raw)
In-Reply-To: <YoyTDCbELrpCZ3eC@kroah.com>

On Tue, May 24, 2022 at 5:10 PM Greg Kroah-Hartman
<gregkh@linuxfoundation.org> wrote:
>
> On Tue, May 24, 2022 at 03:31:59AM +0900, Masahiro Yamada wrote:
> > On Wed, Apr 27, 2022 at 11:50 PM Greg Kroah-Hartman
> > <gregkh@linuxfoundation.org> wrote:
> > >
> > > On Wed, Apr 27, 2022 at 11:29:19PM +0900, Masahiro Yamada wrote:
> > > > On Wed, Apr 27, 2022 at 6:06 PM Greg Kroah-Hartman
> > > > <gregkh@linuxfoundation.org> wrote:
> > > > >
> > > > > Commit c3a6cf19e695 ("export: avoid code duplication in
> > > > > include/linux/export.h") broke the ability for a defined string to be
> > > > > used as a namespace value.
> > > >
> > > > In hindsight, this was a bad idea.
> > > >
> > > >
> > > > EXPORT_SYMBOL_NS_GPL(dw_spi_resume_host, "SPI_DW_CORE")
> > > >
> > > >    is much much better than:
> > > >
> > > > EXPORT_SYMBOL_NS_GPL(dw_spi_resume_host, SPI_DW_CORE)
> > >
> > > I agree, but it's really not that big of a deal.  We could change it if
> > > you want.
> > >
> > > > ccflags-y += -DDEFAULT_SYMBOL_NAMESPACE=USB_STORAGE
> > > >
> > > > is also a bad idea.
> > >
> > > That's not such a bad idea as it lets you set a namespace for a
> > > directory and below easily.  What would you want to use instead?
> > >
> > > > When you look at EXPORT_SYMBOL_GPL() in C files, you will not be
> > > > aware of the presence of the namespace.
> > >
> > > It's easy to tell when things do not link properly :)
> > >
> > > > Anyway, it is presumably too late to fix it.
> > >
> > > Not really, the number of in-kernel users are still small and can be
> > > changed if you like.  External users can update when they hit the change
> > > as well, not a big deal.
> >
> >
> > If I send a patch for global conversion,
> > will you be happy to pick it up?
> >
> >
> > I think this should be applied at the very last moment
> > of the MW.
>
> Make up a patch right after -rc1 to get into -rc2 as that's usually the
> best time for tree-wide changes like this.
>
> > I can convert tree-wide by sed.
> >
> >
> > Example of conversion:
> >
> > EXPORT_SYMBOL_NS_GPL(dw_spi_resume_host, SPI_DW_CORE)
> >    -->
> > EXPORT_SYMBOL_NS_GPL(dw_spi_resume_host, "SPI_DW_CORE")
>
> Ah, but then this breaks my use case where I did in the Android tree:
>
>         EXPORT_SYMBOL_NS_GPL(symbol_name, ANDROID_GKI_VFS_EXPORT_ONLY);
>
> and then in the makefile I did:
>         subdir-ccflags-y += -DANDROID_GKI_VFS_EXPORT_ONLY=VFS_internal_I_am_really_a_filesystem_and_am_NOT_a_driver
>
> That saved me typing a lot of "VFS_internal_I_am..." in the .c files.


Kbuild provides a macro "stringify"

It shall be converted to:

    subdir-ccflags-y += -DANDROID_GKI_VFS_EXPORT_ONLY=$(call
stringify,VFS_internal_I_am_really_a_filesystem_and_am_NOT_a_driver)


>
> I know out-of-tree stuff does not matter, but a simple way to make this
> work would be nice.
>
> I could just do:
>         #define ANDROID_GKI_VFS_EXPORT_ONLY     "VFS_internal_I_am..."
> in a .c file which would handle this, right?

Yes, that is an alternative.


> Ok, so maybe that isn't an issue, nevermind...
>
> But, if we have a string here, what happens if someone puts a space in
> it:
>         EXPORT_SYMBOL_NS_GPL(symbol_name, "MY DRIVER NAMESPACE");
> that will not break the build but will cause the tools to really
> complain, right?  Or do the wrong thing and put them in the "MY"
> namespace?

Right, the compiler does not complain about a space in the namespace.
We can check it in modpost if we like.






BTW, do we need EXPORT_SYMBOL_NS() in the first place?

If you think DEFAULT_SYMBOL_NAMESPACE is useful,
you have already noticed that the per-module namespace is
more convenient than the per-symbol namespace.




For example, if you look at drivers/hwmon/pmbus/pmbus_core.c,
all symbols are exported by EXPORT_SYMBOL_NS_GPL(... , PMBUS).
I do not see any module that exports multiple namespaces.

So, I think per-module namespace control is enough.


[Deprecate]
    EXPORT_SYMBOL_NS(<symbol>, <namespace>)
    EXPORT_SYMBOL_NS_GPL(<symbol>, <namespace>)

[Add]
    MODULE_NAMESPACE(<namespace>)


If MODULE_NAMESPACE(<namespace>) is added to a module,
all symbols exported from that module belong to <namespace>.




> thanks,
>
> greg k-h



-- 
Best Regards
Masahiro Yamada

  reply	other threads:[~2022-05-31  7:45 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-27  9:04 [PATCH v2] export: fix string handling of namespace in EXPORT_SYMBOL_NS Greg Kroah-Hartman
2022-04-27 14:29 ` Masahiro Yamada
2022-04-27 14:50   ` Greg Kroah-Hartman
2022-04-27 15:11     ` Masahiro Yamada
2022-04-27 16:21       ` Greg Kroah-Hartman
2022-05-23 18:31     ` Masahiro Yamada
2022-05-24  8:10       ` Greg Kroah-Hartman
2022-05-31  7:44         ` Masahiro Yamada [this message]
2022-05-31 10:36           ` Masahiro Yamada

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='CAK7LNASMi3MHPf4aOMhWbPgDiWnNBU-MEdMs0UV1qf=1GW-i_A@mail.gmail.com' \
    --to=masahiroy@kernel.org \
    --cc=emil.l.velikov@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jeyu@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maennich@google.com \
    --cc=mbenes@suse.cz \
    --cc=qperret@google.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;
as well as URLs for NNTP newsgroup(s).