From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (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 69D53380FFD for ; Tue, 1 Sep 2026 08:55:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.156.1 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788252918; cv=none; b=R3S8o571j3Laa6FzBKstLGASwfH8mFk2O//ShfuHg72yx9YTylfLRI1w1Yov4L5mkk0VUePoTzEvM+qogyfuVn7Nz7WUzEAXHBLZgpXuo5hfBOnR8OByQaqF7WOJwrEdKvwLkU92yuXSEyiS7Wes9Wh+IJl/P69DhY4/KpFe96M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788252918; c=relaxed/simple; bh=eQ6Ip39Q1b4sDOZ/rNVAlC6gvqu/jwziTL08iyHMs+s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bjm1VP2gQd27ZQIo3vmGnpsNnpIM28GGyS4s3A5YkyJjes+pYKCJjM13ZCzKQJMUgZqJBAYZ0JQQeig6LurkndNUZcR27GYdn6RlIJeUwWdyjHKqLqkYJRVfC5xwp+vt0cCnsQC1hbdCsitUh2JfK7mUzG0xc54FGqstHwD6YAc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=pz+k71QE; arc=none smtp.client-ip=148.163.156.1 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="pz+k71QE" Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6817VbA8571790 for ; Tue, 1 Sep 2026 08:55:16 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=NMibR4teOYdYkghrk XCTY3hUZuOnevJOiLyz9Oe7WJg=; b=pz+k71QEaOLSV+hOnJviv0PhOOCNPOvy5 zhyL2X++vELqUPet+vbhfN0xrkREedOvkWhc7aGTvrJG2U308M46OAK8V1ZWq8hW qBVFvQ8pqMDBzCkAzj+o+EQloqaFVWnakgdHTFo1P7KZwd6lU1dEzt/lLiXNmWzT dF501/FLNxCG3NeHScTT3/raZs4bDxnkoOemGQ7nno/yBLpvEQx+3opPtfxFSAHc qUp5dpQoCUI1jqE3cvBlEoMsA2pxvPH2PWnLaR0QxoVfzVcj1zmlFZtzW1VMV4oH TfKLT6VTZXCvBjkOa/gAvCcbTXton0vOis7t/Vi1taGK2HNn60jyQ== Received: from ppma21.wdc07v.mail.ibm.com (5b.69.3da9.ip4.static.sl-reverse.com [169.61.105.91]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4gbq54pqrf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 01 Sep 2026 08:55:16 +0000 (GMT) Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.18.1.7/8.18.1.7) with ESMTP id 6818fJrZ030690 for ; Tue, 1 Sep 2026 08:55:15 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4gcark2rwe-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 01 Sep 2026 08:55:14 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 6818tAEV31785670 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 1 Sep 2026 08:55:11 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DE0EB20043; Tue, 1 Sep 2026 08:55:10 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C3C7E20040; Tue, 1 Sep 2026 08:55:10 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.87.85.9]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 1 Sep 2026 08:55:10 +0000 (GMT) From: Thomas Richter To: linux-s390@vger.kernel.org Cc: Thomas Richter , Sumanth Korikkar Subject: [PATCH 2/3 v8] s390/pai: Move locking to event init and delete Date: Tue, 1 Sep 2026 10:54:47 +0200 Message-ID: <20260901085448.2260658-3-tmricht@linux.ibm.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260901085448.2260658-1-tmricht@linux.ibm.com> References: <20260901085448.2260658-1-tmricht@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-s390@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwOTAxMDA3NSBTYWx0ZWRfX0oTmbTKnqQGV loIJxDTAjsJURb3VFqspGdbJw7CTNsew4GYjGElo0tzoHxHeLwPF1lvtWTyb7jxVP07EAjxnxrr n83bNID0mvHGXd5llJTD5edin9ckduYb+YdtOB3Tnsi/zMEcBmlVkDKEEe6LGJr0NkWH256kgHE Jbp+JkVv+l0awWeyq7pcoBubjmRkjOfIyAh+D6T1tUYpyfLNuqBLHpLbd9bM1NcGl+gOKCio25A nBTG+0s4NIme4nSHYPmgpJbjiu/fTgo2bnB3vOX+8jmxU4hZVDmDtrq+bswCQk0KVTX5Tgvzyod Mi2A6nZH0eFWjAKhc9q2sHP7blYgJ2uwLnBowRMvBzQQaPM9FtTruhjxvUJjzHe9pgMXX+D3hdj 0yj26FpMFtn/CFTsZDkwy4IsdWZk9x+me8w7H9YFrs+9jTwmXwYSujTtA2HZkNEBn/pEmOVA3Oc Ez9iCY57iwK2ESWvZSQ== X-Proofpoint-ORIG-GUID: 8Dq8dIQxuomYLAWqm55S1sYfxskLU-_D X-Authority-Analysis: v=2.4 cv=CNgamxrD c=1 sm=1 tr=0 ts=6a9692f4 cx=c_pps a=GFwsV6G8L6GxiO2Y/PsHdQ==:117 a=GFwsV6G8L6GxiO2Y/PsHdQ==:17 a=VdqzKS8jKosA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=U7nrCbtTmkRpXpFmAIza:22 a=VnNF1IyMAAAA:8 a=X5N5VOIQNw_dEAXGeB4A:9 X-Proofpoint-GUID: 8Dq8dIQxuomYLAWqm55S1sYfxskLU-_D X-Proofpoint-Spam-Info: AW1haW4tMjYwOTAxMDA3NSBTYWx0ZWRfXz1COVybEDvyQ /K3kItFsUGfwlRCOOhOyJbZMXn14GOXvxybBQN/1EcgVTW4TOt2IK6bDbjXZSr8b5p9rwpZkdbc aSW2SOENZAxWIIJH2SmHVUdhqFWGAzM= X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-09-01_02,2026-08-31_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 bulkscore=0 suspectscore=0 phishscore=0 lowpriorityscore=0 priorityscore=1501 clxscore=1015 impostorscore=0 adultscore=0 malwarescore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2609010075 Move mutex locking from per CPU allocation to event allocation. No functional change. Signed-off-by: Thomas Richter Reviewed-by: Sumanth Korikkar --- arch/s390/kernel/perf_pai.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/arch/s390/kernel/perf_pai.c b/arch/s390/kernel/perf_pai.c index 7c13f5586c79..52d9f654346a 100644 --- a/arch/s390/kernel/perf_pai.c +++ b/arch/s390/kernel/perf_pai.c @@ -138,21 +138,19 @@ static void pai_free(struct pai_mapptr *mp) } /* Adjust usage counters and remove allocated memory when all users are - * gone. + * gone. Called under mutex_lock. */ static void pai_event_destroy_cpu(int idx, int cpu) { struct pai_mapptr *mp = per_cpu_ptr(pai_root[idx].mapptr, cpu); struct pai_map *cpump = mp->mapptr; - mutex_lock(&pai_reserve_mutex); debug_sprintf_event(paidbg, 5, "%s users %d refcnt %u\n", __func__, cpump->active_events, refcount_read(&cpump->refcnt)); if (refcount_dec_and_test(&cpump->refcnt)) pai_free(mp); pai_root_free(idx); - mutex_unlock(&pai_reserve_mutex); } static void pai_event_destroy(struct perf_event *event) @@ -160,6 +158,7 @@ static void pai_event_destroy(struct perf_event *event) int cpu = 0, idx = PAI_PMU_IDX(event); free_page(PAI_SAVE_AREA(event)); + mutex_lock(&pai_reserve_mutex); if (event->cpu == -1) { struct cpumask *mask = PAI_CPU_MASK(event); @@ -169,6 +168,7 @@ static void pai_event_destroy(struct perf_event *event) } else { pai_event_destroy_cpu(idx, event->cpu); } + mutex_unlock(&pai_reserve_mutex); } static void paicrypt_event_destroy(struct perf_event *event) @@ -232,12 +232,10 @@ static u64 paicrypt_getall(struct perf_event *event) return sum; } -/* Check concurrent access of counting and sampling for crypto events. - * This function is called in process context and it is save to block. - * When the event initialization functions fails, no other call back will - * be invoked. - * - * Allocate the memory for the event. +/* Allocate all per-CPU data structures. This function is called in + * process context and can block. In case of error all partly allocated + * memory is released and the reference counters adjusted correctly. + * Called under mutex_lock. */ static int pai_alloc_cpu(int idx, int cpu) { @@ -246,11 +244,10 @@ static int pai_alloc_cpu(int idx, int cpu) struct pai_mapptr *mp; int rc; - mutex_lock(&pai_reserve_mutex); /* Allocate root node */ rc = pai_root_alloc(idx); if (rc) - goto unlock; + goto out; /* Allocate node for this event */ mp = per_cpu_ptr(pai_root[idx].mapptr, cpu); @@ -308,12 +305,12 @@ static int pai_alloc_cpu(int idx, int cpu) */ pai_root_free(idx); } -unlock: - mutex_unlock(&pai_reserve_mutex); +out: /* If rc is non-zero, no increment of counter/sampler was done. */ return rc; } +/* Called under mutex_lock */ static int pai_alloc(struct perf_event *event) { int idx = PAI_PMU_IDX(event); @@ -390,10 +387,12 @@ static int pai_event_init(struct perf_event *event, int idx) } } + mutex_lock(&pai_reserve_mutex); if (event->cpu >= 0) rc = pai_alloc_cpu(idx, event->cpu); else rc = pai_alloc(event); + mutex_unlock(&pai_reserve_mutex); if (rc) { free_page(PAI_SAVE_AREA(event)); goto out; -- 2.55.0