From patchwork Mon Mar 16 16:15: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: 184582 Delivered-To: patch@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp3104917ile; Mon, 16 Mar 2020 11:00:58 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuol87TB1u6vR7oluXaZzaCUZQLPhaPxgfbsQEYTI9NSo5vyfRD3urfSylpoH7bJI2ej9W5 X-Received: by 2002:ac8:2bf9:: with SMTP id n54mr1341602qtn.280.1584381658650; Mon, 16 Mar 2020 11:00:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584381658; cv=none; d=google.com; s=arc-20160816; b=wbZCxquHyl2bn3GlEcIeDFbSOWaMZDzbPoKQB8KgqDiXCy7WW6E0kVj1VS8P2PAr9y yS94qrWuV5Xpm5emaimACp829f+9BZojKEhIMoC2yVgfeENG3MAeKkyDL9Vaf1Qs3SY8 sI2uwjpWoiOnbjd9Q4mmM62K2yIzRlLEiXJmIoMs6QU13Z/UxTnpCIkkyu5V2W8NEmU4 0oR2qkiIT2ueh+NbGWnUV6uQCWf2r8MRPR5lilZudJTWU+cjlgzSliwu4K2iABiblr+c TqeXpQm/55Aimpj74IOxiGnnpt0DlP9DeLwZ4UywgewM9j+02LjVrvEhWYKIAPsbJX7u mzaQ== 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=DvfFmnvnzmdV7n16DCBpQl9zP7AFa8fWloX+1HPoKGE=; b=LtBvKH1K/STwQ3XxQCvza+GAvi4Q5s5nGiqE7DOLYNHTvvsj42U6UOTUeM6FnLomrh CpO3i6PcEzk+LXrl8pf6zUqsv2ZTMrrLYJY91YhFfGzLC2QqNbzr/JRhm6onIJqYAfug KnYGddp/KMCtBB4qNNx5aJGvaE8qklMilt2FfvCyyUvhq/BlzIBvKoCkdrih7WGNrrsD edl6LmPWRYvi4ZgBCaSIFGeMXZktyn776Gw0p+nA1VVMHATPPg/qLBMHDqYcBxp8FA0z X065IX+QVHOcMD1SvPI7rHdIaZ6QxAsZbaBdxkQoDSyJPg4R5IGuEG2lSGlsd/X+mEO+ JWqA== 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 m89si195866qte.202.2020.03.16.11.00.58 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Mar 2020 11:00:58 -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]:45150 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jDu2s-0003br-2D for patch@linaro.org; Mon, 16 Mar 2020 14:00:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40191) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jDsPb-0007tI-5C for qemu-devel@nongnu.org; Mon, 16 Mar 2020 12:16:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jDsPZ-0007no-Ql for qemu-devel@nongnu.org; Mon, 16 Mar 2020 12:16:19 -0400 Received: from mout.kundenserver.de ([212.227.126.133]:49757) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jDsPZ-0007d6-HV for qemu-devel@nongnu.org; Mon, 16 Mar 2020 12:16:17 -0400 Received: from localhost.localdomain ([82.252.135.106]) by mrelayeu.kundenserver.de (mreue012 [212.227.15.167]) with ESMTPSA (Nemesis) id 1Mmhs6-1jcRnQ0xeA-00jqdF; Mon, 16 Mar 2020 17:16:02 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 01/38] target/i386: Renumber EXCP_SYSCALL Date: Mon, 16 Mar 2020 17:15:13 +0100 Message-Id: <20200316161550.336150-2-laurent@vivier.eu> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200316161550.336150-1-laurent@vivier.eu> References: <20200316161550.336150-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:Hg9TaecfWGqylFxCaSMjU0Xvv3kM1cHLMv3Dww2adAN0L0Nu5K/ zxDvSi0i6WKP0yD7r5WDdCJeGGzZiwnWksXUKXn6p/+oK8EI/taRiGkl9jPMwbyLpbmD+l0 n8qtAdHBo0UokEQQrWQzF3H9+uUXsoi7Pnv5SgAlvw4zSR2limoKqVvHMXkQSe05JPM36fG pIUeFUjXJnsH3pebM/fMQ== X-UI-Out-Filterresults: notjunk:1; V03:K0:OPgmv/Ops7s=:Y24l7FXX7NrVtDsUpGnD0I YJPqMXb5VezVkjzt+PiVagokymx3AWYWHQwVfxWUH9PvwaXCVtPzG/qdAgMWF3RsaESuDQi1c ualncTB6x50iToASwTogzRGazczoyCtiZxlk+Oeexq85cUDbVmEX4LbKN9hTgC8WM+lRTzRDq 5YSNX/9bjGoosxxJ/jeqXyknQ7TZASgjpuPfVEaKpjmMOKM6esGD+dIjvrQMhmsfBrs8N8zuP zQNMKTHyaRFtV8iLnOdKCYSGSh05XGojmPDw4Ky8G7c9T1MbIN8JAUJnzh3xjWGVXf8JTpdQJ ElQbZ5zgLj7WUniXA1q9EPux/n3jGEasUBMNynJe6tZ9oBQTGhNfU8On1hOnmYDnHCrsu+IYg 9ceHwDGpz/fRcbtoXNy9fewpTVkCaaOYVI5+QC+Y4UyIHD5PYLNYRaXT5j+Wo5sbzMsto+TW0 PKMm47RNrWUamKHfBEA+SfbJbsqDvp/wG73Wbcj+9uSeCbhk24I0bqoR061xhP/IJTOGojupP csJgdUdHCEx5dYdbbHp2oXSLehdL6IGZomqW30porrgJFyrNOu/wn08Tbv2+o1XQMrH/ah8Hv gF0Y+FBf4Ld147/NP6IOiHQfcWTPimQOvSDOemEwI1nQ5bpv44IEJS5KjgBgMpYJBP3X0BvmP +oTsRgkDvZmcKg9Tkd5FogX8K+0SXjCjXPH7MhRzvPZghHcGFIssA8/HyzMm1adHcEaBhQ3cP Wp616lqqi06nzIVRsyw98BxXC6+pj5Z6QAkIWIWKJEWCJIMFpfneDYewnYKjvWqCzVIFpu8w2 s9YmEn30GCKJ3ob8/SIbJ4mkbG+lbgEKdh3dqT5QZAavlKNxWk47mv39JlY8EKWXhqdle2W X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.126.133 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.24.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 Mon Mar 16 16:15:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 184580 Delivered-To: patch@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp3102549ile; Mon, 16 Mar 2020 10:58:47 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuWxMd9x3mFJKCBV3ogRGmCxaO3jtgBTwGPzwTEzsBNHXTYBV+6rxqqz8zxlAjEgA8dCr3a X-Received: by 2002:ac8:6f6e:: with SMTP id u14mr1339202qtv.304.1584381527049; Mon, 16 Mar 2020 10:58:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584381527; cv=none; d=google.com; s=arc-20160816; b=FEu0OJqSz7OLKesJbMniXmb6qZPT0c0Kb+wGwI7w0u3/0mzLUjelKSFIUEbIAoWKJl 4AKpqE0J4nUu7OQdGOEADijxHaut2N3Fxo3REcsEAWTir6VVAUvYK4GLzNufTrdsHK1T 727HbDPMyt79pahcPEJj16YltlLAKv5eV1gGC5r6BqbI29GBnsIBwKneSfD8A0yvqqq0 46cK6qcUgaYEZOBFN4T8Ao29+SGWtwYoMBXwjhJwEun5VmkcN2GYw6Gc3Begx+u7jZEi FczFn/AemJCXhYFc/VYrkx9R6RdXsn+iYuX28vuVJozfA7GPTUorpCaA1mvJXFD+g9Eu Aj+Q== 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=Wjc2bWa1BgIXJOXmPfwioAw4KgPwMa6HOhu7IMy3hEQ=; b=qDcGe1Bo8JMmqAKoqeP6AnafQ3kkVHDiypnnHRRK6bwy2v2ysBeXJ1vKZdsxyzijTs eyX47e3LSdnHydCOK0T9kcoRl2V69s9aTUjbi2WdJqtswpuTOfRwYHCUC4tBEFZ4yOhh qpnWubVAWmlmrxOWnPW1Yf7sIPr86RLihbbbpTvnnmaREyu8sR4rI0xeJqGVus/RXn1a V+NY3iDOBtAbH31vEPHaMvXVfAyupp2b43XIF7CDx6VYOwKCgzopsXKlekG+gIPDf5JZ 4gD6sNdODVhy4fcBqNiFfsJwhqKqwgI9ky4mCgwxF2oFVDKqwhnWFNQKOG9zomCTE5Vf +WUQ== 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 r2si217414qte.140.2020.03.16.10.58.46 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Mar 2020 10:58:47 -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]:45104 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jDu0k-0008Tw-Ew for patch@linaro.org; Mon, 16 Mar 2020 13:58:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40120) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jDsPZ-0007si-BW for qemu-devel@nongnu.org; Mon, 16 Mar 2020 12:16:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jDsPX-0007Th-Vt for qemu-devel@nongnu.org; Mon, 16 Mar 2020 12:16:17 -0400 Received: from mout.kundenserver.de ([212.227.126.134]:43915) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jDsPX-0007Jc-Ll for qemu-devel@nongnu.org; Mon, 16 Mar 2020 12:16:15 -0400 Received: from localhost.localdomain ([82.252.135.106]) by mrelayeu.kundenserver.de (mreue012 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MpTpc-1jfE1Q2EZQ-00pryl; Mon, 16 Mar 2020 17:16:04 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 02/38] linux-user/i386: Split out gen_signal Date: Mon, 16 Mar 2020 17:15:14 +0100 Message-Id: <20200316161550.336150-3-laurent@vivier.eu> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200316161550.336150-1-laurent@vivier.eu> References: <20200316161550.336150-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:KrL6I/F7MNRegfxQaiB29bAN8Uwn/7ObA5TnQeZdB4gWJH9ikUW Ra1813wakb/rt0BRgSu9R8jfn1sFryE/E8krtgeCWu4xv0wCvN1rgbTTseygIPS8i3eGg+N Gi35z7nG/QTWBranhBE5ofLHdPM2Ja7kRBDVzRbAXgIDRlaqup/v5c7Txl0/hJ95FCX+HCf t25MCMT7BVRw8HcPshu5w== X-UI-Out-Filterresults: notjunk:1; V03:K0:i01+A/033oY=:EB1CbLBRvjfyCHmdn/VBhw LSmjpjvGWmDh5Zr/qHvhah5Ojqsr+qtvpUqdTky9jqOONjxDkTUAs3GUJogL3tCbonp0Qa1fR bW7+PoyR741cYkTcRpXPkO/9N8jGgOzaLBmfjPXxD5j1tuwe134HFRNNLeHHsv8/TLyWt4P3V zIWISABaT9/aXFigAIf78HfiUQWz3MNGHTnz50ZcyG09vJqXfqfDyRJg+EW/qTKCaivk/DPf9 9EmOQKUCp3rFTU/g8aK8xQb7Ju7ekFmcRww9VL3VMR0urhstx9XvuLwpbav1bO+kFtT4Raz6j iJ4TpXnThm/Q9yyL1A85Okmr8PoLyIl8oDPoy5q2fBuy08P9yoiZJpxwaH9OFR5sxvwMIXFZu 4nhF6v3ipeMHdFk0pLuSTvAdB/V8MMGMghzJqlyhB+8EfO+jTNZ11QdpgB2s5+1NIy5cy+391 9ZE88/NIH5tdbhmkeDD07pVBubD7Azspl9CG9nFPPZ8NpxHDWor3rgY3Fi1bKxp6jhxE8Jfnb RZx/kbu/k796z8NyB7glX1/dslcwtacC3N0X1k69lVSmgSKjIGeA6I9yUTEMhReb2RMq7VjCs RYCRJLeHMrQu/jQCC2xpGpZC1H8+GBnnpQ0MUEKAmXVeNP54r81xfCutjbvMPW5EzEL234zmi 142JjxLtLMO+x2PH2aAQMBPaauU/TN3q5lwgO4lQKu7dEdtkkVLg3g+NbfDyFZQONwmPMyY4G F8kRnmBbdulR4k6lwBSd4l641HcNe45+lvWgR1S3ogO5hqjDzpXCPybKMwuplCajgSl7AeXLT tMzUkMwYXEm7jq1C+sFeXjDPw/4piLaQ3mBIOZKGSmyh1Oj5/SamcGVCtQ24ru1tGmNQwmB 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: =?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.24.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 Mon Mar 16 16:15: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: 184571 Delivered-To: patch@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp3091397ile; Mon, 16 Mar 2020 10:46:20 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvOmUyoheKto172D3Z5o1G2Yw1dkjKasOEsvmaRjrcFUhHo9GahFqh45b+GWhfaORxjE8Xm X-Received: by 2002:a37:9a81:: with SMTP id c123mr894928qke.176.1584380779987; Mon, 16 Mar 2020 10:46:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584380779; cv=none; d=google.com; s=arc-20160816; b=Ng7e4Zsqsu1tLQAEUwqzXEaw4uzJyzLspwJ7f1mT8ayzWTEMOb+3SBunnKJdRs9JuQ cNhYKM3/T4vykq+EbAlWO3s+e+EQd0LKpkFfAlwSP6vSP5O8GbhcunjXPRlwfE7yXfny icsSVK/3aTE7I0hJnEL9OtNR/yCfsD9at7BlUd0sfRpiuULcO71XY6GC7kJXG5x1mbOj lo5nxdl8l9YVQD16Tcoy1ZZYg4WOKxDOLFBhQhBABix8qzTvjbmWrg7hd1p5CDHHGYSV cCLvvQyfR62JwZqkXar3BNe+U8z9bNpmoipFI4zREZNs85tcjrNwKiT7vtuzJ+T9+pSq UvIA== 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=qae13QCl6LvvdWjCWFnu8ACk2rYjiYm9QTECpCB+OHM=; b=G7gLh7JtFlNCRL4ET6QDPcGpDUmZScs0dRdm4wZsCNF33nVe8dUFuT2tSq23tSWQqf bGN2GTY6R1ejH8yP314lipCEfK6VIQXTbboPIGT2yHct0IyBCyieHokWAu1MSIqDcm+2 V2NYij5pnX1a7fEFhz4FzNga+kwZ0aLmwSxcGFPTY7F7Ony+1+mPuRZhgI8Aq7bX1nvl RGJUysQO3AQk4wCEqHiuBy+ncHVTEZ8LOJbpeGaKSmFYt3jny2f7GAmteUbuLL9NKYr0 oSDS9l2VZL1zHIqkS/UMuI3rygwO8a6a3EuEQrfXML5/hZ7oIMM2NkdBq1fFku6cDPC4 ui/w== 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 f1si206443qto.242.2020.03.16.10.46.19 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Mar 2020 10:46:19 -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]:44764 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jDtoh-0001vw-Ed for patch@linaro.org; Mon, 16 Mar 2020 13:46:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39974) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jDsPU-0007r1-Sh for qemu-devel@nongnu.org; Mon, 16 Mar 2020 12:16:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jDsPT-0006pI-BQ for qemu-devel@nongnu.org; Mon, 16 Mar 2020 12:16:12 -0400 Received: from mout.kundenserver.de ([212.227.126.133]:49327) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jDsPT-0006eG-1P for qemu-devel@nongnu.org; Mon, 16 Mar 2020 12:16:11 -0400 Received: from localhost.localdomain ([82.252.135.106]) by mrelayeu.kundenserver.de (mreue012 [212.227.15.167]) with ESMTPSA (Nemesis) id 1M7ehh-1jEixU270H-007yRG; Mon, 16 Mar 2020 17:16:05 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 03/38] linux-user/i386: Emulate x86_64 vsyscalls Date: Mon, 16 Mar 2020 17:15:15 +0100 Message-Id: <20200316161550.336150-4-laurent@vivier.eu> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200316161550.336150-1-laurent@vivier.eu> References: <20200316161550.336150-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:lZvFEJ9o9G68c+XASEUpLXin5vmNZDMT1y+F84scUvakLyBelX9 PNSqCPntBUuGnEvlT19tvz9rpFcgNFe++YuVZzItp8OsJEm53cb+HqVh1bI9NdVeJ4+A19V 8Y4306bYtYU7fs1SmTmr8EjBBvb+xh7f1nmMoitU1kw2M/Bqe5CVkISJwhSLHdormGUkKSb jXHEnwWuwHVAmNDLJj4RQ== X-UI-Out-Filterresults: notjunk:1; V03:K0:wFXAT8xnGt0=:Pofy35ZdiFalCR8u0um57I qnocvwCpIKo4FypFLDoML5diRwuXQ19R4UynuqbwOcdwJFlqV0+iouO7jgOpUdDib60fnMlnw vRepkWT8V1sClLCL5iTP4R2gb7lC+4G2Cz02yYQAoL7N2C5DxGV+oMx4JC1PxG+ZCazPEDK59 g6m8PVFmmVdkcqRNKTG2+3qDrZPLWCnnAuLatBrYbqcghX1JwMlChPYX9HqreF4Atd/Ez2rgP bkplbUEK0ybR41jH71/O/1pisey8iDfUjlhYKw91UCqO3A9psrfo5Y/v+IsJRtlIFTWiVpHq8 uOFinNohgw0z1OArti++JzDUuhb4ISb+tPGjv3aDVcHJEFbhIp3UVf7+zr4ozU0B0UVYtKdnb ygGOIVeaL+tQQ/iCdVYl2gGTMGHti7rN38ZjQeHSolaaDIcKdajQKNVWh+6EuDWwd/pVhMqmY B3bDwFctqqE0QaxyEr5KFxhL3oLzbzbs4MIFnuosLgdj8MtmQ176x0oozJ9l9jSspdJGvMJWG c3aL3cyW1NRgrFWph4NuYkQtyj3QfLhiVWXs/NrOcr6gL2/x9FAv/sricC+OiV6Mn/9BAyORD 4jYLzdSFLrxuGcK5DdXF9S7JOIJgxzEx8MyTpo51ywljPxuP8wfZGkjlX7qD8BUSSsShXcQG9 FAuiRXEej80n4iCOLvtuFgJbO1yyp0Sxj/r9Cspe7mYQsusudfw7PwmnVlNfKMzJn54bVLZsA T+eunW6DA2pV/CKRAeFR8MpuX6U+4hq0sAh3NshjjbVJlUS07TxzsZdzcDeu+ruYs7/ilcyo2 10aZSOhS7e/UCLQDOffSjnp/iU1CqgtdTkqFXC+Ll+s0rtukdFi9WLOCIEHM9Jm7cOpZWvj X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.126.133 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.24.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 Mon Mar 16 16:15:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 184575 Delivered-To: patch@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp3096232ile; Mon, 16 Mar 2020 10:51:55 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtufVMxq22wWypvoPDFRVpKAAkTJxheAW9vj0Asqfiv5471toBXA36UBb/TEQxVKkUytE7G X-Received: by 2002:a37:6e84:: with SMTP id j126mr847448qkc.77.1584381115194; Mon, 16 Mar 2020 10:51:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584381115; cv=none; d=google.com; s=arc-20160816; b=aE3wUOCSQeC+qPb2ajIcmEPop4lWIs+Vj6JofD7mfgoEO5sUW16WNLe4kz13ydfVLB EYxu2WQcQYRIGKsmQWNSL5uYfYIoKfgIre3d7gZnbwASW9oO0pgtcBQTGSqHP0I6UM6x STRytebqkGT2RD9BciC/kwhusYTwiwnsYqlchukl4wPxcy8PYg9BwFZbXj3jwH5WLVtM CClsmJDWn1p97TM/Aq+jsBUhlFlFYRxsPbFFr3N0Akw7WX6h4eqStW9B3uHkzKg9gehe odqioAy1wBinjpthefqQwq8DnzFle3GSlzfAHqIGkyqoCFEY/d0Pc5dNBtJ9YdiD22wX KpGQ== 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=/ZvV49OFsjmxWSbOxxoXySr5fzZgNd9AeTlb1UBAj0g=; b=etmlC3Yty0z12ZeOwqRe+llxrTltmAYBsRrtrzFuSmq8uIs2zfngdxrElGwUfc1RSI pW2mB04suMR5bVvs0QXGxZoVi8bsJxVSv5rKp66K4BHxuJiWc4GCEsdDgnxK9dGLRTpr wKjad8eFbR+ty6sdOXASkkD5PMSgfD+A1wB1t0BSmZdYqhwElwnmZxjF1CPtPL6iDgRd Kj1gqQmn5Xs0NN5OrSIdSF98kGg7XOczLA9v8IcXcD6E1ugo2UWyZaJVFihc5oeDcaIZ cY9F9w8bO7RTEUwHkW5SdxnieNhPjgYS6tGEVBbeeMJgzoSZ1ElC6OuG6NHYI1tAyv8w ZeSA== 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 k22si413882qkk.374.2020.03.16.10.51.55 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Mar 2020 10:51:55 -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]:44902 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jDtu6-0004wl-Lf for patch@linaro.org; Mon, 16 Mar 2020 13:51:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40240) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jDsPc-0007tf-6q for qemu-devel@nongnu.org; Mon, 16 Mar 2020 12:16:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jDsPb-00081i-5V for qemu-devel@nongnu.org; Mon, 16 Mar 2020 12:16:20 -0400 Received: from mout.kundenserver.de ([212.227.126.131]:58519) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jDsPa-0007qv-SE for qemu-devel@nongnu.org; Mon, 16 Mar 2020 12:16:19 -0400 Received: from localhost.localdomain ([82.252.135.106]) by mrelayeu.kundenserver.de (mreue012 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MWR6x-1ioucO0HkJ-00Xvoy; Mon, 16 Mar 2020 17:16:07 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 04/38] linux-user: Add x86_64 vsyscall page to /proc/self/maps Date: Mon, 16 Mar 2020 17:15:16 +0100 Message-Id: <20200316161550.336150-5-laurent@vivier.eu> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200316161550.336150-1-laurent@vivier.eu> References: <20200316161550.336150-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:aZJhjr1SrOnsZQ0Eh7GbOh1xCz4COGGOOTZHp4QlnihexQ9KgAx OEI24kevWu/iirqAk5ty1OFeu53UcviEnp1PfguCVZp+MB/s8PSC8wHz4R1BYYRqn5+1NbE PDvMR40ZCB4qy58arwxydxR9er0qeCs3KOKOBim+wTOHAURPP58oGFH/IBx4nUnJbNC3ZKL nnCdQC5AIxJJjxKzMpJSA== X-UI-Out-Filterresults: notjunk:1; V03:K0:ksttNYJ3YiM=:RaSS9gfOnXm7Obg/KdtIYh /o2X0KsGwG+fnmVMVoTjd1cjpGfg97JaJ/Tei93aaKDhA+9quhMkOk5yqTavhnQLxiBYgcuVY SoT5X0lQKx0SaFzRxkLvWUfl7RUputVt7OqY9RefGOHnLA4UAZqdIZzG3hLIvpUV6NN21bR5S qH+ge423gqHd1tQ/KQ/iTih/1GK7Aq957Ls7NkXgauTtC4h8cXbaV+BJkKEGKlOe4FRsujaUv Ekxv2VT71kfLd0nRZIDHEJaQIAdtDQBNjaGziEoZshcFLUDpuy5NHrGZn8fnXEcKZiBf9PD+H 8PcnNe8Cop38psjdLXynSLSn0yEIVsCz5dpmAkSKOfBMMk0whOn19jPQ7zH/GPClb5cXurpY0 DUV6BbEkbq4Uf59WdYlOc1CQBRUsIsDp+8kFZyFbf4MyFl2nldER/CkTkQ80KebzVvi5bd2IM SiVbjm+2J+ufAEz8+AMn0cMMLwBZ4ytQv6jYKJXd17fbodoIhIQV9f0+k/6SNDiU+UcpNI6wY 0p8M8B9vfB3hA4bUctTrHzjnlg+DSUIlyLM6I6YmjSCRh/3GE6n3YE6iarGnU4ycEzrnFaIHN DwmtKpHMN8BhzN5AMB0Cb2J0rlvNdlEFvYd6cLpuUVPFGdRhXcPiGutlBq6SbKEKE9IPuGwGK nSiZKtwjbnKWNurQZ0YTpaIRbCiAIcBz9zzI6NNQa+gjt5PAnIS+mv9kivhI4x+6QqpcZ/kMx JJk3zmYTIV73WSDutgellKeoK7IX44VD7MgjN+oE9QJhwvptUU+i+C8lTIKn2cfZC+4Ro96iI y75aRBDf0z7so6mPrISjNhDBrNhOSGRbX3sFRNUtzuE84ZdJ01AT/GEeOs+0ggmqNzYXkNW 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: 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.24.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 Mon Mar 16 16:15:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 184584 Delivered-To: patch@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp3110158ile; Mon, 16 Mar 2020 11:05:29 -0700 (PDT) X-Google-Smtp-Source: ADFU+vt5Ak4U6fpwQHSEUUAkQ5LHxTX28D+g16GqvSsoQ928kkTKFQ5fyIsjE1dZmouSNgp5KpNO X-Received: by 2002:a37:ac19:: with SMTP id e25mr964510qkm.54.1584381929657; Mon, 16 Mar 2020 11:05:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584381929; cv=none; d=google.com; s=arc-20160816; b=bCA7dOhvD5HDOtqXhBY3xcADFJQkhLjgvWD7M2oqyfou+4df53pgnzoRdG8OIgSKyO 38PF6BuZ71J+oYzfWbKIIDyPOU+15wTJ/lK66b/Dv3m0dJTBPOIR3Zi2ZZXCGukDKush THueo6cz/Q8arbMdgBJPm5vLBoVGg9SFAOzzvUTIOrr2ihLw1E5lCWwBtg0Jbs1EO8Hk BivRxdwq8pDv5PMeexYOokSXnTBZdO+S1Gzs8s26MDh9m/5HuyHi+ooJfviGMAtBe1R8 GbVmGtBwDlsLURmWc8/F8kLtz8EjbZllily90IBOGih64MYbiwvaX8Qiw2OETLwOp/Uo lYoA== 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=i4YHaSqDqOSpUB9V6QUIT7Ej3Vzz/Y8QuNSGvrOpfjA=; b=J0B9TAv1mmjAfZPaq7smDus4mx5Sa0kh0VDPC3n7h0GicMNhy/c/JwxKP/VDOVv1ls 9XqHfQwHjvVT8ImZlzteQwmROK1r/CxJZYbN7xX53IZDRuXlDtwZTic5tSZa6QrDPsgZ DPlFLnUpz/cHug2Z85PKNIoytYPC1LUdeC404r6IDwPyX0MvL1IjpIDo70qcq9sYN0X5 4WHcQ3IYslygqFD1izNWhtEJty3xMDSlrqjTr4/shknilrmcJwfyZYcE8YEJ80B+XTjQ japsGGfEvz0zPZYS9/fRFvKhnztX/aLXazNlo9yrXejtrl2lci0eaynu7L0j6ownZrna iLng== 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 13si504827qkv.290.2020.03.16.11.05.29 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Mar 2020 11:05:29 -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]:45240 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jDu7F-0001hK-3g for patch@linaro.org; Mon, 16 Mar 2020 14:05:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40314) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jDsPe-0007uS-E5 for qemu-devel@nongnu.org; Mon, 16 Mar 2020 12:16:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jDsPd-0008Jz-7p for qemu-devel@nongnu.org; Mon, 16 Mar 2020 12:16:22 -0400 Received: from mout.kundenserver.de ([212.227.126.131]:44111) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jDsPc-00089c-Sw for qemu-devel@nongnu.org; Mon, 16 Mar 2020 12:16:21 -0400 Received: from localhost.localdomain ([82.252.135.106]) by mrelayeu.kundenserver.de (mreue012 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MJWgK-1iu9fF0v5k-00JtBP; Mon, 16 Mar 2020 17:16:09 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 05/38] linux-user: Flush out implementation of gettimeofday Date: Mon, 16 Mar 2020 17:15:17 +0100 Message-Id: <20200316161550.336150-6-laurent@vivier.eu> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200316161550.336150-1-laurent@vivier.eu> References: <20200316161550.336150-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:2+OnKEYWuZtt3LxPwxgWv2MmMh5zFI/qbCEo/Y0vnYsZo1wgRYE XNrFQkaN5nIM6oooTEeFIYSAFrRg38LDumZGna+54GdMhnqhq/41MZ5xndr3aCitIgC+T7Z yrztQN6I19hQXnoOz+hQLkfBEEiYILpfXEl8nJx1+xkVzYqm+lRJ3riYujlsC7jHygr28fP Fl8LsgikLMxCRAqgVWZvw== X-UI-Out-Filterresults: notjunk:1; V03:K0:1lgY4n/pUaE=:1ivdzdwoXUHX6ENjH6hC9+ 2ByfVFANsSd27UMZmS4JEQw0ZJu/hqzsAJvOCmNaNPZmwWwdb79/LQbng227raBS2r+my/K2L DrWjuJ7BQtBy4H8XU4p7cfDVfeajz1b2pRIcRpvc03lLqEYTRdrXXdMYfZ+oBROa8gnNHoITj gJJ4koCHS93o9lI6sVO11j2Egjl6ar8bFKtMv7Wn6xF6pgXS7Dd2NGhqA9Gzw1xc8yl4rv283 zvt1JPS+NWCp29Pd8+bMtMkmrWsElboxajHPZYwOsLAjRKV+YGQrKKwZyUcz1cea78r7/Wwun rlRxyRNfq6P157K/0GpKMDxH2mxlbtNTolhwfwmbokn3a901hww5Gk5yg1bzaToMp3mm0ntXg A3Oci06rf12zs2HHwav58gYG4uwmuyLCkUqi3X6nowP93qr1iF/QcTXxas1jz5Bqj2uSqmSZF g8mUkREfORnPM4TIMWfc9zb7/uKzZWWDF4Nc01WZqwiKGlWmakad6aKZY96p1rMrbnU+ZPE0Q 4KkyWxR3E/H/6BhKcz+2U7g3COtxmmNZivjOzGEjlaMDAczItcT6TGEDEaORxn81fTDhEat9B KeyDNCqAeg6rY7yNHHvmLbljWNsqTUj6q2dIl3z5lywbV4cKKBC2V4M3clvFeowz4Z+KyMb6G z7pcCYPnD+x3sD8gXiXyQSGUGuATWGcdrI+lq7i+aKPzsV4U4iMusKem84EyPp+CKvjHJEoh+ qkElwRxUZ11ebBIioxOzXueQ9LS2b72RPN68D65gyG0nqbDsCXff1EAdWSFkf/ZsFzsqujYAn VtHcXm65RV03EA0WigD/eVxeO3RsZVTbUqAkC00bVwR6+MdsyOn3cipSyWnvJkcTLM36Kn7 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?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.24.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;