From patchwork Wed Jul 18 20:06:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 142295 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp944310ljj; Wed, 18 Jul 2018 13:08:21 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdRCTUL2FD6GkCueLAW5up6NTY/z4j+nD+fm7nM1x+u9IVwUzwLi416nKzbHR4gBzLFI9qE X-Received: by 2002:a37:2a65:: with SMTP id q98-v6mr6515224qkh.174.1531944501705; Wed, 18 Jul 2018 13:08:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531944501; cv=none; d=google.com; s=arc-20160816; b=Kub3spip2v6vbbXDCRZLBurqwQxoydxTPfLvF8evHxCfuZKmTZNgYUmsGcRQAj9Kwk vheEofyT4G+0jJaQbSEIuNtXdpmf8O+v/fhT5rnrRxUdhWYp/duz1MNQwEhaD4mZ5tbK JlQeHUSS+MQZlzzcBaNV+tBL5rItmFDa3jGCZfmkdfVPgHTx48/yCcg53JlU55i/6H78 RSVuLZJb7HiD4oo+xChCc8lsiYTw7je7F1E83uwi5heDMUgNtbDLabi0D8NdAhHKCVQL GkTJzalrKXE4ePV3jsLU9Q+Yg6Qnx27Sis2fRHbAHUOrezn8CZxGr9cGLCVrPsDoVosF teFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:message-id:date:to:from :dkim-signature:arc-authentication-results; bh=WgFADSmcYO1kHCFJUa6Mx6HlkC2oV+z4n0TWgT0vlrE=; b=FaAnHsVZ7I87rhkR8Tox9EsnnSuZlzKWVMJFQrk9a2yNnOCkzHX7Wg5ANil3bgnmSp jESK3FiolnUNrEZ1/uQOUtUg4zJp1ENVJ0H2HYS1ZdqdbPvO5u/bJBszj0gj8UbV9EFx D9bphbh26MH5IMZ9I/jkcYamJDS+2E+xS+XRNmzJkMSfkfEdx1fq1kYODITMgy66562+ jgSWZtMuJ3ZvHOagseJENJnJ1N5mGJeWoh6JhxwlOl6yEPZiyoXbqjUcuZzW6ossv/+T 6efBosly/57z9eFPOSYHCh0fbb2VIXZ/vUB3Q9vvxzyET05Nvg0OygvYJepoqqzKOpCr gVyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Mv6JbBJo; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id v21-v6si2459254qkb.1.2018.07.18.13.08.21 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 18 Jul 2018 13:08:21 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Mv6JbBJo; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:38152 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ffskH-0007gJ-80 for patch@linaro.org; Wed, 18 Jul 2018 16:08:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51094) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ffsiu-0007Iz-7p for qemu-devel@nongnu.org; Wed, 18 Jul 2018 16:06:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ffsir-0003Hs-2x for qemu-devel@nongnu.org; Wed, 18 Jul 2018 16:06:56 -0400 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]:36288) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ffsiq-0003HP-SZ for qemu-devel@nongnu.org; Wed, 18 Jul 2018 16:06:53 -0400 Received: by mail-pg1-x542.google.com with SMTP id m19-v6so2489279pgv.3 for ; Wed, 18 Jul 2018 13:06:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=WgFADSmcYO1kHCFJUa6Mx6HlkC2oV+z4n0TWgT0vlrE=; b=Mv6JbBJoONptoX3TD6SivaMjPlDCxTVAFjmg3owXWSdtWshk/wkypC80ejucYtM+sB Bsine5xK5ulXbwcyKxz6m0HvuDlgvfZGYBWTbNZojJPndQL2IgGax4TyZYMn4A5WhFSy NX377eiE226pt5qtWNWhhxPtn43sKhM3q32b4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=WgFADSmcYO1kHCFJUa6Mx6HlkC2oV+z4n0TWgT0vlrE=; b=s8LpPRK6dwxscTkjyiAu33ZQM0Fnt504O9JxPjDGXhPol9iorj6xhwxbWtMaURv3Gv JVRppiH5pAt8cMgbQgQOeoam0tTATn1+NnjkibR+3F7fle5+sUovfDsOW0m9Ji9riS82 t2Q5FgMIizIJABuAwkWnOMLayOrjJQaJHrPZ1VJyihQ3qDf5LnuoN3FxDDJvaK9FOxTE rz28U3Y8fuXejbFpJIebeyj+TZtXLrKmfrnixDhxbvuLMx14f8m9Ge25YIYNFgQ9uSz5 ONXyg8PUPG4nDVg23OxONJzinJhYxi3YWJ89/aTJsrumZqeFrIz3cUhOTmwFUTBqQs8E ZlTw== X-Gm-Message-State: AOUpUlHm6ukz4wSr8KaxsC8x1YXUGbnC39QJDcHrNjh9q7L6kA5nBgNZ aVxqUv6CI5wTJ1AlswPg6fru8MPBa3w= X-Received: by 2002:a62:dc8f:: with SMTP id c15-v6mr6567689pfl.155.1531944411396; Wed, 18 Jul 2018 13:06:51 -0700 (PDT) Received: from cloudburst.twiddle.net (97-126-112-211.tukw.qwest.net. [97.126.112.211]) by smtp.gmail.com with ESMTPSA id 16-v6sm10796403pfo.164.2018.07.18.13.06.49 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 18 Jul 2018 13:06:50 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 18 Jul 2018 13:06:48 -0700 Message-Id: <20180718200648.22529-1-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::542 Subject: [Qemu-devel] [PATCH] linux-user/ppc: Implement swapcontext syscall X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-ppc@nongnu.org, alex.bennee@linaro.org, laurent@vivier.eu, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This allows the tests generated by debian-powerpc-user-cross to function properly, especially tests/test-coroutine. Technically this syscall is available to both ppc32 and ppc64, but only ppc32 glibc actually uses it. Thus the ppc64 path is untested. Signed-off-by: Richard Henderson --- linux-user/qemu.h | 2 ++ linux-user/ppc/signal.c | 56 +++++++++++++++++++++++++++++++++++++++++ linux-user/syscall.c | 6 +++++ 3 files changed, 64 insertions(+) -- 2.17.1 Tested-by: Alex Bennée Reviewed-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Laurent Vivier diff --git a/linux-user/qemu.h b/linux-user/qemu.h index bb85c81aa4..e0963676c7 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -395,6 +395,8 @@ long do_sigreturn(CPUArchState *env); long do_rt_sigreturn(CPUArchState *env); abi_long do_sigaltstack(abi_ulong uss_addr, abi_ulong uoss_addr, abi_ulong sp); int do_sigprocmask(int how, const sigset_t *set, sigset_t *oldset); +abi_long do_swapcontext(CPUArchState *env, abi_ulong uold_ctx, + abi_ulong unew_ctx, abi_long ctx_size); /** * block_signals: block all signals while handling this guest syscall * diff --git a/linux-user/ppc/signal.c b/linux-user/ppc/signal.c index ef4c518f11..2ae120a2bc 100644 --- a/linux-user/ppc/signal.c +++ b/linux-user/ppc/signal.c @@ -675,3 +675,59 @@ sigsegv: force_sig(TARGET_SIGSEGV); return -TARGET_QEMU_ESIGRETURN; } + +/* This syscall implements {get,set,swap}context for userland. */ +abi_long do_swapcontext(CPUArchState *env, abi_ulong uold_ctx, + abi_ulong unew_ctx, abi_long ctx_size) +{ + struct target_ucontext *uctx; + struct target_mcontext *mctx; + + /* For ppc32, ctx_size is "reserved for future use". + * For ppc64, we do not yet support the VSX extension. + */ + if (ctx_size < sizeof(struct target_ucontext)) { + return -TARGET_EINVAL; + } + + if (uold_ctx) { + TaskState *ts = (TaskState *)thread_cpu->opaque; + + if (!lock_user_struct(VERIFY_WRITE, uctx, uold_ctx, 1)) { + return -TARGET_EFAULT; + } + +#ifdef TARGET_PPC64 + mctx = &uctx->tuc_sigcontext.mcontext; +#else + /* ??? The kernel aligns the pointer down here into padding, but + * in setup_rt_frame we don't. Be self-compatible for now. + */ + mctx = &uctx->tuc_mcontext; + __put_user(h2g(mctx), &uctx->tuc_regs); +#endif + + save_user_regs(env, mctx); + host_to_target_sigset(&uctx->tuc_sigmask, &ts->signal_mask); + + unlock_user_struct(uctx, uold_ctx, 1); + } + + if (unew_ctx) { + int err; + + if (!lock_user_struct(VERIFY_READ, uctx, unew_ctx, 1)) { + return -TARGET_EFAULT; + } + err = do_setcontext(uctx, env, 0); + unlock_user_struct(uctx, unew_ctx, 1); + + if (err) { + /* We cannot return to a partially updated context. */ + force_sig(TARGET_SIGSEGV); + } + return -TARGET_QEMU_ESIGRETURN; + } + + return 0; +} diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 3df3bdffb2..dfc851cc35 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -12790,6 +12790,12 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, ret = get_errno(kcmp(arg1, arg2, arg3, arg4, arg5)); break; #endif +#ifdef TARGET_NR_swapcontext + case TARGET_NR_swapcontext: + /* PowerPC specific. */ + ret = do_swapcontext(cpu_env, arg1, arg2, arg3); + break; +#endif default: unimplemented: