From patchwork Sun Jun 10 03:00:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 138080 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp2575495lji; Sat, 9 Jun 2018 20:05:52 -0700 (PDT) X-Google-Smtp-Source: ADUXVKI1AXHR8RR7OsBcEpEDw+cpDMhqHQPsTcA24kx2hXqJXA0Zs/26gpTDLNDKQXKxiw9d8Ssf X-Received: by 2002:a37:10c4:: with SMTP id 65-v6mr10506284qkq.31.1528599952578; Sat, 09 Jun 2018 20:05:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528599952; cv=none; d=google.com; s=arc-20160816; b=yxvaXjUDjVc0RIyySYIOsAtsBgCzCw3yCdZsmkuC0kb/28i1ERG6HExFw8269UmluO uPcHmZfbvw12NDyoedsHfKPDJpc2StCPAAl6LiwiQ3vhTT/mfrTuMyW+8IBE9Ox1F9Mp n93wWcmXDu8ko7FWX2ffzxooUyG2XVBv1PuDVaFeJJYQWP6vha/I7UD9NWdeT+lqCanP jCxNMn0LxnF+5adTlc/8d/bK1SAGYVj33sZElDyLWY8LORGHZzsUAPBGuZ8NfTHkVVv9 AOjIIgtkO/LcbIPq9p9+WZjME39F3OjuIXqprkBBPIkLtte20h/p25sG0SxpVL67UXm9 uvqw== 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:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=hpaNMq1/oP2oPA//8l/SAajHBioV4Zg1sXyd+VtOq8c=; b=c9SJpQQ5ei23uGzSMSQ52QbtjZwsHFLA34EWNu90rsqBL9po4hYVFWAvvX+X4fv4EI sFJvxpdIedvkIt/AVzBAa8W0VjhbSTiKSbZshD0UO1VHF9k/NA6JqhqerVJNpj8am9HZ ieU+1rGwfACsuMpEchDjiq8EOhiioZ4dcIIxYggAJgI9L6RNvppZNUoO7pD9OtcV6QWm 0haAQ11jIvqQvcDQa98cSFkThRpTKIoos8zdIGHTM1sI2kobkpAo8KnBcBgUxUsKE8iZ ua4lPnjYqkcF7IKW/vKEqpBxh6TZOJPxHZKKXmjZip9DChIYI2VJDe6nopzK/eK4myHn gD/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=WQMRrScF; 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 h15-v6si958000qta.82.2018.06.09.20.05.52 for (version=TLS1 cipher=AES128-SHA bits=128/128); Sat, 09 Jun 2018 20:05:52 -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=WQMRrScF; 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]:42185 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRqfw-00048u-27 for patch@linaro.org; Sat, 09 Jun 2018 23:05:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40143) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRqd0-0001jk-Mv for qemu-devel@nongnu.org; Sat, 09 Jun 2018 23:02:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fRqcx-0003C9-Jh for qemu-devel@nongnu.org; Sat, 09 Jun 2018 23:02:50 -0400 Received: from mail-pg0-x242.google.com ([2607:f8b0:400e:c05::242]:44838) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fRqcx-0003Bm-Bp for qemu-devel@nongnu.org; Sat, 09 Jun 2018 23:02:47 -0400 Received: by mail-pg0-x242.google.com with SMTP id p21-v6so8127188pgd.11 for ; Sat, 09 Jun 2018 20:02:47 -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:in-reply-to:references; bh=hpaNMq1/oP2oPA//8l/SAajHBioV4Zg1sXyd+VtOq8c=; b=WQMRrScFtJ5rsj1a/+H/GziNQIAHADXJN6DXxsvEjwHdGINrUgv8NP3yPHWFTnNz/H ekqijGbfe0eg68cfKJo5ilytRgRAxYe8juHWi7zxRGpm4+TQHz3g70InFXGk74VXz0+z gxNyxqEb+laQnuVwWeyl+ilJyKVC5GoSiDl1g= 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:in-reply-to :references; bh=hpaNMq1/oP2oPA//8l/SAajHBioV4Zg1sXyd+VtOq8c=; b=SgmkqymgBEgqnp0Ki2FaoikSY66zgsOGTLUvmlZZnlN5yajOt1ydqrjKr0qUzF1fFg nPj46NgWEhYRojijta/DPwjOKOudTTMxvy1P+1xoAjV1d3ZWrgfWxMxFpyjeU76f+2/4 43TwWPCSbodtxHUDn6IIxvg9OekuMk51IfR+8FZaTCt50/xrn8XfQyKC2oFjsq/aQBeI Cvvxo0y0qKHxB5xYHRHeTlstamLRzqW5jSduH+ewWzpH5Iauw0zzyr6+HlxZx38+am4R Bsm323NShlC39yekF3fXuWDZ52JRvaeGVA5aiOlMPEDDsGeA4ef93GWbFsuFVeyOynoB lxqA== X-Gm-Message-State: APt69E2q9RzKev3y/LV3Sm0/jYSMPD458SVyy2DCH9xOkliPnMkg9q6v SCLkAzeRzYl5CfNVesL5Rxd0oAIJK5Q= X-Received: by 2002:a62:234a:: with SMTP id j71-v6mr11935177pfj.221.1528599766091; Sat, 09 Jun 2018 20:02:46 -0700 (PDT) Received: from cloudburst.twiddle.net (rrcs-173-198-77-219.west.biz.rr.com. [173.198.77.219]) by smtp.gmail.com with ESMTPSA id y17-v6sm31712718pfe.33.2018.06.09.20.02.44 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 09 Jun 2018 20:02:45 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Sat, 9 Jun 2018 17:00:41 -1000 Message-Id: <20180610030220.3777-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180610030220.3777-1-richard.henderson@linaro.org> References: <20180610030220.3777-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::242 Subject: [Qemu-devel] [PATCH v2 009/108] linux-user: Set up infrastructure for table-izing syscalls 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: laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" At the same time, split out set_robust_list and get_robust_list. Put them together, along with their block comment, at the top of syscall_table. Signed-off-by: Richard Henderson --- linux-user/syscall.c | 87 +++++++++++++++++++++++++++++++++----------- 1 file changed, 66 insertions(+), 21 deletions(-) -- 2.17.1 diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 46f123ee13..8678e749ee 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -7947,6 +7947,17 @@ static int host_to_target_cpu_mask(const unsigned long *host_mask, return 0; } +typedef abi_long impl_fn(void *cpu_env, unsigned num, abi_long arg1, + abi_long arg2, abi_long arg3, abi_long arg4, + abi_long arg5, abi_long arg6, abi_long arg7, + abi_long arg8); + +#define IMPL(NAME) \ +static abi_long impl_##NAME(void *cpu_env, unsigned num, abi_long arg1, \ + abi_long arg2, abi_long arg3, abi_long arg4, \ + abi_long arg5, abi_long arg6, abi_long arg7, \ + abi_long arg8) + /* This is an internal helper for do_syscall so that it is easier * to have a single return point, so that actions, such as logging * of syscall results, can be performed. @@ -11740,23 +11751,6 @@ static abi_long do_syscall1(void *cpu_env, unsigned num, abi_long arg1, return get_errno(safe_tgkill((int)arg1, (int)arg2, target_to_host_signal(arg3))); -#ifdef TARGET_NR_set_robust_list - case TARGET_NR_set_robust_list: - case TARGET_NR_get_robust_list: - /* The ABI for supporting robust futexes has userspace pass - * the kernel a pointer to a linked list which is updated by - * userspace after the syscall; the list is walked by the kernel - * when the thread exits. Since the linked list in QEMU guest - * memory isn't a valid linked list for the host and we have - * no way to reliably intercept the thread-death event, we can't - * support these. Silently return ENOSYS so that guest userspace - * falls back to a non-robust futex implementation (which should - * be OK except in the corner case of the guest crashing while - * holding a mutex that is shared with another process via - * shared memory). - */ - return -TARGET_ENOSYS; -#endif #if defined(TARGET_NR_utimensat) case TARGET_NR_utimensat: @@ -12412,6 +12406,54 @@ static abi_long do_syscall1(void *cpu_env, unsigned num, abi_long arg1, return ret; } +/* The default action for a syscall not listed in syscall_table is to + * log the missing syscall. If a syscall is intentionally emulated as + * not present, then list it with impl_enosys as the implementation, + * which will avoid the logging. + */ +IMPL(enosys) +{ + return -TARGET_ENOSYS; +} + +/* For a given syscall number, return a function implementing it. + * Do this via switch statement instead of table because some targets + * do not begin at 0 and others have a large split in the middle of + * the numbers. The compiler should be able to produce a dense table. + */ +static impl_fn *syscall_table(unsigned num) +{ +#define SYSCALL_WITH(X, Y) case TARGET_NR_##X: return impl_##Y +#define SYSCALL(X) SYSCALL_WITH(X, X) + + switch (num) { + /* The ABI for supporting robust futexes has userspace pass + * the kernel a pointer to a linked list which is updated by + * userspace after the syscall; the list is walked by the kernel + * when the thread exits. Since the linked list in QEMU guest + * memory isn't a valid linked list for the host and we have + * no way to reliably intercept the thread-death event, we can't + * support these. Silently return ENOSYS so that guest userspace + * falls back to a non-robust futex implementation (which should + * be OK except in the corner case of the guest crashing while + * holding a mutex that is shared with another process via + * shared memory). + */ + SYSCALL_WITH(get_robust_list, enosys); + SYSCALL_WITH(set_robust_list, enosys); + + /* + * Other syscalls listed in collation order, with '_' ignored. + */ + } + +#undef SYSCALL +#undef SYSCALL_WITH + + /* After do_syscall1 is fully split, this will be impl_enosys. */ + return do_syscall1; +} + abi_long do_syscall(void *cpu_env, unsigned num, abi_long arg1, abi_long arg2, abi_long arg3, abi_long arg4, abi_long arg5, abi_long arg6, abi_long arg7, @@ -12419,6 +12461,7 @@ abi_long do_syscall(void *cpu_env, unsigned num, abi_long arg1, { CPUState *cpu = ENV_GET_CPU(cpu_env); abi_long ret; + impl_fn *fn; #ifdef DEBUG_ERESTARTSYS /* Debug-only code for exercising the syscall-restart code paths @@ -12437,14 +12480,16 @@ abi_long do_syscall(void *cpu_env, unsigned num, abi_long arg1, trace_guest_user_syscall(cpu, num, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); + fn = syscall_table(num); + if (unlikely(do_strace)) { print_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6); - ret = do_syscall1(cpu_env, num, arg1, arg2, arg3, arg4, - arg5, arg6, arg7, arg8); + ret = fn(cpu_env, num, arg1, arg2, arg3, arg4, + arg5, arg6, arg7, arg8); print_syscall_ret(num, ret); } else { - ret = do_syscall1(cpu_env, num, arg1, arg2, arg3, arg4, - arg5, arg6, arg7, arg8); + ret = fn(cpu_env, num, arg1, arg2, arg3, arg4, + arg5, arg6, arg7, arg8); } trace_guest_user_syscall_ret(cpu, num, ret);