> From: "Ted Unangst" <t...@tedunangst.com>
> Date: Fri, 18 Mar 2022 05:04:23 -0400
> 
> On 2022-03-17, Alexander Bluhm wrote:
> > On Thu, Mar 17, 2022 at 01:07:12AM +0100, Mark Kettenis wrote:
> > > > Date: Thu, 17 Mar 2022 01:01:46 +0100 (CET)
> > > > From: Mark Kettenis <mark.kette...@xs4all.nl>
> > > > 
> > > > > Date: Thu, 17 Mar 2022 00:47:15 +0100
> > > > > From: Alexander Bluhm <alexander.bl...@gmx.net>
> > > > > 
> > > > > Hi,
> > > > > 
> > > > > My previous atempt to add a mutex to in_pcb.h was reverted as it
> > > > > broke userland build.
> > > > > 
> > > > > Is the correct fix to include sys/mutex.h in every .c file that
> > > > > includes netinet/in_pcb.h ?  I made a release with it.
> > > > > Or should I include sys/mutex.h in netinet/in_pcb.h ?
> > > > 
> > > > Neither?
> > > > 
> > > > It makes no sense to export the kernel mutex stuff to userland.  Is
> > > > there a way to avoid doing that by adding a bit for #ifdef _KERNEL?
> > >                                             ^^^^^^^^^
> > >                                       a bit more
> > 
> > My diff adds struct mutex to struct inpcbtable.  My later plan is
> > to add a mutex also to struct inpcb.
> > 
> > tcpbench uses libkvm to extract information from struct inpcbtable.
> > netstat does that for struct inpcb.  Also post mortem analysis from
> > a kernel core dump is possible.
> > 
> > I don't understand why userland must not know the size of struct
> > mutex when tools where written to analyze these structs.
> > 
> > Is there something special about struct mutex that should not shown
> > to userland?
> > 
> > Do you like this?  Different structs for kernel and userland.
> > I think this is confusing when used with libkvm.
> > 
> > struct inpcbtable {
> >         TAILQ_HEAD(inpthead, inpcb) inpt_queue; /* [t] inet PCB queue */
> >         struct  inpcbhead *inpt_hashtbl;        /* [t] local and foreign 
> > hash */
> >         struct  inpcbhead *inpt_lhashtbl;       /* [t] local port hash */
> >         SIPHASH_KEY inpt_key, inpt_lkey;        /* [t] secrets for hashes */
> >         u_long  inpt_mask, inpt_lmask;          /* [t] hash masks */
> >         int     inpt_count, inpt_size;          /* [t] queue count, hash 
> > size */
> > #ifdef _KERNEL
> >         struct mutex inpt_mtx;                  /* protect queue and hash */
> > #endif
> > };
> 
> What if you add an #else case?
> 
> #ifdef _KERNEL
> struct mutex inpt_mtx;
> #else
> char _mtxpad[8];
> #endif

Keeping the size in sync (and consistent across platforms!) will be a
nightmare.  So no.

Reply via email to