From patchwork Tue Apr 12 11:55:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 8809711 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id ADF3B9F39A for ; Tue, 12 Apr 2016 11:56:11 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1443C2035B for ; Tue, 12 Apr 2016 11:56:11 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6C3DA20148 for ; Tue, 12 Apr 2016 11:56:10 +0000 (UTC) Received: from localhost ([::1]:47877 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1apwvR-0004jY-2N for patchwork-qemu-devel@patchwork.kernel.org; Tue, 12 Apr 2016 07:56:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51343) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1apwv7-0004cs-OL for qemu-devel@nongnu.org; Tue, 12 Apr 2016 07:55:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1apwv6-0008Oo-DW for qemu-devel@nongnu.org; Tue, 12 Apr 2016 07:55:49 -0400 Received: from mail-qk0-x235.google.com ([2607:f8b0:400d:c09::235]:33803) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1apwv6-0008Oc-7B for qemu-devel@nongnu.org; Tue, 12 Apr 2016 07:55:48 -0400 Received: by mail-qk0-x235.google.com with SMTP id r184so4907562qkc.1 for ; Tue, 12 Apr 2016 04:55:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ChaOIzA/GRRmRC2fMtYO1ll0MZB7OQ37SjQVVYHFiXU=; b=pPeotuRbMX37BscKYZVQO3UD6txGRdXqxQ5QGxnN+2znH5uOJv/Qn7vT4L8x6dju5m 7kbA3h+TCrF4fJbqzFTFDwXOE4Fn+xR6ztfshIZcuGsbdAPvpO5drUNddBmrTKuFogVU YrXKx5/Xqab62ertm2f6w6FmzvY+y1Um5XeRIVAX+xzSmgoRphGQIygi+TpBndPafMx+ 86GzjmlBINpj0Xv30MG4/u8fDjmu+/wWswUgessPDF3vJGtY31g5cdOG23KXUP12Fg3n P4vbPcu0NEYwoVPjvr46Y8I9+f8TkcXDbs6onww2QLUFhT8+t7zqrgCZ++f9JOXPsQT+ r0mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=ChaOIzA/GRRmRC2fMtYO1ll0MZB7OQ37SjQVVYHFiXU=; b=fj9vpepIe3ErQE6KAY+BAFRGCNjJqK5hAP0T59rWeDcrmyQF5HvehUpvTPfOPgMGWL cCmmL4JlbujsMpR1hcgFdWl+k/7walm/9nhzYJ0fJpnnE1AlB9RmJn2y7rPT8Cl6NBZh W63z8lLK6h3lJtZG0Bazke2+SsqyMXPaHr+10pQUXUJsxNQFl+OIY/wxfTnriM4mp1rs qNLcQ4g6sXIZDzXHu01/SwKh5tD9C91KJTRRQ7uSno3Q5eLY2jAAM3eYtkmaqWDsjmpk H3mpn30GJbV+oN7TGTZ1O66y81KtinZxmtBtxOFKd8no+UCUNQVW6m/GhiEp1qb9enzh gvXg== X-Gm-Message-State: AOPr4FW1xvATW3FLprVveb8M7XKr2YUx0cS/uusIMsIfGQ/AaN2PACvxY/x4VOGtc3y7EQ== X-Received: by 10.55.117.10 with SMTP id q10mr2734225qkc.103.1460462147504; Tue, 12 Apr 2016 04:55:47 -0700 (PDT) Received: from localhost (bne75-h02-31-39-163-232.dsl.sta.abo.bbox.fr. [31.39.163.232]) by smtp.gmail.com with ESMTPSA id 2sm13395395qgi.33.2016.04.12.04.55.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Apr 2016 04:55:46 -0700 (PDT) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Date: Tue, 12 Apr 2016 13:55:25 +0200 Message-Id: <1460462129-17363-6-git-send-email-marcandre.lureau@redhat.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1460462129-17363-1-git-send-email-marcandre.lureau@redhat.com> References: <1460462129-17363-1-git-send-email-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400d:c09::235 Subject: [Qemu-devel] [PATCH 5/9] RFC: ivshmem: use 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: pbonzini@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Marc-André Lureau Instead of writing our own mmap handling code, reuse the code from exec.c. RFC because memory_region_init_ram_from_fd() adds some restrictions (check for xen, kvm sync-mmu, etc) and changes (such as size alignment). In practice, this doesn't seem to hurt though. Signed-off-by: Marc-André Lureau --- hw/misc/ivshmem.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c index 2eb8668..08bf5c6 100644 --- a/hw/misc/ivshmem.c +++ b/hw/misc/ivshmem.c @@ -494,9 +494,9 @@ static void setup_interrupt(IVShmemState *s, int vector, Error **errp) static void process_msg_shmem(IVShmemState *s, int fd, Error **errp) { + Error *err = NULL; struct stat buf; size_t size; - void *ptr; if (s->ivshmem_bar2) { error_setg(errp, "server sent unexpected shared memory message"); @@ -525,15 +525,12 @@ static void process_msg_shmem(IVShmemState *s, int fd, Error **errp) } /* mmap the region and map into the BAR2 */ - ptr = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); - if (ptr == MAP_FAILED) { - error_setg_errno(errp, errno, "Failed to mmap shared memory"); - close(fd); + memory_region_init_ram_from_fd(&s->server_bar2, OBJECT(s), + "ivshmem.bar2", size, true, fd, &err); + if (err) { + error_propagate(errp, err); return; } - memory_region_init_ram_ptr(&s->server_bar2, OBJECT(s), - "ivshmem.bar2", size, ptr); - qemu_set_ram_fd(memory_region_get_ram_addr(&s->server_bar2), fd); s->ivshmem_bar2 = &s->server_bar2; }