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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B03A8CDB465 for ; Mon, 16 Oct 2023 11:58:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230017AbjJPL6z (ORCPT ); Mon, 16 Oct 2023 07:58:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233167AbjJPL6y (ORCPT ); Mon, 16 Oct 2023 07:58:54 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 15E16E3 for ; Mon, 16 Oct 2023 04:58:52 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 616F01FB; Mon, 16 Oct 2023 04:59:31 -0700 (PDT) Received: from [10.1.196.40] (e121345-lin.cambridge.arm.com [10.1.196.40]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 698A83F5A1; Mon, 16 Oct 2023 04:58:48 -0700 (PDT) Message-ID: Date: Mon, 16 Oct 2023 12:58:47 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 07/12] dma-direct: simplify the use atomic pool logic in dma_direct_alloc Content-Language: en-GB To: Christoph Hellwig , Greg Ungerer , iommu@lists.linux.dev Cc: Paul Walmsley , Palmer Dabbelt , Conor Dooley , Geert Uytterhoeven , Magnus Damm , Marek Szyprowski , Geert Uytterhoeven , Wei Fang , Shenwei Wang , Clark Wang , NXP Linux Team , linux-m68k@lists.linux-m68k.org, netdev@vger.kernel.org, linux-riscv@lists.infradead.org, linux-renesas-soc@vger.kernel.org, Jim Quinlan References: <20231016054755.915155-1-hch@lst.de> <20231016054755.915155-8-hch@lst.de> From: Robin Murphy In-Reply-To: <20231016054755.915155-8-hch@lst.de> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-m68k@vger.kernel.org On 16/10/2023 6:47 am, Christoph Hellwig wrote: > The logic in dma_direct_alloc when to use the atomic pool vs remapping > grew a bit unreadable. Consolidate it into a single check, and clean > up the set_uncached vs remap logic a bit as well. Reviewed-by: Robin Murphy > Signed-off-by: Christoph Hellwig > --- > kernel/dma/direct.c | 25 ++++++++++--------------- > 1 file changed, 10 insertions(+), 15 deletions(-) > > diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c > index ec410af1d8a14e..1327d04fa32a25 100644 > --- a/kernel/dma/direct.c > +++ b/kernel/dma/direct.c > @@ -234,27 +234,22 @@ void *dma_direct_alloc(struct device *dev, size_t size, > dma_handle); > > /* > - * Otherwise remap if the architecture is asking for it. But > - * given that remapping memory is a blocking operation we'll > - * instead have to dip into the atomic pools. > + * Otherwise we require the architecture to either be able to > + * mark arbitrary parts of the kernel direct mapping uncached, > + * or remapped it uncached. > */ > + set_uncached = IS_ENABLED(CONFIG_ARCH_HAS_DMA_SET_UNCACHED); > remap = IS_ENABLED(CONFIG_DMA_DIRECT_REMAP); > - if (remap) { > - if (dma_direct_use_pool(dev, gfp)) > - return dma_direct_alloc_from_pool(dev, size, > - dma_handle, gfp); > - } else { > - if (!IS_ENABLED(CONFIG_ARCH_HAS_DMA_SET_UNCACHED)) > - return NULL; > - set_uncached = true; > - } > + if (!set_uncached && !remap) > + return NULL; > } > > /* > - * Decrypting memory may block, so allocate the memory from the atomic > - * pools if we can't block. > + * Remapping or decrypting memory may block, allocate the memory from > + * the atomic pools instead if we aren't allowed block. > */ > - if (force_dma_unencrypted(dev) && dma_direct_use_pool(dev, gfp)) > + if ((remap || force_dma_unencrypted(dev)) && > + dma_direct_use_pool(dev, gfp)) > return dma_direct_alloc_from_pool(dev, size, dma_handle, gfp); > > /* we always manually zero the memory once we are done */