From patchwork Thu Mar 9 11:17:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 95105 Delivered-To: patch@linaro.org Received: by 10.140.82.71 with SMTP id g65csp311773qgd; Thu, 9 Mar 2017 03:25:47 -0800 (PST) X-Received: by 10.55.83.71 with SMTP id h68mr12343073qkb.259.1489058747696; Thu, 09 Mar 2017 03:25:47 -0800 (PST) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id q19si5429002qtg.125.2017.03.09.03.25.47 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 09 Mar 2017 03:25:47 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:33329 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clwCX-0002if-5A for patch@linaro.org; Thu, 09 Mar 2017 06:25:45 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54504) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clw4L-0005Fk-SX for qemu-devel@nongnu.org; Thu, 09 Mar 2017 06:17:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1clw4K-0006Yr-2C for qemu-devel@nongnu.org; Thu, 09 Mar 2017 06:17:17 -0500 Received: from mail-wm0-x232.google.com ([2a00:1450:400c:c09::232]:36657) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1clw4J-0006YP-PS for qemu-devel@nongnu.org; Thu, 09 Mar 2017 06:17:15 -0500 Received: by mail-wm0-x232.google.com with SMTP id n11so136796302wma.1 for ; Thu, 09 Mar 2017 03:17:15 -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=3TTT4ZNU+mhr/sFuYyEUX9LGNuyRL3xCauXi28ZNfCs=; b=QozyHJfupum5bUEVgn3bDWB9BQ+XwFTJCjfOzMaBcCthQl6rwgLbvFcZlE319EA4DR I95IMed/hgmpHcRmIp5FCYj9UebxbjuwtDZNMpyjzHnmLm0gN8w9I/mWYxvut+lKOEa1 5DwTnB4wlQJQfkxIpz3tWHJwJqPQ0JDLHHSWc= 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=3TTT4ZNU+mhr/sFuYyEUX9LGNuyRL3xCauXi28ZNfCs=; b=NkEJi0ncxMwGIb5Vl2qjxyAyfWZSD0Jp0kPoKoFd7Dkw2ixl6AKpawO52if+MGGpjb 7Mh65HG1Cn64YkjnH/J66whgw+ZdQyeCKFE+M3ZbKt1dhupvNum0O4AtMIf/LGNewiVq aR+tf9dvdLCq+XAighT6lauG6ItVIsKCABBtfD3xH51moYp6jTK4U8dmlTbU5jUiwzkz +AR8yiUmWYwkc4AMgI9j7Cbw+Iv41bX/sjQE9HTKGG8Ms8NUm+k0Ttap3vDGLYm42WI5 pfRrm0RzDhvI5YuJ8zp4QyXfTmTjoHRJ3vBWHmXu2JHe8M/joKH1KyN22lmH1U+NbnCY CbAw== X-Gm-Message-State: AMke39nk60sk53O7bmowFGpVT9p2mO8fcDIXzuBa5s78DvV6Ve6TrwFxvpwWDV19MUwtP3Y7 X-Received: by 10.28.159.73 with SMTP id i70mr10066832wme.78.1489058234639; Thu, 09 Mar 2017 03:17:14 -0800 (PST) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id 36sm7877136wrz.8.2017.03.09.03.17.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Mar 2017 03:17:10 -0800 (PST) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id C0A273E383A; Thu, 9 Mar 2017 11:17:15 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Date: Thu, 9 Mar 2017 11:17:12 +0000 Message-Id: <20170309111714.20394-10-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170309111714.20394-1-alex.bennee@linaro.org> References: <20170309111714.20394-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::232 Subject: [Qemu-devel] [PULL 09/11] target-i386: defer VMEXIT to do_interrupt X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-devel@nongnu.org, Eduardo Habkost , Richard Henderson Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Paolo Bonzini Paths through the softmmu code during code generation now need to be audited to check for double locking of tb_lock. In particular, VMEXIT can take tb_lock through cpu_vmexit -> cpu_x86_update_cr4 -> tlb_flush. To avoid this, split VMEXIT delivery in two parts, similar to what is done with exceptions. cpu_vmexit only records the VMEXIT exit code and information, and cc->do_interrupt can then deliver it when it is safe to take the lock. Reported-by: Alexander Boettcher Suggested-by: Richard Henderson Tested-by: Alexander Boettcher Signed-off-by: Paolo Bonzini Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson --- target/i386/cpu.h | 2 ++ target/i386/seg_helper.c | 20 +++++++++++--------- target/i386/svm_helper.c | 22 +++++++++++++--------- 3 files changed, 26 insertions(+), 18 deletions(-) -- 2.11.0 diff --git a/target/i386/cpu.h b/target/i386/cpu.h index fb09aee7f8..406cb24301 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -697,6 +697,7 @@ typedef uint32_t FeatureWordArray[FEATURE_WORDS]; #define EXCP_SYSCALL 0x100 /* only happens in user only emulation for syscall instruction */ +#define EXCP_VMEXIT 0x100 /* i386-specific interrupt pending bits. */ #define CPU_INTERRUPT_POLL CPU_INTERRUPT_TGT_EXT_1 @@ -1632,6 +1633,7 @@ void cpu_svm_check_intercept_param(CPUX86State *env1, uint32_t type, uint64_t param, uintptr_t retaddr); void cpu_vmexit(CPUX86State *nenv, uint32_t exit_code, uint64_t exit_info_1, uintptr_t retaddr); +void do_vmexit(CPUX86State *env, uint32_t exit_code, uint64_t exit_info_1); /* seg_helper.c */ void do_interrupt_x86_hardirq(CPUX86State *env, int intno, int is_hw); diff --git a/target/i386/seg_helper.c b/target/i386/seg_helper.c index 5c845dc25c..0374031ea2 100644 --- a/target/i386/seg_helper.c +++ b/target/i386/seg_helper.c @@ -1297,15 +1297,17 @@ void x86_cpu_do_interrupt(CPUState *cs) /* successfully delivered */ env->old_exception = -1; #else - /* simulate a real cpu exception. On i386, it can - trigger new exceptions, but we do not handle - double or triple faults yet. */ - do_interrupt_all(cpu, cs->exception_index, - env->exception_is_int, - env->error_code, - env->exception_next_eip, 0); - /* successfully delivered */ - env->old_exception = -1; + if (cs->exception_index >= EXCP_VMEXIT) { + assert(env->old_exception == -1); + do_vmexit(env, cs->exception_index - EXCP_VMEXIT, env->error_code); + } else { + do_interrupt_all(cpu, cs->exception_index, + env->exception_is_int, + env->error_code, + env->exception_next_eip, 0); + /* successfully delivered */ + env->old_exception = -1; + } #endif } diff --git a/target/i386/svm_helper.c b/target/i386/svm_helper.c index 78d8df4af6..59e8b5091c 100644 --- a/target/i386/svm_helper.c +++ b/target/i386/svm_helper.c @@ -580,12 +580,10 @@ void helper_svm_check_io(CPUX86State *env, uint32_t port, uint32_t param, } } -/* Note: currently only 32 bits of exit_code are used */ void cpu_vmexit(CPUX86State *env, uint32_t exit_code, uint64_t exit_info_1, uintptr_t retaddr) { CPUState *cs = CPU(x86_env_get_cpu(env)); - uint32_t int_ctl; if (retaddr) { cpu_restore_state(cs, retaddr); @@ -598,6 +596,19 @@ void cpu_vmexit(CPUX86State *env, uint32_t exit_code, uint64_t exit_info_1, control.exit_info_2)), env->eip); + cs->exception_index = EXCP_VMEXIT + exit_code; + env->error_code = exit_info_1; + + /* remove any pending exception */ + env->old_exception = -1; + cpu_loop_exit(cs); +} + +void do_vmexit(CPUX86State *env, uint32_t exit_code, uint64_t exit_info_1) +{ + CPUState *cs = CPU(x86_env_get_cpu(env)); + uint32_t int_ctl; + if (env->hflags & HF_INHIBIT_IRQ_MASK) { x86_stl_phys(cs, env->vm_vmcb + offsetof(struct vmcb, control.int_state), @@ -759,13 +770,6 @@ void cpu_vmexit(CPUX86State *env, uint32_t exit_code, uint64_t exit_info_1, /* If the host's rIP reloaded by #VMEXIT is outside the limit of the host's code segment or non-canonical (in the case of long mode), a #GP fault is delivered inside the host. */ - - /* remove any pending exception */ - cs->exception_index = -1; - env->error_code = 0; - env->old_exception = -1; - - cpu_loop_exit(cs); } #endif