From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (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 A6D1C486BA9; Thu, 27 Aug 2026 15:53:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787845990; cv=none; b=UBLWz4Yg2X1RHhzqIUij7h1oVV+hIpHEw5CfmTZzYnisERlWIpSPLHTQonc3MNxA09VJlhlPVRghD8UCVjdbkv724RIDymQYUrSxrCgBlbn3j6tfhepVb09gTwVKqO0jW7kN5SAarbG6Qvb32j+4FqfmVDE5ryGds1lIBPPbkwk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787845990; c=relaxed/simple; bh=GGMbtyEuxzIWuM9bBkuwnluaQBjqdO1ctV3RbbWb7OQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=LMblGffogysip2SKLHGj4N6vWU3jriuG8qI1ceN0cuQnEyda31CXvW/BPkjq3YPYTVe9tJbIMrMZAEdHULYOU13FZu+6RTuZa9irWkpSyKPE6gS4ilms3gS7am0LyQLTiPS17oBIoWx4mLZ6PFr/Cx3wWl9CQEqyuO4JM9UA7dk= 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=q5jPqch8; arc=none smtp.client-ip=148.163.158.5 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="q5jPqch8" Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 67RF5B5A2224771; Thu, 27 Aug 2026 15:53:05 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=MT+Rbw P/QlHzq7dx/FEVabIZ9enBy18WWWj/Tnk6Gj8=; b=q5jPqch8hvvxf9SVqmTdxf /uzduGgZ+LsE00x8VFKfz9Jv95FXV893Z04nndvWNzQILqXq1qZTXuo4QPYozJHP wsUYWdbjZBqChTBkEfTsKVFEfhj1HGFoDQJt1kouD3+s4yXfMb96UL/+yFbwi70T HCP6PO1CmRxG2mIWsbP7sjnucGlpzqP1HpNUfmrj7Tfuk1Z/xOxc3KRr3MY53L63 hX/sNSGE5qFBn8LYV+ZEGBgGagLLm7AMf45vqtWPmAKkZip44NXIGes7x4qBFIT+ 7h32s1QgDQnl4LPoM0siTptU1ZXv5rh3+Y4QrZPQ3pT/hqhzD3z06w2Qu7o5Enjw == Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4g726ex8su-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 27 Aug 2026 15:53:04 +0000 (GMT) Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.18.1.7/8.18.1.7) with ESMTP id 67RFfhG6015127; Thu, 27 Aug 2026 15:53:03 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4g7pfwgyym-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 27 Aug 2026 15:53:03 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 67RFqxVo41287982 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 27 Aug 2026 15:52:59 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8FF3E2004F; Thu, 27 Aug 2026 15:52:59 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D870820043; Thu, 27 Aug 2026 15:52:58 +0000 (GMT) Received: from [192.168.88.251] (unknown [9.111.61.153]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 27 Aug 2026 15:52:58 +0000 (GMT) From: Christoph Schlameuss Date: Thu, 27 Aug 2026 17:52:47 +0200 Subject: [PATCH v6 07/21] KVM: s390: vsie: Move release/acquire gmap shadow Precedence: bulk X-Mailing-List: kvm@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: <20260827-vsie-sigpi-v6-7-8020bb53be52@linux.ibm.com> References: <20260827-vsie-sigpi-v6-0-8020bb53be52@linux.ibm.com> In-Reply-To: <20260827-vsie-sigpi-v6-0-8020bb53be52@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 , Sven Schnelle , Vasily Gorbik , Paolo Bonzini , Shuah Khan , Sean Christopherson , Christoph Schlameuss X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4854; i=schlameuss@linux.ibm.com; h=from:subject:message-id; bh=GGMbtyEuxzIWuM9bBkuwnluaQBjqdO1ctV3RbbWb7OQ=; b=owGbwMvMwCUmoqVx+bqN+mXG02pJDFkTYoNk8t7y79X0OMc/uSmOeYm3fn5Qc8CEeRkeHLXzu nN1vFZ0lLIwiHExyIopslSLW+dV9bUunXPQ8hrMHFYmkCEMXJwCMJFiY0aGTf+2Hrv3eM2jNG0L uWj34sM2m49wbtzXl2T/0T8u6cjhPYwMl07yRBxcdtyjmuWihMxCkf0XBI4nnvW6kKXquyVl6aZ MFgA= X-Developer-Key: i=schlameuss@linux.ibm.com; a=openpgp; fpr=0E34A68642574B2253AF4D31EEED6AB388551EC3 X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Authority-Analysis: v=2.4 cv=TfimcxQh c=1 sm=1 tr=0 ts=6a905d60 cx=c_pps a=5BHTudwdYE3Te8bg5FgnPg==:117 a=5BHTudwdYE3Te8bg5FgnPg==:17 a=IkcTkHD0fZMA:10 a=Sv0fKeRqtYgA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=V8glGbnc2Ofi9Qvn3v5h:22 a=VnNF1IyMAAAA:8 a=_7pECfS6dbZ_FIWTgVQA:9 a=QEXdDO2ut3YA:10 X-Proofpoint-Spam-Info: AW1haW4tMjYwODI3MDEzMSBTYWx0ZWRfX3XT0AsxuG/tA TRSYz6qLBtEKu09vzsnKtRPRHEAmmALPlxzbuAjJGz3FQPQ4PyPHhMHRkMB+QCOwyh932NhUtSZ J4dpkPeMwfjwVi9BkKJfdxrd3xw0HQU= X-Proofpoint-GUID: _9Mkwgu3qF1W_VC27toOwH1UnENwMIzh X-Proofpoint-ORIG-GUID: QPmQ7pru5JEe6DQ0ULVEQLu3NmWXrOqc X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwODI3MDEzMSBTYWx0ZWRfX5duk/hqwqKsR O86OwG5qqRAuV93FIYSEByvi062QW+gcWuFwNMBS6KLceMfuMmsLozledMSxljPFc3khNWXJLCa rBQOIxLq4vmr+T7hjf21f6TTKnbwetdF2wr7jrvKwzwoFmaKoI/Q2gnCq6fYo/r/tq221RbMjar UaLWZQGfg/vFzEzvY43LXicstQ0EoWXXQ/9ZlLMcy22M3mW2LeAFaK+tPbgtNAq9UMtowrue0+N ygG+5SSlNUO7fEJGYZ1w5Q+NOeBP/U+KFKFsepTBI2w7gAp4p8sNnnBWiwjTfWoihHm05j0fUZX mS8j0YYeclpgn/IOH0ZXRYahY4d1/FpcL65uYbi/0LvWZChDi3ojS5PvZmxcPPMtqfzl2XrcwJK XoFp2ACbJvK4DSthee9v4E0Tswx/HVlLfmmkC2Q6uQJt/SJhEr1miJrNW5JMy2MXrum5MEl7ry1 JrgKxpp1UUrGUEZHANA== 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-27_06,2026-08-27_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 spamscore=0 bulkscore=0 malwarescore=0 priorityscore=1501 lowpriorityscore=0 clxscore=1015 phishscore=0 impostorscore=0 adultscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2608270131 Move {release,acquire}_gmap_shadow() up in preparation for the next patch. No change intended. Signed-off-by: Christoph Schlameuss --- arch/s390/kvm/s390/vsie.c | 130 +++++++++++++++++++++++----------------------- 1 file changed, 65 insertions(+), 65 deletions(-) diff --git a/arch/s390/kvm/s390/vsie.c b/arch/s390/kvm/s390/vsie.c index 55e9399b9b30..afc2e56fcabf 100644 --- a/arch/s390/kvm/s390/vsie.c +++ b/arch/s390/kvm/s390/vsie.c @@ -149,6 +149,71 @@ static int prefix_is_mapped(struct vsie_page *vsie_page) return !(atomic_read(&vsie_page->scb_s.prog20) & PROG_REQUEST); } +static void release_gmap_shadow(struct vsie_page *vsie_page) +{ + struct gmap *gmap = vsie_page->gmap_cache.gmap; + + lockdep_assert_held(&gmap->kvm->arch.gmap->children_lock); + + list_del(&vsie_page->gmap_cache.list); + vsie_page->gmap_cache.gmap = NULL; + prefix_unmapped(vsie_page); + + if (list_empty(&gmap->scb_users)) { + gmap_remove_child(gmap); + gmap_put(gmap); + } +} + +static struct gmap *acquire_gmap_shadow(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page) +{ + union ctlreg0 cr0; + struct gmap *gmap; + union asce asce; + int edat; + + asce.val = vcpu->arch.sie_block->gcr[1]; + cr0.val = vcpu->arch.sie_block->gcr[0]; + edat = cr0.edat && test_kvm_facility(vcpu->kvm, 8); + edat += edat && test_kvm_facility(vcpu->kvm, 78); + + scoped_guard(spinlock, &vcpu->kvm->arch.gmap->children_lock) { + gmap = vsie_page->gmap_cache.gmap; + if (gmap) { + /* + * ASCE or EDAT could have changed since last icpt, or the gmap + * we're holding has been unshadowed. If the gmap is still valid, + * we can safely reuse it. + */ + if (gmap_is_shadow_valid(gmap, asce, edat)) { + vcpu->kvm->stat.gmap_shadow_reuse++; + gmap_get(gmap); + return gmap; + } + /* release the old shadow and mark the prefix as unmapped */ + release_gmap_shadow(vsie_page); + } + } +again: + gmap = gmap_create_shadow(vcpu->arch.mc, vcpu->kvm->arch.gmap, asce, edat); + if (IS_ERR(gmap)) + return gmap; + scoped_guard(spinlock, &vcpu->kvm->arch.gmap->children_lock) { + /* unlikely race condition, remove the previous shadow */ + if (vsie_page->gmap_cache.gmap) + release_gmap_shadow(vsie_page); + if (!gmap->parent) { + gmap_put(gmap); + goto again; + } + vcpu->kvm->stat.gmap_shadow_create++; + list_add(&vsie_page->gmap_cache.list, &gmap->scb_users); + vsie_page->gmap_cache.gmap = gmap; + prefix_unmapped(vsie_page); + } + return gmap; +} + /* * Pin the guest page given by gpa and set hpa to the pinned host address. * Will always be pinned writable. @@ -1311,71 +1376,6 @@ static int do_vsie_run(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page, struc return rc; } -static void release_gmap_shadow(struct vsie_page *vsie_page) -{ - struct gmap *gmap = vsie_page->gmap_cache.gmap; - - lockdep_assert_held(&gmap->kvm->arch.gmap->children_lock); - - list_del(&vsie_page->gmap_cache.list); - vsie_page->gmap_cache.gmap = NULL; - prefix_unmapped(vsie_page); - - if (list_empty(&gmap->scb_users)) { - gmap_remove_child(gmap); - gmap_put(gmap); - } -} - -static struct gmap *acquire_gmap_shadow(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page) -{ - union ctlreg0 cr0; - struct gmap *gmap; - union asce asce; - int edat; - - asce.val = vcpu->arch.sie_block->gcr[1]; - cr0.val = vcpu->arch.sie_block->gcr[0]; - edat = cr0.edat && test_kvm_facility(vcpu->kvm, 8); - edat += edat && test_kvm_facility(vcpu->kvm, 78); - - scoped_guard(spinlock, &vcpu->kvm->arch.gmap->children_lock) { - gmap = vsie_page->gmap_cache.gmap; - if (gmap) { - /* - * ASCE or EDAT could have changed since last icpt, or the gmap - * we're holding has been unshadowed. If the gmap is still valid, - * we can safely reuse it. - */ - if (gmap_is_shadow_valid(gmap, asce, edat)) { - vcpu->kvm->stat.gmap_shadow_reuse++; - gmap_get(gmap); - return gmap; - } - /* release the old shadow and mark the prefix as unmapped */ - release_gmap_shadow(vsie_page); - } - } -again: - gmap = gmap_create_shadow(vcpu->arch.mc, vcpu->kvm->arch.gmap, asce, edat); - if (IS_ERR(gmap)) - return gmap; - scoped_guard(spinlock, &vcpu->kvm->arch.gmap->children_lock) { - /* unlikely race condition, remove the previous shadow */ - if (vsie_page->gmap_cache.gmap) - release_gmap_shadow(vsie_page); - if (!gmap->parent) { - gmap_put(gmap); - goto again; - } - vcpu->kvm->stat.gmap_shadow_create++; - list_add(&vsie_page->gmap_cache.list, &gmap->scb_users); - vsie_page->gmap_cache.gmap = gmap; - prefix_unmapped(vsie_page); - } - return gmap; -} - /* * Register the shadow scb at the VCPU, e.g. for kicking out of vsie. */ -- 2.55.0