Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp372811rdh; Thu, 26 Oct 2023 04:54:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE2VlqCX4m9AS0zzT89lwlew+pN2BJbF5/vva7F32hULMsiQieRwEHg90xsrGppSUsnfLJK X-Received: by 2002:a81:d20a:0:b0:5a7:fb66:61ff with SMTP id x10-20020a81d20a000000b005a7fb6661ffmr3839901ywi.21.1698321293667; Thu, 26 Oct 2023 04:54:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698321293; cv=none; d=google.com; s=arc-20160816; b=BAtaNY81SD7fBodNfwdG229WCXlrtfj8TFTwHph18kT+/LVD0rrlIHCTxOdEYlOzK3 ZOMtdX1pOlJCyjqYQvewqKI7s1AzIoOxmuZji1eUL3Nngvq9T257Qx6sTaSMzuUit3gL H4XGpTVXyCF3hGB4F+1VZkjzX84Ybnyx5GUcXdy6El6dOVxFKC3QKUeLX9STrtNjCO4s LTNO+q+cRAM0TV2kCwud82AzWemvBZ4cpzgAgAHEZt526TVrT6Tv8sI9zs36kXqKyNw6 YQcEWDXJo9ClyueDiDYUqG04XzHCrsLXRSefwaw6Dv9L8qit2uOByOTCFo6t9FDU3TlL RsBg== 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; bh=iN5LWFZts7RqezZAaCHf70+beBXM2h5lkTXF7RgutEs=; fh=85fMwhMCxW3cInIV98XJuVDN4GMT61CpqEcFLP3GFyI=; b=ydGYkStcgJb02CL6eL06cTcYYtR9BBX6A1aeUfpV8tFxqAi+G7RMDanHXFxrICGHa8 /YnVROrW9bg1KxAjapYEWWijjY9t8KSyO8S9szEXM/DyPccVTVCY/7R/bote8k0LF63Y nccP7E7NKQy9Fy5qOs0dH5tPUDgO9oDX2g7Gq8p+lr56rVU56gwbkNvAc3h336DbxMlr bwmkOfDSXhrYbnraPi7sQi0/+3c8azvFZSBlKl5TyueCYnHa9T07A/NbE1ijiz9c6ZvB NFY/i7lk2E2x06AWW6+nnYynNSpB3xEUoBCLYm6aiqcEVRVsrlm1xDMwgkSzSxKiO3hC TK+A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=xiaomi.com Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id b7-20020a0df207000000b005a7d03fbab5si13617591ywf.340.2023.10.26.04.54.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 04:54:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=xiaomi.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 555A7823367E; Thu, 26 Oct 2023 04:54:50 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230321AbjJZLyh (ORCPT + 99 others); Thu, 26 Oct 2023 07:54:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230455AbjJZLyf (ORCPT ); Thu, 26 Oct 2023 07:54:35 -0400 Received: from outboundhk.mxmail.xiaomi.com (outboundhk.mxmail.xiaomi.com [207.226.244.122]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 849011AC for ; Thu, 26 Oct 2023 04:54:30 -0700 (PDT) X-IronPort-AV: E=Sophos;i="6.03,253,1694707200"; d="scan'208";a="94461326" Date: Thu, 26 Oct 2023 19:54:18 +0800 From: Fang Xiang To: Marc Zyngier CC: , , Subject: Re: [PATCH] irqchip/gic-v3-its: Fix the coherent issue in its_setup_baser() when shr = 0. Message-ID: References: <20231026020116.4238-1-fangxiang3@xiaomi.com> <87sf5x6cdu.wl-maz@kernel.org> <86bkcl4sve.wl-maz@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <86bkcl4sve.wl-maz@kernel.org> X-Originating-IP: [10.237.8.19] X-ClientProxiedBy: BJ-MBX02.mioffice.cn (10.237.8.122) To BJ-MBX15.mioffice.cn (10.237.8.135) X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, 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 howler.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 (howler.vger.email [0.0.0.0]); Thu, 26 Oct 2023 04:54:50 -0700 (PDT) On Thu, Oct 26, 2023 at 10:48:05AM +0100, Marc Zyngier wrote: > 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? > It is a complicated situation. Just the Virtual CPUs table is dirty on my device, so the physical LPI works well. > > > > > > > > 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. > Yes, I see it. The tables should be flushed before we write the GITS_BASER[n] registers. > > > > > > > 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? > Sorry, It is a good fix. I will test it on my device and give a feedback soon. > M. > > -- > Without deviation from the norm, progress is not possible.