[PATCH] memory: Log access direction for invalid accesses

BALATON Zoltan posted 1 patch 2 years, 6 months ago
Test checkpatch passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20211011173616.F1DE0756022@zero.eik.bme.hu
Maintainers: Paolo Bonzini <pbonzini@redhat.com>, Peter Xu <peterx@redhat.com>, David Hildenbrand <david@redhat.com>
softmmu/memory.c | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
[PATCH] memory: Log access direction for invalid accesses
Posted by BALATON Zoltan 2 years, 6 months ago
In memory_region_access_valid() invalid accesses are logged to help
debugging but the log message does not say if it was a read or write.
Log that too to better identify the access causing the problem.

Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
---
 softmmu/memory.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/softmmu/memory.c b/softmmu/memory.c
index db182e5d3d..e5826faa0c 100644
--- a/softmmu/memory.c
+++ b/softmmu/memory.c
@@ -1378,17 +1378,17 @@ bool memory_region_access_valid(MemoryRegion *mr,
 {
     if (mr->ops->valid.accepts
         && !mr->ops->valid.accepts(mr->opaque, addr, size, is_write, attrs)) {
-        qemu_log_mask(LOG_GUEST_ERROR, "Invalid access at addr "
-                                       "0x%" HWADDR_PRIX ", size %u, "
-                                       "region '%s', reason: rejected\n",
+        qemu_log_mask(LOG_GUEST_ERROR, "Invalid %s at addr 0x%" HWADDR_PRIX
+                      ", size %u, region '%s', reason: rejected\n",
+                      is_write ? "write" : "read",
                       addr, size, memory_region_name(mr));
         return false;
     }
 
     if (!mr->ops->valid.unaligned && (addr & (size - 1))) {
-        qemu_log_mask(LOG_GUEST_ERROR, "Invalid access at addr "
-                                       "0x%" HWADDR_PRIX ", size %u, "
-                                       "region '%s', reason: unaligned\n",
+        qemu_log_mask(LOG_GUEST_ERROR, "Invalid %s at addr 0x%" HWADDR_PRIX
+                      ", size %u, region '%s', reason: unaligned\n",
+                      is_write ? "write" : "read",
                       addr, size, memory_region_name(mr));
         return false;
     }
@@ -1400,10 +1400,10 @@ bool memory_region_access_valid(MemoryRegion *mr,
 
     if (size > mr->ops->valid.max_access_size
         || size < mr->ops->valid.min_access_size) {
-        qemu_log_mask(LOG_GUEST_ERROR, "Invalid access at addr "
-                                       "0x%" HWADDR_PRIX ", size %u, "
-                                       "region '%s', reason: invalid size "
-                                       "(min:%u max:%u)\n",
+        qemu_log_mask(LOG_GUEST_ERROR, "Invalid %s at addr 0x%" HWADDR_PRIX
+                      ", size %u, region '%s', reason: invalid size "
+                      "(min:%u max:%u)\n",
+                      is_write ? "write" : "read",
                       addr, size, memory_region_name(mr),
                       mr->ops->valid.min_access_size,
                       mr->ops->valid.max_access_size);
-- 
2.21.4


Re: [PATCH] memory: Log access direction for invalid accesses
Posted by David Hildenbrand 2 years, 6 months ago
On 11.10.21 19:32, BALATON Zoltan wrote:
> In memory_region_access_valid() invalid accesses are logged to help
> debugging but the log message does not say if it was a read or write.
> Log that too to better identify the access causing the problem.
> 
> Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
> ---
>   softmmu/memory.c | 20 ++++++++++----------
>   1 file changed, 10 insertions(+), 10 deletions(-)
> 
> diff --git a/softmmu/memory.c b/softmmu/memory.c
> index db182e5d3d..e5826faa0c 100644
> --- a/softmmu/memory.c
> +++ b/softmmu/memory.c
> @@ -1378,17 +1378,17 @@ bool memory_region_access_valid(MemoryRegion *mr,
>   {
>       if (mr->ops->valid.accepts
>           && !mr->ops->valid.accepts(mr->opaque, addr, size, is_write, attrs)) {
> -        qemu_log_mask(LOG_GUEST_ERROR, "Invalid access at addr "
> -                                       "0x%" HWADDR_PRIX ", size %u, "
> -                                       "region '%s', reason: rejected\n",
> +        qemu_log_mask(LOG_GUEST_ERROR, "Invalid %s at addr 0x%" HWADDR_PRIX
> +                      ", size %u, region '%s', reason: rejected\n",
> +                      is_write ? "write" : "read",
>                         addr, size, memory_region_name(mr));
>           return false;
>       }
>   
>       if (!mr->ops->valid.unaligned && (addr & (size - 1))) {
> -        qemu_log_mask(LOG_GUEST_ERROR, "Invalid access at addr "
> -                                       "0x%" HWADDR_PRIX ", size %u, "
> -                                       "region '%s', reason: unaligned\n",
> +        qemu_log_mask(LOG_GUEST_ERROR, "Invalid %s at addr 0x%" HWADDR_PRIX
> +                      ", size %u, region '%s', reason: unaligned\n",
> +                      is_write ? "write" : "read",
>                         addr, size, memory_region_name(mr));
>           return false;
>       }
> @@ -1400,10 +1400,10 @@ bool memory_region_access_valid(MemoryRegion *mr,
>   
>       if (size > mr->ops->valid.max_access_size
>           || size < mr->ops->valid.min_access_size) {
> -        qemu_log_mask(LOG_GUEST_ERROR, "Invalid access at addr "
> -                                       "0x%" HWADDR_PRIX ", size %u, "
> -                                       "region '%s', reason: invalid size "
> -                                       "(min:%u max:%u)\n",
> +        qemu_log_mask(LOG_GUEST_ERROR, "Invalid %s at addr 0x%" HWADDR_PRIX
> +                      ", size %u, region '%s', reason: invalid size "
> +                      "(min:%u max:%u)\n",
> +                      is_write ? "write" : "read",
>                         addr, size, memory_region_name(mr),
>                         mr->ops->valid.min_access_size,
>                         mr->ops->valid.max_access_size);
> 

Reviewed-by: David Hildenbrand <david@redhat.com>

-- 
Thanks,

David / dhildenb


Re: [PATCH] memory: Log access direction for invalid accesses
Posted by Richard Henderson 2 years, 6 months ago
On 10/11/21 10:32 AM, BALATON Zoltan wrote:
> In memory_region_access_valid() invalid accesses are logged to help
> debugging but the log message does not say if it was a read or write.
> Log that too to better identify the access causing the problem.
> 
> Signed-off-by: BALATON Zoltan<balaton@eik.bme.hu>
> ---
>   softmmu/memory.c | 20 ++++++++++----------
>   1 file changed, 10 insertions(+), 10 deletions(-)

Thanks, queued for tcg-next.

r~