From patchwork Mon Mar 18 15:45:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 10857913 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 55D6613B5 for ; Mon, 18 Mar 2019 15:47:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3C61D29151 for ; Mon, 18 Mar 2019 15:47:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2F579293BD; Mon, 18 Mar 2019 15:47:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9B30F29151 for ; Mon, 18 Mar 2019 15:47:30 +0000 (UTC) Received: from localhost ([127.0.0.1]:43464 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h5uU4-0003vV-Mi for patchwork-qemu-devel@patchwork.kernel.org; Mon, 18 Mar 2019 11:47:28 -0400 Received: from eggs.gnu.org ([209.51.188.92]:35570) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h5uSp-0003QX-6y for qemu-devel@nongnu.org; Mon, 18 Mar 2019 11:46:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h5uSo-0003uB-Am for qemu-devel@nongnu.org; Mon, 18 Mar 2019 11:46:11 -0400 Received: from smtp03.citrix.com ([162.221.156.55]:7850) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h5uSn-0003nA-R9 for qemu-devel@nongnu.org; Mon, 18 Mar 2019 11:46:10 -0400 IronPort-Data: A9a23:+ERPma9NHN1x7NLR+aLSDrVtTnXEGK7SOkUsrf30RpOx8vdXlk5Xxd SFxLPOcU1th6Pjb+gBB+GE7DyHl6rnQZiuZqOoUddr6h2ZUdbYggUWWr/cyz2Xa0PCyca0XU 43qgxcudzGtH2lXRf/xfVmduj5hkT2GzVdHLgJMHaO2VqVKm2XaiItgpOUQ4y5NsGgP7WQRi Y1cnjOJaKnpRu/n0g6d/kpMIjJnHNjjiXehQYLwfayRJHQMGY6vYOSofV8M1G2e3OmN3H4i9 2PgCh/+5du3sQSNEVHZHgg00kjTWnsYJcbrBuXEYLZ+KMvR2F/E6HqhUf5rSA1AKWSK4K22s ix99VKZ/AyKDUJXPchnzjaAB4hHW3EDTAJnBpyaBSzKMuzFpgZq6HL8bhDs1rWFVA2Q5pXbc 3hCmJ4gYq3BKt+XuCdjSuRWU+/+nbDQXoGImYkYC2L3hNYloqzDBlZaNw/SYOLJ4ewpUdRtz XHRk+ynDOhrZJ4gZgxlYhhgFVr0XdsvcaMP7i3swOnEf2It/mf9FtxDMetqeEzEViBu5GNNd w1YZeGFC4Z2Wx+1qfMmplpgud1rEpVtPhBGb63Xrewgku6A22hKJjcZEksO2IgVQtf3aSpSr moOE1+4pasjYhAgJkM5w2SAXSuMQWsdkulYH+YjT9p/tkSf4BMHQaEHeG+3RCrH1Bv4i3AHE aLY+uK3xxPmsbEbkdCGZQoiE+yPP1hwbwDKVBcsCXQZny4BJnI2YRUgHbiDIcPJGmCqapqMj URjzXv1OBHqm+gdBAjZdsYFgk1Hs20UZ2KW5d3uvwhQ4aOhJi0Le+faUXiXJNV93V+/Fksiu ySOnxB0R42lDoI4+qSj/I64k+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7gwON/Sy7BkyhYmJoUl6pai0lXiA/rSPDhIOOO1mf1NBVQTaPrT3HP8YXFD71w REG7lcCRvA7jQEnXckPfy2sykSMwrbz10bPw8y4ajUcX9kajpWnizGNM27+lQ+rSZVizdHYo RV+PeyMKN78crY9pPZqPV+JncyQH10AcI8RYdYx8zzXz9M0EMidRBSZqVwVlLIusSHOrwf X-IronPort-AV: E=Sophos;i="5.58,494,1544486400"; d="scan'208";a="80890919" From: Roger Pau Monne To: Date: Mon, 18 Mar 2019 16:45:45 +0100 Message-ID: <20190318154545.13974-1-roger.pau@citrix.com> X-Mailer: git-send-email 2.17.2 (Apple Git-113) MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 162.221.156.55 Subject: [Qemu-devel] [PATCH v2] xen-mapcache: use MAP_FIXED flag so the mmap address hint is always honored 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: Igor Druzhinin , Stefano Stabellini , Eduardo Habkost , "Michael S. Tsirkin" , Paul Durrant , xen-devel@lists.xenproject.org, Anthony Perard , Paolo Bonzini , Richard Henderson , Roger Pau Monne Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Or if it's not possible to honor the hinted address an error is returned instead. This makes it easier to spot the actual failure, instead of failing later on when the caller of xen_remap_bucket realizes the mapping has not been created at the requested address. Also note that at least on FreeBSD using MAP_FIXED will cause mmap to try harder to honor the passed address. Signed-off-by: Roger Pau Monné Reviewed-by: Paul Durrant --- Cc: Stefano Stabellini Cc: Anthony Perard Cc: Paul Durrant Cc: Igor Druzhinin Cc: Paolo Bonzini Cc: Richard Henderson Cc: Eduardo Habkost Cc: "Michael S. Tsirkin" Cc: Marcel Apfelbaum Cc: xen-devel@lists.xenproject.org --- Changes since v1: - Use MAP_FIXED for the dummy mmap call also if a specific virtual address is requested. --- hw/i386/xen/xen-mapcache.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/hw/i386/xen/xen-mapcache.c b/hw/i386/xen/xen-mapcache.c index 349f72d00c..23de5517db 100644 --- a/hw/i386/xen/xen-mapcache.c +++ b/hw/i386/xen/xen-mapcache.c @@ -185,8 +185,13 @@ static void xen_remap_bucket(MapCacheEntry *entry, } if (!dummy) { + /* + * If the caller has requested the mapping at a specific address use + * MAP_FIXED to make sure it's honored. + */ vaddr_base = xenforeignmemory_map2(xen_fmem, xen_domid, vaddr, - PROT_READ | PROT_WRITE, 0, + PROT_READ | PROT_WRITE, + vaddr ? MAP_FIXED : 0, nb_pfn, pfns, err); if (vaddr_base == NULL) { perror("xenforeignmemory_map2"); @@ -198,7 +203,8 @@ static void xen_remap_bucket(MapCacheEntry *entry, * mapping immediately due to certain circumstances (i.e. on resume now) */ vaddr_base = mmap(vaddr, size, PROT_READ | PROT_WRITE, - MAP_ANON | MAP_SHARED, -1, 0); + MAP_ANON | MAP_SHARED | (vaddr ? MAP_FIXED : 0), + -1, 0); if (vaddr_base == MAP_FAILED) { perror("mmap"); exit(-1);