public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Brian Gerst <bgerst@didntduck.org>
To: Constantine Gavrilov <constg@qlusters.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: Calling syscalls from x86-64 kernel results in a crash on Opteron machines
Date: Mon, 13 Sep 2004 11:00:22 -0400	[thread overview]
Message-ID: <4145B606.5080505@didntduck.org> (raw)
In-Reply-To: <4145A8E1.8010409@qlusters.com>

Constantine Gavrilov wrote:
> Hello:
> 
> We have a piece of kernel code that calls some system calls in kernel 
> context (from a process with mm and a daemonized kernel thread that does 
> not have mm). This works fine on IA64 and i386 architectures.
> 
> When I try this on x86-64 kernel on Opteron machines, it results in 
> immediate crash. I have tried standard _syscall() macros from 
> asm/unistd.h. The system panics when returning from the system call.
> The disassembled code shows that gcc has often a hard time deciding 
> which registers (32-bit or 64-bit) it will use. For example, it puts the 
> system call number to eax, while it should put it to rax. However, this 
> register thing is not a problem. I have tried my own gcc hand-crafted 
> inline assembly and glibc inline syscall assembly that results in 
> "correct" disassembled code. The result is always the same -- kernel 
> crash when calling a function defined by _syscall() macros or when using 
> an "inline" block defined by glibc macros.
> 
> Attached please find a test module that tries to call the umask() (JUST 
> TO DEMONSTRATE a problem) via the syscall machanism. Both methods (the 
> _syscall1() marco and GLIBC INLINE_SYCALL() were used.
> 
> The assembly dump of the umask() called via _syscall(1) and via 
> INLINE_SYSCALL() as well as the disassembly of umask() from glibc are 
> provided in a separate attachement. The crash dump (captured with a 
> serial console) is provided along with disassembly of the main module 
> function.
> 
> It seems that segmentation is changed during the syscall and not 
> restored properly, or some other REALLY BAD THING happens. The entry.S 
> for x86_64 architecture is very informative, but I am not an expert in 
> Opteron architecture and I do not know how the syscall instruction is 
> supposed to work.
> 
> Can someone explain the reason for the crash? Can you think of a 
> workaround? Comments and ideas are very welcome (except of the kind that 
> it can be implemented in the user space or with a help of a user proxy 
> process).

You should never use the unistd.h macros from kernel space.  Call 
sys_foo() directly.  This may mean you have to export it.  The reason it 
crashes is that the "syscall" opcode used by the x86-64 macros (unlike 
the "int $0x80" for i386) causes a fault when already running in kernel 
space.

--
				Brian Gerst

  parent reply	other threads:[~2004-09-13 15:12 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-09-13 14:04 Calling syscalls from x86-64 kernel results in a crash on Opteron machines Constantine Gavrilov
2004-09-13 14:38 ` Christoph Hellwig
2004-09-13 15:05   ` Constantine Gavrilov
2004-09-13 16:17     ` Andrea Arcangeli
2004-09-13 16:41       ` Stephen Hemminger
2004-09-13 20:08         ` Andrea Arcangeli
2004-09-13 16:42     ` Greg KH
2004-09-13 17:21     ` Brian Gerst
2004-09-14  2:04     ` William Lee Irwin III
2004-09-13 14:44 ` Arnd Bergmann
2004-09-13 15:18   ` Constantine Gavrilov
2004-09-13 19:39     ` H. Peter Anvin
2004-09-13 15:00 ` Brian Gerst [this message]
2004-09-13 15:26   ` Constantine Gavrilov
     [not found] <2DZQy-7TB-7@gated-at.bofh.it>
2004-09-13 14:31 ` Andi Kleen
2004-09-13 15:28   ` Constantine Gavrilov

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=4145B606.5080505@didntduck.org \
    --to=bgerst@didntduck.org \
    --cc=constg@qlusters.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