Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp2801916rdb; Wed, 4 Oct 2023 11:50:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEHHShsnKQPt0ES1pWIQWKyUpXRN16R55cr/QD94c/sMm0f4M4YuKGOl/LrT7gi1aFldcDa X-Received: by 2002:a9d:4d83:0:b0:6bc:d519:d7b3 with SMTP id u3-20020a9d4d83000000b006bcd519d7b3mr2825967otk.37.1696445458462; Wed, 04 Oct 2023 11:50:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696445458; cv=none; d=google.com; s=arc-20160816; b=JqnMUDyiLbfAYbEc14zsoweReMQdH3Qxbni5Kl2CPbc92aAjpJ2qWgkuVdsYv6q5Qh RTHSFmKA5O3HKqFnmvaRnOxCLHSIZjPOCyp/SxymYo+opQTqo9dJEWOewnag/RrYB8R9 3N5Z8VKhrkByae47ccukmUQOHBZsZrXYZveWQBHXKGZIVJwI/+BDFupIgZDNZyNIXLD2 JBWFOwIq9nPyfn+W3T676tzotTXT8q3/MSnRxyeEhtCd7LsiyqHF4ndkkOyqrj8yETAs ewdr3vYlWxObK5noHNTTHbgEjUPoLF0x6fYdENmd7+jc5AKSfTQPf9ci7fjGb08cs+jG R7jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=aLxg9fH8T1y0yGnPhHcUGUL8dVs76BY9tqGI34u50Bs=; fh=1jyY7/Lmjqf75u9MU2/Wr1/XgOUcFna8Qi7tsbuIHbk=; b=A4fxB1nJH5BiISJ+q2hlTQ8LQciNbYoNhXUolYCjNV2ffdVBUE5EClf9QuK8KXWYad 9Chi8VF3xAVdJw71E9uXQFBRjRcQ0NIeDpkVPemgRTTndEUyB3N3pfxa/yvgev/XOY1j vSkANQCa+eCADM9zwtu6wIFOJmx1I7ldBt8it6UOMSdSYzhxIVuW2ivIHt8MbOjckC/h QvkL0YFjiAk+MwuaMu9FEjQgViBSWr3OgF3b+aTzB6ygiwxDW+J9tUECHCjhqemyqwsu PKqxphvsxFJuqPGG3uJY7NaeBPBzAXoFHcZ74w8qurpgrBE9ktXHtUhRu4TFbBXnGQgg zKUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=QsbIpSBU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id j191-20020a6380c8000000b00570a4303746si4103582pgd.560.2023.10.04.11.50.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 11:50:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=QsbIpSBU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 3836B808D4B8; Wed, 4 Oct 2023 11:50:19 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244207AbjJDSuJ (ORCPT + 99 others); Wed, 4 Oct 2023 14:50:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243785AbjJDSuH (ORCPT ); Wed, 4 Oct 2023 14:50:07 -0400 Received: from mail-qv1-xf2b.google.com (mail-qv1-xf2b.google.com [IPv6:2607:f8b0:4864:20::f2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3BB5AB for ; Wed, 4 Oct 2023 11:50:00 -0700 (PDT) Received: by mail-qv1-xf2b.google.com with SMTP id 6a1803df08f44-65cff6a6878so535136d6.1 for ; Wed, 04 Oct 2023 11:50:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1696445399; x=1697050199; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=aLxg9fH8T1y0yGnPhHcUGUL8dVs76BY9tqGI34u50Bs=; b=QsbIpSBUs1v250EisypmrLo1xZypuMbM2kchknnKaBXNugEvZGKHS6ZnC5LkKIA5HI RkNexXThTo4uZDmP+CH6Ji+frDRYT03SSYNxeH8cmgKaFZgLuaZqX/HbgNhxWazpTJIg SF6OygLNnaOuJHMh42k3lP8vRcYQajUk/goQhWKFF+i0ZBHt33ijTvL+/epwkIPGC3N5 kfE8oiE8pqHarj89/dSVZjC4/XDcGT1Z7eXDvbMyPRhbMVFgerGtkdGOX/5XxhygmSrM VB7mvIWAeLmnsgDnLlICZA725CgpfasFEMSovzPw2eifNm5Hi1e31G4HvHW9gAp1cXq9 ++/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696445399; x=1697050199; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=aLxg9fH8T1y0yGnPhHcUGUL8dVs76BY9tqGI34u50Bs=; b=gZQjig1op49/xfH9ex+GR7abxFCOBHMIk9IoxcC2+MGTy062ye9qJ0T6sifb8IWwn8 flyK15hxPcYEcADCpJzakdP7bWxUnOG9c8lI2d8FQfkl85idXwwXq9tGAQvnUw02Ztx5 /1Teszylq3DvhnA9MaCK0Fad9IJwwCCTglHrPeqOfaWUEGniQemjxh5YqMjaQS2FNiIP vbg4DdD8+pix47QMViiZ94XxE61d6pqzpQJSAg3uLwcIaOhlB4EKZKNN3IqbrlxcnqYe /y87noRFwU3NUqhLzGbDTlsrn1xyWNhvBU71lAlmygrCam0sTATUSGJoFA6Fil1SkTWN tsxA== X-Gm-Message-State: AOJu0YzOlGCi0Jnzk4+I4F+gb0ZipYXPFuv6UAKWHshzUT+ZL8tk0vjv wy0dSngdCiFFzV6XD4rCdevUcw== X-Received: by 2002:a0c:e54f:0:b0:64a:92e9:10e4 with SMTP id n15-20020a0ce54f000000b0064a92e910e4mr2602325qvm.63.1696445399373; Wed, 04 Oct 2023 11:49:59 -0700 (PDT) Received: from ?IPV6:2600:1700:2000:b002:1d3e:176c:909c:5aed? ([2600:1700:2000:b002:1d3e:176c:909c:5aed]) by smtp.gmail.com with ESMTPSA id x1-20020a0ce241000000b0065d89f4d537sm1516928qvl.45.2023.10.04.11.49.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Oct 2023 11:49:58 -0700 (PDT) Message-ID: <20075b03-e3b0-4f29-9ba1-98eed361a44f@sifive.com> Date: Wed, 4 Oct 2023 13:49:56 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 0/6] RISC-V: Add eMMC support for TH1520 boards Content-Language: en-US To: "Lad, Prabhakar" , Robin Murphy Cc: 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 References: <20230921-th1520-mmc-v1-0-49f76c274fb3@baylibre.com> From: Samuel Holland In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=2.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.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 (agentk.vger.email [0.0.0.0]); Wed, 04 Oct 2023 11:50:19 -0700 (PDT) X-Spam-Level: ** On 2023-10-04 12:16 PM, Lad, Prabhakar wrote: > On Wed, Oct 4, 2023 at 5:03 PM Lad, Prabhakar > wrote: >> >> On Wed, Oct 4, 2023 at 3:18 PM Robin Murphy wrote: >>> >>> On 04/10/2023 3:02 pm, Icenowy Zheng wrote: >>> [...] >>>>>>> I believe commit 484861e09f3e ("soc: renesas: Kconfig: Select the >>>>>>> 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 every >>>> core that does not support Svpbmt or vendor-specific alternatives, >>>> because the original RISC-V priv spec does not define memory attributes >>>> 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-mode >>>> (which MMU is enabled in) just sees fixed memory attributes, in this >>>> 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 to do >>> some fiddly work in dma-direct to a) introduce the notion of an optional >>> 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 *dev, > 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_after_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 size, > 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, size, > dma_handle); dma_alloc_from_global_coherent() already checks dma_coherent_default_memory, 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 = dma_alloc_from_global_coherent(dev, size, dma_handle); + if (ret) + return ret; /* * Otherwise remap if the architecture is asking for it. But Regards, Samuel