memory: allow zero size for adjust_endianness()
PATCH 1/2 memory: allow zero size for adjust_endianness()
Wildcard mmio eventfd use zero size, but it will lead abort() since it was illegal in adjust_endianness(). Fix this by allowing zero size.
--- memory.c | 1 + 1 file changed, 1 insertion(+)
memory.c +1 -0
@@ -353,6 +353,7 @@ static void adjust_endianness(MemoryRegion *mr, uint64_t *data, unsigned size) {if (memory_region_wrong_endianness (mr)) {switch (size) { +case 0 :case 1 :break ;case 2 :
Signature · 1 line
2.1.4
PATCH 2/2 pci: test-dev: try to test fast mmio bus for wildcard mmio event
Test fast mmio by using zero size eventfd.
--- hw/misc/pci-testdev.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
hw/misc/pci-testdev.c +5 -1
@@ -261,8 +261,12 @@ static void pci_testdev_realize(PCIDevice *pci_dev, Error **errp)memcpy (test->hdr->name, name,strlen (name) +1 );g_free (name); test->hdr->offset =cpu_to_le32 (IOTEST_SIZE (i) + i *IOTEST_ACCESS_WIDTH ); - test->size =IOTEST_ACCESS_WIDTH ; test->match_data =strcmp (IOTEST_TEST (i),"wildcard-eventfd" ); +if (!test->match_data && !strcmp (IOTEST_TYPE (i),"mmio" )) { + test->size =0 ; + }else { + test->size =IOTEST_ACCESS_WIDTH ; + } test->hdr->test = i; test->hdr->data = test->match_data ?IOTEST_DATAMATCH :IOTEST_NOMATCH ; test->hdr->width =IOTEST_ACCESS_WIDTH ;
Signature · 1 line
2.1.4
Quoted 6 lines · Jason Wang
Wildcard mmio eventfd use zero size, but it will lead
abort()since it was illegal inadjust_endianness(). Fix this by allowing zero size.Cc Greg Kurz <[email protected]>Cc Paolo Bonzini <[email protected]>Signed-off-by Jason Wang <[email protected]>
This seems to me like a bug in the caller. Why would anything try to call into the memory subsystem to do a zero-size transaction?
thanks
-- PMM
Quoted 8 lines · On Wed, 26 Aug 2015 15:21:59 +0100 Peter Maydell <[email protected]>…
Quoted 6 lines · Jason Wang
Wildcard mmio eventfd use zero size, but it will lead
abort()since it was illegal inadjust_endianness(). Fix this by allowing zero size.Cc Greg Kurz <[email protected]>Cc Paolo Bonzini <[email protected]>Signed-off-by Jason Wang <[email protected]>
Quoted 7 lines
This seems to me like a bug in the caller. Why would anything try to call into the memory subsystem to do a zero-size transaction?
thanks
-- PMM
Here's the patch which needs zero-size eventfd:
http://patchwork.ozlabs.org/patch/509428/
Cheers.
--
Greg
Quoted 17 lines · Greg Kurz
Quoted 7 lines · On Wed, 26 Aug 2015 15:21:59 +0100 Peter Maydell <[email protected]>…
Quoted 6 lines · Jason Wang
Wildcard mmio eventfd use zero size, but it will lead
abort()since it was illegal inadjust_endianness(). Fix this by allowing zero size.Cc Greg Kurz <[email protected]>Cc Paolo Bonzini <[email protected]>Signed-off-by Jason Wang <[email protected]>Quoted 7 lines
This seems to me like a bug in the caller. Why would anything try to call into the memory subsystem to do a zero-size transaction?
thanks
-- PMM
Quoted 9 lines
Here's the patch which needs zero-size eventfd:
http://patchwork.ozlabs.org/patch/509428/
Cheers.
--
Greg
Yes, this is because we want to use wildcard mmio eventfd (which requires size to be zero) to speed up virtio 1.0 mmio.
Re: [Qemu-devel] [PATCH 2/2] pci: test-dev: try to test fast mmio bus for wildcard mmio event
In reply to Jason WangQuoted 3 lines · Jason Wang
Test fast mmio by using zero size eventfd.
Signed-off-by Jason Wang <[email protected]>
wildcard is not the same as ignoring length.
I think I have a nicer patch, will post now.
Quoted 24 lines
--- hw/misc/pci-testdev.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)hw/misc/pci-testdev.c +5
-1@@ -261,8 +261,12 @@ static void pci_testdev_realize(PCIDevice *pci_dev, Error **errp)memcpy (test->hdr->name, name,strlen (name) +1 );g_free (name); test->hdr->offset =cpu_to_le32 (IOTEST_SIZE (i) + i *IOTEST_ACCESS_WIDTH ); - test->size =IOTEST_ACCESS_WIDTH ; test->match_data =strcmp (IOTEST_TEST (i),"wildcard-eventfd" ); +if (!test->match_data && !strcmp (IOTEST_TYPE (i),"mmio" )) { + test->size =0 ; + }else { + test->size =IOTEST_ACCESS_WIDTH ; + } test->hdr->test = i; test->hdr->data = test->match_data ?IOTEST_DATAMATCH :IOTEST_NOMATCH ; test->hdr->width =IOTEST_ACCESS_WIDTH ;Signature · 1 line
2.1.4
Quoted 7 lines · Jason Wang
Quoted 5 lines · Greg Kurz
Quoted 3 lines · On Wed, 26 Aug 2015 15:21:59 +0100 Peter Maydell <[email protected]>…
This seems to me like a bug in the caller. Why would anything try to call into the memory subsystem to do a zero-size transaction?
Quoted 6 lines
Quoted 3 lines
Here's the patch which needs zero-size eventfd:
Yes, this is because we want to use wildcard mmio eventfd (which requires size to be zero) to speed up virtio 1.0 mmio.
But *why* does it require the size to be zero? I still think the caller should just avoid trying to do zero-size memory
operations: they don't make sense. What is a zero size operation supposed to mean?
-- PMM
Quoted 15 lines · Peter Maydell
Quoted 7 lines · Jason Wang
Quoted 5 lines · Greg Kurz
Quoted 3 lines · On Wed, 26 Aug 2015 15:21:59 +0100 Peter Maydell <[email protected]>…
This seems to me like a bug in the caller. Why would anything try to call into the memory subsystem to do a zero-size transaction?
Quoted 6 lines
Quoted 3 lines
Here's the patch which needs zero-size eventfd:
Yes, this is because we want to use wildcard mmio eventfd (which requires size to be zero) to speed up virtio 1.0 mmio.
Quoted 6 lines
But *why* does it require the size to be zero? I still think the caller should just avoid trying to do zero-size memory
operations: they don't make sense. What is a zero size operation supposed to mean?-- PMM
This just mirrors an API we have in kvm: if you pass 0 size when registering an ioeventfd, it will match on access of any size.
Signature · 1 line
MST
Quoted 9 lines · Michael S. Tsirkin
Quoted 4 lines · Peter Maydell
But *why* does it require the size to be zero? I still think the caller should just avoid trying to do zero-size memory
operations: they don't make sense. What is a zero size operation supposed to mean?This just mirrors an API we have in kvm: if you pass 0 size when registering an ioeventfd, it will match on access of any size.
Hrm. It feels to me like the memory APIs ought to filter out bad access sizes at an earlier stage, rather than trying to make them work all the way through.
-- PMM
Quoted 11 lines · Peter Maydell
Quoted 9 lines · Michael S. Tsirkin
Quoted 4 lines · Peter Maydell
But *why* does it require the size to be zero? I still think the caller should just avoid trying to do zero-size memory
operations: they don't make sense. What is a zero size operation supposed to mean?This just mirrors an API we have in kvm: if you pass 0 size when registering an ioeventfd, it will match on access of any size.
Quoted 5 lines
Hrm. It feels to me like the memory APIs ought to filter out bad access sizes at an earlier stage, rather than trying to make them work all the way through.
-- PMM
Why do you mention APIs? It's all internal to memory.c, isn't it?
Signature · 1 line
MST
Quoted 12 lines · Michael S. Tsirkin
Quoted 11 lines · Peter Maydell
Quoted 9 lines · Michael S. Tsirkin
Quoted 4 lines · Peter Maydell
But *why* does it require the size to be zero? I still think the caller should just avoid trying to do zero-size memory
operations: they don't make sense. What is a zero size operation supposed to mean?This just mirrors an API we have in kvm: if you pass 0 size when registering an ioeventfd, it will match on access of any size.
Quoted 5 lines
Quoted 3 lines
Hrm. It feels to me like the memory APIs ought to filter out bad access sizes at an earlier stage, rather than trying to make them work all the way through.
Why do you mention APIs? It's all internal to
memory.c, isn't it?
adjust_endianness() is internal to memory.c. The APIs memory.c exposes to the rest of the world are the ones declared in memory.h. I'm suggesting that it would be better to filter out rubbish like zero sizes at the point where the rest of the world calls the memory subsystem rather than ensuring that every part of the memory subsystem code can handle what is basically a completely meaningless request.
-- PMM
Quoted 28 lines · Peter Maydell
Quoted 12 lines · Michael S. Tsirkin
Quoted 11 lines · Peter Maydell
Quoted 9 lines · Michael S. Tsirkin
Quoted 4 lines · Peter Maydell
But *why* does it require the size to be zero? I still think the caller should just avoid trying to do zero-size memory
operations: they don't make sense. What is a zero size operation supposed to mean?This just mirrors an API we have in kvm: if you pass 0 size when registering an ioeventfd, it will match on access of any size.
Quoted 5 lines
Quoted 3 lines
Hrm. It feels to me like the memory APIs ought to filter out bad access sizes at an earlier stage, rather than trying to make them work all the way through.
Why do you mention APIs? It's all internal to
memory.c, isn't it?
adjust_endianness()is internal tomemory.c. The APIsmemory.cexposes to the rest of the world are the ones declared inmemory.h. I'm suggesting that it would be better to filter out rubbish like zero sizes at the point where the rest of the world calls the memory subsystem rather than ensuring that every part of the memory subsystem code can handle what is basically a completely meaningless request.
Quoted 1 line
-- PMM
Basically the point is that ABI is extended to make ioeventfd with len = 0 mean "any length".
0 is thus not meaningless anymore.
Signature · 1 line
MST
Quoted 3 lines · Michael S. Tsirkin
Basically the point is that ABI is extended to make ioeventfd with len = 0 mean "any length".
0 is thus not meaningless anymore.
But how can you do adjustment for incorrect endianness if you don't know the size of the data that you're trying to work with? That's why this switch insists that the size is 1, 2, 4 or 8.
-- PMM
Quoted 11 lines · Peter Maydell
Quoted 3 lines · Michael S. Tsirkin
Basically the point is that ABI is extended to make ioeventfd with len = 0 mean "any length".
0 is thus not meaningless anymore.But how can you do adjustment for incorrect endianness if you don't know the size of the data that you're trying to work with? That's why this switch insists that the size is 1, 2, 4 or 8.
-- PMM
For kvm at least, "any length" implies "any data". So data is eventually discarded, we don't really need to adjust it for endian-ness.
Signature · 1 line
MST
Quoted 6 lines · Michael S. Tsirkin
Quoted 5 lines · Peter Maydell
Quoted 3 lines · Michael S. Tsirkin
Basically the point is that ABI is extended to make ioeventfd with len = 0 mean "any length".
0 is thus not meaningless anymore.
Quoted 8 lines
Quoted 4 lines
But how can you do adjustment for incorrect endianness if you don't know the size of the data that you're trying to work with? That's why this switch insists that the size is 1, 2, 4 or 8.
For kvm at least, "any length" implies "any data". So data is eventually discarded, we don't really need to adjust it for endian-ness.
I'm still confused. If you have data it needs to be adjusted. If we're not actually doing anything with the data why are we calling this function in the first place?
-- PMM
Quoted 16 lines · Peter Maydell
Quoted 6 lines · Michael S. Tsirkin
Quoted 5 lines · Peter Maydell
Quoted 3 lines · Michael S. Tsirkin
Basically the point is that ABI is extended to make ioeventfd with len = 0 mean "any length".
0 is thus not meaningless anymore.Quoted 8 lines
Quoted 4 lines
But how can you do adjustment for incorrect endianness if you don't know the size of the data that you're trying to work with? That's why this switch insists that the size is 1, 2, 4 or 8.
For kvm at least, "any length" implies "any data". So data is eventually discarded, we don't really need to adjust it for endian-ness.
Quoted 6 lines
I'm still confused. If you have data it needs to be adjusted. If we're not actually doing anything with the data why are we calling this function in the first place?
-- PMM
I guess you could skip calls to adjust_endianness when len == 0, that should work just as well.
Signature · 1 line
MST
Quoted 22 lines · On Thu, 27 Aug 2015 15:30:55 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 21 lines · Peter Maydell
Quoted 6 lines · Michael S. Tsirkin
Quoted 5 lines · Peter Maydell
Quoted 3 lines · Michael S. Tsirkin
Basically the point is that ABI is extended to make ioeventfd with len = 0 mean "any length".
0 is thus not meaningless anymore.Quoted 8 lines
Quoted 4 lines
But how can you do adjustment for incorrect endianness if you don't know the size of the data that you're trying to work with? That's why this switch insists that the size is 1, 2, 4 or 8.
For kvm at least, "any length" implies "any data". So data is eventually discarded, we don't really need to adjust it for endian-ness.
I'm still confused. If you have data it needs to be adjusted. If we're not actually doing anything with the data why are we calling this function in the first place?
Quoted 5 lines
Quoted 1 line
-- PMM
I guess you could skip calls to
adjust_endiannesswhen len == 0, that should work just as well.
adjust_endianness() is called from 4 different locations:
- memory_region_dispatch_read()
- memory_region_dispatch_write()
- memory_region_add_eventfd()
- memory_region_del_eventfd()
Since the issue was raised for the eventfd ones, it makes more sense to check in the caller indeed... and to preserve other paths.
Cheers.
--
Greg
Quoted 32 lines · Greg Kurz
Quoted 14 lines · On Thu, 27 Aug 2015 15:30:55 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 13 lines · Peter Maydell
Quoted 12 lines · Michael S. Tsirkin
Quoted 8 lines · Peter Maydell
Quoted 3 lines · Michael S. Tsirkin
Basically the point is that ABI is extended to make ioeventfd with len = 0 mean "any length".
0 is thus not meaningless anymore.But how can you do adjustment for incorrect endianness if you don't know the size of the data that you're trying to work with? That's why this switch insists that the size is 1, 2, 4 or 8.
For kvm at least, "any length" implies "any data". So data is eventually discarded, we don't really need to adjust it for endian-ness.
Quoted 9 lines
Quoted 6 lines
I'm still confused. If you have data it needs to be adjusted. If we're not actually doing anything with the data why are we calling this function in the first place?
-- PMM
I guess you could skip calls to
adjust_endiannesswhen len == 0, that should work just as well.
adjust_endianness()is called from 4 different locations:
-memory_region_dispatch_read()
-memory_region_dispatch_write()
-memory_region_add_eventfd()
-memory_region_del_eventfd()
Quoted 8 lines
Since the issue was raised for the eventfd ones, it makes more sense to check in the caller indeed... and to preserve other paths.
Cheers.
--
Greg
Yes, this seems fine.