From: Stefan Hajnoczi <stefanha@redhat.com>
To: David Miller <davem@davemloft.net>
Cc: netdev@vger.kernel.org, jhansen@vmware.com
Subject: Re: [PATCH] VSOCK: fix uapi/linux/vm_sockets.h incomplete types
Date: Wed, 20 Sep 2017 16:22:22 +0100 [thread overview]
Message-ID: <20170920152222.GI9409@stefanha-x1.localdomain> (raw)
In-Reply-To: <20170919.103840.379059301652331060.davem@davemloft.net>
On Tue, Sep 19, 2017 at 10:38:40AM -0700, David Miller wrote:
> From: Stefan Hajnoczi <stefanha@redhat.com>
> Date: Mon, 18 Sep 2017 16:21:00 +0100
>
> > On Fri, Sep 15, 2017 at 02:14:32PM -0700, David Miller wrote:
> >> > diff --git a/include/uapi/linux/vm_sockets.h b/include/uapi/linux/vm_sockets.h
> >> > index b4ed5d895699..4ae5c625ac56 100644
> >> > --- a/include/uapi/linux/vm_sockets.h
> >> > +++ b/include/uapi/linux/vm_sockets.h
> >> > @@ -18,6 +18,10 @@
> >> >
> >> > #include <linux/socket.h>
> >> >
> >> > +#ifndef __KERNEL__
> >> > +#include <sys/socket.h> /* struct sockaddr */
> >> > +#endif
> >> > +
> >>
> >> There is no precedence whatsoever to include sys/socket.h in _any_ UAPI
> >> header file provided by the kernel.
> >
> > <linux/if.h> does it for the same reason:
> >
> > include/uapi/linux/if.h:#include <sys/socket.h> /* for struct sockaddr. */
>
> You don't need it for struct sockaddr, you need it for sa_family_t,
> the comment is very misleading.
>
> Please do as I have instructed and it will fix this problem.
No, you really cannot rely on struct sockaddr from <linux/socket.h> in
uapi headers. You can check this yourself:
$ cd /tmp && gcc -o a.o -c /usr/include/linux/vm_sockets.h
/usr/include/linux/vm_sockets.h:148:32: error: invalid application of ‘sizeof’ to incomplete type ‘struct sockaddr’
unsigned char svm_zero[sizeof(struct sockaddr) -
^~~~~~
The weird situation is:
1. When compiling the kernel, <linux/socket.h> brings in struct sockaddr
because the compiler finds include/linux/socket.h first before
include/uapi/linux/socket.h.
2. When compiling a userspace application, <linux/socket.h> does not
bring in struct sockaddr because include/uapi/linux/socket.h is
found.
This is why I added the #include <sys/socket> when !__KERNEL__. Sorry
that the commit description wasn't clear on this.
Am I misunderstanding something?
Stefan
prev parent reply other threads:[~2017-09-20 15:22 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-12 16:34 [PATCH] VSOCK: fix uapi/linux/vm_sockets.h incomplete types Stefan Hajnoczi
2017-09-13 7:55 ` Jorgen S. Hansen
2017-09-15 21:14 ` David Miller
2017-09-18 15:21 ` Stefan Hajnoczi
2017-09-19 17:38 ` David Miller
2017-09-20 15:22 ` Stefan Hajnoczi [this message]
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=20170920152222.GI9409@stefanha-x1.localdomain \
--to=stefanha@redhat.com \
--cc=davem@davemloft.net \
--cc=jhansen@vmware.com \
--cc=netdev@vger.kernel.org \
/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