Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp470876pxa; Wed, 19 Aug 2020 06:39:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwf8Ci5uDTy/FT5KF9GGfn4U+blWelcHkL41LRS1Ub7jrm4eh54pFQ+VyHqVV8YSlSP+Qpf X-Received: by 2002:a05:6402:1593:: with SMTP id c19mr25583197edv.318.1597844356251; Wed, 19 Aug 2020 06:39:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597844356; cv=none; d=google.com; s=arc-20160816; b=J8vPWQYLm3orPh/yAL7y+8Mo8iu8nze2njPV+lHGtqKAZ6PQp6CZnfiFM/GEsQre5e gH9d+AgR07woDEf+eTvuG1H0G0OKKtSB35hBpDi6ReGdbMRtEqaXVMOrcd1dpMRG00od +k/dPhzHBNnipBq2MR6/mdL0OF3GKPKoDGhgV/aKuqDkSXS2s1rpcMM2DKgllAv1Smdb aUIrNFcnzVe0S8xz+Pccrvz3FDFSDlI064Ube6JAqONjfKwkGKzBwJAqgS1sUjqQIuYl ovP7Q0/YIRBWwCJmsbrX2eutmy5tB3XZt6teSE/aokXzunk6pXX4GxEB8wDor5t37F4t gphA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=WOy9DSs6VP/aeQ2TB3SLgLXQJtV6VNDteNff/5BLVkA=; b=bxIOLR1RNwr9lZEe5T+bu2j4o40s7s6xQ2y9TuLclvm6xTC9FUaDtIss4v7/WZOz89 GgH69viOehbeqfHpp9OKthU8eFbALQpg+WaXLorXAzD1+bjF3Z/WWYTXddXgkXMSFuSJ hriy3xQ6DhvSmeeT7QZOJ3/6fAv/eVkE7N9Bf0+5hXZ0+X3hDIUXCSDT9v1hwakVz8vq vtflTz7OpXQWY0rM1VeKEZCp7q5aEwN2lMr1fvWV7zORTi6qOgk9u8x2iWXnSwlfARzM YfXqPw9T2me9PUwSxDUSxBGEq09QIqgPKVnid1bMChNwkfyn3143WSGMV5gV8qeV15So aLkQ== 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 i21si16614563edb.205.2020.08.19.06.38.52; Wed, 19 Aug 2020 06:39:16 -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 S1728668AbgHSNf1 (ORCPT + 99 others); Wed, 19 Aug 2020 09:35:27 -0400 Received: from foss.arm.com ([217.140.110.172]:36876 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728499AbgHSNdb (ORCPT ); Wed, 19 Aug 2020 09:33:31 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9224A1063; Wed, 19 Aug 2020 06:33:30 -0700 (PDT) Received: from monolith.localdoman (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 6D3FA3F71F; Wed, 19 Aug 2020 06:33:28 -0700 (PDT) From: Alexandru Elisei To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: mark.rutland@arm.com, maz@kernel.org, will@kernel.org, catalin.marinas@arm.com, swboyd@chromium.org, sumit.garg@linaro.org, Julien Thierry , Will Deacon , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Julien Thierry Subject: [PATCH v6 1/7] arm64: perf: Add missing ISB in armv8pmu_enable_event() Date: Wed, 19 Aug 2020 14:34:13 +0100 Message-Id: <20200819133419.526889-2-alexandru.elisei@arm.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200819133419.526889-1-alexandru.elisei@arm.com> References: <20200819133419.526889-1-alexandru.elisei@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Writes to the PMXEVTYPER_EL0 register are not self-synchronising. In armv8pmu_enable_event(), the PE can reorder configuring the event type after we have enabled the counter and the interrupt. This can lead to an interrupt being asserted because of the previous event type that we were counting using the same counter, not the one that we've just configured. The same rationale applies to writes to the PMINTENSET_EL1 register. The PE can reorder enabling the interrupt at any point in the future after we have enabled the event. Prevent both situations from happening by adding an ISB just before we enable the event counter. Cc: Julien Thierry Cc: Will Deacon Cc: Mark Rutland Cc: Peter Zijlstra Cc: Ingo Molnar Cc: Arnaldo Carvalho de Melo Cc: Alexander Shishkin Cc: Jiri Olsa Cc: Namhyung Kim Cc: Catalin Marinas Fixes: 030896885ade ("arm64: Performance counters support") Reported-by: Julien Thierry Signed-off-by: Alexandru Elisei --- arch/arm64/kernel/perf_event.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kernel/perf_event.c b/arch/arm64/kernel/perf_event.c index 462f9a9cc44b..878e7087be02 100644 --- a/arch/arm64/kernel/perf_event.c +++ b/arch/arm64/kernel/perf_event.c @@ -632,8 +632,10 @@ static void armv8pmu_enable_event(struct perf_event *event) armv8pmu_enable_event_irq(event); /* - * Enable counter + * Enable counter. Make sure event configuration register writes are + * visible before we enable the counter. */ + isb(); armv8pmu_enable_event_counter(event); raw_spin_unlock_irqrestore(&events->pmu_lock, flags); -- 2.28.0