Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1425123ybt; Thu, 9 Jul 2020 06:51:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwCsOrv3+dNL8CTZncVN0pTTyX5/RvtKOxgP2lg582yn+OH3HO0b9cL5k3L6CZRAIGsWmSu X-Received: by 2002:a17:906:1b45:: with SMTP id p5mr55947250ejg.51.1594302717544; Thu, 09 Jul 2020 06:51:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594302717; cv=none; d=google.com; s=arc-20160816; b=NsjQLmMvSbmlM4XL8NYUrgy+pR4J+YqJmCpwhWlsAn/rvOf+H/J5d4CM9ZZwDyzwiY r3nWh/s/PJyP7kVEc8lu0XUSEt2PjG3HVRnxJhw0fAxZfq5A2ANY719KGG3IfrzoJ7wt ADVM8NwVcQD3/Cxr/yXkfP31VQYZIqZw1n88c98lvdjTG4/rX0G0zAR6yNZYmeHTXfDX KA4yDWgsTxCGJvNcr6ZlsI/96l5wx1syTahRtDV98pUGgRgslw+LzTTNy3JCOatbybcu EMXV+9sZNjZAsZypsDY17diZQUbOUFUDia69Bdz39RuscDY+Yvn2BsmfdqyOHWlO7B7T +uoQ== 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 :message-id:date:subject:cc:to:from; bh=/KbvNCy0RDC4BT9HRgWyRToluk+ULi576rY9/McAiCo=; b=BxtxnKLbMqgg0PZoUyK9gMo8Scm7rhZMwv1JpCEUFW10qfMgSzoRO5sSJUqlMHUHEf slwsT4anScWB9OfWuqvBBnVD/ng9X3sFryGUYeqnMll5hdrq0IJZV2QzuM3R93XcfiEP uKlK8VNPRwC/1fnLG4n8ZqWFZWGs2PojR3PR/E95O3BL2gnF2qCmUL26CC6Xpy8RUT0R IZkAH5/VS6+vtht+YR5F0Dm06TJ1U/VbI8MvV41d7yjZbSHtHh78QGBE/8SIC8jAwNKR Nyi/4WJmrLozPqK04Sr9DQhY8TMgKoCNpIfyfygGBqBg8opgxJP2mVBjA+MkiNxS8up3 zr3g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b5si1744195edy.563.2020.07.09.06.51.34; Thu, 09 Jul 2020 06:51:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727839AbgGINuT (ORCPT + 99 others); Thu, 9 Jul 2020 09:50:19 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:33878 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726358AbgGINuT (ORCPT ); Thu, 9 Jul 2020 09:50:19 -0400 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 95FC5C72E21C9F5B04F0; Thu, 9 Jul 2020 21:50:15 +0800 (CST) Received: from DESKTOP-8RFUVS3.china.huawei.com (10.174.185.226) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.487.0; Thu, 9 Jul 2020 21:50:08 +0800 From: Zenghui Yu To: , CC: , , , Zenghui Yu Subject: [PATCH] irqchip/gic-v4.1: Ensure accessing the correct RD when writing INVALLR Date: Thu, 9 Jul 2020 21:49:59 +0800 Message-ID: <20200709134959.1039-1-yuzenghui@huawei.com> X-Mailer: git-send-email 2.23.0.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.174.185.226] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The GICv4.1 spec tells us that it's CONSTRAINED UNPREDICTABLE to issue a register-based invalidation operation for a vPEID not mapped to that RD, or another RD within the same CommonLPIAff group. To follow this rule, commit f3a059219bc7 ("irqchip/gic-v4.1: Ensure mutual exclusion between vPE affinity change and RD access") tried to address the race between the RD accesses and the vPE affinity change, but somehow forgot to take GICR_INVALLR into account. Let's take the vpe_lock before evaluating vpe->col_idx to fix it. Signed-off-by: Zenghui Yu --- drivers/irqchip/irq-gic-v3-its.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c index da44bfa48bc2..50a04cca8207 100644 --- a/drivers/irqchip/irq-gic-v3-its.c +++ b/drivers/irqchip/irq-gic-v3-its.c @@ -4087,18 +4087,22 @@ static void its_vpe_4_1_deschedule(struct its_vpe *vpe, static void its_vpe_4_1_invall(struct its_vpe *vpe) { void __iomem *rdbase; + unsigned long flags; u64 val; + int cpu; val = GICR_INVALLR_V; val |= FIELD_PREP(GICR_INVALLR_VPEID, vpe->vpe_id); /* Target the redistributor this vPE is currently known on */ - raw_spin_lock(&gic_data_rdist_cpu(vpe->col_idx)->rd_lock); - rdbase = per_cpu_ptr(gic_rdists->rdist, vpe->col_idx)->rd_base; + cpu = vpe_to_cpuid_lock(vpe, &flags); + raw_spin_lock(&gic_data_rdist_cpu(cpu)->rd_lock); + rdbase = per_cpu_ptr(gic_rdists->rdist, cpu)->rd_base; gic_write_lpir(val, rdbase + GICR_INVALLR); wait_for_syncr(rdbase); - raw_spin_unlock(&gic_data_rdist_cpu(vpe->col_idx)->rd_lock); + raw_spin_unlock(&gic_data_rdist_cpu(cpu)->rd_lock); + vpe_to_cpuid_unlock(vpe, flags); } static int its_vpe_4_1_set_vcpu_affinity(struct irq_data *d, void *vcpu_info) -- 2.19.1