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 3DC8A47279B; Tue, 16 Jun 2026 16:51:20 +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=1781628681; cv=none; b=FrAMDBjBAfWp+D5HEYzq36iLT5C3rxLb2QazLLmmaII2xmVUgq44TTOPvAnke4aXBKusdLUinZcMFBfitmR5j1at+SVvBPsPe5twi1IELlGi1blpZuRKtav9K7U9MPE9E9t9uYYr7NCV+pVzGiVv9RHMW3hOyNcebBY7QwDvcgc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781628681; c=relaxed/simple; bh=46SK69pXx2EKmBrYWCxndPE6Bf25/tb1d4s6yRYUzOw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qpnvscbreMPAIWgOeT7l24whSz8Cp9tkjugqZy+dfu/IqRR6vqj6qmMOmVNbwIJq12l4SS5CJEmawft59fbN96DJwwzEh7hEfAmPHRzI67XKs1o5SmxEmW42ydvMonDQ62y6038H8KJ7/Ush6wtF6s66eswpmdlOOFZLL1QmUz8= 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=pYiOnksW; 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="pYiOnksW" 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 65GFmMPE1969304; Tue, 16 Jun 2026 16:51:18 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=SLbEgJ/k/LE26R4n/ VkT3vyq9bPmf+OhkKyVdffnorQ=; b=pYiOnksW0PfWDpB1uBhdBMSDrINSlZky0 sj+4eshL+4Xj9UaxvSY2I/U9A9Xem2jGuGCnQ3ypflJR4y7lIU3j++Kj56SCDDms a/C0C+sooNW5KfHXieUUsxROHxMHfSYzThHhSgBlZhylvLph9QtK21mqmHu43WLw w86pAabeSbsC3TWSFjwwBm+4rtoeRZneoMmIWSf8QSvAgEtf9aGCWbhuAnT2IyCu +tFRadkGd+jg4t3g+elASiNBFbqjqEWNCNh8q47Rt08z9JSoNd4rHtWIf0HcSKcE Q4dg+WXXgVVI9yGm12dGfVEgyLHu5OBzM4scsMH8J5wwvgsx3jRIA== 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 4es23npwps-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 16 Jun 2026 16:51:18 +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 65GGndT1018570; Tue, 16 Jun 2026 16:51:17 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4eshww4gu0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 16 Jun 2026 16:51:17 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (smtpav01.fra02v.mail.ibm.com [10.20.54.100]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 65GGpDmA50856226 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Jun 2026 16:51:13 GMT Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 23BAB20040; Tue, 16 Jun 2026 16:51:13 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 13CDD20043; Tue, 16 Jun 2026 16:51:12 +0000 (GMT) Received: from p-imbrenda.ibmuc.com (unknown [9.111.66.4]) by smtpav01.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 16 Jun 2026 16:51:11 +0000 (GMT) From: Claudio Imbrenda To: linux-kernel@vger.kernel.org Cc: kvm@vger.kernel.org, linux-s390@vger.kernel.org, borntraeger@de.ibm.com, frankja@linux.ibm.com, david@kernel.org, seiden@linux.ibm.com, nrb@linux.ibm.com, schlameuss@linux.ibm.com, gra@linux.ibm.com, hca@linux.ibm.com, gerald.schaefer@linux.ibm.com, gor@linux.ibm.com, agordeev@linux.ibm.com, svens@linux.ibm.com Subject: [PATCH v3 1/4] s390/mm: Fix handling of _PAGE_UNUSED pte bit Date: Tue, 16 Jun 2026 18:51:07 +0200 Message-ID: <20260616165110.360921-2-imbrenda@linux.ibm.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260616165110.360921-1-imbrenda@linux.ibm.com> References: <20260616165110.360921-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: 8bit X-TM-AS-GCONF: 00 X-Authority-Analysis: v=2.4 cv=XtnK/1F9 c=1 sm=1 tr=0 ts=6a317f06 cx=c_pps a=5BHTudwdYE3Te8bg5FgnPg==:117 a=5BHTudwdYE3Te8bg5FgnPg==:17 a=FelO9ux0wxsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=iQ6ETzBq9ecOQQE5vZCe:22 a=VnNF1IyMAAAA:8 a=BXoTXrUDSLvzEcKRN5AA:9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNjE2MDE3MyBTYWx0ZWRfX+2H6UX5yHeVH LQwjX+bYNjduZdKG0Y77+YbJEPYyp7y8dwM1imAQMR31lPc4+gQuVw3YS4txVzOw4Niy18MB9Gh EpK6j93TdWfd8WkkPXsTxLgASGYDaAnkVxo0uGlr1PYYmGlIe1Iom/yP26DdmSLEW0e5tlOH0r1 PfZdxdNlG+qbsTRh/wa+UmildnkHHdooSgUu55BeexcCT4rGoGpmquuempaaqFlMjISF9hYRqb1 qBo46z8pxKjky5Hezbzve494W1YMw7EYOKOZE/2k0GRLwKQbAs+FvnZgDxwCGAsrHdz7dKkeC7Z hmaoeUr7kPP+M+jD23+YkK0Z30g20TGH50Q8a7rO8cyx49CkZQSq4mEAvCyb93rmF/xo3H79gao GaBzM2Ln1iHpUdtsm9A4IjYjStk4cpgiugspABFKg5OYgI7DgmSBN7jz4v4bwOYRoGr9lSyjIIO +KsT9PEItGNaihULd1w== X-Proofpoint-GUID: zPRpL4GFqVqcrV3l30QfNREShDFPmOc3 X-Proofpoint-ORIG-GUID: zPRpL4GFqVqcrV3l30QfNREShDFPmOc3 X-Proofpoint-Spam-Info: AW1haW4tMjYwNjE2MDE3MyBTYWx0ZWRfX1yMI72zzSrLg 5NC4dH5Ne1TY66/NgFnIgQ/Gc1uXQ4FspwJeg5J8rW0XHZBUp9QBw26DIRsTrWAKZmGF9d8rklv T0cteTp269wKXOS4q2nqMw57UiRTqCk= X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.125,FMLib:17.12.100.49 definitions=2026-06-16_05,2026-06-15_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 adultscore=0 phishscore=0 lowpriorityscore=0 priorityscore=1501 suspectscore=0 clxscore=1015 malwarescore=0 spamscore=0 impostorscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606040000 definitions=main-2606160173 The _PAGE_UNUSED softbit should not really be lying around. Its sole purpose is to signal to try_to_unmap_one() and try_to_migrate_one() that the page can be discarded instead of being moved / swapped. KVM has no way to know why a page is being unmapped, so it sets the bit on userspace ptes corresponding to unused guest pages every time they get unmapped. KVM has no reasonable way to clear the bit once the page is in use again. Without appropriate cleanup, the _PAGE_UNUSED bit will linger around and cause guest corruption when a used page is instead thrown out. While set_ptes() checks and clears the bit, other paths that set new ptes did not. This led to used pages being thrown out as if they were unused, causing guest corruption. This patch fixes the issue by clearing the _PAGE_UNUSED bit in set_pte(), so whenever a present pte is getting set. The check in set_ptes() is then redundant and can be removed. Also fix gmap_helper_try_set_pte_unused() to only set the bit if the pte is present; the _PAGE_UNUSED bit is only defined for present ptes and thus should not be set for non-present ptes. Signed-off-by: Claudio Imbrenda Fixes: c98175b7917f ("KVM: s390: Add gmap_helper_set_unused()") --- arch/s390/include/asm/pgtable.h | 4 ++-- arch/s390/mm/gmap_helpers.c | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/arch/s390/include/asm/pgtable.h b/arch/s390/include/asm/pgtable.h index ca376a9b8e41..d03663483f76 100644 --- a/arch/s390/include/asm/pgtable.h +++ b/arch/s390/include/asm/pgtable.h @@ -980,6 +980,8 @@ static inline void set_pmd(pmd_t *pmdp, pmd_t pmd) static inline void set_pte(pte_t *ptep, pte_t pte) { + if (pte_present(pte)) + pte = clear_pte_bit(pte, __pgprot(_PAGE_UNUSED)); WRITE_ONCE(*ptep, pte); } @@ -1332,8 +1334,6 @@ pgprot_t pgprot_writecombine(pgprot_t prot); static inline void set_ptes(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t entry, unsigned int nr) { - if (pte_present(entry)) - entry = clear_pte_bit(entry, __pgprot(_PAGE_UNUSED)); page_table_check_ptes_set(mm, addr, ptep, entry, nr); for (;;) { set_pte(ptep, entry); diff --git a/arch/s390/mm/gmap_helpers.c b/arch/s390/mm/gmap_helpers.c index 1cfe4724fbe2..60023b6fdcb1 100644 --- a/arch/s390/mm/gmap_helpers.c +++ b/arch/s390/mm/gmap_helpers.c @@ -181,7 +181,8 @@ void gmap_helper_try_set_pte_unused(struct mm_struct *mm, unsigned long vmaddr) if (IS_ERR_OR_NULL(ptep)) return; - __atomic64_or(_PAGE_UNUSED, (long *)ptep); + if (pte_present(*ptep)) + __atomic64_or(_PAGE_UNUSED, (long *)ptep); pte_unmap_unlock(ptep, ptl); } EXPORT_SYMBOL_GPL(gmap_helper_try_set_pte_unused); -- 2.54.0