qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: Peter Xu <peterx@redhat.com>
Cc: "Eduardo Habkost" <ehabkost@redhat.com>,
	"Juan Quintela" <quintela@redhat.com>,
	"Pankaj Gupta" <pankaj.gupta@cloud.ionos.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	teawater <teawaterz@linux.alibaba.com>,
	qemu-devel@nongnu.org,
	"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
	"Alex Williamson" <alex.williamson@redhat.com>,
	"Marek Kedzierski" <mkedzier@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Philippe Mathieu-Daudé" <philmd@redhat.com>,
	"Andrey Gruzdev" <andrey.gruzdev@virtuozzo.com>,
	"Wei Yang" <richard.weiyang@linux.alibaba.com>
Subject: Re: [PATCH v4 7/9] migration: Simplify alignment and alignment checks
Date: Fri, 3 Sep 2021 12:07:20 +0200	[thread overview]
Message-ID: <2d04741d-94bd-9cd2-4d70-f6505bc8db16@redhat.com> (raw)
In-Reply-To: <8985fca4-e15c-95a7-2c45-74353a3a19fa@redhat.com>

On 03.09.21 10:47, David Hildenbrand wrote:
> On 03.09.21 00:32, Peter Xu wrote:
>> On Thu, Sep 02, 2021 at 03:14:30PM +0200, David Hildenbrand wrote:
>>> diff --git a/migration/migration.c b/migration/migration.c
>>> index bb909781b7..ae97c2c461 100644
>>> --- a/migration/migration.c
>>> +++ b/migration/migration.c
>>> @@ -391,7 +391,7 @@ int migrate_send_rp_message_req_pages(MigrationIncomingState *mis,
>>>    int migrate_send_rp_req_pages(MigrationIncomingState *mis,
>>>                                  RAMBlock *rb, ram_addr_t start, uint64_t haddr)
>>>    {
>>> -    void *aligned = (void *)(uintptr_t)(haddr & (-qemu_ram_pagesize(rb)));
>>> +    void *aligned = (void *)QEMU_ALIGN_DOWN(haddr, qemu_ram_pagesize(rb));
>>
>> Is uintptr_t still needed?  I thought it would generate a warning otherwise but
>> not sure.
> 
> It doesn't in my setup, but maybe it will on 32bit archs ...
> 
> I discussed this with Phil in
> 
> https://lkml.kernel.org/r/2c8d80ad-f171-7d5f-3235-92f02fa174b3@redhat.com
> 
> Maybe
> 
> QEMU_ALIGN_PTR_DOWN((void *)haddr, qemu_ram_pagesize(rb)));
> 
> Is really what we want.

... but it would suffer the same issue I think. I just ran it trough the 
gitlab pipeline, including "i386-fedora-cross-compile" ... and it seems 
to compile just fine, which is weird, because I'd also expect

"warning: cast to pointer from integer of different size 
[-Wint-to-pointer-cast]"

We most certainly need the "(void *)(uintptr_t)" to convert from u64 to 
a pointer.

Let's just do it cleanly:

void *unaligned = (void *)(uintptr_t)haddr;
void *aligned = QEMU_ALIGN_PTR_DOWN(unaligned, qemu_ram_pagesize(rb));

Thoughts?

-- 
Thanks,

David / dhildenb



  reply	other threads:[~2021-09-03 10:08 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-02 13:14 [PATCH v4 0/9] migration/ram: Optimize for virtio-mem via RamDiscardManager David Hildenbrand
2021-09-02 13:14 ` [PATCH v4 1/9] memory: Introduce replay_discarded callback for RamDiscardManager David Hildenbrand
2021-09-02 13:14 ` [PATCH v4 2/9] virtio-mem: Implement replay_discarded RamDiscardManager callback David Hildenbrand
2021-09-02 13:14 ` [PATCH v4 3/9] migration/ram: Don't passs RAMState to migration_clear_memory_region_dirty_bitmap_*() David Hildenbrand
2021-09-02 13:14 ` [PATCH v4 4/9] migration/ram: Handle RAMBlocks with a RamDiscardManager on the migration source David Hildenbrand
2021-09-02 13:14 ` [PATCH v4 5/9] virtio-mem: Drop precopy notifier David Hildenbrand
2021-09-02 13:14 ` [PATCH v4 6/9] migration/postcopy: Handle RAMBlocks with a RamDiscardManager on the destination David Hildenbrand
2021-09-02 13:14 ` [PATCH v4 7/9] migration: Simplify alignment and alignment checks David Hildenbrand
2021-09-02 22:32   ` Peter Xu
2021-09-03  8:47     ` David Hildenbrand
2021-09-03 10:07       ` David Hildenbrand [this message]
2021-09-03 10:22         ` David Hildenbrand
2021-09-03 19:14         ` Peter Xu
2021-09-03 19:37           ` David Hildenbrand
2021-09-02 13:14 ` [PATCH v4 8/9] migration/ram: Factor out populating pages readable in ram_block_populate_pages() David Hildenbrand
2021-09-02 22:28   ` Peter Xu
2021-09-03  7:45     ` David Hildenbrand
2021-09-03  7:58       ` David Hildenbrand
2021-09-03 19:20         ` Peter Xu
2021-09-03 19:40           ` David Hildenbrand
2021-09-03 19:45             ` David Hildenbrand
2021-09-02 13:14 ` [PATCH v4 9/9] migration/ram: Handle RAMBlocks with a RamDiscardManager on background snapshots David Hildenbrand

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=2d04741d-94bd-9cd2-4d70-f6505bc8db16@redhat.com \
    --to=david@redhat.com \
    --cc=alex.williamson@redhat.com \
    --cc=andrey.gruzdev@virtuozzo.com \
    --cc=dgilbert@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=mkedzier@redhat.com \
    --cc=mst@redhat.com \
    --cc=pankaj.gupta@cloud.ionos.com \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.com \
    --cc=philmd@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    --cc=richard.weiyang@linux.alibaba.com \
    --cc=teawaterz@linux.alibaba.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).