* [Qemu-devel] [PATCH v2] migration: Don't use *_to_cpup() and cpu_to_*w()
@ 2016-06-10 16:09 Peter Maydell
2016-06-10 19:15 ` Eric Blake
2016-06-13 4:38 ` Amit Shah
0 siblings, 2 replies; 3+ messages in thread
From: Peter Maydell @ 2016-06-10 16:09 UTC (permalink / raw)
To: qemu-devel; +Cc: patches, Juan Quintela, Amit Shah, Eric Blake
The *_to_cpup() and cpu_to_*w() functions just compose a pointer
dereference with a byteswap. Instead use ld*_p() and st*_p(),
which handle potential pointer misalignment and avoid the need
to cast the pointer.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
Changes v1->v2: fix cpu_to_*w() uses too.
The motivation here is that I'd like to get rid of _to_cpup()
and cpu_to_*w() entirely: we don't have many places that use them.
---
migration/migration.c | 12 ++++++------
migration/savevm.c | 4 ++--
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/migration/migration.c b/migration/migration.c
index 7ecbade..551da0a 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -1381,7 +1381,7 @@ static void *source_return_path_thread(void *opaque)
/* OK, we have the message and the data */
switch (header_type) {
case MIG_RP_MSG_SHUT:
- sibling_error = be32_to_cpup((uint32_t *)buf);
+ sibling_error = ldl_be_p(buf);
trace_source_return_path_thread_shut(sibling_error);
if (sibling_error) {
error_report("RP: Sibling indicated error %d", sibling_error);
@@ -1395,13 +1395,13 @@ static void *source_return_path_thread(void *opaque)
goto out;
case MIG_RP_MSG_PONG:
- tmp32 = be32_to_cpup((uint32_t *)buf);
+ tmp32 = ldl_be_p(buf);
trace_source_return_path_thread_pong(tmp32);
break;
case MIG_RP_MSG_REQ_PAGES:
- start = be64_to_cpup((uint64_t *)buf);
- len = be32_to_cpup((uint32_t *)(buf + 8));
+ start = ldq_be_p(buf);
+ len = ldl_be_p(buf + 8);
migrate_handle_rp_req_pages(ms, NULL, start, len);
break;
@@ -1409,8 +1409,8 @@ static void *source_return_path_thread(void *opaque)
expected_len = 12 + 1; /* header + termination */
if (header_len >= expected_len) {
- start = be64_to_cpup((uint64_t *)buf);
- len = be32_to_cpup((uint32_t *)(buf + 8));
+ start = ldq_be_p(buf);
+ len = ldl_be_p(buf + 8);
/* Now we expect an idstr */
tmp32 = buf[12]; /* Length of the following idstr */
buf[13 + tmp32] = '\0';
diff --git a/migration/savevm.c b/migration/savevm.c
index 6c21231..7da46a6 100644
--- a/migration/savevm.c
+++ b/migration/savevm.c
@@ -822,9 +822,9 @@ void qemu_savevm_send_postcopy_ram_discard(QEMUFile *f, const char *name,
buf[tmplen++] = '\0';
for (t = 0; t < len; t++) {
- cpu_to_be64w((uint64_t *)(buf + tmplen), start_list[t]);
+ stq_be_p(buf + tmplen, start_list[t]);
tmplen += 8;
- cpu_to_be64w((uint64_t *)(buf + tmplen), length_list[t]);
+ stq_be_p(buf + tmplen, length_list[t]);
tmplen += 8;
}
qemu_savevm_command_send(f, MIG_CMD_POSTCOPY_RAM_DISCARD, tmplen, buf);
--
1.9.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH v2] migration: Don't use *_to_cpup() and cpu_to_*w()
2016-06-10 16:09 [Qemu-devel] [PATCH v2] migration: Don't use *_to_cpup() and cpu_to_*w() Peter Maydell
@ 2016-06-10 19:15 ` Eric Blake
2016-06-13 4:38 ` Amit Shah
1 sibling, 0 replies; 3+ messages in thread
From: Eric Blake @ 2016-06-10 19:15 UTC (permalink / raw)
To: Peter Maydell, qemu-devel; +Cc: patches, Juan Quintela, Amit Shah
[-- Attachment #1: Type: text/plain, Size: 825 bytes --]
On 06/10/2016 10:09 AM, Peter Maydell wrote:
> The *_to_cpup() and cpu_to_*w() functions just compose a pointer
> dereference with a byteswap. Instead use ld*_p() and st*_p(),
> which handle potential pointer misalignment and avoid the need
> to cast the pointer.
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> Changes v1->v2: fix cpu_to_*w() uses too.
>
> The motivation here is that I'd like to get rid of _to_cpup()
> and cpu_to_*w() entirely: we don't have many places that use them.
> ---
> migration/migration.c | 12 ++++++------
> migration/savevm.c | 4 ++--
> 2 files changed, 8 insertions(+), 8 deletions(-)
>
Reviewed-by: Eric Blake <eblake@redhat.com>
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH v2] migration: Don't use *_to_cpup() and cpu_to_*w()
2016-06-10 16:09 [Qemu-devel] [PATCH v2] migration: Don't use *_to_cpup() and cpu_to_*w() Peter Maydell
2016-06-10 19:15 ` Eric Blake
@ 2016-06-13 4:38 ` Amit Shah
1 sibling, 0 replies; 3+ messages in thread
From: Amit Shah @ 2016-06-13 4:38 UTC (permalink / raw)
To: Peter Maydell; +Cc: qemu-devel, patches, Juan Quintela, Eric Blake
On (Fri) 10 Jun 2016 [17:09:22], Peter Maydell wrote:
> The *_to_cpup() and cpu_to_*w() functions just compose a pointer
> dereference with a byteswap. Instead use ld*_p() and st*_p(),
> which handle potential pointer misalignment and avoid the need
> to cast the pointer.
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Amit Shah <amit.shah@redhat.com>
I'll pick this up, thanks.
Amit
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-06-13 4:39 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-06-10 16:09 [Qemu-devel] [PATCH v2] migration: Don't use *_to_cpup() and cpu_to_*w() Peter Maydell
2016-06-10 19:15 ` Eric Blake
2016-06-13 4:38 ` Amit Shah
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).