From nobody Thu Nov 6 08:30:59 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1497524247895301.3739873243235; Thu, 15 Jun 2017 03:57:27 -0700 (PDT) Received: from localhost ([::1]:53143 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dLSSs-00032P-Mf for importer@patchew.org; Thu, 15 Jun 2017 06:57:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40678) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dLSOm-000833-QI for qemu-devel@nongnu.org; Thu, 15 Jun 2017 06:53:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dLSOl-0007Rn-VJ for qemu-devel@nongnu.org; Thu, 15 Jun 2017 06:53:12 -0400 Received: from mail-wr0-x232.google.com ([2a00:1450:400c:c0c::232]:35092) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dLSOl-0007R4-PO for qemu-devel@nongnu.org; Thu, 15 Jun 2017 06:53:11 -0400 Received: by mail-wr0-x232.google.com with SMTP id q97so16311948wrb.2 for ; Thu, 15 Jun 2017 03:53:11 -0700 (PDT) Received: from 640k.lan (94-39-191-51.adsl-ull.clienti.tiscali.it. [94.39.191.51]) by smtp.gmail.com with ESMTPSA id f21sm3258597wra.5.2017.06.15.03.53.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Jun 2017 03:53:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Dyeaiv42aLh2Yw1dPg0cjO/BjMJgakJTmb/Jex2w6Yc=; b=DOFFWRIQXkCOgAB+q7XYvMKj2T+QLVwSlRRhBzUdkX8KT0+Kp4rgLdt/UWaWuOILIl iRfe/MOqK70gtsrv6GDPtHrE3r64v6wcHMZPxAkDPVC3jvGRlmxdQfdVNKBBkXLdXE/W 5cHSqKSuDx0CKY8QhOxFoRqHDkUE0HT71tWhPjD+k5qOR/cq5UmIGKdRHwDTeuVc+3xN hho6Xe3WiUe4tv7avYzfYdD8aeZliCEU3LaiE9H8niLAx8e8EeH8mT3+amfK5pDv4K3S sPUEHElWjPeuEAssgOGUUYCLskwAtQgXYWZ8ZLD3PH0QSLl21W4pTJtmZE4EPwCVR1Ix AfYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=Dyeaiv42aLh2Yw1dPg0cjO/BjMJgakJTmb/Jex2w6Yc=; b=t1+BbRWURcaInZZ3pJtM/bo/kCOlLYQ9lidkuptxecOWuDc8qRq4H5I2fvraxRQv2t TDG5YrvoGyQ5UUCcGn3UI3JQjoFX+pIVME5RodKICGf6G0FhzT3cXN4VToZrh1RNbuBF kYn8ID66Z5O+AUdQ76dIrrCIypz2Ec6NTVwow/dWEu1mRd2/QPoXxhdhEb6tnkU8UG6b 60WDXGE4XSsTptvzErZ5KGH5uBJ3w916a19sqPlxT8vQLBJrLhkIwYVgFreS+WXXNjRu 2fjJH1mP1665re77cBTxz13YpreUKY4lBKD/ji2uOtiGbMrxqtgfHHTXkw3yobltRyX7 kPIg== X-Gm-Message-State: AKS2vOxNBXxDnRbOCmUDX9o4Gmy2uRzIw5zvk41cgCEWjMCRraTycqIO 3RMW5jX9EpOLXz2hdC4= X-Received: by 10.28.113.200 with SMTP id d69mr3199216wmi.106.1497523990396; Thu, 15 Jun 2017 03:53:10 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 15 Jun 2017 12:52:24 +0200 Message-Id: <1497523981-38449-5-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1497523981-38449-1-git-send-email-pbonzini@redhat.com> References: <1497523981-38449-1-git-send-email-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::232 Subject: [Qemu-devel] [PULL 04/41] Add memory_region_init_ram_from_fd() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 From: Marc-Andr=C3=A9 Lureau Add a new function to initialize a RAM memory region with a file descriptor to be mmap-ed. Signed-off-by: Marc-Andr=C3=A9 Lureau Message-Id: <20170602141229.15326-5-marcandre.lureau@redhat.com> Signed-off-by: Paolo Bonzini --- include/exec/memory.h | 20 ++++++++++++++++++++ memory.c | 16 ++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/include/exec/memory.h b/include/exec/memory.h index 80e605a..51a54c9 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -456,6 +456,26 @@ void memory_region_init_ram_from_file(MemoryRegion *mr, bool share, const char *path, Error **errp); + +/** + * memory_region_init_ram_from_fd: Initialize RAM memory region with a + * mmap-ed backend. + * + * @mr: the #MemoryRegion to be initialized. + * @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 + * @fd: the fd to mmap. + * @errp: pointer to Error*, to store an error if it happens. + */ +void memory_region_init_ram_from_fd(MemoryRegion *mr, + struct Object *owner, + const char *name, + uint64_t size, + bool share, + int fd, + Error **errp); #endif =20 /** diff --git a/memory.c b/memory.c index 0ddc4cc..b2ace20 100644 --- a/memory.c +++ b/memory.c @@ -1397,6 +1397,22 @@ void memory_region_init_ram_from_file(MemoryRegion *= mr, mr->ram_block =3D qemu_ram_alloc_from_file(size, mr, share, path, errp= ); mr->dirty_log_mask =3D tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0; } + +void memory_region_init_ram_from_fd(MemoryRegion *mr, + struct Object *owner, + const char *name, + uint64_t size, + bool share, + int fd, + Error **errp) +{ + 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_from_fd(size, mr, share, fd, errp); + mr->dirty_log_mask =3D tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0; +} #endif =20 void memory_region_init_ram_ptr(MemoryRegion *mr, --=20 1.8.3.1