mbox series

[0/4] remove PDE_DATA()

Message ID 20211101093518.86845-1-songmuchun@bytedance.com (mailing list archive)
Headers show
Series remove PDE_DATA() | expand

Message

Muchun Song Nov. 1, 2021, 9:35 a.m. UTC
I found a bug [1] some days ago, which is because we want to use
inode->i_private to pass user private data. However, this is wrong
on proc fs. We provide a specific function PDE_DATA() to get user
private data. Actually, we can hide this detail by storing
PDE()->data into inode->i_private and removing PDE_DATA() completely.
The user could use inode->i_private to get user private data just
like debugfs does. This series is trying to remove PDE_DATA().

[1] https://lore.kernel.org/lkml/20211029032638.84884-1-songmuchun@bytedance.com/

Muchun Song (4):
  fs: proc: store PDE()->data into inode->i_private
  fs: proc: replace PDE_DATA(inode) with inode->i_private
  fs: proc: remove PDE_DATA()
  fs: proc: use DEFINE_PROC_SHOW_ATTRIBUTE() to simplify the code

 arch/alpha/kernel/srm_env.c                        |  4 ++--
 arch/arm/kernel/atags_proc.c                       |  2 +-
 arch/ia64/kernel/salinfo.c                         | 10 ++++-----
 arch/powerpc/kernel/proc_powerpc.c                 |  4 ++--
 arch/sh/mm/alignment.c                             |  2 +-
 arch/xtensa/platforms/iss/simdisk.c                |  4 ++--
 drivers/acpi/proc.c                                |  2 +-
 drivers/hwmon/dell-smm-hwmon.c                     |  4 ++--
 drivers/net/bonding/bond_procfs.c                  |  8 ++++----
 drivers/net/wireless/cisco/airo.c                  | 22 ++++++++++----------
 drivers/net/wireless/intersil/hostap/hostap_ap.c   | 16 +++++++--------
 .../net/wireless/intersil/hostap/hostap_download.c |  2 +-
 drivers/net/wireless/intersil/hostap/hostap_proc.c | 24 +++++++++++-----------
 drivers/net/wireless/ray_cs.c                      |  2 +-
 drivers/nubus/proc.c                               |  2 +-
 drivers/parisc/led.c                               |  4 ++--
 drivers/pci/proc.c                                 | 10 ++++-----
 drivers/platform/x86/thinkpad_acpi.c               |  4 ++--
 drivers/platform/x86/toshiba_acpi.c                | 16 +++++++--------
 drivers/pnp/isapnp/proc.c                          |  2 +-
 drivers/pnp/pnpbios/proc.c                         |  4 ++--
 drivers/scsi/scsi_proc.c                           |  4 ++--
 drivers/usb/gadget/function/rndis.c                |  4 ++--
 drivers/zorro/proc.c                               |  2 +-
 fs/afs/proc.c                                      |  6 +++---
 fs/cifs/cifs_debug.c                               | 17 ++-------------
 fs/ext4/mballoc.c                                  | 14 ++++++-------
 fs/jbd2/journal.c                                  |  2 +-
 fs/nfsd/stats.c                                    | 15 ++------------
 fs/proc/generic.c                                  |  6 ------
 fs/proc/inode.c                                    |  1 +
 fs/proc/internal.h                                 |  5 -----
 fs/proc/proc_net.c                                 | 12 +++++------
 include/linux/proc_fs.h                            |  2 --
 include/linux/seq_file.h                           |  2 +-
 ipc/util.c                                         |  2 +-
 kernel/irq/proc.c                                  |  8 ++++----
 kernel/resource.c                                  |  4 ++--
 net/atm/proc.c                                     |  4 ++--
 net/bluetooth/af_bluetooth.c                       |  8 ++++----
 net/can/bcm.c                                      |  2 +-
 net/can/proc.c                                     |  2 +-
 net/core/neighbour.c                               |  6 +++---
 net/core/pktgen.c                                  |  6 +++---
 net/ipv4/netfilter/ipt_CLUSTERIP.c                 |  6 +++---
 net/ipv4/raw.c                                     |  8 ++++----
 net/ipv4/tcp_ipv4.c                                |  2 +-
 net/ipv4/udp.c                                     |  6 +++---
 net/netfilter/x_tables.c                           | 10 ++++-----
 net/netfilter/xt_hashlimit.c                       | 18 ++++++++--------
 net/netfilter/xt_recent.c                          |  4 ++--
 net/sunrpc/auth_gss/svcauth_gss.c                  |  4 ++--
 net/sunrpc/cache.c                                 | 24 +++++++++++-----------
 net/sunrpc/stats.c                                 | 15 ++------------
 sound/core/info.c                                  |  4 ++--
 55 files changed, 168 insertions(+), 215 deletions(-)

