From nobody Wed Apr 1 10:59:08 2026 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 5F3993DE432; Mon, 30 Mar 2026 17:40:27 +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=1774892430; cv=none; b=bLB2QWBY4mF2HD0o9LZAZIyXTlTa3R26T6Bi0lI99rulzfNort/bhWZnA/LYyyhmKi6m+ZYw75vJZ/2GITZZvgSbyVUwDHZ7U+OejhtpAJ0a4pYo1d9yx243Am3OV4m8u7stm7C8rXhw8EUtQ3RIaO0QYClNrHTDRP3F0J4UII4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774892430; c=relaxed/simple; bh=zmO9qVygBTl3Ynmb51HKeC92Av1E7/vfIZEtPOocSCU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lYxVcWengu3yiOgm6wyQVSFH82d8GytDxRcZdZZy+BNauheOAcAif/WzZlo75MWOIACFeEYqS8XFPg+tAn1rZY/uZWQfTI014yWWvitcHvK/HrVSYln3DBjOSOR6+BNBYFbuA/8uuWR2pj+9Q8GpLK66VNXCtyCfyhVBT3/GhLg= 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=bbTBn8Ip; 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="bbTBn8Ip" Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 62UFSIQE270868; Mon, 30 Mar 2026 17:40:20 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=FYxLOqn7kUmMT8BfP Dug1DpYshopCZ3Iipsaiwu5E84=; b=bbTBn8Ipcd4uU2kQmdZ+aCIUXKEjv6e7e Up2VaqjOfSq5UdRLO7bozzKgKGkqiZ9bw0TADGc+UzSmNSrc5eGMfvSFDE/anFnw LIGDMoXak+Tk7AaMH7WKDYpo2bJojnXbaf1yfJr+WXBQEtOSuz6vwDQjj6cklVfl ozOwRNwm5JEWxy4awtn0rzySdka3NKzNEZvLNOYX3Qxz7Sprb8q5AyB7Sds5co7a CiLJ9dmIDXGODZI2uFN5w4k9FKByH+EtB+n2GH8u1XRtUfdtuGdxS7+AH0tnEJR6 gDKIgzRr0l58hKq/FGZI/rfGjyRzmzqA4XWoIcdqN2wR9b56LFldw== Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4d65dc7pvn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 30 Mar 2026 17:40:20 +0000 (GMT) Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 62UG1ItH008698; Mon, 30 Mar 2026 17:40:19 GMT Received: from smtprelay02.dal12v.mail.ibm.com ([172.16.1.4]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 4d6v11dmqk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 30 Mar 2026 17:40:19 +0000 Received: from smtpav04.dal12v.mail.ibm.com (smtpav04.dal12v.mail.ibm.com [10.241.53.103]) by smtprelay02.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 62UHeIGI1901252 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 30 Mar 2026 17:40:18 GMT Received: from smtpav04.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C1C1A58056; Mon, 30 Mar 2026 17:40:18 +0000 (GMT) Received: from smtpav04.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F2C8158062; Mon, 30 Mar 2026 17:40:17 +0000 (GMT) Received: from IBM-D32RQW3.ibm.com (unknown [9.61.243.214]) by smtpav04.dal12v.mail.ibm.com (Postfix) with ESMTP; Mon, 30 Mar 2026 17:40:17 +0000 (GMT) From: Farhan Ali To: linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org Cc: helgaas@kernel.org, lukas@wunner.de, alex@shazbot.org, clg@redhat.com, kbusch@kernel.org, alifm@linux.ibm.com, schnelle@linux.ibm.com, mjrosato@linux.ibm.com Subject: [PATCH v12 5/7] vfio-pci/zdev: Add a device feature for error information Date: Mon, 30 Mar 2026 10:40:09 -0700 Message-ID: <20260330174011.1161-6-alifm@linux.ibm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260330174011.1161-1-alifm@linux.ibm.com> References: <20260330174011.1161-1-alifm@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: quoted-printable X-TM-AS-GCONF: 00 X-Authority-Analysis: v=2.4 cv=RsjI7SmK c=1 sm=1 tr=0 ts=69cab584 cx=c_pps a=aDMHemPKRhS1OARIsFnwRA==:117 a=aDMHemPKRhS1OARIsFnwRA==:17 a=Yq5XynenixoA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=V8glGbnc2Ofi9Qvn3v5h:22 a=VnNF1IyMAAAA:8 a=QIy8Zix3hhx26zbqT_4A:9 X-Proofpoint-GUID: vrMufRkLdoDnQmSYejUT6F0YpNkgfA5d X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMzMwMDE0MSBTYWx0ZWRfX2BDLNWCGY6I/ mzMqI8aS6RrMyvXwswdFzr4SViIz/lnuS3xCvRPFyaz+I9A4i+Jtpc2saNHalzr+D86VCl07H6O 6uauTFzLq3r5NfP+kv3/92xfTUD9vIeapGAu+XyF1ujbcho1G3pABIUNYpON0JqEGIA++lGFkYM JPW3NsjsEpEHCuyPgcHoQTRMD8tgmb3CHMkO/A6VtaRtXJWi+CzgGZnHsA/I4HXGMhyq3Z6TgvD WV5y6tVu890eVUx/0zB9L/s6LH/T0Tk/jQCpbVt9KWE02R525WdaDAiB6fVnSFqmrMHQisSuRk+ JM9xhEjMFAEq9be9On97f7r3nEBzk/bsyZzAAW5W5gbnP7LUkqNZPUQcOq0kXI4VYkgecRQypja 60ohePQDTp0RhLE/HJLidMBzTcMLjqGKIwe5nRRCHa9iZULW+p8XKxTRhOORqU7Dl8adktV/W2r +pxz+JVWHhPMEkgt0vg== X-Proofpoint-ORIG-GUID: vrMufRkLdoDnQmSYejUT6F0YpNkgfA5d X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-03-29_05,2026-03-28_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 bulkscore=0 priorityscore=1501 lowpriorityscore=0 suspectscore=0 malwarescore=0 spamscore=0 clxscore=1015 phishscore=0 adultscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2603050001 definitions=main-2603300141 Content-Type: text/plain; charset="utf-8" For zPCI devices, we have platform specific error information. The platform firmware provides this error information to the operating system in an architecture specific mechanism. To enable recovery from userspace for these devices, we want to expose this error information to userspace. Add a new device feature to expose this information. Signed-off-by: Farhan Ali Reviewed-by: Matthew Rosato --- drivers/vfio/pci/vfio_pci_core.c | 2 ++ drivers/vfio/pci/vfio_pci_priv.h | 9 ++++++++ drivers/vfio/pci/vfio_pci_zdev.c | 36 ++++++++++++++++++++++++++++++++ include/uapi/linux/vfio.h | 18 ++++++++++++++++ 4 files changed, 65 insertions(+) diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_c= ore.c index d43745fe4c84..bbdb625e35ef 100644 --- a/drivers/vfio/pci/vfio_pci_core.c +++ b/drivers/vfio/pci/vfio_pci_core.c @@ -1534,6 +1534,8 @@ int vfio_pci_core_ioctl_feature(struct vfio_device *d= evice, u32 flags, return vfio_pci_core_feature_token(vdev, flags, arg, argsz); case VFIO_DEVICE_FEATURE_DMA_BUF: return vfio_pci_core_feature_dma_buf(vdev, flags, arg, argsz); + case VFIO_DEVICE_FEATURE_ZPCI_ERROR: + return vfio_pci_zdev_feature_err(device, flags, arg, argsz); default: return -ENOTTY; } diff --git a/drivers/vfio/pci/vfio_pci_priv.h b/drivers/vfio/pci/vfio_pci_p= riv.h index 27ac280f00b9..647a9e8f348d 100644 --- a/drivers/vfio/pci/vfio_pci_priv.h +++ b/drivers/vfio/pci/vfio_pci_priv.h @@ -89,6 +89,8 @@ int vfio_pci_info_zdev_add_caps(struct vfio_pci_core_devi= ce *vdev, struct vfio_info_cap *caps); int vfio_pci_zdev_open_device(struct vfio_pci_core_device *vdev); void vfio_pci_zdev_close_device(struct vfio_pci_core_device *vdev); +int vfio_pci_zdev_feature_err(struct vfio_device *device, u32 flags, + void __user *arg, size_t argsz); #else static inline int vfio_pci_info_zdev_add_caps(struct vfio_pci_core_device = *vdev, struct vfio_info_cap *caps) @@ -103,6 +105,13 @@ static inline int vfio_pci_zdev_open_device(struct vfi= o_pci_core_device *vdev) =20 static inline void vfio_pci_zdev_close_device(struct vfio_pci_core_device = *vdev) {} + +static inline int vfio_pci_zdev_feature_err(struct vfio_device *device, + u32 flags, void __user *arg, + size_t argsz) +{ + return -ENOTTY; +} #endif =20 static inline bool vfio_pci_is_vga(struct pci_dev *pdev) diff --git a/drivers/vfio/pci/vfio_pci_zdev.c b/drivers/vfio/pci/vfio_pci_z= dev.c index 0658095ac5b1..0a8663879eee 100644 --- a/drivers/vfio/pci/vfio_pci_zdev.c +++ b/drivers/vfio/pci/vfio_pci_zdev.c @@ -141,6 +141,42 @@ int vfio_pci_info_zdev_add_caps(struct vfio_pci_core_d= evice *vdev, return ret; } =20 +int vfio_pci_zdev_feature_err(struct vfio_device *device, u32 flags, + void __user *arg, size_t argsz) +{ + struct vfio_device_feature_zpci_err err =3D {}; + struct vfio_pci_core_device *vdev; + struct zpci_dev *zdev; + int head =3D 0; + int ret; + + vdev =3D container_of(device, struct vfio_pci_core_device, vdev); + zdev =3D to_zpci(vdev->pdev); + if (!zdev) + return -ENODEV; + + ret =3D vfio_check_feature(flags, argsz, VFIO_DEVICE_FEATURE_GET, + sizeof(err)); + if (ret !=3D 1) + return ret; + + mutex_lock(&zdev->pending_errs_lock); + if (zdev->pending_errs.count) { + head =3D zdev->pending_errs.head % ZPCI_ERR_PENDING_MAX; + err.pec =3D zdev->pending_errs.err[head].pec; + zdev->pending_errs.head++; + zdev->pending_errs.count--; + err.pending_errors =3D zdev->pending_errs.count; + } + mutex_unlock(&zdev->pending_errs_lock); + + err.version =3D 1; + if (copy_to_user(arg, &err, sizeof(err))) + return -EFAULT; + + return 0; +} + int vfio_pci_zdev_open_device(struct vfio_pci_core_device *vdev) { struct zpci_dev *zdev =3D to_zpci(vdev->pdev); diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h index bb7b89330d35..2552eef42000 100644 --- a/include/uapi/linux/vfio.h +++ b/include/uapi/linux/vfio.h @@ -1510,6 +1510,24 @@ struct vfio_device_feature_dma_buf { struct vfio_region_dma_range dma_ranges[] __counted_by(nr_ranges); }; =20 +/** + * VFIO_DEVICE_FEATURE_ZPCI_ERROR feature provides PCI error information to + * userspace for vfio-pci devices on s390x. On s390x PCI error recovery + * involves platform firmware and notification to operating system is done + * by architecture specific mechanism. Exposing this information to + * userspace allows userspace to take appropriate actions to handle an + * error on the device. The pending_errors provide any additional errors + * pending for the device, and userspace should read until zero. + */ + +struct vfio_device_feature_zpci_err { + __u8 version; + __u8 pending_errors; + __u16 pec; +}; + +#define VFIO_DEVICE_FEATURE_ZPCI_ERROR 12 + /* -------- API for Type1 VFIO IOMMU -------- */ =20 /** --=20 2.43.0