From nobody Tue Feb 10 04:55:22 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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 ARC-Seal: i=1; a=rsa-sha256; t=1610476502; cv=none; d=zohomail.com; s=zohoarc; b=MmDy0w00nQmqRdflK3zH3Og2xzlXUihbqqyu1vKSGhR35j33P9UKSUZKQ0z1h5f2DZHI2gsjaUENhmLVJuNAVeHlChMzGYuS8r77VjBoqR4Y5+gTN6SgXowtJ7BTqZe4ejRjx6TdKgTRi2vgnhISdJ0GZKC82/eV/PzwUDvXxIg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610476502; 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=gwLkkoK/+dydzm8heKck9BBE/YRuiTWrMp/0M2XBSig=; b=hQxgoJt1O1kEAFdw+pSrQilX7aPlDDgs5xpME8UFlf0or+sw9xJakkLqSbSReg/F/20Tte8zVsCyExL/7rMeAPDKicOFIE/XH6dinDbEml9+O3dztP2AICEUftjhnuGXaDmzlOS4WDerPbGj5Y5EMzNsgW8Q5ktFRF+GaW7eHdI= ARC-Authentication-Results: i=1; mx.zohomail.com; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1610476502971471.70784129403785; Tue, 12 Jan 2021 10:35:02 -0800 (PST) Received: from localhost ([::1]:48242 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kzOVR-0000Ho-L1 for importer@patchew.org; Tue, 12 Jan 2021 13:35:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:48164) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kzO1L-0005Sg-2y for qemu-devel@nongnu.org; Tue, 12 Jan 2021 13:03:55 -0500 Received: from mx2.suse.de ([195.135.220.15]:33762) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kzO15-0004wP-PM for qemu-devel@nongnu.org; Tue, 12 Jan 2021 13:03:53 -0500 Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 4D465AD5C; Tue, 12 Jan 2021 18:03:28 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Claudio Fontana To: Paolo Bonzini , Thomas Huth , Richard Henderson , Stefano Stabellini , Wenchao Wang , Roman Bolshakov , Sunil Muthuswamy , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v12 12/22] physmem: make watchpoint checking code TCG-only Date: Tue, 12 Jan 2021 19:03:02 +0100 Message-Id: <20210112180312.26043-13-cfontana@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210112180312.26043-1-cfontana@suse.de> References: <20210112180312.26043-1-cfontana@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=195.135.220.15; envelope-from=cfontana@suse.de; helo=mx2.suse.de X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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: Laurent Vivier , Peter Maydell , Eduardo Habkost , Paul Durrant , Jason Wang , Marcelo Tosatti , qemu-devel@nongnu.org, Peter Xu , Dario Faggioli , Cameron Esfahani , haxm-team@intel.com, Claudio Fontana , Anthony Perard , Bruce Rogers , Olaf Hering , "Emilio G . Cota" , Colin Xu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" cpu_check_watchpoint, watchpoint_address_matches are TCG-only. Signed-off-by: Claudio Fontana --- softmmu/physmem.c | 141 +++++++++++++++++++++++----------------------- 1 file changed, 72 insertions(+), 69 deletions(-) diff --git a/softmmu/physmem.c b/softmmu/physmem.c index 6301f4f0a5..9e7c50e0db 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -840,6 +840,7 @@ void cpu_watchpoint_remove_all(CPUState *cpu, int mask) } } =20 +#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, vadd= r addr, vaddr len) return ret; } =20 +/* 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 =3D 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 =3D 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 =3D=3D BP_MEM_READ) { + wp->flags |=3D BP_WATCHPOINT_HIT_READ; + } else { + wp->flags |=3D BP_WATCHPOINT_HIT_WRITE; + } + wp->hitaddr =3D MAX(addr, wp->vaddr); + wp->hitattrs =3D attrs; + if (!cpu->watchpoint_hit) { + if (wp->flags & BP_CPU && + !cc->debug_check_watchpoint(cpu, wp)) { + wp->flags &=3D ~BP_WATCHPOINT_HIT; + continue; + } + cpu->watchpoint_hit =3D wp; + + mmap_lock(); + tb_check_watchpoint(cpu, ra); + if (wp->flags & BP_STOP_BEFORE_ACCESS) { + cpu->exception_index =3D EXCP_DEBUG; + mmap_unlock(); + cpu_loop_exit_restore(cpu, ra); + } else { + /* Force execution of one insn next time. */ + cpu->cflags_next_tb =3D 1 | curr_cflags(); + mmap_unlock(); + if (ra) { + cpu_restore_state(cpu, ra, true); + } + cpu_loop_exit_noexc(cpu); + } + } + } else { + wp->flags &=3D ~BP_WATCHPOINT_HIT; + } + } +} + +#endif /* CONFIG_TCG */ + /* Called from RCU critical section */ static RAMBlock *qemu_get_ram_block(ram_addr_t addr) { @@ -2355,75 +2427,6 @@ ram_addr_t qemu_ram_addr_from_host(void *ptr) return block->offset + offset; } =20 -/* 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 =3D 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 =3D 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 =3D=3D BP_MEM_READ) { - wp->flags |=3D BP_WATCHPOINT_HIT_READ; - } else { - wp->flags |=3D BP_WATCHPOINT_HIT_WRITE; - } - wp->hitaddr =3D MAX(addr, wp->vaddr); - wp->hitattrs =3D attrs; - if (!cpu->watchpoint_hit) { - if (wp->flags & BP_CPU && - !cc->debug_check_watchpoint(cpu, wp)) { - wp->flags &=3D ~BP_WATCHPOINT_HIT; - continue; - } - cpu->watchpoint_hit =3D wp; - - mmap_lock(); - tb_check_watchpoint(cpu, ra); - if (wp->flags & BP_STOP_BEFORE_ACCESS) { - cpu->exception_index =3D EXCP_DEBUG; - mmap_unlock(); - cpu_loop_exit_restore(cpu, ra); - } else { - /* Force execution of one insn next time. */ - cpu->cflags_next_tb =3D 1 | curr_cflags(); - mmap_unlock(); - if (ra) { - cpu_restore_state(cpu, ra, true); - } - cpu_loop_exit_noexc(cpu); - } - } - } else { - wp->flags &=3D ~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 at= trs, --=20 2.26.2