From nobody Mon Feb 9 16:51:00 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1630590617951696.7123149925394; Thu, 2 Sep 2021 06:50:17 -0700 (PDT) Received: from localhost ([::1]:46402 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mLn6f-0003Yz-0q for importer@patchew.org; Thu, 02 Sep 2021 09:50:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44888) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLmZW-0008Ki-JT for qemu-devel@nongnu.org; Thu, 02 Sep 2021 09:16:02 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:36116) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLmZT-0007ZZ-AE for qemu-devel@nongnu.org; Thu, 02 Sep 2021 09:16:02 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-516-y47JLsm5MK2-YB6HY5DWAQ-1; Thu, 02 Sep 2021 09:15:57 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C8993107ACCA; Thu, 2 Sep 2021 13:15:56 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.39.193.198]) by smtp.corp.redhat.com (Postfix) with ESMTP id 131666ACE5; Thu, 2 Sep 2021 13:15:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630588558; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=a/2hkVjyNEsIm3ZK2v55DqIK6eNo6TsQ/fA/eegGpuc=; b=ZP7JJbuy1SYzU28XzWMjWoVboRWMbVryXoLCGWTCYSoibQhGT4i3+fwQYMW9d4lClZoVt0 yiN/aku+KayDvO+Hkbi5foc0o3iAyHETW/ILB8uLFuZLr4a6MfWXotfyBxmVZgEbG5swY1 b3M7cMrsNkYMOVMxPXKNN5hFwHsY8aI= X-MC-Unique: y47JLsm5MK2-YB6HY5DWAQ-1 From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH v4 7/9] migration: Simplify alignment and alignment checks Date: Thu, 2 Sep 2021 15:14:30 +0200 Message-Id: <20210902131432.23103-8-david@redhat.com> In-Reply-To: <20210902131432.23103-1-david@redhat.com> References: <20210902131432.23103-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=david@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=david@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.39, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , "Michael S. Tsirkin" , Pankaj Gupta , Juan Quintela , David Hildenbrand , "Dr. David Alan Gilbert" , Peter Xu , Marek Kedzierski , Alex Williamson , teawater , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Andrey Gruzdev , Wei Yang Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1630590619510100001 Content-Type: text/plain; charset="utf-8" Let's use QEMU_ALIGN_DOWN() and friends to make the code a bit easier to read. Signed-off-by: David Hildenbrand --- migration/migration.c | 6 +++--- migration/postcopy-ram.c | 9 ++++----- migration/ram.c | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) 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(MigrationIncoming= State *mis, int migrate_send_rp_req_pages(MigrationIncomingState *mis, RAMBlock *rb, ram_addr_t start, uint64_t had= dr) { - void *aligned =3D (void *)(uintptr_t)(haddr & (-qemu_ram_pagesize(rb))= ); + void *aligned =3D (void *)QEMU_ALIGN_DOWN(haddr, qemu_ram_pagesize(rb)= ); bool received =3D false; =20 WITH_QEMU_LOCK_GUARD(&mis->page_request_mutex) { @@ -2619,8 +2619,8 @@ static void migrate_handle_rp_req_pages(MigrationStat= e *ms, const char* rbname, * Since we currently insist on matching page sizes, just sanity check * we're being asked for whole host pages. */ - if (start & (our_host_ps - 1) || - (len & (our_host_ps - 1))) { + if (!QEMU_IS_ALIGNED(start, our_host_ps) || + !QEMU_IS_ALIGNED(len, our_host_ps)) { error_report("%s: Misaligned page request, start: " RAM_ADDR_FMT " len: %zd", __func__, start, len); mark_source_rp_bad(ms); diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index 39e3e057b4..3f0a1f7aa6 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -402,7 +402,7 @@ bool postcopy_ram_supported_by_host(MigrationIncomingSt= ate *mis) strerror(errno)); goto out; } - g_assert(((size_t)testarea & (pagesize - 1)) =3D=3D 0); + g_assert(QEMU_PTR_IS_ALIGNED(testarea, pagesize)); =20 reg_struct.range.start =3D (uintptr_t)testarea; reg_struct.range.len =3D pagesize; @@ -660,7 +660,7 @@ int postcopy_wake_shared(struct PostCopyFD *pcfd, struct uffdio_range range; int ret; trace_postcopy_wake_shared(client_addr, qemu_ram_get_idstr(rb)); - range.start =3D client_addr & ~(pagesize - 1); + range.start =3D QEMU_ALIGN_DOWN(client_addr, pagesize); range.len =3D pagesize; ret =3D ioctl(pcfd->fd, UFFDIO_WAKE, &range); if (ret) { @@ -702,8 +702,7 @@ static int postcopy_request_page(MigrationIncomingState= *mis, RAMBlock *rb, int postcopy_request_shared_page(struct PostCopyFD *pcfd, RAMBlock *rb, uint64_t client_addr, uint64_t rb_offset) { - size_t pagesize =3D qemu_ram_pagesize(rb); - uint64_t aligned_rbo =3D rb_offset & ~(pagesize - 1); + uint64_t aligned_rbo =3D QEMU_ALIGN_DOWN(rb_offset, qemu_ram_pagesize(= rb)); MigrationIncomingState *mis =3D migration_incoming_get_current(); =20 trace_postcopy_request_shared_page(pcfd->idstr, qemu_ram_get_idstr(rb), @@ -993,7 +992,7 @@ static void *postcopy_ram_fault_thread(void *opaque) break; } =20 - rb_offset &=3D ~(qemu_ram_pagesize(rb) - 1); + rb_offset =3D QEMU_ALIGN_DOWN(rb_offset, qemu_ram_pagesize(rb)= ); trace_postcopy_ram_fault_thread_request(msg.arg.pagefault.addr= ess, qemu_ram_get_idstr(rb), rb_offset, diff --git a/migration/ram.c b/migration/ram.c index e8abe10ddb..e1c158dc92 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -811,7 +811,7 @@ static void migration_clear_memory_region_dirty_bitmap(= RAMBlock *rb, assert(shift >=3D 6); =20 size =3D 1ULL << (TARGET_PAGE_BITS + shift); - start =3D (((ram_addr_t)page) << TARGET_PAGE_BITS) & (-size); + start =3D QEMU_ALIGN_DOWN((ram_addr_t)page << TARGET_PAGE_BITS, size); trace_migration_bitmap_clear_dirty(rb->idstr, start, size, page); memory_region_clear_dirty_bitmap(rb->mr, start, size); } --=20 2.31.1