From nobody Mon Feb 9 09:22:39 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 ARC-Seal: i=1; a=rsa-sha256; t=1620647369; cv=none; d=zohomail.com; s=zohoarc; b=l5SxvNP8t6H94x5nB1D4zH/tX83ceXo1PP+HzO4y3BM3bwXHdl/4/do2sfrLfaNb8V7NLsUGgzcmvRkNdmP0nYGlYpiOes7eL3oa9d89gL8GPh/9a2GMtJ1zl0L78rWMX3E0a/HHfFDKVNa8rQ6LNS3ljp/Phll64lazo05Rht4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620647369; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Pg6T/UFb2UD6NVpK1Q/nWln1mtcCS/74JJKpmUMEt6M=; b=GYGS0BLaLGtwEn+IPQ2Z7uNhI6zgTdTMD0weuF+nn3soU7G/axgfzVWhFQQTFdnbgHs8LMlulSKPJ2MBn4tN/61J+8CgQgAIsRiF9zYIIP0FI9FlG3oP0+hzrISfEll2SiW3hO/psRsWW3IroL18fOmf+smqwzpu+2klj3byO+0= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1620647369073688.7985037351799; Mon, 10 May 2021 04:49:29 -0700 (PDT) Received: from localhost ([::1]:55196 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lg4Pf-00005y-Uk for importer@patchew.org; Mon, 10 May 2021 07:49:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57242) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lg4Kc-0000Ol-FK for qemu-devel@nongnu.org; Mon, 10 May 2021 07:44:14 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:55576) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lg4KZ-0003ho-Rl for qemu-devel@nongnu.org; Mon, 10 May 2021 07:44:14 -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-61-NLwSI4yeOXmntF_bJGtLJw-1; Mon, 10 May 2021 07:44:09 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A98CC10066E6 for ; Mon, 10 May 2021 11:44:08 +0000 (UTC) Received: from t480s.redhat.com (ovpn-114-137.ams2.redhat.com [10.36.114.137]) by smtp.corp.redhat.com (Postfix) with ESMTP id 661861037F2C; Mon, 10 May 2021 11:44:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620647051; 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=Pg6T/UFb2UD6NVpK1Q/nWln1mtcCS/74JJKpmUMEt6M=; b=aiiB9F6JmlNdnPu7UKGH+QOkeOGUj+nH9ohbJi81HCUIOfxo4ALIR2q8Fm/vASl2UJ8dwC MJm21iIpjQrJmtvRF9FnaDilmF5og8M1sLtc47Lmov0xs7YJjGSB+uJmDkxSBRU4TbROe2 Tge5UBp7HzCf6fjxeEKR+p/I0i9V030= X-MC-Unique: NLwSI4yeOXmntF_bJGtLJw-1 From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH v8 06/15] softmmu/memory: Pass ram_flags to qemu_ram_alloc() and qemu_ram_alloc_internal() Date: Mon, 10 May 2021 13:43:19 +0200 Message-Id: <20210510114328.21835-7-david@redhat.com> In-Reply-To: <20210510114328.21835-1-david@redhat.com> References: <20210510114328.21835-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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-Type: text/plain; charset="utf-8" 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=216.205.24.124; envelope-from=david@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.698, 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_H4=0.001, RCVD_IN_MSPIKE_WL=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: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , David Hildenbrand Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Let's pass ram_flags to qemu_ram_alloc() and qemu_ram_alloc_internal(), preparing for passing additional flags. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Acked-by: Eduardo Habkost for memory backend and mach= ine core Signed-off-by: David Hildenbrand --- include/exec/ram_addr.h | 2 +- softmmu/memory.c | 4 ++-- softmmu/physmem.c | 29 ++++++++++++----------------- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h index a7e3378340..6d4513f8e2 100644 --- a/include/exec/ram_addr.h +++ b/include/exec/ram_addr.h @@ -122,7 +122,7 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, Memor= yRegion *mr, =20 RAMBlock *qemu_ram_alloc_from_ptr(ram_addr_t size, void *host, MemoryRegion *mr, Error **errp); -RAMBlock *qemu_ram_alloc(ram_addr_t size, bool share, MemoryRegion *mr, +RAMBlock *qemu_ram_alloc(ram_addr_t size, uint32_t ram_flags, MemoryRegion= *mr, Error **errp); RAMBlock *qemu_ram_alloc_resizeable(ram_addr_t size, ram_addr_t max_size, void (*resized)(const char*, diff --git a/softmmu/memory.c b/softmmu/memory.c index 27b17a7c99..172527e89f 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -1546,7 +1546,7 @@ void memory_region_init_ram_flags_nomigrate(MemoryReg= ion *mr, mr->ram =3D true; mr->terminates =3D true; mr->destructor =3D memory_region_destructor_ram; - mr->ram_block =3D qemu_ram_alloc(size, ram_flags & RAM_SHARED, mr, &er= r); + mr->ram_block =3D qemu_ram_alloc(size, ram_flags, mr, &err); if (err) { mr->size =3D int128_zero(); object_unparent(OBJECT(mr)); @@ -1702,7 +1702,7 @@ void memory_region_init_rom_device_nomigrate(MemoryRe= gion *mr, mr->terminates =3D true; mr->rom_device =3D true; mr->destructor =3D memory_region_destructor_ram; - mr->ram_block =3D qemu_ram_alloc(size, false, mr, &err); + mr->ram_block =3D qemu_ram_alloc(size, 0, mr, &err); if (err) { mr->size =3D int128_zero(); object_unparent(OBJECT(mr)); diff --git a/softmmu/physmem.c b/softmmu/physmem.c index 98d41b0138..7fc3151fd2 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -2105,12 +2105,15 @@ RAMBlock *qemu_ram_alloc_internal(ram_addr_t size, = ram_addr_t max_size, void (*resized)(const char*, uint64_t length, void *host), - void *host, bool resizeable, bool share, + void *host, uint32_t ram_flags, MemoryRegion *mr, Error **errp) { RAMBlock *new_block; Error *local_err =3D NULL; =20 + assert((ram_flags & ~(RAM_SHARED | RAM_RESIZEABLE | RAM_PREALLOC)) =3D= =3D 0); + assert(!host ^ (ram_flags & RAM_PREALLOC)); + size =3D HOST_PAGE_ALIGN(size); max_size =3D HOST_PAGE_ALIGN(max_size); new_block =3D g_malloc0(sizeof(*new_block)); @@ -2122,15 +2125,7 @@ RAMBlock *qemu_ram_alloc_internal(ram_addr_t size, r= am_addr_t max_size, new_block->fd =3D -1; new_block->page_size =3D qemu_real_host_page_size; new_block->host =3D host; - if (host) { - new_block->flags |=3D RAM_PREALLOC; - } - if (share) { - new_block->flags |=3D RAM_SHARED; - } - if (resizeable) { - new_block->flags |=3D RAM_RESIZEABLE; - } + new_block->flags =3D ram_flags; ram_block_add(new_block, &local_err); if (local_err) { g_free(new_block); @@ -2143,15 +2138,15 @@ RAMBlock *qemu_ram_alloc_internal(ram_addr_t size, = ram_addr_t max_size, RAMBlock *qemu_ram_alloc_from_ptr(ram_addr_t size, void *host, MemoryRegion *mr, Error **errp) { - return qemu_ram_alloc_internal(size, size, NULL, host, false, - false, mr, errp); + return qemu_ram_alloc_internal(size, size, NULL, host, RAM_PREALLOC, m= r, + errp); } =20 -RAMBlock *qemu_ram_alloc(ram_addr_t size, bool share, +RAMBlock *qemu_ram_alloc(ram_addr_t size, uint32_t ram_flags, MemoryRegion *mr, Error **errp) { - return qemu_ram_alloc_internal(size, size, NULL, NULL, false, - share, mr, errp); + assert((ram_flags & ~RAM_SHARED) =3D=3D 0); + return qemu_ram_alloc_internal(size, size, NULL, NULL, ram_flags, mr, = errp); } =20 RAMBlock *qemu_ram_alloc_resizeable(ram_addr_t size, ram_addr_t maxsz, @@ -2160,8 +2155,8 @@ RAMBlock *qemu_ram_alloc_resizeable(ram_addr_t size, = ram_addr_t maxsz, void *host), MemoryRegion *mr, Error **errp) { - return qemu_ram_alloc_internal(size, maxsz, resized, NULL, true, - false, mr, errp); + return qemu_ram_alloc_internal(size, maxsz, resized, NULL, + RAM_RESIZEABLE, mr, errp); } =20 static void reclaim_ramblock(RAMBlock *block) --=20 2.30.2