[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230914131700.0ba3ee80@gandalf.local.home>
Date: Thu, 14 Sep 2023 13:17:00 -0400
From: Steven Rostedt <rostedt@...dmis.org>
To: Clément Léger <cleger@...osinc.com>
Cc: Masami Hiramatsu <mhiramat@...nel.org>,
linux-kernel@...r.kernel.org, linux-trace-kernel@...r.kernel.org,
Beau Belgrave <beaub@...ux.microsoft.com>
Subject: Re: [PATCH] tracing/user_events: align uaddr on unsigned long
alignment
On Thu, 14 Sep 2023 15:11:02 +0200
Clément Léger <cleger@...osinc.com> wrote:
> @@ -511,13 +511,19 @@ static int user_event_enabler_write(struct user_event_mm *mm,
> }
>
> kaddr = kmap_local_page(page);
> +
> + bit_offset = uaddr & (sizeof(unsigned long) - 1);
> + if (bit_offset) {
> + bit_offset *= 8;
> + uaddr &= ~(sizeof(unsigned long) - 1);
> + }
> ptr = kaddr + (uaddr & ~PAGE_MASK);
>
> /* Update bit atomically, user tracers must be atomic as well */
> if (enabler->event && enabler->event->status)
> - set_bit(ENABLE_BIT(enabler), ptr);
> + set_bit(ENABLE_BIT(enabler) + bit_offset, ptr);
> else
> - clear_bit(ENABLE_BIT(enabler), ptr);
> + clear_bit(ENABLE_BIT(enabler) + bit_offset, ptr);
>
> kunmap_local(kaddr);
> unpin_user_pages_dirty_lock(&page, 1, true);
Does this work for big endian machines too?
Little endian layout:
uaddr = 0xbeef0004
enabler = 1;
memory at 0xbeef0000: 00 00 00 00 02 00 00 00
^
addr: 0xbeef0004
(enabler is set )
bitoffset = uaddr & (sizeof(unsigned long) - 1); bitoffset = 4
bit_offset *= 8; bitoffset = 32
uaddr &= ~(sizeof(unsigned long) - 1); uaddr = 0xbeef0000
ptr = kaddr + (uaddr & ~PAGE_MASK);
clear_bit(1 + 32, ptr);
memory at 0xbeef0000: 00 00 00 00 02 00 00 00
^
bit 33 of 0xbeef0000
Now lets look at big endian layout:
uaddr = 0xbeef0004
enabler = 1;
memory at 0xbeef0000: 00 00 00 00 00 00 00 02
^
addr: 0xbeef0004
(enabler is set )
bitoffset = uaddr & (sizeof(unsigned long) - 1); bitoffset = 4
bit_offset *= 8; bitoffset = 32
uaddr &= ~(sizeof(unsigned long) - 1); uaddr = 0xbeef0000
ptr = kaddr + (uaddr & ~PAGE_MASK);
clear_bit(1 + 32, ptr);
memory at 0xbeef0000: 00 00 00 00 00 00 00 02
^
bit 33 of 0xbeef0000
I don't think that's what you expected!
-- Steve
Powered by blists - more mailing lists