From nobody Tue Dec 2 02:04:17 2025 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 771F53242AB; Thu, 20 Nov 2025 17:16:25 +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=1763658987; cv=none; b=cGptUuN7JBW7UB/2oZ1tjBL/lFbgj+/eQRwy06b8Mkr5q+7dE02Gz+PGPYVV+DizO/3FPbRf1irt+8MVfavTg9TFuMmnc0S86iuDAn3K3FcXac1LL2Q7CMGdamMVAjhWWWHENBESzO2ZbHBL/c+d8Dv4LaH3usmI4MS8vs1FhI8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763658987; c=relaxed/simple; bh=gVuoVjsqmNdGa9KNfggc9JKmi16j23yUI5AoHAqa+QY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sHYlDHzYZ6oNThWS1BfjxcnUB+EEK7ot13f/K+4QFeJqteeTCLTOJONYyiJ5fOlay/+uijoK1dW9fWsNdjQJJyU0SekzLFHbowlIkSttw50XWMizJjdetf13/Y39ftAlz89z2N/YXRML238L2JJj8Wi58xpPCe0BWxr8u/9+Z1I= 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=pVvYfTPx; 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="pVvYfTPx" Received: from pps.filterd (m0353729.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5AKCarh4028121; Thu, 20 Nov 2025 17:16:21 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=+tJ3G0BCx/KpJ4pd/ x+8oFCxk1gtphfpy4kH4nQ+4WU=; b=pVvYfTPxvUvuxrT35PaonV1qcPQEyfaj6 RUBx3/16r/Yqb9+6G5BG1hJpd4AMqOhz57Vxbmj15oLKjF8QZGNjd6D7CUo4Pw6u zkmLzONmwlPsO/7SXeK9JC6JTpIp2GyhTMKi1SspO4f3vtXfy6IiVSYAA/euO2W0 AoNf7OYj48IqrlY86eg+h7UXO66jia6kjRKjS7Gfwl6vFqFd9ppItCC0yprj9tNi /lIDcBIx4SGtG4bYsbmU3Z3lsNgIr14uyu6AxHM7C7A4ghynhGtY4aHVwBiH2I0A Cu1j+G1/fvkdCFaYo/3vZRtsjhhGPkpB5FMe1fWJtT0crd+7WTsAg== 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 4aejka7n00-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 20 Nov 2025 17:16:21 +0000 (GMT) Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 5AKF8nV2007037; Thu, 20 Nov 2025 17:16:20 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 4af62jqdqy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 20 Nov 2025 17:16:20 +0000 Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 5AKHGGcP49283508 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 20 Nov 2025 17:16:16 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B904A2004D; Thu, 20 Nov 2025 17:16:16 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 167A920040; Thu, 20 Nov 2025 17:16:15 +0000 (GMT) Received: from p-imbrenda.ibmuc.com (unknown [9.111.12.33]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 20 Nov 2025 17:16:14 +0000 (GMT) From: Claudio Imbrenda To: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org, borntraeger@de.ibm.com, frankja@linux.ibm.com, nsg@linux.ibm.com, nrb@linux.ibm.com, seiden@linux.ibm.com, gra@linux.ibm.com, schlameuss@linux.ibm.com, hca@linux.ibm.com, svens@linux.ibm.com, agordeev@linux.ibm.com, gor@linux.ibm.com, david@redhat.com, gerald.schaefer@linux.ibm.com Subject: [PATCH v4 16/23] KVM: s390: Add some helper functions needed for vSIE Date: Thu, 20 Nov 2025 18:15:37 +0100 Message-ID: <20251120171544.96841-17-imbrenda@linux.ibm.com> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251120171544.96841-1-imbrenda@linux.ibm.com> References: <20251120171544.96841-1-imbrenda@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: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 0VWEUFjZ24rPZRcSDwqMai4qRzozo_ZT X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTE1MDAzMiBTYWx0ZWRfX+PT5sjyR4EDY o1JqQUsd0DSe+celUIkcHv9Cw9QUSeeu3GHTtwzyRGnD7aPt/SYzD6gYzZK4YDRJ4Mme0hQGAl3 7JdumB73cRO3kCINzvNzt+QiUKrNIQz8LL26mngLPFBMsO1HWNauRq+cR/+GLicB7TqjZ6U0jj7 gotV/T3w81wpDO3RdZIfxN4f0znDm1qNPBiOuipeNX3OuW9PAzpHUFseDFG5Z1dfk79cF+iLXZj b1dPZGK+oZ9tNzLORPqwJ/+n0QXq+UA70swpW/uSn1GwemFdEKAE83hrwBk0ejo7JO1o45YjLB/ qdN4AEqlOxxWb7eQmdhkbLQB73q8A6d86jd8BNDPIkOlG0HczDM9Y5ej5C8OidgNifEXvhXgxYN IfGMn44FhK2WDFI38kgXSc1nlkuUhA== X-Proofpoint-ORIG-GUID: 0VWEUFjZ24rPZRcSDwqMai4qRzozo_ZT X-Authority-Analysis: v=2.4 cv=XtL3+FF9 c=1 sm=1 tr=0 ts=691f4ce5 cx=c_pps a=AfN7/Ok6k8XGzOShvHwTGQ==:117 a=AfN7/Ok6k8XGzOShvHwTGQ==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=VnNF1IyMAAAA:8 a=aP1jQA4SsBbapb4bBcQA:9 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.9,FMLib:17.12.100.49 definitions=2025-11-20_06,2025-11-20_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 spamscore=0 bulkscore=0 priorityscore=1501 impostorscore=0 adultscore=0 lowpriorityscore=0 phishscore=0 suspectscore=0 malwarescore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2510240000 definitions=main-2511150032 Content-Type: text/plain; charset="utf-8" Implement gmap_protect_asce_top_level(), which was a stub. This function was a stub due to cross dependencies with other patches. Signed-off-by: Claudio Imbrenda --- arch/s390/kvm/gmap.c | 73 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 71 insertions(+), 2 deletions(-) diff --git a/arch/s390/kvm/gmap.c b/arch/s390/kvm/gmap.c index 29ce8df697dd..cbb777e940d1 100644 --- a/arch/s390/kvm/gmap.c +++ b/arch/s390/kvm/gmap.c @@ -22,6 +22,7 @@ #include "dat.h" #include "gmap.h" #include "kvm-s390.h" +#include "faultin.h" =20 static inline bool kvm_s390_is_in_sie(struct kvm_vcpu *vcpu) { @@ -988,10 +989,78 @@ static struct gmap *gmap_find_shadow(struct gmap *par= ent, union asce asce, int e return NULL; } =20 +#define CRST_TABLE_PAGES (_CRST_TABLE_SIZE / PAGE_SIZE) +struct gmap_protect_asce_top_level { + unsigned long seq; + struct guest_fault f[CRST_TABLE_PAGES]; +}; + +static inline int __gmap_protect_asce_top_level(struct kvm_s390_mmu_cache = *mc, struct gmap *sg, + struct gmap_protect_asce_top_level *context) +{ + int rc, i; + + guard(write_lock)(&sg->kvm->mmu_lock); + + if (kvm_s390_array_needs_retry_safe(sg->kvm, context->seq, context->f)) + return -EAGAIN; + + scoped_guard(spinlock, &sg->parent->children_lock) { + for (i =3D 0; i < CRST_TABLE_PAGES; i++) { + rc =3D gmap_protect_rmap(mc, sg, context->f[i].gfn, 0, context->f[i].pf= n, + TABLE_TYPE_REGION1 + 1, context->f[i].writable); + if (rc) + return rc; + } + sg->initialized =3D true; + gmap_add_child(sg->parent, sg); + } + + kvm_s390_release_faultin_array(sg->kvm, context->f, false); + return 0; +} + +static inline int _gmap_protect_asce_top_level(struct kvm_s390_mmu_cache *= mc, struct gmap *sg, + struct gmap_protect_asce_top_level *context) +{ + int rc; + + if (kvm_s390_array_needs_retry_unsafe(sg->kvm, context->seq, context->f)) + return -EAGAIN; + do { + rc =3D kvm_s390_mmu_cache_topup(mc); + if (rc) + return rc; + rc =3D radix_tree_preload(GFP_KERNEL); + if (rc) + return rc; + rc =3D __gmap_protect_asce_top_level(mc, sg, context); + radix_tree_preload_end(); + } while (rc =3D=3D -ENOMEM); + + return rc; +} + static int gmap_protect_asce_top_level(struct kvm_s390_mmu_cache *mc, stru= ct gmap *sg) { - KVM_BUG_ON(1, sg->kvm); - return -EINVAL; + struct gmap_protect_asce_top_level context =3D {}; + union asce asce =3D sg->guest_asce; + int rc; + + KVM_BUG_ON(!sg->is_shadow, sg->kvm); + + context.seq =3D sg->kvm->mmu_invalidate_seq; + /* Pairs with the smp_wmb() in kvm_mmu_invalidate_end(). */ + smp_rmb(); + + rc =3D kvm_s390_get_guest_pages(sg->kvm, context.f, asce.rsto, asce.dt + = 1, false); + if (rc > 0) + rc =3D -EFAULT; + if (!rc) + rc =3D _gmap_protect_asce_top_level(mc, sg, &context); + if (rc) + kvm_s390_release_faultin_array(sg->kvm, context.f, true); + return rc; } =20 /** --=20 2.51.1