Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2490622lqp; Sun, 24 Mar 2024 23:19:53 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUnZe5zzp9gph5J4y5XqJKKH81vz2PSMtmfULuukXDxoqOqRaZvK4MmB6oL6qdl2o+hApCuyzMOWj6KuBhzUcDRduBsxr4irOhnPwPtPw== X-Google-Smtp-Source: AGHT+IGNfcYvZgrfmbYTJiUuIgH2VI4EQK9lda5cy1hY9Qk/eiTuMqBAmY/bP4E0GvZq76Jjvy97 X-Received: by 2002:a05:6358:5e9d:b0:17f:591e:e4 with SMTP id z29-20020a0563585e9d00b0017f591e00e4mr7666162rwn.25.1711347593444; Sun, 24 Mar 2024 23:19:53 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711347593; cv=pass; d=google.com; s=arc-20160816; b=iNhdOFoDOp9mbOmfZkKrT+5w5BhqSJ2jo/zTH4Chjn3FT3BK/gLP94sW5MItqNafjp hKVdBpS3a6QqAPqXAr0iAis7WX+kLJ1b4HkJMgUNv6JONbvYn8U8YN0AKEbGBPY+egTx 7VVHW9ogM0Ayr45N+oqAdAuZS65UkqX/swlw18rLi/s2Rmzn2B/9PwyB8FnmCFS+5ahk U27C71OYqHfnvJM/BMzT4hfPCQAwW4lZiectiokRPm/ePSm01hGtHyPNgyc4/Sp4k0cO i/2ihzKDRHNODQOFuMlc3nMkp8fYisL4gqQJ/2XTRpcM3URBX9aQvIr8QQ6tE9QcMM2/ nfQw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=4Ztricvh3ZZNdPlUJ9Y7/CN7KSRWinruUHTN9ln0o90=; fh=Zi6NXJJhI5uOYhg9rydmDapCAkqkjL33glUi1T7i+U8=; b=gNjND8yknoh4J7tqUpYx5F9PKxURuJc9hNtwBZIBc9o5x7Ntt5mdBse7NqatwKokAU 7wuU4ZJnSwmNgVkVVuhyNlLsb+E3CBRb9AODkfUD8BsB32sdmV+YfVbubUA5vdcpwsP/ OVFjwhsE9gpErC5EZWRBAOaBqybGJdQnlzAdFQGPItXHsJY07ZIfu8MA5lOqCEjmTvZQ m4QyRiloQEwdoX+lybuEe8+vvVAS+CwopKYPZjF7yaA3woiVxCyZCh/uDdKdrjXoGJbL ZGOB8s8LlnFzOaEHJnv7+sJIrmrhsJfyypz3TUMX5PdJB+Y0hLNuWEVp3rAt4mKokNPY 9ZuQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BqD6nTj1; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-114604-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-114604-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 2-20020a630a02000000b005dbec3481efsi7206358pgk.91.2024.03.24.23.19.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 23:19:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-114604-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BqD6nTj1; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-114604-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-114604-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 06478291BBA for ; Mon, 25 Mar 2024 06:19:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 89B2C18765F; Sun, 24 Mar 2024 23:54:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="BqD6nTj1" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7626614C5BD; Sun, 24 Mar 2024 23:17:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711322251; cv=none; b=k1uMfxbQisfe8jqm4YrUyxjxjhh9R4yZuJJyHuz4oIyjMcN6PSZy4hWPPCksXqKlq0rnY5j7Ae9uK4tmJ9/Q+gZRSKQsyf24Zx+pijPF25+WloIA1q3tWKtSaVuSURRRndu04X5vaQeJ51pgdn0gHSrCPlEmHv9NRqnAioiIXwY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711322251; c=relaxed/simple; bh=fejz7w+e6Aj4cT1OE67UQDec9MuCv/5OD/3K8QSXQsU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CORSpTDqA20WKNksEP5fiLdu83F1sCPtuKLU5p/6bIjvTQQyRVx6H/E5TtBKPeOIvACxKofxoFoZ1zSlS0iuUjH3i63csYp06KIJgK1+MZsyjAwtQm2NNcEfq5M5JFhTdaWIqyN6T7Tr8gXHDp7TmYwoc5bMW2BGmH1P2W7GGgE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BqD6nTj1; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9FF18C43390; Sun, 24 Mar 2024 23:17:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711322250; bh=fejz7w+e6Aj4cT1OE67UQDec9MuCv/5OD/3K8QSXQsU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BqD6nTj137H/L8nDb9AnLJQrbwY9jpZ2fq3Uejej2ttOL/gEESGWaZgSN9yZkcN/E XXvzjQ2LwYg/HRmnbYaky/YfO2wtOO7P1XP0Qs3oJGtE5jrz5LtJuO9Y5/Rrnhy3j4 qqPM9lt8B6oei8Eqdrzc2m//0WYg4tpH0h37CerZ6VQC83aJHcDok1fi+IHy7ROVpu qSVYUmikPHmxC1OsTCziPDK+oCqRNAwKVr9YEI2GLBGXp6FsnZhvdIlNhgIbznqv6g dEAKBf0yNqnWX4uzA/gCaMQCxUhQqj4hr78RojUDNNcX4xGobf/SMC4r339igdqmx+ P5VeRx4UQOsMg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Kajol Jain , Akanksha J N , Michael Ellerman , Sasha Levin Subject: [PATCH 6.1 332/451] powerpc/hv-gpci: Fix the H_GET_PERF_COUNTER_INFO hcall return value checks Date: Sun, 24 Mar 2024 19:10:08 -0400 Message-ID: <20240324231207.1351418-333-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324231207.1351418-1-sashal@kernel.org> References: <20240324231207.1351418-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Kajol Jain [ Upstream commit ad86d7ee43b22aa2ed60fb982ae94b285c1be671 ] Running event hv_gpci/dispatch_timebase_by_processor_processor_time_in_timebase_cycles,phys_processor_idx=0/ in one of the system throws below error: ---Logs--- # perf list | grep hv_gpci/dispatch_timebase_by_processor_processor_time_in_timebase_cycles hv_gpci/dispatch_timebase_by_processor_processor_time_in_timebase_cycles,phys_processor_idx=?/[Kernel PMU event] # perf stat -v -e hv_gpci/dispatch_timebase_by_processor_processor_time_in_timebase_cycles,phys_processor_idx=0/ sleep 2 Using CPUID 00800200 Control descriptor is not initialized Warning: hv_gpci/dispatch_timebase_by_processor_processor_time_in_timebase_cycles,phys_processor_idx=0/ event is not supported by the kernel. failed to read counter hv_gpci/dispatch_timebase_by_processor_processor_time_in_timebase_cycles,phys_processor_idx=0/ Performance counter stats for 'system wide': hv_gpci/dispatch_timebase_by_processor_processor_time_in_timebase_cycles,phys_processor_idx=0/ 2.000700771 seconds time elapsed The above error is because of the hcall failure as required permission "Enable Performance Information Collection" is not set. Based on current code, single_gpci_request function did not check the error type incase hcall fails and by default returns EINVAL. But we can have other reasons for hcall failures like H_AUTHORITY/H_PARAMETER with detail_rc as GEN_BUF_TOO_SMALL, for which we need to act accordingly. Fix this issue by adding new checks in the single_gpci_request and h_gpci_event_init functions. Result after fix patch changes: # perf stat -e hv_gpci/dispatch_timebase_by_processor_processor_time_in_timebase_cycles,phys_processor_idx=0/ sleep 2 Error: No permission to enable hv_gpci/dispatch_timebase_by_processor_processor_time_in_timebase_cycles,phys_processor_idx=0/ event. Fixes: 220a0c609ad1 ("powerpc/perf: Add support for the hv gpci (get performance counter info) interface") Reported-by: Akanksha J N Signed-off-by: Kajol Jain Signed-off-by: Michael Ellerman Link: https://msgid.link/20240229122847.101162-1-kjain@linux.ibm.com Signed-off-by: Sasha Levin --- arch/powerpc/perf/hv-gpci.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/perf/hv-gpci.c b/arch/powerpc/perf/hv-gpci.c index 7ff8ff3509f5f..943248a0e9a9d 100644 --- a/arch/powerpc/perf/hv-gpci.c +++ b/arch/powerpc/perf/hv-gpci.c @@ -164,6 +164,20 @@ static unsigned long single_gpci_request(u32 req, u32 starting_index, ret = plpar_hcall_norets(H_GET_PERF_COUNTER_INFO, virt_to_phys(arg), HGPCI_REQ_BUFFER_SIZE); + + /* + * ret value as 'H_PARAMETER' with detail_rc as 'GEN_BUF_TOO_SMALL', + * specifies that the current buffer size cannot accommodate + * all the information and a partial buffer returned. + * Since in this function we are only accessing data for a given starting index, + * we don't need to accommodate whole data and can get required count by + * accessing first entry data. + * Hence hcall fails only incase the ret value is other than H_SUCCESS or + * H_PARAMETER with detail_rc value as GEN_BUF_TOO_SMALL(0x1B). + */ + if (ret == H_PARAMETER && be32_to_cpu(arg->params.detail_rc) == 0x1B) + ret = 0; + if (ret) { pr_devel("hcall failed: 0x%lx\n", ret); goto out; @@ -228,6 +242,7 @@ static int h_gpci_event_init(struct perf_event *event) { u64 count; u8 length; + unsigned long ret; /* Not our event */ if (event->attr.type != event->pmu->type) @@ -258,13 +273,23 @@ static int h_gpci_event_init(struct perf_event *event) } /* check if the request works... */ - if (single_gpci_request(event_get_request(event), + ret = single_gpci_request(event_get_request(event), event_get_starting_index(event), event_get_secondary_index(event), event_get_counter_info_version(event), event_get_offset(event), length, - &count)) { + &count); + + /* + * ret value as H_AUTHORITY implies that partition is not permitted to retrieve + * performance information, and required to set + * "Enable Performance Information Collection" option. + */ + if (ret == H_AUTHORITY) + return -EPERM; + + if (ret) { pr_devel("gpci hcall failed\n"); return -EINVAL; } -- 2.43.0