All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pavel Dovgalyuk <pavel.dovgalyuk@ispras.ru>
To: qemu-devel@nongnu.org
Cc: pavel.dovgalyuk@ispras.ru, david@redhat.com,
	richard.henderson@linaro.org, peterx@redhat.com,
	pbonzini@redhat.com, alex.bennee@linaro.org
Subject: [PATCH v2 3/3] softmmu: fix watchpoints on memory used by vCPU internals
Date: Thu, 11 Nov 2021 12:55:19 +0300	[thread overview]
Message-ID: <163662451972.125458.8046031260136838656.stgit@pasha-ThinkPad-X280> (raw)
In-Reply-To: <163662450348.125458.5494710452733592356.stgit@pasha-ThinkPad-X280>

When vCPU processes interrupt request or exception, it can save
register values to the memory. Watchpoints may also be set on
these memory cells. In this case watchpoint processing code should
not retranslate the block which accessed the memory, because there
is no such block at all. "After access" watchpoint also can't be
used in such case.
This patch adds some conditions to prevent failures when watchpoint
is set on memory used for saving the registers on interrupt request.

Signed-off-by: Pavel Dovgalyuk <Pavel.Dovgalyuk@ispras.ru>
---
 softmmu/physmem.c |   14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/softmmu/physmem.c b/softmmu/physmem.c
index 314f8b439c..53edcf9a51 100644
--- a/softmmu/physmem.c
+++ b/softmmu/physmem.c
@@ -886,6 +886,14 @@ void cpu_check_watchpoint(CPUState *cpu, vaddr addr, vaddr len,
 
     assert(tcg_enabled());
     if (cpu->watchpoint_hit) {
+        if (!ra) {
+            /*
+             * Another memory access after hitting the watchpoint.
+             * There is no translation block and interrupt request
+             * is already set.
+             */
+            return;
+        }
         /*
          * We re-entered the check after replacing the TB.
          * Now raise the debug interrupt so that it will
@@ -936,6 +944,12 @@ void cpu_check_watchpoint(CPUState *cpu, vaddr addr, vaddr len,
                 continue;
             }
             cpu->watchpoint_hit = wp;
+            if (!ra) {
+                /* We're not in the TB, can't stop before the access. */
+                g_assert(!(wp->flags & BP_STOP_BEFORE_ACCESS));
+                cpu_interrupt(cpu, CPU_INTERRUPT_DEBUG);
+                return;
+            }
 
             mmap_lock();
             /* This call also restores vCPU state */



  parent reply	other threads:[~2021-11-11  9:56 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-11  9:55 [PATCH v2 0/3] Some watchpoint-related patches Pavel Dovgalyuk
2021-11-11  9:55 ` [PATCH v2 1/3] icount: preserve cflags when custom tb is about to execute Pavel Dovgalyuk
2021-11-11 12:20   ` Alex Bennée
2021-11-16  7:40     ` Pavel Dovgalyuk
2021-11-16 10:57       ` Alex Bennée
2021-11-17  9:47   ` Alex Bennée
2021-11-17 10:03     ` Richard Henderson
2021-11-17 10:29       ` Alex Bennée
2021-11-17 11:29         ` Richard Henderson
2021-11-18 11:05     ` Pavel Dovgalyuk
2021-11-11  9:55 ` [PATCH v2 2/3] softmmu: fix watchpoint-interrupt races Pavel Dovgalyuk
2021-11-11 13:15   ` Alex Bennée
2021-11-12 10:10   ` David Hildenbrand
2021-11-11  9:55 ` Pavel Dovgalyuk [this message]
2021-11-11 10:48 ` [PATCH v2 0/3] Some watchpoint-related patches David Hildenbrand
2021-11-11 10:50   ` Pavel Dovgalyuk

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=163662451972.125458.8046031260136838656.stgit@pasha-ThinkPad-X280 \
    --to=pavel.dovgalyuk@ispras.ru \
    --cc=alex.bennee@linaro.org \
    --cc=david@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.