linux-um archives
 help / color / mirror / Atom feed
From: Thomas Meyer <thomas@m3y3r.de>
To: Richard Weinberger <richard@nod.at>,
	elicooper@gmx.com, linux-kernel@vger.kernel.org,
	"open list:USER-MODE LINUX (UML)"
	<user-mode-linux-devel@lists.sourceforge.net>
Subject: um: PTRACE_SETREGSET failure with XSTATE on Kabylake CPU
Date: Tue, 20 Jun 2017 03:56:46 +0200	[thread overview]
Message-ID: <1497923806.7300.2.camel@m3y3r.de> (raw)

Hi,

I finally did figure out where in the host kernel the ptrace syscall
fails with -EFAULT.

In arch/x86/kernel/fpu/regset.c:130:

114 int xstateregs_set(struct task_struct *target, const struct user_regset *regset,
115                   unsigned int pos, unsigned int count,
116                   const void *kbuf, const void __user *ubuf)
117 {
118         struct fpu *fpu = &target->thread.fpu;
119         struct xregs_state *xsave;
120         int ret;
121 
122         if (!boot_cpu_has(X86_FEATURE_XSAVE))
123                 return -ENODEV;
124 
125         pr_info("in xstateregs_set");
126 
127         /*
128          * A whole standard-format XSAVE buffer is needed:
129          */
130         if ((pos != 0) || (count < fpu_user_xstate_size)) {
131                 pr_info("EFAULT from xstateregs_set");
132->               pr_info("pos = %i, count = %i, fpu_user_xstate_size= %i\n", pos, count, fpu_user_xstate_size);
133                 return -EFAULT;
134         }

Sadly I had to fallback to debugging by printk because kgdb/qemu
gdbstub, all didn't work for some unknown reason :-(

output is:
[   69.598349] EFAULT from xstateregs_set
[   69.598350] pos = 0, count = 832, fpu_user_xstate_size= 1088

calling code is in arch/x86/um/os-Linux/registers.c:

 49 int restore_fp_registers(int pid, unsigned long *fp_regs)
 50 {
 51         struct iovec iov;
 52 
 53         if (have_xstate_support) {
 54                 iov.iov_base = fp_regs;
 55                 iov.iov_len = sizeof(struct _xstate);
 56                 if (ptrace(PTRACE_SETREGSET, pid, NT_X86_XSTATE, &iov) < 0)
 57  ->                     return -errno;
 58                 return 0;
 59         } else {
 60                 return restore_i387_registers(pid, fp_regs);
 61         }
 62 }

it looks like _xstate is too short for above operation, I wonder why
PTRACE_GETREGSET works without a warning of too short size.

with kind regards
thomas



             reply	other threads:[~2017-06-20  1:56 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-20  1:56 Thomas Meyer [this message]
2017-06-20  6:58 ` um: PTRACE_SETREGSET failure with XSTATE on Kabylake CPU Richard Weinberger
2017-06-20  8:49   ` [uml-devel] " Thomas Meyer
2017-06-20  9:05     ` Richard Weinberger
2017-06-20 18:04       ` Yu-cheng Yu
2017-06-20 18:17         ` [uml-devel] " Richard Weinberger
2017-06-20 18:59           ` Richard Weinberger
2017-06-20 19:53             ` Yu-cheng Yu
2017-06-20 20:13               ` [uml-devel] " Thomas Meyer
2017-06-21  8:39                 ` Natale Patriciello
2017-06-21  9:44                   ` Thomas Meyer
2017-06-21 12:47                     ` Richard Weinberger

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=1497923806.7300.2.camel@m3y3r.de \
    --to=thomas@m3y3r.de \
    --cc=elicooper@gmx.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=richard@nod.at \
    --cc=user-mode-linux-devel@lists.sourceforge.net \
    /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