qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Alberto Faria <afaria@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-devel <qemu-devel@nongnu.org>,
	"Peter Xu" <peterx@redhat.com>,
	"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
	"David Hildenbrand" <david@redhat.com>,
	"Stefan Hajnoczi" <stefanha@redhat.com>
Subject: Re: [PATCH v2] softmmu/physmem: Fix address of FlatView access in address_space_(read|write)_cached_slow()
Date: Fri, 2 Dec 2022 12:29:10 +0000	[thread overview]
Message-ID: <CAELaAXzhsNYQZV_FCmaY06x0UOqPTw3Lwsao1veBCq+eM4eayg@mail.gmail.com> (raw)
In-Reply-To: <CABgObfahkrhwwn6+D7uUbqKYPXmA3mQGXHwe6f-TiA+iQoFyAQ@mail.gmail.com>

On Mon, Sep 5, 2022 at 8:45 AM Paolo Bonzini <pbonzini@redhat.com> wrote:
> Thanks, I will queue it.
>
> Paolo
>
> Il lun 5 set 2022, 02:00 Alberto Faria <afaria@redhat.com> ha scritto:
>>
>> flatview_(read|write)_continue() must be called with an address in the
>> FlatView's address space, but `addr` is relative to the
>> MemoryRegionCache.
>>
>> Convert `addr` from the MemoryRegionCache's address space to the
>> FlatView's before passing it to flatview_(read|write)_continue().
>>
>> This problem was uncovered while attempting to perform unaligned writes,
>> which caused flatview_write_continue() to reach the call to
>> flatview_translate(), which then translated the erroneous address and
>> caused the subsequent write to fail.
>>
>> Fixes: 48564041a7 ("exec: reintroduce MemoryRegion caching")
>> Co-Developed-by: Stefan Hajnoczi <stefanha@redhat.com>
>> Signed-off-by: Alberto Faria <afaria@redhat.com>
>> ---
>>  softmmu/physmem.c | 18 ++++++++++++++----
>>  1 file changed, 14 insertions(+), 4 deletions(-)
>>
>> diff --git a/softmmu/physmem.c b/softmmu/physmem.c
>> index 50231bab30..bdde4eb927 100644
>> --- a/softmmu/physmem.c
>> +++ b/softmmu/physmem.c
>> @@ -3420,6 +3420,14 @@ static inline MemoryRegion *address_space_translate_cached(
>>      return section.mr;
>>  }
>>
>> +/* Converts `addr` from the address space of `cache` to that of `cache->fv`. */
>> +static inline hwaddr addr_in_cache_to_in_flat_view(MemoryRegionCache *cache,
>> +                                                   hwaddr addr)
>> +{
>> +    hwaddr addr_in_mrs = addr + cache->xlat - cache->mrs.offset_within_region;
>> +    return addr_in_mrs + cache->mrs.offset_within_address_space;
>> +}
>> +
>>  /* Called from RCU critical section. address_space_read_cached uses this
>>   * out of line function when the target is an MMIO or IOMMU region.
>>   */
>> @@ -3434,8 +3442,9 @@ address_space_read_cached_slow(MemoryRegionCache *cache, hwaddr addr,
>>      mr = address_space_translate_cached(cache, addr, &addr1, &l, false,
>>                                          MEMTXATTRS_UNSPECIFIED);
>>      return flatview_read_continue(cache->fv,
>> -                                  addr, MEMTXATTRS_UNSPECIFIED, buf, len,
>> -                                  addr1, l, mr);
>> +                                  addr_in_cache_to_in_flat_view(cache, addr),
>> +                                  MEMTXATTRS_UNSPECIFIED, buf, len, addr1, l,
>> +                                  mr);
>>  }
>>
>>  /* Called from RCU critical section. address_space_write_cached uses this
>> @@ -3452,8 +3461,9 @@ address_space_write_cached_slow(MemoryRegionCache *cache, hwaddr addr,
>>      mr = address_space_translate_cached(cache, addr, &addr1, &l, true,
>>                                          MEMTXATTRS_UNSPECIFIED);
>>      return flatview_write_continue(cache->fv,
>> -                                   addr, MEMTXATTRS_UNSPECIFIED, buf, len,
>> -                                   addr1, l, mr);
>> +                                   addr_in_cache_to_in_flat_view(cache, addr),
>> +                                   MEMTXATTRS_UNSPECIFIED, buf, len, addr1, l,
>> +                                   mr);
>>  }
>>
>>  #define ARG1_DECL                MemoryRegionCache *cache
>> --
>> 2.37.2

This doesn't seem to be in master yet. Maybe it fell through the cracks?

Alberto



  reply	other threads:[~2022-12-02 12:30 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-05  0:00 [PATCH v2] softmmu/physmem: Fix address of FlatView access in address_space_(read|write)_cached_slow() Alberto Faria
2022-09-05  7:45 ` Paolo Bonzini
2022-12-02 12:29   ` Alberto Faria [this message]
2023-01-11 14:28     ` Stefan Hajnoczi

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=CAELaAXzhsNYQZV_FCmaY06x0UOqPTw3Lwsao1veBCq+eM4eayg@mail.gmail.com \
    --to=afaria@redhat.com \
    --cc=david@redhat.com \
    --cc=f4bug@amsat.org \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /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 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).