From patchwork Fri Feb 5 22:56:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 377030 Delivered-To: patch@linaro.org Received: by 2002:a17:906:48d2:0:0:0:0 with SMTP id d18csp2590981ejt; Fri, 5 Feb 2021 15:29:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJz30otLDyZlrlUAeRqOkCs+mftmgrRxN/YoFxC+IbT1ja6j5Rk8xmVsct9fVS6HYR5t2QzG X-Received: by 2002:a25:b3c2:: with SMTP id x2mr9513770ybf.304.1612567760281; Fri, 05 Feb 2021 15:29:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612567760; cv=none; d=google.com; s=arc-20160816; b=MuQPdnfOEUHoHaGc6V3l53u8nZgZZAMfZDtSPpc3OTEmuXEuXVLeCvdTLiE6Lr7Es5 DoQ0DH6NF3topr+E2nH2rXGNgvpFOo7JrXsLbMgcGCpvWQsJjxKqj+zcqOhf80XLo8nH WRRakdgA0byamIa5kYP2nP71huC0TZ53YI2K7tUyWM+KxfN7YmhY6gdEZctjwOsjvSgz wyM9WgtDUMK1uFfyjr8Z0CpSSpXc/U7qyTj91l3Skcm8c1o/9jffqBTh+eAMhR9TiOdW fzJ/sDx2hxLRN/bTYccsFyL+mSEP/7hndrWAKJowk88mTiyxCNeSP4d3abQMjOZfXAGB 7HcQ== 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=cBSZecFHJJp/usGc+3/heP75DKhmYnZ0kaH0ekZQKBs=; b=CegwF/kjrhMHOCX5D5hqKEgaE+DVM3t/79ZZhUAZTU3Bu21hbwkKnSsOn/reZcm/tj VHuewjEtIOYL12oiHPtW4Bcrk/k1wLHumKu0PdQj+ZsrxNfvE/QL5LHwlnnBDOTZI2V6 CZiZkBGJ+pTO2uK8+F34mbRyLo3BMEUlgK9nFa2Rw9+nZmYKus9f35gCASB4KShjdyAr 1VSCswOl1L2LPlfaffeuQwHHvPWvqpMSNLOVOlV8CpzLjY8ZxWFBSBmeqZxo9f6zHSOQ Q3t4whqU6skfEG911VgfaPA+sFRNhltFfbx1CDo3k5L+F5ZB1qKYHPnksLO+0CykNYVa CUkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=JGy7VPrH; 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 n190si12098895ybn.445.2021.02.05.15.29.20 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 05 Feb 2021 15:29:20 -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=JGy7VPrH; 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]:51618 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l8AXP-0000i0-MP for patch@linaro.org; Fri, 05 Feb 2021 18:29:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:59684) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l8A3J-0002oc-1k for qemu-devel@nongnu.org; Fri, 05 Feb 2021 17:58:13 -0500 Received: from mail-pg1-x532.google.com ([2607:f8b0:4864:20::532]:37879) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l8A3H-0003g0-7r for qemu-devel@nongnu.org; Fri, 05 Feb 2021 17:58:12 -0500 Received: by mail-pg1-x532.google.com with SMTP id z21so5586060pgj.4 for ; Fri, 05 Feb 2021 14:58:10 -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=cBSZecFHJJp/usGc+3/heP75DKhmYnZ0kaH0ekZQKBs=; b=JGy7VPrHFvp6Q5MFOHFT7S+4keAzms7339nHI3a/B2GazBwJY8NXdWPHU4G8shMB6F IjTaGvuJjc/qM4oHqXO0f7HarSFamue0w0DJ8Ln0ggUVssIXcsJKiKkvZSVobSzYcWmV GpL2EHXalAHQLrKax+Tf1lFxorkg5I8WlWtUscAqctbGG/f55+wjXn786DRzOzhBdh7W BWyAz4vwExVcAQ0nPjLuYascgX2ym1qEbSfuEbHVZR/Bd89y8hpIOl72XaBJi+Y8wSuq +8h/+s8oihx6o2lQ/agricg023jkX+xkbpncEA9ZIBabOCSrIMUeW4aQJq/aqgBjPLW7 ODYw== 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=cBSZecFHJJp/usGc+3/heP75DKhmYnZ0kaH0ekZQKBs=; b=UwRLnJPFEMziWnp7iqZrzpasIX9vufIk6XuBHXHKaA7yjxA0khLDP2FVD/S/NkZ10M AmtjXJ78NlKeMjs+SdYUiyZ3mNIv+AV0PMBqQbA10piUkq0CP/6rdIOkXpcpLCgVa8Bn aiSzf5CRBfJC9aDylio4oZnv2dMNmtPWLwGNNFQy53gGBA1Y2hoMsZ9UMsfbnvTgmIe/ 3rnAfEMH3OVhu9h+VilC2lW+nGm5ominyQ+GBvRvqoRNCoc5phnwm43HT7rD4uq4k209 9ho6SLyAuzL7okqLZCln+sQtP6Z8RBTFTktp4HnnF/fZojZIgzGrB8i5M2nT9TcPSKDH QAOA== X-Gm-Message-State: AOAM533ZECa0WrUY/phXKnyZlZYp/0h9w1me6YDsSCrQFNid7VtOmwVx 7GN1agF2sq8W40ZEAHod5tm60WEiK/yCZZ3q X-Received: by 2002:aa7:8bce:0:b029:1b8:f395:87a with SMTP id s14-20020aa78bce0000b02901b8f395087amr6500518pfd.36.1612565889820; Fri, 05 Feb 2021 14:58:09 -0800 (PST) Received: from localhost.localdomain (cpe-66-27-222-29.hawaii.res.rr.com. [66.27.222.29]) by smtp.gmail.com with ESMTPSA id c23sm12155149pgc.72.2021.02.05.14.58.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Feb 2021 14:58:09 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 40/46] physmem: make watchpoint checking code TCG-only Date: Fri, 5 Feb 2021 12:56:44 -1000 Message-Id: <20210205225650.1330794-41-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210205225650.1330794-1-richard.henderson@linaro.org> References: <20210205225650.1330794-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::532; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x532.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: peter.maydell@linaro.org, =?utf-8?q?Alex_Benn=C3=A9e?= , Claudio Fontana Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Claudio Fontana cpu_check_watchpoint, watchpoint_address_matches are TCG-only. Signed-off-by: Claudio Fontana Reviewed-by: Alex Bennée Message-Id: <20210204163931.7358-13-cfontana@suse.de> Signed-off-by: Richard Henderson --- softmmu/physmem.c | 141 +++++++++++++++++++++++----------------------- 1 file changed, 72 insertions(+), 69 deletions(-) -- 2.25.1 diff --git a/softmmu/physmem.c b/softmmu/physmem.c index 60760a3bdc..51ed600bf9 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -840,6 +840,7 @@ void cpu_watchpoint_remove_all(CPUState *cpu, int mask) } } +#ifdef CONFIG_TCG /* Return true if this watchpoint address matches the specified * access (ie the address range covered by the watchpoint overlaps * partially or completely with the address range covered by the @@ -873,6 +874,77 @@ int cpu_watchpoint_address_matches(CPUState *cpu, vaddr addr, vaddr len) return ret; } +/* Generate a debug exception if a watchpoint has been hit. */ +void cpu_check_watchpoint(CPUState *cpu, vaddr addr, vaddr len, + MemTxAttrs attrs, int flags, uintptr_t ra) +{ + CPUClass *cc = CPU_GET_CLASS(cpu); + CPUWatchpoint *wp; + + assert(tcg_enabled()); + if (cpu->watchpoint_hit) { + /* + * We re-entered the check after replacing the TB. + * Now raise the debug interrupt so that it will + * trigger after the current instruction. + */ + qemu_mutex_lock_iothread(); + cpu_interrupt(cpu, CPU_INTERRUPT_DEBUG); + qemu_mutex_unlock_iothread(); + return; + } + + addr = cc->adjust_watchpoint_address(cpu, addr, len); + QTAILQ_FOREACH(wp, &cpu->watchpoints, entry) { + if (watchpoint_address_matches(wp, addr, len) + && (wp->flags & flags)) { + if (replay_running_debug()) { + /* + * Don't process the watchpoints when we are + * in a reverse debugging operation. + */ + replay_breakpoint(); + return; + } + if (flags == BP_MEM_READ) { + wp->flags |= BP_WATCHPOINT_HIT_READ; + } else { + wp->flags |= BP_WATCHPOINT_HIT_WRITE; + } + wp->hitaddr = MAX(addr, wp->vaddr); + wp->hitattrs = attrs; + if (!cpu->watchpoint_hit) { + if (wp->flags & BP_CPU && + !cc->debug_check_watchpoint(cpu, wp)) { + wp->flags &= ~BP_WATCHPOINT_HIT; + continue; + } + cpu->watchpoint_hit = wp; + + mmap_lock(); + tb_check_watchpoint(cpu, ra); + if (wp->flags & BP_STOP_BEFORE_ACCESS) { + cpu->exception_index = EXCP_DEBUG; + mmap_unlock(); + cpu_loop_exit_restore(cpu, ra); + } else { + /* Force execution of one insn next time. */ + cpu->cflags_next_tb = 1 | curr_cflags(); + mmap_unlock(); + if (ra) { + cpu_restore_state(cpu, ra, true); + } + cpu_loop_exit_noexc(cpu); + } + } + } else { + wp->flags &= ~BP_WATCHPOINT_HIT; + } + } +} + +#endif /* CONFIG_TCG */ + /* Called from RCU critical section */ static RAMBlock *qemu_get_ram_block(ram_addr_t addr) { @@ -2359,75 +2431,6 @@ ram_addr_t qemu_ram_addr_from_host(void *ptr) return block->offset + offset; } -/* Generate a debug exception if a watchpoint has been hit. */ -void cpu_check_watchpoint(CPUState *cpu, vaddr addr, vaddr len, - MemTxAttrs attrs, int flags, uintptr_t ra) -{ - CPUClass *cc = CPU_GET_CLASS(cpu); - CPUWatchpoint *wp; - - assert(tcg_enabled()); - if (cpu->watchpoint_hit) { - /* - * We re-entered the check after replacing the TB. - * Now raise the debug interrupt so that it will - * trigger after the current instruction. - */ - qemu_mutex_lock_iothread(); - cpu_interrupt(cpu, CPU_INTERRUPT_DEBUG); - qemu_mutex_unlock_iothread(); - return; - } - - addr = cc->adjust_watchpoint_address(cpu, addr, len); - QTAILQ_FOREACH(wp, &cpu->watchpoints, entry) { - if (watchpoint_address_matches(wp, addr, len) - && (wp->flags & flags)) { - if (replay_running_debug()) { - /* - * Don't process the watchpoints when we are - * in a reverse debugging operation. - */ - replay_breakpoint(); - return; - } - if (flags == BP_MEM_READ) { - wp->flags |= BP_WATCHPOINT_HIT_READ; - } else { - wp->flags |= BP_WATCHPOINT_HIT_WRITE; - } - wp->hitaddr = MAX(addr, wp->vaddr); - wp->hitattrs = attrs; - if (!cpu->watchpoint_hit) { - if (wp->flags & BP_CPU && - !cc->debug_check_watchpoint(cpu, wp)) { - wp->flags &= ~BP_WATCHPOINT_HIT; - continue; - } - cpu->watchpoint_hit = wp; - - mmap_lock(); - tb_check_watchpoint(cpu, ra); - if (wp->flags & BP_STOP_BEFORE_ACCESS) { - cpu->exception_index = EXCP_DEBUG; - mmap_unlock(); - cpu_loop_exit_restore(cpu, ra); - } else { - /* Force execution of one insn next time. */ - cpu->cflags_next_tb = 1 | curr_cflags(); - mmap_unlock(); - if (ra) { - cpu_restore_state(cpu, ra, true); - } - cpu_loop_exit_noexc(cpu); - } - } - } else { - wp->flags &= ~BP_WATCHPOINT_HIT; - } - } -} - static MemTxResult flatview_read(FlatView *fv, hwaddr addr, MemTxAttrs attrs, void *buf, hwaddr len); static MemTxResult flatview_write(FlatView *fv, hwaddr addr, MemTxAttrs attrs,