Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4387672imu; Tue, 29 Jan 2019 00:14:26 -0800 (PST) X-Google-Smtp-Source: ALg8bN4ZP5tvfcmqa4IBteGNQ0jBbGbBzzmWt/hPY8NjyOi0C3QR4b2w12kXgMJHi4ezWC9BWDXa X-Received: by 2002:a17:902:112c:: with SMTP id d41mr24206906pla.144.1548749665970; Tue, 29 Jan 2019 00:14:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548749665; cv=none; d=google.com; s=arc-20160816; b=ppoT/YkzRJBfmzHhxknYPZ84J8vm/DaU4MwOhJmDLAHIm2HWpFy5L5190raruzbmzD DD61Al4aFpDVwSp57ETQXZhyoaDAU8UKfYXPrSG7ly9ziYYX67f2cSLRxR02eEYGp3pj gXNeLwfRFjPsDOq+n2Q+sx7N9ya9LHI/kI8z9rl8XchacSzArvR5NgD89G5fPQBWv6bu h2OB4LlEYt4eUojLXC+cdB2W7KVUMhNH7MdJBUgT1O35SDI9Mkd3CMZKleWYYawth3IM 3hpIMiLlDj57gztJ1nHDdE3zgms3s0ZEWWS3hTjyN0xCaKbx4MNb61BQeYbABjkofsyA e3oA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:organization:user-agent :references:in-reply-to:subject:cc:to:from:message-id:date; bh=kURPVGAQGdViA2uEWHXFiqE88eFU3gzUuLthHfXAziE=; b=W8/SIc/ZGI0kavtQeK4pmXonknitKEV6uFVC9nqIeeaCbrliZ3tj1gX9uAO86ATOHF H3ETKHmkhotpx4LKoM/u0zd5nPzn6u9ieGzlJolID2ItgEGZy+Q3lNDNMB59xAuq27fS pqw2HCZ8QJfudpu8j1MoNpygXHWw9+YSBKNboJM2kLaQNYL4Vlw1t6n5s7SAOz3IUwnX Od+YiEMOXFZwSDV9l7P76LzDKyhaBg7Mg55VXSHWGyzxZJVLFugvQw6otbzpx0yILTVK ZvttN4JyoW+Tf9ovWEJgFYxlnDiMuGQItQ/HHtaM+Z2e8BtGC/D/sA1LRL+4kB01SHCI bQog== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l129si8492586pfl.284.2019.01.29.00.14.10; Tue, 29 Jan 2019 00:14:25 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727710AbfA2IMy (ORCPT + 99 others); Tue, 29 Jan 2019 03:12:54 -0500 Received: from foss.arm.com ([217.140.101.70]:59602 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727470AbfA2IMy (ORCPT ); Tue, 29 Jan 2019 03:12:54 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9CE29EBD; Tue, 29 Jan 2019 00:12:53 -0800 (PST) Received: from big-swifty.misterjones.org (usa-sjc-mx-foss1.foss.arm.com [217.140.101.70]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E7EAE3F7A6; Tue, 29 Jan 2019 00:12:51 -0800 (PST) Date: Tue, 29 Jan 2019 08:12:49 +0000 Message-ID: <86bm3zvq4e.wl-marc.zyngier@arm.com> From: Marc Zyngier To: Heyi Guo Cc: , Thomas Gleixner , Jason Cooper , , Subject: Re: [PATCH v2] irqchip/gic-v4: fix occasional VLPI drop In-Reply-To: <80e52297-b2b3-ef90-4626-be3819afbf92@huawei.com> References: <1548337028-21801-1-git-send-email-guoheyi@huawei.com> <80e52297-b2b3-ef90-4626-be3819afbf92@huawei.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 EasyPG/1.0.0 Emacs/25.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) Organization: ARM Ltd MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 29 Jan 2019 01:32:55 +0000, Heyi Guo wrote: > > Hi Marc, > > Any comments? None so far, I've queued this to let it soak, and will send it as a fix if nothing else breaks. Thanks, M. > > Thanks, > > Heyi > > > On 2019/1/24 21:37, Heyi Guo wrote: > > 1. In current implementation, every VLPI will temporarily be mapped to > > the first CPU in system (normally CPU0) and then moved to the real > > scheduled CPU later. > > > > 2. So there is a time window and a VLPI may be sent to CPU0 instead of > > the real scheduled vCPU, in a multi-CPU virtual machine. > > > > 3. However, CPU0 may have not been scheduled as a virtual CPU after > > system boots up, so the value of its GICR_VPROPBASER is unknown at > > that moment. > > > > 4. If the INTID of VLPI is larger than 2^(GICR_VPROPBASER.IDbits+1), > > while IDbits is also in unknown state, GIC will behave as if the VLPI > > is out of range and simply drop it, which results in interrupt missing > > in Guest. > > > > As no code will clear GICR_VPROPBASER at runtime, we can safely > > initialize the IDbits field at boot time for each CPU to get rid of > > this issue. > > > > We also clear Valid bit of GICR_VPENDBASER in case any ancient > > programming gets left in and causes memory corrupting. A new function > > its_clear_vpend_valid() is added to reuse the code in > > its_vpe_deschedule(). > > > > Signed-off-by: Heyi Guo > > Signed-off-by: Heyi Guo > > --- > > > > Notes: > > v2: > > - Also wait GICR_VPENDBASER.Dirty bit to be 0 in initialization [Marc] > > - Add a new function to reuse the code in its_vpe_deschedule() [Marc] > > > > drivers/irqchip/irq-gic-v3-its.c | 66 +++++++++++++++++++++++++++++----------- > > 1 file changed, 49 insertions(+), 17 deletions(-) > > > > diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c > > index 3365d44..531e945 100644 > > --- a/drivers/irqchip/irq-gic-v3-its.c > > +++ b/drivers/irqchip/irq-gic-v3-its.c > > @@ -2060,6 +2060,29 @@ static int __init allocate_lpi_tables(void) > > return 0; > > } > > +static u64 its_clear_vpend_valid(void __iomem *vlpi_base) > > +{ > > + u32 count = 1000000; /* 1s! */ > > + bool clean; > > + u64 val; > > + > > + val = gits_read_vpendbaser(vlpi_base + GICR_VPENDBASER); > > + val &= ~GICR_VPENDBASER_Valid; > > + gits_write_vpendbaser(val, vlpi_base + GICR_VPENDBASER); > > + > > + do { > > + val = gits_read_vpendbaser(vlpi_base + GICR_VPENDBASER); > > + clean = !(val & GICR_VPENDBASER_Dirty); > > + if (!clean) { > > + count--; > > + cpu_relax(); > > + udelay(1); > > + } > > + } while (!clean && count); > > + > > + return val; > > +} > > + > > static void its_cpu_init_lpis(void) > > { > > void __iomem *rbase = gic_data_rdist_rd_base(); > > @@ -2145,6 +2168,30 @@ static void its_cpu_init_lpis(void) > > val |= GICR_CTLR_ENABLE_LPIS; > > writel_relaxed(val, rbase + GICR_CTLR); > > + if (gic_rdists->has_vlpis) { > > + void __iomem *vlpi_base = gic_data_rdist_vlpi_base(); > > + > > + /* > > + * It's possible for CPU to receive VLPIs before it is > > + * sheduled as a vPE, especially for the first CPU, and the > > + * VLPI with INTID larger than 2^(IDbits+1) will be considered > > + * as out of range and dropped by GIC. > > + * So we initialize IDbits to known value to avoid VLPI drop. > > + */ > > + val = (LPI_NRBITS - 1) & GICR_VPROPBASER_IDBITS_MASK; > > + pr_debug("GICv4: CPU%d: Init IDbits to 0x%llx for GICR_VPROPBASER\n", > > + smp_processor_id(), val); > > + gits_write_vpropbaser(val, vlpi_base + GICR_VPROPBASER); > > + > > + /* > > + * Also clear Valid bit of GICR_VPENDBASER, in case some > > + * ancient programming gets left in and has possibility of > > + * corrupting memory. > > + */ > > + val = its_clear_vpend_valid(vlpi_base); > > + WARN_ON(val & GICR_VPENDBASER_Dirty); > > + } > > + > > /* Make sure the GIC has seen the above */ > > dsb(sy); > > out: > > @@ -2757,26 +2804,11 @@ static void its_vpe_schedule(struct its_vpe *vpe) > > static void its_vpe_deschedule(struct its_vpe *vpe) > > { > > void __iomem *vlpi_base = gic_data_rdist_vlpi_base(); > > - u32 count = 1000000; /* 1s! */ > > - bool clean; > > u64 val; > > - /* We're being scheduled out */ > > - val = gits_read_vpendbaser(vlpi_base + GICR_VPENDBASER); > > - val &= ~GICR_VPENDBASER_Valid; > > - gits_write_vpendbaser(val, vlpi_base + GICR_VPENDBASER); > > - > > - do { > > - val = gits_read_vpendbaser(vlpi_base + GICR_VPENDBASER); > > - clean = !(val & GICR_VPENDBASER_Dirty); > > - if (!clean) { > > - count--; > > - cpu_relax(); > > - udelay(1); > > - } > > - } while (!clean && count); > > + val = its_clear_vpend_valid(vlpi_base); > > - if (unlikely(!clean && !count)) { > > + if (unlikely(val & GICR_VPENDBASER_Dirty)) { > > pr_err_ratelimited("ITS virtual pending table not cleaning\n"); > > vpe->idai = false; > > vpe->pending_last = true; > > -- Jazz is not dead, it just smell funny.