From nobody Thu May 16 06:02:26 2024 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=1620647181; cv=none; d=zohomail.com; s=zohoarc; b=iLwtqU6BQwFJFCqkRQiC/xaOntFmAHMxIdj0pAK7evmv+dkmrl9Ntcwf6aoF7oPMb3xePaXY5ka+lFIZOaRGzvC2x+avfdNl8t5kv1fSaR0M9QSTTTuZcIH2sjqN1vMDsgQ80NeZ48pnqVYtEt613SQcmdGSBiuJIJKqbzPyTq4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620647181; 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=s3C1oJzNV471w+Fa7T9SNNHwXhd96D3h4JMmZIiRBt4=; b=QnLUrgROKRHgtLfTHL5vhZFwPLyQsuc070CME+dI+eIjbkO5sTNmmb7rbFUk+sqMv+1WYV3bvS/BnpOd2our4HWaO8SC7UyRTP3/2gwzBCseenZwM0oL+h26rR4Nbr2sEeJSrqfq6B33pa+jxjDl0i/irddjOBT8rLeS5ddwJ5k= 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 1620647181216156.88556192104386; Mon, 10 May 2021 04:46:21 -0700 (PDT) Received: from localhost ([::1]:46468 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lg4Md-0002T5-Rx for importer@patchew.org; Mon, 10 May 2021 07:46:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57172) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lg4KR-0008LB-TF for qemu-devel@nongnu.org; Mon, 10 May 2021 07:44:03 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:23940) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lg4KQ-0003b6-6y for qemu-devel@nongnu.org; Mon, 10 May 2021 07:44:03 -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-316-yqdjSQIrMm6FnJPmn4quPQ-1; Mon, 10 May 2021 07:43:59 -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 ECDAF501E1; Mon, 10 May 2021 11:43:58 +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 875CB1037E80; Mon, 10 May 2021 11:43:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620647041; 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=s3C1oJzNV471w+Fa7T9SNNHwXhd96D3h4JMmZIiRBt4=; b=BHe79VnZY/C0GUkHTFJCOxfMAk74HXHH4ZMIPq3MJ89l9+gEjLJyp6jI068DGj6I6j2AFr fp6ch/LjnIa7/VMll13RwePrxf67RHgvaBpAYr3nHNynLqOCZDLa5D9L4lYqH9WIXgjjKq IvvmC4z0tondU0aEMM+tgOPPIY5jWKU= X-MC-Unique: yqdjSQIrMm6FnJPmn4quPQ-1 From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH v8 01/15] util/mmap-alloc: Factor out calculation of the pagesize for the guard page Date: Mon, 10 May 2021 13:43:14 +0200 Message-Id: <20210510114328.21835-2-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-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: -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: Igor Kotrasinski , Murilo Opsfelder Araujo , Eduardo Habkost , Peter Xu , David Hildenbrand Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Let's factor out calculating the size of the guard page and rename the variable to make it clearer that this pagesize only applies to the guard page. Reviewed-by: Peter Xu Acked-by: Murilo Opsfelder Araujo Acked-by: Eduardo Habkost for memory backend and mach= ine core Cc: Igor Kotrasinski Signed-off-by: David Hildenbrand --- util/mmap-alloc.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c index e6fa8b598b..24854064b4 100644 --- a/util/mmap-alloc.c +++ b/util/mmap-alloc.c @@ -82,6 +82,16 @@ size_t qemu_mempath_getpagesize(const char *mem_path) return qemu_real_host_page_size; } =20 +static inline size_t mmap_guard_pagesize(int fd) +{ +#if defined(__powerpc64__) && defined(__linux__) + /* Mappings in the same segment must share the same page size */ + return qemu_fd_getpagesize(fd); +#else + return qemu_real_host_page_size; +#endif +} + void *qemu_ram_mmap(int fd, size_t size, size_t align, @@ -90,12 +100,12 @@ void *qemu_ram_mmap(int fd, bool is_pmem, off_t map_offset) { + const size_t guard_pagesize =3D mmap_guard_pagesize(fd); int prot; int flags; int map_sync_flags =3D 0; int guardfd; size_t offset; - size_t pagesize; size_t total; void *guardptr; void *ptr; @@ -116,8 +126,7 @@ void *qemu_ram_mmap(int fd, * anonymous memory is OK. */ flags =3D MAP_PRIVATE; - pagesize =3D qemu_fd_getpagesize(fd); - if (fd =3D=3D -1 || pagesize =3D=3D qemu_real_host_page_size) { + if (fd =3D=3D -1 || guard_pagesize =3D=3D qemu_real_host_page_size) { guardfd =3D -1; flags |=3D MAP_ANONYMOUS; } else { @@ -126,7 +135,6 @@ void *qemu_ram_mmap(int fd, } #else guardfd =3D -1; - pagesize =3D qemu_real_host_page_size; flags =3D MAP_PRIVATE | MAP_ANONYMOUS; #endif =20 @@ -138,7 +146,7 @@ void *qemu_ram_mmap(int fd, =20 assert(is_power_of_2(align)); /* Always align to host page size */ - assert(align >=3D pagesize); + assert(align >=3D guard_pagesize); =20 flags =3D MAP_FIXED; flags |=3D fd =3D=3D -1 ? MAP_ANONYMOUS : 0; @@ -193,8 +201,8 @@ void *qemu_ram_mmap(int fd, * a guard page guarding against potential buffer overflows. */ total -=3D offset; - if (total > size + pagesize) { - munmap(ptr + size + pagesize, total - size - pagesize); + if (total > size + guard_pagesize) { + munmap(ptr + size + guard_pagesize, total - size - guard_pagesize); } =20 return ptr; @@ -202,15 +210,8 @@ void *qemu_ram_mmap(int fd, =20 void qemu_ram_munmap(int fd, void *ptr, size_t size) { - size_t pagesize; - if (ptr) { /* Unmap both the RAM block and the guard page */ -#if defined(__powerpc64__) && defined(__linux__) - pagesize =3D qemu_fd_getpagesize(fd); -#else - pagesize =3D qemu_real_host_page_size; -#endif - munmap(ptr, size + pagesize); + munmap(ptr, size + mmap_guard_pagesize(fd)); } } --=20 2.30.2 From nobody Thu May 16 06:02:26 2024 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=1620647190; cv=none; d=zohomail.com; s=zohoarc; b=PCc44CPa6kFoaggRzeOnCuX6fWn1BG6oaERLS7ejRKiXBqBx3/XZ8O0XI9Wia28BJCWcHmkSTg54DBGZFCy97vRqVuqoEWboD/8wJUZjUJlaQfvFtyUIBsni4MOGMNZge9SYstS23ymDlPQQFcg1vqtzKYsurZ1zsyPg2tCuV+Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620647190; 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=eai7+4GQGDdoGCog0eFd9Dn2XiXqHPmulkQvIIf2DEs=; b=LyXjy/sioultodvAaeg2/r9c3UypTO29WdWYG4EsP4Q6cCrOAbp6rugcsLHJ9IyLuEztRXJE6fVWPOePjdBnSquTO+9anxVLNVbi570ANJ0i3dBVLWYtkuEDfa8GaDGDdp6276/lWVTUVTDziMRFnbjyHdxwbSYpaVFstNW3Ef4= 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 1620647190510248.50538463674752; Mon, 10 May 2021 04:46:30 -0700 (PDT) Received: from localhost ([::1]:46878 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lg4Ml-0002jz-3T for importer@patchew.org; Mon, 10 May 2021 07:46:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57184) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lg4KU-0008RS-SI for qemu-devel@nongnu.org; Mon, 10 May 2021 07:44:06 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:20631) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lg4KT-0003d6-2p for qemu-devel@nongnu.org; Mon, 10 May 2021 07:44:06 -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-543-S18V2qtiOE-cbTcUlR5pDQ-1; Mon, 10 May 2021 07:44:02 -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 4EFD1800FF0; Mon, 10 May 2021 11:44:01 +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 72F911037F20; Mon, 10 May 2021 11:43:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620647044; 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=eai7+4GQGDdoGCog0eFd9Dn2XiXqHPmulkQvIIf2DEs=; b=fx7cxpoEfSO03ERSDuQWYXkcGeoYqzOH9e9TUkVKcqau7aWUUNsOYComp9wB+O4Z2kTvR6 N6fzB+suusiQVa7jgRaaYXrJARkh3Gous1icZCOEN+yWD4fx6FTG1uTCuzfq5yQqv9Wa+k 2N2kJeuGO+5b1HVA4ps/Na45x/Mdo9k= X-MC-Unique: S18V2qtiOE-cbTcUlR5pDQ-1 From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH v8 02/15] util/mmap-alloc: Factor out reserving of a memory region to mmap_reserve() Date: Mon, 10 May 2021 13:43:15 +0200 Message-Id: <20210510114328.21835-3-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-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: Eduardo Habkost , David Hildenbrand , Igor Kotrasinski , Richard Henderson , Peter Xu , Murilo Opsfelder Araujo Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" We want to reserve a memory region without actually populating memory. Let's factor that out. Reviewed-by: Igor Kotrasinski Acked-by: Murilo Opsfelder Araujo Reviewed-by: Richard Henderson Reviewed-by: Peter Xu Acked-by: Eduardo Habkost for memory backend and mach= ine core Signed-off-by: David Hildenbrand --- util/mmap-alloc.c | 58 +++++++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c index 24854064b4..223d66219c 100644 --- a/util/mmap-alloc.c +++ b/util/mmap-alloc.c @@ -82,6 +82,38 @@ size_t qemu_mempath_getpagesize(const char *mem_path) return qemu_real_host_page_size; } =20 +/* + * Reserve a new memory region of the requested size to be used for mapping + * from the given fd (if any). + */ +static void *mmap_reserve(size_t size, int fd) +{ + int flags =3D MAP_PRIVATE; + +#if defined(__powerpc64__) && defined(__linux__) + /* + * On ppc64 mappings in the same segment (aka slice) must share the sa= me + * page size. Since we will be re-allocating part of this segment + * from the supplied fd, we should make sure to use the same page size= , to + * this end we mmap the supplied fd. In this case, set MAP_NORESERVE = to + * avoid allocating backing store memory. + * We do this unless we are using the system page size, in which case + * anonymous memory is OK. + */ + if (fd =3D=3D -1 || qemu_fd_getpagesize(fd) =3D=3D qemu_real_host_page= _size) { + fd =3D -1; + flags |=3D MAP_ANONYMOUS; + } else { + flags |=3D MAP_NORESERVE; + } +#else + fd =3D -1; + flags |=3D MAP_ANONYMOUS; +#endif + + return mmap(0, size, PROT_NONE, flags, fd, 0); +} + static inline size_t mmap_guard_pagesize(int fd) { #if defined(__powerpc64__) && defined(__linux__) @@ -104,7 +136,6 @@ void *qemu_ram_mmap(int fd, int prot; int flags; int map_sync_flags =3D 0; - int guardfd; size_t offset; size_t total; void *guardptr; @@ -116,30 +147,7 @@ void *qemu_ram_mmap(int fd, */ total =3D size + align; =20 -#if defined(__powerpc64__) && defined(__linux__) - /* On ppc64 mappings in the same segment (aka slice) must share the sa= me - * page size. Since we will be re-allocating part of this segment - * from the supplied fd, we should make sure to use the same page size= , to - * this end we mmap the supplied fd. In this case, set MAP_NORESERVE = to - * avoid allocating backing store memory. - * We do this unless we are using the system page size, in which case - * anonymous memory is OK. - */ - flags =3D MAP_PRIVATE; - if (fd =3D=3D -1 || guard_pagesize =3D=3D qemu_real_host_page_size) { - guardfd =3D -1; - flags |=3D MAP_ANONYMOUS; - } else { - guardfd =3D fd; - flags |=3D MAP_NORESERVE; - } -#else - guardfd =3D -1; - flags =3D MAP_PRIVATE | MAP_ANONYMOUS; -#endif - - guardptr =3D mmap(0, total, PROT_NONE, flags, guardfd, 0); - + guardptr =3D mmap_reserve(total, fd); if (guardptr =3D=3D MAP_FAILED) { return MAP_FAILED; } --=20 2.30.2 From nobody Thu May 16 06:02:26 2024 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=1620647364; cv=none; d=zohomail.com; s=zohoarc; b=W/jC1Vzl+jHbuOHDIWjJvVJJWftdDHKoMBuUB/gpHxudkKZIBitfnsOwxAy6HOoV4XI+RZvW+zI/Tu29xnmaIuVf4o3K/OCES3cegaATnt6fphkfFClYTVFXECSx3nDYCl49Co98ftK3vtkIG1G5HsQUQIJEoXg36v+uzUqk1xE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620647364; 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=1AuyFLgbrhSLl+Xc/bn3QakF+zY/5tyHpGNlgisVbh8=; b=N0A4Oni2O4x0NeUE2of4R2Qpf60CWoTi5Dtzsr2nZ2RXsrChkP5xJJSlbra+Iu1s7bDajMhOgFptHk+0fDMJqe4qFVpstB9rGIvFNwkqkKEFfnp92G61MnLFSUXdrfb6WGimvYq2Tnk1aU8uHDw4NZmi16K4b81S42XgNyGOSoE= 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 1620647364267112.02758236285285; Mon, 10 May 2021 04:49:24 -0700 (PDT) Received: from localhost ([::1]:54782 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lg4Pb-0008H1-5I for importer@patchew.org; Mon, 10 May 2021 07:49:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57212) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lg4Ka-0000G6-7l for qemu-devel@nongnu.org; Mon, 10 May 2021 07:44:12 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:47787) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lg4KX-0003h2-RD for qemu-devel@nongnu.org; Mon, 10 May 2021 07:44:11 -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-555-0KS_RDyAMbWCxrOyUyL4OA-1; Mon, 10 May 2021 07:44:08 -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 5C24D801817; Mon, 10 May 2021 11:44:03 +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 ACF1F1007606; Mon, 10 May 2021 11:44:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620647049; 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=1AuyFLgbrhSLl+Xc/bn3QakF+zY/5tyHpGNlgisVbh8=; b=ahUNEWGpLxAuhZvdgLlnJGbgvSvXH2w9WHexQhmB65mnAEOQ0BQjv+bAB2421el4i+0txb BFKrtP6pOSR1Qr54rlsLCntfXO4082CEEalIEbm+9ItqcdqkPCB39efvNCTE8UuYZsKlCs kMdpy8sF7ba9syG8KiaFvUo5nCHbvaQ= X-MC-Unique: 0KS_RDyAMbWCxrOyUyL4OA-1 From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH v8 03/15] util/mmap-alloc: Factor out activating of memory to mmap_activate() Date: Mon, 10 May 2021 13:43:16 +0200 Message-Id: <20210510114328.21835-4-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-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: Murilo Opsfelder Araujo , Richard Henderson , Eduardo Habkost , Peter Xu , David Hildenbrand Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" We want to activate memory within a reserved memory region, to make it accessible. Let's factor that out. Reviewed-by: Richard Henderson Acked-by: Murilo Opsfelder Araujo Reviewed-by: Peter Xu Acked-by: Eduardo Habkost for memory backend and mach= ine core Signed-off-by: David Hildenbrand --- util/mmap-alloc.c | 94 +++++++++++++++++++++++++---------------------- 1 file changed, 50 insertions(+), 44 deletions(-) diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c index 223d66219c..0e2bd7bc0e 100644 --- a/util/mmap-alloc.c +++ b/util/mmap-alloc.c @@ -114,6 +114,52 @@ static void *mmap_reserve(size_t size, int fd) return mmap(0, size, PROT_NONE, flags, fd, 0); } =20 +/* + * Activate memory in a reserved region from the given fd (if any), to make + * it accessible. + */ +static void *mmap_activate(void *ptr, size_t size, int fd, bool readonly, + bool shared, bool is_pmem, off_t map_offset) +{ + const int prot =3D PROT_READ | (readonly ? 0 : PROT_WRITE); + int map_sync_flags =3D 0; + int flags =3D MAP_FIXED; + void *activated_ptr; + + flags |=3D fd =3D=3D -1 ? MAP_ANONYMOUS : 0; + flags |=3D shared ? MAP_SHARED : MAP_PRIVATE; + if (shared && is_pmem) { + map_sync_flags =3D MAP_SYNC | MAP_SHARED_VALIDATE; + } + + activated_ptr =3D mmap(ptr, size, prot, flags | map_sync_flags, fd, + map_offset); + if (activated_ptr =3D=3D MAP_FAILED && map_sync_flags) { + if (errno =3D=3D ENOTSUP) { + char *proc_link =3D g_strdup_printf("/proc/self/fd/%d", fd); + char *file_name =3D g_malloc0(PATH_MAX); + int len =3D readlink(proc_link, file_name, PATH_MAX - 1); + + if (len < 0) { + len =3D 0; + } + file_name[len] =3D '\0'; + fprintf(stderr, "Warning: requesting persistence across crashe= s " + "for backend file %s failed. Proceeding without " + "persistence, data might become corrupted in case of h= ost " + "crash.\n", file_name); + g_free(proc_link); + g_free(file_name); + } + /* + * If mmap failed with MAP_SHARED_VALIDATE | MAP_SYNC, we will try + * again without these flags to handle backwards compatibility. + */ + activated_ptr =3D mmap(ptr, size, prot, flags, fd, map_offset); + } + return activated_ptr; +} + static inline size_t mmap_guard_pagesize(int fd) { #if defined(__powerpc64__) && defined(__linux__) @@ -133,13 +179,8 @@ void *qemu_ram_mmap(int fd, off_t map_offset) { const size_t guard_pagesize =3D mmap_guard_pagesize(fd); - int prot; - int flags; - int map_sync_flags =3D 0; - size_t offset; - size_t total; - void *guardptr; - void *ptr; + size_t offset, total; + void *ptr, *guardptr; =20 /* * Note: this always allocates at least one extra page of virtual addr= ess @@ -156,45 +197,10 @@ void *qemu_ram_mmap(int fd, /* Always align to host page size */ assert(align >=3D guard_pagesize); =20 - flags =3D MAP_FIXED; - flags |=3D fd =3D=3D -1 ? MAP_ANONYMOUS : 0; - flags |=3D shared ? MAP_SHARED : MAP_PRIVATE; - if (shared && is_pmem) { - map_sync_flags =3D MAP_SYNC | MAP_SHARED_VALIDATE; - } - offset =3D QEMU_ALIGN_UP((uintptr_t)guardptr, align) - (uintptr_t)guar= dptr; =20 - prot =3D PROT_READ | (readonly ? 0 : PROT_WRITE); - - ptr =3D mmap(guardptr + offset, size, prot, - flags | map_sync_flags, fd, map_offset); - - if (ptr =3D=3D MAP_FAILED && map_sync_flags) { - if (errno =3D=3D ENOTSUP) { - char *proc_link, *file_name; - int len; - proc_link =3D g_strdup_printf("/proc/self/fd/%d", fd); - file_name =3D g_malloc0(PATH_MAX); - len =3D readlink(proc_link, file_name, PATH_MAX - 1); - if (len < 0) { - len =3D 0; - } - file_name[len] =3D '\0'; - fprintf(stderr, "Warning: requesting persistence across crashe= s " - "for backend file %s failed. Proceeding without " - "persistence, data might become corrupted in case of h= ost " - "crash.\n", file_name); - g_free(proc_link); - g_free(file_name); - } - /* - * if map failed with MAP_SHARED_VALIDATE | MAP_SYNC, - * we will remove these flags to handle compatibility. - */ - ptr =3D mmap(guardptr + offset, size, prot, flags, fd, map_offset); - } - + ptr =3D mmap_activate(guardptr + offset, size, fd, readonly, shared, i= s_pmem, + map_offset); if (ptr =3D=3D MAP_FAILED) { munmap(guardptr, total); return MAP_FAILED; --=20 2.30.2 From nobody Thu May 16 06:02:26 2024 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=1620647196; cv=none; d=zohomail.com; s=zohoarc; b=ezlxf51TwNLHVxDQYOZ0W0B5uhfl5/T9oIe/O5HdPb7+lsEwgPCZBA7k+/JtpGYkdcqyOTHEK5fPqITD9mDm675i6eQEmBLKNSPTc/bfWAJmXmiG4K7VsNIxvc1esJzsa69yGgMa9SHZT+sXbMi9kl+32+hpvRElprzFaQRm3FU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620647196; 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=buUe3eaXC3j+5RL9lDMrx2vngFVR1N18ca4zebC123E=; b=fB/xEmQc/w0kiFK6B88MGkkntTux/NzI8qvCm8c/LBpMppr4aUKZvT1jYxrXggrnC5L3R1ojscP8CfAdTzChR2A0kGgZrE38BDxap/u/79Hp/dsq6T9N51Mm09Nqfg1Qe31czEplaDi0ox6Kh7nCfAj6tWxDmBfX3yQO+ro8cA8= 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 1620647196085159.16686733926326; Mon, 10 May 2021 04:46:36 -0700 (PDT) Received: from localhost ([::1]:47332 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lg4Mt-00033m-26 for importer@patchew.org; Mon, 10 May 2021 07:46:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57208) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lg4KZ-0000E5-OJ for qemu-devel@nongnu.org; Mon, 10 May 2021 07:44:11 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:48312) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lg4KX-0003gz-LG for qemu-devel@nongnu.org; Mon, 10 May 2021 07:44:11 -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-575-fT36RbwmMYa1Yy0jhSyXRA-1; Mon, 10 May 2021 07:44:06 -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 4EEC0107ACC7 for ; Mon, 10 May 2021 11:44:05 +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 B8DF31037F20; Mon, 10 May 2021 11:44:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620647049; 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=buUe3eaXC3j+5RL9lDMrx2vngFVR1N18ca4zebC123E=; b=iDam70fawN16Ay0RepyHoB5vvttu0dlYqhcaizM52XBH2mLj8wKmZ4ZMoymbVW14Vkdtgl TGTVFMQ9cecryNfQ+XJHt16UP0HCuZGYYMLH+9fNBVSR3QkPiHs5Lt6xnrbjwlyOJZQgP1 3z8OmtrHVsFtvBTgtW9VOT9cdIheWgc= X-MC-Unique: fT36RbwmMYa1Yy0jhSyXRA-1 From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH v8 04/15] softmmu/memory: Pass ram_flags to qemu_ram_alloc_from_fd() Date: Mon, 10 May 2021 13:43:17 +0200 Message-Id: <20210510114328.21835-5-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 , Peter Xu , 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 in ram flags just like we do with qemu_ram_alloc_from_file(), to clean up and prepare for more flags. Simplify the documentation of passed ram flags: Looking at our documentation of RAM_SHARED and RAM_PMEM is sufficient, no need to be repetitive. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Peter Xu Acked-by: Eduardo Habkost for memory backend and mach= ine core Signed-off-by: David Hildenbrand --- backends/hostmem-memfd.c | 7 ++++--- hw/misc/ivshmem.c | 5 ++--- include/exec/memory.h | 9 +++------ include/exec/ram_addr.h | 6 +----- softmmu/memory.c | 7 +++---- 5 files changed, 13 insertions(+), 21 deletions(-) diff --git a/backends/hostmem-memfd.c b/backends/hostmem-memfd.c index da75e27057..3076da146d 100644 --- a/backends/hostmem-memfd.c +++ b/backends/hostmem-memfd.c @@ -35,6 +35,7 @@ static void memfd_backend_memory_alloc(HostMemoryBackend *backend, Error **errp) { HostMemoryBackendMemfd *m =3D MEMORY_BACKEND_MEMFD(backend); + uint32_t ram_flags; char *name; int fd; =20 @@ -52,9 +53,9 @@ memfd_backend_memory_alloc(HostMemoryBackend *backend, Er= ror **errp) } =20 name =3D host_memory_backend_get_name(backend); - memory_region_init_ram_from_fd(&backend->mr, OBJECT(backend), - name, backend->size, - backend->share, fd, 0, errp); + ram_flags =3D backend->share ? RAM_SHARED : 0; + memory_region_init_ram_from_fd(&backend->mr, OBJECT(backend), name, + backend->size, ram_flags, fd, 0, errp); g_free(name); } =20 diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c index a1fa4878be..1ba4a98377 100644 --- a/hw/misc/ivshmem.c +++ b/hw/misc/ivshmem.c @@ -493,9 +493,8 @@ static void process_msg_shmem(IVShmemState *s, int fd, = Error **errp) size =3D buf.st_size; =20 /* mmap the region and map into the BAR2 */ - memory_region_init_ram_from_fd(&s->server_bar2, OBJECT(s), - "ivshmem.bar2", size, true, fd, 0, - &local_err); + memory_region_init_ram_from_fd(&s->server_bar2, OBJECT(s), "ivshmem.ba= r2", + size, RAM_SHARED, fd, 0, &local_err); if (local_err) { error_propagate(errp, local_err); return; diff --git a/include/exec/memory.h b/include/exec/memory.h index 5728a681b2..8ad280e532 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -991,10 +991,7 @@ void memory_region_init_resizeable_ram(MemoryRegion *m= r, * @size: size of the region. * @align: alignment of the region base address; if 0, the default alignme= nt * (getpagesize()) will be used. - * @ram_flags: Memory region features: - * - RAM_SHARED: memory must be mmaped with the MAP_SHARED flag - * - RAM_PMEM: the memory is persistent memory - * Other bits are ignored now. + * @ram_flags: RamBlock flags. Supported flags: RAM_SHARED, RAM_PMEM. * @path: the path in which to allocate the RAM. * @readonly: true to open @path for reading, false for read/write. * @errp: pointer to Error*, to store an error if it happens. @@ -1020,7 +1017,7 @@ void memory_region_init_ram_from_file(MemoryRegion *m= r, * @owner: the object that tracks the region's reference count * @name: the name of the region. * @size: size of the region. - * @share: %true if memory must be mmaped with the MAP_SHARED flag + * @ram_flags: RamBlock flags. Supported flags: RAM_SHARED, RAM_PMEM. * @fd: the fd to mmap. * @offset: offset within the file referenced by fd * @errp: pointer to Error*, to store an error if it happens. @@ -1032,7 +1029,7 @@ void memory_region_init_ram_from_fd(MemoryRegion *mr, Object *owner, const char *name, uint64_t size, - bool share, + uint32_t ram_flags, int fd, ram_addr_t offset, Error **errp); diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h index 3cb9791df3..a7e3378340 100644 --- a/include/exec/ram_addr.h +++ b/include/exec/ram_addr.h @@ -104,11 +104,7 @@ long qemu_maxrampagesize(void); * Parameters: * @size: the size in bytes of the ram block * @mr: the memory region where the ram block is - * @ram_flags: specify the properties of the ram block, which can be one - * or bit-or of following values - * - RAM_SHARED: mmap the backing file or device with MAP_SHA= RED - * - RAM_PMEM: the backend @mem_path or @fd is persistent mem= ory - * Other bits are ignored. + * @ram_flags: RamBlock flags. Supported flags: RAM_SHARED, RAM_PMEM. * @mem_path or @fd: specify the backing file or device * @readonly: true to open @path for reading, false for read/write. * @errp: pointer to Error*, to store an error if it happens diff --git a/softmmu/memory.c b/softmmu/memory.c index 3bb533c0bc..7501c5e767 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -1609,7 +1609,7 @@ void memory_region_init_ram_from_fd(MemoryRegion *mr, Object *owner, const char *name, uint64_t size, - bool share, + uint32_t ram_flags, int fd, ram_addr_t offset, Error **errp) @@ -1619,9 +1619,8 @@ void memory_region_init_ram_from_fd(MemoryRegion *mr, mr->ram =3D true; mr->terminates =3D true; mr->destructor =3D memory_region_destructor_ram; - mr->ram_block =3D qemu_ram_alloc_from_fd(size, mr, - share ? RAM_SHARED : 0, - fd, offset, false, &err); + mr->ram_block =3D qemu_ram_alloc_from_fd(size, mr, ram_flags, fd, offs= et, + false, &err); if (err) { mr->size =3D int128_zero(); object_unparent(OBJECT(mr)); --=20 2.30.2 From nobody Thu May 16 06:02:26 2024 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=1620647374; cv=none; d=zohomail.com; s=zohoarc; b=J6meRZrAIlZ1knfMFzMortN7orqBlXN23JTNgAYwhveeM5PpBOc+vH1kJFDIx6q1fxGydDjQIwvpNdE9jRDKlh3jGl+Y7dQ1VDKLnUYOlEq3arUsycYYK8CvhzxeBkvBL+CqwC9ns9nDVheXDMia8/l17g+VAY+cUTurhge2oNE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620647374; 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=icjc+emxQgamcTnGwGmD5ldPMwyUSfjztoslpNOGJKk=; b=N2AgOWek9cAs1l1voojQExr9bsjM8YI8v8PnGnrMJyG9wF/Q489otdG0rMyGrarTZon1nK1m4LpYBIABBnfRCruhKHObYpmh/9Jk7yPjHVwbHNV3W5UJITNlhI5rw0IVPyjjQvdTBN80Dxm62vYGT0U3fDet/CQ5TcrB9rKfbsY= 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 1620647374292490.57976051432445; Mon, 10 May 2021 04:49:34 -0700 (PDT) Received: from localhost ([::1]:55754 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lg4Pl-0000V5-5G for importer@patchew.org; Mon, 10 May 2021 07:49:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57230) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lg4Kb-0000Kv-EF for qemu-devel@nongnu.org; Mon, 10 May 2021 07:44:13 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:33813) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lg4KY-0003h6-1i for qemu-devel@nongnu.org; Mon, 10 May 2021 07:44:13 -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-370-yljr25nYNlSy7gi8Vhe3Gw-1; Mon, 10 May 2021 07:44:07 -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 12781107ACC7 for ; Mon, 10 May 2021 11:44:07 +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 AB3821037F20; Mon, 10 May 2021 11:44:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620647049; 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=icjc+emxQgamcTnGwGmD5ldPMwyUSfjztoslpNOGJKk=; b=CCNiGAu5CrdSrGIV17v++bj3NTuwcmtpzoFF6ByUKXKUWgtnhkMQu0GfV7luvUgsRUUDdr GqURMA9kbrteKm8tlcGw/BRBeoGZkmMLuEAdz7qoTELQYPyybIA+lJwrjyXhNNd5FybmaZ rg05zw3tyIWVwwJGes0YfBOOd8YevhA= X-MC-Unique: yljr25nYNlSy7gi8Vhe3Gw-1 From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH v8 05/15] softmmu/memory: Pass ram_flags to memory_region_init_ram_shared_nomigrate() Date: Mon, 10 May 2021 13:43:18 +0200 Message-Id: <20210510114328.21835-6-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=170.10.133.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 , Peter Xu , 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 forward ram_flags instead, renaming memory_region_init_ram_shared_nomigrate() into memory_region_init_ram_flags_nomigrate(). Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Peter Xu Acked-by: Eduardo Habkost for memory backend and mach= ine core Signed-off-by: David Hildenbrand --- backends/hostmem-ram.c | 6 +++-- hw/m68k/next-cube.c | 4 ++-- include/exec/memory.h | 24 +++++++++---------- .../memory-region-housekeeping.cocci | 8 +++---- softmmu/memory.c | 18 +++++++------- 5 files changed, 31 insertions(+), 29 deletions(-) diff --git a/backends/hostmem-ram.c b/backends/hostmem-ram.c index 5cc53e76c9..741e701062 100644 --- a/backends/hostmem-ram.c +++ b/backends/hostmem-ram.c @@ -19,6 +19,7 @@ static void ram_backend_memory_alloc(HostMemoryBackend *backend, Error **errp) { + uint32_t ram_flags; char *name; =20 if (!backend->size) { @@ -27,8 +28,9 @@ ram_backend_memory_alloc(HostMemoryBackend *backend, Erro= r **errp) } =20 name =3D host_memory_backend_get_name(backend); - memory_region_init_ram_shared_nomigrate(&backend->mr, OBJECT(backend),= name, - backend->size, backend->share, errp); + ram_flags =3D backend->share ? RAM_SHARED : 0; + memory_region_init_ram_flags_nomigrate(&backend->mr, OBJECT(backend), = name, + backend->size, ram_flags, errp); g_free(name); } =20 diff --git a/hw/m68k/next-cube.c b/hw/m68k/next-cube.c index de951ffe5d..e0d4a94f9d 100644 --- a/hw/m68k/next-cube.c +++ b/hw/m68k/next-cube.c @@ -984,8 +984,8 @@ static void next_cube_init(MachineState *machine) sysbus_mmio_map(SYS_BUS_DEVICE(pcdev), 1, 0x02100000); =20 /* BMAP memory */ - memory_region_init_ram_shared_nomigrate(bmapm1, NULL, "next.bmapmem", = 64, - true, &error_fatal); + memory_region_init_ram_flags_nomigrate(bmapm1, NULL, "next.bmapmem", 6= 4, + RAM_SHARED, &error_fatal); memory_region_add_subregion(sysmem, 0x020c0000, bmapm1); /* The Rev_2.5_v66.bin firmware accesses it at 0x820c0020, too */ memory_region_init_alias(bmapm2, NULL, "next.bmapmem2", bmapm1, 0x0, 6= 4); diff --git a/include/exec/memory.h b/include/exec/memory.h index 8ad280e532..10179c6695 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -928,27 +928,27 @@ void memory_region_init_ram_nomigrate(MemoryRegion *m= r, Error **errp); =20 /** - * memory_region_init_ram_shared_nomigrate: Initialize RAM memory region. - * Accesses into the region will - * modify memory directly. + * memory_region_init_ram_flags_nomigrate: Initialize RAM memory region. + * Accesses into the region will + * modify memory directly. * * @mr: the #MemoryRegion to be initialized. * @owner: the object that tracks the region's reference count * @name: Region name, becomes part of RAMBlock name used in migration str= eam * must be unique within any device * @size: size of the region. - * @share: allow remapping RAM to different addresses + * @ram_flags: RamBlock flags. Supported flags: RAM_SHARED. * @errp: pointer to Error*, to store an error if it happens. * - * Note that this function is similar to memory_region_init_ram_nomigrate. - * The only difference is part of the RAM region can be remapped. + * Note that this function does not do anything to cause the data in the + * RAM memory region to be migrated; that is the responsibility of the cal= ler. */ -void memory_region_init_ram_shared_nomigrate(MemoryRegion *mr, - Object *owner, - const char *name, - uint64_t size, - bool share, - Error **errp); +void memory_region_init_ram_flags_nomigrate(MemoryRegion *mr, + Object *owner, + const char *name, + uint64_t size, + uint32_t ram_flags, + Error **errp); =20 /** * memory_region_init_resizeable_ram: Initialize memory region with resiz= eable diff --git a/scripts/coccinelle/memory-region-housekeeping.cocci b/scripts/= coccinelle/memory-region-housekeeping.cocci index c768d8140a..29651ebde9 100644 --- a/scripts/coccinelle/memory-region-housekeeping.cocci +++ b/scripts/coccinelle/memory-region-housekeeping.cocci @@ -127,8 +127,8 @@ static void device_fn(DeviceState *dev, ...) - memory_region_init_rom(E1, NULL, E2, E3, E4); + memory_region_init_rom(E1, obj, E2, E3, E4); | -- memory_region_init_ram_shared_nomigrate(E1, NULL, E2, E3, E4, E5); -+ memory_region_init_ram_shared_nomigrate(E1, obj, E2, E3, E4, E5); +- memory_region_init_ram_flags_nomigrate(E1, NULL, E2, E3, E4, E5); ++ memory_region_init_ram_flags_nomigrate(E1, obj, E2, E3, E4, E5); ) ...+> } @@ -152,8 +152,8 @@ static void device_fn(DeviceState *dev, ...) - memory_region_init_rom(E1, NULL, E2, E3, E4); + memory_region_init_rom(E1, OBJECT(dev), E2, E3, E4); | -- memory_region_init_ram_shared_nomigrate(E1, NULL, E2, E3, E4, E5); -+ memory_region_init_ram_shared_nomigrate(E1, OBJECT(dev), E2, E3, E4, E5); +- memory_region_init_ram_flags_nomigrate(E1, NULL, E2, E3, E4, E5); ++ memory_region_init_ram_flags_nomigrate(E1, OBJECT(dev), E2, E3, E4, E5); ) ...+> } diff --git a/softmmu/memory.c b/softmmu/memory.c index 7501c5e767..27b17a7c99 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -1531,22 +1531,22 @@ void memory_region_init_ram_nomigrate(MemoryRegion = *mr, uint64_t size, Error **errp) { - memory_region_init_ram_shared_nomigrate(mr, owner, name, size, false, = errp); + memory_region_init_ram_flags_nomigrate(mr, owner, name, size, 0, errp); } =20 -void memory_region_init_ram_shared_nomigrate(MemoryRegion *mr, - Object *owner, - const char *name, - uint64_t size, - bool share, - Error **errp) +void memory_region_init_ram_flags_nomigrate(MemoryRegion *mr, + Object *owner, + const char *name, + uint64_t size, + uint32_t ram_flags, + Error **errp) { Error *err =3D NULL; memory_region_init(mr, owner, name, size); mr->ram =3D true; mr->terminates =3D true; mr->destructor =3D memory_region_destructor_ram; - mr->ram_block =3D qemu_ram_alloc(size, share, mr, &err); + mr->ram_block =3D qemu_ram_alloc(size, ram_flags & RAM_SHARED, mr, &er= r); if (err) { mr->size =3D int128_zero(); object_unparent(OBJECT(mr)); @@ -1682,7 +1682,7 @@ void memory_region_init_rom_nomigrate(MemoryRegion *m= r, uint64_t size, Error **errp) { - memory_region_init_ram_shared_nomigrate(mr, owner, name, size, false, = errp); + memory_region_init_ram_flags_nomigrate(mr, owner, name, size, 0, errp); mr->readonly =3D true; } =20 --=20 2.30.2 From nobody Thu May 16 06:02:26 2024 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 From nobody Thu May 16 06:02:26 2024 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=1620647488; cv=none; d=zohomail.com; s=zohoarc; b=jh4tHhcLuHjk+LNnIgr2TTaS4qGTFj6Bum/TKJzQ5CuqOSLLnxNv+sgZWDKfpHEW3Ft7sKRfm+B93Gg+t6+2cfZzzGAWPqyXFRHfJH6tYhfEosDhXII/iyI164dLTC+I4hn6IuV8ztwUllA2nG1Oor/k8wqdAopjNtm3SzXw6fw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620647488; 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=nCDi+GsLb2OY0kivT/l1k7sPXbfHbgSt0Qa0PUnPaMY=; b=IJ/ex6s5EFqBPvqWc5KnzZiU3AyShrl+GU7XVNAbhlW060p4PPDZBPpoHRmyHssudSnsBjvg1u8+YF4Vr6l9cGYZ47+0sMlhXmdd+GCbGkzO/o/zuKnUgixHOkMGKkmOXtxTjfsWymhI44Neq0x8t/7gcB0BXHjTxibCbMSg/Lg= 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 1620647488498223.99009964703305; Mon, 10 May 2021 04:51:28 -0700 (PDT) Received: from localhost ([::1]:35008 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lg4Rb-0005ZU-AN for importer@patchew.org; Mon, 10 May 2021 07:51:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57278) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lg4Kg-0000hH-QG for qemu-devel@nongnu.org; Mon, 10 May 2021 07:44:18 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:27807) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lg4Ke-0003kr-NY for qemu-devel@nongnu.org; Mon, 10 May 2021 07:44:18 -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-564-2PL7rzMRPQKe_r_g2dIORg-1; Mon, 10 May 2021 07:44:14 -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 B04488014D8 for ; Mon, 10 May 2021 11:44:13 +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 1393B1007606; Mon, 10 May 2021 11:44:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620647056; 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=nCDi+GsLb2OY0kivT/l1k7sPXbfHbgSt0Qa0PUnPaMY=; b=TQnt/i5RYYywJXLa+JTOHntCW/TpbyvHbwCK0DPuMmtyk4raa89RV5/cNeY3HhRZJ9/k7I 5W3/rUQgYoGpPI5cv0+skCX+/5bx80kHyUHBkKdiDjQ0GXCY04dqTC43tJJ4Yr7WDMk7Q/ PL+07V7ozMHqkAbT9ChyQOR5LkhJOF4= X-MC-Unique: 2PL7rzMRPQKe_r_g2dIORg-1 From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH v8 07/15] util/mmap-alloc: Pass flags instead of separate bools to qemu_ram_mmap() Date: Mon, 10 May 2021 13:43:20 +0200 Message-Id: <20210510114328.21835-8-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=170.10.133.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 , Peter Xu , 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 flags instead of bools to prepare for passing other flags and update the documentation of qemu_ram_mmap(). Introduce new QEMU_MAP_ flags that abstract the mmap() PROT_ and MAP_ flag handling and simplify it. We expose only flags that are currently supported by qemu_ram_mmap(). Maybe, we'll see qemu_mmap() in the future as well that can implement these flags. Note: We don't use MAP_ flags as some flags (e.g., MAP_SYNC) are only defined for some systems and we want to always be able to identify these flags reliably inside qemu_ram_mmap() -- for example, to properly warn when some future flags are not available or effective on a system. Also, this way we can simplify PROT_ handling as well. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Peter Xu Acked-by: Eduardo Habkost for memory backend and mach= ine core Signed-off-by: David Hildenbrand --- include/qemu/mmap-alloc.h | 16 +++++++++------- include/qemu/osdep.h | 18 ++++++++++++++++++ softmmu/physmem.c | 8 +++++--- util/mmap-alloc.c | 15 ++++++++------- util/oslib-posix.c | 3 ++- 5 files changed, 42 insertions(+), 18 deletions(-) diff --git a/include/qemu/mmap-alloc.h b/include/qemu/mmap-alloc.h index 456ff87df1..90d0eee705 100644 --- a/include/qemu/mmap-alloc.h +++ b/include/qemu/mmap-alloc.h @@ -7,18 +7,22 @@ size_t qemu_fd_getpagesize(int fd); size_t qemu_mempath_getpagesize(const char *mem_path); =20 /** - * qemu_ram_mmap: mmap the specified file or device. + * qemu_ram_mmap: mmap anonymous memory, the specified file or device. + * + * mmap() abstraction to map guest RAM, simplifying flag handling, taking + * care of alignment requirements and installing guard pages. * * Parameters: * @fd: the file or the device to mmap * @size: the number of bytes to be mmaped * @align: if not zero, specify the alignment of the starting mapping add= ress; * otherwise, the alignment in use will be determined by QEMU. - * @readonly: true for a read-only mapping, false for read/write. - * @shared: map has RAM_SHARED flag. - * @is_pmem: map has RAM_PMEM flag. + * @qemu_map_flags: QEMU_MAP_* flags * @map_offset: map starts at offset of map_offset from the start of fd * + * Internally, MAP_PRIVATE, MAP_ANONYMOUS and MAP_SHARED_VALIDATE are set + * implicitly based on other parameters. + * * Return: * On success, return a pointer to the mapped area. * On failure, return MAP_FAILED. @@ -26,9 +30,7 @@ size_t qemu_mempath_getpagesize(const char *mem_path); void *qemu_ram_mmap(int fd, size_t size, size_t align, - bool readonly, - bool shared, - bool is_pmem, + uint32_t qemu_map_flags, off_t map_offset); =20 void qemu_ram_munmap(int fd, void *ptr, size_t size); diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index cb2a07e472..a96d6cb7ac 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -366,6 +366,24 @@ void *qemu_anon_ram_alloc(size_t size, uint64_t *align= , bool shared); void qemu_vfree(void *ptr); void qemu_anon_ram_free(void *ptr, size_t size); =20 +/* + * Abstraction of PROT_ and MAP_ flags as passed to mmap(), for example, + * consumed by qemu_ram_mmap(). + */ + +/* Map PROT_READ instead of PROT_READ | PROT_WRITE. */ +#define QEMU_MAP_READONLY (1 << 0) + +/* Use MAP_SHARED instead of MAP_PRIVATE. */ +#define QEMU_MAP_SHARED (1 << 1) + +/* + * Use MAP_SYNC | MAP_SHARED_VALIDATE if supported. Ignored without + * QEMU_MAP_SHARED. If mapping fails, warn and fallback to !QEMU_MAP_SYNC. + */ +#define QEMU_MAP_SYNC (1 << 2) + + #define QEMU_MADV_INVALID -1 =20 #if defined(CONFIG_MADVISE) diff --git a/softmmu/physmem.c b/softmmu/physmem.c index 7fc3151fd2..0138b7c31a 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -1530,6 +1530,7 @@ static void *file_ram_alloc(RAMBlock *block, off_t offset, Error **errp) { + uint32_t qemu_map_flags; void *area; =20 block->page_size =3D qemu_fd_getpagesize(fd); @@ -1577,9 +1578,10 @@ static void *file_ram_alloc(RAMBlock *block, perror("ftruncate"); } =20 - area =3D qemu_ram_mmap(fd, memory, block->mr->align, readonly, - block->flags & RAM_SHARED, block->flags & RAM_PME= M, - offset); + qemu_map_flags =3D readonly ? QEMU_MAP_READONLY : 0; + qemu_map_flags |=3D (block->flags & RAM_SHARED) ? QEMU_MAP_SHARED : 0; + qemu_map_flags |=3D (block->flags & RAM_PMEM) ? QEMU_MAP_SYNC : 0; + area =3D qemu_ram_mmap(fd, memory, block->mr->align, qemu_map_flags, o= ffset); if (area =3D=3D MAP_FAILED) { error_setg_errno(errp, errno, "unable to map backing store for guest RAM"); diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c index 0e2bd7bc0e..1ddc0e2a1e 100644 --- a/util/mmap-alloc.c +++ b/util/mmap-alloc.c @@ -118,9 +118,12 @@ static void *mmap_reserve(size_t size, int fd) * Activate memory in a reserved region from the given fd (if any), to make * it accessible. */ -static void *mmap_activate(void *ptr, size_t size, int fd, bool readonly, - bool shared, bool is_pmem, off_t map_offset) +static void *mmap_activate(void *ptr, size_t size, int fd, + uint32_t qemu_map_flags, off_t map_offset) { + const bool readonly =3D qemu_map_flags & QEMU_MAP_READONLY; + const bool shared =3D qemu_map_flags & QEMU_MAP_SHARED; + const bool sync =3D qemu_map_flags & QEMU_MAP_SYNC; const int prot =3D PROT_READ | (readonly ? 0 : PROT_WRITE); int map_sync_flags =3D 0; int flags =3D MAP_FIXED; @@ -128,7 +131,7 @@ static void *mmap_activate(void *ptr, size_t size, int = fd, bool readonly, =20 flags |=3D fd =3D=3D -1 ? MAP_ANONYMOUS : 0; flags |=3D shared ? MAP_SHARED : MAP_PRIVATE; - if (shared && is_pmem) { + if (shared && sync) { map_sync_flags =3D MAP_SYNC | MAP_SHARED_VALIDATE; } =20 @@ -173,9 +176,7 @@ static inline size_t mmap_guard_pagesize(int fd) void *qemu_ram_mmap(int fd, size_t size, size_t align, - bool readonly, - bool shared, - bool is_pmem, + uint32_t qemu_map_flags, off_t map_offset) { const size_t guard_pagesize =3D mmap_guard_pagesize(fd); @@ -199,7 +200,7 @@ void *qemu_ram_mmap(int fd, =20 offset =3D QEMU_ALIGN_UP((uintptr_t)guardptr, align) - (uintptr_t)guar= dptr; =20 - ptr =3D mmap_activate(guardptr + offset, size, fd, readonly, shared, i= s_pmem, + ptr =3D mmap_activate(guardptr + offset, size, fd, qemu_map_flags, map_offset); if (ptr =3D=3D MAP_FAILED) { munmap(guardptr, total); diff --git a/util/oslib-posix.c b/util/oslib-posix.c index 36820fec16..c12108c6cb 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -229,8 +229,9 @@ void *qemu_memalign(size_t alignment, size_t size) /* alloc shared memory pages */ void *qemu_anon_ram_alloc(size_t size, uint64_t *alignment, bool shared) { + const uint32_t qemu_map_flags =3D shared ? QEMU_MAP_SHARED : 0; size_t align =3D QEMU_VMALLOC_ALIGN; - void *ptr =3D qemu_ram_mmap(-1, size, align, false, shared, false, 0); + void *ptr =3D qemu_ram_mmap(-1, size, align, qemu_map_flags, 0); =20 if (ptr =3D=3D MAP_FAILED) { return NULL; --=20 2.30.2 From nobody Thu May 16 06:02:26 2024 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=1620647593; cv=none; d=zohomail.com; s=zohoarc; b=QLYDTjhu/Pqjy0Zh8li8jrIrqoCzFVBvqYxrovSMviV0zPArTrgxL4yjnVlEOHG7aVuLxrhhnpfsF3fwtBhaNrFMYjRbQE2mhMyy9Rb1rWM3AhlgdWx+AZcXYtWXv1otx9MYx7VwSm53WCEEVN7hYCZox5CK2pyXnQE9JOKQsNM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620647593; 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=Q2F8mEtNzYBTc3ymYIrkQAbL3REHUpl9fC94XbEh4NI=; b=TKaTgj2ffXVbCQJPNCc+v1PTMNUw6QM5XVUVZFTkUm6CHqm4V67b/Y57DNZ/Dd4ycJ7Ms2E5HpVIBGnoy8DygrsFSUx9Bnkbtl0J6fP2MJHawkYx0EH9zYAWO/PdCXMoDvXZNq4QQ8oCtK7mfl3MMof/e6/mIt+AF0S3LVIiC2g= 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 1620647593332138.04213159729693; Mon, 10 May 2021 04:53:13 -0700 (PDT) Received: from localhost ([::1]:41728 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lg4TI-0001gn-9W for importer@patchew.org; Mon, 10 May 2021 07:53:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57308) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lg4Kp-000114-Vp for qemu-devel@nongnu.org; Mon, 10 May 2021 07:44:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:43140) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lg4Kk-0003oO-Co for qemu-devel@nongnu.org; Mon, 10 May 2021 07:44:27 -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-236-kmfSM5InMGWqbDGA1FB3Wg-1; Mon, 10 May 2021 07:44:19 -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 EB38F801B16 for ; Mon, 10 May 2021 11:44:18 +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 094A5100EBAF; Mon, 10 May 2021 11:44:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620647061; 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=Q2F8mEtNzYBTc3ymYIrkQAbL3REHUpl9fC94XbEh4NI=; b=MGO48WP7FrIfcAwNW/GjQwvy29H5Rls5n1rzSABkEJX7s/vNfZoX7Lz2F5xbku+yK47nA7 SRxEepW8Hx2FJiZ1eLy2mK2KPQzPv2ayNv4t+6OpWwm9DFnynaGUsz1PR3q53aKeUv4bcC fhQndEvSk20dhAlgGmcbEfeSM5hbKEU= X-MC-Unique: kmfSM5InMGWqbDGA1FB3Wg-1 From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH v8 08/15] memory: Introduce RAM_NORESERVE and wire it up in qemu_ram_mmap() Date: Mon, 10 May 2021 13:43:21 +0200 Message-Id: <20210510114328.21835-9-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=170.10.133.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 , Peter Xu , 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 introduce RAM_NORESERVE, allowing mmap'ing with MAP_NORESERVE. The new flag has the following semantics: " RAM is mmap-ed with MAP_NORESERVE. When set, reserving swap space (or huge pages if applicable) is skipped: will bail out if not supported. When not set, the OS will do the reservation, if supported for the memory type. " Allow passing it into: - memory_region_init_ram_nomigrate() - memory_region_init_resizeable_ram() - memory_region_init_ram_from_file() ... and teach qemu_ram_mmap() and qemu_anon_ram_alloc() about the flag. Bail out if the flag is not supported, which is the case right now for both, POSIX and win32. We will add Linux support next and allow specifying RAM_NORESERVE via memory backends. The target use case is virtio-mem, which dynamically exposes memory inside a large, sparse memory area to the VM. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Peter Xu Acked-by: Eduardo Habkost for memory backend and mach= ine core Signed-off-by: David Hildenbrand --- include/exec/cpu-common.h | 1 + include/exec/memory.h | 15 ++++++++++++--- include/exec/ram_addr.h | 3 ++- include/qemu/osdep.h | 9 ++++++++- migration/ram.c | 3 +-- softmmu/physmem.c | 15 ++++++++++++--- util/mmap-alloc.c | 7 +++++++ util/oslib-posix.c | 6 ++++-- util/oslib-win32.c | 13 ++++++++++++- 9 files changed, 59 insertions(+), 13 deletions(-) diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h index 5a0a2d93e0..38a47ad4ac 100644 --- a/include/exec/cpu-common.h +++ b/include/exec/cpu-common.h @@ -58,6 +58,7 @@ void *qemu_ram_get_host_addr(RAMBlock *rb); ram_addr_t qemu_ram_get_offset(RAMBlock *rb); ram_addr_t qemu_ram_get_used_length(RAMBlock *rb); bool qemu_ram_is_shared(RAMBlock *rb); +bool qemu_ram_is_noreserve(RAMBlock *rb); bool qemu_ram_is_uf_zeroable(RAMBlock *rb); void qemu_ram_set_uf_zeroable(RAMBlock *rb); bool qemu_ram_is_migratable(RAMBlock *rb); diff --git a/include/exec/memory.h b/include/exec/memory.h index 10179c6695..8d77819bcd 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -155,6 +155,13 @@ typedef struct IOMMUTLBEvent { */ #define RAM_UF_WRITEPROTECT (1 << 6) =20 +/* + * RAM is mmap-ed with MAP_NORESERVE. When set, reserving swap space (or h= uge + * pages if applicable) is skipped: will bail out if not supported. When n= ot + * set, the OS will do the reservation, if supported for the memory type. + */ +#define RAM_NORESERVE (1 << 7) + static inline void iommu_notifier_init(IOMMUNotifier *n, IOMMUNotify fn, IOMMUNotifierFlag flags, hwaddr start, hwaddr end, @@ -937,7 +944,7 @@ void memory_region_init_ram_nomigrate(MemoryRegion *mr, * @name: Region name, becomes part of RAMBlock name used in migration str= eam * must be unique within any device * @size: size of the region. - * @ram_flags: RamBlock flags. Supported flags: RAM_SHARED. + * @ram_flags: RamBlock flags. Supported flags: RAM_SHARED, RAM_NORESERVE. * @errp: pointer to Error*, to store an error if it happens. * * Note that this function does not do anything to cause the data in the @@ -991,7 +998,8 @@ void memory_region_init_resizeable_ram(MemoryRegion *mr, * @size: size of the region. * @align: alignment of the region base address; if 0, the default alignme= nt * (getpagesize()) will be used. - * @ram_flags: RamBlock flags. Supported flags: RAM_SHARED, RAM_PMEM. + * @ram_flags: RamBlock flags. Supported flags: RAM_SHARED, RAM_PMEM, + * RAM_NORESERVE, * @path: the path in which to allocate the RAM. * @readonly: true to open @path for reading, false for read/write. * @errp: pointer to Error*, to store an error if it happens. @@ -1017,7 +1025,8 @@ void memory_region_init_ram_from_file(MemoryRegion *m= r, * @owner: the object that tracks the region's reference count * @name: the name of the region. * @size: size of the region. - * @ram_flags: RamBlock flags. Supported flags: RAM_SHARED, RAM_PMEM. + * @ram_flags: RamBlock flags. Supported flags: RAM_SHARED, RAM_PMEM, + * RAM_NORESERVE. * @fd: the fd to mmap. * @offset: offset within the file referenced by fd * @errp: pointer to Error*, to store an error if it happens. diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h index 6d4513f8e2..551876bed0 100644 --- a/include/exec/ram_addr.h +++ b/include/exec/ram_addr.h @@ -104,7 +104,8 @@ long qemu_maxrampagesize(void); * Parameters: * @size: the size in bytes of the ram block * @mr: the memory region where the ram block is - * @ram_flags: RamBlock flags. Supported flags: RAM_SHARED, RAM_PMEM. + * @ram_flags: RamBlock flags. Supported flags: RAM_SHARED, RAM_PMEM, + * RAM_NORESERVE. * @mem_path or @fd: specify the backing file or device * @readonly: true to open @path for reading, false for read/write. * @errp: pointer to Error*, to store an error if it happens diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index a96d6cb7ac..af65b36698 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -362,7 +362,8 @@ extern "C" { int qemu_daemon(int nochdir, int noclose); void *qemu_try_memalign(size_t alignment, size_t size); void *qemu_memalign(size_t alignment, size_t size); -void *qemu_anon_ram_alloc(size_t size, uint64_t *align, bool shared); +void *qemu_anon_ram_alloc(size_t size, uint64_t *align, bool shared, + bool noreserve); void qemu_vfree(void *ptr); void qemu_anon_ram_free(void *ptr, size_t size); =20 @@ -383,6 +384,12 @@ void qemu_anon_ram_free(void *ptr, size_t size); */ #define QEMU_MAP_SYNC (1 << 2) =20 +/* + * Use MAP_NORESERVE to skip reservation of swap space (or huge pages if + * applicable). Bail out if not supported/effective. + */ +#define QEMU_MAP_NORESERVE (1 << 3) + =20 #define QEMU_MADV_INVALID -1 =20 diff --git a/migration/ram.c b/migration/ram.c index ace8ad431c..daa29b845a 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -3369,8 +3369,7 @@ int colo_init_ram_cache(void) WITH_RCU_READ_LOCK_GUARD() { RAMBLOCK_FOREACH_NOT_IGNORED(block) { block->colo_cache =3D qemu_anon_ram_alloc(block->used_length, - NULL, - false); + NULL, false, false); if (!block->colo_cache) { error_report("%s: Can't alloc memory for COLO cache of blo= ck %s," "size 0x" RAM_ADDR_FMT, __func__, block->idst= r, diff --git a/softmmu/physmem.c b/softmmu/physmem.c index 0138b7c31a..a356c3fc09 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -1581,6 +1581,7 @@ static void *file_ram_alloc(RAMBlock *block, qemu_map_flags =3D readonly ? QEMU_MAP_READONLY : 0; qemu_map_flags |=3D (block->flags & RAM_SHARED) ? QEMU_MAP_SHARED : 0; qemu_map_flags |=3D (block->flags & RAM_PMEM) ? QEMU_MAP_SYNC : 0; + qemu_map_flags |=3D (block->flags & RAM_NORESERVE) ? QEMU_MAP_NORESERV= E : 0; area =3D qemu_ram_mmap(fd, memory, block->mr->align, qemu_map_flags, o= ffset); if (area =3D=3D MAP_FAILED) { error_setg_errno(errp, errno, @@ -1701,6 +1702,11 @@ bool qemu_ram_is_shared(RAMBlock *rb) return rb->flags & RAM_SHARED; } =20 +bool qemu_ram_is_noreserve(RAMBlock *rb) +{ + return rb->flags & RAM_NORESERVE; +} + /* Note: Only set at the start of postcopy */ bool qemu_ram_is_uf_zeroable(RAMBlock *rb) { @@ -1928,6 +1934,7 @@ static void dirty_memory_extend(ram_addr_t old_ram_si= ze, =20 static void ram_block_add(RAMBlock *new_block, Error **errp) { + const bool noreserve =3D qemu_ram_is_noreserve(new_block); const bool shared =3D qemu_ram_is_shared(new_block); RAMBlock *block; RAMBlock *last_block =3D NULL; @@ -1951,7 +1958,7 @@ static void ram_block_add(RAMBlock *new_block, Error = **errp) } else { new_block->host =3D qemu_anon_ram_alloc(new_block->max_length, &new_block->mr->align, - shared); + shared, noreserve); if (!new_block->host) { error_setg_errno(errp, errno, "cannot set up guest memory '%s'", @@ -2022,7 +2029,7 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, Mem= oryRegion *mr, int64_t file_size, file_align; =20 /* Just support these ram flags by now. */ - assert((ram_flags & ~(RAM_SHARED | RAM_PMEM)) =3D=3D 0); + assert((ram_flags & ~(RAM_SHARED | RAM_PMEM | RAM_NORESERVE)) =3D=3D 0= ); =20 if (xen_enabled()) { error_setg(errp, "-mem-path not supported with Xen"); @@ -2114,6 +2121,8 @@ RAMBlock *qemu_ram_alloc_internal(ram_addr_t size, ra= m_addr_t max_size, Error *local_err =3D NULL; =20 assert((ram_flags & ~(RAM_SHARED | RAM_RESIZEABLE | RAM_PREALLOC)) =3D= =3D 0); + assert((ram_flags & ~(RAM_SHARED | RAM_RESIZEABLE | RAM_PREALLOC | + RAM_NORESERVE)) =3D=3D 0); assert(!host ^ (ram_flags & RAM_PREALLOC)); =20 size =3D HOST_PAGE_ALIGN(size); @@ -2147,7 +2156,7 @@ RAMBlock *qemu_ram_alloc_from_ptr(ram_addr_t size, vo= id *host, RAMBlock *qemu_ram_alloc(ram_addr_t size, uint32_t ram_flags, MemoryRegion *mr, Error **errp) { - assert((ram_flags & ~RAM_SHARED) =3D=3D 0); + assert((ram_flags & ~(RAM_SHARED | RAM_NORESERVE)) =3D=3D 0); return qemu_ram_alloc_internal(size, size, NULL, NULL, ram_flags, mr, = errp); } =20 diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c index 1ddc0e2a1e..d0cf4aaee5 100644 --- a/util/mmap-alloc.c +++ b/util/mmap-alloc.c @@ -20,6 +20,7 @@ #include "qemu/osdep.h" #include "qemu/mmap-alloc.h" #include "qemu/host-utils.h" +#include "qemu/error-report.h" =20 #define HUGETLBFS_MAGIC 0x958458f6 =20 @@ -121,6 +122,7 @@ static void *mmap_reserve(size_t size, int fd) static void *mmap_activate(void *ptr, size_t size, int fd, uint32_t qemu_map_flags, off_t map_offset) { + const bool noreserve =3D qemu_map_flags & QEMU_MAP_NORESERVE; const bool readonly =3D qemu_map_flags & QEMU_MAP_READONLY; const bool shared =3D qemu_map_flags & QEMU_MAP_SHARED; const bool sync =3D qemu_map_flags & QEMU_MAP_SYNC; @@ -129,6 +131,11 @@ static void *mmap_activate(void *ptr, size_t size, int= fd, int flags =3D MAP_FIXED; void *activated_ptr; =20 + if (noreserve) { + error_report("Skipping reservation of swap space is not supported"= ); + return MAP_FAILED; + } + flags |=3D fd =3D=3D -1 ? MAP_ANONYMOUS : 0; flags |=3D shared ? MAP_SHARED : MAP_PRIVATE; if (shared && sync) { diff --git a/util/oslib-posix.c b/util/oslib-posix.c index c12108c6cb..5bbdebae0e 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -227,9 +227,11 @@ void *qemu_memalign(size_t alignment, size_t size) } =20 /* alloc shared memory pages */ -void *qemu_anon_ram_alloc(size_t size, uint64_t *alignment, bool shared) +void *qemu_anon_ram_alloc(size_t size, uint64_t *alignment, bool shared, + bool noreserve) { - const uint32_t qemu_map_flags =3D shared ? QEMU_MAP_SHARED : 0; + const uint32_t qemu_map_flags =3D (shared ? QEMU_MAP_SHARED : 0) | + (noreserve ? QEMU_MAP_NORESERVE : 0); size_t align =3D QEMU_VMALLOC_ALIGN; void *ptr =3D qemu_ram_mmap(-1, size, align, qemu_map_flags, 0); =20 diff --git a/util/oslib-win32.c b/util/oslib-win32.c index 1fc42ec0e3..2499a031f3 100644 --- a/util/oslib-win32.c +++ b/util/oslib-win32.c @@ -38,6 +38,7 @@ #include "trace.h" #include "qemu/sockets.h" #include "qemu/cutils.h" +#include "qemu/error-report.h" #include =20 /* this must come after including "trace.h" */ @@ -76,10 +77,20 @@ static int get_allocation_granularity(void) return system_info.dwAllocationGranularity; } =20 -void *qemu_anon_ram_alloc(size_t size, uint64_t *align, bool shared) +void *qemu_anon_ram_alloc(size_t size, uint64_t *align, bool shared, + bool noreserve) { void *ptr; =20 + if (noreserve) { + /* + * We need a MEM_COMMIT before accessing any memory in a MEM_RESER= VE + * area; we cannot easily mimic POSIX MAP_NORESERVE semantics. + */ + error_report("Skipping reservation of swap space is not supported.= "); + return NULL; + } + ptr =3D VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE); trace_qemu_anon_ram_alloc(size, ptr); =20 --=20 2.30.2 From nobody Thu May 16 06:02:26 2024 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=1620647513; cv=none; d=zohomail.com; s=zohoarc; b=Uxn/v4RbF1dVv4D03IRrlHCpw075u11TSIGEP0pIZ+OcDMVJhKY4K+2TefF4jtZqiR/hOkECzkI+K1xDbkXBkvgvKdahlYrXST7T/EFFZQ7WM0k02TIWkf/RiJKuXQJ+s7nxFTPli70CcQLDAbUN4pi1CXwJq+d5shnxvRqNGZQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620647513; 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=Q83OtAetkgZ7UQqRuJxlLuDbdvHopk4FRWRZ1JgAx6A=; b=Ki5mKLkZk4E/0kTIsW48so6iNhVfepec5l860Dn2T2iLyjZ3Wf4pEta/Kc9FZODYsl1BeXLDLST08Wsyp0b4onejuVaew6jxsDnH1V1kPXswzKBO4w7myLEojYWc1J4e3Ae6S/r+N36daa48NI+JwxP/gxK2jT55VB2ioKq1XeE= 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 162064751342559.988094842204305; Mon, 10 May 2021 04:51:53 -0700 (PDT) Received: from localhost ([::1]:35978 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lg4S0-0006D0-2u for importer@patchew.org; Mon, 10 May 2021 07:51:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57318) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lg4Kq-00012h-HA for qemu-devel@nongnu.org; Mon, 10 May 2021 07:44:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:25146) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lg4Km-0003pN-CY for qemu-devel@nongnu.org; Mon, 10 May 2021 07:44:27 -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-346-6_E_XYKuOC-Z6c7XOO91Yw-1; Mon, 10 May 2021 07:44:21 -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 8C27810066E5 for ; Mon, 10 May 2021 11:44:20 +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 434071037F20; Mon, 10 May 2021 11:44:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620647063; 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=Q83OtAetkgZ7UQqRuJxlLuDbdvHopk4FRWRZ1JgAx6A=; b=BzH3WfPUxeShSW3dRBtqao57mNoVjDwAVtYY4R53MVoPzovjfltp/H8cwvb6y65r1tr9f6 kyhBlZUyK25Ly5r8gfrlkck+286btlAQ4wEv4xLw2colkLzX3sUt7rzwn8tH04y6fe5XvI U5HUaZwdNRXA55T9Qm/TkRv4O9GLgnM= X-MC-Unique: 6_E_XYKuOC-Z6c7XOO91Yw-1 From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH v8 09/15] util/mmap-alloc: Support RAM_NORESERVE via MAP_NORESERVE under Linux Date: Mon, 10 May 2021 13:43:22 +0200 Message-Id: <20210510114328.21835-10-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-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: -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: Eduardo Habkost , Peter Xu , David Hildenbrand Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Let's support RAM_NORESERVE via MAP_NORESERVE on Linux. The flag has no effect on most shared mappings - except for hugetlbfs and anonymous memory. Linux man page: "MAP_NORESERVE: Do not reserve swap space for this mapping. When swap space is reserved, one has the guarantee that it is possible to modify the mapping. When swap space is not reserved one might get SIGSEGV upon a write if no physical memory is available. See also the discussion of the file /proc/sys/vm/overcommit_memory in proc(5). In kernels before 2.6, this flag had effect only for private writable mappings." Note that the "guarantee" part is wrong with memory overcommit in Linux. Also, in Linux hugetlbfs is treated differently - we configure reservation of huge pages from the pool, not reservation of swap space (huge pages cannot be swapped). The rough behavior is [1]: a) !Hugetlbfs: 1) Without MAP_NORESERVE *or* with memory overcommit under Linux disabled ("/proc/sys/vm/overcommit_memory =3D=3D 2"), the following accounting/reservation happens: For a file backed map SHARED or READ-only - 0 cost (the file is the map not swap) PRIVATE WRITABLE - size of mapping per instance For an anonymous or /dev/zero map SHARED - size of mapping PRIVATE READ-only - 0 cost (but of little use) PRIVATE WRITABLE - size of mapping per instance 2) With MAP_NORESERVE, no accounting/reservation happens. b) Hugetlbfs: 1) Without MAP_NORESERVE, huge pages are reserved. 2) With MAP_NORESERVE, no huge pages are reserved. Note: With "/proc/sys/vm/overcommit_memory =3D=3D 0", we were already able to configure it for !hugetlbfs globally; this toggle now allows configuring it more fine-grained, not for the whole system. The target use case is virtio-mem, which dynamically exposes memory inside a large, sparse memory area to the VM. [1] https://www.kernel.org/doc/Documentation/vm/overcommit-accounting Reviewed-by: Peter Xu Acked-by: Eduardo Habkost for memory backend and mach= ine core Signed-off-by: David Hildenbrand --- include/qemu/osdep.h | 3 ++ softmmu/physmem.c | 1 + util/mmap-alloc.c | 69 ++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 71 insertions(+), 2 deletions(-) diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index af65b36698..0a7384d15c 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -195,6 +195,9 @@ extern "C" { #ifndef MAP_FIXED_NOREPLACE #define MAP_FIXED_NOREPLACE 0 #endif +#ifndef MAP_NORESERVE +#define MAP_NORESERVE 0 +#endif #ifndef ENOMEDIUM #define ENOMEDIUM ENODEV #endif diff --git a/softmmu/physmem.c b/softmmu/physmem.c index a356c3fc09..a8394acc3a 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -2227,6 +2227,7 @@ void qemu_ram_remap(ram_addr_t addr, ram_addr_t lengt= h) flags =3D MAP_FIXED; flags |=3D block->flags & RAM_SHARED ? MAP_SHARED : MAP_PRIVATE; + flags |=3D block->flags & RAM_NORESERVE ? MAP_NORESERVE : = 0; if (block->fd >=3D 0) { area =3D mmap(vaddr, length, PROT_READ | PROT_WRITE, flags, block->fd, offset); diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c index d0cf4aaee5..838e286ce5 100644 --- a/util/mmap-alloc.c +++ b/util/mmap-alloc.c @@ -20,6 +20,7 @@ #include "qemu/osdep.h" #include "qemu/mmap-alloc.h" #include "qemu/host-utils.h" +#include "qemu/cutils.h" #include "qemu/error-report.h" =20 #define HUGETLBFS_MAGIC 0x958458f6 @@ -83,6 +84,70 @@ size_t qemu_mempath_getpagesize(const char *mem_path) return qemu_real_host_page_size; } =20 +#define OVERCOMMIT_MEMORY_PATH "/proc/sys/vm/overcommit_memory" +static bool map_noreserve_effective(int fd, uint32_t qemu_map_flags) +{ +#if defined(__linux__) + const bool readonly =3D qemu_map_flags & QEMU_MAP_READONLY; + const bool shared =3D qemu_map_flags & QEMU_MAP_SHARED; + gchar *content =3D NULL; + const char *endptr; + unsigned int tmp; + + /* + * hugeltb accounting is different than ordinary swap reservation: + * a) Hugetlb pages from the pool are reserved for both private and + * shared mappings. For shared mappings, all mappers have to specify + * MAP_NORESERVE. + * b) MAP_NORESERVE is not affected by /proc/sys/vm/overcommit_memory. + */ + if (qemu_fd_getpagesize(fd) !=3D qemu_real_host_page_size) { + return true; + } + + /* + * Accountable mappings in the kernel that can be affected by MAP_NORE= SEVE + * are private writable mappings (see mm/mmap.c:accountable_mapping() = in + * Linux). For all shared or readonly mappings, MAP_NORESERVE is always + * implicitly active -- no reservation; this includes shmem. The only + * exception is shared anonymous memory, it is accounted like private + * anonymous memory. + */ + if (readonly || (shared && fd >=3D 0)) { + return true; + } + + /* + * MAP_NORESERVE is globally ignored for applicable !hugetlb mappings = when + * memory overcommit is set to "never". Sparse memory regions aren't r= eally + * possible in this system configuration. + * + * Bail out now instead of silently committing way more memory than + * currently desired by the user. + */ + if (g_file_get_contents(OVERCOMMIT_MEMORY_PATH, &content, NULL, NULL) = && + !qemu_strtoui(content, &endptr, 0, &tmp) && + (!endptr || *endptr =3D=3D '\n')) { + if (tmp =3D=3D 2) { + error_report("Skipping reservation of swap space is not suppor= ted:" + " \"" OVERCOMMIT_MEMORY_PATH "\" is \"2\""); + return false; + } + return true; + } + /* this interface has been around since Linux 2.6 */ + error_report("Skipping reservation of swap space is not supported:" + " Could not read: \"" OVERCOMMIT_MEMORY_PATH "\""); + return false; +#endif + /* + * E.g., FreeBSD used to define MAP_NORESERVE, never implemented it, + * and removed it a while ago. + */ + error_report("Skipping reservation of swap space is not supported"); + return false; +} + /* * Reserve a new memory region of the requested size to be used for mapping * from the given fd (if any). @@ -131,13 +196,13 @@ static void *mmap_activate(void *ptr, size_t size, in= t fd, int flags =3D MAP_FIXED; void *activated_ptr; =20 - if (noreserve) { - error_report("Skipping reservation of swap space is not supported"= ); + if (noreserve && !map_noreserve_effective(fd, qemu_map_flags)) { return MAP_FAILED; } =20 flags |=3D fd =3D=3D -1 ? MAP_ANONYMOUS : 0; flags |=3D shared ? MAP_SHARED : MAP_PRIVATE; + flags |=3D noreserve ? MAP_NORESERVE : 0; if (shared && sync) { map_sync_flags =3D MAP_SYNC | MAP_SHARED_VALIDATE; } --=20 2.30.2 From nobody Thu May 16 06:02:26 2024 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=1620647624; cv=none; d=zohomail.com; s=zohoarc; b=Ti4UrGc/u7EOtwxGjWDdQ57pke7fSh4Yc7K8xEs8pka5kNd0KTH2MqR9QRPQ+SkY4hARLCIVrqC9jwg6+a4SVN6MiMzi6+7TRvrbLe7+T+vQRV+T3P4YE4rYfSEc/F3OAhSYNLCV/5MaM8JkiBV1nMDFBQtK++IOwH6Qq9Z8bNc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620647624; 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=CMizUfsQW5CSIN46y3iyCTj5ZPBVBZSdLlZkE0O60GI=; b=PfB6MkAqRv4WMGAdGgi/mZlAIliBzShC9v71Jm6LmmSUro9Puxt4YqPkf/iNjC7Q/ZejqSmkhPygtdgGO6kWIuS0x+Ua9h0At7o2Oo+xWoQHT8HNLNNQZYKkKeBhlvOMXgMSiEf1lHlnP3ki88SsHISOXTfVHWx9oq8C12GYBPg= 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 1620647624329558.9099913412393; Mon, 10 May 2021 04:53:44 -0700 (PDT) Received: from localhost ([::1]:42218 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lg4Tn-00020x-4D for importer@patchew.org; Mon, 10 May 2021 07:53:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57352) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lg4Ks-00014g-Kb for qemu-devel@nongnu.org; Mon, 10 May 2021 07:44:30 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:34743) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lg4Kp-0003qh-3u for qemu-devel@nongnu.org; Mon, 10 May 2021 07:44:30 -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-445-goEyC9ZhMBO2DWY55D39Xw-1; Mon, 10 May 2021 07:44:23 -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 CB98B107ACCA for ; Mon, 10 May 2021 11:44:22 +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 EA3CA1037F20; Mon, 10 May 2021 11:44:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620647065; 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=CMizUfsQW5CSIN46y3iyCTj5ZPBVBZSdLlZkE0O60GI=; b=SDmM9cNt3amX86ATWtNQGXIABwYezZ1Uk7BdPXMgMD2WHNQ3frSI7ldm9N035rJHc4EdEn pz8OW/FAkEf3WOSy4HT/hRnMzi1MZpk4iXvzoEJl9NJKULlJmHRDQz4iFighmN6w69SV+A yCc6EkBNqE9I3MIQE9VAaq3YdF8Bygs= X-MC-Unique: goEyC9ZhMBO2DWY55D39Xw-1 From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH v8 10/15] hostmem: Wire up RAM_NORESERVE via "reserve" property Date: Mon, 10 May 2021 13:43:23 +0200 Message-Id: <20210510114328.21835-11-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-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, T_FILL_THIS_FORM_SHORT=0.01 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 , David Hildenbrand , Markus Armbruster , Peter Xu , Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Let's provide a way to control the use of RAM_NORESERVE via memory backends using the "reserve" property which defaults to true (old behavior). Only Linux currently supports clearing the flag (and support is checked at runtime, depending on the setting of "/proc/sys/vm/overcommit_memory"). Windows and other POSIX systems will bail out with "reserve=3Dfalse". The target use case is virtio-mem, which dynamically exposes memory inside a large, sparse memory area to the VM. This essentially allows avoiding to set "/proc/sys/vm/overcommit_memory =3D=3D 0") when using virtio-mem and also supporting hugetlbfs in the future. As really only Linux implements RAM_NORESERVE right now, let's expose the property only with CONFIG_LINUX. Setting the property to "false" will then only fail in corner cases -- for example on very old kernels or when memory overcommit was completely disabled by the admin. Reviewed-by: Peter Xu Reviewed-by: Eduardo Habkost Reviewed-by: Markus Armbruster Acked-by: Eduardo Habkost for memory backend and mach= ine core Cc: Markus Armbruster Cc: Eric Blake Cc: Igor Mammedov Signed-off-by: David Hildenbrand --- backends/hostmem-file.c | 11 ++++++----- backends/hostmem-memfd.c | 1 + backends/hostmem-ram.c | 1 + backends/hostmem.c | 36 ++++++++++++++++++++++++++++++++++++ include/sysemu/hostmem.h | 2 +- qapi/qom.json | 10 ++++++++++ 6 files changed, 55 insertions(+), 6 deletions(-) diff --git a/backends/hostmem-file.c b/backends/hostmem-file.c index 9b1b9f0a56..cd038024fa 100644 --- a/backends/hostmem-file.c +++ b/backends/hostmem-file.c @@ -39,6 +39,7 @@ file_backend_memory_alloc(HostMemoryBackend *backend, Err= or **errp) object_get_typename(OBJECT(backend))); #else HostMemoryBackendFile *fb =3D MEMORY_BACKEND_FILE(backend); + uint32_t ram_flags; gchar *name; =20 if (!backend->size) { @@ -51,11 +52,11 @@ file_backend_memory_alloc(HostMemoryBackend *backend, E= rror **errp) } =20 name =3D host_memory_backend_get_name(backend); - memory_region_init_ram_from_file(&backend->mr, OBJECT(backend), - name, - backend->size, fb->align, - (backend->share ? RAM_SHARED : 0) | - (fb->is_pmem ? RAM_PMEM : 0), + ram_flags =3D backend->share ? RAM_SHARED : 0; + ram_flags |=3D backend->reserve ? 0 : RAM_NORESERVE; + ram_flags |=3D fb->is_pmem ? RAM_PMEM : 0; + memory_region_init_ram_from_file(&backend->mr, OBJECT(backend), name, + backend->size, fb->align, ram_flags, fb->mem_path, fb->readonly, errp); g_free(name); #endif diff --git a/backends/hostmem-memfd.c b/backends/hostmem-memfd.c index 3076da146d..3fc85c3db8 100644 --- a/backends/hostmem-memfd.c +++ b/backends/hostmem-memfd.c @@ -54,6 +54,7 @@ memfd_backend_memory_alloc(HostMemoryBackend *backend, Er= ror **errp) =20 name =3D host_memory_backend_get_name(backend); ram_flags =3D backend->share ? RAM_SHARED : 0; + ram_flags |=3D backend->reserve ? 0 : RAM_NORESERVE; memory_region_init_ram_from_fd(&backend->mr, OBJECT(backend), name, backend->size, ram_flags, fd, 0, errp); g_free(name); diff --git a/backends/hostmem-ram.c b/backends/hostmem-ram.c index 741e701062..b8e55cdbd0 100644 --- a/backends/hostmem-ram.c +++ b/backends/hostmem-ram.c @@ -29,6 +29,7 @@ ram_backend_memory_alloc(HostMemoryBackend *backend, Erro= r **errp) =20 name =3D host_memory_backend_get_name(backend); ram_flags =3D backend->share ? RAM_SHARED : 0; + ram_flags |=3D backend->reserve ? 0 : RAM_NORESERVE; memory_region_init_ram_flags_nomigrate(&backend->mr, OBJECT(backend), = name, backend->size, ram_flags, errp); g_free(name); diff --git a/backends/hostmem.c b/backends/hostmem.c index aab3de8408..4c05862ed5 100644 --- a/backends/hostmem.c +++ b/backends/hostmem.c @@ -216,6 +216,11 @@ static void host_memory_backend_set_prealloc(Object *o= bj, bool value, Error *local_err =3D NULL; HostMemoryBackend *backend =3D MEMORY_BACKEND(obj); =20 + if (!backend->reserve && value) { + error_setg(errp, "'prealloc=3Don' and 'reserve=3Doff' are incompat= ible"); + return; + } + if (!host_memory_backend_mr_inited(backend)) { backend->prealloc =3D value; return; @@ -267,6 +272,7 @@ static void host_memory_backend_init(Object *obj) /* TODO: convert access to globals to compat properties */ backend->merge =3D machine_mem_merge(machine); backend->dump =3D machine_dump_guest_core(machine); + backend->reserve =3D true; backend->prealloc_threads =3D 1; } =20 @@ -425,6 +431,30 @@ static void host_memory_backend_set_share(Object *o, b= ool value, Error **errp) backend->share =3D value; } =20 +#ifdef CONFIG_LINUX +static bool host_memory_backend_get_reserve(Object *o, Error **errp) +{ + HostMemoryBackend *backend =3D MEMORY_BACKEND(o); + + return backend->reserve; +} + +static void host_memory_backend_set_reserve(Object *o, bool value, Error *= *errp) +{ + HostMemoryBackend *backend =3D MEMORY_BACKEND(o); + + if (host_memory_backend_mr_inited(backend)) { + error_setg(errp, "cannot change property value"); + return; + } + if (backend->prealloc && !value) { + error_setg(errp, "'prealloc=3Don' and 'reserve=3Doff' are incompat= ible"); + return; + } + backend->reserve =3D value; +} +#endif /* CONFIG_LINUX */ + static bool host_memory_backend_get_use_canonical_path(Object *obj, Error **errp) { @@ -493,6 +523,12 @@ host_memory_backend_class_init(ObjectClass *oc, void *= data) host_memory_backend_get_share, host_memory_backend_set_share); object_class_property_set_description(oc, "share", "Mark the memory as private to QEMU or shared"); +#ifdef CONFIG_LINUX + object_class_property_add_bool(oc, "reserve", + host_memory_backend_get_reserve, host_memory_backend_set_reserve); + object_class_property_set_description(oc, "reserve", + "Reserve swap space (or huge pages) if applicable"); +#endif /* CONFIG_LINUX */ /* * Do not delete/rename option. This option must be considered stable * (as if it didn't have the 'x-' prefix including deprecation period)= as diff --git a/include/sysemu/hostmem.h b/include/sysemu/hostmem.h index df5644723a..9ff5c16963 100644 --- a/include/sysemu/hostmem.h +++ b/include/sysemu/hostmem.h @@ -64,7 +64,7 @@ struct HostMemoryBackend { /* protected */ uint64_t size; bool merge, dump, use_canonical_path; - bool prealloc, is_mapped, share; + bool prealloc, is_mapped, share, reserve; uint32_t prealloc_threads; DECLARE_BITMAP(host_nodes, MAX_NODES + 1); HostMemPolicy policy; diff --git a/qapi/qom.json b/qapi/qom.json index cd0e76d564..7049d85f42 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -545,6 +545,9 @@ # @share: if false, the memory is private to QEMU; if true, it is shared # (default: false) # +# @reserve: if true, reserve swap space (or huge pages) if applicable +# (default: true) (since 6.1) +# # @size: size of the memory region in bytes # # @x-use-canonical-path-for-ramblock-id: if true, the canoncial path is us= ed @@ -556,6 +559,12 @@ # false generally, but true for mac= hine # types <=3D 4.0) # +# Note: prealloc=3Dtrue and reserve=3Dfalse cannot be set at the same time= . With +# reserve=3Dtrue, the behavior depends on the operating system: for = example, +# Linux will not reserve swap space for shared file mappings -- +# "not applicable". In contrast, reserve=3Dfalse will bail out if it= cannot +# be configured accordingly. +# # Since: 2.1 ## { 'struct': 'MemoryBackendProperties', @@ -566,6 +575,7 @@ '*prealloc': 'bool', '*prealloc-threads': 'uint32', '*share': 'bool', + '*reserve': 'bool', 'size': 'size', '*x-use-canonical-path-for-ramblock-id': 'bool' } } =20 --=20 2.30.2 From nobody Thu May 16 06:02:26 2024 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=1620647360; cv=none; d=zohomail.com; s=zohoarc; b=XJRBXpa8oGvg74Zx8yGLvfjSjko/RIK1xfWR+r2A/FKHFBTMz9aAis7A18VvFO86cfFRarytmC+nUSdohD12LzUi3wIt2B36BSR9ZOM6AMlsc/9vDM3HoOdt1hs8aF9jKQg68God/9xYHFmdC14i+seVKPsvRmKDBk7YCRX/ftA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620647360; 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=ZacCp3jZkietsRPTeV5HCeGZSGU00S880UbdMRTwnys=; b=JkAA0PnexJ8Bdy9krd7eaRGscqv5eYk+KqMidfobvFA32N8ZXiQkPEakkyASkRhA8bcxlTMwedjxUE/mSN2sH6iVF09K/oF/teS+cUc/QTEA5IC4yUsCcj+VjSZmf3PZv7+Vfc4racTpnEfECRa8+qjQPceKK9l0B01yw5kah4w= 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 1620647360389367.38219562766096; Mon, 10 May 2021 04:49:20 -0700 (PDT) Received: from localhost ([::1]:54352 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lg4PX-0007xo-8X for importer@patchew.org; Mon, 10 May 2021 07:49:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57372) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lg4Kt-00017L-HE for qemu-devel@nongnu.org; Mon, 10 May 2021 07:44:31 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:46972) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lg4Kq-0003qu-4S for qemu-devel@nongnu.org; Mon, 10 May 2021 07:44:31 -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-120--BsD5EpyMl-i0eKWf-y3eQ-1; Mon, 10 May 2021 07:44:25 -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 EB501802690 for ; Mon, 10 May 2021 11:44:24 +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 338FC1037F20; Mon, 10 May 2021 11:44:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620647067; 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=ZacCp3jZkietsRPTeV5HCeGZSGU00S880UbdMRTwnys=; b=QuQshbUbp5Ia4PoTLYTmNCyt4ZZdYcAMPctAiu56PK6oOq9tc2BoswX2lAmig/ODM8vxJT bS7qybm9n3hMU6EIJsEGeCnmNdQKz5jE/noN2/QMywePXK240UXAMaJroXNMbafCLWpr1I ZA4jmBH7F4MHSovdQF8/oGFQE+yazbs= X-MC-Unique: -BsD5EpyMl-i0eKWf-y3eQ-1 From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH v8 11/15] qmp: Clarify memory backend properties returned via query-memdev Date: Mon, 10 May 2021 13:43:24 +0200 Message-Id: <20210510114328.21835-12-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=170.10.133.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: Eduardo Habkost , David Hildenbrand , Markus Armbruster , Igor Mammedov , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) We return information on the currently configured memory backends and don't configure them, so decribe what the currently set properties express. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Eduardo Habkost Reviewed-by: Markus Armbruster Suggested-by: Markus Armbruster Acked-by: Eduardo Habkost for memory backend and mach= ine core Cc: Eric Blake Cc: Markus Armbruster Cc: Igor Mammedov Signed-off-by: David Hildenbrand --- qapi/machine.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/qapi/machine.json b/qapi/machine.json index 6e90d463fc..758b901185 100644 --- a/qapi/machine.json +++ b/qapi/machine.json @@ -790,11 +790,11 @@ # # @size: memory backend size # -# @merge: enables or disables memory merge support +# @merge: whether memory merge support is enabled # -# @dump: includes memory backend's memory in a core dump or not +# @dump: whether memory backend's memory is included in a core dump # -# @prealloc: enables or disables memory preallocation +# @prealloc: whether memory was preallocated # # @host-nodes: host nodes for its memory policy # --=20 2.30.2 From nobody Thu May 16 06:02:26 2024 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=1620647729; cv=none; d=zohomail.com; s=zohoarc; b=RqwFPvlgZIykVstx6ocgs++hZ9/h5jrvKT1+h0jt3cSkwcJ+/jjFCjDJfp4rq4IRi1J4GS/fd+6Dz1o1CGk+KWHu3nqlvWGf8ya6SSQ1I+qX2+a6MeMuuewekdnTBAtdY3tKhklOfZzJC29pmuZvgHTc11+fR3Mf0HNbpwSHITI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620647729; 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=EZcBREX11EcBhJU/zRoS5Ly0VAJn/b6xYn0UDMt7+fk=; b=mJGbiunUuz/OifsptBezufcZjWQQISHcQgB9dXt4y/czSkavnF8oq8IGug0FEEQd/FfDuHVL6Xs5wM5ZigdK39FaOUxbGcohPIYGU62sdv03ssRI9KG4z+YWVcrR/uVXG/dDwZIYbkX6pu35+EVIf8sOswVDXLi+bBfwDbC3I44= 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 162064772921344.551199069281324; Mon, 10 May 2021 04:55:29 -0700 (PDT) Received: from localhost ([::1]:46356 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lg4VS-0004rT-5p for importer@patchew.org; Mon, 10 May 2021 07:55:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57376) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lg4Ku-0001Ai-5Y for qemu-devel@nongnu.org; Mon, 10 May 2021 07:44:32 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:20502) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lg4Ks-0003sV-Ay for qemu-devel@nongnu.org; Mon, 10 May 2021 07:44:31 -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-339-Mjof7mfaMcSjsJgwHNF3Zw-1; Mon, 10 May 2021 07:44:28 -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 2305A1854E25 for ; Mon, 10 May 2021 11:44:27 +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 5F01D1037F20; Mon, 10 May 2021 11:44:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620647069; 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=EZcBREX11EcBhJU/zRoS5Ly0VAJn/b6xYn0UDMt7+fk=; b=ayz4gvEECdf8/6iVFdYlt1s8OlgTx8TjH96zJxdAgGcF96zpbRiqgztzvD/A7XjYP5SzDx KPYiIsS3sx1Cr2W5kQUZOvWufsGQhIg93h+J7WaNg2lFUk7toUU3rS0ye6WMq3wL8Dx+SD 5TlqZgUrB1A5atZeXJLlxCUOC+L/n/o= X-MC-Unique: Mjof7mfaMcSjsJgwHNF3Zw-1 From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH v8 12/15] qmp: Include "share" property of memory backends Date: Mon, 10 May 2021 13:43:25 +0200 Message-Id: <20210510114328.21835-13-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: Eduardo Habkost , David Hildenbrand , Markus Armbruster , Igor Mammedov , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Let's include the property, which can be helpful when debugging, for example, to spot misuse of MAP_PRIVATE which can result in some ugly corner cases (e.g., double-memory consumption on shmem). Use the same description we also use for describing the property. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Eduardo Habkost Reviewed-by: Markus Armbruster Acked-by: Eduardo Habkost for memory backend and mach= ine core Cc: Eric Blake Cc: Markus Armbruster Cc: Igor Mammedov Signed-off-by: David Hildenbrand --- hw/core/machine-qmp-cmds.c | 1 + qapi/machine.json | 3 +++ 2 files changed, 4 insertions(+) diff --git a/hw/core/machine-qmp-cmds.c b/hw/core/machine-qmp-cmds.c index a36c96608f..a36ceaf4f3 100644 --- a/hw/core/machine-qmp-cmds.c +++ b/hw/core/machine-qmp-cmds.c @@ -172,6 +172,7 @@ static int query_memdev(Object *obj, void *opaque) m->merge =3D object_property_get_bool(obj, "merge", &error_abort); m->dump =3D object_property_get_bool(obj, "dump", &error_abort); m->prealloc =3D object_property_get_bool(obj, "prealloc", &error_a= bort); + m->share =3D object_property_get_bool(obj, "share", &error_abort); m->policy =3D object_property_get_enum(obj, "policy", "HostMemPoli= cy", &error_abort); host_nodes =3D object_property_get_qobject(obj, diff --git a/qapi/machine.json b/qapi/machine.json index 758b901185..32650bfe9e 100644 --- a/qapi/machine.json +++ b/qapi/machine.json @@ -796,6 +796,8 @@ # # @prealloc: whether memory was preallocated # +# @share: whether memory is private to QEMU or shared (since 6.1) +# # @host-nodes: host nodes for its memory policy # # @policy: memory policy of memory backend @@ -809,6 +811,7 @@ 'merge': 'bool', 'dump': 'bool', 'prealloc': 'bool', + 'share': 'bool', 'host-nodes': ['uint16'], 'policy': 'HostMemPolicy' }} =20 --=20 2.30.2 From nobody Thu May 16 06:02:26 2024 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=1620647851; cv=none; d=zohomail.com; s=zohoarc; b=b1p8Kzein2W0/pMyTFFrkNDsBZDOO//cxqAnI7UDkKzCeZOWL4dUC8BlxqJkAZPNXyQPIdoUe9gxO+mTBfEqxA/ZZ8A/j7uJSGnfM8wqyEB9vgrLJO7PeQAFK+/0f8ZTu2j+zgkRz/awbXnF5SdIaCsZdLQeBwdIVMnvHoyJtxs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620647851; 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=20qt2EnzwFpcw01o+wmJhQR2fpMjgJcjeppQq//Cu0U=; b=QX15UI6ks34QqLfeEumW4Dq+asjNvVWA6I8MnZW9nxrc6dv7a8nrEKxGhxigA4zhinnrKlqhJ/B2iMBSItAHTbYMpBVbDIyacloUMjOPcv1u8DRzNtOnaT1hfNEhL5EDp1eFu+zKhNZD8aDHROan1JVfA/BFSIxRavz9JEk03As= 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 1620647851010916.9931984738641; Mon, 10 May 2021 04:57:31 -0700 (PDT) Received: from localhost ([::1]:50490 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lg4XQ-0007ky-BU for importer@patchew.org; Mon, 10 May 2021 07:57:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57388) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lg4Kw-0001KA-Au for qemu-devel@nongnu.org; Mon, 10 May 2021 07:44:34 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:35693) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lg4Ku-0003un-NP for qemu-devel@nongnu.org; Mon, 10 May 2021 07:44:34 -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-36-UAAGzx-HOpq6kZauXh4ZRg-1; Mon, 10 May 2021 07:44:30 -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 97902107ACC7 for ; Mon, 10 May 2021 11:44:29 +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 7D7D91037F20; Mon, 10 May 2021 11:44:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620647072; 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=20qt2EnzwFpcw01o+wmJhQR2fpMjgJcjeppQq//Cu0U=; b=EFSguTo+udWFcW97Iu8JcfVVrwhyLUfBHl2xPbesk8/gOaY+tImPUe6jtea79W+BZOclnD bv5bpLMiNTAVUVhe6SCO1jNPrRFksptmhzSWt6cE6i7YWeW2WW3chlQmPVY/TP+Gq5Oa4Y 9juS52G7+eQev8oJ1DEXtpduGiuAytQ= X-MC-Unique: UAAGzx-HOpq6kZauXh4ZRg-1 From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH v8 13/15] hmp: Print "share" property of memory backends with "info memdev" Date: Mon, 10 May 2021 13:43:26 +0200 Message-Id: <20210510114328.21835-14-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=170.10.133.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: Eduardo Habkost , David Hildenbrand , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , "Dr . David Alan Gilbert" , Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Let's print the property. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Eduardo Habkost Reviewed-by: Markus Armbruster Acked-by: Eduardo Habkost for memory backend and mach= ine core Cc: Markus Armbruster Cc: Eric Blake Cc: Igor Mammedov Signed-off-by: David Hildenbrand --- hw/core/machine-hmp-cmds.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hw/core/machine-hmp-cmds.c b/hw/core/machine-hmp-cmds.c index 58248cffa3..004a92b3d6 100644 --- a/hw/core/machine-hmp-cmds.c +++ b/hw/core/machine-hmp-cmds.c @@ -110,6 +110,8 @@ void hmp_info_memdev(Monitor *mon, const QDict *qdict) m->value->dump ? "true" : "false"); monitor_printf(mon, " prealloc: %s\n", m->value->prealloc ? "true" : "false"); + monitor_printf(mon, " share: %s\n", + m->value->share ? "true" : "false"); monitor_printf(mon, " policy: %s\n", HostMemPolicy_str(m->value->policy)); visit_complete(v, &str); --=20 2.30.2 From nobody Thu May 16 06:02:26 2024 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=1620647483; cv=none; d=zohomail.com; s=zohoarc; b=Ez3O1fqdcnXKTt1NnkhxPcHhZxdZY6Tdi1ylznp0I54oTAhH5MkQKloavBIjEy65CUhtvfSpeFZ35X4stGnpdVpTTSogIEYSrZyMJNTltfZs47dDC+iXLGoT6T5aleIHBGPcINVl1AX/Z84oPgzOm7utHnTrEQYM+rOsnzib85M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620647483; 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=OgD0H0WDIKDVJ5YzHTe0l8wioVl0CiZcYd7oSM9KHO8=; b=Xh5Th9wiVM5NJPLKSafMCwLsaHfsub4xQOPAyP8g+TbvGCnHfJAS/9p9MnQg69cUytlXeArxAM9nDMCsGs/vdMgqDh4nOoDHm9z+s2VkA2+O4BZcTCq6WlS72TGgKiRM0fAr/2YZ5a1Uzs5KRIHzGP5fEbYDGXxrgOwBIfm4Ez8= 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 1620647483724152.32979188308707; Mon, 10 May 2021 04:51:23 -0700 (PDT) Received: from localhost ([::1]:34544 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lg4RW-0005Fs-Fi for importer@patchew.org; Mon, 10 May 2021 07:51:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57422) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lg4L6-0001hd-7A for qemu-devel@nongnu.org; Mon, 10 May 2021 07:44:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:22056) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lg4Kz-0003wn-Qf for qemu-devel@nongnu.org; Mon, 10 May 2021 07:44:44 -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-188-_AOmIdHTMU6iSyWwYclgbg-1; Mon, 10 May 2021 07:44:35 -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 04086801817 for ; Mon, 10 May 2021 11:44:35 +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 E0A98100EBAD; Mon, 10 May 2021 11:44:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620647077; 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=OgD0H0WDIKDVJ5YzHTe0l8wioVl0CiZcYd7oSM9KHO8=; b=UdX32UEiUBeXuCd17Pn8YYcgiHlSesxzxCmwBkr0/5Eriz9t12aqDiDdiJabQrQaFOn451 lrDi0RyQW714+9qgULYOuisrhg1kWgbkPBW7aO1ts9eqChCVSiaqog+WxS3sBNLbE+QVIb BtxN0i9sA9OQqt82B/oDMvjVr2LMDx4= X-MC-Unique: _AOmIdHTMU6iSyWwYclgbg-1 From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH v8 14/15] qmp: Include "reserve" property of memory backends Date: Mon, 10 May 2021 13:43:27 +0200 Message-Id: <20210510114328.21835-15-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=170.10.133.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: Eduardo Habkost , David Hildenbrand , Markus Armbruster , Igor Mammedov , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Let's include the new property. Instead of relying on CONFIG_LINUX, let's try to unconditionally grab the property and treat errors as "does not exist". Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Eduardo Habkost Reviewed-by: Markus Armbruster Acked-by: Eduardo Habkost for memory backend and mach= ine core Cc: Eric Blake Cc: Markus Armbruster Cc: Igor Mammedov Signed-off-by: David Hildenbrand --- hw/core/machine-qmp-cmds.c | 7 +++++++ qapi/machine.json | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/hw/core/machine-qmp-cmds.c b/hw/core/machine-qmp-cmds.c index a36ceaf4f3..216fdfaf3a 100644 --- a/hw/core/machine-qmp-cmds.c +++ b/hw/core/machine-qmp-cmds.c @@ -157,6 +157,7 @@ void qmp_set_numa_node(NumaOptions *cmd, Error **errp) =20 static int query_memdev(Object *obj, void *opaque) { + Error *err =3D NULL; MemdevList **list =3D opaque; Memdev *m; QObject *host_nodes; @@ -173,6 +174,12 @@ static int query_memdev(Object *obj, void *opaque) m->dump =3D object_property_get_bool(obj, "dump", &error_abort); m->prealloc =3D object_property_get_bool(obj, "prealloc", &error_a= bort); m->share =3D object_property_get_bool(obj, "share", &error_abort); + m->reserve =3D object_property_get_bool(obj, "reserve", &err); + if (err) { + error_free_or_abort(&err); + } else { + m->has_reserve =3D true; + } m->policy =3D object_property_get_enum(obj, "policy", "HostMemPoli= cy", &error_abort); host_nodes =3D object_property_get_qobject(obj, diff --git a/qapi/machine.json b/qapi/machine.json index 32650bfe9e..1cfb16e6eb 100644 --- a/qapi/machine.json +++ b/qapi/machine.json @@ -798,6 +798,12 @@ # # @share: whether memory is private to QEMU or shared (since 6.1) # +# @reserve: whether swap space (or huge pages) was reserved if applicable. +# This corresponds to the user configuration and not the actual +# behavior implemented in the OS to perform the reservation. +# For example, Linux will never reserve swap space for shared +# file mappings. (since 6.1) +# # @host-nodes: host nodes for its memory policy # # @policy: memory policy of memory backend @@ -812,6 +818,7 @@ 'dump': 'bool', 'prealloc': 'bool', 'share': 'bool', + '*reserve': 'bool', 'host-nodes': ['uint16'], 'policy': 'HostMemPolicy' }} =20 --=20 2.30.2 From nobody Thu May 16 06:02:26 2024 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=1620647948; cv=none; d=zohomail.com; s=zohoarc; b=MKbOfKDe/3Trq/3fXZObaiFfI6yzZCzEXRWwMVakcTEb8Ivbb4BDusvgbBMV5G295kS9ZvjS8nwYjrGT5jqbKjOrRESzO6MCxDnOJc6G4DFQ5ElYPdL9x39ekN8Wgx7Pw5w6vN9GxQhBsOi+qQeTleqR8GDg9RrnqvmP56kAvDc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620647948; 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=q8FUQuvkBJkZMlXlq4cmeKVMjzCEUMLJpy6YYspqodE=; b=iaQ2KwQfHm4hJy7kp1XlsQewVvdUK8wd/82b6l0ZRxXPN1WxnLQS4G0qtAsykKzHnLV9uU2+GcMKMonL2dNLBsKTZsaUiskVejR8u6etNontULmJQBk6aMvBC50lujn7pe9Jxtp+0vYI7/hkDyTMRbB+afYXi+rQuurqohd6pIA= 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 1620647948712694.4095783580076; Mon, 10 May 2021 04:59:08 -0700 (PDT) Received: from localhost ([::1]:53708 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lg4Z1-0001Xg-Ou for importer@patchew.org; Mon, 10 May 2021 07:59:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57410) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lg4L4-0001ea-K2 for qemu-devel@nongnu.org; Mon, 10 May 2021 07:44:42 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:42944) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lg4L1-0003y4-VC for qemu-devel@nongnu.org; Mon, 10 May 2021 07:44:42 -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-44-7m7XW8b0Pai4-GvWVKj6og-1; Mon, 10 May 2021 07:44:37 -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 27EA41854E25 for ; Mon, 10 May 2021 11:44:37 +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 4D3D0100EBAD; Mon, 10 May 2021 11:44:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620647079; 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=q8FUQuvkBJkZMlXlq4cmeKVMjzCEUMLJpy6YYspqodE=; b=LXLsBL1qisJTVcM72Q7ZAaH8vowfqcqyC3gMAIKQ6DfrwaAByU36ijeoDulERKe5ZKO0/t HCkNBa4Ozc5KZ86/hVxtPp94UGCeTYxSNiClPUUz4hkFGn5AOjyGMTakW1Z3lJ5A9PiQUf Bcc2k/pIEHCtpMk3v9sfBJ0w/brAQKQ= X-MC-Unique: 7m7XW8b0Pai4-GvWVKj6og-1 From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH v8 15/15] hmp: Print "reserve" property of memory backends with "info memdev" Date: Mon, 10 May 2021 13:43:28 +0200 Message-Id: <20210510114328.21835-16-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=170.10.133.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: Eduardo Habkost , David Hildenbrand , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , "Dr . David Alan Gilbert" , Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Let's print the new property. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Eduardo Habkost Reviewed-by: Markus Armbruster Acked-by: Eduardo Habkost for memory backend and mach= ine core Cc: Markus Armbruster Cc: Eric Blake Cc: Igor Mammedov Signed-off-by: David Hildenbrand --- hw/core/machine-hmp-cmds.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/core/machine-hmp-cmds.c b/hw/core/machine-hmp-cmds.c index 004a92b3d6..76b22b00d6 100644 --- a/hw/core/machine-hmp-cmds.c +++ b/hw/core/machine-hmp-cmds.c @@ -112,6 +112,10 @@ void hmp_info_memdev(Monitor *mon, const QDict *qdict) m->value->prealloc ? "true" : "false"); monitor_printf(mon, " share: %s\n", m->value->share ? "true" : "false"); + if (m->value->has_reserve) { + monitor_printf(mon, " reserve: %s\n", + m->value->reserve ? "true" : "false"); + } monitor_printf(mon, " policy: %s\n", HostMemPolicy_str(m->value->policy)); visit_complete(v, &str); --=20 2.30.2