Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2601020lqp; Mon, 25 Mar 2024 04:10:22 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXCMhGdEtVjlQbH9sV8kIN3sPV7rl1qnCLUUEjOV6eGR+x7mRjct4AwNdEvC2b36ywCBVQ86MMnVwnL1ln47/Po2Gpu65ajmAGi4X4Ohg== X-Google-Smtp-Source: AGHT+IHB9V1/tkm15D4VVOZIDCwYLqTvGy5Jtmd6Cd+oncrqRh0REjvdgI33ToPGEV8+odFX1qVi X-Received: by 2002:a50:aa81:0:b0:565:a6a4:2ecc with SMTP id q1-20020a50aa81000000b00565a6a42eccmr4889407edc.2.1711365022149; Mon, 25 Mar 2024 04:10:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711365022; cv=pass; d=google.com; s=arc-20160816; b=ZdiifePRcQKyr/JO3nJpW3o6N+V8GEYMMb53jbEl21IksM33w/57TIJYegucFvr3Rh qMST9nEmoE2YOb3S1g9dlRGJo2bVUrhx1gOEwQW29Qs9MukwyRq1dMTX9TuaI4w8qlOK If7G+/OyMYOdB/bHzUvgKoEVMl84Mg3k77cUGHpusSKg4yzJqBDW5Ipm2HXZKxR8UjNI koMCwcl1SyGGy9O3sVkUGsFS2zpjvwd/UA6mrWMQZA9LnzlUKB9Cp1HKo6sc6WZzczQ7 pYxxEc+ppDCLXGB4EWVnjREpPmo/9d5Fufh5oOMpfrx7vw4H43kUD/iZavh5O29bxNtd dpZQ== 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=lZ86Uk6ouVdPmkEZ6+16FPxrF+CUNbAllep7f/+pPg4=; fh=Zi6NXJJhI5uOYhg9rydmDapCAkqkjL33glUi1T7i+U8=; b=gEe2SRxAqe9eSa1bTHqcDgXpgD3iHUOWfPucpxh4zyWOjoC+yuctirW+ovBFYVpawo Q8z61R04+qmYqZJHJYxv1SUkFmbKH5mGduCQMuuoSfRDAqewn9DCucLO+ktaClVKVHaw K0MM5eoVCt2a2VInpS5VTzkjvCUA8nfZdRtYsZe0V51ynZTSxI9BXsOsbcWZQoeeCyjR BZGOBcqMdv8qL0ZBpnAS93vzqthi2EwOfRVx3vlKML0zM5C+p9iUReqkOiiT8Oa7iUMQ xfYzzddI1ApYeytDGt1bjU+DhxspoLjGawU3KFBa/zrqU4kPbMj4W7/98Lt8n9OGdYos SS+w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XcPC2pjz; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-115517-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-115517-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id p19-20020aa7d313000000b00568a61b1918si2434519edq.464.2024.03.25.04.10.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 04:10:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-115517-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XcPC2pjz; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-115517-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-115517-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 am.mirrors.kernel.org (Postfix) with ESMTPS id B3E3D1F34E0A for ; Mon, 25 Mar 2024 11:10:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 90C3D23C410; Mon, 25 Mar 2024 02:42:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="XcPC2pjz" 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 3DBEF12B16A; Sun, 24 Mar 2024 22:56:07 +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=1711320968; cv=none; b=m8zjUra891XXX/akxwlgdwzd/1Ai7uLog+7Z9CIXK2nf+kjPn6fvv1kNlorqvJWcNHxPGThwbvfNRtCQh/pKzyPO7ePeb8HlpiKWAazpB4pnczA6jNAnFHaJC18GN1ZmGwaqJxxd9sKor2KzXIBe7atpncqXQ/C+CN1Ec9GWPTM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711320968; c=relaxed/simple; bh=LOo3lC22VEDvJtM2gwHrvZYeaT0SOw4YiVKbCdHHZVk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eFN3/Dt/CJ8XlW6azObwRkjuVH6V7xPb52R9cjAwM2Mz2YfYyqZcaGUsLRHAWnJEwiX28oHdgxwmH06Ck53QXCZg89h5/kZ8bkfjyEQYtD9BDRfBylfN41ikgxiH4k01Dk/HVeu5UofTJNiYcq0xdc2nY1z6mkbvhPn2UNPeWBE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XcPC2pjz; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 64A6FC433C7; Sun, 24 Mar 2024 22:56:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711320967; bh=LOo3lC22VEDvJtM2gwHrvZYeaT0SOw4YiVKbCdHHZVk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XcPC2pjz6HRGrBgnYB8WCUJYQaKS+FbytDsc/rFKZWZmOSvPuqYkhxAIn034bPe5q TCw8NWaqSfRkGznuei4X2l2g51Xbwgvn9G+16Dg4UBKBOKWAqluR9c4rROJfUYY3Fr aec3XmcJaJvTSTJ6pZY0EpkUSSKc1pAAv5uflEwSGZnFlZ9480I1FjrM/PVF63uSay vwKV7FUOUBI52eO42ZC8f84GCnJyi6uFQJ/27QbfcXTG7ZHOx6ffDnBgdv9ZyP/a1j ZBeZnkru0+Em49sEuVlXPUDQcOVSWbiPXWnA+hT1N2Wte6vj7G8kLC7hwVwUtvVNO6 qpgNufnQ3bC3Q== 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.7 530/713] powerpc/hv-gpci: Fix the H_GET_PERF_COUNTER_INFO hcall return value checks Date: Sun, 24 Mar 2024 18:44:16 -0400 Message-ID: <20240324224720.1345309-531-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324224720.1345309-1-sashal@kernel.org> References: <20240324224720.1345309-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 27f18119fda17..241551d1282f8 100644 --- a/arch/powerpc/perf/hv-gpci.c +++ b/arch/powerpc/perf/hv-gpci.c @@ -695,6 +695,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; @@ -759,6 +773,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) @@ -789,13 +804,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