From patchwork Fri Oct 1 17:11:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 515060 Delivered-To: patch@linaro.org Received: by 2002:a02:606e:0:0:0:0:0 with SMTP id d46csp1003347jaf; Fri, 1 Oct 2021 10:20:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzhbmEgVgCrxeNMCTjqOFZbr9lHdmSW4HQ8E2hwhglbXisBOAsI89t/wDZn9muCyGHs5I6O X-Received: by 2002:a67:2447:: with SMTP id k68mr5610256vsk.38.1633108853952; Fri, 01 Oct 2021 10:20:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633108853; cv=none; d=google.com; s=arc-20160816; b=tVPX9HuGN79j2rHfA8T82ECZcuxvBx9kuc/9x6Pt/DtEQyisSJDWmclMOI+8kcuYWJ m/LJLqNjO+C67s9qXeA7ACTkbc7/8NIEHRJX9Gwufk4kMm7B84kzi1QsIkhPzMh4ndAM S9/VxQ0EiP/exm04LPNZF8yQRbuCfVZICyOafU3PtpDLLlK51a+YKMBXksy+iqtFAmp4 ieuyQxk7ia1eT1E1eJ3qUJMVQz0Fpffaw2C6Sz5X1hQZZO24wp2EOX/K4PlZESHI+l5r V0ucKtQQPUGZPkD0HXhxzH1yOMkvjAZ8SkhdjJJNISIga2AQ0QgnPjiwsy5kHluXLyLU rrRQ== 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=MwSLIpZg3SBDOkqorWI9RwSF0cto2aAplNrO4o3oH4g=; b=Jw+IsBnZ5YwcnZtLFbOakM2hI5+ANOawL8+cjlYPR8CAGvdyFvEUHky7zunpAOxFxn rTSYnc+Dr5y6Qh4/sYzJmyAXbAb7d9cRE412p/9o0TMRFNm0aeGP1C+A5ukVQEb5rRIK +XJWzaVpeO04/0RnBGOkd27YN4Gp5+V1+bUl5QwnMH3Rd6JFm68P/TLSP/z8s/+tExNG or5oTo7x2O+1NEA9tHCRobAvArtIACAesgaAqZjU40ArKMaVMD8oqgd5nQDaW2tNfQH5 0S0KXwrP1ElB6ThVWK+ka4exj/KCILAqMqe1jhs1ZUtagWukjeXOIokCuHANAjPvYOxD cZ1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=oS226YFK; 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 h19si2477301vsa.327.2021.10.01.10.20.53 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Oct 2021 10:20:53 -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=oS226YFK; 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]:37444 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mWMDL-0007ga-4s for patch@linaro.org; Fri, 01 Oct 2021 13:20:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54520) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mWM4k-0004Yz-A9 for qemu-devel@nongnu.org; Fri, 01 Oct 2021 13:11:58 -0400 Received: from mail-qt1-x835.google.com ([2607:f8b0:4864:20::835]:35654) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mWM4i-0004v0-Dr for qemu-devel@nongnu.org; Fri, 01 Oct 2021 13:11:58 -0400 Received: by mail-qt1-x835.google.com with SMTP id c20so9632927qtb.2 for ; Fri, 01 Oct 2021 10:11:56 -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 :mime-version:content-transfer-encoding; bh=MwSLIpZg3SBDOkqorWI9RwSF0cto2aAplNrO4o3oH4g=; b=oS226YFKN/UABBQtiQ2wJ1eX89Oobv6W4nIEnL5Oe1vYlRfVSmXbWkRs0eYir/7kBJ T0kGZuD0tedQMhlVdlIO+FCEW96v74WXPdAlfg6SnycVcH1/WD0ierhqaLOEmXy1DOoD KaTSBY4owfZxOuSYKmtP+DMOpqZ7r84WEVGysZ6aB7ysOJMiDtlZi4Q1FRHrFLCOFZKS l3qTgsq0QLvlFw2DNH/+oWuXLbFV43w7F6RV4Zi5p37o2kURV9q4B0vF5umfuZNA78mL X4T542mAhNoibSZDYL3a2JaRLrqVnqDy1aQj8QaYLr3BOBlIT2igFew03rfK+GmnhTGg fQOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MwSLIpZg3SBDOkqorWI9RwSF0cto2aAplNrO4o3oH4g=; b=1AlBPlvW7YnJHpsCU4AugbPXQ5nJkcrrpY/p//ePw/fzs0fzX1qEUJKDSngtu5tN0f 6R4+XsAL+gDhQCrEdDsULhyA6GFDWHDvgZ4wRuheLgSf8a3KTuFdcYwydznBZEbzxnu2 m1ud9n9KojbaeRELwJe8Nk/JPi22sMOur5FFH32r84kxAgy3p3VLVhd74AfIKaccyvVe 6x6huQAU0ST11jQKxsTckvwHktVjnsGuiob5Ph9fqAl6PKJ4y0GGbCSSVTVxVvUBlGb1 LkanI+O3qrbYvipbL63NRrJgo+WV3EiCtu1TZbu3wCMjt2D9TYNrNmKXNWuZDJ0BdjNx a0+g== X-Gm-Message-State: AOAM532OWIxopPo+ZznUNorETmkpbOx/8Ny5mqcW3fnL3d0bYKw2Mshw l9zMxO2tTuTgUm6npGDS5OKWYad5+z1Ekg== X-Received: by 2002:ac8:724b:: with SMTP id l11mr14103408qtp.109.1633108313940; Fri, 01 Oct 2021 10:11:53 -0700 (PDT) Received: from localhost.localdomain (c-67-174-166-185.hsd1.ga.comcast.net. [67.174.166.185]) by smtp.gmail.com with ESMTPSA id y15sm3557250qko.78.2021.10.01.10.11.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Oct 2021 10:11:53 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 01/41] accel/tcg: Split out adjust_signal_pc Date: Fri, 1 Oct 2021 13:11:11 -0400 Message-Id: <20211001171151.1739472-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211001171151.1739472-1-richard.henderson@linaro.org> References: <20211001171151.1739472-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::835; envelope-from=richard.henderson@linaro.org; helo=mail-qt1-x835.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: alex.bennee@linaro.org, laurent@vivier.eu, =?utf-8?q?Philippe_Mathieu-?= =?utf-8?b?RGF1ZMOp?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Split out a function to adjust the raw signal pc into a value that could be passed to cpu_restore_state. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- v2: Adjust pc in place; return MMUAccessType. --- include/exec/exec-all.h | 10 ++++++++++ accel/tcg/user-exec.c | 41 +++++++++++++++++++++++++---------------- 2 files changed, 35 insertions(+), 16 deletions(-) -- 2.25.1 diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index 9d5987ba04..e54f8e5d65 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -663,6 +663,16 @@ static inline tb_page_addr_t get_page_addr_code_hostp(CPUArchState *env, return addr; } +/** + * adjust_signal_pc: + * @pc: raw pc from the host signal ucontext_t. + * @is_write: host memory operation was write, or read-modify-write. + * + * Alter @pc as required for unwinding. Return the type of the + * guest memory access -- host reads may be for guest execution. + */ +MMUAccessType adjust_signal_pc(uintptr_t *pc, bool is_write); + /** * cpu_signal_handler * @signum: host signal number diff --git a/accel/tcg/user-exec.c b/accel/tcg/user-exec.c index 8fed542622..cef025d001 100644 --- a/accel/tcg/user-exec.c +++ b/accel/tcg/user-exec.c @@ -57,18 +57,11 @@ static void QEMU_NORETURN cpu_exit_tb_from_sighandler(CPUState *cpu, cpu_loop_exit_noexc(cpu); } -/* 'pc' is the host PC at which the exception was raised. 'address' is - the effective address of the memory exception. 'is_write' is 1 if a - write caused the exception and otherwise 0'. 'old_set' is the - signal set which should be restored */ -static inline int handle_cpu_signal(uintptr_t pc, siginfo_t *info, - int is_write, sigset_t *old_set) +/* + * Adjust the pc to pass to cpu_restore_state; return the memop type. + */ +MMUAccessType adjust_signal_pc(uintptr_t *pc, bool is_write) { - CPUState *cpu = current_cpu; - CPUClass *cc; - unsigned long address = (unsigned long)info->si_addr; - MMUAccessType access_type = is_write ? MMU_DATA_STORE : MMU_DATA_LOAD; - switch (helper_retaddr) { default: /* @@ -77,7 +70,7 @@ static inline int handle_cpu_signal(uintptr_t pc, siginfo_t *info, * pointer into the generated code that will unwind to the * correct guest pc. */ - pc = helper_retaddr; + *pc = helper_retaddr; break; case 0: @@ -97,7 +90,7 @@ static inline int handle_cpu_signal(uintptr_t pc, siginfo_t *info, * Therefore, adjust to compensate for what will be done later * by cpu_restore_state_from_tb. */ - pc += GETPC_ADJ; + *pc += GETPC_ADJ; break; case 1: @@ -113,12 +106,28 @@ static inline int handle_cpu_signal(uintptr_t pc, siginfo_t *info, * * Like tb_gen_code, release the memory lock before cpu_loop_exit. */ - pc = 0; - access_type = MMU_INST_FETCH; mmap_unlock(); - break; + *pc = 0; + return MMU_INST_FETCH; } + return is_write ? MMU_DATA_STORE : MMU_DATA_LOAD; +} + +/* + * 'pc' is the host PC at which the exception was raised. + * 'address' is the effective address of the memory exception. + * 'is_write' is 1 if a write caused the exception and otherwise 0. + * 'old_set' is the signal set which should be restored. + */ +static inline int handle_cpu_signal(uintptr_t pc, siginfo_t *info, + int is_write, sigset_t *old_set) +{ + CPUState *cpu = current_cpu; + CPUClass *cc; + unsigned long address = (unsigned long)info->si_addr; + MMUAccessType access_type = adjust_signal_pc(&pc, is_write); + /* For synchronous signals we expect to be coming from the vCPU * thread (so current_cpu should be valid) and either from running * code or during translation which can fault as we cross pages.