Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp568302lqb; Wed, 29 May 2024 04:37:49 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU6DJTwYYQ+GXd6wQZ+LYe6cXM5ZEk7Sjk6YRXtLRHB2Is2fZwKlxgxI3X/DQYRiWqGh+ZKY0SbchdhDQ/mhNAFYLTyczwSahyGx3YnFQ== X-Google-Smtp-Source: AGHT+IENHlIXmR/RXcupg22hhqIYOMxtMLszzamfy48VxfzLRIKsenZr1fzWCn5l2RkKHVAW6dm/ X-Received: by 2002:a05:6a21:3383:b0:1af:d95d:98e with SMTP id adf61e73a8af0-1b212d45624mr18305359637.29.1716982669187; Wed, 29 May 2024 04:37:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716982669; cv=pass; d=google.com; s=arc-20160816; b=PI3VQBFpj7+NxQAtvQx6//y2GYBz25SVND4NkTDh3cf3nZWg08A3vIton5+VTi46Ce 9zDO4jL2V+YxJV3wXukWG1X25JrsL7K5JRyC2MQVHQxCldNn16h7tTsoV4YUSE94t7Uo PO9lSnoWxv6BfW6XaPsTeqVU1K5diLsntNspdtIIre9Qc4JzQPgr+vn/xecb9DpovIvL Geje0BauYzLYty/StLpoP9wZIML5wSOnnH0SgohWsNbxPtAS7I0HrYbOiF1CrQ3eMdgg dvm0unrwZsYR5HBSTHf9byO7F/sSHSiVx9H1LzFYPdOCQpmylISwpTfItO0CFF/CSP2b 89Ig== 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=LTrthfU6+VvQnNM7AhQqXcpa/YUXxL1CYEpRBlk6l6E=; fh=BjFYr6X8L2WqYooHA5fyz58wrsXqR6Et7L3dAeCUqCU=; b=PGOMERwVWbtU9NoKeNvUCek0Pl9UtnjCiuwgp/3JH+3TaNsKi8m24meQcGUnkfqTSO MuAvOCRCvGSyM/2fcYKfMIADJAq7Lt7jmT6+MJ0AfMFnug4eXq3G57p0lPjR1Diyba2b 1ucZPqsIEe6FeyKTEf+yCWtyCNa1zWR7uQTVrx9FVE+TP9WYuV9oniXGBCzISPB+RT3Z 1w4seaWdjuz2U0SeuPg7ocL4oO2JqZUvT55ZOw0MuRqjAYLdABK019rvANDpSL5pXQFH oHmobIUGXuZniDSO2KMnLg2itCoSQ3y++u/JJxtDsXVGjVMXK8GO0s1nmJPOA3JDu0je wirA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=pguluGcq; 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-194031-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194031-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 98e67ed59e1d1-2bde918008csi10531865a91.93.2024.05.29.04.37.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 04:37:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-194031-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=pguluGcq; 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-194031-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194031-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id AF984281FE6 for ; Wed, 29 May 2024 11:37:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C99BB181B80; Wed, 29 May 2024 11:37:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="pguluGcq" 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 0AE63180A82; Wed, 29 May 2024 11:37:02 +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=1716982625; cv=none; b=rYvTVMRecU+7DSn4cVfWMeOELT+ZcUPIgHP0Uc5vQv5KXsNafmMTUEGyTsD61b1ByZ7Y9RPIipHuheCRQnPsGwSki6507uwTcB/uJVAmbRblxd/jjkRKZBogmawkBoycMqeStpGF/FdavHXcwYjNApUm4+foWjKM45wgnlZcacw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716982625; c=relaxed/simple; bh=kmttkYcl7RaIqBVfs1vIdHpH/R3f9A14cvLyhdB1rck=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dOHTsd+n8hkakPEIeR64wVnvaSaR+psa/gDUFcQugXlIVv9RRKsBm0uKfIYSCLgs8gy7AWtrxobMyxHKPQrR/gQJDDFvfSajK9d5JzkM1Pu5heC7ZPTarz9D082Qmb52meKZVnSAcHIFiNiSzXDcIdJmUiM0PPFFZqct+N7O6IY= 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=pguluGcq; 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 Received: from pps.filterd (m0353729.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 44TBDpON005211; Wed, 29 May 2024 11:37:02 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=LTrthfU6+VvQnNM7AhQqXcpa/YUXxL1CYEpRBlk6l6E=; b=pguluGcqrLKZ8SkhT+RtyY1YVxI7A+iPs21xPhmPSZ+tjZk5rJe6AW0NSUnbXza6IvnD +KoYC8FDZC8mSmaraeMXMPxjo8b35ykv/6dYlKVwBXFrvqbd+70LbDOGAZEbPk+GA43k n1qR6pWqLnh16lrDgZ0qd06bgBKPUzKPKLfHtFSQoeDe/6kfYDzds+9fBonbgexGpgpC A5DdlCoIkwuD2Xmcp5gH4l9MsrD7IZ7JWMu/1rJEBvUEMk6CzMe35S9djX5hBuPnTcar KBLBPxOh1C7nI15p2OK3mcjyuQAogjD0nGTMPFzdOXKYuQTz0oam7954nie9wx/zIkC7 6g== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3ye39cr1n8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 29 May 2024 11:37:01 +0000 Received: from m0353729.ppops.net (m0353729.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 44TBaHug007440; Wed, 29 May 2024 11:37:01 GMT 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 3ye39cr1n5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 29 May 2024 11:37:01 +0000 Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 44T82ufB028984; Wed, 29 May 2024 11:37:00 GMT Received: from smtprelay07.dal12v.mail.ibm.com ([172.16.1.9]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3ydpaykgwc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 29 May 2024 11:37:00 +0000 Received: from smtpav02.wdc07v.mail.ibm.com (smtpav02.wdc07v.mail.ibm.com [10.39.53.229]) by smtprelay07.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 44TBauuD33751328 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 29 May 2024 11:36:59 GMT Received: from smtpav02.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DB88058074; Wed, 29 May 2024 11:36:54 +0000 (GMT) Received: from smtpav02.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8C0515805B; Wed, 29 May 2024 11:36:52 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by smtpav02.wdc07v.mail.ibm.com (Postfix) with ESMTP; Wed, 29 May 2024 11:36:52 +0000 (GMT) From: Niklas Schnelle Date: Wed, 29 May 2024 13:36:24 +0200 Subject: [PATCH v3 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: <20240529-vfio_pci_mmap-v3-1-cd217d019218@linux.ibm.com> References: <20240529-vfio_pci_mmap-v3-0-cd217d019218@linux.ibm.com> In-Reply-To: <20240529-vfio_pci_mmap-v3-0-cd217d019218@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=1957; i=schnelle@linux.ibm.com; h=from:subject:message-id; bh=kmttkYcl7RaIqBVfs1vIdHpH/R3f9A14cvLyhdB1rck=; b=owGbwMvMwCH2Wz534YHOJ2GMp9WSGNLChR1M1t4JTg+8vrHIxvrJ9ybJHXH3dHtdX527t/b7z GO+8c0/O0pZGMQ4GGTFFFkWdTn7rSuYYronqL8DZg4rE8gQBi5OAZiIYSfDX6krwWL/eBL9lm8p aa+a8bn/fXrzXr8dF+/sm8Dldk+rYh4jw2GmJD6ZPzsS/9kXaH3JZH+2/uG+sFxmG8lQoa4tXOY yjAA= X-Developer-Key: i=schnelle@linux.ibm.com; a=openpgp; fpr=9DB000B2D2752030A5F72DDCAFE43F15E8C26090 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 2JRiljfBl3hdHKTx1iHIh_9E1EXsoUiP X-Proofpoint-ORIG-GUID: EUrSTaRqNyfi2MMyxOBcsN5HH5SwKS8D 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-29_07,2024-05-28_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 suspectscore=0 mlxlogscore=999 phishscore=0 mlxscore=0 clxscore=1015 lowpriorityscore=0 spamscore=0 bulkscore=0 impostorscore=0 malwarescore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2405010000 definitions=main-2405290079 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 Reviewed-by: Matthew Rosato 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 5398729bfe1b..80c21b1a101c 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, mmio_addr, &ptep, &ptl); - if (ret) - goto out_unlock_mmap; + if (ret) { + fixup_user_fault(current->mm, mmio_addr, FAULT_FLAG_WRITE, NULL); + ret = follow_pte(vma, 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, mmio_addr, &ptep, &ptl); - if (ret) - goto out_unlock_mmap; + if (ret) { + fixup_user_fault(current->mm, mmio_addr, 0, NULL); + ret = follow_pte(vma, 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