From: Balbir Singh <balbir@linux.vnet.ibm.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Jeff Mahoney <jeffm@suse.com>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] delayacct: align to 8 byte boundary on 64-bit systems
Date: Sat, 13 Feb 2010 07:44:21 +0530 [thread overview]
Message-ID: <20100213021420.GE11364@balbir.in.ibm.com> (raw)
In-Reply-To: <20100212101957.9f4a4a3a.akpm@linux-foundation.org>
* Andrew Morton <akpm@linux-foundation.org> [2010-02-12 10:19:57]:
> On Fri, 12 Feb 2010 11:48:27 -0500
> Jeff Mahoney <jeffm@suse.com> wrote:
>
> > prepare_reply sets up an skb for the response. If I understand it correctly,
> > the payload contains:
> >
> > +--------------------------------+
> > | genlmsghdr - 4 bytes |
> > +--------------------------------+
> > | NLA header - 4 bytes | /* Aggregate header */
> > +-+------------------------------+
> > | | NLA header - 4 bytes | /* PID header */
> > | +------------------------------+
> > | | pid/tgid - 4 bytes |
>
> So we put another four zero bytes in here and add four to the "PID header".
>
Do you know if these breaks existing applications?
> > | +------------------------------+
> > | | NLA header - 4 bytes | /* stats header */
> > | + -----------------------------+ <- oops. aligned on 4 byte boundary
> > | | struct taskstats - 328 bytes |
> > +-+------------------------------+
> >
> > The start of the taskstats struct must be 8 byte aligned on IA64 (and other
> > systems with 8 byte alignment rules for 64-bit types) or runtime alignment
> > warnings will be issued.
> >
> > This patch pads the pid/tgid field out to sizeof(long), which forces
> > the alignment of taskstats. The getdelays userspace code is ok with this
> > since it assumes 32-bit pid/tgid and then honors that header's length field.
> >
Could you define OK above? Does the application work without
recompiling? Have you checked for endianness issues?
> > An array is used to avoid exposing kernel memory contents to userspace in the
> > response.
> >
> > Signed-off-by: Jeff Mahoney <jeffm@suse.com>
> > ---
> > kernel/taskstats.c | 8 +++++++-
> > 1 file changed, 7 insertions(+), 1 deletion(-)
> >
> > --- a/kernel/taskstats.c
> > +++ b/kernel/taskstats.c
> > @@ -362,6 +362,12 @@ static struct taskstats *mk_reply(struct
> > struct nlattr *na, *ret;
> > int aggr;
> >
> > + /* If we don't pad, we end up with alignment on a 4 byte boundary.
> > + * This causes lots of runtime warnings on systems requiring 8 byte
> > + * alignment */
> > + u32 pids[2] = { pid, 0 };
Shouldn't this be endianness dependent?
> > + int pid_size = ALIGN(sizeof(pid), sizeof(long));
> > +
> > aggr = (type == TASKSTATS_TYPE_PID)
> > ? TASKSTATS_TYPE_AGGR_PID
> > : TASKSTATS_TYPE_AGGR_TGID;
> > @@ -369,7 +375,7 @@ static struct taskstats *mk_reply(struct
> > na = nla_nest_start(skb, aggr);
> > if (!na)
> > goto err;
> > - if (nla_put(skb, type, sizeof(pid), &pid) < 0)
> > + if (nla_put(skb, type, pid_size, pids) < 0)
> > goto err;
> > ret = nla_reserve(skb, TASKSTATS_TYPE_STATS, sizeof(struct taskstats));
> > if (!ret)
>
> So any code which assumes that the pid/tgid field is four bytes long
> will break. Code which takes that length from the netlink message
> header will work OK.
>
I think we assume that PID/TGID is 32 bits long, we use the length to
extract the rest of the message. We cast NLA_DATA to int* in
getdelays.c.
> 32-bit architectures are unaltered.
>
> Seems safe enough. We'd be safer still if we didn't do this on 64-bit
> architectures which don't need it. ie: x86_64. But if we do that we
> add a risk that people will develop shoddy code which works on x86_64
> and doesn't work on ia64.
>
May be, this deserves an ABI and version bump in taskstats. I'll test
this patch soon.
--
Three Cheers,
Balbir
next prev parent reply other threads:[~2010-02-13 2:14 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-02-12 16:48 Jeff Mahoney
2010-02-12 18:19 ` Andrew Morton
2010-02-12 19:20 ` Jeff Mahoney
2010-02-12 19:29 ` Andrew Morton
2010-02-12 19:34 ` Jeff Mahoney
2010-02-13 2:14 ` Balbir Singh [this message]
2010-02-17 21:47 ` Jeff Mahoney
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=20100213021420.GE11364@balbir.in.ibm.com \
--to=balbir@linux.vnet.ibm.com \
--cc=akpm@linux-foundation.org \
--cc=jeffm@suse.com \
--cc=linux-kernel@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
all inboxes | Powered by JetHome®