* [Qemu-devel] virtio_tswaps() vs virtio_ld/st_p()
@ 2015-01-19 11:35 Stefan Hajnoczi
2015-01-19 11:45 ` Peter Maydell
0 siblings, 1 reply; 6+ messages in thread
From: Stefan Hajnoczi @ 2015-01-19 11:35 UTC (permalink / raw)
To: Greg Kurz; +Cc: qemu-devel
What is the difference between the virtio_tswaps() and
virtio_ld/st_p() families of functions?
Both seem to byteswap when necessary (i.e. host and device endianness
do not match).
Stefan
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] virtio_tswaps() vs virtio_ld/st_p()
2015-01-19 11:35 [Qemu-devel] virtio_tswaps() vs virtio_ld/st_p() Stefan Hajnoczi
@ 2015-01-19 11:45 ` Peter Maydell
2015-01-19 12:49 ` Greg Kurz
0 siblings, 1 reply; 6+ messages in thread
From: Peter Maydell @ 2015-01-19 11:45 UTC (permalink / raw)
To: Stefan Hajnoczi; +Cc: qemu-devel
On 19 January 2015 at 11:35, Stefan Hajnoczi <stefanha@gmail.com> wrote:
> What is the difference between the virtio_tswaps() and
> virtio_ld/st_p() families of functions?
virtio_ld/st*_p() perform a load or store from memory pointed
to by the (host) pointer argument.
virtio_tswap16 &c take a value, swap it as appropriate and
return a value.
virtio_tswap16s &c do an in-place byteswap on the value pointed
to by the host pointer argument.
(The tswap*/tswap*s pairs are a mirror of the equivalent families
of functions bswap16/bswap16s provided by bswap.h.)
The most important distinction here is that the ld/st functions
will handle possibly unaligned accesses, whereas the tswap
functions will not. The former are intended for "fish this value
out from some guest RAM" and the latter for "we have a structure
we've copied from guest RAM already via memcpy and want to swizzle
the entries in it".
-- PMM
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] virtio_tswaps() vs virtio_ld/st_p()
2015-01-19 11:45 ` Peter Maydell
@ 2015-01-19 12:49 ` Greg Kurz
2015-01-19 12:53 ` Peter Maydell
2015-01-19 13:10 ` Stefan Hajnoczi
0 siblings, 2 replies; 6+ messages in thread
From: Greg Kurz @ 2015-01-19 12:49 UTC (permalink / raw)
To: Peter Maydell; +Cc: Stefan Hajnoczi, qemu-devel
On Mon, 19 Jan 2015 11:45:39 +0000
Peter Maydell <peter.maydell@linaro.org> wrote:
> On 19 January 2015 at 11:35, Stefan Hajnoczi <stefanha@gmail.com> wrote:
> > What is the difference between the virtio_tswaps() and
> > virtio_ld/st_p() families of functions?
>
> virtio_ld/st*_p() perform a load or store from memory pointed
> to by the (host) pointer argument.
>
> virtio_tswap16 &c take a value, swap it as appropriate and
> return a value.
>
> virtio_tswap16s &c do an in-place byteswap on the value pointed
> to by the host pointer argument.
>
> (The tswap*/tswap*s pairs are a mirror of the equivalent families
> of functions bswap16/bswap16s provided by bswap.h.)
>
> The most important distinction here is that the ld/st functions
> will handle possibly unaligned accesses, whereas the tswap
> functions will not. The former are intended for "fish this value
> out from some guest RAM" and the latter for "we have a structure
> we've copied from guest RAM already via memcpy and want to swizzle
> the entries in it".
>
> -- PMM
>
Heh, not sure I would have provided such a comprehensive answer. :)
Stefan,
Feeling curious, what was the intent behind your question ?
Cheers.
--
Greg
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] virtio_tswaps() vs virtio_ld/st_p()
2015-01-19 12:49 ` Greg Kurz
@ 2015-01-19 12:53 ` Peter Maydell
2015-01-19 13:01 ` Paolo Bonzini
2015-01-19 13:10 ` Stefan Hajnoczi
1 sibling, 1 reply; 6+ messages in thread
From: Peter Maydell @ 2015-01-19 12:53 UTC (permalink / raw)
To: Greg Kurz; +Cc: Stefan Hajnoczi, qemu-devel
On 19 January 2015 at 12:49, Greg Kurz <gkurz@linux.vnet.ibm.com> wrote:
> Heh, not sure I would have provided such a comprehensive answer. :)
...so now I have a question: what semantics does virtio expect
for its virtio_ld*/st*_phys accessors if QEMU is emulating a
CPU with virtualization support? Is the assumption just that
the guest that's using virtio has a 1:1 mapping of what it
thinks are physical addresses to real guest physical addresses?
(ie you couldn't have a virtio device that you passed through
to a hypervisor guest, because what the guest thinks are
physical addresses are really just intermediate physical
addresses in that configuration).
-- PMM
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] virtio_tswaps() vs virtio_ld/st_p()
2015-01-19 12:53 ` Peter Maydell
@ 2015-01-19 13:01 ` Paolo Bonzini
0 siblings, 0 replies; 6+ messages in thread
From: Paolo Bonzini @ 2015-01-19 13:01 UTC (permalink / raw)
To: Peter Maydell, Greg Kurz; +Cc: Stefan Hajnoczi, qemu-devel
On 19/01/2015 13:53, Peter Maydell wrote:
> > Heh, not sure I would have provided such a comprehensive answer. :)
>
> ...so now I have a question: what semantics does virtio expect
> for its virtio_ld*/st*_phys accessors if QEMU is emulating a
> CPU with virtualization support? Is the assumption just that
> the guest that's using virtio has a 1:1 mapping of what it
> thinks are physical addresses to real guest physical addresses?
Right now, the semantics are "PPC uses DMA addresses, everything else
uses physical addresses". However, this could be changed since x86
IOMMU support is still experimental, and without an IOMMU DMA addresses
_are_ physical addresses.
Paolo
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] virtio_tswaps() vs virtio_ld/st_p()
2015-01-19 12:49 ` Greg Kurz
2015-01-19 12:53 ` Peter Maydell
@ 2015-01-19 13:10 ` Stefan Hajnoczi
1 sibling, 0 replies; 6+ messages in thread
From: Stefan Hajnoczi @ 2015-01-19 13:10 UTC (permalink / raw)
To: Greg Kurz; +Cc: Peter Maydell, qemu-devel
On Mon, Jan 19, 2015 at 12:49 PM, Greg Kurz <gkurz@linux.vnet.ibm.com> wrote:
> On Mon, 19 Jan 2015 11:45:39 +0000
> Peter Maydell <peter.maydell@linaro.org> wrote:
>
>> On 19 January 2015 at 11:35, Stefan Hajnoczi <stefanha@gmail.com> wrote:
>> > What is the difference between the virtio_tswaps() and
>> > virtio_ld/st_p() families of functions?
>>
>> virtio_ld/st*_p() perform a load or store from memory pointed
>> to by the (host) pointer argument.
>>
>> virtio_tswap16 &c take a value, swap it as appropriate and
>> return a value.
>>
>> virtio_tswap16s &c do an in-place byteswap on the value pointed
>> to by the host pointer argument.
>>
>> (The tswap*/tswap*s pairs are a mirror of the equivalent families
>> of functions bswap16/bswap16s provided by bswap.h.)
>>
>> The most important distinction here is that the ld/st functions
>> will handle possibly unaligned accesses, whereas the tswap
>> functions will not. The former are intended for "fish this value
>> out from some guest RAM" and the latter for "we have a structure
>> we've copied from guest RAM already via memcpy and want to swizzle
>> the entries in it".
>>
>> -- PMM
>>
>
> Heh, not sure I would have provided such a comprehensive answer. :)
>
> Stefan,
>
> Feeling curious, what was the intent behind your question ?
I'm converting hw/virtio/dataplane/vring.c to use virtio_ld/st()
accessors so that KVM on Power supports bi-endian mode.
I noticed that devices use both virtio_tswap() and virtio_ld/st() in
different places. My main worry was that they are implemented
slightly different (how they combine #ifdefs and
virtio_access_is_big_endian()) and that I was missing something.
But it seems in my case there is no difference between the two.
Stefan
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2015-01-19 13:10 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-19 11:35 [Qemu-devel] virtio_tswaps() vs virtio_ld/st_p() Stefan Hajnoczi
2015-01-19 11:45 ` Peter Maydell
2015-01-19 12:49 ` Greg Kurz
2015-01-19 12:53 ` Peter Maydell
2015-01-19 13:01 ` Paolo Bonzini
2015-01-19 13:10 ` Stefan Hajnoczi
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).