Comments

Andrew Morton Nov. 16, 2021, 5:09 a.m. UTC | #1
On Mon,  1 Nov 2021 17:35:14 +0800 Muchun Song <songmuchun@bytedance.com> wrote:

> I found a bug [1] some days ago, which is because we want to use
> inode->i_private to pass user private data. However, this is wrong
> on proc fs. We provide a specific function PDE_DATA() to get user
> private data. Actually, we can hide this detail by storing
> PDE()->data into inode->i_private and removing PDE_DATA() completely.
> The user could use inode->i_private to get user private data just
> like debugfs does. This series is trying to remove PDE_DATA().

Why can't we do

/*
 * comment goes here
 */
static inline void *PDE_DATA(struct inode *inode)
{
	return inode->i_private;
}

to abstract things a bit and to reduce the patch size?

otoh, that upper-case thing needs to go, so the patch size remains the
same anyway.

And perhaps we should have a short-term

#define PDE_DATA(i) pde_data(i)

because new instances are sure to turn up during the development cycle.

But I can handle that by staging the patch series after linux-next and
reminding myself to grep for new PDE_DATA instances prior to
upstreaming.
Muchun Song Nov. 16, 2021, 8:26 a.m. UTC | #2
On Tue, Nov 16, 2021 at 1:09 PM Andrew Morton <akpm@linux-foundation.org> wrote:
>
> On Mon,  1 Nov 2021 17:35:14 +0800 Muchun Song <songmuchun@bytedance.com> wrote:
>
> > I found a bug [1] some days ago, which is because we want to use
> > inode->i_private to pass user private data. However, this is wrong
> > on proc fs. We provide a specific function PDE_DATA() to get user
> > private data. Actually, we can hide this detail by storing
> > PDE()->data into inode->i_private and removing PDE_DATA() completely.
> > The user could use inode->i_private to get user private data just
> > like debugfs does. This series is trying to remove PDE_DATA().
>
> Why can't we do
>
> /*
>  * comment goes here
>  */
> static inline void *PDE_DATA(struct inode *inode)
> {
>         return inode->i_private;
> }
>
> to abstract things a bit and to reduce the patch size?
>
> otoh, that upper-case thing needs to go, so the patch size remains the
> same anyway.
>
> And perhaps we should have a short-term
>
> #define PDE_DATA(i) pde_data(i)

Right. This way is the easiest way to reduce the patch size.
Actually, I want to make all PDE_DATA() go away, which
makes this patch series go big.

>
> because new instances are sure to turn up during the development cycle.
>
> But I can handle that by staging the patch series after linux-next and
> reminding myself to grep for new PDE_DATA instances prior to
> upstreaming.

I'd be happy if you could replace PDE_DATA() with inode->i_private.
In this case, should I still introduce pde_data() and perform the above
things to make this series smaller?

Thanks.
Andrew Morton Nov. 16, 2021, 8:01 p.m. UTC | #3
On Tue, 16 Nov 2021 16:26:12 +0800 Muchun Song <songmuchun@bytedance.com> wrote:

> >
> > because new instances are sure to turn up during the development cycle.
> >
> > But I can handle that by staging the patch series after linux-next and
> > reminding myself to grep for new PDE_DATA instances prior to
> > upstreaming.
> 
> I'd be happy if you could replace PDE_DATA() with inode->i_private.
> In this case, should I still introduce pde_data() and perform the above
> things to make this series smaller?

I do tend to think that pde_data() would be better than open-coding
inode->i_private everywhere.  More explanatory, easier if we decide to
change it again in the future.
Muchun Song Nov. 17, 2021, 8:24 a.m. UTC | #4
On Wed, Nov 17, 2021 at 4:01 AM Andrew Morton <akpm@linux-foundation.org> wrote:
>
> On Tue, 16 Nov 2021 16:26:12 +0800 Muchun Song <songmuchun@bytedance.com> wrote:
>
> > >
> > > because new instances are sure to turn up during the development cycle.
> > >
> > > But I can handle that by staging the patch series after linux-next and
> > > reminding myself to grep for new PDE_DATA instances prior to
> > > upstreaming.
> >
> > I'd be happy if you could replace PDE_DATA() with inode->i_private.
> > In this case, should I still introduce pde_data() and perform the above
> > things to make this series smaller?
>
> I do tend to think that pde_data() would be better than open-coding
> inode->i_private everywhere.  More explanatory, easier if we decide to
> change it again in the future.
>

Got it. I'll do that in the next version. Thanks.