From mboxrd@z Thu Jan 1 00:00:00 1970 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 E09A6664C6; Wed, 26 Feb 2025 08:28:29 +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=1740558511; cv=none; b=iYz7+rTeveVTNbci73PXXUT3GLJOOPJbm8IhhqIThmkE+vIuaB0++4Ao6M3uLoIF+mEugQsw0wtyvIT3JHHqS0ig7oZlCnnlyHLk11UkoY4mGMGaOv4kGo417qe9YiyxV8/7Sa10636dXsMzG9ttTSHOBjPf2RaDIwW+loPkS+o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740558511; c=relaxed/simple; bh=0ptEIfd32oQfSxB6r25bb4uP2sJl1wEhKVXmitSq000=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=DIIghUCbIUx928hORjoIRNWHuCdqd9s7wxgrlbVyLPod8CW/yvG+aAMooptvSX7b2EaPZUnrV/i7SrnqjFqAvsCmgnyx+kEfGH35IvfmsYpx1xQqenhUFgbkKGeV8MycI8a64fvC22JD1w6pj7EFBG54EAdQ1Ij+y6ItUOnaayo= 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=Ve09bE+5; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="Ve09bE+5" Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 51Q7WwWM006040; Wed, 26 Feb 2025 08:28:22 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=udgNGr tAOUprShQeSA3PWIHA1GsrHM5gY8vXZ2r23TQ=; b=Ve09bE+5q4W7X9BEoapg3d uZqyeB64IvpOtYBlD6OjL3IwjraVo5Up6QZlkD2TRH3X/yPvvlq5ELu9XSl6mFcl boeqK1KWikJ0bCBZUV6+hflrxQl2yP9QNwPo450ODh0K+ZqKDQ4WTOHeU5tiI0qw IMYbb2Zkj5uD6UTTZI0F1d6LIz71cPj2/vXLu4tipliN3oNVms6MWfk8CeaBhH9l oeecFZKUnFFJtG7Wf64kTTaN4wGtMDu8UIRAs4RDlFZAwUtZvcUivcOr5+LiVm+h p6dJQ47ihQK7sX8pUUbRWayJSID6XW40PTjbXvOdZW9uFM1Pjp5NnfYyV6CCNkBQ == Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 451xnp076y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 26 Feb 2025 08:28:21 +0000 (GMT) Received: from m0360072.ppops.net (m0360072.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 51Q8SLOq026704; Wed, 26 Feb 2025 08:28:21 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 451xnp076w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 26 Feb 2025 08:28:21 +0000 (GMT) Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 51Q573jO026964; Wed, 26 Feb 2025 08:28:20 GMT Received: from smtprelay07.dal12v.mail.ibm.com ([172.16.1.9]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 44ytdkhgrx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 26 Feb 2025 08:28:20 +0000 Received: from smtpav01.wdc07v.mail.ibm.com (smtpav01.wdc07v.mail.ibm.com [10.39.53.228]) by smtprelay07.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 51Q8SJ8W23921274 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 26 Feb 2025 08:28:19 GMT Received: from smtpav01.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 27A1458055; Wed, 26 Feb 2025 08:28:19 +0000 (GMT) Received: from smtpav01.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B7DD05804B; Wed, 26 Feb 2025 08:28:14 +0000 (GMT) Received: from [9.171.22.19] (unknown [9.171.22.19]) by smtpav01.wdc07v.mail.ibm.com (Postfix) with ESMTP; Wed, 26 Feb 2025 08:28:14 +0000 (GMT) Message-ID: <4cd8929d6ef45f62e9eb6bb905f28ada62600c23.camel@linux.ibm.com> Subject: Re: [PATCH v6 0/3] vfio/pci: s390: Fix issues preventing VFIO_PCI_MMAP=y for s390 and enable it From: Niklas Schnelle To: Bjorn Helgaas Cc: Christoph Hellwig , Alexandra Winter , Alex Williamson , Gerd Bayer , Matthew Rosato , Jason Gunthorpe , Thorsten Winkler , Bjorn Helgaas , Julian Ruess , Halil Pasic , Christian Borntraeger , Sven Schnelle , Gerald Schaefer , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-pci@vger.kernel.org Date: Wed, 26 Feb 2025 09:28:13 +0100 In-Reply-To: <20250225203524.GA516498@bhelgaas> References: <20250225203524.GA516498@bhelgaas> Autocrypt: addr=schnelle@linux.ibm.com; prefer-encrypt=mutual; keydata=mQINBGHm3M8BEAC+MIQkfoPIAKdjjk84OSQ8erd2OICj98+GdhMQpIjHXn/RJdCZLa58k /ay5x0xIHkWzx1JJOm4Lki7WEzRbYDexQEJP0xUia0U+4Yg7PJL4Dg/W4Ho28dRBROoJjgJSLSHwc 3/1pjpNlSaX/qg3ZM8+/EiSGc7uEPklLYu3gRGxcWV/944HdUyLcnjrZwCn2+gg9ncVJjsimS0ro/ 2wU2RPE4ju6NMBn5Go26sAj1owdYQQv9t0d71CmZS9Bh+2+cLjC7HvyTHKFxVGOznUL+j1a45VrVS XQ+nhTVjvgvXR84z10bOvLiwxJZ/00pwNi7uCdSYnZFLQ4S/JGMs4lhOiCGJhJ/9FR7JVw/1t1G9a UlqVp23AXwzbcoV2fxyE/CsVpHcyOWGDahGLcH7QeitN6cjltf9ymw2spBzpRnfFn80nVxgSYVG1d w75ksBAuQ/3e+oTQk4GAa2ShoNVsvR9GYn7rnsDN5pVILDhdPO3J2PGIXa5ipQnvwb3EHvPXyzakY tK50fBUPKk3XnkRwRYEbbPEB7YT+ccF/HioCryqDPWUivXF8qf6Jw5T1mhwukUV1i+QyJzJxGPh19 /N2/GK7/yS5wrt0Lwxzevc5g+jX8RyjzywOZGHTVu9KIQiG8Pqx33UxZvykjaqTMjo7kaAdGEkrHZ dVHqoPZwhCsgQARAQABtChOaWtsYXMgU2NobmVsbGUgPHNjaG5lbGxlQGxpbnV4LmlibS5jb20+iQ JXBBMBCABBAhsBBQsJCAcCBhUKCQgLAgQWAgMBAh4BAheAAhkBFiEEnbAAstJ1IDCl9y3cr+Q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WrKSq/mXIbl5nVW/wD+nJ7U7elW9BoJQVky03G0DhEF6fMJs08DGG3XoKw/CpGtMe 2V1z/FRotP5Fkf5VD3IQGtkxSnO/awtxjlhytigylgrZ4wDpSE= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.54.3 (3.54.3-1.fc41) Precedence: bulk X-Mailing-List: linux-s390@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: K55zgNeapAKBGSzLJ7WfwAUcMlY9elvN X-Proofpoint-GUID: XZLNQhPQgtBWY7hJQdhxbOM1jjuQ4vmc X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-02-26_01,2025-02-26_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 priorityscore=1501 suspectscore=0 mlxlogscore=999 spamscore=0 phishscore=0 mlxscore=0 adultscore=0 malwarescore=0 bulkscore=0 clxscore=1015 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2502100000 definitions=main-2502260063 On Tue, 2025-02-25 at 14:35 -0600, Bjorn Helgaas wrote: > On Tue, Feb 25, 2025 at 09:59:13AM +0100, Niklas Schnelle wrote: > > On Mon, 2025-02-24 at 14:53 -0600, Bjorn Helgaas wrote: > > > On Fri, Feb 14, 2025 at 02:10:51PM +0100, Niklas Schnelle wrote: > > > > With the introduction of memory I/O (MIO) instructions enbaled in c= ommit > > > > 71ba41c9b1d9 ("s390/pci: provide support for MIO instructions") s39= 0 > > > > gained support for direct user-space access to mapped PCI resources= . > > > > Even without those however user-space can access mapped PCI resourc= es > > > > via the s390 specific MMIO syscalls. There is thus nothing fundamen= tally > > > > preventing s390 from supporting VFIO_PCI_MMAP, allowing user-space > > > > drivers to access PCI resources without going through the pread() > > > > interface. To actually enable VFIO_PCI_MMAP a few issues need fixin= g > > > > however. > > > >=20 > > > > Firstly the s390 MMIO syscalls do not cause a page fault when > > > > follow_pte() fails due to the page not being present. This breaks > > > > vfio-pci's mmap() handling which lazily maps on first access. > > > >=20 > > > > Secondly on s390 there is a virtual PCI device called ISM which has > > > > a few oddities. For one it claims to have a 256 TiB PCI BAR (not a = typo) > > > > which leads to any attempt to mmap() it fail with the following mes= sage: > > > >=20 > > > > vmap allocation for size 281474976714752 failed: use vmalloc=3D= to increase size > > > >=20 > > > > Even if one tried to map this BAR only partially the mapping would = not > > > > be usable on systems with MIO support enabled. So just block mappin= g > > > > BARs which don't fit between IOREMAP_START and IOREMAP_END. Solve t= his > > > > by keeping the vfio-pci mmap() blocking behavior around for this > > > > specific device via a PCI quirk and new pdev->non_mappable_bars > > > > flag. > > > >=20 > > > > As noted by Alex Williamson With mmap() enabled in vfio-pci it make= s > > > > sense to also enable HAVE_PCI_MMAP with the same restriction for pd= ev-> > > > > non_mappable_bars. So this is added in patch 3 and I tested this wi= th > > > > another small test program. > > > >=20 > > > > Note: > > > > For your convenience the code is also available in the tagged > > > > b4/vfio_pci_mmap branch on my git.kernel.org site below: > > > > https://git.kernel.org/pub/scm/linux/kernel/git/niks/linux.git/ > > > >=20 > > > > Thanks, > > > > Niklas > > > >=20 > > > > Link: https://lore.kernel.org/all/c5ba134a1d4f4465b5956027e6a4ea6f6= beff969.camel@linux.ibm.com/ > > > > Signed-off-by: Niklas Schnelle > > > > --- > > > > Changes in v6: > > > > - Add a patch to also enable PCI resource mmap() via sysfs and proc > > > > exlcluding pdev->non_mappable_bars devices (Alex Williamson) > > > > - Added Acks > > > > - Link to v5: https://lore.kernel.org/r/20250212-vfio_pci_mmap-v5-0= -633ca5e056da@linux.ibm.com > > >=20 > > > I think the series would be more readable if patch 2/3 included all > > > the core changes (adding pci_dev.non_mappable_bars, the 3/3 > > > pci-sysfs.c and proc.c changes to test it, and I suppose the similar > > > vfio_pci_core.c change), and we moved all the s390 content from 2/3 t= o > > > 3/3. > >=20 > > Maybe we could do the following: > >=20 > > 1/3: As is > >=20 > > 2/3: Introduces pdev->non_mappable_bars and the checks in vfio and > > proc.c/pci-sysfs.c. To make the flag handle the vfio case with > > VFIO_PCI_MMAP gone, a one-line change in s390 will set pdev- > > > non_mappable_bars =3D 1 for all PCI devices. >=20 > What if you moved the vfio_pci_core.c change to patch 3? Then I think > patch 2 would do nothing at all (since there's nothing that sets > non_mappable_bars), and all the s390 stuff would be in patch 3? >=20 > Not sure if that's possible, but I think it's a little confusing to > have the s390 changes split across patch 2 and 3. I'm not really a fan of having a completely unused flag, even in an intermediate commit. I've edited the commits yesterday and with this approach the s390 specific part of 2/3 really is just the below hunk:=20 diff --git a/arch/s390/pci/pci.c b/arch/s390/pci/pci.c index 88f72745fa59..d14b8605a32c 100644 --- a/arch/s390/pci/pci.c +++ b/arch/s390/pci/pci.c @@ -590,6 +590,7 @@ int pcibios_device_add(struct pci_dev *pdev) zpci_zdev_get(zdev); if (pdev->is_physfn) pdev->no_vf_scan =3D 1; + pdev->non_mappable_bars =3D 1; zpci_map_resources(pdev); That added line then gets deleted again in 3/3. I think this makes it pretty logical, with patch 2/3 we set it for all PCI devices giving the existing behavior and by pdev->non_mappable_bars replacing the "y if S390" of VFIO_PCI_MMAP, then 3/3 narrows it down to just the ISM device. Thanks, Niklas