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 0974533AD88; Mon, 10 Aug 2026 15:54:33 +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=1786377275; cv=none; b=A6axVZbv4GOssgbqhzz31ytOK4hI9ljvjPl4ODI+I5PPtSs6QCXYlryssfM9Hj96rw2G0MZq8fNBD2RV4aOmjPQVxLfynRM+4nuWwZhoWqHzQrjeWdUNA9x9JmAIbMDgKbqRyCeaRx78LpXsUcn9JE3a6eJQ1E90poFYkWc67T4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786377275; c=relaxed/simple; bh=pbKUNDDyEQnSiAGvSD6q9iktKaNo/9iyZDSRcSxQOzQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=iTJzSqnGxksWdWPrvVlKGa/SMg9FiDkWw9gU2hSOMivf2DEIlp8CfwleGcuvMbCYIiNPQ8o+IMvfuApDDv1h+ctnethPwSX7HwYOQsPpOwvj4xhhlMp+E3qthHEHOvYqCbtiS6qgHGrcSAznIUUH/nyR5IBFE5zlzcAsjbwrrtY= 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=hxXiF0YN; 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="hxXiF0YN" 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 67AFX25F1983779; Mon, 10 Aug 2026 15:54:28 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pp1; bh=eJEyXf apTU97DGj61icUtCk2YETHkxIuZSEjKmGH8D0=; b=hxXiF0YN8NyAVhfiLEcTOC /TGu6FjBQRdIbyf3mQUM6vLqZfXClQSVoTtrwp2llt72joPqo5l/aSgagzI5u1VL /vF43izughFutqGVhyKX8okhwhgPftpX6UTAsdUY6XLZlZkXUyQlB9+qiXKhmUwz LWnrFdx6QxOLgfsPDjYxverEqZHZZr/+n9zYbfOVv+7aIuZ1HY6K/F1NmZ+kligO fE7qng2M37J7bUT/2pB1zLqC5cBrzSBzdomzgfrlvFiHPblilZoZRA6JKOO+nuKN MY0o0XJwbxOoNBy0Wi+fAK8S3Yg8aXbzXg7QHwq4nlRxeg1Onne+AAHRGes+XkCA == Received: from ppma12.dal12v.mail.ibm.com (dc.9e.1632.ip4.static.sl-reverse.com [50.22.158.220]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4fwvq98t6m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 10 Aug 2026 15:54:27 +0000 (GMT) Received: from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1]) by ppma12.dal12v.mail.ibm.com (8.18.1.7/8.18.1.7) with ESMTP id 67AFgY2J024485; Mon, 10 Aug 2026 15:54:27 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 4fxespwjkg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 10 Aug 2026 15:54:27 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 67AFsNZ030278224 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 10 Aug 2026 15:54:23 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5A1F020040; Mon, 10 Aug 2026 15:54:23 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BD73520049; Mon, 10 Aug 2026 15:54:22 +0000 (GMT) Received: from [192.168.88.52] (unknown [9.111.41.151]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 10 Aug 2026 15:54:22 +0000 (GMT) From: Christoph Schlameuss Date: Mon, 10 Aug 2026 17:54:04 +0200 Subject: [PATCH v2 16/20] KVM: s390: vsie: Allow guest-3 cpu add and remove with ssca Precedence: bulk X-Mailing-List: linux-s390@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260810-vsie-sigpi-v2-16-e8d59a2f2f70@linux.ibm.com> References: <20260810-vsie-sigpi-v2-0-e8d59a2f2f70@linux.ibm.com> In-Reply-To: <20260810-vsie-sigpi-v2-0-e8d59a2f2f70@linux.ibm.com> To: kvm@vger.kernel.org, linux-s390@vger.kernel.org Cc: Alexander Gordeev , Christian Borntraeger , Claudio Imbrenda , David Hildenbrand , Eric Farman , Heiko Carstens , Janosch Frank , Nico Boehr , Paolo Bonzini , Shuah Khan , Sven Schnelle , Vasily Gorbik , Christoph Schlameuss X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4501; i=schlameuss@linux.ibm.com; h=from:subject:message-id; bh=pbKUNDDyEQnSiAGvSD6q9iktKaNo/9iyZDSRcSxQOzQ=; b=owGbwMvMwCUmoqVx+bqN+mXG02pJDFmVX5Qufl/w1e+5vdeWjwoMW2wD17Y/iHzOOVnjl1mQT pPAnHtcHaUsDGJcDLJiiizV4tZ5VX2tS+cctLwGM4eVCWQIAxenAEzk6TNGhr2/fI+fP7TJ1Kb7 an60yc4mr4rAx/0vqlpjg4K6T7YvkWFk2G3f23W1QupZ+FHWaZ5fZI9m/arum2T5QjGEvfF8Bn8 fHwA= X-Developer-Key: i=schlameuss@linux.ibm.com; a=openpgp; fpr=0E34A68642574B2253AF4D31EEED6AB388551EC3 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: DAjtBGiA778tfxl3N9Mv16JEemJrWgV9 X-Authority-Analysis: v=2.4 cv=PbDPQChd c=1 sm=1 tr=0 ts=6a79f434 cx=c_pps a=bLidbwmWQ0KltjZqbj+ezA==:117 a=bLidbwmWQ0KltjZqbj+ezA==:17 a=IkcTkHD0fZMA:10 a=Sv0fKeRqtYgA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=iQ6ETzBq9ecOQQE5vZCe:22 a=VnNF1IyMAAAA:8 a=PXeH2Pb9wBGPeq1YnyQA:9 a=QEXdDO2ut3YA:10 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwODEwMDEzNCBTYWx0ZWRfX4lvLl8txpLbH kF8EUuxlZOICtcukoT13z2pyEipb/3Q2k64WYAuMaDDRkRBr9YYXcMJYsTIt+Ehsw/HVlLrNnBg 5lLPZAyObwDt5OHWQg8bmrEfFzvh3BNvF2XkmF2oMspe2F28eGl5MK+O8Rt79QTLGt/Pu6ptEKf V3osPzSACm+D1GmzOdFleB6Ng2XpTQwi13eFuAJz05avEzNOvdlgxs7rczCftN6eT7HdqyqYGcP gN6rWW2ACymvmueDufQ+xTgRRoOGSvMMJT6VfEOQ5KStDL/htKwF1rBQvmjSaPSkEY0rgrBjMAc jYrrVDbNaOrldpkdBVHvo1P12cn0ejgqNvd9CcMSiyh68m2nXMGobGBZBibjhhBkp4H72Tp9iAE yvmhvepX7SYA8E943l4gZw/FjOYwTqpR/WB/WaUMv/1eljjEssuPia52PkLO2YQLBSMK5AE/GoN WfCp/v2G8MzWrmwp/GA== X-Proofpoint-ORIG-GUID: DAjtBGiA778tfxl3N9Mv16JEemJrWgV9 X-Proofpoint-Spam-Info: AW1haW4tMjYwODEwMDEzNCBTYWx0ZWRfX0rFSC/M22lw4 /QBaKGpZb4HTJrsJIRuNdOIbMmXR2gFqbHO7qNfuz6/xawuJr+QUzuGnKsDmjAy1Y83fZm0goj3 NFqlhcDMyNnyLoEdf2Tw/18qD3I6a8g= 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-08-10_03,2026-08-10_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 bulkscore=0 impostorscore=0 malwarescore=0 adultscore=0 clxscore=1015 priorityscore=1501 suspectscore=0 phishscore=0 lowpriorityscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2608100134 As we are shadowing the SCA we need to add and remove the pointers to the shadowed control blocks and sca entries whenever the mcn / processors in the configuration changes. It is not expected that the mcn changes frequently for an already running guest-3 configuration. So we can simply fully re-init the ssca whenever the mcn changes. To detect the mcn change we store the expected mcn in the struct vsie_sca when running _shadow_sca(). Signed-off-by: Christoph Schlameuss --- arch/s390/kvm/vsie.c | 68 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 58 insertions(+), 10 deletions(-) diff --git a/arch/s390/kvm/vsie.c b/arch/s390/kvm/vsie.c index 844ffd3244fe..3ae346265b81 100644 --- a/arch/s390/kvm/vsie.c +++ b/arch/s390/kvm/vsie.c @@ -2051,6 +2051,43 @@ static struct vsie_page *get_vsie_page_cpu_nr(struct kvm_vcpu *vcpu, struct vsie return vsie_page; } +/* + * Copy the mcn from the osca to the vsie_sca to be able to detect mcn changes later on. + * + * @vsie_sca: vsie_sca to copy mcn to. + * @sca: Pointer to a struct bsca_block or struct esca_block to read from. + */ +static void sca_mcn_copy(struct vsie_sca *vsie_sca, void *sca) +{ + int offset = offsetof(struct bsca_block, mcn); + int size = sizeof(unsigned long); + + if (test_bit(VSIE_SCA_ESCA, &vsie_sca->flags)) { + offset = offsetof(struct esca_block, mcn); + size = size * 4; + } + memcpy(&vsie_sca->mcn, sca + offset, size); +} + +/* + * Compare the mcn from the given sca to the vsie_sca to be able to detect mcn changes. + * + * @vsie_sca: vsie_sca to compare mcn to. + * @sca: Pointer to a struct bsca_block or struct esca_block to compare to. + */ +static bool sca_mcn_equals(struct vsie_sca *vsie_sca, void *sca) +{ + int offset = offsetof(struct bsca_block, mcn); + int size = sizeof(unsigned long); + + if (test_bit(VSIE_SCA_ESCA, &vsie_sca->flags)) { + size = size * 4; + offset = offsetof(struct esca_block, mcn); + } + + return !memcmp(&vsie_sca->mcn, sca + offset, size); +} + static void vsie_sca_update(struct vsie_sca *vsie_sca, unsigned int cpu_nr, struct vsie_page *vsie_page_n, hpa_t sca_o_entry_hpa) { @@ -2070,18 +2107,16 @@ static int _shadow_sca(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page, struct vsie_page *vsie_page_n; hpa_t sca_o_entry_hpa; hva_t sca_o_entry_hva; - unsigned long *mcn; gpa_t scb_o_gpa; int rc; if (is_esca) - mcn = phys_to_virt(sca_o_hpa(vsie_sca)) + offsetof(struct esca_block, mcn); - else - mcn = phys_to_virt(sca_o_hpa(vsie_sca)) + offsetof(struct bsca_block, mcn); + __set_bit(VSIE_SCA_ESCA, &vsie_sca->flags); + sca_mcn_copy(vsie_sca, phys_to_virt(sca_o_hpa(vsie_sca))); /* pin and make shadow for ALL scb in the sca */ cpu_slots = is_esca ? KVM_S390_MAX_VSIE_VCPUS : KVM_S390_BSCA_CPU_SLOTS; - for_each_set_bit_inv(cpu_nr, mcn, cpu_slots) { + for_each_set_bit_inv(cpu_nr, (unsigned long *)&vsie_sca->mcn, cpu_slots) { rc = get_sca_entry_addr(vcpu->kvm, vsie_sca, cpu_nr, NULL, &sca_o_entry_hpa); if (rc) goto err; @@ -2117,23 +2152,36 @@ static int _shadow_sca(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page, return 0; err: - for_each_set_bit_inv(cpu_nr, mcn, cpu_slots) { + vsie_sca->ssca.osca = 0; + for_each_set_bit_inv(cpu_nr, (unsigned long *)&vsie_sca->mcn, cpu_slots) { vsie_sca->ssca.cpu[cpu_nr].ssda = 0; vsie_sca->ssca.cpu[cpu_nr].ossea = 0; } return rc; } +static bool config_changed(struct vsie_page *vsie_page, struct vsie_sca *vsie_sca) +{ + bool changed = !vsie_sca->ssca.osca; + + changed = changed || sie_uses_esca(vsie_page->scb_o) != + test_bit(VSIE_SCA_ESCA, &vsie_sca->flags); + return changed || !sca_mcn_equals(vsie_sca, phys_to_virt(sca_o_hpa(vsie_sca))); +} + /* Shadow or reshadow the SCA on VSIE enter. */ static int shadow_sca(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page, struct vsie_sca *vsie_sca) { - int rc = 0; + scoped_guard(rwsem_read, &vcpu->kvm->arch.vsie.vsie_sca_lock) { + if (!config_changed(vsie_page, vsie_sca)) + return 0; + } guard(rwsem_write)(&vcpu->kvm->arch.vsie.vsie_sca_lock); - if (!vsie_sca->ssca.osca) - rc = _shadow_sca(vcpu, vsie_page, vsie_sca); + if (!config_changed(vsie_page, vsie_sca)) + return 0; - return rc; + return _shadow_sca(vcpu, vsie_page, vsie_sca); } int kvm_s390_handle_vsie(struct kvm_vcpu *vcpu) -- 2.55.0