Received: by 2002:ab2:7855:0:b0:1f9:5764:f03e with SMTP id m21csp917494lqp; Thu, 23 May 2024 04:11:58 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUFckjXYaIv7HcgPS0IK5WZQ8gw7mOM+XjNW6Qc1uQmf8cGxDwnKHh3ENZXBkEqTv/e3yORN+mHtPq70r4frbkfp0JKflaxD7VHU7K+6w== X-Google-Smtp-Source: AGHT+IHSRWjf6kkVZHhTN2qX+zh+/DSk/SOqkzS0aHDpERItmJk09URRss/xNAfaHOQXtMsvm7ZZ X-Received: by 2002:a17:906:dc9:b0:a62:4726:1f2 with SMTP id a640c23a62f3a-a62472604f5mr61138866b.37.1716462718306; Thu, 23 May 2024 04:11:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716462718; cv=pass; d=google.com; s=arc-20160816; b=hKeDKYw5Dl/mjKxMF+18iWytFnIpClYY891N16HO2+HjBUldl46lR/JSzxoAbIWLXI dxbRcOG3NgPQmPHI4arJCZvO84Unvjkunn5Ofl0PaW0rKrUZDDanEoslqNPKoHGbEDgX HHpRk1jAdulpzKdsRkK8O0lRhM6s4vA65UqRf84MfjnHDRi6YioSyGoJReLq3Y2mSA9k KspRrDAtT9dWRxr5lJ3FAWTh4RlEd4FvT6lEAQZuGvAlcA1XEgDasLCDQQ0vhlvcA7EU 1OtNBHBI4XAReKsqYizrFo3VJdfzgrAiI6zYsFpwlXeyPoleMDDXN4UIMhr8FVdJqtke o3Wg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=bUFP5CycpZZ5HV22vNMvqpWdG4N/x0IfliF7CPJsewA=; fh=BjFYr6X8L2WqYooHA5fyz58wrsXqR6Et7L3dAeCUqCU=; b=A9aCo9vEFnSzATl2XYw4JIl03ow6m7IL8uhiWB+A7jvrtqoB7PycLCX9T/NJrC8h4g Blv5WVj4ik1hLHRb8dYUGHICZVNc2/0OtiDX3xw6nIebIltK/B3UyQHZnJ5HqTBnypn1 38wMKGjnH3GW4FmJpf8w+B+Kje5aKJ81gO8BokDUQX6n0/mjFAes+08rL6/6qO5QxUbG qXdObm14oF+nk7bbNwxQPnjFCDDpr/dQcsCnhfkNkedYU08H/X728m1y1HG9SfagolfV 8czzbtdctYGJIu9ozKP9FT6DSHdswmngoe1ucrZZ9bTsaAl9sr0KbEA99IqvNSpHGCvP Ku3g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=FVqZfOF3; arc=pass (i=1 spf=pass spfdomain=linux.ibm.com dkim=pass dkdomain=ibm.com dmarc=pass fromdomain=linux.ibm.com); spf=pass (google.com: domain of linux-kernel+bounces-187378-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-187378-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a5d19f32088si618651066b.861.2024.05.23.04.11.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 04:11:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-187378-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=FVqZfOF3; arc=pass (i=1 spf=pass spfdomain=linux.ibm.com dkim=pass dkdomain=ibm.com dmarc=pass fromdomain=linux.ibm.com); spf=pass (google.com: domain of linux-kernel+bounces-187378-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-187378-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id DC95E1F2221E for ; Thu, 23 May 2024 11:11:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1E908148821; Thu, 23 May 2024 11:10:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="FVqZfOF3" 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 B6FCB147C63; Thu, 23 May 2024 11:10:36 +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=1716462639; cv=none; b=X479UOB83W+QMjcgRIFUNkHAtuSorWDzWh0gRv8qS5YrPIq7mUG0D2Mp11/tpTAz1lHUlTN9XxMBs6DEe/MC533XO9FKhyQPELNVZTDtkzJchCoLHE9WUN0v/xQ925ydj8Z86vO+4GGOLV8U+fANbZxd4YHKuYlq2V2QROs68IM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716462639; c=relaxed/simple; bh=V9p54K0J4aEM5NILVOof+HaaDipCamwYqPH+otYYUpU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=b1s7y+q3N/xx3m9ozs0cpntvkcvM5ELdwcdorl8eZPNdrGCpWMpA0Zbibpz06O1bejc04+cU6WdAJ2mr6QGOC2RT35CCfC/gk+IyEh5av9X0ZKGPqft1ux2etNjiIpXoo/rNCNxWYJgJEqTW5ABJJD8BH3ZXm2w3O+fKNxgDGjY= 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=FVqZfOF3; 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 Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 44NArGvC015420; Thu, 23 May 2024 11:10:35 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : date : subject : mime-version : content-type : content-transfer-encoding : message-id : references : in-reply-to : to : cc; s=pp1; bh=bUFP5CycpZZ5HV22vNMvqpWdG4N/x0IfliF7CPJsewA=; b=FVqZfOF3nJnThkGQJrcB64nGcL2Kh0vG5+RSe5WyERbmaYx1ymox+Ar1Sb7a3UX6OJq2 2dNfDMGlaGj5JwILk90BqXWo9ntKn9inkR/RlOCYQmqLUn1EtYqAc+43+fYOggM/HkuO KxxgyLDW72D2HL2DiND6KVBFEI7SSV2FFAVlpbt53JNOlaXUkVRoIsEMMSlWuVoTB/d8 bkbSqipuDiV91bFZzbWka+BPTmcC8EcxR9mt0jflCHVQ+9WTLzpYYWjuW9yiHO1aQnLj 3oJOYi6kP7JLkwcZ/yTKswlMqd638AimC7CH2TYuNfWtGUnSENNakGGucvjOLnZ8QrZv Qg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3ya4edr1fu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 23 May 2024 11:10:35 +0000 Received: from m0353725.ppops.net (m0353725.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 44NBAYau009744; Thu, 23 May 2024 11:10:34 GMT Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3ya4edr1fr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 23 May 2024 11:10:34 +0000 Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 44N7oTtG026478; Thu, 23 May 2024 11:10:34 GMT Received: from smtprelay07.wdc07v.mail.ibm.com ([172.16.1.74]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3y785msghu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 23 May 2024 11:10:34 +0000 Received: from smtpav04.wdc07v.mail.ibm.com (smtpav04.wdc07v.mail.ibm.com [10.39.53.231]) by smtprelay07.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 44NBAUvd27132424 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 23 May 2024 11:10:33 GMT Received: from smtpav04.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DADE458056; Thu, 23 May 2024 11:10:30 +0000 (GMT) Received: from smtpav04.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7E7EF58045; Thu, 23 May 2024 11:10:28 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by smtpav04.wdc07v.mail.ibm.com (Postfix) with ESMTP; Thu, 23 May 2024 11:10:28 +0000 (GMT) From: Niklas Schnelle Date: Thu, 23 May 2024 13:10:14 +0200 Subject: [PATCH v2 1/3] s390/pci: Fix s390_mmio_read/write syscall page fault handling Precedence: bulk X-Mailing-List: linux-kernel@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: <20240523-vfio_pci_mmap-v2-1-0dc6c139a4f1@linux.ibm.com> References: <20240523-vfio_pci_mmap-v2-0-0dc6c139a4f1@linux.ibm.com> In-Reply-To: <20240523-vfio_pci_mmap-v2-0-0dc6c139a4f1@linux.ibm.com> To: Gerald Schaefer , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Alex Williamson , Gerd Bayer , Matthew Rosato , Jason Gunthorpe Cc: linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Niklas Schnelle , Jason Gunthorpe X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=1929; i=schnelle@linux.ibm.com; h=from:subject:message-id; bh=V9p54K0J4aEM5NILVOof+HaaDipCamwYqPH+otYYUpU=; b=owGbwMvMwCH2Wz534YHOJ2GMp9WSGNL8VRSVTt048ayW409BpsqFyI9GvTo1efy571dUmEv7i W7LWjS7o5SFQYyDQVZMkWVRl7PfuoIppnuC+jtg5rAygQxh4OIUgIlYGTMyPLf0YzE4l74tW/aL dLxZeDlvVr3kYbkbBzRmLOf+KOewlJFh++F9xXwaxx9e0t9U4Hj7UnGH38fnEj8NDe/JdYSrn6t mBAA= X-Developer-Key: i=schnelle@linux.ibm.com; a=openpgp; fpr=9DB000B2D2752030A5F72DDCAFE43F15E8C26090 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: iGZWZvNzKYdq6YLi-4JCW5cmVp9v1HQP X-Proofpoint-ORIG-GUID: k7dGvF_7I8BFoeEYrO8o0_q_BADXgR94 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.650,FMLib:17.12.28.16 definitions=2024-05-23_07,2024-05-23_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 lowpriorityscore=0 adultscore=0 mlxscore=0 impostorscore=0 bulkscore=0 phishscore=0 priorityscore=1501 clxscore=1015 spamscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2405010000 definitions=main-2405230075 The s390 MMIO syscalls when using the classic PCI instructions do not cause a page fault when follow_pte() fails due to the page not being present. Besides being a general deficiency this breaks vfio-pci's mmap() handling once VFIO_PCI_MMAP gets enabled as this lazily maps on first access. Fix this by following a failed follow_pte() with fixup_user_page() and retrying the follow_pte(). Reviewed-by: Jason Gunthorpe Signed-off-by: Niklas Schnelle --- arch/s390/pci/pci_mmio.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/arch/s390/pci/pci_mmio.c b/arch/s390/pci/pci_mmio.c index a90499c087f0..217defbcb4f1 100644 --- a/arch/s390/pci/pci_mmio.c +++ b/arch/s390/pci/pci_mmio.c @@ -170,8 +170,12 @@ SYSCALL_DEFINE3(s390_pci_mmio_write, unsigned long, mmio_addr, goto out_unlock_mmap; ret = follow_pte(vma->vm_mm, mmio_addr, &ptep, &ptl); - if (ret) - goto out_unlock_mmap; + if (ret) { + fixup_user_fault(vma->vm_mm, mmio_addr, FAULT_FLAG_WRITE, NULL); + ret = follow_pte(vma->vm_mm, mmio_addr, &ptep, &ptl); + if (ret) + goto out_unlock_mmap; + } io_addr = (void __iomem *)((pte_pfn(*ptep) << PAGE_SHIFT) | (mmio_addr & ~PAGE_MASK)); @@ -305,12 +309,16 @@ SYSCALL_DEFINE3(s390_pci_mmio_read, unsigned long, mmio_addr, if (!(vma->vm_flags & (VM_IO | VM_PFNMAP))) goto out_unlock_mmap; ret = -EACCES; - if (!(vma->vm_flags & VM_WRITE)) + if (!(vma->vm_flags & VM_READ)) goto out_unlock_mmap; ret = follow_pte(vma->vm_mm, mmio_addr, &ptep, &ptl); - if (ret) - goto out_unlock_mmap; + if (ret) { + fixup_user_fault(vma->vm_mm, mmio_addr, 0, NULL); + ret = follow_pte(vma->vm_mm, mmio_addr, &ptep, &ptl); + if (ret) + goto out_unlock_mmap; + } io_addr = (void __iomem *)((pte_pfn(*ptep) << PAGE_SHIFT) | (mmio_addr & ~PAGE_MASK)); -- 2.40.1