Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp282671rdh; Thu, 26 Oct 2023 01:56:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHkYesBD4HJBbOGovEWuAqxg0wjXW+jfHenjLeEaxvMsl5kWJ/xhzA2Y9x7Rc3wurM4WMZ/ X-Received: by 2002:a67:ae09:0:b0:44e:99a2:a42 with SMTP id x9-20020a67ae09000000b0044e99a20a42mr12564256vse.11.1698310595879; Thu, 26 Oct 2023 01:56:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698310595; cv=none; d=google.com; s=arc-20160816; b=U3M8ggY9kA3oqTJet5lG6JOLInhiGX2yRt92gycoRri4rKOFe5tn+WQaEYTYPiEImb oH1CkA+5mT7d18cCQ6Mt/NNM05vbj77/cBmaibPhPaxkNVt6a/p9lC/sYt4iWVVEb5CN xXEMfm43Zk2x2JRvEqZ3uX2i6cRgPLTeAjxJFGKuAyeT2sms+btH+lx+U1UmnyzAX32G kE5zsiwi2voFgxWn9tm4q1Pw/RoFC6sCpsvythuSSiJ9X183g4UYlkM94lhssd1m3sfg r8VIKca3Bv6VZ97Ksf1OvKKlXvzsl1E0QicXtbb+rZ5zA54q1eQ9G52UdfHWY4wG2vmS Dr8Q== 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=UJ/L1qMTkHYP9fwld8z1gVa/hDMIGWwRUr9Es41XB5M=; fh=85fMwhMCxW3cInIV98XJuVDN4GMT61CpqEcFLP3GFyI=; b=cBL95dImi3OoJxJf7FaPJc48SnrAtI+bdfsMFlhQ+Lqbq/f3mueYVMXixu9C/6hhPi opcB3cxE0wOdvAFe6xvMOLNYM4itpSdXFFs8wn89+uBk6/t/8T6ZeaBtk/LOXlMOi95f FnfKZJTTYBphf0hVYMbXEwUBCODxg1PFIeSPsUB6dQU77W/MYwabs2ioeqxgesFMJ75w subz+YndgLGKl7oY3E5gZQkNotYA/FVAb6QB0nVZKcM2YMu0KeuJ8EjQtPqkcWm3PekE Z7NxlaCpo30HfMF/FY6xJ8D9ZcIqsZtZ2b7f3TPBB6ed8bw0nEaPESuSYNzVHVGdWxVj PUSA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id g138-20020a25db90000000b00da06fb44e62si4917156ybf.300.2023.10.26.01.56.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 01:56:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (Postfix) with ESMTP id 587EB81C19E4; Thu, 26 Oct 2023 01:56:32 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344576AbjJZI4N (ORCPT + 99 others); Thu, 26 Oct 2023 04:56:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233231AbjJZI4L (ORCPT ); Thu, 26 Oct 2023 04:56:11 -0400 X-Greylist: delayed 64 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Thu, 26 Oct 2023 01:56:05 PDT Received: from outboundhk.mxmail.xiaomi.com (outboundhk.mxmail.xiaomi.com [207.226.244.122]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id ECD0D183 for ; Thu, 26 Oct 2023 01:56:05 -0700 (PDT) X-IronPort-AV: E=Sophos;i="6.03,253,1694707200"; d="scan'208";a="94429981" Date: Thu, 26 Oct 2023 16:48:13 +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> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <87sf5x6cdu.wl-maz@kernel.org> X-Originating-IP: [10.237.8.11] X-ClientProxiedBy: BJ-MBX14.mioffice.cn (10.237.8.134) 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 pete.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 (pete.vger.email [0.0.0.0]); Thu, 26 Oct 2023 01:56:32 -0700 (PDT) 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. > > > > 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? > > > 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. > -- > Without deviation from the norm, progress is not possible.