Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp2858164rdb; Wed, 4 Oct 2023 13:48:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEIDg/uwJcbQ+2xZdo9j6H/qpoSJ6sii3OpndlaaXkuREQ9E167aM036CgmN8VFeylR2BJU X-Received: by 2002:a17:90a:d718:b0:277:61d7:78be with SMTP id y24-20020a17090ad71800b0027761d778bemr1011006pju.14.1696452522624; Wed, 04 Oct 2023 13:48:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696452522; cv=none; d=google.com; s=arc-20160816; b=fAKbJN8sBAXPGgdBJu6b4HDyr70lzfxEOU1pU6eeu9GZuqjxwac9MLudzaT5ITm4gI 559B/Q4Gt1gCDNKfBZX729HzHzU1t51Kfjc5dybazSQy30agYx7zsaeEyzxZdnn1zt4O hSXTOiyX+56ykhDj6rYvJ7KEXcXPIsEvn2V9gF0NmugoCKxVAIVgjKCpJ9THnoRH6tvA m5lYQE3RrqOZZkYQsM2bCBsRVL5liN2kg+zMwYDtf8dGAv/11nlBFcgajs1gYhBWjJ0l BZGAxYsRnIi5yBptNEmGD/g+/wUNxBzvU9NbF7obMR+q+w7EZsRaC75Xbq/WbAVj/hlK Ziew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=HfMc2o3aeaMtgo1tIGkp8mKMdGYs27vkJXRJNkCUQ0A=; fh=I1SUrR2QQxqZ4aolr5RqRf1+BBqViQ6rl5dHDRQgTnw=; b=SgZ99EMPzm568o5MlTSpkjGiNGBT1L2APA7fhOf8Lm+XhMMkfAYgPoTjuKTw/FQTZe sd+RtLhNxYwwYAP1wNSmnzZ1m/NRySGf4infzUqsM7eJE0UCst5MAGg+AuKBZUhpcQW6 +NFj/P/MEL6CaXGRUICfCBDEYomHgbk3nfEgw2YVaWvR7aouFGEuIUkQ21oW6ZsuetkW egyVqfgdfBgj5OVy1EI2dPGm953gmYiyLFQqSBqzxTSGGQz4MGGaPJt+8EKFAV208Jps trLTvKFJrs3DGsoMB7g1QPvRg1zQzx0MeKMxNTrunUT4Dokyt2Kg64G0n1y7Rp7K6I+Z MfRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=gtaAswo8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id i62-20020a638741000000b00578086d1387si4194487pge.74.2023.10.04.13.48.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 13:48:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=gtaAswo8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 9D0D280BD5FB; Wed, 4 Oct 2023 13:48:39 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243766AbjJDUsF (ORCPT + 99 others); Wed, 4 Oct 2023 16:48:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233286AbjJDUsE (ORCPT ); Wed, 4 Oct 2023 16:48:04 -0400 Received: from mail-vk1-xa29.google.com (mail-vk1-xa29.google.com [IPv6:2607:f8b0:4864:20::a29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8400BF; Wed, 4 Oct 2023 13:48:00 -0700 (PDT) Received: by mail-vk1-xa29.google.com with SMTP id 71dfb90a1353d-49d45964fcaso916735e0c.1; Wed, 04 Oct 2023 13:48:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696452480; x=1697057280; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=HfMc2o3aeaMtgo1tIGkp8mKMdGYs27vkJXRJNkCUQ0A=; b=gtaAswo8hQfyNdz0TsBfYA1dZ/cinoQwqTodnlwWfIkqJ/yJZys/YfWKh8hWMRBnRP Kk0tAoxPtQEGaSSBWiw1JaF7iXDjjs5A8os5Yoj2LP1yVdBq8YsjXOK764QsiHYPx6Y7 /CqlfON3kgNETZYRjj4BNkO3IgC8WGauFrjnIrtY5gwoz8aWUTq0TNCN+o+P2BjF14ER XovCoSNEZ/BEtRFVqgSKcWVd39htGYGx2i817rhIDQF58LRW6agAOOfxgyD1kpRs5pfs bNKAaH7TterUEJHOFeonofRoadxP7YlBITcGhxSoflxVxeAcYdzWkLYizkRSCOD0ISMT HPAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696452480; x=1697057280; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HfMc2o3aeaMtgo1tIGkp8mKMdGYs27vkJXRJNkCUQ0A=; b=Zy8iHRWu6lSPcDU9DyxmIglgwyhPhtKaPK0r0n1qoSzI2XOyiZyTcUmiwUvFIVV/LI NBRAarlIz0W82DD8PS3eaXONSl+Q39+fYiPBdaxMhM1GPswFQsjpaxu2OlZ0MlG40U3Y jYaEqdpwwEoAe+tPTLK+q3VIKXKmb0VwbNvkxzeASgZ4fE1J51Juzjy6lQyn/gWx5dmP wx4oTD/NFYOyOmInOrmDTuMhjBVCbzStBhbaLdnUhZvZI3cXIOIgvtd7Fn9MCK7yOscq vYuUKOoslfUdigCJjff2KiOb16AH5g7id+oPZ5PM79lB/tDyYMw8PoF0SzeQJb7d3VUR t8kw== X-Gm-Message-State: AOJu0YxmRPyknXFtn5JE0u7a0H/gmF2lkT9uWTvtIa+nXuVQHcAC1u7L AxGEj40igiiONwimTQf6uPGeap+LkMG+KhrEfuw= X-Received: by 2002:a05:6122:178a:b0:495:f495:bab1 with SMTP id o10-20020a056122178a00b00495f495bab1mr442731vkf.0.1696452478361; Wed, 04 Oct 2023 13:47:58 -0700 (PDT) MIME-Version: 1.0 References: <20230921-th1520-mmc-v1-0-49f76c274fb3@baylibre.com> <20075b03-e3b0-4f29-9ba1-98eed361a44f@sifive.com> <498ffcef-2ff9-495b-8544-b87c5c2eb6e1@arm.com> In-Reply-To: <498ffcef-2ff9-495b-8544-b87c5c2eb6e1@arm.com> From: "Lad, Prabhakar" Date: Wed, 4 Oct 2023 21:47:03 +0100 Message-ID: Subject: Re: [PATCH 0/6] RISC-V: Add eMMC support for TH1520 boards To: Robin Murphy Cc: Samuel Holland , Ulf Hansson , Jisheng Zhang , Drew Fustini , linux-kernel@vger.kernel.org, Linux-MM , Guo Ren , Krzysztof Kozlowski , linux-riscv@lists.infradead.org, Christoph Hellwig , Geert Uytterhoeven , Fabrizio Castro , devicetree@vger.kernel.org, Conor Dooley , Albert Ou , Alexandre Ghiti , Arnd Bergmann , Han Gao , Lad Prabhakar , Jason Kridner , Paul Walmsley , Robert Nelson , linux-mmc@vger.kernel.org, Adrian Hunter , Conor Dooley , =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= , Rob Herring , Palmer Dabbelt , Xi Ruoyao , Fu Wei Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=3.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_SBL_CSS, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Wed, 04 Oct 2023 13:48:39 -0700 (PDT) X-Spam-Level: ** On Wed, Oct 4, 2023 at 8:38=E2=80=AFPM Robin Murphy = wrote: > > On 2023-10-04 19:49, Samuel Holland wrote: > > On 2023-10-04 12:16 PM, Lad, Prabhakar wrote: > >> On Wed, Oct 4, 2023 at 5:03=E2=80=AFPM Lad, Prabhakar > >> wrote: > >>> > >>> On Wed, Oct 4, 2023 at 3:18=E2=80=AFPM Robin Murphy wrote: > >>>> > >>>> On 04/10/2023 3:02 pm, Icenowy Zheng wrote: > >>>> [...] > >>>>>>>> I believe commit 484861e09f3e ("soc: renesas: Kconfig: Select th= e > >>>>>>>> required configs for RZ/Five SoC") can cause regression on all > >>>>>>>> non-dma-coherent riscv platforms with generic defconfig. This is > >>>>>>>> a common issue. The logic here is: generic riscv defconfig > >>>>>>>> selects > >>>>>>>> ARCH_R9A07G043 which selects DMA_GLOBAL_POOL, which assumes all > >>>>>>>> non-dma-coherent riscv platforms have a dma global pool, this > >>>>>>>> assumption > >>>>>>>> seems not correct. And I believe DMA_GLOBAL_POOL should not be > >>>>>>>> selected by ARCH_SOCFAMILIY, instead, only ARCH under some > >>>>>>>> specific > >>>>>>>> conditions can select it globaly, for example NOMMU ARM and so > >>>>>>>> on. > >>>>>>>> > >>>>>>>> Since this is a regression, what's proper fix? any suggestion is > >>>>>>>> appreciated. > >>>>>> > >>>>>> I think the answer is to not select DMA_GLOBAL_POOL, since that is > >>>>>> only > >>>>> > >>>>> Well I think for RISC-V, it's not NOMMU only but applicable for eve= ry > >>>>> core that does not support Svpbmt or vendor-specific alternatives, > >>>>> because the original RISC-V priv spec does not define memory attrib= utes > >>>>> in page table entries. > >>>>> > >>>>> For the Renesas/Andes case I think a pool is set by OpenSBI with > >>>>> vendor-specific M-mode facility and then passed in DT, and the S-mo= de > >>>>> (which MMU is enabled in) just sees fixed memory attributes, in thi= s > >>>>> case I think DMA_GLOBAL_POOL is needed. > >>>> > >>>> Oh wow, is that really a thing? In that case, either you just can't > >>>> support this platform in a multi-platform kernel, or someone needs t= o do > >>>> some fiddly work in dma-direct to a) introduce the notion of an opti= onal > >>>> global pool, > >>> Looking at the code [0] we do have compile time check for > >>> CONFIG_DMA_GLOBAL_POOL irrespective of this being present in DT or > >>> not, instead if we make it compile time and runtime check ie either > >>> check for DT node or see if pool is available and only then proceed > >>> for allocation form this pool. > >>> > >>> What are your thoughts on this? > >>> > >> Something like the below: > >> > >> diff --git a/include/linux/dma-map-ops.h b/include/linux/dma-map-ops.h > >> index f2fc203fb8a1..7bf41a4634a4 100644 > >> --- a/include/linux/dma-map-ops.h > >> +++ b/include/linux/dma-map-ops.h > >> @@ -198,6 +198,7 @@ int dma_release_from_global_coherent(int order, > >> void *vaddr); > >> int dma_mmap_from_global_coherent(struct vm_area_struct *vma, void *= cpu_addr, > >> size_t size, int *ret); > >> int dma_init_global_coherent(phys_addr_t phys_addr, size_t size); > >> +bool dma_global_pool_available(void); > >> #else > >> static inline void *dma_alloc_from_global_coherent(struct device *de= v, > >> ssize_t size, dma_addr_t *dma_handle) > >> @@ -213,6 +214,10 @@ static inline int > >> dma_mmap_from_global_coherent(struct vm_area_struct *vma, > >> { > >> return 0; > >> } > >> +static inline bool dma_global_pool_available(void) > >> +{ > >> + return false; > >> +} > >> #endif /* CONFIG_DMA_GLOBAL_POOL */ > >> > >> /* > >> diff --git a/kernel/dma/coherent.c b/kernel/dma/coherent.c > >> index c21abc77c53e..605f243b8262 100644 > >> --- a/kernel/dma/coherent.c > >> +++ b/kernel/dma/coherent.c > >> @@ -277,6 +277,14 @@ int dma_mmap_from_dev_coherent(struct device > >> *dev, struct vm_area_struct *vma, > >> #ifdef CONFIG_DMA_GLOBAL_POOL > >> static struct dma_coherent_mem *dma_coherent_default_memory __ro_aft= er_init; > >> > >> +bool dma_global_pool_available(void) > >> +{ > >> + if (!dma_coherent_default_memory) > >> + return false; > >> + > >> + return true; > >> +} > >> + > >> void *dma_alloc_from_global_coherent(struct device *dev, ssize_t siz= e, > >> dma_addr_t *dma_handle) > >> { > >> diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c > >> index 9596ae1aa0da..a599bb731ceb 100644 > >> --- a/kernel/dma/direct.c > >> +++ b/kernel/dma/direct.c > >> @@ -235,7 +235,7 @@ void *dma_direct_alloc(struct device *dev, size_t = size, > >> * If there is a global pool, always allocate from it= for > >> * non-coherent devices. > >> */ > >> - if (IS_ENABLED(CONFIG_DMA_GLOBAL_POOL)) > >> + if (IS_ENABLED(CONFIG_DMA_GLOBAL_POOL) && > >> dma_global_pool_available()) > >> return dma_alloc_from_global_coherent(dev, si= ze, > >> dma_handle); > > > > dma_alloc_from_global_coherent() already checks dma_coherent_default_me= mory, so > > the solution could be even simpler: > > > > --- a/kernel/dma/direct.c > > +++ b/kernel/dma/direct.c > > @@ -232,12 +232,12 @@ void *dma_direct_alloc(struct device *dev, size_t= size, > > attrs); > > > > /* > > - * If there is a global pool, always allocate from it for > > + * If there is a global pool, always try to allocate from= it for > > * non-coherent devices. > > */ > > - if (IS_ENABLED(CONFIG_DMA_GLOBAL_POOL)) > > - return dma_alloc_from_global_coherent(dev, size, > > - dma_handle); > > + ret =3D dma_alloc_from_global_coherent(dev, size, dma_han= dle); > > + if (ret) > > + return ret; > > So if allocation fails because the pool is full, we should go ahead and > remap something that can't work? ;) > > The dma_global_pool_available() idea sort of works, but I'm still > concerned about the case where it *should* have been available but the > platform has been misconfigured, so again we fall through to > If the platform is misconfigured it is bound to fail anyway so should we consider that as a valid case? > DMA_DIRECT_REMAP "successfully" returning a coherent buffer that isn't, > and the user's filesystem gets corrupted. Or at best, they get confused > by weird errors from random devices going wrong. That's why I said it > would be fiddly - the current state of DMA_GLOBAL_POOL as a binary > arch-wide thing is relatively robust and easy to reason about, but > attempting to generalise it further is... less so. > > Thanks, > Robin. > Cheers, Prabhakar