From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=148.163.158.5 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1792777455; b=ntWr9PAS6hGE6Uonu+YMFDtv4b+O4lodKWgbM2kXNqoLlfk8oxYuAwbvYQa+FYnEYriw 9FQE+XdvVdZvTczFILOSWu6B8V/8r6HtnStLuk4Cwofwy+vF5rMsM9zHt1fQO0Q3JOAY1 Sz8k6tlMbsIWGY7DScL08807h2Fdi/c7wXXhybKm8pe+gs6iA+EWZuiwSK9/fSvPgd70z ukgOYxioMWIzxMeVKZ4oN+9RWx6awc984w51QnToBPf1B9IUCktVgy3De7YyeM8kdTvzl 22yFWyg9SlQeiFM6laXsduGs4rRnZQvMVtnG4SqrshOwQO/RLLwv1NfJakYVrvy3kdw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1792777455; h=DMARC-Filter:Received:DKIM-Signature:Received:Received:Received: Received:Received:Received:Received:From:To:Cc:Subject:Date: Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-TM-AS-GCONF:X-Proofpoint-Spam-Details-Enc: X-Proofpoint-ORIG-GUID:X-Proofpoint-GUID:X-Proofpoint-Spam-Info: X-Authority-Analysis:X-Proofpoint-Virus-Version: X-Proofpoint-Spam-Details; bh=Zg81FUwF9qZlwOOmSJs9rueHdpIitErXi5ZszLAulKc=; b=bDb9aI2qDpecFj+ZWi2g+zYolhdpcFZjpd9VONklBt7ES63GS/pIda8sl2VEyGlXy56E o0ga4xY3Ibtjgqibe5f/wLXJHOnVjgBURVIO138U7OQwCNNzldLGd8Rk75njH4NtdbcRL Bt62nioz597wbWF6Q7RSoDspl20LskSj7A6sT9XLGKZEM5cEbVg3fkQDZUdzPp0ncc0z9 V2R3q9MR82sC/oKjz9pSHbQNxWwaJsvN1ljPwnvuhqMgi19BNu8yvy0qYojlvnw1aOTJL lopPWMloe9Aup03/8raqNOrQQIU5cL5kgYOwgGQZYcZIXpITR3y2Kt2muFVImqrLlmA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=KKvhJvAx; arc=none smtp.remote-ip=148.163.158.5 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 629C2606A33B; Fri, 23 Oct 2026 17:44:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 629C2606A33B 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, unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=KKvhJvAx Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 69NGpAJK3562594; Fri, 23 Oct 2026 17:44:10 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=Zg81FUwF9qZlwOOmS Js9rueHdpIitErXi5ZszLAulKc=; b=KKvhJvAxUdCA4wUnfqem3aGhN5bqPfL9s lZjothX2wp0NTxoOy69FN7qSYfNsV16xh9I99rnptVmbgV4Dc2mFaODJu7MtjZOF o4KIMHUr31iZFn99+g9NjJ18y/vuoXEar32q/aS/zaammO9nI+YKhyFpRZafT1Mo kUpIXIJ3f+92BBn2Ftfi0uaQ0hQVxwUX+P500KeBksUFOLbk44i9lB0TKH9gJUqa IaghiP9wNZ2wE4+uRGqOl3xt1rSD8OKUf809QfzcxaWJ40EF7Lz1dug7UDO5i0Bc +xZ8p8IZPbB8B41Rj67mAL+0VNw7OpgxU+crUhjyK6sGJwzimin6w== Received: from ppma13.dal12v.mail.ibm.com (dd.9e.1632.ip4.static.sl-reverse.com [50.22.158.221]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4hdw5adx9u-1 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 23 Oct 2026 17:44:10 +0000 (GMT) Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.18.1.11/8.18.1.11) with ESMTP id 69NE65oB1018579; Fri, 23 Oct 2026 17:44:09 GMT Received: from smtprelay04.wdc07v.mail.ibm.com ([172.16.1.71]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 4hg5exsqvf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 23 Oct 2026 17:44:09 +0000 (GMT) Received: from smtpav03.wdc07v.mail.ibm.com (smtpav03.wdc07v.mail.ibm.com [10.39.53.230]) by smtprelay04.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 69NHi7hW64422378 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 23 Oct 2026 17:44:07 GMT Received: from smtpav03.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CEACF5805D; Fri, 23 Oct 2026 17:44:07 +0000 (GMT) Received: from smtpav03.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3B67E58054; Fri, 23 Oct 2026 17:44:06 +0000 (GMT) Received: from li-4c4c4544-004d-4810-8043-b7c04f423534.ibm.com.com (unknown [9.61.48.60]) by smtpav03.wdc07v.mail.ibm.com (Postfix) with ESMTP; Fri, 23 Oct 2026 17:44:06 +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 v10 09/15] s390/vfio-ap: Prepare lock helpers and matrix init for cross-file use Date: Fri, 23 Oct 2026 13:43:43 -0400 Message-ID: <20261023174349.3545941-10-akrowiak@linux.ibm.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261023174349.3545941-1-akrowiak@linux.ibm.com> References: <20261023174349.3545941-1-akrowiak@linux.ibm.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMDIzMDA2OSBTYWx0ZWRfX+UpZdYSP8pVw Hyzg71iqCBM1KTy67Bzsq+UoUCS95WWhU2weiaf1eZ+S8Zt/hOOdi2BtSNKa33aUJMCZGB0iBaS xgmT3t807TiTrJ7dL7s1yf0c3maG84O2PMtwjq/r/penEoYldXJDIpdl9Uunn8vTFUJSPmuz06c 3Lrgz8NsG3sdKZKiHCbjkllQnkd6ZirhAIZ9HQz+QefWcrDqwu0GRkuEUGFYsMhSc2Bl38xdaZI +LgakR2oNCBfB9cpqj3ZwDxn3g9uj2x7ZTKmLjHkYJHnP7dJT+Bpv3+dVSS3LyUzH3lIjC2C+uV r4G+MjKNFYJVQb5+TbfWWM9oN6eUUFYgjbbsKo0nB8rYtiFP8nyjQ3MrYg3V2SRGpeQX8KbED2u SjrAc/2hW9NZ76jNAPicffcSRCEjn/niUkVL1VXF7aWSunroHD1pYota9EZbgP3z7opNXHDGDAE OxQ1nvpqiUaPhkUD6DA== X-Proofpoint-ORIG-GUID: XD7XYzhyNx1K4zMJ0O_z_qfxIqfHmKgp X-Proofpoint-GUID: XD7XYzhyNx1K4zMJ0O_z_qfxIqfHmKgp X-Proofpoint-Spam-Info: AW1haW4tMjYxMDIzMDA2OSBTYWx0ZWRfX+22f/3zvFvAk WC0g0TwHorhFy66n8aUjYVChbRe0ua6MI5OxFBlbWy9Hwjz7hzbwQAbfCmcR60vdzlNgwzDpSXy vofWeN0wBbvv+hs61a8fd9N4Iyugbm4= X-Authority-Analysis: v=2.4 cv=ZfSIpcVA c=1 sm=1 tr=0 ts=6adb9cea cx=c_pps a=AfN7/Ok6k8XGzOShvHwTGQ==:117 a=AfN7/Ok6k8XGzOShvHwTGQ==:17 a=660iZSQnnn4A:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=RzCfie-kr_QcCd8fBx8p:22 a=VnNF1IyMAAAA:8 a=048xGIV9IKhEGYfkAfgA:9 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-10-23_04,2026-10-21_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 impostorscore=0 malwarescore=0 spamscore=0 suspectscore=0 clxscore=1015 phishscore=0 bulkscore=0 lowpriorityscore=0 adultscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2610190000 definitions=main-2610230069 Move get_update_locks_for_mdev() and release_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. Add assert_has_update_locks_for_mdev() to vfio_ap_private.h for lockdep validation of these update locks across files. 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 635c8a20af86..a4eed70b05d8 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 c6e577064e7e..1324d94638d8 100644 --- a/drivers/s390/crypto/vfio_ap_private.h +++ b/drivers/s390/crypto/vfio_ap_private.h @@ -176,4 +176,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