Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp128725iob; Tue, 17 May 2022 21:11:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy30hRPhPyFz8uWJIElcRGJg/nQY96iVfifq5JkcG2qLYvlklsumDG3BjIYBKQS4bHU0y03 X-Received: by 2002:aa7:8d47:0:b0:4f6:a7f9:1ead with SMTP id s7-20020aa78d47000000b004f6a7f91eadmr25875222pfe.42.1652847087614; Tue, 17 May 2022 21:11:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652847087; cv=none; d=google.com; s=arc-20160816; b=FQ5GMwKbvfIu+tFpGIH/o/O55KSHNlo09sJHa8RFjxNK9bEPIG54YqbKjJR3hgsjRF YnXk7/WBh5jgpRH9m2YbNs4sIXVA2DkVQj96YvXONCJi0yNnr7+nG5dLKOFpAN7A8eLu 8yDfa+gIfRpm6D43vwlnTLYuo4l5uYDqAl40yuI1Eo9lpiD5KCzmbGmRyf08Q1idXrPK 6gPzwgyuxf+aykBTGC889cFWLWrLStXdLsLBz5HmcrK248rGvqsb+fLRnvf63xmxZqMQ LVSyYwMEaMu6QcYQ6fUmbsR7yAU/Cl+jh/emBEryw78/AtCu7hLI4aACEm3ed02gF7F3 PPNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=xUxnvY0wWYvQFwVkkKnZ0hYzB77/1hWqL1wilzE489c=; b=oBf+/Yp4BOANyjjEQL2ofQXkFkY+0R+C9SH5boksM/6dKfJYS0DrAAJqjMXxyOsOMP VinqCf6i9iTiFBo8RBxMR0K41GY034WomC+NjjVyip2USygVofUkzSSKAdiHUVJWvbqL Z0nKSBlxIZ1eSGW/CReKE2ubdSUhgZcjXLyocWZBMTVmDm12QHA5xTuriufzKZQtYSq9 imbKp5k5ibVAN6BITiEnPx64y6GERwNO0ND/fre4dbcqHaAMeRBzKUTrQda+K7X9E+QU 4kZ5X1Unf4bg4yZTEjMHseXAddu552L205UapIBTgQOvNr7EO/IHszzWa5zyKjQcCikk 2DKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=kb8ddVNG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id jg13-20020a17090326cd00b00158e5c01c2esi1116944plb.339.2022.05.17.21.11.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 May 2022 21:11:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=kb8ddVNG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1A13519C3E; Tue, 17 May 2022 20:42:15 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351813AbiEQSFr (ORCPT + 99 others); Tue, 17 May 2022 14:05:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351931AbiEQSF1 (ORCPT ); Tue, 17 May 2022 14:05:27 -0400 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8B8E5158D for ; Tue, 17 May 2022 11:04:33 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id p5-20020a1c2905000000b003970dd5404dso1694989wmp.0 for ; Tue, 17 May 2022 11:04:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=xUxnvY0wWYvQFwVkkKnZ0hYzB77/1hWqL1wilzE489c=; b=kb8ddVNGcr5cVeafnyHPeYNXQERd/qF31HFkfUdq2R0uWdYsIrV5qJc5rqOLz8AJ2R LeqlzPakVREbISyj+rzFqGHtWdSCexiQvfb3BzQZY4Gb6WIGH1gnWvSpBsaSAoOAgJPw Y2gQVbghkdgpguWD5R6ZUeT1mykXPwp1lsXvUamDbQaFqmfp7ZJs19gwZMPPJzKo2yI5 qsxQdCIXfE44XW+Ui9ZV8j0XprUOYnEv+bHcF2+ibhH3I9NCtjxHxMwKRYDXdrArzigQ AkB6D1SgJLfFBjy+aEuoy/qrUgNvZwQus2tAbvnVgDGakrkC9Xvt3cWzsnYci380bHt5 MjFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=xUxnvY0wWYvQFwVkkKnZ0hYzB77/1hWqL1wilzE489c=; b=rJ3sRgpdWQjRsPrMVGIVDDw9mAyP62EFJA32M0pAF+iewIGG6150dKGjar9oerkoju DhDYxAq40E2gi+c3eKytSpPR+/7AimuK9YClA+M7mTsKTKodEu90mFf9KzyLVDiyBc8X PvnBJkW3BXiR/G2yueRzWCSeb2DJF1S7+V8oOs5aO8WY0JoQSHx6AVNDHlPvMsnM0DSa rvx7lhdMtEwquvJMM5awP6lF6G5bQ1M05NW+MSqphvv58MD6KMw3qeCy0BNS0FaYp+m4 lZq63t5ej8c5VlYOun/iqhaJ3PEzSBHLpwvRlYB5Im2+5+Of14Pp2oRGUwYKwEJ3aWQq p3sQ== X-Gm-Message-State: AOAM5334ui9/7PAXtpZU/icfmRfXVwG45gYFXhxGgEfI/K9POYSAWkSt eXK+dDxQtX25fg3VJUiANQE= X-Received: by 2002:a05:600c:1989:b0:394:8dc0:b57f with SMTP id t9-20020a05600c198900b003948dc0b57fmr33101152wmq.110.1652810672320; Tue, 17 May 2022 11:04:32 -0700 (PDT) Received: from otyshchenko.router ([212.22.223.21]) by smtp.gmail.com with ESMTPSA id c3-20020adfc6c3000000b0020c5253d8dasm12978625wrh.38.2022.05.17.11.04.31 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 May 2022 11:04:31 -0700 (PDT) From: Oleksandr Tyshchenko To: xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org Cc: Oleksandr Tyshchenko , Stefano Stabellini , Boris Ostrovsky , Juergen Gross , Julien Grall Subject: [RFC PATCH 2/2] xen/grant-table: Use unpopulated DMAable pages instead of real RAM ones Date: Tue, 17 May 2022 21:04:18 +0300 Message-Id: <1652810658-27810-3-git-send-email-olekstysh@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1652810658-27810-1-git-send-email-olekstysh@gmail.com> References: <1652810658-27810-1-git-send-email-olekstysh@gmail.com> X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Oleksandr Tyshchenko Depends on CONFIG_XEN_UNPOPULATED_ALLOC. If enabled then unpopulated DMAable (contiguous) pages will be allocated for grant mapping into instead of ballooning out real RAM pages. TODO: Fallback to real RAM pages if xen_alloc_unpopulated_dma_pages() fails. Signed-off-by: Oleksandr Tyshchenko --- drivers/xen/grant-table.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/drivers/xen/grant-table.c b/drivers/xen/grant-table.c index 8ccccac..2bb4392 100644 --- a/drivers/xen/grant-table.c +++ b/drivers/xen/grant-table.c @@ -864,6 +864,25 @@ EXPORT_SYMBOL_GPL(gnttab_free_pages); */ int gnttab_dma_alloc_pages(struct gnttab_dma_alloc_args *args) { +#ifdef CONFIG_XEN_UNPOPULATED_ALLOC + int ret; + + ret = xen_alloc_unpopulated_dma_pages(args->dev, args->nr_pages, + args->pages); + if (ret < 0) + return ret; + + ret = gnttab_pages_set_private(args->nr_pages, args->pages); + if (ret < 0) { + gnttab_dma_free_pages(args); + return ret; + } + + args->vaddr = page_to_virt(args->pages[0]); + args->dev_bus_addr = page_to_phys(args->pages[0]); + + return ret; +#else unsigned long pfn, start_pfn; size_t size; int i, ret; @@ -910,6 +929,7 @@ int gnttab_dma_alloc_pages(struct gnttab_dma_alloc_args *args) fail: gnttab_dma_free_pages(args); return ret; +#endif } EXPORT_SYMBOL_GPL(gnttab_dma_alloc_pages); @@ -919,6 +939,12 @@ EXPORT_SYMBOL_GPL(gnttab_dma_alloc_pages); */ int gnttab_dma_free_pages(struct gnttab_dma_alloc_args *args) { +#ifdef CONFIG_XEN_UNPOPULATED_ALLOC + gnttab_pages_clear_private(args->nr_pages, args->pages); + xen_free_unpopulated_dma_pages(args->dev, args->nr_pages, args->pages); + + return 0; +#else size_t size; int i, ret; @@ -946,6 +972,7 @@ int gnttab_dma_free_pages(struct gnttab_dma_alloc_args *args) dma_free_wc(args->dev, size, args->vaddr, args->dev_bus_addr); return ret; +#endif } EXPORT_SYMBOL_GPL(gnttab_dma_free_pages); #endif -- 2.7.4