From patchwork Thu Mar 19 09:26:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 184691 Delivered-To: patch@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp1726124ile; Thu, 19 Mar 2020 02:31:17 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtYJZQi+4VbMiuUSWpTQx2Z1K+ruqUfr7zwCcRlftqeDVswvwkGvYOgFVgYBy9xbEIkwywA X-Received: by 2002:a37:8346:: with SMTP id f67mr1890676qkd.61.1584610276690; Thu, 19 Mar 2020 02:31:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584610276; cv=none; d=google.com; s=arc-20160816; b=ayu4QnJyJCMSZD27stsdFcbL9t/+MZGjihV5Fn0sSDy6ZuRJKv79RalxxiJmmIblnY ddQz1XxW90o3/VDIdz4l834k3l3KDaZzAubzW23ZDzZ/1ABU2TpFfuSeNssHAB0wghl0 e8c0rxcwqs0rBpbeeWnj6dbI3t7pzPu18wmeHa3XkMOTambdH0TpPcWDfaEkVoAnLUqt bdyqfr0OpiPHMewutVSEITTHkHsvai8r/BlK6bGmvERTTdUBTSMar+EDFWOdXQvZVhrL jk3P4bv0tdNSCw1pugilr9g07tesmaMChRcft3toO94Lhd35ylAo9eNd+TaPd42VLMPp r61g== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from; bh=/3hzZ4Q/7OOMupgi1GAy71CgAejhzcfxgjtJ9mcuTTU=; b=nckyN+uJEuh8jHKChkqy9MWJOtef3LtFqG9JDzJjNuO7kYvONsRKI8ECqxBfANxfJL jNgQoYmAT6po5K9hg7khy2w4Gu6sox7T++Ajl7kHNZyzZkEbYd3hRNm/q9B5OfTtvo6+ a9huSELxFsHTsTIjKN+nhkNeweL3NVQT25BjPteGjMNORMXJcYui1lD8Xlz6ygti4stE Okb8gqZkWk0SX+02ahF5fXjZx2vSOJE3kJOmCLaYdlJzsqeO3s99R2/xTRTevPZCe7tX X/v1cS7OZ8oj6fa8D+KcIq9drXWzBqNu8UoUQi6BwmyE3vh+2JKpps3ItcY0yK4nJlG7 lc3A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id cn10si769794qvb.166.2020.03.19.02.31.16 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 19 Mar 2020 02:31:16 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1]:35312 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jErWG-0006jR-1k for patch@linaro.org; Thu, 19 Mar 2020 05:31:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40915) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jErRx-0005Os-3i for qemu-devel@nongnu.org; Thu, 19 Mar 2020 05:26:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jErRv-0004Dt-Qb for qemu-devel@nongnu.org; Thu, 19 Mar 2020 05:26:49 -0400 Received: from mout.kundenserver.de ([212.227.126.187]:46993) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jErRv-0004DI-HN for qemu-devel@nongnu.org; Thu, 19 Mar 2020 05:26:47 -0400 Received: from localhost.localdomain ([82.252.135.106]) by mrelayeu.kundenserver.de (mreue012 [212.227.15.167]) with ESMTPSA (Nemesis) id 1M2Plu-1jHbXC338g-003s6h; Thu, 19 Mar 2020 10:26:32 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL v3 01/16] target/i386: Renumber EXCP_SYSCALL Date: Thu, 19 Mar 2020 10:26:12 +0100 Message-Id: <20200319092627.51487-2-laurent@vivier.eu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200319092627.51487-1-laurent@vivier.eu> References: <20200319092627.51487-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:9HGTExg1wp02cp06LD11V11vWuFuKKYKX4/OK/2gXe1DIZUeoGB 20EERSaCpdqUGqmvoEI5Nh5SyjIg8L4mhrZdeCIPbKwI0Gjf19qkV3gN8tOT217QI8tqxR3 MacyWqyWWr2GP5UJBX2xKsgRjrw38DMnopCE2YVUrzxFd00Bwslcqgs4z28yAgPgh5D6klV sXCa+/K/tg4hnwL+oOVug== X-UI-Out-Filterresults: notjunk:1; V03:K0:FxU1ZPEB50I=:lLs9ykG/SKh10TtpeQvga9 3xc1ZjDSd4JD+c3LflwyHlBinrIL5T6zhC5+ZGG7uLmZFmZr/YnUo5vbVFbQJk1CzTAQW5CTv 2Rn/d8Y0A5hACnDVozwIopGFM5gufBtkiE27zhACx2v5URIjm4KjE/OnRb1pdyVAcvC4xoWNk btPGaIkXL9427j8aGW5Z+MVLRhihd5cgWMkPiZONIkFgsc3QdtXIzSL9omyjJduqIdeQXFGk2 XIizD/E4HdLXyMiNUG46VJ3yz2Av80fFz+Cs959Enrj6ULIQHYk4kZ4Cp6p82qyEK68Y5mAFh lXcjLd29krXI0H37ThxBSgB0bKzrl2HplqhR8P0Cn05YQdhnlLqEJQpynKPbIp/LZvKT99DbX 43k3b8nFui0DpGIO5NQlcbb8KrYzo43aJuFbutLTpiSK8LtWIGeKoVp4ejSqL0dS7DCGfWIsw i26GpZWy+uPcJhKqFydpDtgPJL0mHwYOAHWsel71O7vTmgCG41TtERbuW+371dmhZ1nLQO9px jXOeMxum8EUVdq5nXilxQSnRZp+9rOed0GNc3AMb7pEKRfa/wInerLKRr2YRDba0WM61/nRVV 4jm2nluxpbw4bv3OpYVcCYa3dKQgaPiWRxxPDZY77y1P24L2F1KxoIEMmdWY4wp7W0EySqMvR lZKzuUegDFnFeRDTflaGc4m1Eid3t0YQbG4FJtu4Ti5bLYSGHnr/Wd420yHpOtqHbCZmyFcbS v5GF98txBhFvB9kQBelwEKOil+1WMfkHUFglKDmh3wcmlIX+fjulWOrwWxKAg+/7MCNUqqlO9 e1ih0MTZinmNs9JfnMBBalqCB1vXcGQZXbPvUSvK3lP45qGLrTJ1tG0PyK0EEptEy+N7jEv X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.126.187 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Riku Voipio , Richard Henderson , Laurent Vivier , Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson We are not short of numbers for EXCP_*. There is no need to confuse things by having EXCP_VMEXIT and EXCP_SYSCALL overlap, even though the former is only used for system mode and the latter is only used for user mode. Reviewed-by: Paolo Bonzini Reviewed-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson Message-Id: <20200213032223.14643-2-richard.henderson@linaro.org> Signed-off-by: Laurent Vivier --- target/i386/cpu.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) -- 2.25.1 diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 576f309bbfc8..08b4422f36bd 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -999,9 +999,8 @@ typedef uint64_t FeatureWordArray[FEATURE_WORDS]; #define EXCP11_ALGN 17 #define EXCP12_MCHK 18 -#define EXCP_SYSCALL 0x100 /* only happens in user only emulation - for syscall instruction */ -#define EXCP_VMEXIT 0x100 +#define EXCP_VMEXIT 0x100 /* only for system emulation */ +#define EXCP_SYSCALL 0x101 /* only for user emulation */ /* i386-specific interrupt pending bits. */ #define CPU_INTERRUPT_POLL CPU_INTERRUPT_TGT_EXT_1 From patchwork Thu Mar 19 09:26:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 184692 Delivered-To: patch@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp1727213ile; Thu, 19 Mar 2020 02:32:16 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtd0k/HEVzoib0/rW12OAxrIZW58OgwYdB36euAh48se++wKAY48l9gPIk9yNgVGtmE8NSX X-Received: by 2002:ac8:7693:: with SMTP id g19mr1900916qtr.25.1584610336267; Thu, 19 Mar 2020 02:32:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584610336; cv=none; d=google.com; s=arc-20160816; b=TnA3HTDhSb/6Li1CrPprL1SIBhBIBE/cW08xMkdjWGDp0bo2WIFFOH+VRbCIE1TgEn OSfWHSo5emo3a25MmWabk0QHKJZVi5eoes58X0+DJZV4r55RizIo0aQrCc7FZBURVzi/ GTZVXkDxKPfpKMMnoFPMQrOwlE8PC1DO5nMgr3xUOjIQbguyXVRkJ8kxRtBcRRsZwDdk 4tSiNxvVY1tscPbTmWoaQWFTecJcsyELTWBZg9eUGYV0OtoXXFu2DpQYSoiRqPwY26EM vgcoZkKVLlpe4lRDsSrUPEVYopDcfVOToT+OBpK7hsfBmi3QRfYvvE77ahhJQRF7g/zu 2txQ== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from; bh=YEkw+BD3XM1DvhPhvynvQr2RL1QhFvPB4Cz5qQZtHws=; b=Dcz4ifQRR2DMC/jcmFQmGlJFq4zw1qEJ6uW3EkDVglRyFXJABXUIGg+8jXFeoRxPKC Pmo0cUDi6f+bgDl8BY4l6LfKFptradNTN33YEuyxK9X70T4NEhnvolwPbMl7MT+UZjZE WX/mCZkSQNhbWv4jjdCrW65HCqSGdvBIqhdfIJCmeORS33FaBDH8IMK/z3agRBFR8ofw Jk7qecGEPl60b9kD6YGo2aH9HJ2jqjsfdk+wHL6Bec7yd3JATHS2q4fEE1ZCJ8JVcN0d ejvS1twASWNtkyS2nPDfrrCRSh2PlOcCj/koHjuJr+Rkn+U8ajqgBdAA3QYvr3Y2xGgJ sqWA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id j3si806082qth.72.2020.03.19.02.32.16 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 19 Mar 2020 02:32:16 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1]:35324 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jErXD-0007TX-PT for patch@linaro.org; Thu, 19 Mar 2020 05:32:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40944) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jErRy-0005QJ-26 for qemu-devel@nongnu.org; Thu, 19 Mar 2020 05:26:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jErRw-0004EV-Du for qemu-devel@nongnu.org; Thu, 19 Mar 2020 05:26:49 -0400 Received: from mout.kundenserver.de ([212.227.126.131]:51571) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jErRw-0004DR-4x for qemu-devel@nongnu.org; Thu, 19 Mar 2020 05:26:48 -0400 Received: from localhost.localdomain ([82.252.135.106]) by mrelayeu.kundenserver.de (mreue012 [212.227.15.167]) with ESMTPSA (Nemesis) id 1Mth79-1jZ8Q21ls7-00v9Ha; Thu, 19 Mar 2020 10:26:33 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL v3 02/16] linux-user/i386: Split out gen_signal Date: Thu, 19 Mar 2020 10:26:13 +0100 Message-Id: <20200319092627.51487-3-laurent@vivier.eu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200319092627.51487-1-laurent@vivier.eu> References: <20200319092627.51487-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:Jo0Z5G9FVg3jJZgoxBWz3muaUTKrn2C79oThQC79xGBX9ZzU5vD sl7a07mQeF+whjDliZZ3OGM0oB2LWTxvhJ0YJ95IiTuG9X8SxRS3PZjqVedRXwleF2HIr4T 01PXr/dLGELE4NyVuaHZahbL7u4djtmA2eWpcR8RejTe+SxfVJiQlr4KoiLzj7kevZG5rWK cGXHWrPUzTHX8365X0/pA== X-UI-Out-Filterresults: notjunk:1; V03:K0:JfugAy3XM0Y=:G69lrxU3U3YcdUVFgjFWDC sN70aZ1ihMyPfrhBlMrz9O1n2/oXm9nTcYgAbalD5emeVcEkvXtXLAMZpDGCmJPRquUUWBr55 dWVsJ1AQ7+PxiiypqJAH67s+2kKM2CabtJv3RiueyJWuKwxkkV5qkmoD+U5J4pNiGbov5ehUO Ehv3tBC/w6Sx1PcoMwa/8MIPckLLQJMqogBycdgLaVmyrSn0s3Onb2UFnLw6Ujs3XGzwwxHFy Cgw6V734nf5J2N32jNSi23LPnC7gzVZh2LDnG+r29ktpI4DspnOzkKRMS3AV60BMsvYNbLTMM OK2utjcpfkPmpQc+Nh1Ibg1U+IOZoMXfWEShl7aZACIh2yWWzSYzil6OGcE+Wf4HXRxllTsZO E3GDeiC0e1fAsvNIt6RwX+UUyjIY+qQRGnQ/q7YuX3akAjnew+54kpviTIhfZMCHkuCafLHZ3 xItJjnxAubGSjRL6RxBaquHFcdLOtq7PGe/6O4dHoPt2ydVIxj7PrXxtq6k0I6ksMxspF1o9m ANl86/s42cNz37IWGkjJrT+GPPLOCYv3mTPxhGPpLY+tFi7ei5X+7udunQs8C/Sp2ydyd+EhX sNpxattLo11b90jRKjw+VEXyokRbX69wb/eqI1NluLHnmthQNfy0hoRd8bIMgcTB2hIEB+2Lb KSvVUUOi83s4O7EUhxija9uWq9sI6FuZvqG5RxTf6s2fa1P/IFLhFsrGi8NiQiMc8xl9mxu2y t8oSBwEw/nmWswZMatbWQBfPVKS1jaQONehET9j6AcZ26XwG3+tt+g91khOJg4AcBV0NBM79A VjQ5wJelN3rWvtxQW1PJgeCkVJocvUAeqOWZLsMRUVMZwLV1BZFqLs7jMgvjd+jkeAMaZbZ X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.126.131 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Riku Voipio , Richard Henderson , Laurent Vivier , Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson This is a bit tidier than open-coding the 5 lines necessary to initialize the target_siginfo_t. In addition, this zeros the remaining bytes of the target_siginfo_t, rather than passing in garbage. Reviewed-by: Paolo Bonzini Reviewed-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson Message-Id: <20200213032223.14643-3-richard.henderson@linaro.org> Signed-off-by: Laurent Vivier --- linux-user/i386/cpu_loop.c | 93 ++++++++++++++------------------------ 1 file changed, 33 insertions(+), 60 deletions(-) -- 2.25.1 diff --git a/linux-user/i386/cpu_loop.c b/linux-user/i386/cpu_loop.c index 024b6f4d588c..e217cca5ee1e 100644 --- a/linux-user/i386/cpu_loop.c +++ b/linux-user/i386/cpu_loop.c @@ -81,13 +81,23 @@ static void set_idt(int n, unsigned int dpl) } #endif +static void gen_signal(CPUX86State *env, int sig, int code, abi_ptr addr) +{ + target_siginfo_t info = { + .si_signo = sig, + .si_code = code, + ._sifields._sigfault._addr = addr + }; + + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); +} + void cpu_loop(CPUX86State *env) { CPUState *cs = env_cpu(env); int trapnr; abi_ulong pc; abi_ulong ret; - target_siginfo_t info; for(;;) { cpu_exec_start(cs); @@ -134,70 +144,45 @@ void cpu_loop(CPUX86State *env) #endif case EXCP0B_NOSEG: case EXCP0C_STACK: - info.si_signo = TARGET_SIGBUS; - info.si_errno = 0; - info.si_code = TARGET_SI_KERNEL; - info._sifields._sigfault._addr = 0; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + gen_signal(env, TARGET_SIGBUS, TARGET_SI_KERNEL, 0); break; case EXCP0D_GPF: /* XXX: potential problem if ABI32 */ #ifndef TARGET_X86_64 if (env->eflags & VM_MASK) { handle_vm86_fault(env); - } else -#endif - { - info.si_signo = TARGET_SIGSEGV; - info.si_errno = 0; - info.si_code = TARGET_SI_KERNEL; - info._sifields._sigfault._addr = 0; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + break; } +#endif + gen_signal(env, TARGET_SIGSEGV, TARGET_SI_KERNEL, 0); break; case EXCP0E_PAGE: - info.si_signo = TARGET_SIGSEGV; - info.si_errno = 0; - if (!(env->error_code & 1)) - info.si_code = TARGET_SEGV_MAPERR; - else - info.si_code = TARGET_SEGV_ACCERR; - info._sifields._sigfault._addr = env->cr[2]; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + gen_signal(env, TARGET_SIGSEGV, + (env->error_code & 1 ? + TARGET_SEGV_ACCERR : TARGET_SEGV_MAPERR), + env->cr[2]); break; case EXCP00_DIVZ: #ifndef TARGET_X86_64 if (env->eflags & VM_MASK) { handle_vm86_trap(env, trapnr); - } else -#endif - { - /* division by zero */ - info.si_signo = TARGET_SIGFPE; - info.si_errno = 0; - info.si_code = TARGET_FPE_INTDIV; - info._sifields._sigfault._addr = env->eip; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + break; } +#endif + gen_signal(env, TARGET_SIGFPE, TARGET_FPE_INTDIV, env->eip); break; case EXCP01_DB: case EXCP03_INT3: #ifndef TARGET_X86_64 if (env->eflags & VM_MASK) { handle_vm86_trap(env, trapnr); - } else + break; + } #endif - { - info.si_signo = TARGET_SIGTRAP; - info.si_errno = 0; - if (trapnr == EXCP01_DB) { - info.si_code = TARGET_TRAP_BRKPT; - info._sifields._sigfault._addr = env->eip; - } else { - info.si_code = TARGET_SI_KERNEL; - info._sifields._sigfault._addr = 0; - } - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + if (trapnr == EXCP01_DB) { + gen_signal(env, TARGET_SIGTRAP, TARGET_TRAP_BRKPT, env->eip); + } else { + gen_signal(env, TARGET_SIGTRAP, TARGET_SI_KERNEL, 0); } break; case EXCP04_INTO: @@ -205,31 +190,19 @@ void cpu_loop(CPUX86State *env) #ifndef TARGET_X86_64 if (env->eflags & VM_MASK) { handle_vm86_trap(env, trapnr); - } else -#endif - { - info.si_signo = TARGET_SIGSEGV; - info.si_errno = 0; - info.si_code = TARGET_SI_KERNEL; - info._sifields._sigfault._addr = 0; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + break; } +#endif + gen_signal(env, TARGET_SIGSEGV, TARGET_SI_KERNEL, 0); break; case EXCP06_ILLOP: - info.si_signo = TARGET_SIGILL; - info.si_errno = 0; - info.si_code = TARGET_ILL_ILLOPN; - info._sifields._sigfault._addr = env->eip; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + gen_signal(env, TARGET_SIGILL, TARGET_ILL_ILLOPN, env->eip); break; case EXCP_INTERRUPT: /* just indicate that signals should be handled asap */ break; case EXCP_DEBUG: - info.si_signo = TARGET_SIGTRAP; - info.si_errno = 0; - info.si_code = TARGET_TRAP_BRKPT; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + gen_signal(env, TARGET_SIGTRAP, TARGET_TRAP_BRKPT, 0); break; case EXCP_ATOMIC: cpu_exec_step_atomic(cs); From patchwork Thu Mar 19 09:26:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 184689 Delivered-To: patch@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp1723214ile; Thu, 19 Mar 2020 02:28:07 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuUbjCBZv9dzCffXdv5u/8TRyAN8gOTTK/TAANcx6gCBoZHWZJYL6sSUVfrbslIfAlEML6i X-Received: by 2002:a37:b101:: with SMTP id a1mr1966883qkf.197.1584610087471; Thu, 19 Mar 2020 02:28:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584610087; cv=none; d=google.com; s=arc-20160816; b=hlIVFdem9yFqf33ttFy3ty7HjWptuM4BCVkyolo+h0zH+TYXavVBpqTPdRpI3vL+z9 CbzDxMqtA5CKLSMrFuUS4LvvnXBcHK5k6Qi2HlZnmYaDGax13rTrfJLz6xF9pYqieN5n 8M9BaOZChs/m/F8kZxf4JCS08sKotCxPDBn7/AHKIZakkLJSUkccDZuBcIpyzIweqrW1 hXpHf17/j3iuHtk3vhbz9xZ3ukwtyO4VnPtfBAOWAZDVVqwa6ytE5LHSM2WUiSYF6tsx GbLHZUBWa+utc8Lfs1UCKQJTLpQOGfVkywGnjf0dQIGPmh9mw1X+c9dCNnbb+p1IBztz 3OqA== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from; bh=HBlV5vK8a7BFVxhmdIPp/khOgln0WXiH8MYxznwUTsg=; b=WPt2vECK1iABPtrx2ycqJfcLEEODGkCfuSn2r4IZpQfaawpW0ki8qYc2EK/YRC6xSe c5isr2gICJ2h254Mt33B28cmEZyS+jtqbE466zKuySVvn81Y+ea3Ux0mm2LenHkqg3Xu zb/7ZKnDu+pRXNv3ETftFBbtahtCI2PXwnJnWlNssDp4XP2hMe8X6RAwg5I8Ty8rzgSr 9DRmkHKG56nY+SZaEnCNql8WSe5lI+Nh0vua9CTdK9g6/6tzxgXG/lwCq/Loa7Wy3XlU 1X/lRT2llba2UxZ/u8zY2FssYhmEOmdwVIAaF2mom9p+a/bt3C/9sWiNZkP383S1vDVM jSPA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id j37si823859qte.263.2020.03.19.02.28.07 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 19 Mar 2020 02:28:07 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1]:35250 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jErTC-0000Bn-TY for patch@linaro.org; Thu, 19 Mar 2020 05:28:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40820) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jErRq-0005DH-Mn for qemu-devel@nongnu.org; Thu, 19 Mar 2020 05:26:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jErRp-000488-8V for qemu-devel@nongnu.org; Thu, 19 Mar 2020 05:26:42 -0400 Received: from mout.kundenserver.de ([212.227.126.134]:59829) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jErRo-00044i-VO for qemu-devel@nongnu.org; Thu, 19 Mar 2020 05:26:41 -0400 Received: from localhost.localdomain ([82.252.135.106]) by mrelayeu.kundenserver.de (mreue012 [212.227.15.167]) with ESMTPSA (Nemesis) id 1Mpkwn-1jdy0F05yX-00q9MK; Thu, 19 Mar 2020 10:26:34 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL v3 03/16] linux-user/i386: Emulate x86_64 vsyscalls Date: Thu, 19 Mar 2020 10:26:14 +0100 Message-Id: <20200319092627.51487-4-laurent@vivier.eu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200319092627.51487-1-laurent@vivier.eu> References: <20200319092627.51487-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:nZQ3FBqNzQhrqOP5mWCt76B83fNEBxa51x7BfenTNo8DnmjVtP3 b0VqPquMvR2xeck7/JTVcMELFL25GO/+HFvkb95+cjNjHKMBuOD+760U/AodcAlqAMZnS56 VEBueio5q2kGiHeuWuXobzaMMWu+3HRyBIc/bddEZ8xL90/jmXKGSXYZE5+tFjvaO1zOY14 1JnwCbhRsWNc/WBrbMXCg== X-UI-Out-Filterresults: notjunk:1; V03:K0:GlgdFC3RNPE=:H4zz2fdGY1sZOV9p3v9HiU c3zyAwE5Ths8NQ/01/StHVdJmi7FZYFls8HjHGLKHNILx/NkzlxlwiNGjzRjCtWY9DEpGmsUE JV91X9S3J6QhEKnHbDqFsj6RoyY4eeIOufeUfW7cHBwUi6lNOPo7ysdN9M7R/69LZZ1HNi1Ps tx54Oh5sze/ASaIPElVLs3qsAvkrpRNsFSZwJW5suY6p7L0bitwCO6uKqYM/X/s3YoM0HyrRK fpOnYVhTpY0f3WwFPp7/P3gHM5dwTok8QUECQUTcNGy3ukxAqtIx3lw4YEsjfvnTkjbZOmuF7 eREaxHMLLRGbR9MTDu2BR8aZTsituxAB9+EraxRntFF7U5Eij+s2Ir/bhWm++usQWk6gkUfLR HgN35wS/iMk8IQkMh7qk8ylH668uOXMrvUU/zzGXxZrnHrtjaz7aqBv1EmO9jQwEO9t/Rsmz8 e2ylCs/501bdNs25Hnoq7ZG6Y/27qvdrzF68nhBquKNAUdqXQNJcFBkH3f+OybiUkgqDR8Gjr u37fJOCgOuL+YBtAeL3bS3cj7nz83t6dBUXylGYiAdw50CF+lwXIK0w8jFQ76l7AGaEzxpkSB M/Aq0nkcpnB9VZ8gS7YNdN3HHxh1x5DXhtLPxDsERubpscFOpPdcfGmqfi+7k2pB5QZbNv/Jj QtQ4Ptc1AdXeGfkybEvY6wxPhTWA58pfqy+/ru9OCceQuRznhdCCyhafuvJp4avdbcEsWpFNz 0+aP2JkFN53y84Wv37lDQq2QWUCshoW5nFriyZY6RLBna1IDaDD0u6nIop1IF9InP1gGBiiE2 hW3TTdkLdEatrhnna3c8Oa8AF3G9/jqFw5w7egBITKik+mBC1ASZRFtYF3ltyKiRkNJ8gTS X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.126.134 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Riku Voipio , Richard Henderson , Laurent Vivier Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson Notice the magic page during translate, much like we already do for the arm32 commpage. At runtime, raise an exception to return cpu_loop for emulation. Reviewed-by: Paolo Bonzini Signed-off-by: Richard Henderson Message-Id: <20200213032223.14643-4-richard.henderson@linaro.org> Signed-off-by: Laurent Vivier --- linux-user/i386/cpu_loop.c | 108 +++++++++++++++++++++++++++++++++++++ target/i386/cpu.h | 7 +++ target/i386/translate.c | 14 ++++- 3 files changed, 128 insertions(+), 1 deletion(-) -- 2.25.1 diff --git a/linux-user/i386/cpu_loop.c b/linux-user/i386/cpu_loop.c index e217cca5ee1e..70cde417e605 100644 --- a/linux-user/i386/cpu_loop.c +++ b/linux-user/i386/cpu_loop.c @@ -92,6 +92,109 @@ static void gen_signal(CPUX86State *env, int sig, int code, abi_ptr addr) queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); } +#ifdef TARGET_X86_64 +static bool write_ok_or_segv(CPUX86State *env, abi_ptr addr, size_t len) +{ + /* + * For all the vsyscalls, NULL means "don't write anything" not + * "write it at address 0". + */ + if (addr == 0 || access_ok(VERIFY_WRITE, addr, len)) { + return true; + } + + env->error_code = PG_ERROR_W_MASK | PG_ERROR_U_MASK; + gen_signal(env, TARGET_SIGSEGV, TARGET_SEGV_MAPERR, addr); + return false; +} + +/* + * Since v3.1, the kernel traps and emulates the vsyscall page. + * Entry points other than the official generate SIGSEGV. + */ +static void emulate_vsyscall(CPUX86State *env) +{ + int syscall; + abi_ulong ret; + uint64_t caller; + + /* + * Validate the entry point. We have already validated the page + * during translation to get here; now verify the offset. + */ + switch (env->eip & ~TARGET_PAGE_MASK) { + case 0x000: + syscall = TARGET_NR_gettimeofday; + break; + case 0x400: + syscall = TARGET_NR_time; + break; + case 0x800: + syscall = TARGET_NR_getcpu; + break; + default: + goto sigsegv; + } + + /* + * Validate the return address. + * Note that the kernel treats this the same as an invalid entry point. + */ + if (get_user_u64(caller, env->regs[R_ESP])) { + goto sigsegv; + } + + /* + * Validate the the pointer arguments. + */ + switch (syscall) { + case TARGET_NR_gettimeofday: + if (!write_ok_or_segv(env, env->regs[R_EDI], + sizeof(struct target_timeval)) || + !write_ok_or_segv(env, env->regs[R_ESI], + sizeof(struct target_timezone))) { + return; + } + break; + case TARGET_NR_time: + if (!write_ok_or_segv(env, env->regs[R_EDI], sizeof(abi_long))) { + return; + } + break; + case TARGET_NR_getcpu: + if (!write_ok_or_segv(env, env->regs[R_EDI], sizeof(uint32_t)) || + !write_ok_or_segv(env, env->regs[R_ESI], sizeof(uint32_t))) { + return; + } + break; + default: + g_assert_not_reached(); + } + + /* + * Perform the syscall. None of the vsyscalls should need restarting. + */ + ret = do_syscall(env, syscall, env->regs[R_EDI], env->regs[R_ESI], + env->regs[R_EDX], env->regs[10], env->regs[8], + env->regs[9], 0, 0); + g_assert(ret != -TARGET_ERESTARTSYS); + g_assert(ret != -TARGET_QEMU_ESIGRETURN); + if (ret == -TARGET_EFAULT) { + goto sigsegv; + } + env->regs[R_EAX] = ret; + + /* Emulate a ret instruction to leave the vsyscall page. */ + env->eip = caller; + env->regs[R_ESP] += 8; + return; + + sigsegv: + /* Like force_sig(SIGSEGV). */ + gen_signal(env, TARGET_SIGSEGV, TARGET_SI_KERNEL, 0); +} +#endif + void cpu_loop(CPUX86State *env) { CPUState *cs = env_cpu(env); @@ -141,6 +244,11 @@ void cpu_loop(CPUX86State *env) env->regs[R_EAX] = ret; } break; +#endif +#ifdef TARGET_X86_64 + case EXCP_VSYSCALL: + emulate_vsyscall(env); + break; #endif case EXCP0B_NOSEG: case EXCP0C_STACK: diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 08b4422f36bd..39be555db3da 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1001,6 +1001,7 @@ typedef uint64_t FeatureWordArray[FEATURE_WORDS]; #define EXCP_VMEXIT 0x100 /* only for system emulation */ #define EXCP_SYSCALL 0x101 /* only for user emulation */ +#define EXCP_VSYSCALL 0x102 /* only for user emulation */ /* i386-specific interrupt pending bits. */ #define CPU_INTERRUPT_POLL CPU_INTERRUPT_TGT_EXT_1 @@ -2215,4 +2216,10 @@ static inline bool hyperv_feat_enabled(X86CPU *cpu, int feat) return !!(cpu->hyperv_features & BIT(feat)); } +#if defined(TARGET_X86_64) && \ + defined(CONFIG_USER_ONLY) && \ + defined(CONFIG_LINUX) +# define TARGET_VSYSCALL_PAGE (UINT64_C(-10) << 20) +#endif + #endif /* I386_CPU_H */ diff --git a/target/i386/translate.c b/target/i386/translate.c index d9af8f4078b3..5e5dbb41b0ce 100644 --- a/target/i386/translate.c +++ b/target/i386/translate.c @@ -8555,7 +8555,19 @@ static bool i386_tr_breakpoint_check(DisasContextBase *dcbase, CPUState *cpu, static void i386_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu) { DisasContext *dc = container_of(dcbase, DisasContext, base); - target_ulong pc_next = disas_insn(dc, cpu); + target_ulong pc_next; + +#ifdef TARGET_VSYSCALL_PAGE + /* + * Detect entry into the vsyscall page and invoke the syscall. + */ + if ((dc->base.pc_next & TARGET_PAGE_MASK) == TARGET_VSYSCALL_PAGE) { + gen_exception(dc, EXCP_VSYSCALL, dc->base.pc_next); + return; + } +#endif + + pc_next = disas_insn(dc, cpu); if (dc->tf || (dc->base.tb->flags & HF_INHIBIT_IRQ_MASK)) { /* if single step mode, we generate only one instruction and From patchwork Thu Mar 19 09:26:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 184688 Delivered-To: patch@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp1723083ile; Thu, 19 Mar 2020 02:27:59 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvevx0GlAXPD+zev6MsfT3GAxWECBTsAMAbSI7cMq5QO9VICBrfuQH1RzWrPOO0qke9vdBE X-Received: by 2002:a37:5907:: with SMTP id n7mr1957572qkb.227.1584610079315; Thu, 19 Mar 2020 02:27:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584610079; cv=none; d=google.com; s=arc-20160816; b=Hln9HkhwjTKm1u+2YvD9Uq8+BE7G/wemsfP1r1C4nuw5Go4fQmJNuN9cYXJTt5oTFN 8Tb/dH/17jhwwriGBlSs0oElPys6yOWXZ9Hw4FTWITMK7Y9/tx5In+BTZ2OMOrUovHyc OcfMeBgkn2wyLB/v+Xwcj8NhCYiCSx8k364vlfct61OwPMMAKcODwsrsYm6/yvxiBDM2 QHGBHUDzTjhFr7wevYdD9P0LyO3RDU3wJiwDgLKND9dQVviHb3ja1uROdfbLU0Fy6JCp QK6lV+Ou6SJVpWcQukUTVb68cvZiMeTCy9jRRLkEv3xNLeoysS4StdMEMDIway5g33/F rKhA== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from; bh=sBpnDqxru+s9MpUXr4dKG0QfltM7MVlV2/ENFhwXKvk=; b=jgxP4zuyr7eN9NovBQX4VALtKFoZK//m9hBiGdXTQK5OL6hD27sCT9rrq0Zc+E7dHh hh4bJ2uAycEaR9JZZHzBUw04DyYtw+dRfPUe6iM+AoLIPy4+DoRi49fQ1VlCyWSqxKmL V4uclbsJysj9RIevs56MY8BzkRo2kyUVvGQTdh4mGIZdPVPre2oUxTMQBNBlcbJSOPF+ B31hXBD4ja6UIT4+QNiV1izCsjI9iAoGhEv8RiNtt3TcD6CZQA/r0eAZ1bZtQmzYU5uc Ocxn0n1kAiO4qXVDJXJGS16ZiF6qdjTViNirHmSSUhIXJlZJWV6m5WJZaDjWd9ioJnfN oMpA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id t9si810032qvv.61.2020.03.19.02.27.59 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 19 Mar 2020 02:27:59 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1]:35242 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jErT4-0008Go-OG for patch@linaro.org; Thu, 19 Mar 2020 05:27:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40786) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jErRn-0005Cr-Qu for qemu-devel@nongnu.org; Thu, 19 Mar 2020 05:26:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jErRm-0003zC-QF for qemu-devel@nongnu.org; Thu, 19 Mar 2020 05:26:39 -0400 Received: from mout.kundenserver.de ([212.227.126.130]:41479) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jErRm-0003uH-Hi for qemu-devel@nongnu.org; Thu, 19 Mar 2020 05:26:38 -0400 Received: from localhost.localdomain ([82.252.135.106]) by mrelayeu.kundenserver.de (mreue012 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MzkK9-1jRyUF2MV7-00vghs; Thu, 19 Mar 2020 10:26:34 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL v3 04/16] linux-user: Add x86_64 vsyscall page to /proc/self/maps Date: Thu, 19 Mar 2020 10:26:15 +0100 Message-Id: <20200319092627.51487-5-laurent@vivier.eu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200319092627.51487-1-laurent@vivier.eu> References: <20200319092627.51487-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:Sgje0iFrVPMb2dQMJ0RAnWbHBX/NKwa72+1hEXPBC8ZRpsF/lQz JJLjCn6KXzrrmrh5Cko64vSzRlCqZOh0n0NAlkViYBO9kErl5adXYgAoyhBHFZbpi2ddG5r UFQNEjAWhrcFmg/V1Hw1jG6CAmAYO6ErR+h6N6HeE5ZnkbCeEAV7au4ZUo8ssbmTrSQe3V4 mgpK+5fhFMFCbr1bjd4Sg== X-UI-Out-Filterresults: notjunk:1; V03:K0:/yUYey2NAI0=:qu1ieyKu6NOSvSU4dgJKDo KTQjX48b3F19iNScHWMHer67nlD6XUTXzlLoow6Gx1F/3DvYr8pMcZ3cwQK8aiNmM0JIfXm1w 8CXA8/gvKPpDPc20Ti+voNvo0ip/02WFUKKwzhDshyk5nufBVYFF+RH4aQZMv/6mtJy5W2lvS hKCWC2w375FZW8HG2DbtzrYX5FUpkm8ieeu/Yt1rjkks1KFl+lMOCSfg5lyzbz/BG/rvtlaPQ 82nVaj7gAHfzCrlm6yDY/fEqxW3Mv0NSiNP24isrPV0nOTTZHuZLQJTdUzQRzIUltijTcT2Nd Wy/02PzXUWy9g1ChSqOB/iXJ7AFZnCIWdKjTL/M2gP40B/71lygWlS8sA5EUXmmZ00vJtDWnD 28Ppq/3zNbxmNxiGIfTLUx2MdBqlDim5vMP5G3OEfqOp6hAcWrRzCXpVtj5BTUiKfKAA2vdx/ RuQMMOoAOvPHzE8OsFMh8Q1CUYtlNEZstj1lpq9Xc4rowWViCHPloqRd2/C+ciAhtMd0DLWJx iZOBN6Syovhh8Ge1ZStv3FmtKU3YjLQtgWy9dUCNAo6CVVfLER6eguCc3KOjjcvZyEztcfc2V LwGUXm98U7aLBeXwevXcEOmGV6vCkfTxydOgpgMzKge8Ly1Ym5gmOzayPZnNGX5c8C7SmtMGQ pQ24SWP0q7Qpi6OecPiieJfWiSg7DIHKE6rQfHCVtXYcrE/Xjapty5j6QL0NmKk3ewj4I3VI9 g2hUxg6omzCrodLxCGwvjhuJk54wjtJF8hjS+mUWA5+PsVe2L5alBfU47DrseFJtZ9s53akN1 UB7KEjEEQFxNrY8Y9r+eYk9TucU1KKNDSC1Io71fcKiXwOB/rMBwOv4W3iZi8dsV2K/Evbn X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.126.130 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Riku Voipio , Richard Henderson , Laurent Vivier Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson The page isn't (necessarily) present in the host /proc/self/maps, and even if it might be it isn't present in page_flags, and even if it was it might not have the same set of page permissions. The easiest thing to do, particularly when it comes to the "[vsyscall]" note at the end of line, is to special case it. Signed-off-by: Richard Henderson Message-Id: <20200213032223.14643-5-richard.henderson@linaro.org> [lv: remove trailing whitespace] Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 10 ++++++++++ 1 file changed, 10 insertions(+) -- 2.25.1 diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 8d27d1080752..5479d67a10be 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -7079,6 +7079,16 @@ static int open_self_maps(void *cpu_env, int fd) } } +#ifdef TARGET_VSYSCALL_PAGE + /* + * We only support execution from the vsyscall page. + * This is as if CONFIG_LEGACY_VSYSCALL_XONLY=y from v5.3. + */ + dprintf(fd, TARGET_FMT_lx "-" TARGET_FMT_lx + " --xp 00000000 00:00 0 [vsyscall]\n", + TARGET_VSYSCALL_PAGE, TARGET_VSYSCALL_PAGE + TARGET_PAGE_SIZE); +#endif + free(line); fclose(fp); From patchwork Thu Mar 19 09:26:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 184690 Delivered-To: patch@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp1724682ile; Thu, 19 Mar 2020 02:29:51 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsk1kTk8ADTZow2pZovavcHwWFJzDESI6Sba1COj/fBBXtUDUlqq6+KTCcGb18WQUsN+NOG X-Received: by 2002:a37:b17:: with SMTP id 23mr2050801qkl.326.1584610191341; Thu, 19 Mar 2020 02:29:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584610191; cv=none; d=google.com; s=arc-20160816; b=q5qd1N5nVFmkFROiAKScj9V+NDUxWdcmYzVe9L5OH4DTUZtCagEtt+PJXJdaO8Dn8x z4oxJuu7II8KKiBmVBsdhprGiko2xTz5l96T7DcVdykTKXO7XsPMaXwZWM4Sy7E62yeS AxXdTGVDlqMJdalSDR2Sxx6Y0AQ0vxql+f26YO9aXotbPEMCq26gRpOmNWlrfmGhXOdy Ici3FMPLTd+cyPqfznoIeHrwCiJO71CYC/1yj1k2O03NbTRxHV4BmasR+CP9b+VtEpaO 7o/JGf3GvZ9fpT6FaxfEMYtfxPbrUKg8vzdf81HoCe+zKj92/Nm686CTpr80Ieh5oFdu UDAA== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from; bh=Q3zdwzqEbUj0sEDnLxYF3gBixyA795qVdjxv2jHwAWU=; b=p6ropZ10J0USyh/SjHLl4+p+LEjN30mn4DTFXqw9oBnYhlpKHaOc2jcpCaW+cp53Bk /08o6fFCjTQtiiXf1QoDp92JA4Dw6hjDsHKKODjB+jxvsmA9gZrJN7ol6tobCZD/QWuW 6VCzWZI8IhR4wbsa4qZ9c6GZLbt+UNuh8jGmuvTxXf3thvUzMdvKzlNGIQHWAnayIT2K UEt2TXPSpcFpd/8nUJeOMGLh9HJSDCRJLqR0OH7SRZNh/WwSV3Z+ZEIZtVGWOp4Jn85f E2WFyyaUc9OgFLu8C1twhG2G9X97358RVPY3nowPgBJQGQTtpYTiCjn+QXclCncjv1i5 7teA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id p58si857696qtk.18.2020.03.19.02.29.51 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 19 Mar 2020 02:29:51 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1]:35278 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jErUs-0003m8-T8 for patch@linaro.org; Thu, 19 Mar 2020 05:29:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40875) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jErRv-0005MQ-MY for qemu-devel@nongnu.org; Thu, 19 Mar 2020 05:26:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jErRu-0004D2-Gj for qemu-devel@nongnu.org; Thu, 19 Mar 2020 05:26:47 -0400 Received: from mout.kundenserver.de ([212.227.126.135]:40723) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jErRu-0004Ce-7I for qemu-devel@nongnu.org; Thu, 19 Mar 2020 05:26:46 -0400 Received: from localhost.localdomain ([82.252.135.106]) by mrelayeu.kundenserver.de (mreue012 [212.227.15.167]) with ESMTPSA (Nemesis) id 1Mw9oq-1jXlmB0qrU-00s8TV; Thu, 19 Mar 2020 10:26:35 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL v3 05/16] linux-user: Flush out implementation of gettimeofday Date: Thu, 19 Mar 2020 10:26:16 +0100 Message-Id: <20200319092627.51487-6-laurent@vivier.eu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200319092627.51487-1-laurent@vivier.eu> References: <20200319092627.51487-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:A1gRnY8zWnzS4FbXY6sw/gIdS9rOUf6PKVl0Fh7zabe1Ojordm3 j5Gv34XV1xEmN61PjkE9sUVX8be70NciUyXyGotX6s1PoGezB9kfMmIuYKO4kcJcjC93ABb GNd7QHnldbAve6Zg36G7ZJqMhaBFy6A+QGDBR5D9CqnxPGKRsxTMBXnh7xspkh/aZjpHgyG ozv8bXJw4Tg+7S/FFOMAQ== X-UI-Out-Filterresults: notjunk:1; V03:K0:eDuNZpO6p+w=:BkUi6WE3VEQf4xndonIecB 6XV0ZGNdHbWo1ocLy3J7d3hqL7h2UOQc7zLv4YP6i7XprYj+vKPSsYw93ORm+8WsmQIbNtT16 P+TTaVrO8a2Ojfy7Qh8VSKD/T/ROvb5K+CCRm4iX9ASuidnx9dC1DQdzS2V+VcgSwHVl+QJ82 wefAwIif8qHNerL2JRkck24XBmMjOVi0JO7UDom9W/XzzlWOamDeNI/CiP3y5zWWXDi2hKX4n hcj3H+DOB7E+JvcpxcYZU5aqRIDI6cl0LCYAU1YI+xMXLZmxmuwFpPSAiYcHp4RhUv/tPd+Qi Inf9B5Z82SkgSGr77+1sgp+qL8l//JyFB7c/K33RUuwZW3HNYjcOzW0Tpc4XzaHb4Mh2Jr8v5 TEp6I9/L2gG5QDI97ERhlkjy0AYvYYcwzokM34UqFHImRVbxjD3gg7VMlHKCu1LI5mGQoU6h6 DdVFC9OeMNKm8LhwqcAa1lQ1d90/GgwdiI5ZSSAepc2enkQxztB2uhD4umszWDYFQwxPdIdQO 3A4uK62KQ2YlcAdSVBfWFf545hm9ccqsQrKXp8b9CTW1iu6MJmogDKDy74aYqNyS2qfsE6I6B H8NmBIgazIMDgy8w5H69huIHUraBaAY05sCg/QTeApH7xKC+LvPu7Dh/qPG5cb0wO/AOeSDvS BAt1kLV87z+wENJgSmw85tlWCDuG64WmIzXgXlLkHfRsdXRZk7Oyc8+6ohZ8m42x71JWByRzD QKBBHdA9GrEccxXbJpW4FPO9mTR8K1JeUWVKs6WoQhtTomVcScFZlNWIwD9YPMirun3nDF9aR JO1ZaVN/7q3loOZ2ha8CREiFYWbuYnohsv66v3FAHchCDrmIgkVprr85qikrxouWhMKgP7J X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.126.135 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Riku Voipio , Richard Henderson , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?b?w6k=?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson The first argument, timeval, is allowed to be NULL. The second argument, timezone, was missing. While its use is deprecated, it is still present in the syscall. Reviewed-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson Message-Id: <20200213032223.14643-6-richard.henderson@linaro.org> Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) -- 2.25.1 diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 5479d67a10be..811495c3a0bc 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -1228,6 +1228,23 @@ static inline abi_long host_to_target_timespec64(abi_ulong target_addr, return 0; } +static inline abi_long copy_to_user_timezone(abi_ulong target_tz_addr, + struct timezone *tz) +{ + struct target_timezone *target_tz; + + if (!lock_user_struct(VERIFY_WRITE, target_tz, target_tz_addr, 1)) { + return -TARGET_EFAULT; + } + + __put_user(tz->tz_minuteswest, &target_tz->tz_minuteswest); + __put_user(tz->tz_dsttime, &target_tz->tz_dsttime); + + unlock_user_struct(target_tz, target_tz_addr, 1); + + return 0; +} + static inline abi_long copy_from_user_timezone(struct timezone *tz, abi_ulong target_tz_addr) { @@ -8642,10 +8659,16 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, case TARGET_NR_gettimeofday: { struct timeval tv; - ret = get_errno(gettimeofday(&tv, NULL)); + struct timezone tz; + + ret = get_errno(gettimeofday(&tv, &tz)); if (!is_error(ret)) { - if (copy_to_user_timeval(arg1, &tv)) + if (arg1 && copy_to_user_timeval(arg1, &tv)) { return -TARGET_EFAULT; + } + if (arg2 && copy_to_user_timezone(arg2, &tz)) { + return -TARGET_EFAULT; + } } } return ret;