From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4897AF43832 for ; Wed, 15 Apr 2026 15:01:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7CDCF6B0096; Wed, 15 Apr 2026 11:01:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7A5266B0099; Wed, 15 Apr 2026 11:01:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 693276B009B; Wed, 15 Apr 2026 11:01:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 574AF6B0096 for ; Wed, 15 Apr 2026 11:01:38 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id EF74616049D for ; Wed, 15 Apr 2026 15:01:37 +0000 (UTC) X-FDA: 84661104234.03.A6374B2 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by imf06.hostedemail.com (Postfix) with ESMTP id 6DC5218002B for ; Wed, 15 Apr 2026 15:01:35 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=L18ep5zs; spf=pass (imf06.hostedemail.com: domain of agordeev@linux.ibm.com designates 148.163.158.5 as permitted sender) smtp.mailfrom=agordeev@linux.ibm.com; dmarc=pass (policy=none) header.from=ibm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1776265295; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Kh5NIg+tCmgqxLw712whetL2DfIqpUdC//9g+2sX4n4=; b=SEM8QRT8ZiPO/6RQAbBr2N/39T24sYvKUUMa9Orm5/ZcyPfY1kS99RHcZFclFTLRunwobJ qOfjXfL6BrmnwAzcA6DBJR/b4Bh1bvYHU3OC2qQ736inD76Cf22dWCu71oUbUze9eOeCHv 5tdakUY8sMTcWWlSeP5dXcLHpGOIlig= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=L18ep5zs; spf=pass (imf06.hostedemail.com: domain of agordeev@linux.ibm.com designates 148.163.158.5 as permitted sender) smtp.mailfrom=agordeev@linux.ibm.com; dmarc=pass (policy=none) header.from=ibm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1776265295; a=rsa-sha256; cv=none; b=OSQu4jgqbsKQ9DdjJMugvBYoLQl1lFMS7IMs4FRFpL6SiQndIqeZL7+INWKsJTY6Q3n/Qb lk+yHE7i24q+U72WWDYMMPhXDtsspktFcW/N22XPPaNmUYRcuKkudNek8cIzCIXrkXQ18Y U6DIbvAQxaD8MTk2lDWPO6mi19LyJ1g= 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 63F5bDiH2030542; Wed, 15 Apr 2026 15:01:29 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=Kh5NIg +tCmgqxLw712whetL2DfIqpUdC//9g+2sX4n4=; b=L18ep5zsRU1smJtlyFqlcv xNtx5kAeRPqHhgeZJa4T5G8c7OTcJZiImxJsD66YkrM6ll0DtytPQSaTYiNEG0nH lDbpHcadoG8LpUjTb7uWE2y4ZAucc022YBkqFuJmKm4KZmcSWprxc09ouPrDnYDj gJmPthmYeU/yFlBlPTzxq6lKdKbJX+1I78gqYCNnsnIvbyLwzu/WNrcPzTS7ldKd sdB2mxt4mGgjORK6d5xbBdhea2sYjxyn5V3iSN2pTCnsJXNQydyEmWGyfEp6Mtxc jHpnKsjK2Jd15cry7NdUMGRPKqZlIGFnQK09vkQLgXaQNFA4SGEKt75Hyr1xAMpw == Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4dh89m8688-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 15 Apr 2026 15:01:29 +0000 (GMT) Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 63FDNpoP003256; Wed, 15 Apr 2026 15:01:28 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 4djbh90aud-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 15 Apr 2026 15:01:28 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 63FF1PgC45482368 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 15 Apr 2026 15:01:25 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1DA072004D; Wed, 15 Apr 2026 15:01:25 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id ECF4020040; Wed, 15 Apr 2026 15:01:24 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.87.85.9]) by smtpav06.fra02v.mail.ibm.com (Postfix) with SMTP; Wed, 15 Apr 2026 15:01:24 +0000 (GMT) Received: by tuxmaker.boeblingen.de.ibm.com (Postfix, from userid 55669) id D6DF0E080A; Wed, 15 Apr 2026 17:01:24 +0200 (CEST) From: Alexander Gordeev To: Kevin Brodsky , David Hildenbrand , Andrew Morton , Gerald Schaefer , Heiko Carstens , Christian Borntraeger , Vasily Gorbik , Claudio Imbrenda Cc: linux-s390@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 4/6] s390/mm: Make PTC and UV call order consistent Date: Wed, 15 Apr 2026 17:01:22 +0200 Message-ID: <7b0e73e3c6f4000f9bf7cb161d8ca9a9f2312d70.1776264097.git.agordeev@linux.ibm.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Authority-Analysis: v=2.4 cv=I/dVgtgg c=1 sm=1 tr=0 ts=69dfa849 cx=c_pps a=aDMHemPKRhS1OARIsFnwRA==:117 a=aDMHemPKRhS1OARIsFnwRA==:17 a=IkcTkHD0fZMA:10 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=V8glGbnc2Ofi9Qvn3v5h:22 a=VnNF1IyMAAAA:8 a=sUKjrkhoaZ6cYlpXR9kA:9 a=QEXdDO2ut3YA:10 X-Proofpoint-GUID: GfE48YsPTVl7zllCgjvdRH7LvPfm3xJ5 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDE1MDEzNyBTYWx0ZWRfX/07hu9qNKP6r QKBNomPZz7UzONVTmNLDO6fQfAVZXFHJanLyTBj2i0kFfvFq2UNXrVvdqnKAcoo2/GcL4SdpAQQ AXozAvUogB+Pe9q0CGDVMcWCj/EXM29fpbEjGlTQOY4FdDAPYc0UAb4xn+aQe2brSsABBLwW201 kLSfPhT1yb/yCQ63+n6v7NG2fn3JPnQvTro5PxSwVHGbCJWkDCs1XUuS5/Rn/rKq/1/bOGDSH88 OguXmlwtb+HLzNMSlLtAdlwjaURiicwb9R04uMNpVEEHIfbpHVHaJbVlvI2P08pu1PMxR6cv4zT 5KAoVv/9L/rogs6OsHtXmXTjc9I8JBeS5qF5o96HiaCkIQePHjj9F1CX0n6EZMPx6OWzl/4IJV+ zKeCEsUGQocNjSgLj/66IXDNyCGlFRVTHV0Z5YhsQhzOeYhglOJogNpLrHc4xPKUBS7m46oJTcC 1ZFKrO+lToDUc9n4M1A== X-Proofpoint-ORIG-GUID: GfE48YsPTVl7zllCgjvdRH7LvPfm3xJ5 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-15_01,2026-04-13_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 bulkscore=0 clxscore=1015 adultscore=0 lowpriorityscore=0 suspectscore=0 impostorscore=0 phishscore=0 spamscore=0 priorityscore=1501 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2604070000 definitions=main-2604150137 X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 6DC5218002B X-Stat-Signature: pdoz3pndae5zuz6w4q6n6mgq85ciygrc X-Rspam-User: X-HE-Tag: 1776265295-924641 X-HE-Meta: U2FsdGVkX18IAX/levSCNECHgTmQ6iu4lhMrICqtCI9HoIQYLNFeIkj69u49sVn0Znr/tYc7RBU9fCoFxYlwMkNNpO82EvL7HHMF4DmQm1g0dynVUsGHKE302gSOdolDogYEhDf5Yp/1zV2KpWgzjGeAwi6nWxKBsRhB0oFFU8l2MXpK0RJQwotOU5wWzeg8N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MkOjs3qRPP/0GtrKIKe8ZM/OWgJZ4qSkc= Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: In various code paths, page_table_check_pte_clear() is called before converting a secure page, while in others it is called after. Make this consistent and always perform the conversion after the PTC hook has been called. Also make all conversion=E2=80=91 eligibility condition checks look the same, and rework the one in ptep_get_and_clear_full() slightly. Acked-by: Claudio Imbrenda Signed-off-by: Alexander Gordeev --- arch/s390/include/asm/pgtable.h | 39 +++++++++++++++------------------ 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/arch/s390/include/asm/pgtable.h b/arch/s390/include/asm/pgta= ble.h index 42688ea4337f..010a33fec867 100644 --- a/arch/s390/include/asm/pgtable.h +++ b/arch/s390/include/asm/pgtable.h @@ -1219,10 +1219,10 @@ static inline pte_t ptep_get_and_clear(struct mm_= struct *mm, pte_t res; =20 res =3D ptep_xchg_lazy(mm, addr, ptep, __pte(_PAGE_INVALID)); + page_table_check_pte_clear(mm, addr, res); /* At this point the reference through the mapping is still present */ if (mm_is_protected(mm) && pte_present(res)) WARN_ON_ONCE(uv_convert_from_secure_pte(res)); - page_table_check_pte_clear(mm, addr, res); return res; } =20 @@ -1238,10 +1238,10 @@ static inline pte_t ptep_clear_flush(struct vm_ar= ea_struct *vma, pte_t res; =20 res =3D ptep_xchg_direct(vma->vm_mm, addr, ptep, __pte(_PAGE_INVALID)); + page_table_check_pte_clear(vma->vm_mm, addr, res); /* At this point the reference through the mapping is still present */ if (mm_is_protected(vma->vm_mm) && pte_present(res)) WARN_ON_ONCE(uv_convert_from_secure_pte(res)); - page_table_check_pte_clear(vma->vm_mm, addr, res); return res; } =20 @@ -1265,26 +1265,23 @@ static inline pte_t ptep_get_and_clear_full(struc= t mm_struct *mm, } else { res =3D ptep_xchg_lazy(mm, addr, ptep, __pte(_PAGE_INVALID)); } - page_table_check_pte_clear(mm, addr, res); - - /* Nothing to do */ - if (!mm_is_protected(mm) || !pte_present(res)) - return res; - /* - * At this point the reference through the mapping is still present. - * The notifier should have destroyed all protected vCPUs at this - * point, so the destroy should be successful. - */ - if (full && !uv_destroy_pte(res)) - return res; - /* - * If something went wrong and the page could not be destroyed, or - * if this is not a mm teardown, the slower export is used as - * fallback instead. If even that fails, print a warning and leak - * the page, to avoid crashing the whole system. - */ - WARN_ON_ONCE(uv_convert_from_secure_pte(res)); + /* At this point the reference through the mapping is still present */ + if (mm_is_protected(mm) && pte_present(res)) { + /* + * The notifier should have destroyed all protected vCPUs at + * this point, so the destroy should be successful. + */ + if (full && !uv_destroy_pte(res)) + return res; + /* + * If something went wrong and the page could not be destroyed, + * or if this is not a mm teardown, the slower export is used + * as fallback instead. If even that fails, print a warning and + * leak the page, to avoid crashing the whole system. + */ + WARN_ON_ONCE(uv_convert_from_secure_pte(res)); + } return res; } =20 --=20 2.51.0