Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1134313rwd; Wed, 31 May 2023 09:52:40 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ655FlMAMop/PhdEiahAg+TolJm/o0HBJyKfDmX3+YHYq2G2I8cd2J27u6N7pBWSum59eVl X-Received: by 2002:a17:903:258e:b0:1ac:8be5:8787 with SMTP id jb14-20020a170903258e00b001ac8be58787mr4151068plb.21.1685551959864; Wed, 31 May 2023 09:52:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685551959; cv=none; d=google.com; s=arc-20160816; b=BX0xCj4YKzkYE5Z9NMHBe3IbA9xABrSyhegNudIv/ALtB26e3HY4h2ZCpRHyPQFV3A CBfAFPkYY0ZA2FMkbKnPV9pklhfOZW0+NCNZjstGEaiiXy1bnaH7oF1WQglYh1A4VNMY YCxVqa/MJ9duErHKyoSPFSczcrHFzUOmfs0cLe00k0QGZcq2ICin8P0i7nqohknrqwUA k/pMhfZSgTGPVrv+Y9OSW2OXGa7LfcWqLUY4JrUC2hlHh0ZIt2OYUF/QJrwyP34aJ5Rd Smoz95hp7e2vuU5zsTx/38MvVVBKNTGWOVe00KJTXRsnNVTYVCRAEjI5K2AaZbXWO/Qz mhkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=O4/5nyl+5ZexLNd+R1XRwaxOm0NqeNIfLzJu8DJJcqw=; b=SWgovA4mimdzgpvLAK8SpbiGpUmpLlWjdn0cfVfvK8R2938qfhhrOFAqhQa+Mtl4Sc ocJ+hLuhZjFNncAUZhzptDLaNNAgE20hSWnq3Il0VgI+YwQhXXVt6H+3OfsOAz6Bj7AV wBS7PbUt4g8ppfQYkgsej9WoMc+Yiu2Tm3KGt8woJevJVUl5O0uWqg0X1P7wzAMi/nh4 zCOfHbd5ip+6kbAAGN8sU1/Vi37rcminJhRt/BCYNPWgKGs+vl5kZ8kFJom8P6U/lECR it6Hk0ik3yR6aoERLVUCX671d0tChWKgsrRC5UBT2ZoRM04+NP7ik9Cg262JWiveJsAu Dhzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IuhjRqmq; 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 z18-20020a170903019200b001b06fa47440si1191935plg.352.2023.05.31.09.52.24; Wed, 31 May 2023 09:52:39 -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=IuhjRqmq; 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 S229683AbjEaQ32 (ORCPT + 99 others); Wed, 31 May 2023 12:29:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229668AbjEaQ31 (ORCPT ); Wed, 31 May 2023 12:29:27 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 843DF1AD for ; Wed, 31 May 2023 09:29:09 -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 2C85F63DCE for ; Wed, 31 May 2023 16:29:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E0B26C433D2; Wed, 31 May 2023 16:28:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685550540; bh=2DPmqH41nj7TTQeLCW2cj8dAxqMnQAvSWlrm0fLb+0s=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=IuhjRqmqy+q7X4w8AXgprvr+XbiiHE8U7fo3RFN/LJJSzFlUEnehvi1OZCkHpJ6v7 OUUjGEfmu7tjvnkEuojRNtIytQBpZp/S90wMZmiY4aSLLiigcvEhs8BcqHYmG7k3HO aZpnbYLGP8/WRogGHBP5gJBn9/XTXh7CkdiIDMk+Miuq5WHiEXfNkLK+nEp82W3OFg QEQtbwTlLjr6YhzD53zGcKUVjtw6gLviaYvSy/QMBMhqcGAIS6vfUhFRtRIPOi3Vn+ e/D7eU70svoa85j/BRVTWXlavd7B6/AAbpUjCGT9By1HzSXIzhZ3ZXYzSCybCVGmjW QzGngXOVRITJw== Date: Wed, 31 May 2023 17:28:56 +0100 From: Conor Dooley To: Jisheng Zhang Cc: Conor Dooley , Paul Walmsley , Palmer Dabbelt , Albert Ou , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Catalin Marinas Subject: Re: [PATCH 4/6] riscv: mm: pass noncoherent or not to riscv_noncoherent_supported() Message-ID: <20230531-applied-antacid-77abfb5b2e55@spud> References: <20230526165958.908-1-jszhang@kernel.org> <20230526165958.908-5-jszhang@kernel.org> <20230529-gainfully-ribbon-48520d25ef6e@wendy> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="BjOrWNtSKlv6yyL3" Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, 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 --BjOrWNtSKlv6yyL3 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, May 31, 2023 at 11:28:22PM +0800, Jisheng Zhang wrote: > On Wed, May 31, 2023 at 11:24:19PM +0800, Jisheng Zhang wrote: > > On Mon, May 29, 2023 at 12:13:10PM +0100, Conor Dooley wrote: > > > On Sat, May 27, 2023 at 12:59:56AM +0800, Jisheng Zhang wrote: > > > > We will soon take different actions by checking the HW is noncohere= nt > > > > or not, I.E ZICBOM/ERRATA_THEAD_CMO or not. > > > >=20 > > > > Signed-off-by: Jisheng Zhang > > > > --- > > > > arch/riscv/errata/thead/errata.c | 19 +++++++++++-------- > > > > arch/riscv/include/asm/cacheflush.h | 4 ++-- > > > > arch/riscv/kernel/setup.c | 6 +++++- > > > > arch/riscv/mm/dma-noncoherent.c | 10 ++++++---- > > > > 4 files changed, 24 insertions(+), 15 deletions(-) > > > >=20 > > > > diff --git a/arch/riscv/errata/thead/errata.c b/arch/riscv/errata/t= head/errata.c > > > > index be84b14f0118..c192b80a5166 100644 > > > > --- a/arch/riscv/errata/thead/errata.c > > > > +++ b/arch/riscv/errata/thead/errata.c > > > > @@ -36,21 +36,24 @@ static bool errata_probe_pbmt(unsigned int stag= e, > > > > static bool errata_probe_cmo(unsigned int stage, > > > > unsigned long arch_id, unsigned long impid) > > > > { > > > > - if (!IS_ENABLED(CONFIG_ERRATA_THEAD_CMO)) > > > > - return false; > > > > - > > > > - if (arch_id !=3D 0 || impid !=3D 0) > > > > - return false; > > > > + bool cmo; > > > > =20 > > > > if (stage =3D=3D RISCV_ALTERNATIVES_EARLY_BOOT) > > > > return false; > > > > =20 > > > > + if (IS_ENABLED(CONFIG_ERRATA_THEAD_CMO) && > > > > + (arch_id =3D=3D 0 && impid =3D=3D 0)) > > > > + cmo =3D true; > > > > + else > > > > + cmo =3D false; > > > > + > > > > if (stage =3D=3D RISCV_ALTERNATIVES_BOOT) { > > > > - riscv_cbom_block_size =3D L1_CACHE_BYTES; > > > > - riscv_noncoherent_supported(); > > > > + if (cmo) > > > > + riscv_cbom_block_size =3D L1_CACHE_BYTES; > > > > + riscv_noncoherent_supported(cmo); > > > > } > > > > =20 > > > > - return true; > > > > + return cmo; > > >=20 > > > I don't really understand the changes that you are making to this > > > function, so that is tries really hard to call > > > riscv_noncoherent_supported(). Why do we need to always call the func= tion > > > in the erratum's probe function, if the erratum is not detected, given > >=20 > > In one unified kernel Image, to support both coherent and noncoherent > > platforms(currently, either T-HEAD CMO or ZICBOM), we need to let the > > kmalloc meet both cases, specifically, ARCH_DMA_MINALIGN aligned. >=20 > seems adding three words can make it better: >=20 > kmalloc meet both cases at the beginning, specifically ... >=20 > > Once we know the underlying HW is coherent, I.E neither T-HEAD CMO nor > > ZICBOM, we need to notice kmalloc we are safe to reduce the alignment > > to 1. The notice action is done in patch 5: > >=20 > > + } else { > > + dma_cache_alignment =3D 1; > >=20 > >=20 > > > that riscv_noncoherent_supported() is called immediately after > > > apply_boot_alternatives() in setup_arch()? This bit here is the key part of my confusion. You try really hard in the errata stuff to call riscv_noncoherent_supported(), which I do understand is because of the other branch that you add to the function later in the series. What I do not understand is why we are not able to rely on the call to it in setup_arch() to trigger it when we do not have T-HEAD CMOs or Zicbom. You've explained why you want to make sure it always gets called during boot, but my question is about why it looks like it is being called more than once. Actually, now that I think of it, what happens on a T-HEAD system where there is no T-HEAD CMOs, but there is Zicbom. In theory, this could exist. Bear with me here a moment in case I am completely wrong, snippet is =66rom setup_arch() apply_boot_alternatives(); On my example system, this will trigger, eventually sending us into errata_probe_cmo(), where we will call riscv_noncoherent_supported() with false, setting dma_cache_alignment to 1. if (IS_ENABLED(CONFIG_RISCV_ISA_ZICBOM) && riscv_isa_extension_available(NULL, ZICBOM)) cmo =3D true; On this system, this will be true. else cmo =3D false; riscv_noncoherent_supported(cmo); now riscv_noncoherent_supported() is called with true, and we have dma_cache_alignment =3D 1 still. Is that not problematic? Or the inverse, where the T-HEAD system has its custom CMOs and there is no Zicbom, it gets called twice with different args too. There's clearly something fundamental that I am missing here, this seems like it should be immediately obvious why this either cannot happen or is not a problem, but I can't see it. Sorry, Conor. --BjOrWNtSKlv6yyL3 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iHUEABYIAB0WIQRh246EGq/8RLhDjO14tDGHoIJi0gUCZHd1tQAKCRB4tDGHoIJi 0pGNAPwLSwfmm5OuyEL8BRsFeMVHyDtHAo2DcjggAIKEVSHDngEA0jAajERdcZXM dZ5aJkHDIEmfSvibu/CfaGJlDgFknQY= =AxKn -----END PGP SIGNATURE----- --BjOrWNtSKlv6yyL3--