From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.1 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9C10AC433E0 for ; Fri, 24 Jul 2020 16:19:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6EE852067D for ; Fri, 24 Jul 2020 16:19:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="xY5LsiQ9" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726703AbgGXQT4 (ORCPT ); Fri, 24 Jul 2020 12:19:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726381AbgGXQTz (ORCPT ); Fri, 24 Jul 2020 12:19:55 -0400 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 559FCC0619D3 for ; Fri, 24 Jul 2020 09:19:55 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id r2so3745053wrs.8 for ; Fri, 24 Jul 2020 09:19:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=cn6mIcIhNrNjGLZLY/eqMcDuxtyycO8StVpDq6XMfg4=; b=xY5LsiQ9yZqTUPrlACwii7Rvx/e7Y7RsnLk7diTi9eQSzBurj4ppdVmON5hT0zTWZ+ AxTwAD/StnDH/EtXLJcuULhgmramutlTRx5mwyKbC3fX2dR0HoxaSDsa8G0qnBU7WDSQ rWs6HIssfGwS5/ZfWSjyr24w65ZDHGaDg0g2zNlVnXSCQYj6cEErFBXhkzoKruiy2nJw p4O5cv87RSmIjkE7Cy1ypz70KFWaN1DDTtHGHLxpkGVUBn6DD3R006MpeDijBhPXWozi 8wqpTCs4mr2Pw/eqpQI7HpWEmOxo4+oHEHh+uxeO1mL8/AaT3ybhbMinOal7LBWuVSGw G5eA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=cn6mIcIhNrNjGLZLY/eqMcDuxtyycO8StVpDq6XMfg4=; b=RCLlkBQ9l5sTOQU9WIfTWNmjW0xyq9TGaRrQv9HO1NIofwFkQFRoxAk5ESmtQFDuJA 1WiCjBKluN/Kp8jFGEY0SeUzzGl1nnIn66/OlReNMaVE8jhbwhcA7B86sT+Xk6uyFUB0 Uv4WpUZAqZBBvmUvuNFNssQAgW2sA3s4FqAstKjmLq7cccJfA2SuiqRB98vZQJbL6eFb aTaiXOWixhTYDa9OXB7Vs2JMY9xqhbxEAVvawtk85qsFE11LEoPfosH6XIT0gD+ScHpm 0aoe3x6t+lxvSZhWZxLlkmxTP3aOVPK4qk9T0OwzMC3kbHxKK/TpvbCsIxpkF0hpWh2W 2Gpg== X-Gm-Message-State: AOAM532Tw1UTFd6Aem078qtRH/QotDm77kx/WjBMYMiRUEyurWZKXjjL w7PfjIqX1QZgENjzUzo20z+/4txBKHAH//0o6oJ6zA== X-Google-Smtp-Source: ABdhPJyafoSdic4aXYtLTcXiuz6OGiyCfozJU0MCkFavQrWqNmc9MZxK44TRvda3nnDDgYO9d5zO8BxLY0SDE86xF3k= X-Received: by 2002:adf:d84f:: with SMTP id k15mr8930588wrl.176.1595607594046; Fri, 24 Jul 2020 09:19:54 -0700 (PDT) MIME-Version: 1.0 References: <550b30a86c0785049d24c945e2c6628d491cee3a.camel@suse.de> <011994f8a717a00dcd9ed7682a1ddeb421c2c43f.camel@suse.de> <01831596e4a2a6c9c066138b23bd30435f8e5569.camel@suse.de> <6db722947546221ed99d3f473f78e1a6de65d7d6.camel@suse.de> <0dc1e922bf87fa73790e7471b3974528dd261486.camel@suse.de> <20200724134114.GA3152@lst.de> In-Reply-To: <20200724134114.GA3152@lst.de> From: Amit Pundir Date: Fri, 24 Jul 2020 21:49:17 +0530 Message-ID: Subject: Re: [PATCH] dma-pool: Do not allocate pool memory from CMA To: Christoph Hellwig Cc: Nicolas Saenz Julienne , Marek Szyprowski , Robin Murphy , David Rientjes , linux-rpi-kernel@lists.infradead.org, jeremy.linton@arm.com, iommu@lists.linux-foundation.org, lkml , John Stultz , Sumit Semwal Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 24 Jul 2020 at 19:11, Christoph Hellwig wrote: > > Yes, the iommu is an interesting case, and the current code is > wrong for that. Can you try the patch below? It contains a modified > version of Nicolas' patch to try CMA again for the expansion and a new > (for now hackish) way to not apply the addressability check for dma-iommu > allocations. Thank you. The below patch worked on today's linux/master (f37e99aca03f). Regards, Amit Pundir > > diff --git a/kernel/dma/pool.c b/kernel/dma/pool.c > index 6bc74a2d51273e..ec5e525d2b9309 100644 > --- a/kernel/dma/pool.c > +++ b/kernel/dma/pool.c > @@ -3,7 +3,9 @@ > * Copyright (C) 2012 ARM Ltd. > * Copyright (C) 2020 Google LLC > */ > +#include > #include > +#include > #include > #include > #include > @@ -55,6 +57,31 @@ static void dma_atomic_pool_size_add(gfp_t gfp, size_t size) > pool_size_kernel += size; > } > > +static bool cma_in_zone(gfp_t gfp) > +{ > + phys_addr_t end; > + unsigned long size; > + struct cma *cma; > + > + cma = dev_get_cma_area(NULL); > + if (!cma) > + return false; > + > + size = cma_get_size(cma); > + if (!size) > + return false; > + end = cma_get_base(cma) - memblock_start_of_DRAM() + size - 1; > + > + /* CMA can't cross zone boundaries, see cma_activate_area() */ > + if (IS_ENABLED(CONFIG_ZONE_DMA) && (gfp & GFP_DMA) && > + end <= DMA_BIT_MASK(zone_dma_bits)) > + return true; > + if (IS_ENABLED(CONFIG_ZONE_DMA32) && (gfp & GFP_DMA32) && > + end <= DMA_BIT_MASK(32)) > + return true; > + return true; > +} > + > static int atomic_pool_expand(struct gen_pool *pool, size_t pool_size, > gfp_t gfp) > { > @@ -68,7 +95,11 @@ static int atomic_pool_expand(struct gen_pool *pool, size_t pool_size, > > do { > pool_size = 1 << (PAGE_SHIFT + order); > - page = alloc_pages(gfp, order); > + if (cma_in_zone(gfp)) > + page = dma_alloc_from_contiguous(NULL, 1 << order, > + order, false); > + if (!page) > + page = alloc_pages(gfp, order); > } while (!page && order-- > 0); > if (!page) > goto out; > @@ -251,7 +282,11 @@ void *dma_alloc_from_pool(struct device *dev, size_t size, > continue; > > phys = gen_pool_virt_to_phys(pool, val); > - if (dma_coherent_ok(dev, phys, size)) > + /* > + * Only apply the addressability check for dma-direct. > + * This is a nasty hack and won't work e.g. for arm. > + */ > + if (get_dma_ops(dev) || dma_coherent_ok(dev, phys, size)) > break; > > gen_pool_free(pool, val, size); From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9FBF7C433E4 for ; Fri, 24 Jul 2020 16:20:05 +0000 (UTC) Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 61030206EB for ; Fri, 24 Jul 2020 16:20:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="xY5LsiQ9" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 61030206EB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=iommu-bounces@lists.linux-foundation.org Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 075A088B57; Fri, 24 Jul 2020 16:20:05 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id CcNh5-r02xwX; Fri, 24 Jul 2020 16:20:04 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by hemlock.osuosl.org (Postfix) with ESMTP id 4603488A81; Fri, 24 Jul 2020 16:20:04 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 27BFDC004E; Fri, 24 Jul 2020 16:20:04 +0000 (UTC) Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 8DCA4C004C for ; Fri, 24 Jul 2020 16:20:02 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 0C99087122 for ; Fri, 24 Jul 2020 16:19:57 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id JGC4-mmtCYsA for ; Fri, 24 Jul 2020 16:19:56 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by fraxinus.osuosl.org (Postfix) with ESMTPS id AA1BE87106 for ; Fri, 24 Jul 2020 16:19:55 +0000 (UTC) Received: by mail-wr1-f68.google.com with SMTP id r4so5866416wrx.9 for ; Fri, 24 Jul 2020 09:19:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=cn6mIcIhNrNjGLZLY/eqMcDuxtyycO8StVpDq6XMfg4=; b=xY5LsiQ9yZqTUPrlACwii7Rvx/e7Y7RsnLk7diTi9eQSzBurj4ppdVmON5hT0zTWZ+ AxTwAD/StnDH/EtXLJcuULhgmramutlTRx5mwyKbC3fX2dR0HoxaSDsa8G0qnBU7WDSQ rWs6HIssfGwS5/ZfWSjyr24w65ZDHGaDg0g2zNlVnXSCQYj6cEErFBXhkzoKruiy2nJw p4O5cv87RSmIjkE7Cy1ypz70KFWaN1DDTtHGHLxpkGVUBn6DD3R006MpeDijBhPXWozi 8wqpTCs4mr2Pw/eqpQI7HpWEmOxo4+oHEHh+uxeO1mL8/AaT3ybhbMinOal7LBWuVSGw G5eA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=cn6mIcIhNrNjGLZLY/eqMcDuxtyycO8StVpDq6XMfg4=; b=he5D2rul8cH9bdLbu10GEZBhBmI+wCNdUGt+9AFUWcKFG7Gf/CH87IQjSsKLR2qZOr qpZvLPbmoNCtNRHGJRfuZMwcinu2CCHvfyuKWXmMmaYdjv0RJ5VKuDr8tQEEC3ubDuCK 06Sxs0Q+eGtUWcyO+mnai4AgQJ+11Ffw3xJ6iwbbR94AvjAimkFaaGER0z7AU1Pi1QGe yfYwi9HKg3HSbESCEF5fyOYX5c4Mev3JVSRA0k8TWAdMpgdJfpBKp7jqSbTEm5Qir5nz K5f6t6n1QL0P3uxBk6THkdBQ0HSt7q5d8ZrX8NFLnV6YMKziAYm8UBhwxYx8hYMYmxHh 7avQ== X-Gm-Message-State: AOAM530m3FiRLVrkZnDScU/IUwoI0LJXdcax20W1TiTqXFOJMwEjSGVj 5d2kTtLKfb77hUckXTuzQn3gV0Zl0nouXOSkhGq8RA== X-Google-Smtp-Source: ABdhPJyafoSdic4aXYtLTcXiuz6OGiyCfozJU0MCkFavQrWqNmc9MZxK44TRvda3nnDDgYO9d5zO8BxLY0SDE86xF3k= X-Received: by 2002:adf:d84f:: with SMTP id k15mr8930588wrl.176.1595607594046; Fri, 24 Jul 2020 09:19:54 -0700 (PDT) MIME-Version: 1.0 References: <550b30a86c0785049d24c945e2c6628d491cee3a.camel@suse.de> <011994f8a717a00dcd9ed7682a1ddeb421c2c43f.camel@suse.de> <01831596e4a2a6c9c066138b23bd30435f8e5569.camel@suse.de> <6db722947546221ed99d3f473f78e1a6de65d7d6.camel@suse.de> <0dc1e922bf87fa73790e7471b3974528dd261486.camel@suse.de> <20200724134114.GA3152@lst.de> In-Reply-To: <20200724134114.GA3152@lst.de> From: Amit Pundir Date: Fri, 24 Jul 2020 21:49:17 +0530 Message-ID: Subject: Re: [PATCH] dma-pool: Do not allocate pool memory from CMA To: Christoph Hellwig Cc: lkml , jeremy.linton@arm.com, iommu@lists.linux-foundation.org, John Stultz , linux-rpi-kernel@lists.infradead.org, David Rientjes , Robin Murphy , Sumit Semwal X-BeenThere: iommu@lists.linux-foundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Development issues for Linux IOMMU support List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: iommu-bounces@lists.linux-foundation.org Sender: "iommu" On Fri, 24 Jul 2020 at 19:11, Christoph Hellwig wrote: > > Yes, the iommu is an interesting case, and the current code is > wrong for that. Can you try the patch below? It contains a modified > version of Nicolas' patch to try CMA again for the expansion and a new > (for now hackish) way to not apply the addressability check for dma-iommu > allocations. Thank you. The below patch worked on today's linux/master (f37e99aca03f). Regards, Amit Pundir > > diff --git a/kernel/dma/pool.c b/kernel/dma/pool.c > index 6bc74a2d51273e..ec5e525d2b9309 100644 > --- a/kernel/dma/pool.c > +++ b/kernel/dma/pool.c > @@ -3,7 +3,9 @@ > * Copyright (C) 2012 ARM Ltd. > * Copyright (C) 2020 Google LLC > */ > +#include > #include > +#include > #include > #include > #include > @@ -55,6 +57,31 @@ static void dma_atomic_pool_size_add(gfp_t gfp, size_t size) > pool_size_kernel += size; > } > > +static bool cma_in_zone(gfp_t gfp) > +{ > + phys_addr_t end; > + unsigned long size; > + struct cma *cma; > + > + cma = dev_get_cma_area(NULL); > + if (!cma) > + return false; > + > + size = cma_get_size(cma); > + if (!size) > + return false; > + end = cma_get_base(cma) - memblock_start_of_DRAM() + size - 1; > + > + /* CMA can't cross zone boundaries, see cma_activate_area() */ > + if (IS_ENABLED(CONFIG_ZONE_DMA) && (gfp & GFP_DMA) && > + end <= DMA_BIT_MASK(zone_dma_bits)) > + return true; > + if (IS_ENABLED(CONFIG_ZONE_DMA32) && (gfp & GFP_DMA32) && > + end <= DMA_BIT_MASK(32)) > + return true; > + return true; > +} > + > static int atomic_pool_expand(struct gen_pool *pool, size_t pool_size, > gfp_t gfp) > { > @@ -68,7 +95,11 @@ static int atomic_pool_expand(struct gen_pool *pool, size_t pool_size, > > do { > pool_size = 1 << (PAGE_SHIFT + order); > - page = alloc_pages(gfp, order); > + if (cma_in_zone(gfp)) > + page = dma_alloc_from_contiguous(NULL, 1 << order, > + order, false); > + if (!page) > + page = alloc_pages(gfp, order); > } while (!page && order-- > 0); > if (!page) > goto out; > @@ -251,7 +282,11 @@ void *dma_alloc_from_pool(struct device *dev, size_t size, > continue; > > phys = gen_pool_virt_to_phys(pool, val); > - if (dma_coherent_ok(dev, phys, size)) > + /* > + * Only apply the addressability check for dma-direct. > + * This is a nasty hack and won't work e.g. for arm. > + */ > + if (get_dma_ops(dev) || dma_coherent_ok(dev, phys, size)) > break; > > gen_pool_free(pool, val, size); _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu