From patchwork Tue Jul 9 16:36:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 168752 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp8789653ilk; Tue, 9 Jul 2019 09:42:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqzsrvTvEsyviGR0A0dr04XJYGyzSTADTF6oPsvvI02aLbvIWTUT/eD/D6t1HJRzW3rW0Zoh X-Received: by 2002:a17:906:9385:: with SMTP id l5mr21772896ejx.8.1562690523144; Tue, 09 Jul 2019 09:42:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562690523; cv=none; d=google.com; s=arc-20160816; b=exW6m7IhoIcLSgqcMuQE7dlCgy2l3YknBqIxUCEFIz220pMexvmDGugEuyCyud9EBS XE6hkPf0siaPvVxXg92PGfSNOsxwthZP6oRHb8zfRli/Ppe4XzIkQn41ET9Kwh8Decqr 7tGnEGOivYxuf72hPp54lN8SyC8WOlMv7lkJu5GrokiySgjN4AYXdyaCqDzLde2EOpPe dv/xq7ysF90rM3jm+7kyiILySJTgaehreWeCsSKWN+NlZfcZ0nejJIyvcJJgqLULwO9O pOzD5c1kOFMNr39/nucZH4aTOaPOl2OpiHRlviJFi3v91XtiErklRU3AEwGdkWjPTNpo XF9g== 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:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=wKi63WC2ID0LFZEyokn53XQcJ3+e0eDjytzjfhF4FC4=; b=LGXn4fwgHzVdL8cOSY4LJPTX3+Tv64Qio99SbcJXnFELPe/YVO/LXxZV1RmATzfP3y nO/JuDmHDkTiVdnh4NgZ443MUO+SzFREWR+cvDzeJrZcnv57DwupOdXxepTGbrnH/eBU Gp3aarwd/E3o9ZY3IiUEzkOACUhlDB+nN/HF9UGgVxfBlzqe7YeAdI+ITdlhp1LAR461 rXF3npehC2dU9WWM4wAcxGa7MNkhe6WuQXzHtDVEfTQXcXcOu/OeC22mJYpYR+W+GRyT 4w0j38qGU1hE2l3jb/8v9zVGYEbykkmkCn71Qmp41sU72JhkubV42hRcPhvc5HxOe6uj 2fCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=b02Q5tDk; 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 o21si1033432eja.9.2019.07.09.09.42.02 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 09 Jul 2019 09:42:03 -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; dkim=fail header.i=@linaro.org header.s=google header.b=b02Q5tDk; 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]:51938 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hktBq-00060y-4g for patch@linaro.org; Tue, 09 Jul 2019 12:42:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38181) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hkt7s-0003Em-8r for qemu-devel@nongnu.org; Tue, 09 Jul 2019 12:38:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hkt7m-0006v4-Jc for qemu-devel@nongnu.org; Tue, 09 Jul 2019 12:37:53 -0400 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]:43769) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hkt7e-0006jG-Qs for qemu-devel@nongnu.org; Tue, 09 Jul 2019 12:37:44 -0400 Received: by mail-pl1-x642.google.com with SMTP id cl9so10341858plb.10 for ; Tue, 09 Jul 2019 09:37:32 -0700 (PDT) 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; bh=wKi63WC2ID0LFZEyokn53XQcJ3+e0eDjytzjfhF4FC4=; b=b02Q5tDk/hNubaV3heBz8XfZJYQkPE7gra0q5kGO3lHnG8C/qCszOoV+soTRIKxjaK IQe1YpAkuxQM68dXsnco4w13PmK+sfQObYDXYjBwNc7jJ9FBDJS9LUQcxhafoUj9tQEH dhUYs2FKqjWoQptIxYsSPArWQOYYlMDTD1AymatlQGy6yr4uSu4ZTKgkIr2R22JMO7G8 P4UtN7k/k97wd++qOx37+FpvUia1W24ySkPVdfQf8Hv61CEldS8lmlPtUbKBOnC8ALmA QlKS3N+ck3uO+K5FVeXx3NtFMgoAS7NE38+d3HYhuz5nXH79HvGN18mHJNAl5aRWhnCC z5kw== 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; bh=wKi63WC2ID0LFZEyokn53XQcJ3+e0eDjytzjfhF4FC4=; b=GHAZNLu5ThwqR33+chzpvGsCOhAOegmYl53EFftpWesLEdDP/1UIEf4dDM1VT+KbfI hf1jqka2gdWKhpE/tvHA6v0NxtX3NCJ5B6G7PR4fP1KeKGb3WhasfahOWbmR5VpbYN2I vrt+j781cSzwXxc4yqJxT3eCBJgEZW+8LSPTzLEdMZSI9wINAU1n6UnCcb0zF5o6VYJJ phd/DC7AutV73a/8YyLUA0lmMdKtbJp+8b6UY8r1uoLbA85AT/EMhtHnK0fU5rWVoEZt yzKq8evv0hCWqfqTHfDavDbMGVwM7oiMujTGy3z+qlOx2nH8wQAaMeUiF/Jojgi9mXZ0 FMfw== X-Gm-Message-State: APjAAAWo7rFmm4mRV/x9ZPpryJAeBMOO87TAAeu+WGikjwCjExOyYHWd dNoa+HNTfGaI/6oj4pXDhmUI+7rIjvc= X-Received: by 2002:a17:902:2ec5:: with SMTP id r63mr32915763plb.21.1562690250940; Tue, 09 Jul 2019 09:37:30 -0700 (PDT) Received: from localhost.localdomain ([172.56.12.212]) by smtp.gmail.com with ESMTPSA id v8sm19225231pgs.82.2019.07.09.09.37.26 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 09 Jul 2019 09:37:30 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 9 Jul 2019 18:36:56 +0200 Message-Id: <20190709163656.3100-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190709163656.3100-1-richard.henderson@linaro.org> References: <20190709163656.3100-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::642 Subject: [Qemu-devel] [PATCH v2 5/5] tcg: Release mmap_lock on translation fault 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: lvivier@redhat.com, peter.maydell@linaro.org, alex.bennee@linaro.org, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Turn helper_retaddr into a multi-state flag that may now also indicate when we're performing a read on behalf of the translator. In this case, release the mmap_lock before the longjmp back to the main cpu loop, and thereby avoid a failing assert therein. Fixes: https://bugs.launchpad.net/qemu/+bug/1832353 Signed-off-by: Richard Henderson --- include/exec/cpu_ldst_useronly_template.h | 20 +++++-- accel/tcg/user-exec.c | 66 ++++++++++++++++------- 2 files changed, 63 insertions(+), 23 deletions(-) -- 2.17.1 Reviewed-by: Alex Bennée Tested-by: Alex Bennée diff --git a/include/exec/cpu_ldst_useronly_template.h b/include/exec/cpu_ldst_useronly_template.h index d663826ac2..2378f2958c 100644 --- a/include/exec/cpu_ldst_useronly_template.h +++ b/include/exec/cpu_ldst_useronly_template.h @@ -64,12 +64,18 @@ static inline RES_TYPE glue(glue(cpu_ld, USUFFIX), MEMSUFFIX)(CPUArchState *env, abi_ptr ptr) { -#if !defined(CODE_ACCESS) +#ifdef CODE_ACCESS + RES_TYPE ret; + set_helper_retaddr(1); + ret = glue(glue(ld, USUFFIX), _p)(g2h(ptr)); + clear_helper_retaddr(); + return ret; +#else trace_guest_mem_before_exec( env_cpu(env), ptr, trace_mem_build_info(SHIFT, false, MO_TE, false)); -#endif return glue(glue(ld, USUFFIX), _p)(g2h(ptr)); +#endif } #ifndef CODE_ACCESS @@ -90,12 +96,18 @@ glue(glue(glue(cpu_ld, USUFFIX), MEMSUFFIX), _ra)(CPUArchState *env, static inline int glue(glue(cpu_lds, SUFFIX), MEMSUFFIX)(CPUArchState *env, abi_ptr ptr) { -#if !defined(CODE_ACCESS) +#ifdef CODE_ACCESS + int ret; + set_helper_retaddr(1); + ret = glue(glue(lds, SUFFIX), _p)(g2h(ptr)); + clear_helper_retaddr(); + return ret; +#else trace_guest_mem_before_exec( env_cpu(env), ptr, trace_mem_build_info(SHIFT, true, MO_TE, false)); -#endif return glue(glue(lds, SUFFIX), _p)(g2h(ptr)); +#endif } #ifndef CODE_ACCESS diff --git a/accel/tcg/user-exec.c b/accel/tcg/user-exec.c index 4384b59a4d..897d1571c4 100644 --- a/accel/tcg/user-exec.c +++ b/accel/tcg/user-exec.c @@ -64,27 +64,56 @@ static inline int handle_cpu_signal(uintptr_t pc, siginfo_t *info, CPUState *cpu = current_cpu; CPUClass *cc; unsigned long address = (unsigned long)info->si_addr; - MMUAccessType access_type; + MMUAccessType access_type = is_write ? MMU_DATA_STORE : MMU_DATA_LOAD; - /* We must handle PC addresses from two different sources: - * a call return address and a signal frame address. - * - * Within cpu_restore_state_from_tb we assume the former and adjust - * the address by -GETPC_ADJ so that the address is within the call - * insn so that addr does not accidentally match the beginning of the - * next guest insn. - * - * However, when the PC comes from the signal frame, it points to - * the actual faulting host insn and not a call insn. Subtracting - * GETPC_ADJ in that case may accidentally match the previous guest insn. - * - * So for the later case, adjust forward to compensate for what - * will be done later by cpu_restore_state_from_tb. - */ - if (helper_retaddr) { + switch (helper_retaddr) { + default: + /* + * Fault during host memory operation within a helper function. + * The helper's host return address, saved here, gives us a + * pointer into the generated code that will unwind to the + * correct guest pc. + */ pc = helper_retaddr; - } else { + break; + + case 0: + /* + * Fault during host memory operation within generated code. + * (Or, a unrelated bug within qemu, but we can't tell from here). + * + * We take the host pc from the signal frame. However, we cannot + * use that value directly. Within cpu_restore_state_from_tb, we + * assume PC comes from GETPC(), as used by the helper functions, + * so we adjust the address by -GETPC_ADJ to form an address that + * is within the call insn, so that the address does not accidentially + * match the beginning of the next guest insn. However, when the + * pc comes from the signal frame it points to the actual faulting + * host memory insn and not the return from a call insn. + * + * Therefore, adjust to compensate for what will be done later + * by cpu_restore_state_from_tb. + */ pc += GETPC_ADJ; + break; + + case 1: + /* + * Fault during host read for translation, or loosely, "execution". + * + * The guest pc is already pointing to the start of the TB for which + * code is being generated. If the guest translator manages the + * page crossings correctly, this is exactly the correct address + * (and if the translator doesn't handle page boundaries correctly + * there's little we can do about that here). Therefore, do not + * trigger the unwinder. + * + * Like tb_gen_code, release the memory lock before cpu_loop_exit. + */ + pc = 0; + access_type = MMU_INST_FETCH; + mmap_unlock(); + break; } /* For synchronous signals we expect to be coming from the vCPU @@ -155,7 +184,6 @@ static inline int handle_cpu_signal(uintptr_t pc, siginfo_t *info, clear_helper_retaddr(); cc = CPU_GET_CLASS(cpu); - access_type = is_write ? MMU_DATA_STORE : MMU_DATA_LOAD; cc->tlb_fill(cpu, address, 0, access_type, MMU_USER_IDX, false, pc); g_assert_not_reached(); }