From patchwork Fri Mar 15 08:58:47 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: 10854315 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 74AD21669 for ; Fri, 15 Mar 2019 09:01:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5FFCF2A8E4 for ; Fri, 15 Mar 2019 09:01:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5E5DA2A8E5; Fri, 15 Mar 2019 09:01:38 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BC2DC2A8D2 for ; Fri, 15 Mar 2019 09:01:36 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1h4igM-0002MB-Hc; Fri, 15 Mar 2019 08:59:14 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1h4igL-0002M6-48 for xen-devel@lists.xenproject.org; Fri, 15 Mar 2019 08:59:13 +0000 X-Inumbo-ID: 9890aefa-4700-11e9-8591-df9aac289dd0 Received: from SMTP03.CITRIX.COM (unknown [162.221.156.55]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 9890aefa-4700-11e9-8591-df9aac289dd0; Fri, 15 Mar 2019 08:59:10 +0000 (UTC) X-IronPort-AV: E=Sophos;i="5.58,481,1544486400"; d="scan'208";a="80659663" From: Roger Pau Monne To: Date: Fri, 15 Mar 2019 09:58:47 +0100 Message-ID: <20190315085847.31245-1-roger.pau@citrix.com> X-Mailer: git-send-email 2.17.2 (Apple Git-113) MIME-Version: 1.0 Subject: [Xen-devel] [PATCH] xen-mapcache: use MAP_FIXED flag so the mmap address hint is always honored X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Igor Druzhinin , Stefano Stabellini , Eduardo Habkost , "Michael S. Tsirkin" , Paul Durrant , Marcel Apfelbaum , xen-devel@lists.xenproject.org, Anthony Perard , Paolo Bonzini , Richard Henderson , Roger Pau Monne Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-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é Acked-by: Anthony PERARD --- 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 --- hw/i386/xen/xen-mapcache.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/hw/i386/xen/xen-mapcache.c b/hw/i386/xen/xen-mapcache.c index 349f72d00c..0e2870b320 100644 --- a/hw/i386/xen/xen-mapcache.c +++ b/hw/i386/xen/xen-mapcache.c @@ -185,8 +185,14 @@ 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. Note that with MAP_FIXED at + * least FreeBSD will try harder to honor the passed address. + */ 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");