Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp64734iog; Wed, 29 Jun 2022 18:13:09 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uKSXj0aPX1QIKI1Hwandh8GydIyQ0VA8pFp3mm1d7cgfXCBA4nnc0Z5sG+6+GFhdp0cGZB X-Received: by 2002:a05:6402:2051:b0:435:71b5:b627 with SMTP id bc17-20020a056402205100b0043571b5b627mr8171399edb.267.1656551589180; Wed, 29 Jun 2022 18:13:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656551589; cv=none; d=google.com; s=arc-20160816; b=Ndp4ZXL52DoMXRsxLj3TVF+59gUX8/KJNGvCMkSiOt5y88p5tcY4+bICbOeFvIUE06 eS5HHooGMgNL8l/4UZjH5A7vxwYPef50ehuPLA7OOExzzMc91xU3zuJDETsM6QIiwKPn B64BEXj7EUxjfP/1nqBt3Jv2lsS0Pd6gZ6uph6mfk7LMOJoen98yGaF5svpK5/DsCRdY y5yhp1DspGL96wCz1MVb16M8p9ji8nu05EUmiEAPYHfaQaDW2od9HYm6GLR1qXu+xvvX 39mvhzzu/BnKluaUWuA6VtZc0joS62uQK/G6Em9qaB4PhayhR2uNSMd1OihcNj0gcjT4 X2eA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:message-id :in-reply-to:subject:cc:to:from:date:dkim-signature; bh=hi3BHnFbloELY5mGt/pl9CqskyTnDglf3ZNxgnERZ9U=; b=muPRReqMEIHmH34WcrIjWnKCWY7gGRFgQRUIuYo57SejjK4ss9bFOsibgKXBjGTydB uCBIxBIFg88pp1Bc5/KPsXtMWNLkeXtM7K6/iLagzltnMw9Yj0RdUujISEje6Sx6sbQX YDMI0O6cb48DEzSIUz58cei6S3Ftg5Yr0IDpXmYl9AI4c+HnnWFbe5U2deoOrnul23ip ALCGEW/0LuNoAhq1ccrK+H8C7Hn0pPC8zuHHMwqygI5m+ACMeXdZW+zLU5XT3uFxPIeo LUTDd/ZJ7K5WbsShMN2NvVT8dGMGnUH4h8gQSr0rNYNZYdSW6SRijsyBJOWyixAWu9JE 9pCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DavTASOo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i26-20020a0564020f1a00b00437ddf2abeasi667975eda.512.2022.06.29.18.12.21; Wed, 29 Jun 2022 18:13:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DavTASOo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230286AbiF3BHG (ORCPT + 99 others); Wed, 29 Jun 2022 21:07:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229755AbiF3BHB (ORCPT ); Wed, 29 Jun 2022 21:07:01 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1EE7339680 for ; Wed, 29 Jun 2022 18:07:00 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 92EAF61F55 for ; Thu, 30 Jun 2022 01:06:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9650AC34114; Thu, 30 Jun 2022 01:06:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1656551219; bh=ADS86hmhn+G273gfWNc4aN140CYL60KTh6QbXWJGJvo=; h=Date:From:To:cc:Subject:In-Reply-To:References:From; b=DavTASOoI9td7fwL7mHKPagtz5xyIlnQedTtDOaOvZ6ndzgqlwpx11PlN4c9HIIHS xNIV80kui868Wif0OVHp/10ajvogB/Jdeed2JymhxXSHb7EXGK1kqCLWLt65t6IYHV 0XdUWVCaZSaAvoauiiMPJWJUotNp4Ne8Y2m2Mh2upGDQ5qHqcSsgT+jf/ZNyugLeOZ 5+ovvrqmfV6JZI1xaHAUOZ4YGo7blBs3TUfNG3hg7yDr1fMiBX7SJFikGkNZpq6Do+ c4sOsSMVcL5IZOKt1wYNIrlTA6N50dzEE6yipuBa91sxbm0riZJNH38Dv+J4n9Faxr z3hAb6Xw4oG9g== Date: Wed, 29 Jun 2022 18:06:57 -0700 (PDT) From: Stefano Stabellini X-X-Sender: sstabellini@ubuntu-linux-20-04-desktop To: Oleksandr Tyshchenko cc: xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org, Oleksandr Tyshchenko , Stefano Stabellini , Juergen Gross , Julien Grall Subject: Re: [PATCH V1 2/2] xen/grant-table: Use unpopulated contiguous pages instead of real RAM ones In-Reply-To: <1655740136-3974-3-git-send-email-olekstysh@gmail.com> Message-ID: References: <1655740136-3974-1-git-send-email-olekstysh@gmail.com> <1655740136-3974-3-git-send-email-olekstysh@gmail.com> User-Agent: Alpine 2.22 (DEB 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 On Mon, 20 Jun 2022, Oleksandr Tyshchenko wrote: > From: Oleksandr Tyshchenko > > Depends on CONFIG_XEN_UNPOPULATED_ALLOC. If enabled then unpopulated > contiguous pages will be allocated for grant mapping into instead of > ballooning out real RAM pages. > > Also fallback to allocate DMAable pages (balloon out real RAM pages) > if we failed to allocate unpopulated contiguous pages. Use recently > introduced is_xen_unpopulated_page() in gnttab_dma_free_pages() to know > what API to use for freeing pages. > > Signed-off-by: Oleksandr Tyshchenko > --- > Please note, I haven't re-checked yet the use-case where the xen-swiotlb > is involved (proposed by Stefano): > https://lore.kernel.org/xen-devel/alpine.DEB.2.22.394.2206031348230.2783803@ubuntu-linux-20-04-desktop/ > I will re-check that for next version and add corresponding comment > in the code. Great. The patch looks good so far. > Changes RFC -> V1: > - update commit subject/description > - rework to avoid introducing alternative implementation > of gnttab_dma_alloc(free)_pages(), use IS_ENABLED() > - implement a fallback to real RAM pages if we failed to allocate > unpopulated contiguous pages (resolve initial TODO) > - update according to the API renaming (s/dma/contiguous) > --- > drivers/xen/grant-table.c | 24 ++++++++++++++++++++++++ > 1 file changed, 24 insertions(+) > > diff --git a/drivers/xen/grant-table.c b/drivers/xen/grant-table.c > index 738029d..15e426b 100644 > --- a/drivers/xen/grant-table.c > +++ b/drivers/xen/grant-table.c > @@ -1047,6 +1047,23 @@ int gnttab_dma_alloc_pages(struct gnttab_dma_alloc_args *args) > size_t size; > int i, ret; > > + if (IS_ENABLED(CONFIG_XEN_UNPOPULATED_ALLOC)) { > + ret = xen_alloc_unpopulated_contiguous_pages(args->dev, args->nr_pages, > + args->pages); > + if (ret < 0) > + goto fallback; > + > + ret = gnttab_pages_set_private(args->nr_pages, args->pages); > + if (ret < 0) > + goto fail; > + > + args->vaddr = page_to_virt(args->pages[0]); > + args->dev_bus_addr = page_to_phys(args->pages[0]); > + > + return ret; > + } > + > +fallback: > size = args->nr_pages << PAGE_SHIFT; > if (args->coherent) > args->vaddr = dma_alloc_coherent(args->dev, size, > @@ -1103,6 +1120,13 @@ int gnttab_dma_free_pages(struct gnttab_dma_alloc_args *args) > > gnttab_pages_clear_private(args->nr_pages, args->pages); > > + if (IS_ENABLED(CONFIG_XEN_UNPOPULATED_ALLOC) && > + is_xen_unpopulated_page(args->pages[0])) { > + xen_free_unpopulated_contiguous_pages(args->dev, args->nr_pages, > + args->pages); > + return 0; > + } > + > for (i = 0; i < args->nr_pages; i++) > args->frames[i] = page_to_xen_pfn(args->pages[i]); > > -- > 2.7.4 >