Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp2268814imc; Tue, 12 Mar 2019 10:15:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqzOT2yw7PSZdGwYBvB58xnl3xxYvx1mqNwd+yeiqBqU2um0MGdfiAfyQAek6FD6cNrlxzKU X-Received: by 2002:a17:902:aa92:: with SMTP id d18mr10233856plr.278.1552410940413; Tue, 12 Mar 2019 10:15:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552410940; cv=none; d=google.com; s=arc-20160816; b=jSetGbLXGMi3RNdA32GHQHo1Dxf0hHuqfKxjz4nPaJ0XztBmt01JJ+/rTdUO2XxUAo iUr2MYIKF29tvA4viNPgdMgeYBjc21gpn9sS7b+6rvsph0oniZ5kNddAJu9lz3lEw76i S9Fmw+0GLbiC9/pc7TCmwhYbFas3cut2/Qgh8LPuVFryR0SAvbN5ju10Bz3vD/zrW5ZL pZK2p10VVfrWSFA1ICK7odv7C+9qZWmqeCQKV/CBn3484VJKUSI5gC6UqY4e/9EDJH6M gZ7oxBH0k45MlHZ1IcYnWBUL+iKAog41vgdGm1Vl/qqWlHvPzXoQjLUvxG0o1Bk8tHfb ShPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=xkJowME4EuS5yYf3P3Ch74h9WqGbRB+/xiHKU7RpQ8s=; b=ZyBWioY88AnFsbCsZj9C+7jLD6FJL1pN0tKDBH9EtHUrek4CJnhcfrr1HbmjaBGl4A mTYs1OF7hINea6CbycyarbYsbsFbqvEX2alcTT1EKKbg+Il3hrGrmnAvEuUvFX+6ZkTY UmNQg0AQNn4/KQ+7HebaMC8zvxfLe3S/6REv/v+W+UQNdG4IHNMoedyBB3iSadV9Vm4X l+lI9272t2UoBGmJY60szMkn5ohbzY/F/OX6fKG3fVkMSpWByeavyF1s2tF+ztHnkE8P THmcU136H9VuiTFxsklr5VEPBgbiixDQNswpWdsnJT9jMBAwlZmMiFsShT+7lEOR1+Le Q1mw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=pkXAkgum; 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 h1si9070129plh.265.2019.03.12.10.15.25; Tue, 12 Mar 2019 10:15:40 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=default header.b=pkXAkgum; 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 S1727877AbfCLRNS (ORCPT + 99 others); Tue, 12 Mar 2019 13:13:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:48506 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727625AbfCLRMq (ORCPT ); Tue, 12 Mar 2019 13:12:46 -0400 Received: from localhost (unknown [104.133.8.98]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5B44B2173C; Tue, 12 Mar 2019 17:12:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1552410764; bh=Q9EhXD+AKN+RwbZifH4Rpj5VSNrmZ0JeDMm/eTp26f4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pkXAkgum36HA208QolUeFPVTg1c3UmloBsRL6FfD8oaLZonim0fHAHLRK7GUPnPwy 0zC/J3ddPOowdhWhNCYzTBMXbmolivIuYLB5KMUCokkHW7rVoaiLGtzJQyWkjXuSGP bve/hvI+q+t1C3GXY4FYXPNVYWpxkReYIwENOL8I= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Heyi Guo , Heyi Guo , Marc Zyngier , Sasha Levin Subject: [PATCH 4.20 098/171] irqchip/gic-v4: Fix occasional VLPI drop Date: Tue, 12 Mar 2019 10:07:58 -0700 Message-Id: <20190312170356.434100900@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190312170347.868927101@linuxfoundation.org> References: <20190312170347.868927101@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.20-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 6479450f72c1391c03f08affe0d0110f41ae7ca0 ] 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(). Fixes: e643d8034036 ("irqchip/gic-v3-its: Add VPE scheduling") Signed-off-by: Heyi Guo Signed-off-by: Heyi Guo Signed-off-by: Marc Zyngier Signed-off-by: Sasha Levin --- 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 350f999d205b..f25ec92f23ee 100644 --- a/drivers/irqchip/irq-gic-v3-its.c +++ b/drivers/irqchip/irq-gic-v3-its.c @@ -2065,6 +2065,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(); @@ -2150,6 +2173,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: @@ -2776,26 +2823,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; -- 2.19.1