Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp306511rdh; Thu, 26 Oct 2023 02:48:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGHz99PGyWV1/FlFJV3EIMB/ZrguMYsGaVaoh+3nLevWznkU5Qy1fJ8NB53SX4plurrF4ZQ X-Received: by 2002:a05:6122:36aa:b0:49a:466c:199e with SMTP id ec42-20020a05612236aa00b0049a466c199emr19262530vkb.2.1698313713398; Thu, 26 Oct 2023 02:48:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698313713; cv=none; d=google.com; s=arc-20160816; b=h5oRenQW2k+M5c7D+RtdCJHuWuHXxMCqDDarnL1aBcqE5dx463TRV0KKjhXb0uwcZP WPG85dXsGOgUJP2FPlqX7zBJukRlU587nNYALK0otZvilm4kc4IErDjwTr7VtiWEcXSp wKTBhYZDDpfjvB+eRSlkRatojaKZNDEOzxpv71Cj9hjslOtTANOK+rd1yqs6JwzHzoOG X7Gh3yJhgldVh6KBv2PfKNiDF+BeesFmHuY4qb+89JfTGddwKNB1GzI4PgWqqldGKgon OGscAUmXkW1G/syc9cnLvq4QOBg+/1MnCm9AZmlZYCDS6sR66uI1I4UmPRoP4UDtCI6s bBQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date:dkim-signature; bh=2Qfs24gfJt/+wQeHvdahT1FlAyEmsw/aPQR+CMjadlg=; fh=BZUIbKTvNaWWi8NpBbHHqJKbr9CgeiODVt8vvMN93ZY=; b=RHrFKHRZKlUiMYzVcBMz4kF8dBR8PV6jWvw1+s9DbmdVW8DgamP9qHzW05eL+L6nQw ZnMNaX1c5J7RPahf0zUk4Q3R7w/p+sB8MiLhWdHHI/OTbqspB0oqhQh20vYVVVko2g1l ZtxNWbYib7DlBGHkNs+y7FJ4FoYzlbsv5IobxtG5Ju1s0FgyVitsKZNxbdUHbAAgTMPS dK3ZDVCXZYZTnSkJMGOwTGzDEAyRGS47bXDzp/CfAOVAmCJYFICI8ADvn3oHyyb1Fzhv VfKdfZZ3czLTSquX10xuEoFgoXqtx+Z9EK7GUnsAp+JkThOTicH9wMNhly6HqS8x2iv2 Vr6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Qh1MXEyM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id m81-20020a0dca54000000b005a7bc7881c7si13340937ywd.306.2023.10.26.02.48.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 02:48:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Qh1MXEyM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 9392480EE777; Thu, 26 Oct 2023 02:48:29 -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 S230030AbjJZJsN (ORCPT + 99 others); Thu, 26 Oct 2023 05:48:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229791AbjJZJsM (ORCPT ); Thu, 26 Oct 2023 05:48:12 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D9BB198 for ; Thu, 26 Oct 2023 02:48:09 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 28491C433C7; Thu, 26 Oct 2023 09:48:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1698313689; bh=m4K6I24gIzB9BEoM41jPYXXjvqkA7hNcqLdkKLZniac=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Qh1MXEyMRsZLlL1JUNqEdadQCjdW8famLwX+f0ofG+gkNFPp+UA71u57siF3UTuDQ NJ67HK70KU1xhb30RaOmdFULUZ9mvhrMn6Ig6b7jROVFvrmO1cgVpq16kF9X7KBOVz R0pS8fbJdWzlW97rdhe7YxutiK2GMKgAF2cCXH9XGXRyvHayVdw1rou+AnZrPFeF3p h0nTsoMxUAyXpjLfxUhsJkiNUuG25Xf7gB+Ai4a6pj2I+iVd9Ma6i7BenSzPc5nvp8 tRhJJugR+HBJv19ociccQ/o+YN/K+5g21PxsunazoiKmdJa1UJCfgHlp7wyc7EFc5w RGZ6tjisAXosw== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1qvwyD-007qfE-Ex; Thu, 26 Oct 2023 10:48:06 +0100 Date: Thu, 26 Oct 2023 10:48:05 +0100 Message-ID: <86bkcl4sve.wl-maz@kernel.org> From: Marc Zyngier To: Fang Xiang Cc: , , Subject: Re: [PATCH] irqchip/gic-v3-its: Fix the coherent issue in its_setup_baser() when shr = 0. In-Reply-To: References: <20231026020116.4238-1-fangxiang3@xiaomi.com> <87sf5x6cdu.wl-maz@kernel.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/29.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: fangxiang3@xiaomi.com, tglx@linutronix.de, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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]); Thu, 26 Oct 2023 02:48:29 -0700 (PDT) On Thu, 26 Oct 2023 09:48:13 +0100, Fang Xiang wrote: > > On Thu, Oct 26, 2023 at 09:01:17AM +0100, Marc Zyngier wrote: > > On Thu, 26 Oct 2023 03:01:16 +0100, > > Fang Xiang wrote: > > > > > > The table would not be flushed if the input parameter shr = 0 in > > > its_setup_baser() and it would cause a coherent problem. > > > > Would? Or does? I'm asking, as you have previously indicated that this > > workaround was working for you. > > > > Have you actually observed a problem? Or is that by inspection? > > > I actually observed this problem on my device. GIC get a dirty table > because CPU did not flush the clean one to memory. So how comes you previously reported that it was working for you? > > > > > > Signed-off-by: Fang Xiang > > > --- > > > drivers/irqchip/irq-gic-v3-its.c | 8 +++++--- > > > 1 file changed, 5 insertions(+), 3 deletions(-) > > > > > > diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c > > > index 75a2dd550625..58a9f24ccfa7 100644 > > > --- a/drivers/irqchip/irq-gic-v3-its.c > > > +++ b/drivers/irqchip/irq-gic-v3-its.c > > > @@ -2394,13 +2394,15 @@ static int its_setup_baser(struct its_node *its, struct its_baser *baser, > > > * non-cacheable as well. > > > */ > > > shr = tmp & GITS_BASER_SHAREABILITY_MASK; > > > - if (!shr) { > > > + if (!shr) > > > cache = GITS_BASER_nC; > > > - gic_flush_dcache_to_poc(base, PAGE_ORDER_TO_SIZE(order)); > > > - } > > > + > > > goto retry_baser; > > > } > > > > > > + if (!shr) > > > + gic_flush_dcache_to_poc(base, PAGE_ORDER_TO_SIZE(order)); > > > + > > > > This is wrong. You're doing the cache clean *after* the register has > > been programmed with its final value, and the ITS is perfectly allowed > > to prefetch anything it wants as soon as you program the register. The > > clean must thus happen before the write. Yes, it was wrong before, but > > you are now making it wrong always. > Sorry for that. But on my device, GIC would not read the table before > ITS enable(GITS_CTLR.Enabled == 1). When ITS is disabled, the prefetch > happens ever in other platforms? GITS_CTLR.Enabled == 1 controls the *translation* (i.e. whether a write to GITS_TRANSLATER gets processed or not). It doesn't say anything of the tables that are pointed to by the ITS. If you care to read the spec, you will find this (Arm IHI 0069H, page 5-95, "Software access to the private ITS tables"): * For a table that is pointed to by a GITS_BASER register for which GITS_BASER.Valid == 1 and GITS_BASER.Indirect == 0, behavior is UNPREDICTABLE if the table is written by software. and a cache clean definitely counts as a write from the PoV of the ITS. What your device does is pretty much irrelevant, as the architecture allows any sort of access as soon as the Valid bit is set. > > > > > if (val != tmp) { > > > pr_err("ITS@%pa: %s doesn't stick: %llx %llx\n", > > > &its->phys_base, its_base_type_string[type], > > > > Overall, I think we need a slightly better fix. Since non-coherent > > ITSs are quickly becoming the common case, we can save ourselves some > > effort and hoist the quirked attributes early. > > > > Does the hack below work for you? > > > > M. > > > > diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c > > index 75a2dd550625..d76d44ea2de1 100644 > > --- a/drivers/irqchip/irq-gic-v3-its.c > > +++ b/drivers/irqchip/irq-gic-v3-its.c > > @@ -2379,12 +2379,12 @@ static int its_setup_baser(struct its_node *its, struct its_baser *baser, > > break; > > } > > > > + if (!shr) > > + gic_flush_dcache_to_poc(base, PAGE_ORDER_TO_SIZE(order)); > > + > > its_write_baser(its, baser, val); > > tmp = baser->val; > > > > - if (its->flags & ITS_FLAGS_FORCE_NON_SHAREABLE) > > - tmp &= ~GITS_BASER_SHAREABILITY_MASK; > > - > > if ((val ^ tmp) & GITS_BASER_SHAREABILITY_MASK) { > > /* > > * Shareability didn't stick. Just use > > @@ -2394,10 +2394,9 @@ static int its_setup_baser(struct its_node *its, struct its_baser *baser, > > * non-cacheable as well. > > */ > > shr = tmp & GITS_BASER_SHAREABILITY_MASK; > > - if (!shr) { > > + if (!shr) > > cache = GITS_BASER_nC; > > - gic_flush_dcache_to_poc(base, PAGE_ORDER_TO_SIZE(order)); > > - } > > + > > goto retry_baser; > > } > > > > @@ -2609,6 +2608,11 @@ static int its_alloc_tables(struct its_node *its) > > /* erratum 24313: ignore memory access type */ > > cache = GITS_BASER_nCnB; > > > > + if (its->flags & ITS_FLAGS_FORCE_NON_SHAREABLE) { > > + cache = GITS_BASER_nC; > > + shr = 0; > > + } > > + > > for (i = 0; i < GITS_BASER_NR_REGS; i++) { > > struct its_baser *baser = its->tables + i; > > u64 val = its_read_baser(its, baser); > > > There maybe a risk in this patch above when non-shareable attibute indicated > by hardware, the table would not be flushed ever. How? If the HW rejects the shareability attribute, we set shr to 0 and hit the retry path. At this point, we will clean the page to the PoC before writing the register again. What am I missing? M. -- Without deviation from the norm, progress is not possible.