From patchwork Thu Feb 13 03:22:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 183326 Delivered-To: patch@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp27847ile; Wed, 12 Feb 2020 19:22:40 -0800 (PST) X-Google-Smtp-Source: APXvYqyyAxzzr5R38dA9PkxBhq8jsbxvcnPLd2y7T3CJCGAhM0W0uVZl8S18MpJunv8RM3YLQCFd X-Received: by 2002:ac8:2939:: with SMTP id y54mr9849688qty.109.1581564160400; Wed, 12 Feb 2020 19:22:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581564160; cv=none; d=google.com; s=arc-20160816; b=IWcIi9ICWkSHr1/Fdnu05IcpAS+iD3xWqTLNZxWVOrzr1fD7PkCLAfsFnqzoVu82+6 n6kJlbvh2+Gjnu4BwvoQZhK8Ud13mjuZ7vRKhvXP37KLdJ8eDJtoOcc68fTsg5AdLJMl c+SRIWJTkb0RnJ8MuXguncJMSSoGzr2auUy2D2n6Zw5yHnWtMUsRILOH/aoJh5lzQpsH l5CTPrFy9dSdEKxs3AjkItKTjsLM/arPJXOqj+0ta5vun5bCzYQKJS+YLVrsVXky55ra G4qNrGXXwWCeAX7bezMySBPm15kxs09cqtDR4VKzSw/faP5JPf4rNPf2Dr5mqgcXkS5Z GeOA== 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 :dkim-signature; bh=b0SUyaJJjQZuc34rLJlUYZCom+bkortVckKDUk4LlxA=; b=pZgBg4RNt+skXDNnKCVLjj+smMl80CBm8Lcn9kNN+Kvb/gF+JnkaMuuagXK3+QmnCO 3RyTpMIDFXJR3aTmuqh9jEjfRYH4rm65C85HBvRQCpjwGe45m11U61UHWN+1z6h1QLb0 FT4TXnsmXF374pNMVGSuoEglFs/LQ94KJW6czBSZ+KWCy/5EfDWlJZ1bCKVq8YV5Lvc/ WaMc5F/hh/PNY3UaEyJfvEFNYWcHreEs9XJ8+zHNI1+i8Me6noLnw6riJltk6j4iMMVf RL9/J0GjlrSmE3KsFrvHhxPVbcwSuHqqfLawe6M8UPoDbBfVkAObHi26zApITsVG0pnt jVAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=tEI+Wq+M; 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"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id bl1si369611qvb.90.2020.02.12.19.22.40 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 12 Feb 2020 19:22:40 -0800 (PST) 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; dkim=fail header.i=@linaro.org header.s=google header.b=tEI+Wq+M; 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"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:46774 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j255L-0002Bb-RY for patch@linaro.org; Wed, 12 Feb 2020 22:22:39 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:60132) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j255B-0002BP-95 for qemu-devel@nongnu.org; Wed, 12 Feb 2020 22:22:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j255A-0008W3-7e for qemu-devel@nongnu.org; Wed, 12 Feb 2020 22:22:29 -0500 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]:38429) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j255A-0008Uj-2M for qemu-devel@nongnu.org; Wed, 12 Feb 2020 22:22:28 -0500 Received: by mail-pl1-x642.google.com with SMTP id t6so1750871plj.5 for ; Wed, 12 Feb 2020 19:22:28 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=b0SUyaJJjQZuc34rLJlUYZCom+bkortVckKDUk4LlxA=; b=tEI+Wq+MT+AsYiUz4cgA7Dp9LDe139xyevHXaao51NWk4Qy+oHi8p3FQTzxyP6TQoL vn3yo3aKQhiqaWVSgTQBnM/i1ZWcF5GRjHnqZqpIKSop9zahZmSW2lPkOX/K6XirkBqm /hEGcr3q0MjJCWTwiswI8i2EZOSz4V9Sot3kp/G5Jn0xXD8rkcDjqidnN4iRidn+LqYn CL0QQQPBoVyX1fX+aG0+o5NWXugfdCywTMVZr0ky8Jl71dNhDP1GxrSAI0cSSXXvXP/L qubE268Myx0bhtFagMfU4vyfzI6m5q6blBQnJK5Yu3TiEkvqqwctKFggO0iwgVl/PAua rVRA== 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:mime-version:content-transfer-encoding; bh=b0SUyaJJjQZuc34rLJlUYZCom+bkortVckKDUk4LlxA=; b=f5KhhQ7ouOqjRD1qePlmcoiYc/ZdLcd+1DwgoY5WItmNHCaxBy5ueaYsmZo3BH4OnW 56gkZJjrqUiyy7vCNNUYs7Q5aZFeqZulBaJ5P5pxgkFcENsojOtjicf6+LncNSIp4B1W FCaDoxvLRNfe8YPQS2kobvmFrsjsx5G5IkOMybGvAIqoODk3XPzHXExpOInOJmpj6Hia cWsS1k88XpbEBDyxqamrlTzCsbi4MmGiODywfJSa4P8IQj5Ss+pKgsdV/hnf9f3jgJB+ XHoRVkEiMUnicuTWELG/jqtmZ/eECjvQdoc6f6JTTEVxvlDUjDxScTTxAezJ6aKnaSEH y8Lg== X-Gm-Message-State: APjAAAWxg+NATTcSOE4LDEJ8C9eWP6aU9bs58/MF6DYAHHNjTbX5OsbD uAwwl+zaIO8376E9kyRSmcnLX/VDHDs= X-Received: by 2002:a17:90a:bf83:: with SMTP id d3mr2634922pjs.77.1581564146790; Wed, 12 Feb 2020 19:22:26 -0800 (PST) Received: from localhost.localdomain (97-126-123-70.tukw.qwest.net. [97.126.123.70]) by smtp.gmail.com with ESMTPSA id l15sm536067pgi.31.2020.02.12.19.22.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Feb 2020 19:22:26 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 1/5] target/i386: Renumber EXCP_SYSCALL Date: Wed, 12 Feb 2020 19:22:19 -0800 Message-Id: <20200213032223.14643-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200213032223.14643-1-richard.henderson@linaro.org> References: <20200213032223.14643-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::642 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 , =?utf-8?q?Alex_Benn=C3=A9e?= , laurent@vivier.eu, =?utf-8?q?Philippe_Mathi?= =?utf-8?b?ZXUtRGF1ZMOp?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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 --- target/i386/cpu.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) -- 2.20.1 diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 576f309bbf..08b4422f36 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 Feb 13 03:22:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 183327 Delivered-To: patch@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp27882ile; Wed, 12 Feb 2020 19:22:44 -0800 (PST) X-Google-Smtp-Source: APXvYqxIJr2OzVxrGKkBTlM65mszoC3MWQc8IM0SRkShzBo12/T+Gq7GO2byTzs28DmHwqlZmGdL X-Received: by 2002:ac8:5055:: with SMTP id h21mr22002421qtm.30.1581564164060; Wed, 12 Feb 2020 19:22:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581564164; cv=none; d=google.com; s=arc-20160816; b=OeQs6tIgWd7l+UmpbtK2ouZBY5uaX8KHXRfOiKajqErzIrLjkODNuNqYZ+7bN3PgAi +zMGx647F8Tm0iW/ZkQYcXTvnGYWbDdQ5NdkqyKhu5pPd7S3zg3TeCLzHelu0I+STwda TaoEW4Le1zXo4TuGhF4YnuQlKwkRw5qAtw/wg4nvV9RFmaDWZUQ7Gy78Gm6dpHUb2/TQ 53LNRRmywXt3tICXbckZsyQzqr3Z/ULrkjnX4/rRnsNs26UobjecIDzxdB7N6g6Z4pWW meoRZHVsAJqgoEzMEJIqm1qBX93wrSIU4WbM+sLW71KF02jWSkPwfNkr2ZIN9oVA9etu kz9A== 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 :dkim-signature; bh=3RA4GH2ajonQfyTX2FF7Fo2q74LDzhgpTLSFFMfVDM0=; b=vY9mkv7B1fvb9YXqdJQ3jMFbDhH6r12XWbY/15r59WMJzhzLwV7y6ht4sFNsc3+p8P 5V6WoCVdTzo584N7O7J3OOsnyjffpvN2//tuAI6e428oEqjrXPr5iCEKXfBbO3rQnPYb KWosPEI0TBxeFqQcDuoIBpj3I2AHEDgEoAPZMfC7Moj3DLduXyRsNuQAxDFL0qbd3NJK QopNPx3spORPWJLMliCo2cMb+4sORu7B6E3WHI5A11EMgfQs+CzZOQJFNtRp4s1CqDIN I4TCSG3kRWOtE1qdh6JHXEeNFfTzAWcegEeP9rvfO6HheYz5IK9yacgRduVntEcOJsKW L1mg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=THdGCW3B; 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"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id w65si582876qkb.63.2020.02.12.19.22.43 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 12 Feb 2020 19:22:44 -0800 (PST) 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; dkim=fail header.i=@linaro.org header.s=google header.b=THdGCW3B; 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"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:46794 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j255P-0002HD-EZ for patch@linaro.org; Wed, 12 Feb 2020 22:22:43 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:60152) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j255D-0002Bh-6W for qemu-devel@nongnu.org; Wed, 12 Feb 2020 22:22:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j255B-0000BH-RB for qemu-devel@nongnu.org; Wed, 12 Feb 2020 22:22:31 -0500 Received: from mail-pj1-x1042.google.com ([2607:f8b0:4864:20::1042]:32824) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j255B-000076-Kr for qemu-devel@nongnu.org; Wed, 12 Feb 2020 22:22:29 -0500 Received: by mail-pj1-x1042.google.com with SMTP id m7so2277559pjs.0 for ; Wed, 12 Feb 2020 19:22:29 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=3RA4GH2ajonQfyTX2FF7Fo2q74LDzhgpTLSFFMfVDM0=; b=THdGCW3BNt7EkumthnWSpnaggBv5wTqJePjQFtUbV0FtYNR6Elwo6RmDAszysaDX93 WZxt67oaz68yYxgCu/DmOwUR3qLrwQwuXBejZD7Fz7Jd0KgRtxo8rOLgJH3dSlvoyYQq 4kMCGRVoGb7U3CbOTjulcz3d/M/izPUoiprD+3lCjRfPdRf+c5JgKBmYFOabTGYpXpYQ rVIy0h07eIUin5tRf/RxBiQEMfvOx9jb0d+hVn1gRFnB6ASyeyPGgt+hQTZKJsaC0YF3 nvgh13RmH1LFDiqU54VZVgbW/d3+1+8pR+FlukC9/S26o+HJdwOddr3EewtR/vfWQlRk v0bA== 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:mime-version:content-transfer-encoding; bh=3RA4GH2ajonQfyTX2FF7Fo2q74LDzhgpTLSFFMfVDM0=; b=LpIfLcNhtMhBXhb4yNvh25ACGWIs57eHXdwEkYhgTW95Jxhsonnv7nyQg/zUhxtavQ fgYpuiitKq0kAbow5m35O4hS4U8m75yRrtgqihpOFnBfnL7TvInvmAcwCGXcXHTtg+Yp b5VwMMLWNV7k5lyONtm25ioO9WX/UZ9GP8CKFDIquuEQDxuRuxEmiDHN80XBPTS1fFcS S3ewYEmGJ8LBI5j3ui6FBDtuIYK1/SH1NOt9oTepul9SdcCPIEzqv8zB7uMcUcAoIUYu ECYlZ/csl3VGeSr3DDYgsdETNioNKQIfohK/U+Qv0n+jKUbLYiSC4MvriCpgZMptjvCE wFqA== X-Gm-Message-State: APjAAAWIvY80pDpqcDlIwSZj0sEuhql7qC8rGMdT7jMwC/LtTfms3iOd IqLV9qXCDeJ6omyrpCWbk7vEpJRWrqM= X-Received: by 2002:a17:90a:f317:: with SMTP id ca23mr2611033pjb.20.1581564148049; Wed, 12 Feb 2020 19:22:28 -0800 (PST) Received: from localhost.localdomain (97-126-123-70.tukw.qwest.net. [97.126.123.70]) by smtp.gmail.com with ESMTPSA id l15sm536067pgi.31.2020.02.12.19.22.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Feb 2020 19:22:27 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 2/5] linux-user/i386: Split out gen_signal Date: Wed, 12 Feb 2020 19:22:20 -0800 Message-Id: <20200213032223.14643-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200213032223.14643-1-richard.henderson@linaro.org> References: <20200213032223.14643-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::1042 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 , =?utf-8?q?Alex_Benn=C3=A9e?= , laurent@vivier.eu, =?utf-8?q?Philippe_Mathi?= =?utf-8?b?ZXUtRGF1ZMOp?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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 --- linux-user/i386/cpu_loop.c | 93 ++++++++++++++------------------------ 1 file changed, 33 insertions(+), 60 deletions(-) -- 2.20.1 diff --git a/linux-user/i386/cpu_loop.c b/linux-user/i386/cpu_loop.c index 024b6f4d58..e217cca5ee 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 Feb 13 03:22:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 183330 Delivered-To: patch@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp28731ile; Wed, 12 Feb 2020 19:23:57 -0800 (PST) X-Google-Smtp-Source: APXvYqzJQBoI2u9ikIKop9P9rjd58sKqAUDgmaAy+8//W/NWDKyYfQnmE1h4AiY36S2dsDqyhVPk X-Received: by 2002:ac8:2b82:: with SMTP id m2mr9754809qtm.161.1581564237477; Wed, 12 Feb 2020 19:23:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581564237; cv=none; d=google.com; s=arc-20160816; b=sy/e6aPDJ04EUlIS+YkrrJ/Q8GgrmX8/+S0wAbOy9MrKsmXnEWEFLWlCq8MACO5tJ6 MGCfVGeXhjprUj66u5RW2FWKG9JEBMuzcvm8o8m1a2cUBXArteqKg1eCJmzTes3KfaTq s+qIb9Pm/s4+y0UjvvgV0MX67dKqdiRBawqdl5Z2FRK46ClwT5JNql6vppr2r2l5Fohd lfukQJPSOnMC5usIN1SPmXWlLFvVEWpE87DvO08wqsPK5wCJw1VoP6Ay1jCytH1DUluP tF9CPGY3gMShmcD+pGxE78Bzgr54eYo6p4ArOnIYKBGxLmwAzzjR6oi9OTGKXBNgke9o UXUQ== 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 :dkim-signature; bh=hRsQ7XlJN4rMifYbK1S2B4u9AT4d8Fx9ZqVq28vUwr8=; b=r4ScXACynqp+IF/e3NlNvYYC+epIYHbE3fG0K/A/q4HcHc9DF18jdUmQhNpj+xqP9J CuqHHiSlSmAkNDJgZa5UsYcMbgeB353PM/4rTUlwlO/7LafHI9zf6OVJDUvHcIAn4H// bfi7ONEC5j2MDqg2whv2CiMIO60eSSt9nbwlw2vbNGPzzzyebEomO0/fv48CHGQR7j3b XCfTMov0GhCD51ntQnt8U2Lbp/UumtCJ3Ttjt+562Ue/JKzMJ7gmG2NgsTXH7vPJ+U9u 5cpZ19wRJNYyuoetyJiizafweNCiQg/u549zdyoixaCDf2KEblENv8SvRKR10vfgnBhT pDMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=l0j9dxdz; 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"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d12si537157qtw.390.2020.02.12.19.23.57 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 12 Feb 2020 19:23:57 -0800 (PST) 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; dkim=fail header.i=@linaro.org header.s=google header.b=l0j9dxdz; 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"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:46840 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j256a-0005Rf-PF for patch@linaro.org; Wed, 12 Feb 2020 22:23:56 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:60164) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j255E-0002E1-CT for qemu-devel@nongnu.org; Wed, 12 Feb 2020 22:22:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j255D-0000IU-0p for qemu-devel@nongnu.org; Wed, 12 Feb 2020 22:22:32 -0500 Received: from mail-pj1-x1041.google.com ([2607:f8b0:4864:20::1041]:38566) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j255C-0000E3-QX for qemu-devel@nongnu.org; Wed, 12 Feb 2020 22:22:30 -0500 Received: by mail-pj1-x1041.google.com with SMTP id j17so1772988pjz.3 for ; Wed, 12 Feb 2020 19:22:30 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=hRsQ7XlJN4rMifYbK1S2B4u9AT4d8Fx9ZqVq28vUwr8=; b=l0j9dxdzytU2BofWbBFLt+92/1oDuW3FSzq/JoTfrGb93GIpGcaR/InhGpzg8KKbmy jsBvuMcn6le2JfX4L1Z0pqMtzkvuhyv5Quzh0/m35/8bpF5YbTUhqfEoIPiUGuaSHGGN 6hhHSU51ctjE4HqvZp6zBpJYnr+wc8HeJK8mKPaptz/ctnnCXPGvRNNHP5Ce5oI4JYQC dKFdaNPfJP2sMuXd3o8uZQH3iJlYFYVESclVCnTeGwor8/zqT+1FLnTzFezv6+3HE1vZ 3r4ITl93TNuTxck+jRbrrnytqGB5uIZIfb3mu25DjbekgM8oR2ZYcsyXWtwZmi/DGa0G 36DA== 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:mime-version:content-transfer-encoding; bh=hRsQ7XlJN4rMifYbK1S2B4u9AT4d8Fx9ZqVq28vUwr8=; b=bcMOX00oHEr/HuAAiPxpOmitOU6s5Vp86IB7cLigjzK388jZhiMVU3oiXSaDwZiNgU nvsRxGpqsU8CyWwDLyTQo5sxNRrPihMRut5VRiWySZOoJqQ5VV9Y1R5u7CDUy0U+tUwI Z0iO97DCygIysTAj3WU1scdipCwrIYslj4ednYfQ8rATYMOKBeBpfzVt4ReLZZ1wgSk7 mA/NviKdjeUZtHAhVD7z2mOW6oQSuiEnZSYoSnrudWHEwxteKU1FTLXEiTUAg0A6eikr LJOzB8H0dmON6O87BJTmFEH82j3ih9e6PN+1bW4X12UaoZ7d+qWtaPv0SiegTG0e8+A6 TizA== X-Gm-Message-State: APjAAAVVYNdFF3Tme0xAvN+CCXQjSRqNjFBJOGEdLUZCLKxLGwpSigct x6MWSG5H4qghRumHLeAThz3LwbXw93E= X-Received: by 2002:a17:90a:7187:: with SMTP id i7mr2553289pjk.6.1581564149193; Wed, 12 Feb 2020 19:22:29 -0800 (PST) Received: from localhost.localdomain (97-126-123-70.tukw.qwest.net. [97.126.123.70]) by smtp.gmail.com with ESMTPSA id l15sm536067pgi.31.2020.02.12.19.22.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Feb 2020 19:22:28 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 3/5] linux-user/i386: Emulate x86_64 vsyscalls Date: Wed, 12 Feb 2020 19:22:21 -0800 Message-Id: <20200213032223.14643-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200213032223.14643-1-richard.henderson@linaro.org> References: <20200213032223.14643-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::1041 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 , laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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 --- v3: Adjust the gotos. Define TARGET_VSYSCALL_PAGE. --- target/i386/cpu.h | 7 +++ linux-user/i386/cpu_loop.c | 108 +++++++++++++++++++++++++++++++++++++ target/i386/translate.c | 14 ++++- 3 files changed, 128 insertions(+), 1 deletion(-) -- 2.20.1 diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 08b4422f36..39be555db3 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/linux-user/i386/cpu_loop.c b/linux-user/i386/cpu_loop.c index e217cca5ee..70cde417e6 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/translate.c b/target/i386/translate.c index d9af8f4078..5e5dbb41b0 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 Feb 13 03:22:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 183328 Delivered-To: patch@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp27917ile; Wed, 12 Feb 2020 19:22:46 -0800 (PST) X-Google-Smtp-Source: APXvYqypnf9POr9S0vpHKumUYE8dGc9yq/seyc3cKUFTY+XnV0Bs2QX23+F8CEH+Sj0Q+rXTFNGz X-Received: by 2002:a05:620a:8ca:: with SMTP id z10mr2791726qkz.242.1581564166345; Wed, 12 Feb 2020 19:22:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581564166; cv=none; d=google.com; s=arc-20160816; b=dT3OLXt2KcTvGi80IgM2WrZiSVGf7SLM4hdUp+FCqRRm2exOIHL+oTuRA5LIc0hcTh R06PU/fsC/OfduXwIUX1ppIw3l+xyzaz2gDavJG11WADOrZMI9rDXkgx6Nf3fiCvCImT 7H5UDo6IjnNrcNLr9+QiRVdkrTN+8ck3Xg6BSbtCoQzlGgKNm7OgF42gnhZbHPAVG/on fmgrsvU5CeLfGvwfmfhrbaJ+B5XgKQ1rMT6zrHIvwUFwsJUqvPVtztbd3VRz/PpVX0eu NavcdRhdYy0R4dX1p9wB7HGuIfhgfitJwkUkv0V2cVRVDXTzS078cX+pJ3+6BgNQu8Tj E1EQ== 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 :dkim-signature; bh=FNe39eIz0v47jOI5MYP3eadgdWO6rgbl92hzBmHUc0w=; b=jeS0EPjWGFxu9o5Es1esHZTI7lUXb1GlHW2DjWeauEYTI6tZfO2vLLa5n05iizI4+n JzB5LvfmYBvb2RzAymusBsFN6tg80k2wPKCOwv4gJgMCBFpsdRQ1T3UcdjstTL7hdah8 W4E8TGa+jJKDuIbNq5uTrAC5uHVFpjcZ/+BioSa2LHMTuVvbctB3qWDrmaxdjeg4qa99 hl6gItNrE2vGZwa/dWJuLF2bAEg6BbGlqemxp5/3uKTa60zsfUYM6dGO3Ur1QRsX9m96 Pf7LgEk6CgfMZypGILlTGrnyKwd8DDxO4iRbMDhFHrOY2Sxuq6nltLL05ldh2TTC6x8S pRJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HIXbCS1Z; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id m18si373894qvv.130.2020.02.12.19.22.46 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 12 Feb 2020 19:22:46 -0800 (PST) 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; dkim=pass header.i=@linaro.org header.s=google header.b=HIXbCS1Z; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:46810 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j255R-0002Nl-OV for patch@linaro.org; Wed, 12 Feb 2020 22:22:45 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:60179) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j255G-0002Hb-3e for qemu-devel@nongnu.org; Wed, 12 Feb 2020 22:22:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j255F-0000NF-2o for qemu-devel@nongnu.org; Wed, 12 Feb 2020 22:22:34 -0500 Received: from mail-pj1-x1044.google.com ([2607:f8b0:4864:20::1044]:52547) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j255E-0000Lv-Ti for qemu-devel@nongnu.org; Wed, 12 Feb 2020 22:22:33 -0500 Received: by mail-pj1-x1044.google.com with SMTP id ep11so1746732pjb.2 for ; Wed, 12 Feb 2020 19:22:32 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=FNe39eIz0v47jOI5MYP3eadgdWO6rgbl92hzBmHUc0w=; b=HIXbCS1ZU372+NaJEEEzzWn7BlZr4pjvORj7nWp9LM5MR7V83wNETb0Pcgamv9jjPM MSCSrrwrVfKyjCrW9VbMTD6ZyvA9ltnyrPka96gWtNueWaFKyXL1LO6HzRZ1LxlsHwJH E4R9Dx/cdFt90v13RlD8xWLD+dUZk/Yku707pLxH9CFq3wSpyMKeXt7lvT0GR4/cvo37 aaByeQR7+gU7LctR6vhj89U4o+I0JElRL2jhtmhu8FmUNxZ9Iw95SJtqNwK9Ddn+FvKN IJMW05OECoHeWggQkSZrEjXuknGc8k9+psGW8QKHPQC1BjEZY92dYPBd/k7xZdaBIjqI HJIw== 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:mime-version:content-transfer-encoding; bh=FNe39eIz0v47jOI5MYP3eadgdWO6rgbl92hzBmHUc0w=; b=jJYh5IKeLU7vK9Fye2wJUzjZiNxY0vZMD0vwMx1kCBKjSuNffL6EE/CnN1jtR3zavh Ce8R7mOOn4LxHdqNFQY1/s3iChuQKs6FX5Y3S7yiD58S4xhc2nYqx5FpLH+/WN4Wc3fp 4mq1/57F6LgQVl/h1OqoouNrS2BPkUdfg8yzyW3KUmNTZI7OD+MUGLeEFYbTIN5aDn4/ j19sb0UfB3f5Zsgldk0SeEz43wfBOfs/ZCDO18wemDoZWXV2RzoUgeMzKJZMrXzXAlyu C+siWHRRxrECPWpU1LRx8CX+qi+Y64co9lMSq2F7d8y7GXpcpSJGe0q4Xc0Yfg3PS1ew M9AA== X-Gm-Message-State: APjAAAWxbI/LiWb6ao5lCPNUBt7xuYB6BwQR908IWW1Q0T6Brb9EsEOV YIyMocWafGyaID1TJ8bWGFVBvZ0JDu0= X-Received: by 2002:a17:902:ab95:: with SMTP id f21mr10487855plr.188.1581564150563; Wed, 12 Feb 2020 19:22:30 -0800 (PST) Received: from localhost.localdomain (97-126-123-70.tukw.qwest.net. [97.126.123.70]) by smtp.gmail.com with ESMTPSA id l15sm536067pgi.31.2020.02.12.19.22.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Feb 2020 19:22:29 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 4/5] linux-user: Add x86_64 vsyscall page to /proc/self/maps Date: Wed, 12 Feb 2020 19:22:22 -0800 Message-Id: <20200213032223.14643-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200213032223.14643-1-richard.henderson@linaro.org> References: <20200213032223.14643-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::1044 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: laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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 --- v3: Use TARGET_VSYSCALL_PAGE. --- linux-user/syscall.c | 10 ++++++++++ 1 file changed, 10 insertions(+) -- 2.20.1 diff --git a/linux-user/syscall.c b/linux-user/syscall.c index d60142f069..b684727b83 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -7012,6 +7012,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 Feb 13 03:22:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 183331 Delivered-To: patch@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp29428ile; Wed, 12 Feb 2020 19:24:55 -0800 (PST) X-Google-Smtp-Source: APXvYqyCBzNS99gllxdjzw2wP9oWYzbKKPNM+KIhqEp+U9mi2YmnIc6X/Ju7190z35Rt52Cjo6Bk X-Received: by 2002:ac8:b43:: with SMTP id m3mr9724893qti.191.1581564295838; Wed, 12 Feb 2020 19:24:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581564295; cv=none; d=google.com; s=arc-20160816; b=xrWjMKLRU1ZsHkpA0/u/U/hbErO7/UDcEu9ucOTn2gmpchx5wX1xz7y6cKttvHkRDK uAbAUOLQr6/B3hvPoAXb66uoswBFKOS8rDfBmm+V2HoeYRsYBhC8yRjlgAgPp4uCLGVP 2vwyVYaQmQlZ64ps2jP7pSLqY6MjaO5BCFQU5fEyQveqvDc9Jl4LLQ033Ke1SZe5g91r IwLpyOVSyixkj0IqSHfVSNHZqdfEe1k6ITQ8MhZUP43qa6A49nWDssHRjpg/sTKDAn4C KZMktU7p8P7BBlMn7YPbiZZXCoiwYBKe/QgOKeqp0pwC9mbITPlsSHoM5e4a1wwjpU3V m6sA== 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 :dkim-signature; bh=loZSDj7GbxB0gzb7RHJRf8hxO888UT+p/O47I0Z8QQ8=; b=vdL0Mv9glX5u7aS6ETzExMVSx0xOvs0NzaMiE7aqk6Ptk4BGAvyvESFM9EJ/iLutos JZD6nC9IjRDdHcdLSyCexpkNAuyAxZcmgkG9/40RL8C52ccMmiGv8oSbp7OD/FPjTBZu xB73xSyijhfxS2upuO2U9CeNRNbLD4fpBXeslGFjgmxn9nEPKhK9/V+H9X8ZndSyj7s9 HEKn5SRUluAT5L9BiEBmKcKlrBnkvMxmM3HcJUrWuTJpGKAV5PQCt3X9y9e/PMleDTKT Ft7nug5d+hjcTZC6Q5nwnym2G1DS3/Bq+gMgGzdgsepfZAWkY3xiTPzst1HhXXrqMAut entQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=ebFsybtE; 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"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id f10si589100qtm.88.2020.02.12.19.24.55 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 12 Feb 2020 19:24:55 -0800 (PST) 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; dkim=fail header.i=@linaro.org header.s=google header.b=ebFsybtE; 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"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:46860 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j257X-0006S8-CY for patch@linaro.org; Wed, 12 Feb 2020 22:24:55 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:60193) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j255H-0002KQ-4W for qemu-devel@nongnu.org; Wed, 12 Feb 2020 22:22:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j255G-0000TH-5u for qemu-devel@nongnu.org; Wed, 12 Feb 2020 22:22:35 -0500 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]:45221) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j255G-0000Pw-0d for qemu-devel@nongnu.org; Wed, 12 Feb 2020 22:22:34 -0500 Received: by mail-pl1-x643.google.com with SMTP id b22so1740614pls.12 for ; Wed, 12 Feb 2020 19:22:33 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=loZSDj7GbxB0gzb7RHJRf8hxO888UT+p/O47I0Z8QQ8=; b=ebFsybtErAWS33ZnmSR9QtMslkJ+yhZ1QYl+bDmPK8/RDQ4UPTffxGbi6DXGB54ZS+ R+vbhhSCdcQSMfT5dERWaIzUJfa1Oihc8oCYDvLx9h3LxCciGYsiS8vmGnEb4KnF0ntj HiwkAnilA9x4gtnDiiYimLfCblFIpDri62aW9NXAC0ToiwdzQoLfRiGx2NHCWnZV4EVP LIipGOgtOSqbyaPJ3iGg8XVWVKiq7P+XmWs9IqcI6XsQ570HiI4jEAF8opERscEnoCVt 1z0BQUhxgwAfpb737KDnQjd4wfRx6cxQUibhVRtiy+9qAYUHe9PFLi0y8lZgV3znDg+f tPWA== 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:mime-version:content-transfer-encoding; bh=loZSDj7GbxB0gzb7RHJRf8hxO888UT+p/O47I0Z8QQ8=; b=o7rh8FzJ/tctknX9aaO8B+fzLuEXf2C3ozQqlLAq0XA/sI8QemLBnd2NyDZ9a4wRYL YxXzgBw8yeaOy5deOlg8S1Kut2do2kIAfYD/o7D33jH6fAVtQT99HWZubajDe1o0GONr LBYSXvpLXCDNdIHFYyZrU9NUtdDaChKQK0q8bmEamujLpHd0fvzFQkRR1ZF1ADMU31f7 2fxDExWES6VraNw5tCfjMD5QUFxiDj/pKPcDCY7dymGA1l3Pu+3zxDqeW25YKj0CTVXC /h2KVLmSqPDM3NWQk5Hl6XgT8nIIa4HieX1abapBFrJ1qrh1vVivQo42/JrhkVdK1P31 4hAw== X-Gm-Message-State: APjAAAXxQ4eJJA8ZR4R4rh1RNCEWJfXdHMMgnZXXDyMxL3i0VkoOZr5l FF2pLWtl7K0HMLYTz3V8Bsx6c3hTtGA= X-Received: by 2002:a17:90a:e509:: with SMTP id t9mr2534894pjy.110.1581564152733; Wed, 12 Feb 2020 19:22:32 -0800 (PST) Received: from localhost.localdomain (97-126-123-70.tukw.qwest.net. [97.126.123.70]) by smtp.gmail.com with ESMTPSA id l15sm536067pgi.31.2020.02.12.19.22.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Feb 2020 19:22:32 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 5/5] linux-user: Flush out implementation of gettimeofday Date: Wed, 12 Feb 2020 19:22:23 -0800 Message-Id: <20200213032223.14643-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200213032223.14643-1-richard.henderson@linaro.org> References: <20200213032223.14643-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::643 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?= , =?utf-8?q?Alex_Benn=C3=A9e?= , laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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 --- linux-user/syscall.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) -- 2.20.1 diff --git a/linux-user/syscall.c b/linux-user/syscall.c index b684727b83..a006e53088 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -1224,6 +1224,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) { @@ -8575,10 +8592,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;