From: Johannes Berg <johannes@sipsolutions.net>
To: Nathan Chancellor <nathan@kernel.org>,
Benjamin Berg <benjamin@sipsolutions.net>
Cc: linux-um@lists.infradead.org, llvm@lists.linux.dev
Subject: Re: [PATCH 1/2] um: mark rodata read-only and implement _nofault accesses
Date: Thu, 03 Apr 2025 22:47:39 +0200 [thread overview]
Message-ID: <5c8f9b27e77c793295c2f6a0c3a3794ec4c05c3c.camel@sipsolutions.net> (raw)
In-Reply-To: <20250403191910.GA3085607@ax162>
On Thu, 2025-04-03 at 12:19 -0700, Nathan Chancellor wrote:
>
> Thanks, I applied that change, which shows a slightly different crash
> message now:
Pretty sure it's all just a bug in my inline assembly, and clang
allocates registers differently:
#define ___backtrack_faulted(_faulted) \
asm volatile ( \
"mov $0, %0\n" \
"movq $__get_kernel_nofault_faulted_%=,%1\n" \
"jmp _end_%=\n" \
"__get_kernel_nofault_faulted_%=:\n" \
"mov $1, %0;" \
"_end_%=:" \
: "=r" (_faulted), \
"=m" (current->thread.segv_continue) :: \
)
It _looks_ as though both %0 and %1 are output only, but clang compiles
it to:
51: 48 83 fb 08 cmp $0x8,%rbx
55: 72 44 jb 9b <_end_0+0x2a>
57: 48 8b 01 mov (%rcx),%rax
// start inline assembly ---vvv--- //
5a: b8 00 00 00 00 mov $0x0,%eax
5f: 48 c7 80 90 07 00 00 movq $0x0,0x790(%rax) // crash
66: 00 00 00 00
66: R_X86_64_32S .text+0x6c
6a: eb 05 jmp 71 <_end_0>
000000000000006c <__get_kernel_nofault_faulted_0>:
6c: b8 01 00 00 00 mov $0x1,%eax
// end inline assembly ---^^^--- //
0000000000000071 <_end_0>:
71: 85 c0 test %eax,%eax
73: 75 56 jne cb <_end_1+0x10>
which clearly cannot work? I must be missing something. Switching the
first two instructions fixes it, of course, but right now I can't see
what I forgot in terms of constraints to make the compiler not do that.
Probably trivial to someone more familiar with inline assembly.
Modifying the _faulted to be +r instead of =r also fixes it.
johannes
next prev parent reply other threads:[~2025-04-03 20:55 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-10 16:09 [PATCH 0/2] Remove incorrect host mincore call and add rodata handling Benjamin Berg
2025-02-10 16:09 ` [PATCH 1/2] um: mark rodata read-only and implement _nofault accesses Benjamin Berg
2025-04-02 22:12 ` Nathan Chancellor
2025-04-03 6:20 ` Benjamin Berg
2025-04-03 19:19 ` Nathan Chancellor
2025-04-03 20:47 ` Johannes Berg [this message]
2025-02-10 16:09 ` [PATCH 2/2] um: remove copy_from_kernel_nofault_allowed Benjamin Berg
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=5c8f9b27e77c793295c2f6a0c3a3794ec4c05c3c.camel@sipsolutions.net \
--to=johannes@sipsolutions.net \
--cc=benjamin@sipsolutions.net \
--cc=linux-um@lists.infradead.org \
--cc=llvm@lists.linux.dev \
--cc=nathan@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;
as well as URLs for NNTP newsgroup(s).