From patchwork Mon Jan 6 12:22:05 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 307216 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 032C52C00C6 for ; Mon, 6 Jan 2014 23:23:35 +1100 (EST) Received: from localhost ([::1]:34442 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W09DO-0001Cc-RV for incoming@patchwork.ozlabs.org; Mon, 06 Jan 2014 07:23:30 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54225) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W09D0-0001Ba-Px for qemu-devel@nongnu.org; Mon, 06 Jan 2014 07:23:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W09Cv-0002nd-Mq for qemu-devel@nongnu.org; Mon, 06 Jan 2014 07:23:06 -0500 Received: from smtp.citrix.com ([66.165.176.89]:26514) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W09Cv-0002nP-I9 for qemu-devel@nongnu.org; Mon, 06 Jan 2014 07:23:01 -0500 X-IronPort-AV: E=Sophos;i="4.95,612,1384300800"; d="scan'208";a="90036366" Received: from accessns.citrite.net (HELO FTLPEX01CL02.citrite.net) ([10.9.154.239]) by FTLPIPO01.CITRIX.COM with ESMTP; 06 Jan 2014 12:23:00 +0000 Received: from ukmail1.uk.xensource.com (10.80.16.128) by smtprelay.citrix.com (10.13.107.79) with Microsoft SMTP Server id 14.2.342.4; Mon, 6 Jan 2014 07:23:00 -0500 Received: from kaball.uk.xensource.com ([10.80.2.59]) by ukmail1.uk.xensource.com with esmtp (Exim 4.69) (envelope-from ) id 1W09Ct-0004ty-Os; Mon, 06 Jan 2014 12:22:59 +0000 From: Stefano Stabellini To: Date: Mon, 6 Jan 2014 12:22:05 +0000 Message-ID: <1389010925-22832-1-git-send-email-stefano.stabellini@eu.citrix.com> X-Mailer: git-send-email 1.7.9.5 MIME-Version: 1.0 X-DLP: MIA2 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 66.165.176.89 Cc: stefano.stabellini@eu.citrix.com, phcoder@gmail.com, qemu-devel@nongnu.org, Gerd Hoffmann , Anthony Liguori , Paolo Bonzini Subject: [Qemu-devel] [PATCH] xenfb: map framebuffer read-only and handle unmap errors X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The framebuffer is needlessly mapped (PROT_READ | PROT_WRITE), map it PROT_READ instead. The framebuffer is unmapped by replacing the framebuffer pages with anonymous shared memory, calling mmap. Check for return errors and print a warning. Signed-off-by: Stefano Stabellini CC: Gerd Hoffmann CC: Paolo Bonzini CC: Anthony Liguori CC: phcoder@gmail.com diff --git a/hw/display/xenfb.c b/hw/display/xenfb.c index f0333a0..cb9d456 100644 --- a/hw/display/xenfb.c +++ b/hw/display/xenfb.c @@ -495,7 +495,7 @@ static int xenfb_map_fb(struct XenFB *xenfb) munmap(map, n_fbdirs * XC_PAGE_SIZE); xenfb->pixels = xc_map_foreign_pages(xen_xc, xenfb->c.xendev.dom, - PROT_READ | PROT_WRITE, fbmfns, xenfb->fbpages); + PROT_READ, fbmfns, xenfb->fbpages); if (xenfb->pixels == NULL) goto out; @@ -903,6 +903,11 @@ static void fb_disconnect(struct XenDevice *xendev) fb->pixels = mmap(fb->pixels, fb->fbpages * XC_PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); + if (fb->pixels == MAP_FAILED) { + xen_be_printf(xendev, 0, + "Couldn't replace the framebuffer with anonymous memory errno=%d\n", + errno); + } common_unbind(&fb->c); fb->feature_update = 0; fb->bug_trigger = 0;