Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp3038577lqo; Tue, 21 May 2024 05:17:07 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXriUmHZfuHNYTWytyoxT6X1MmfS5WcjxaFCBg0FYnARzucUZHoh+7/op8+rqKW7dSlpdlG3QOiEehfFTC+odqzvL+VWHi/xSwoFd5L6A== X-Google-Smtp-Source: AGHT+IFl6B/24VC+VECbM8yTMDDrP7l/WExiGk9GkhpdDhHAMHXlyXCyDB93At0sSpR/WM5iBKFg X-Received: by 2002:a17:902:ea01:b0:1f3:2bf:4cd with SMTP id d9443c01a7336-1f302bf08e2mr54709845ad.39.1716293827112; Tue, 21 May 2024 05:17:07 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716293827; cv=pass; d=google.com; s=arc-20160816; b=y6pwOXM9lnkMlbgvWWoF1axCQOYa7B/BbBmJ8MuLnXNok6stBHE8N+Dz/kxcqt9g/W wf7Hwsn6q9dD+xWz6DiynlMjuAqY3+og9ZFEdvg48emxXs0UNTro+emRkM8KpXL5E3Lk 6P2AR4NZNyqowCEop4iPrqFV76+oiuvp76zdjcygLI+8qbgFVNbgtGb39JgLvDM+m2hZ /Dij6wSfEk8Nj1JNyk48JyIdgTv+NyhwDFwXX5NkTmawcZt8gU667P3AoUUVwgnBi5qS ySe+RHOonuzX+gMKvEwlsXZxaIEX76V5AOqDr2NsuwlyLb+DCSZ6jqZs0Kk0dITJIzLI LEZw== 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=0xh5DBvKXFg7KZScVHo4DoheXvv3/yC0K5O0DOCG9Aw=; fh=oGt6q2ZwpnJzXptinqitReeMFDIe4eIOmPhwsLhLj/U=; b=xQuMmzcy7eGBWlNYfRiopEqAGm2fWcRFDy5uPKU8sjf3V5W+cr1d9kVz5zC/it17++ 6OA8R1+fQCgvpBKIqPS7zqbQpijEZ8mN5RKBy31dRsJ56BhSM+IoOE+aUXA+Ib8OURVF ClVbPeXtCHvRUFUgMu20SOuz6HexdXXQ4sMBd3HH6/mlWKhKmpvd5xtM8agR6D/wSjH7 KdiqNEUrRxvXgc6HyGy6gtxkjVSE94xqgVFJ8SvYQToB07RmKLqcTdocF4FKaH7EmD5V emWY7qKXQ8ixFHNRQ9/keii169LcbztWgGnej7rt7g6cFjdyMtnIQkpmlLrojTf3d5Op HRIA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b="CZEqcH/E"; 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-184932-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-184932-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. [139.178.88.99]) by mx.google.com with ESMTPS id d9443c01a7336-1ef0bad5fafsi41998105ad.157.2024.05.21.05.17.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 May 2024 05:17:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-184932-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b="CZEqcH/E"; 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-184932-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-184932-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 59160283BAE for ; Tue, 21 May 2024 12:16:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8CD2677105; Tue, 21 May 2024 12:15:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="CZEqcH/E" 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 1FF7476410; Tue, 21 May 2024 12:15:35 +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=1716293737; cv=none; b=m0uPGH6QjaTcFYUWAgMgZoNITM7A/2SY8s39HEAwShqQVhgB+QOCQc7InZsxZ6I9XD1IkmxvcGOCOXkpnmsMroq8JrllAS+qGGm+napvRGiFXPDNy2h1MwZnQ9osAqKK33MC2zE6+speKO3cZXwspZ40eGTTNhIcma1p9blitqs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716293737; c=relaxed/simple; bh=dAABayEDOSfEypk9NTThYmbaf19C4af1A3Lunw+eFII=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HxIqEX0pcZ5ebfsFWgpsM6HH+BDSaClzrgso/DcEqWiEu2PWz3JrDjojkwgldasNJpZ0GEu2ZMyiRlmZgaW/RYo6fwiKsX+wo7l5LQLhfxjq1/NyPOr3hpi3BwtyPD3auKRpBwo73majqb+XpmkACixI+VAhh63q3JvCqQfir9s= 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=CZEqcH/E; 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 (m0353728.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 44LCCg1B012068; Tue, 21 May 2024 12:15: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=0xh5DBvKXFg7KZScVHo4DoheXvv3/yC0K5O0DOCG9Aw=; b=CZEqcH/EUZ9mnj0rAgEwUYGIgej49SZkWgf+YKKe0YHZui0yEyhy8Rvu0AP4WJ/Lq3zQ SUYx+L8WbR9tOKxIaFQncEEBVXNg5C/8E52/8ZfWuzczqEhqhJW0b/vEoFxA4VMGEhBD b5SibtQl/GakTDEXzUXd3eZniJF7nmfps9wpxJT1UOkHr4Pu83SAvucbo8qTduJIfijL oZVyMkb3KDF8bBL8/DYranK4DcF/wF2Y4PZpZ/D+bx1klfDExFNgqMiQ8hW0shlNLYWS LxRW20x2qQV9VkvFAkOFcrJSaKNjm2jAZl5duqsbIV0/f7WFFQCbc6n9H1CylXzVSAlS MQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3y8udsr0cy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 21 May 2024 12:15:34 +0000 Received: from m0353728.ppops.net (m0353728.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 44LCFYac017446; Tue, 21 May 2024 12:15:34 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 3y8udsr0ct-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 21 May 2024 12:15:34 +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 44LAHaTG000887; Tue, 21 May 2024 12:15:33 GMT Received: from smtprelay01.wdc07v.mail.ibm.com ([172.16.1.68]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3y77205pj3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 21 May 2024 12:15:33 +0000 Received: from smtpav06.dal12v.mail.ibm.com (smtpav06.dal12v.mail.ibm.com [10.241.53.105]) by smtprelay01.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 44LCFToo50201236 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 21 May 2024 12:15:32 GMT Received: from smtpav06.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D53695805E; Tue, 21 May 2024 12:15:29 +0000 (GMT) Received: from smtpav06.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 11D9858043; Tue, 21 May 2024 12:15:28 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by smtpav06.dal12v.mail.ibm.com (Postfix) with ESMTP; Tue, 21 May 2024 12:15:27 +0000 (GMT) From: Niklas Schnelle Date: Tue, 21 May 2024 14:14:57 +0200 Subject: [PATCH 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: <20240521-vfio_pci_mmap-v1-1-2f6315e0054e@linux.ibm.com> References: <20240521-vfio_pci_mmap-v1-0-2f6315e0054e@linux.ibm.com> In-Reply-To: <20240521-vfio_pci_mmap-v1-0-2f6315e0054e@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 X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=1882; i=schnelle@linux.ibm.com; h=from:subject:message-id; bh=dAABayEDOSfEypk9NTThYmbaf19C4af1A3Lunw+eFII=; b=owGbwMvMwCH2Wz534YHOJ2GMp9WSGNJ8JkS7cflp7L3LErOJ8ULm7tiGrYtO7JrwtulZYPWpJ zs+10Zu6ChlYRDjYJAVU2RZ1OXst65giumeoP4OmDmsTCBDGLg4BWAi5XKMDDcWe/xI3aTxtm3y tSyZd3seCb3+u05pfU/jzS0vp6wprmZlZFgz+VX+AamY9PBE163XPPa2LZ16xOmJQJt+Z3Hrpxe FvGwA X-Developer-Key: i=schnelle@linux.ibm.com; a=openpgp; fpr=9DB000B2D2752030A5F72DDCAFE43F15E8C26090 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: mKSek11CftSv1bSJDKmIIgkbryhBnIFl X-Proofpoint-GUID: b6UkesWe_d7WXLuxNf71rkWASCJrfMBb 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-21_08,2024-05-21_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 suspectscore=0 mlxlogscore=931 mlxscore=0 lowpriorityscore=0 bulkscore=0 priorityscore=1501 adultscore=0 malwarescore=0 clxscore=1015 spamscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2405010000 definitions=main-2405210092 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(). 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