From patchwork Mon Mar 18 17:37:31 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: 10858365 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 8C7071390 for ; Mon, 18 Mar 2019 17:45:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 70AFD28F6C for ; Mon, 18 Mar 2019 17:45:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 652AD29453; Mon, 18 Mar 2019 17:45:56 +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 DFB8528F6C for ; Mon, 18 Mar 2019 17:45:55 +0000 (UTC) Received: from localhost ([127.0.0.1]:45234 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h5wKg-0007bH-TX for patchwork-qemu-devel@patchwork.kernel.org; Mon, 18 Mar 2019 13:45:54 -0400 Received: from eggs.gnu.org ([209.51.188.92]:58023) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h5wCw-0001nq-7H for qemu-devel@nongnu.org; Mon, 18 Mar 2019 13:37:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h5wCv-0001y8-AF for qemu-devel@nongnu.org; Mon, 18 Mar 2019 13:37:54 -0400 Received: from smtp03.citrix.com ([162.221.156.55]:19641) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h5wCu-0001v2-UR for qemu-devel@nongnu.org; Mon, 18 Mar 2019 13:37:53 -0400 IronPort-Data: A9a23:X+cXgqwG+6TLGRh7MhF6t4n5zX2q8pwBZkZajsDslgifGU9jxPU8VO SFirS/VJh9ycLBV5Q3URkGp0cujdgYBNtxlqvBQIMKUbsJKHzeooXRtwdxjcE11W8xK3PsBm Ysus+SCU7vqWWVWLQcOIqn0vA42bi0YDVl8koL2XEHi1vsPzZt8XSotzCdB/8/o9dqoLWwHV cHd6+OW5AswX9eqL8+MDm1y5xf+SJ8mWs1X412KUkWDyjzGLVIl37nBPnQpFefgHYC64quPe lwYmNspr6FdaivC4lWNkj37E40GwFVcHfU7loid6TTrvIuRy/DZJne9Jxm4sdUPwfGjMENkr Mh1Eu6Tx/s/r/w1P2XQSoFM2G96KaUxcUKeKGbV1L4qtaTHC9BD4sbhp6uhb451rIR1yM03D KTEMROMwA/oc8X/WyxEwfvsK0eXC0Aq4he8MrRhwVPrz9jvuc88NNQOBAjg8mIN3+eYjjxEh vtTlGD48tYouaaijDiEgjZnFC0bOSgs5Qf2I0VUluXX2fhgsOrOwgoVFU0cdkQwHaKqJkv0n 1V3UU990EpQYjHeZiVvLcljgvsS9w1gvBmXn6yiUKYzrirmJheb9pBok0IzHAsAW2WFS/bfu r1gz9OLmBzjmiLEpBURTc2u86pbMtpyWA2/QoO608wXGEPkYbKNYsC9OTI+yyp4OaPBYXQdV LxZNswNd5+um7nD4uCP3hJsDk6p+5sycQ+B7IaUkxdSOx9PCbg2ll0Qy7vgiedueOyBc7FYZ MfLbEz9eHFO6nsgLN4CstoBWN7YS93vUWIRLzobTXKbJ4oVFyRYhYS7fkIXOB+HqcLzNuOKc D6muwOi9NZOxaqA/pJJICc8c4d/w2SCsYx3VqFPcb/E2yb9JJtzG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1h/jpDtwTVeShA2lx3PO6ZP MOgqcuYzw5nJA3P+jnyxY5lJgKBdJwG2pDB9r1fYZ+O53vKpo8BDSUYPMtAAqcKFfiTMQHC6 h7UFlG5u51pixxvgLQd99UYL1yN4PqyzPv+qi2E2NoQXzCjJSIW5NyF+iWp5E3VdM= X-IronPort-AV: E=Sophos;i="5.58,494,1544486400"; d="scan'208";a="80910778" From: Roger Pau Monne To: Date: Mon, 18 Mar 2019 18:37:31 +0100 Message-ID: <20190318173731.14494-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 v3] 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 Reviewed-by: Igor Druzhinin 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 --- Changes since v2: - Move comment position. 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..254759f776 100644 --- a/hw/i386/xen/xen-mapcache.c +++ b/hw/i386/xen/xen-mapcache.c @@ -184,9 +184,14 @@ static void xen_remap_bucket(MapCacheEntry *entry, pfns[i] = (address_index << (MCACHE_BUCKET_SHIFT-XC_PAGE_SHIFT)) + i; } + /* + * If the caller has requested the mapping at a specific address use + * MAP_FIXED to make sure it's honored. + */ if (!dummy) { 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);