From nobody Wed Nov 5 14:35:45 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.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 [208.118.235.17]) by mx.zohomail.com with SMTPS id 153487508244789.90615989282423; Tue, 21 Aug 2018 11:11:22 -0700 (PDT) Received: from localhost ([::1]:55324 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fsB7h-0004sw-8H for importer@patchew.org; Tue, 21 Aug 2018 14:11:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33969) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fsA4y-0002SZ-50 for qemu-devel@nongnu.org; Tue, 21 Aug 2018 13:04:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fsA4p-0007EP-1W for qemu-devel@nongnu.org; Tue, 21 Aug 2018 13:04:25 -0400 Received: from mail-wm0-x232.google.com ([2a00:1450:400c:c09::232]:51295) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fsA4o-0006yW-Lh for qemu-devel@nongnu.org; Tue, 21 Aug 2018 13:04:18 -0400 Received: by mail-wm0-x232.google.com with SMTP id y2-v6so3645367wma.1 for ; Tue, 21 Aug 2018 10:04:07 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-184-244.clienti.tiscali.it. [78.12.184.244]) by smtp.gmail.com with ESMTPSA id v6-v6sm2608955wmc.43.2018.08.21.10.04.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Aug 2018 10:04:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=7m8cigBDEuBZgo1LOtio9vHXPS5Ch1iISu9Ukyh74+o=; b=l3pMWE+LiFXDPo6/IYdXylJHBDdhfEUqOavUj3qmfnUF+vxnGtOcpxG3k/wv380OyJ xn/ji7scy2mTK+ihyIr5tcz1rnpCKmFCrS2kZDIiu0YI4etmyJRa4M+beWal8ER6+QJ5 Cix/W0ThaYVeueo6B7A7/++/hp5q3m4a3NvFqSxOsR0bzJ6QgfFC9wouuIor3BrNS9jM ksIC+LZ57AkmgnfJIdtcTkto8JDI825Nk7c9Ol9TS9bWt1XKJHEASSqo2Xb++I7fYrVP 1947asnkthGmXYmdW103YGBqS7s28eu042//gQstW+veCUx9VhHMPpPaP/QTWWD380B4 vacw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=7m8cigBDEuBZgo1LOtio9vHXPS5Ch1iISu9Ukyh74+o=; b=D1d6JH4VJBC8eMpebf7o1XtknX7/TZoLkGmzJa0CwiWAb0GARNZ3DGZYE8W/IBhs1P /KF02gs1N+jlZvSNxijQwBAs+hjMjDtnKKRsvR70kYGp0xQKQMMkSJ54Zpq73V8VcZV5 /Bosrljt3saSMj2Hq/FQ0kLxM4I0QkEaJn49DKbc4NKWHF4KjpxrHn+zvygyfIG/4ACU Of+GyeSTR72qkFF8VBIscUdB2E1MO6NGmD4BE93jveBY18VDMTvdiaktT9K6zPpoRFxa ugCdXX02QRMe8APv00vtjkaPfV+0qPx8akVrpKIcVlOxXEZqKaRlGYcs+kd4zqIhbGYF 2tGg== X-Gm-Message-State: APzg51A7SO68SstWNtOyqp7xTIbc7ZZEnQ826p9OENhhdc+U1eEE/9cg x68adhQ6OKdYJYYcR0eCtyIdw4xK X-Google-Smtp-Source: ANB0Vda5STsmqDtAz4xv0W3tXZdgKYIhNEuMsD/N55+rhssWsmvK53yfo+eIJFz4PY4JqzJ4kgi5Jg== X-Received: by 2002:a1c:2142:: with SMTP id h63-v6mr141171wmh.51.1534871046082; Tue, 21 Aug 2018 10:04:06 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 21 Aug 2018 19:02:31 +0200 Message-Id: <1534870966-9287-60-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1534870966-9287-1-git-send-email-pbonzini@redhat.com> References: <1534870966-9287-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::232 Subject: [Qemu-devel] [PULL 59/74] util/oslib-win32: indicate alignment for qemu_anon_ram_alloc() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: David Hildenbrand Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: David Hildenbrand Let's set the alignment just like for the posix variant. This will implicitly set the alignment of the underlying memory region and therefore make memory_region_get_alignment(mr) return something > 0 for all memory backends applicable to PCDIMM/NVDIMM. The allocation granularity is ususally 64k, while the page size is 4k. The documentation of VirtualAlloc is not really comprehensible in case only MEM_COMMIT is specified without an address. We'll detect the actual values and then go for the bigger one. The expection is, that it will always be 64k aligned. (The assumption is that MEM_COMMIT does an implicit MEM_RESERVE, so the address will always be aligned to the allocation granularity. And the allocation granularity is always bigger than the page size). This will allow us to drop special handling in pc.c for memory_region_get_alignment(mr) =3D=3D 0, as we can then assume that it is always set (and AFAICS >=3D getpagesize()). For pc in pc_memory_plug(), under Windows TARGET_PAGE_SIZE =3D=3D getpagesi= ze(), therefore alignment of DIMMs will not change, and therefore also not the guest physical memory layout. For spapr in spapr_memory_plug(), an alignment of 0 would have been used until now. As QEMU_ALIGN_UP will crash with the alignment being 0, this never worked, so we don't have to care about compatibility handling. Reviewed-by: David Gibson Signed-off-by: David Hildenbrand Message-Id: <20180801133444.11269-3-david@redhat.com> Reviewed-by: Igor Mammedov Signed-off-by: Paolo Bonzini --- util/oslib-win32.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/util/oslib-win32.c b/util/oslib-win32.c index bb5ad28..25dd159 100644 --- a/util/oslib-win32.c +++ b/util/oslib-win32.c @@ -67,15 +67,24 @@ void *qemu_memalign(size_t alignment, size_t size) return qemu_oom_check(qemu_try_memalign(alignment, size)); } =20 +static int get_allocation_granularity(void) +{ + SYSTEM_INFO system_info; + + GetSystemInfo(&system_info); + return system_info.dwAllocationGranularity; +} + void *qemu_anon_ram_alloc(size_t size, uint64_t *align, bool shared) { void *ptr; =20 - /* FIXME: this is not exactly optimal solution since VirtualAlloc - has 64Kb granularity, but at least it guarantees us that the - memory is page aligned. */ ptr =3D VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE); trace_qemu_anon_ram_alloc(size, ptr); + + if (ptr && align) { + *align =3D MAX(get_allocation_granularity(), getpagesize()); + } return ptr; } =20 --=20 1.8.3.1