qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] memory: stricter checks prior to unsetting engaged_in_io
@ 2023-05-16  8:40 Alexander Bulekov
  2023-05-17 14:21 ` Darren Kenny
  0 siblings, 1 reply; 2+ messages in thread
From: Alexander Bulekov @ 2023-05-16  8:40 UTC (permalink / raw)
  To: qemu-devel
  Cc: mcascell, Alexander Bulekov, Thomas Huth, Paolo Bonzini, Peter Xu,
	David Hildenbrand, Philippe Mathieu-Daudé

engaged_in_io could be unset by an MR with re-entrancy checks disabled.
Ensure that only MRs that can set the engaged_in_io flag can unset it.

Closes: https://gitlab.com/qemu-project/qemu/-/issues/1563
Reported-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexander Bulekov <alxndr@bu.edu>
---
 softmmu/memory.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/softmmu/memory.c b/softmmu/memory.c
index b7b3386e9d..26424f1d78 100644
--- a/softmmu/memory.c
+++ b/softmmu/memory.c
@@ -534,6 +534,7 @@ static MemTxResult access_with_adjusted_size(hwaddr addr,
     unsigned access_size;
     unsigned i;
     MemTxResult r = MEMTX_OK;
+    bool reentrancy_guard_applied = false;
 
     if (!access_size_min) {
         access_size_min = 1;
@@ -552,6 +553,7 @@ static MemTxResult access_with_adjusted_size(hwaddr addr,
             return MEMTX_ACCESS_ERROR;
         }
         mr->dev->mem_reentrancy_guard.engaged_in_io = true;
+        reentrancy_guard_applied = true;
     }
 
     /* FIXME: support unaligned access? */
@@ -568,7 +570,7 @@ static MemTxResult access_with_adjusted_size(hwaddr addr,
                         access_mask, attrs);
         }
     }
-    if (mr->dev) {
+    if (mr->dev && reentrancy_guard_applied) {
         mr->dev->mem_reentrancy_guard.engaged_in_io = false;
     }
     return r;
-- 
2.39.0



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] memory: stricter checks prior to unsetting engaged_in_io
  2023-05-16  8:40 [PATCH] memory: stricter checks prior to unsetting engaged_in_io Alexander Bulekov
@ 2023-05-17 14:21 ` Darren Kenny
  0 siblings, 0 replies; 2+ messages in thread
From: Darren Kenny @ 2023-05-17 14:21 UTC (permalink / raw)
  To: Alexander Bulekov, qemu-devel
  Cc: mcascell, Alexander Bulekov, Thomas Huth, Paolo Bonzini, Peter Xu,
	David Hildenbrand, Philippe Mathieu-Daudé


On Tuesday, 2023-05-16 at 04:40:02 -04, Alexander Bulekov wrote:
> engaged_in_io could be unset by an MR with re-entrancy checks disabled.
> Ensure that only MRs that can set the engaged_in_io flag can unset it.
>
> Closes: https://gitlab.com/qemu-project/qemu/-/issues/1563
> Reported-by: Thomas Huth <thuth@redhat.com>
> Signed-off-by: Alexander Bulekov <alxndr@bu.edu>

Reviewed-by: Darren Kenny <darren.kenny@oracle.com>

> ---
>  softmmu/memory.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/softmmu/memory.c b/softmmu/memory.c
> index b7b3386e9d..26424f1d78 100644
> --- a/softmmu/memory.c
> +++ b/softmmu/memory.c
> @@ -534,6 +534,7 @@ static MemTxResult access_with_adjusted_size(hwaddr addr,
>      unsigned access_size;
>      unsigned i;
>      MemTxResult r = MEMTX_OK;
> +    bool reentrancy_guard_applied = false;
>  
>      if (!access_size_min) {
>          access_size_min = 1;
> @@ -552,6 +553,7 @@ static MemTxResult access_with_adjusted_size(hwaddr addr,
>              return MEMTX_ACCESS_ERROR;
>          }
>          mr->dev->mem_reentrancy_guard.engaged_in_io = true;
> +        reentrancy_guard_applied = true;
>      }
>  
>      /* FIXME: support unaligned access? */
> @@ -568,7 +570,7 @@ static MemTxResult access_with_adjusted_size(hwaddr addr,
>                          access_mask, attrs);
>          }
>      }
> -    if (mr->dev) {
> +    if (mr->dev && reentrancy_guard_applied) {
>          mr->dev->mem_reentrancy_guard.engaged_in_io = false;
>      }
>      return r;
> -- 
> 2.39.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-05-17 14:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-16  8:40 [PATCH] memory: stricter checks prior to unsetting engaged_in_io Alexander Bulekov
2023-05-17 14:21 ` Darren Kenny

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).