From patchwork Thu Feb 23 20:43:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 656004 Delivered-To: patch@linaro.org Received: by 2002:adf:a3c6:0:0:0:0:0 with SMTP id m6csp539576wrb; Thu, 23 Feb 2023 12:46:32 -0800 (PST) X-Google-Smtp-Source: AK7set8dwZ3jsrgKRpbaoy+0bMBy0N4ZcAzySkFmzs2zf+bI7a3OaTvKZOb87iykXcvQBtglCrJF X-Received: by 2002:a05:6214:e62:b0:56e:c0df:8492 with SMTP id jz2-20020a0562140e6200b0056ec0df8492mr24535301qvb.31.1677185192714; Thu, 23 Feb 2023 12:46:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677185192; cv=none; d=google.com; s=arc-20160816; b=Jk8lHmGFh8QGzZ1OIrirS2wLmBann7AC/L1QdhyhlOFLY+gxEEsgeSyATtJW5m8J9C 1a5I2ubTWwCAjLfHhKGowRsGrooGqkH+2GlGTX8rAja/q2M9SA6cGlMlI6Rjk8mkO/Sp Y4ribKt1+fDxAjtB/g3flkNa7MfuOaqc47W2LzzcA/0UdyCFL9fL79LLztOowXzEtiTX RC6kWYCRjqT+r6eo3HYm2vM1k21n6MEJDR8Ob5vSLqiAYLR1FM1tMEzGkQ766srHsd3m CWNCQdyANhgfFeAn9ZTgAYBKuGvvp3SsKY9NyEjH63hK2Jda/vS75AhwqDADeuTmYIa4 +X+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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:cc:to :from:dkim-signature; bh=uCfgSwaCWGjVH4XmiAS5xzTjPaTu2Mc57Kv2qaU5lRM=; b=zAWpYeuU0VWCcjNaHzAYq3o2JIYkblDXi8yb815pggcsVZATCmibJlVGX07qYDBJZ2 xoNDN65b0ntAck1Pu60cgZmGQK6Cqm84lguC3yCi81nCyTMuiSNy54WdUco6Bx74KHSg En5u5KanRAkVbvjGb2TgvUTsSRxjJGfXq0cHAbwI4d61XPXp2tyakWI8y+hw9iGxxMqy BwBebVqo69HSuEDTCnyJyYvfMsaNhnCgqL+7uYk1a/tNut5tYnMTHjJew5F7VyU8yGxw cuzfYr0Mt2Ce0gmpv32jVvbkGCg6k7Pvz08nzxrfHSny2U63bBfUew5D2iLbWHQmtf3u DYsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="n89/wfw9"; 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=pass (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 z14-20020ac8430e000000b003b9b4d9091asi6148056qtm.531.2023.02.23.12.46.32 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 23 Feb 2023 12:46:32 -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=pass header.i=@linaro.org header.s=google header.b="n89/wfw9"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pVIRc-0002oz-ED; Thu, 23 Feb 2023 15:44:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pVIRa-0002nj-Mo for qemu-devel@nongnu.org; Thu, 23 Feb 2023 15:43:58 -0500 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pVIRZ-0007RI-3M for qemu-devel@nongnu.org; Thu, 23 Feb 2023 15:43:58 -0500 Received: by mail-pj1-x102b.google.com with SMTP id u10so14349975pjc.5 for ; Thu, 23 Feb 2023 12:43:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=uCfgSwaCWGjVH4XmiAS5xzTjPaTu2Mc57Kv2qaU5lRM=; b=n89/wfw9eZdbECZlYDz5DfRTWcaLs9CRGk61ZLnt0wYLe7RkvzUXWZxy/qVdfS/xMx jhsvJk5jAkHNTzM81PI0a2bQQTbAZvfnVX8sAfjjaNeQsDs4wj0zY/cwXWeHTiefiCab LKLWuP/9XG+VMZ4JnJ5xrnl5S+WFM3XgAXMW3c/f8WuxGqF5jLknWA8HkHqCRJpRw/wJ fF0P+VrmAlNGpOZI5BCoMTEDk5mXgU4pN+OP5Sdrd9UUPfchmR81q3hbglvMBN5bOSUy cV1N3zw+lSJPnew/CiLPXvFrEaqiZDMYaQLK2t4Hy0JAmDl6ATXosa0QSXk15skr8h/R R/Vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uCfgSwaCWGjVH4XmiAS5xzTjPaTu2Mc57Kv2qaU5lRM=; b=Z2bqDraQtrwppEr55IV59HgG/NmTglEt1SFOTulxgkN7jailwYWR9q1Oh6HMmaYWpR 2p0lc6bHSkAEKVBJ5P/E+++bB4fdJ1E7kYCqcmC+1K4rN5SVu8j05CUcwN93tElrmsoU H0aOZ8MaHDJCRbl/LVy7tB5yr1709UwXNzSLuutKGgEQsib8byMCN3lFyniZGCIYsjuS LMnJLa+G2FjAke/xCpZTEpaVZ+Aq3UpxPXWoAC6kOP+1AqDymqmCxrUDG087VcfqJc11 7evhcFGodEZBJyr9C8+16Z03+qLSY2PyyLWdBFGMZX94L4w17e4k2PypgTGPZYAhSrsI HHpw== X-Gm-Message-State: AO0yUKVnITNzBuYDD/XSYHCOuJ3oBuuR+Jswnd0/w7pTStbER0atViVF jGqfcaCN7MKiRMvGQNYPvb0QT6/orS2RMXGKOfk= X-Received: by 2002:a17:90b:38c7:b0:234:a88e:d67e with SMTP id nn7-20020a17090b38c700b00234a88ed67emr14757191pjb.34.1677185035744; Thu, 23 Feb 2023 12:43:55 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id e187-20020a6369c4000000b004b1fef0bf16sm5992850pgc.73.2023.02.23.12.43.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Feb 2023 12:43:55 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH 05/13] softmmu/physmem: Check watchpoints for read+write at once Date: Thu, 23 Feb 2023 10:43:34 -1000 Message-Id: <20230223204342.1093632-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230223204342.1093632-1-richard.henderson@linaro.org> References: <20230223204342.1093632-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102b; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102b.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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Atomic operations are read-modify-write, and we'd like to be able to test both read and write with one call. This is easy enough, with BP_MEM_READ | BP_MEM_WRITE. Add BP_HIT_SHIFT to make it easy to set BP_WATCHPOINT_HIT_*. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé --- include/hw/core/cpu.h | 7 ++++--- softmmu/physmem.c | 19 ++++++++++--------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index 2417597236..2f85ba14b3 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -921,9 +921,10 @@ void cpu_single_step(CPUState *cpu, int enabled); #define BP_GDB 0x10 #define BP_CPU 0x20 #define BP_ANY (BP_GDB | BP_CPU) -#define BP_WATCHPOINT_HIT_READ 0x40 -#define BP_WATCHPOINT_HIT_WRITE 0x80 -#define BP_WATCHPOINT_HIT (BP_WATCHPOINT_HIT_READ | BP_WATCHPOINT_HIT_WRITE) +#define BP_HIT_SHIFT 6 +#define BP_WATCHPOINT_HIT_READ (BP_MEM_READ << BP_HIT_SHIFT) +#define BP_WATCHPOINT_HIT_WRITE (BP_MEM_WRITE << BP_HIT_SHIFT) +#define BP_WATCHPOINT_HIT (BP_MEM_ACCESS << BP_HIT_SHIFT) int cpu_breakpoint_insert(CPUState *cpu, vaddr pc, int flags, CPUBreakpoint **breakpoint); diff --git a/softmmu/physmem.c b/softmmu/physmem.c index cb998cdf23..c4f62dee60 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -915,9 +915,12 @@ void cpu_check_watchpoint(CPUState *cpu, vaddr addr, vaddr len, /* this is currently used only by ARM BE32 */ addr = cc->tcg_ops->adjust_watchpoint_address(cpu, addr, len); } + + assert((flags & ~BP_MEM_ACCESS) == 0); QTAILQ_FOREACH(wp, &cpu->watchpoints, entry) { - if (watchpoint_address_matches(wp, addr, len) - && (wp->flags & flags)) { + int hit_flags = wp->flags & flags; + + if (hit_flags && watchpoint_address_matches(wp, addr, len)) { if (replay_running_debug()) { /* * replay_breakpoint reads icount. @@ -936,16 +939,14 @@ void cpu_check_watchpoint(CPUState *cpu, vaddr addr, vaddr len, replay_breakpoint(); return; } - if (flags == BP_MEM_READ) { - wp->flags |= BP_WATCHPOINT_HIT_READ; - } else { - wp->flags |= BP_WATCHPOINT_HIT_WRITE; - } + + wp->flags |= hit_flags << BP_HIT_SHIFT; wp->hitaddr = MAX(addr, wp->vaddr); wp->hitattrs = attrs; - if (wp->flags & BP_CPU && cc->tcg_ops->debug_check_watchpoint && - !cc->tcg_ops->debug_check_watchpoint(cpu, wp)) { + if (wp->flags & BP_CPU + && cc->tcg_ops->debug_check_watchpoint + && !cc->tcg_ops->debug_check_watchpoint(cpu, wp)) { wp->flags &= ~BP_WATCHPOINT_HIT; continue; }