From nobody Fri Apr 19 11:45:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1579036412; cv=none; d=zohomail.com; s=zohoarc; b=k/iqRSO1MvNCFiiZkFp9SCpn9d2DfdDXtpp3SlpoxHX9CKK2dAaPaPi2j8s7oOtB18jsNqU2c5vhZpYdGK1TLoa17DFNUvXQUd3/mY/xUZbxwUsfsS7WYfRCEBOS/XKTt/d20z3OomDVyxYxj81LhmIhYxcs68NRpJEiWDJenWA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579036412; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=4s1PqpDA2phXf0Lid2sF9zCU5S3KdedJJZ1I7QflK10=; b=UY7BoswhgcoOnJzVLBUzojh+ZK6KtlLtmsfip8AxvzL6ONTmC+k57jcVEQe3rm6RyzROq90U5Ksx04/WERzRXfL6i2pMf4Da5d8dZcchShcyy2dNzYUZDlQhO3EsAimYHqUYER5mqk9xzKDQS3S7VbfS+p0zT27+ehgcsy5uKyI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1579036412011951.9763879834235; Tue, 14 Jan 2020 13:13:32 -0800 (PST) Received: from localhost ([::1]:46048 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irTVC-00065T-Lw for importer@patchew.org; Tue, 14 Jan 2020 16:13:30 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40817) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irTRK-00022g-Nm for qemu-devel@nongnu.org; Tue, 14 Jan 2020 16:09:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1irTRJ-0001Qe-R0 for qemu-devel@nongnu.org; Tue, 14 Jan 2020 16:09:30 -0500 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]:36917) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1irTRJ-0001PM-LR for qemu-devel@nongnu.org; Tue, 14 Jan 2020 16:09:29 -0500 Received: by mail-pf1-x442.google.com with SMTP id p14so7180613pfn.4 for ; Tue, 14 Jan 2020 13:09:29 -0800 (PST) Received: from cloudburst.ASUS (rrcs-66-91-136-155.west.biz.rr.com. [66.91.136.155]) by smtp.gmail.com with ESMTPSA id d26sm17881020pgv.66.2020.01.14.13.09.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2020 13:09:27 -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=4s1PqpDA2phXf0Lid2sF9zCU5S3KdedJJZ1I7QflK10=; b=OKEvSgwyeHh3f0wJjlOVQQtX+sacNY++tkDoDrglulLWsMrjJAlgkMcwSpchzowu+/ lMgcgQpqXhCXN3eE1pCH3yytK/ZTGAICUiXDTB5+uSryCpKcZwXh+ayHuQGkBYpLgsMh mkFkAh+Nia0vFqBQ7fVb0xtAo9ysZBBcdx9xAZm0ZtWrj8413lj5JNbvyUdxiuIzV3sL UwuSWO9p1CyayR+U6q+VSSjpYD3dD6AQPaCnf8gk8scOZSBDCdixAsH2bOYf4LKy/y4i 2egnwstlxDKmw+gQn4SbLEmuxKLcL/KeQUKtCLOpaZY0JA1pPkMHpn3C7AACjQ75NrpO qAjw== 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=4s1PqpDA2phXf0Lid2sF9zCU5S3KdedJJZ1I7QflK10=; b=M1JeVuyO9CfivnfGUgzTznaRlUBsgi9SPv0ytiTON3a14E2f7B07GUgPBtMWkUzkhZ iQ2clYiD6zsqDA9lLrQOtwr8Yd53fwQf+R0L3SPrFLzZODv97AX3gAb9h8G/kuGOiX8G b1Fg9qmB0KssZKRoQmaqlQn+6zAkQAfNLpcbLo1p0CBI5nCVxb0BZd3hF/4iD/KRLDlP iamnWp77rYz/N7Xsj6n2oR2EZpVXfnOXLxBcLzWj7iHnOV0uzTmlUqqQRgmz5i+NuYhY /vH4Jfv+PX/Z6080CIqqJxwKk2ApkOR8pX1GdQBkzOhvDQZeaEiciWSMmJ6wi8bFqNZe h/Aw== X-Gm-Message-State: APjAAAXd4mAjitN5mvyptraGnvNiPKkQiskm83cyJZa5Asnc/qX+x5DD /j3iubqnrut4InSt6rhZWQ5AFiyobdg= X-Google-Smtp-Source: APXvYqyXPA1WupNkOBPSoMvUE3OVlL85WYspCcGAmLg+N6VsrO9SrjBK3bXbRmzZGXNDICAw2/OpIg== X-Received: by 2002:a65:644b:: with SMTP id s11mr29280672pgv.332.1579036168326; Tue, 14 Jan 2020 13:09:28 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 1/3] target/i386: Renumber EXCP_SYSCALL Date: Tue, 14 Jan 2020 11:09:19 -1000 Message-Id: <20200114210921.11216-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200114210921.11216-1-richard.henderson@linaro.org> References: <20200114210921.11216-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::442 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: pbonzini@redhat.com, riku.voipio@iki.fi, laurent@vivier.eu, peter.maydell@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Richard Henderson Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Paolo Bonzini Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- target/i386/cpu.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 594326a794..164d038d1f 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -998,9 +998,8 @@ typedef uint64_t FeatureWordArray[FEATURE_WORDS]; #define EXCP11_ALGN 17 #define EXCP12_MCHK 18 =20 -#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 */ =20 /* i386-specific interrupt pending bits. */ #define CPU_INTERRUPT_POLL CPU_INTERRUPT_TGT_EXT_1 --=20 2.20.1 From nobody Fri Apr 19 11:45:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1579036302; cv=none; d=zohomail.com; s=zohoarc; b=Lisf7LJSOoDrIO6kg4IGl32pJUMQBNeXL5lR3ZjrdVVRFj76hJL/F1dqDuicydf3o+UmDYL1PQxKtQrDeDIhGeXrNR3MyHw3S4Yk/7USF1VFIMobsb5cyV7QFOGq2sOvOfL4iI+asO8HC3Wv9QS5bg7fljgT+Ax5LYpmcNudJfA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579036302; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=OtMkA9jtkqDohRDArG4G7wi+OMjr6/nJEha17cuXw6E=; b=lj64osGrL9l0eEw98/qEMGX618bAK6KySyutcSDzY3jUhqipsgU90O918+GdjCoG2jEH97J3B+QtFt+IYCqxRA4S8INql6r/k2xbfI60sx4GHjKxH1dPV632g/+eB+Mszt5kMMgD7v4Zfk2+vDp76AqGE171SsZXJ12oZD6mBj0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1579036302468141.39434218636507; Tue, 14 Jan 2020 13:11:42 -0800 (PST) Received: from localhost ([::1]:46010 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irTTP-0004EF-Vq for importer@patchew.org; Tue, 14 Jan 2020 16:11:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40852) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irTRN-00024v-Dy for qemu-devel@nongnu.org; Tue, 14 Jan 2020 16:09:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1irTRM-0001Sh-5e for qemu-devel@nongnu.org; Tue, 14 Jan 2020 16:09:33 -0500 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]:38039) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1irTRL-0001Rv-WB for qemu-devel@nongnu.org; Tue, 14 Jan 2020 16:09:32 -0500 Received: by mail-pf1-x441.google.com with SMTP id x185so7187157pfc.5 for ; Tue, 14 Jan 2020 13:09:31 -0800 (PST) Received: from cloudburst.ASUS (rrcs-66-91-136-155.west.biz.rr.com. [66.91.136.155]) by smtp.gmail.com with ESMTPSA id d26sm17881020pgv.66.2020.01.14.13.09.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2020 13:09: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=OtMkA9jtkqDohRDArG4G7wi+OMjr6/nJEha17cuXw6E=; b=Z9CGgoAa+dsFr6+KZtK2eUY1b0RHugwIy4f4fwN+Hdy5kaiiSt0LCIDvclEUIDG3pu 7FXktKQodAQnJiYuM8XHAWiBNg8EwvoiUUjeMkTCgSigj+XkXjbpn8rj4R8ckvG/aZD3 cfr+5B9rtB58b5ICN108inS/WNlisYaQDtVR1rXr6EbSUZN9tsG5XYMpX5WBB+HazUzB x7vPmrfWQDxiQ+1tiqNVfglODA2CHUbCcEmAGdERFWHn0LS6i+T7aldZkuDXAkV8hXhg PCOsE9bLvmBDhXiZgASzp62NLjGjXLlwtcY+BI18NhgIQ98riWRZXNxU6y7/4PJvEXb0 g0XA== 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=OtMkA9jtkqDohRDArG4G7wi+OMjr6/nJEha17cuXw6E=; b=FJL62jpfkFWXMl3XguHJAkcAVUQtbOUi3I4yP74ncj02qorCiygly5uux8umQcLErZ wpKuIebP8AMAHm8223MNd+bK74kAPM6zQTk+tWKjxZCph7ssQBVRUcBlrHAnsuJV/UCR 3nefrjdTWD52DaqkRL5SElbgmTRw7bg7Gz18TstWRA6tYYgPWIuqtRSdyMvySdirohO9 aS+66oLB6iMHVCwq/6Xsg3tCZ6tNwgbHmg+vsdbr7LE+ZigXd9B1i+lUArtHDKXKdOkb s1XjnwK6Lz4oQrIns/8Zx8PukYX8jgrq2Bml9DDzKK1Zx2dL88RxfSRIE/5G/KxzyILQ AnlQ== X-Gm-Message-State: APjAAAUMxv+5ewVCZDr3yoYUW7GXftxhVolGJp/VXnxcuuXAWbHb2Qd8 SVuSxZYic42/FL3EJRlJiblzOD9m400= X-Google-Smtp-Source: APXvYqxGDRkX9hZgZp0Ho6y4PR2LRuXqQISsM5/IbZiS8JB/xc80iJfg0Dm8DvZvcT/GfK3rXHnNzA== X-Received: by 2002:aa7:9a10:: with SMTP id w16mr26927694pfj.107.1579036170851; Tue, 14 Jan 2020 13:09:30 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 2/3] linux-user/i386: Split out gen_signal Date: Tue, 14 Jan 2020 11:09:20 -1000 Message-Id: <20200114210921.11216-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200114210921.11216-1-richard.henderson@linaro.org> References: <20200114210921.11216-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::441 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: pbonzini@redhat.com, riku.voipio@iki.fi, laurent@vivier.eu, peter.maydell@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Richard Henderson Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Paolo Bonzini Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- linux-user/i386/cpu_loop.c | 93 ++++++++++++++------------------------ 1 file changed, 33 insertions(+), 60 deletions(-) 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 =20 +static void gen_signal(CPUX86State *env, int sig, int code, abi_ptr addr) +{ + target_siginfo_t info =3D { + .si_signo =3D sig, + .si_code =3D code, + ._sifields._sigfault._addr =3D addr + }; + + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); +} + void cpu_loop(CPUX86State *env) { CPUState *cs =3D env_cpu(env); int trapnr; abi_ulong pc; abi_ulong ret; - target_siginfo_t info; =20 for(;;) { cpu_exec_start(cs); @@ -134,70 +144,45 @@ void cpu_loop(CPUX86State *env) #endif case EXCP0B_NOSEG: case EXCP0C_STACK: - info.si_signo =3D TARGET_SIGBUS; - info.si_errno =3D 0; - info.si_code =3D TARGET_SI_KERNEL; - info._sifields._sigfault._addr =3D 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 =3D TARGET_SIGSEGV; - info.si_errno =3D 0; - info.si_code =3D TARGET_SI_KERNEL; - info._sifields._sigfault._addr =3D 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 =3D TARGET_SIGSEGV; - info.si_errno =3D 0; - if (!(env->error_code & 1)) - info.si_code =3D TARGET_SEGV_MAPERR; - else - info.si_code =3D TARGET_SEGV_ACCERR; - info._sifields._sigfault._addr =3D 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 =3D TARGET_SIGFPE; - info.si_errno =3D 0; - info.si_code =3D TARGET_FPE_INTDIV; - info._sifields._sigfault._addr =3D 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 =3D TARGET_SIGTRAP; - info.si_errno =3D 0; - if (trapnr =3D=3D EXCP01_DB) { - info.si_code =3D TARGET_TRAP_BRKPT; - info._sifields._sigfault._addr =3D env->eip; - } else { - info.si_code =3D TARGET_SI_KERNEL; - info._sifields._sigfault._addr =3D 0; - } - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + if (trapnr =3D=3D EXCP01_DB) { + gen_signal(env, TARGET_SIGTRAP, TARGET_TRAP_BRKPT, env->ei= p); + } 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 =3D TARGET_SIGSEGV; - info.si_errno =3D 0; - info.si_code =3D TARGET_SI_KERNEL; - info._sifields._sigfault._addr =3D 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 =3D TARGET_SIGILL; - info.si_errno =3D 0; - info.si_code =3D TARGET_ILL_ILLOPN; - info._sifields._sigfault._addr =3D 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 =3D TARGET_SIGTRAP; - info.si_errno =3D 0; - info.si_code =3D 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); --=20 2.20.1 From nobody Fri Apr 19 11:45:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1579036500; cv=none; d=zohomail.com; s=zohoarc; b=IngKU7oS257IUbd1AjgLNrW/GtIydQCA8sbinuDKfYhN6ofByYtrc5FdzmCGot3zAyJxvv+2+aj/Wnfl8k9/LIZT6+y7oU1q7DjpyRyf47Rv6dMIhs0NzswDx4li5ASslGOacEXGtDuJWPc8nH5MHoYlXGbXULc2waTlT4j0F/o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579036500; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=9lI8WRIgAr/TmVWyIUuWbVdccm9/3r0w1XSlr2VZrj8=; b=gvNjXJZqXI8BCHKF9xj0btzbB2XEamIRbXaEsFTQ1vNUuEBsl+KVJSWq7uMsoM4vhAezkUxpDD2vyHdKJaXslkf3nhU8Uf9pInIJCpfdVwkUpHxZb62aT2nqIWAikew6vFfMwR401xhxShy38OVHMq3rQFr9UsCEzm++YuQPj14= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1579036500430711.9882316974092; Tue, 14 Jan 2020 13:15:00 -0800 (PST) Received: from localhost ([::1]:46068 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irTWd-0007II-Bw for importer@patchew.org; Tue, 14 Jan 2020 16:14:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40901) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irTRS-0002Az-F0 for qemu-devel@nongnu.org; Tue, 14 Jan 2020 16:09:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1irTRR-0001Wg-5W for qemu-devel@nongnu.org; Tue, 14 Jan 2020 16:09:38 -0500 Received: from mail-pj1-x1041.google.com ([2607:f8b0:4864:20::1041]:39403) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1irTRQ-0001Va-VU for qemu-devel@nongnu.org; Tue, 14 Jan 2020 16:09:37 -0500 Received: by mail-pj1-x1041.google.com with SMTP id e11so4889309pjt.4 for ; Tue, 14 Jan 2020 13:09:35 -0800 (PST) Received: from cloudburst.ASUS (rrcs-66-91-136-155.west.biz.rr.com. [66.91.136.155]) by smtp.gmail.com with ESMTPSA id d26sm17881020pgv.66.2020.01.14.13.09.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2020 13:09: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=9lI8WRIgAr/TmVWyIUuWbVdccm9/3r0w1XSlr2VZrj8=; b=jfI/3fOjamIo03jzwwbaELN6PgeBrvFi1IsmjMlqTlB7HaU2aiRr1l5WvFnOApXlhb +4AKpKLx3MJ3flhWrXYceb/hujvZdFY4Pzt4Kb1yt5lOa/Lwp0Scn0Mmm0wET02N1DAG Rw8qNPm2830jimxXFRbzLk7bhqP9C1jTbWkaP9DeyaMKsqTzQw3LRUuCy06OOq9W3ArG YcsbtqNdKYj9LMc14ytZo9zkMCniN4LiJc4TmVAkRwfQHIbZftDJshX4n3RXYmDfIbna NgSWlfdQwrlqRrAy7IP2W25fBie7CPJ7ZrHNTHDlboT7mPfQMT97ZYHtNHYPx0kcF2+L h4YA== 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=9lI8WRIgAr/TmVWyIUuWbVdccm9/3r0w1XSlr2VZrj8=; b=cytF/mQClVoAIN6GmGuF1xD9pucj5geNkE2UOFl4HAw+Tgv871sNcDIPfnyrGYL/DT RaC81G9yU6t1W7mNOu/SJthbf1L5JhJsh0ATsxoFWUHnZ0H5cEgHsEI27Z43WUCAepYu WwjGwaAAm8m4zNCZStGal1DDXh7eIZzmo9eCEBxc8ciUx5rqZfRoZIx4EUtyMtp3YleO 21y0zWaQRV+nVEiaeU6Iqft8BOrCptrLs8xC4Tb6lBpqJqp3OsXNujAQ65mMtjO00V3j QY9frGJbtJkedTXSxQdtQ+hJqOM1ZE5rWMm0OtEE9ffGX5TrvxdYDRMBmobeCuDqwMxm rGxw== X-Gm-Message-State: APjAAAWHp/RgaVzZz+GACMF9U+o7hWxp/OJJbA5MojNREF788vjM5xGm 5ne8uSBT1RkuVITNHbIzTXvE1IQ0gl8= X-Google-Smtp-Source: APXvYqxyvWVvOZ46EzvrdrNyDuBtgQwVP+QAHkbNgUgbUYAiiqmU5zh6NFiB/2AC1OwhTrz+YTwSvQ== X-Received: by 2002:a17:90a:7f01:: with SMTP id k1mr16441140pjl.81.1579036174507; Tue, 14 Jan 2020 13:09:34 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 3/3] linux-user/i386: Emulate x86_64 vsyscalls Date: Tue, 14 Jan 2020 11:09:21 -1000 Message-Id: <20200114210921.11216-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200114210921.11216-1-richard.henderson@linaro.org> References: <20200114210921.11216-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: pbonzini@redhat.com, riku.voipio@iki.fi, laurent@vivier.eu, peter.maydell@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Richard Henderson Reviewed-by: Paolo Bonzini --- target/i386/cpu.h | 1 + linux-user/i386/cpu_loop.c | 104 +++++++++++++++++++++++++++++++++++++ target/i386/translate.c | 16 +++++- 3 files changed, 120 insertions(+), 1 deletion(-) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 164d038d1f..3fb2d2a986 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1000,6 +1000,7 @@ typedef uint64_t FeatureWordArray[FEATURE_WORDS]; =20 #define EXCP_VMEXIT 0x100 /* only for system emulation */ #define EXCP_SYSCALL 0x101 /* only for user emulation */ +#define EXCP_VSYSCALL 0x102 /* only for user emulation */ =20 /* i386-specific interrupt pending bits. */ #define CPU_INTERRUPT_POLL CPU_INTERRUPT_TGT_EXT_1 diff --git a/linux-user/i386/cpu_loop.c b/linux-user/i386/cpu_loop.c index e217cca5ee..8b7c9f7337 100644 --- a/linux-user/i386/cpu_loop.c +++ b/linux-user/i386/cpu_loop.c @@ -92,6 +92,105 @@ static void gen_signal(CPUX86State *env, int sig, int c= ode, abi_ptr addr) queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); } =20 +#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 =3D=3D 0 || access_ok(VERIFY_WRITE, addr, len)) { + return true; + } + + 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, now verify the offset. + */ + switch (env->eip & ~TARGET_PAGE_MASK) { + case 0x000: + syscall =3D TARGET_NR_gettimeofday; + break; + case 0x400: + syscall =3D TARGET_NR_time; + break; + case 0x800: + syscall =3D TARGET_NR_getcpu; + break; + default: + sigsegv: + /* Like force_sig(SIGSEGV). */ + gen_signal(env, TARGET_SIGSEGV, TARGET_SI_KERNEL, 0); + return; + } + + /* + * 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, + * and all faults should have been caught above. + */ + ret =3D 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 !=3D -TARGET_ERESTARTSYS); + g_assert(ret !=3D -TARGET_QEMU_ESIGRETURN); + g_assert(ret !=3D -TARGET_EFAULT); + env->regs[R_EAX] =3D ret; + + /* Emulate a ret instruction to leave the vsyscall page. */ + env->eip =3D caller; + env->regs[R_ESP] +=3D 8; +} +#endif + void cpu_loop(CPUX86State *env) { CPUState *cs =3D env_cpu(env); @@ -141,6 +240,11 @@ void cpu_loop(CPUX86State *env) env->regs[R_EAX] =3D 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 7c99ef1385..391b4ef149 100644 --- a/target/i386/translate.c +++ b/target/i386/translate.c @@ -8555,7 +8555,21 @@ static bool i386_tr_breakpoint_check(DisasContextBas= e *dcbase, CPUState *cpu, static void i386_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu) { DisasContext *dc =3D container_of(dcbase, DisasContext, base); - target_ulong pc_next =3D disas_insn(dc, cpu); + target_ulong pc_next; + +#if defined(TARGET_X86_64) && \ + defined(CONFIG_USER_ONLY) && \ + defined(CONFIG_LINUX) + /* + * Detect entry into the vsyscall page and invoke the syscall. + */ + if ((dc->base.pc_next & TARGET_PAGE_MASK) =3D=3D 0xffffffffff600000ull= ) { + gen_exception(dc, EXCP_VSYSCALL, dc->base.pc_next); + return; + } +#endif + + pc_next =3D disas_insn(dc, cpu); =20 if (dc->tf || (dc->base.tb->flags & HF_INHIBIT_IRQ_MASK)) { /* if single step mode, we generate only one instruction and --=20 2.20.1