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 13F0F534451; Tue, 13 Oct 2026 15:32:51 +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=1791905573; cv=none; b=uJlwvi+sjBfWd0NNo2tZkqDTCkC0h1FtwvNJ1z+voqtXfcnC225L/3/M44pV04UQI1BGV7l/UijyJPFiE0gEu4rx+9nzitMsd3+t2hr2tHnABvat6AvYjeNnCpdJNzVrtUDyjFfpTT9UcBkAMK58zJ67pBwWb/kKgF1+yCAMBOw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791905573; c=relaxed/simple; bh=stOag1eM2e3ktvWsD/UCDytefx6z1v8t3vr8OyEpI0c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pcugXtxIwv6LjbwKHAKyKuH+JGlxAtE8Yo03/B/a1DL9S8ufHjqwaROEcyHevFQ2195m8L9SVRcWDT6jOL5YOFrJwZn+j17VQvcI54AsKn7GwKvnzENhjJvWnzCHxYMGgpxMTAJLrECQROYkSJKXzpcrQz+bBp6XHRQou2Ggb9U= 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=C5xnig+V; 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="C5xnig+V" Received: from pps.filterd (m0360083.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 69DE0pjP2016027; Tue, 13 Oct 2026 15:32:40 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=vmigop82pP2ICkkpL x/1phcp7fszWB85DwuBAtpEFTM=; b=C5xnig+VY8Nv2dwot48HXUesHidIqiHUS O2pYYepTRXT+riZxgqFp0LuREe9OaS9fW+WdtQ4Eelgci2NA1AscPYI5ucdh2Lom ZV+7u+0ziB68/kcWUqMJUCNxjgJqBIN7ngBcPu2fmmIJA8SmjyjOUxm7H0p+TdnU +8EXbo/xKGrDuIcz9DMdHsWqwq/oGTHVnlLjr49mTh6LIOJ/B1UjCJnMiT6a0lgM LOvVENLWy/lL/AAGysZFQIeNlsnJargz1GMvi2LOz6Uuk8V3/GavfXIvoD1LbLuP rYVh0zebwWxl6VZ2CwduaFnPI9qUeKlB+lPhCP5pZfOxHx9I/0CRw== 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 4h7dugf2nv-1 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 13 Oct 2026 15:32:40 +0000 (GMT) Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.18.1.11/8.18.1.11) with ESMTP id 69DFC6fA3211944; Tue, 13 Oct 2026 15:32:39 GMT Received: from smtprelay06.wdc07v.mail.ibm.com ([172.16.1.73]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4h9q2yg3ap-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Oct 2026 15:32:39 +0000 (GMT) Received: from smtpav01.wdc07v.mail.ibm.com (smtpav01.wdc07v.mail.ibm.com [10.39.53.228]) by smtprelay06.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 69DFWcNs48103774 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 13 Oct 2026 15:32:38 GMT Received: from smtpav01.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 643EC5804B; Tue, 13 Oct 2026 15:32:38 +0000 (GMT) Received: from smtpav01.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C24B158063; Tue, 13 Oct 2026 15:32:36 +0000 (GMT) Received: from li-4c4c4544-004d-4810-8043-b7c04f423534.ibm.com.com (unknown [9.61.17.246]) by smtpav01.wdc07v.mail.ibm.com (Postfix) with ESMTP; Tue, 13 Oct 2026 15:32:36 +0000 (GMT) From: Anthony Krowiak To: linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: jjherne@linux.ibm.com, borntraeger@de.ibm.com, mjrosato@linux.ibm.com, pasic@linux.ibm.com, alex@shazbot.org, kwankhede@nvidia.com, fiuczy@linux.ibm.com, pbonzini@redhat.com, frankja@linux.ibm.com, imbrenda@linux.ibm.com, agordeev@linux.ibm.com, hca@linux.ibm.com, gor@linux.ibm.com Subject: [PATCH v9 09/15] s390/vfio-ap: Prepare lock helpers and matrix init for cross-file use Date: Tue, 13 Oct 2026 11:32:13 -0400 Message-ID: <20261013153219.3534306-10-akrowiak@linux.ibm.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261013153219.3534306-1-akrowiak@linux.ibm.com> References: <20261013153219.3534306-1-akrowiak@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Authority-Analysis: v=2.4 cv=Cr0q4X4D c=1 sm=1 tr=0 ts=6ace4f18 cx=c_pps a=GFwsV6G8L6GxiO2Y/PsHdQ==:117 a=GFwsV6G8L6GxiO2Y/PsHdQ==:17 a=660iZSQnnn4A:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=iQ6ETzBq9ecOQQE5vZCe:22 a=VnNF1IyMAAAA:8 a=fTSzii-f3gA6o6vWqDQA:9 X-Proofpoint-GUID: SXUtzXnhOFgbzRTPWCkrlaJ-aMMTaaLj X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMDEzMDA2MCBTYWx0ZWRfX7b45tS/bjZQb VjssruNSY6IF6X1F84bAJ04SYfw1PaBVDVHp3Y/tC8UnPLuK7C/katoEwBPj4dOvqn7wfedX4Qy qATSpc5taD5MOYq9kH4KP7nCgRQkWHMwq41OGbsBvVg5nKcwe7RA4zE7xooCwIxcnoSl/wRk/2u zDOWKVAT799w9Y2RTUWSJ0siItSo/qiaWEjAXvk1QRK4MOTq5/fVMZCcTwv5KBn1JclIAqgF82n OuVP3Lv5PhFGrz9ezf9ilDG3LjWHI8WfV+5mFiixnGNhwkix7PewK7i5+CRDN70e3gjHopgqRNi hO1Qrjfv1YUMFC8j4vmVqdqr9goYZorC0Ted/5Qp2x2VJiG6FyefUIYcBK6krCDLUMvGaKFEAkq d+OcIVqMRd4x1LT/URh8ET+ivfUo/Ac2dSSWFjNFr+Mk5aWKkdRaBhiKe9fcVfPyuSRy/7iVVSo Ab/sl1NP4QNrIsPg6eQ== X-Proofpoint-Spam-Info: AW1haW4tMjYxMDEzMDA2MCBTYWx0ZWRfX0Bagv9Qw4f6C +A1LAmx18BmIVjdcGRXMFpzJ4Dj19T2NZ1xryHP3dDe600sUwRm5yEG40k9etJAIbeu1bPbLOVL DLW6BNA3bLy/6FyRsrUmqljDgAtJw+0= X-Proofpoint-ORIG-GUID: SXUtzXnhOFgbzRTPWCkrlaJ-aMMTaaLj 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-10-13_01,2026-10-09_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 spamscore=0 adultscore=0 priorityscore=1501 suspectscore=0 malwarescore=0 clxscore=1015 impostorscore=0 lowpriorityscore=0 phishscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2610080000 definitions=main-2610130060 Move get_update_locks_for_mdev(), release_update_locks_for_mdev(), and assert_has_update_locks_for_mdev() from vfio_ap_ops.c into vfio_ap_private.h as static inline functions so they are accessible to vfio_ap_migration.c in subsequent patches. Make vfio_ap_matrix_init() non-static and add its declaration to vfio_ap_private.h for the same reason. No functional change. Signed-off-by: Anthony Krowiak --- drivers/s390/crypto/vfio_ap_ops.c | 50 +---------------------- drivers/s390/crypto/vfio_ap_private.h | 58 +++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 49 deletions(-) diff --git a/drivers/s390/crypto/vfio_ap_ops.c b/drivers/s390/crypto/vfio_ap_ops.c index 3095e771b6a5..c951f289f305 100644 --- a/drivers/s390/crypto/vfio_ap_ops.c +++ b/drivers/s390/crypto/vfio_ap_ops.c @@ -88,53 +88,6 @@ static inline void release_update_locks_for_kvm(struct kvm *kvm) mutex_unlock(&matrix_dev->guests_lock); } -/** - * get_update_locks_for_mdev: Acquire the locks required to dynamically update a - * KVM guest's APCB in the proper order. - * - * @matrix_mdev: a pointer to a struct ap_matrix_mdev object containing the AP - * configuration data to use to update a KVM guest's APCB. - * - * The proper locking order is: - * 1. matrix_dev->guests_lock: required to use the KVM pointer to update a KVM - * guest's APCB. - * 2. matrix_mdev->kvm->lock: required to update a guest's APCB - * 3. matrix_dev->mdevs_lock: required to access data stored in a matrix_mdev - * - * Note: If @matrix_mdev is NULL or is not attached to a KVM guest, the KVM - * lock will not be taken. - */ -static inline void get_update_locks_for_mdev(struct ap_matrix_mdev *matrix_mdev) -{ - mutex_lock(&matrix_dev->guests_lock); - if (matrix_mdev && matrix_mdev->kvm) - mutex_lock(&matrix_mdev->kvm->lock); - mutex_lock(&matrix_dev->mdevs_lock); -} - -/** - * release_update_locks_for_mdev: Release the locks used to dynamically update a - * KVM guest's APCB in the proper order. - * - * @matrix_mdev: a pointer to a struct ap_matrix_mdev object containing the AP - * configuration data to use to update a KVM guest's APCB. - * - * The proper unlocking order is: - * 1. matrix_dev->mdevs_lock - * 2. matrix_mdev->kvm->lock - * 3. matrix_dev->guests_lock - * - * Note: If @matrix_mdev is NULL or is not attached to a KVM guest, the KVM - * lock will not be released. - */ -static inline void release_update_locks_for_mdev(struct ap_matrix_mdev *matrix_mdev) -{ - mutex_unlock(&matrix_dev->mdevs_lock); - if (matrix_mdev && matrix_mdev->kvm) - mutex_unlock(&matrix_mdev->kvm->lock); - mutex_unlock(&matrix_dev->guests_lock); -} - /** * get_update_locks_by_apqn: Find the mdev to which an APQN is assigned and * acquire the locks required to update the APCB of @@ -649,8 +602,7 @@ static int handle_pqap(struct kvm_vcpu *vcpu) return 0; } -static void vfio_ap_matrix_init(struct ap_config_info *info, - struct ap_matrix *matrix) +void vfio_ap_matrix_init(struct ap_config_info *info, struct ap_matrix *matrix) { matrix->apm_max = info->apxa ? info->na : 63; matrix->aqm_max = info->apxa ? info->nd : 15; diff --git a/drivers/s390/crypto/vfio_ap_private.h b/drivers/s390/crypto/vfio_ap_private.h index 79cd378c30d8..9044ef4408c8 100644 --- a/drivers/s390/crypto/vfio_ap_private.h +++ b/drivers/s390/crypto/vfio_ap_private.h @@ -177,4 +177,62 @@ int vfio_ap_init_migration_data(struct ap_matrix_mdev *matrix_mdev); void vfio_ap_release_migration_data(struct ap_matrix_mdev *matrix_mdev); void vfio_ap_reset_migration_state(struct ap_matrix_mdev *matrix_mdev); +/** + * get_update_locks_for_mdev: Acquire the locks required to dynamically update a + * KVM guest's APCB in the proper order. + * + * @matrix_mdev: a pointer to a struct ap_matrix_mdev object containing the AP + * configuration data to use to update a KVM guest's APCB. + * + * The proper locking order is: + * 1. matrix_dev->guests_lock: required to use the KVM pointer to update a KVM + * guest's APCB. + * 2. matrix_mdev->kvm->lock: required to update a guest's APCB + * 3. matrix_dev->mdevs_lock: required to access data stored in a matrix_mdev + * + * Note: If @matrix_mdev is NULL or is not attached to a KVM guest, the KVM + * lock will not be taken. + */ +static inline void get_update_locks_for_mdev(struct ap_matrix_mdev *matrix_mdev) +{ + mutex_lock(&matrix_dev->guests_lock); + if (matrix_mdev && matrix_mdev->kvm) + mutex_lock(&matrix_mdev->kvm->lock); + mutex_lock(&matrix_dev->mdevs_lock); +} + +/** + * release_update_locks_for_mdev: Release the locks used to dynamically update a + * KVM guest's APCB in the proper order. + * + * @matrix_mdev: a pointer to a struct ap_matrix_mdev object containing the AP + * configuration data to use to update a KVM guest's APCB. + * + * The proper unlocking order is: + * 1. matrix_dev->mdevs_lock + * 2. matrix_mdev->kvm->lock + * 3. matrix_dev->guests_lock + * + * Note: If @matrix_mdev is NULL or is not attached to a KVM guest, the KVM + * lock will not be released. + */ +static inline void release_update_locks_for_mdev(struct ap_matrix_mdev *matrix_mdev) +{ + mutex_unlock(&matrix_dev->mdevs_lock); + if (matrix_mdev && matrix_mdev->kvm) + mutex_unlock(&matrix_mdev->kvm->lock); + mutex_unlock(&matrix_dev->guests_lock); +} + +static inline void +assert_has_update_locks_for_mdev(struct ap_matrix_mdev *matrix_mdev) +{ + lockdep_assert_held(&matrix_dev->guests_lock); + if (matrix_mdev && matrix_mdev->kvm) + lockdep_assert_held(&matrix_mdev->kvm->lock); + lockdep_assert_held(&matrix_dev->mdevs_lock); +} + +void vfio_ap_matrix_init(struct ap_config_info *info, struct ap_matrix *matrix); + #endif /* _VFIO_AP_PRIVATE_H_ */ -- 2.53.0