From nobody Mon Feb 9 12:26:26 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1603192679; cv=none; d=zohomail.com; s=zohoarc; b=NvLOWrprqRJfoz792jG09JEOvloF2c8IGGZC1N7FloNpg3YumhTLxSl6QtwbivJPPro0JombN7RblT5M0uuRfjDY6HMR6If5PqTf9B9cySj+KFdATiI8zYREgJUr6KgfXeBFGhEWm3kccpn58/Nv93+ek2W1RABt4ou+AGfdWgc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603192679; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=oWEbSFnTLkseVlOjOLaK6om3VaPCN0vE+qGHKWT8qrg=; b=AlkahlepE4tBQ6VrlNqXcLqiY1mCBMb+mOhPswNi4GWncD2dgOrvOPZj3ZhlkqqQOf5LD3xNQ/iHvs1eKCqyqDiCd9QiGp46y7+7scTp1o3FL5SyTeXMAFL7H9RO46M0lQ+NM50hrWOf972phoatMG5WMe2pugnj88OcqjsO4rw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1603192679708383.59304979130707; Tue, 20 Oct 2020 04:17:59 -0700 (PDT) Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-305-HI-KEgzBNpe7JMOcBDhPSw-1; Tue, 20 Oct 2020 07:17:57 -0400 Received: by mail-wm1-f69.google.com with SMTP id l22so283943wmi.4 for ; Tue, 20 Oct 2020 04:17:56 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (237.red-88-18-140.staticip.rima-tde.net. [88.18.140.237]) by smtp.gmail.com with ESMTPSA id q8sm2510936wro.32.2020.10.20.04.17.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Oct 2020 04:17:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603192678; 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=oWEbSFnTLkseVlOjOLaK6om3VaPCN0vE+qGHKWT8qrg=; b=YJ1Moud5lXbUvEX4jYpLzQ09/yiqlUN100tGRSBvl3+VBunWi7N6TCvwKpTCeYnBP+3vvb urFzZiymFcBuwaR9T9rgV3IJGRHunzG76XKjMzmh5rWRG0rdonf72+aZTTa6cbuHLahpzg WGUzXPkCP9tVySWE2Cgv9CKNqj4295Q= X-MC-Unique: HI-KEgzBNpe7JMOcBDhPSw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=oWEbSFnTLkseVlOjOLaK6om3VaPCN0vE+qGHKWT8qrg=; b=aXr3vpr2l2w0edDMi28pSGT8l3DFyattvaIOG+pnu9oQsecXtNs9d5FkC5Mv24sFeX DtLiJlqlQz5E325k9CUqJU1IvaSp15DZY1gmqcWHv/dG+wgESTIZF7BQZLHVuZI4IudH jXjXRAizQKeUHrxxFk392dMPOb0I4PGpp7/+e5/9I6jW3obtyHJNLP2M5icKuOwJ1O14 2fBE4jovwrLlx7v099aQI3eE+L0lwGgNxCHe1kcPiZ5dYmzjAQKatspHBkTfNq6z4fJ7 BQJv9Q0hon8nWSESQN4GjONzPoEcO87asOhYoFaZ0qZvwnXkfyyG4crEYPdZU9YrQU0n jQBw== X-Gm-Message-State: AOAM531yunMoJIPX1VGPuy+vtWor8hS245pdjQZllmi1j/2x7KaqSx7C qexlQZMpncpO1NrmuNGgwWMhQYsmXESL5Zaz95zF0AY69l7BBNV6alcMzVG47UTMtn3qMSbLcw8 OuX0sV9V7vLlarQ== X-Received: by 2002:a7b:c3d3:: with SMTP id t19mr710641wmj.139.1603192676015; Tue, 20 Oct 2020 04:17:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzR07YGqsZwzjUp+0JV69TIFhP+WUrJ+X+m+Gq/NfjN6XQhUYHY9OViC5hwKA+osKwlgG7Ulg== X-Received: by 2002:a7b:c3d3:: with SMTP id t19mr710632wmj.139.1603192675868; Tue, 20 Oct 2020 04:17:55 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, Richard Henderson Cc: Paolo Bonzini , Stefan Weil , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v4 2/2] util/oslib: Assert qemu_try_memalign() alignment is a power of 2 Date: Tue, 20 Oct 2020 13:17:43 +0200 Message-Id: <20201020111743.2074694-3-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201020111743.2074694-1-philmd@redhat.com> References: <20201020111743.2074694-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) qemu_try_memalign() expects a power of 2 alignment: - posix_memalign(3): The address of the allocated memory will be a multiple of alignment, which must be a power of two and a multiple of sizeof(void *). - _aligned_malloc() The alignment value, which must be an integer power of 2. Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- util/oslib-posix.c | 3 +++ util/oslib-win32.c | 1 + 2 files changed, 4 insertions(+) diff --git a/util/oslib-posix.c b/util/oslib-posix.c index f15234b5c03..9d6451f9239 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -200,6 +200,9 @@ void *qemu_try_memalign(size_t alignment, size_t size) =20 if (alignment < sizeof(void*)) { alignment =3D sizeof(void*); + } else { + g_assert(QEMU_IS_ALIGNED(alignment, sizeof(void *))); + g_assert(is_power_of_2(alignment)); } =20 #if defined(CONFIG_POSIX_MEMALIGN) diff --git a/util/oslib-win32.c b/util/oslib-win32.c index 29dd05d59d7..72e4ee910ce 100644 --- a/util/oslib-win32.c +++ b/util/oslib-win32.c @@ -58,6 +58,7 @@ void *qemu_try_memalign(size_t alignment, size_t size) void *ptr; =20 g_assert(size !=3D 0); + g_assert(is_power_of_2(alignment)); ptr =3D _aligned_malloc(alignment, size); trace_qemu_memalign(alignment, size, ptr); return ptr; --=20 2.26.2