From nobody Sat May 30 18:34:29 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1777665787; cv=none; d=zohomail.com; s=zohoarc; b=R/TUbXKEuF0npN/JYmr8Y+GVyZc1rmhNbeFnjTz2baWZJ52urtquc7USQnQRclRGUiVyawJsxdtlUyoawXjHgZP/7WRpBpJbkdnW5oKUv6MB34zgl12BKhJ0HHDxk0Em9UU78HoQL5sCCGqhVvQGUwWw5kglzpe6Mpy5P+MAVZE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1777665787; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=2IaD55tpATj/ZVnphn8buKRjOnzNdJxxssi+olLWHzw=; b=AMHe2PahuhyYKrPnj2IBIDKEKkcUer40pI4TKkuFF47c4yHFU3q7VwUPknGNYGLwOeMBEwRwjbg9KqVxL1iWSDxwOtNX5ZtohJ+Py3EnBxRREZvX30SiDzeaiSUtaurQjziNUaMhQgEB175nX/4BL1gyQEIPRldgfldGfgQA5c0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1777665787674369.0903693087092; Fri, 1 May 2026 13:03:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wIu4U-0000ZN-Qg; Fri, 01 May 2026 16:02:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wIu4R-0000YN-SD; Fri, 01 May 2026 16:02:44 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wIu4Q-0001Au-CD; Fri, 01 May 2026 16:02:43 -0400 Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 64197Xb81317126; Fri, 1 May 2026 20:02:37 GMT Received: from ppma13.dal12v.mail.ibm.com (dd.9e.1632.ip4.static.sl-reverse.com [50.22.158.221]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4drk1k4cq2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 01 May 2026 20:02:37 +0000 (GMT) Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.18.1.7/8.18.1.7) with ESMTP id 641Jrnrd000693; Fri, 1 May 2026 20:02:36 GMT Received: from smtprelay03.dal12v.mail.ibm.com ([172.16.1.5]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 4dsa5grt8q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 01 May 2026 20:02:36 +0000 (GMT) Received: from smtpav06.dal12v.mail.ibm.com (smtpav06.dal12v.mail.ibm.com [10.241.53.105]) by smtprelay03.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 641K2YgS32571910 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 1 May 2026 20:02:34 GMT Received: from smtpav06.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0E41D58043; Fri, 1 May 2026 20:02:34 +0000 (GMT) Received: from smtpav06.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E2C4358055; Fri, 1 May 2026 20:02:32 +0000 (GMT) Received: from Mac.ibm.com (unknown [9.61.247.25]) by smtpav06.dal12v.mail.ibm.com (Postfix) with ESMTP; Fri, 1 May 2026 20:02:32 +0000 (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=2IaD55tpATj/ZVnph n8buKRjOnzNdJxxssi+olLWHzw=; b=CUE516T7ZQklu//l6WdrkQ5unqhOEHYEd 7wn0HXdl3fIMYbswL4pcj2JkMQSoRviyh8I1Fr75S/H1aoS3lWyDwYdNvStE+aZ0 3F48+YKWbe4N8299KrvW1qYoFWX8Ka51zjdOjrgQFn3V5mVsMHhKybCA9MkEfpop 5pmOSQwTeEvwt6AuzB+KwIp4hABiFMnuSssD+yrrBk0g11/2GC6ge06LSsiIHwSq JKXa9iT8+/ywhThV3RChrGt61nBRuGrxT+zoZJIxOm6DHFY1GAg2J3vaXcHIQBci 2nRgFvccG4rpxsPxStcX+c+suNj4Tgr7KSK4a2YkYbiCYhiMMhlvg== From: Omar Elghoul To: qemu-devel@nongnu.org, qemu-s390x@nongnu.org Cc: oelghoul@linux.ibm.com, mjrosato@linux.ibm.com, alifm@linux.ibm.com, farman@linux.ibm.com, pasic@linux.ibm.com, borntraeger@linux.ibm.com, richard.henderson@linaro.org, iii@linux.ibm.com, david@kernel.org, cohuck@redhat.com, mst@redhat.com, pbonzini@redhat.com, clg@redhat.com Subject: [RFC PATCH v1 1/5] [do-not-merge] linux-headers: Add definitions for VFIO zPCI FMB passthrough Date: Fri, 1 May 2026 16:00:22 -0400 Message-ID: <20260501200026.22784-2-oelghoul@linux.ibm.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260501200026.22784-1-oelghoul@linux.ibm.com> References: <20260501200026.22784-1-oelghoul@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNTAxMDE5NSBTYWx0ZWRfX6X3WidarEm5T wfQKfQF7K/DEgeMJGBoWdvlDx2TTGgxRv7qBYb+SFUeI7yJO3jKgBi2KQ0EVVRv0P4ouB3kOlfY SkI+7qwKHuxlZyUprOKbFvrateskNvhXKZozScRC9x4g3JR3P3E9n9ghcc99tydhSp/Ilt1jTCa bdhtG9pk0DeO0JVWevPzIMCeDmV3sZmJ7W3Z+30GlETj/VwZ6QcgMD0xPneAfELpNruxTzDTL8d COeEOHdMorXZqXXgJOgPXHVru1H0jqA00ROQ8xXjN9qYGbIzcFHS5kGSyYvKu2iR4wcBQ0mP0ay 0GiiKx1k2ItKOxRq3lR/JzdECQv7ebtR8aN++C+J/7K8S9YH2E3EssGNPZhLD0qaCUZS4K8nps7 o6LklKvjhxfyVITq+ZPF90Y2XfHvOQ11lJSUJVL2yBhhuk2zeZ8Ttn4+epOfrC2iQAN1gpJQf8D sDHVI/lisoyM5g1OzOQ== X-Proofpoint-GUID: PsLjcL_buIwjBmG76iIIBuieJbZmTb_v X-Proofpoint-ORIG-GUID: PsLjcL_buIwjBmG76iIIBuieJbZmTb_v X-Authority-Analysis: v=2.4 cv=MohiLWae c=1 sm=1 tr=0 ts=69f506dd cx=c_pps a=AfN7/Ok6k8XGzOShvHwTGQ==:117 a=AfN7/Ok6k8XGzOShvHwTGQ==:17 a=NGcC8JguVDcA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=Y2IxJ9c9Rs8Kov3niI8_:22 a=VnNF1IyMAAAA:8 a=05gaV3nvTOrdMBspcBoA:9 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-05-01_05,2026-04-30_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 adultscore=0 suspectscore=0 bulkscore=0 spamscore=0 priorityscore=1501 malwarescore=0 clxscore=1011 lowpriorityscore=0 impostorscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2604200000 definitions=main-2605010195 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=148.163.158.5; envelope-from=oelghoul@linux.ibm.com; helo=mx0b-001b2d01.pphosted.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ibm.com) X-ZM-MESSAGEID: 1777665789189154101 Content-Type: text/plain; charset="utf-8" This is a temporary patch intended for testing purposes only. It defines the new VFIO device feature for FMB passthrough on zPCI. Signed-off-by: Omar Elghoul --- linux-headers/linux/vfio.h | 43 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/linux-headers/linux/vfio.h b/linux-headers/linux/vfio.h index 720edfee7a..ee5f8a2276 100644 --- a/linux-headers/linux/vfio.h +++ b/linux-headers/linux/vfio.h @@ -1506,6 +1506,49 @@ struct vfio_device_feature_dma_buf { struct vfio_region_dma_range dma_ranges[] __counted_by(nr_ranges); }; =20 +/** + * Upon VFIO_DEVICE_FEATURE_GET, provide FMB passthrough for VFIO zPCI dev= ices. + *=20 + * Upon VFIO_DEVICE_FEATURE_SET, only the flags field is read while the + * remainder of the structure is ignored. This allows the driver to enable= or + * disable the FMB while also leaving reserved bits for future flag expans= ion. + * All reserved fields should be zero for future compatibility. + */ +#define VFIO_DEVICE_FEATURE_ZPCI_FMB 13 +#define VFIO_DEVICE_FEATURE_ZPCI_FMB_FLAGS_ENABLED 0x1 + +struct vfio_device_feature_zpci_fmb { + __u64 flags; + __u32 format: 8; + __u32 fmt_ind: 24; + __u32 samples; + __u64 last_update; + __u64 ld_ops; + __u64 st_ops; + __u64 stb_ops; + __u64 rpcit_ops; + union { + struct { + __u64 dma_rbytes; + __u64 dma_wbytes; + } fmt0; + struct { + __u64 rx_bytes; + __u64 rx_packets; + __u64 tx_bytes; + __u64 tx_packets; + } fmt1; + struct { + __u64 consumed_work_units; + __u64 max_work_units; + } fmt2; + struct { + __u64 tx_bytes; + } fmt3; + }; + __u64 reserved[16]; +}; + /* -------- API for Type1 VFIO IOMMU -------- */ =20 /** --=20 2.52.0 From nobody Sat May 30 18:34:29 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1777665809; cv=none; d=zohomail.com; s=zohoarc; b=caygrwNKeSjmyhtO8q3wWmEmqMs8U7z7JDfw+u6+bydvcE1rBUioD+K/n13mQRIWu0rrnmZZwcpPNXpnqSyh9/BV2XLt7eomgzCYvLm7n7q7pFuW5/CGmtrAvg1Mk1e0EILzl2jeqmg87ux/3v5CP7ze4N/z5Y2D6lLVKPG33GI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1777665809; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=MmAIrOmBi+O9AQ6ZS5atURf23x4XcDe8K9D0teZNruQ=; b=bhVzrAxgwoz75m4mFy4arPPFS5fo6PtVY+R8YUtxbT3UvGsm8XJf6UGtFhDTMcHdAI6fAhOo3pceSWo9S9ehs+sEY5KeXfwWyDCZiKZ67pd6LdnrPG8wIyOnUOwD2Ffds+fSNSUWUmnOCOwhupAnS0UwIYif/19G3VumCe4wGeQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1777665809540896.1926686747069; Fri, 1 May 2026 13:03:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wIu52-0000lk-Cn; Fri, 01 May 2026 16:03:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wIu4w-0000kX-Fd; Fri, 01 May 2026 16:03:15 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wIu4u-0001Eb-U3; Fri, 01 May 2026 16:03:14 -0400 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 641GKXLn3403831; Fri, 1 May 2026 20:03:08 GMT Received: from ppma21.wdc07v.mail.ibm.com (5b.69.3da9.ip4.static.sl-reverse.com [169.61.105.91]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4drm1ec7ru-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 01 May 2026 20:03:07 +0000 (GMT) Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.18.1.7/8.18.1.7) with ESMTP id 641Js0Po003852; Fri, 1 May 2026 20:03:07 GMT Received: from smtprelay06.wdc07v.mail.ibm.com ([172.16.1.73]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4ds8xkgxjw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 01 May 2026 20:03:07 +0000 (GMT) Received: from smtpav06.dal12v.mail.ibm.com (smtpav06.dal12v.mail.ibm.com [10.241.53.105]) by smtprelay06.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 641K34ba29032896 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 1 May 2026 20:03:04 GMT Received: from smtpav06.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6352658055; Fri, 1 May 2026 20:03:04 +0000 (GMT) Received: from smtpav06.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 421D158043; Fri, 1 May 2026 20:03:03 +0000 (GMT) Received: from Mac.ibm.com (unknown [9.61.247.25]) by smtpav06.dal12v.mail.ibm.com (Postfix) with ESMTP; Fri, 1 May 2026 20:03:03 +0000 (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=MmAIrOmBi+O9AQ6ZS 5atURf23x4XcDe8K9D0teZNruQ=; b=lB78hm0OYR/ddkY6t28Qb9G7ThrYBkt/Z EFVlLFDtgkpwnJI52N7cBc5bUsQvkpAlHa0I2dl5NhKU6gLdSik+teLcWe0waE+5 6G9QaaIqwl2PKBCQGhrOg+HDjI9vhs3TybL3TDkvVTR1Ecf/8UeWjJT7TmoUQmYR kTflfKFr3JeuRC4kUPiv3/mUevLPbP7sPpqS3bZftfEgaeAHqgLoBgbmjWN+zyny YewZBYItxy0wkglrEr3/eR5RSvSdY+X0wAwGY+/gSn0VK+lzloiR45noWmU6jUyJ t1JG3qkW/Ox64wL8NQheEiYERPhGBwhSN/5CqgTkVXfY+fca6GkLw== From: Omar Elghoul To: qemu-devel@nongnu.org, qemu-s390x@nongnu.org Cc: oelghoul@linux.ibm.com, mjrosato@linux.ibm.com, alifm@linux.ibm.com, farman@linux.ibm.com, pasic@linux.ibm.com, borntraeger@linux.ibm.com, richard.henderson@linaro.org, iii@linux.ibm.com, david@kernel.org, cohuck@redhat.com, mst@redhat.com, pbonzini@redhat.com, clg@redhat.com Subject: [RFC PATCH v1 2/5] hw/s390x: Clarified FMB format for emulated and passthrough devices Date: Fri, 1 May 2026 16:00:23 -0400 Message-ID: <20260501200026.22784-3-oelghoul@linux.ibm.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260501200026.22784-1-oelghoul@linux.ibm.com> References: <20260501200026.22784-1-oelghoul@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: iKmMe7lmwB7SjmWYCxL8p4SSFByjXCjO X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNTAxMDE5NSBTYWx0ZWRfXx8IrxA9ZhwlS Su2yf8IcoK1fBR6wF0QfoOX5SdcYLuKCRQPdfD8zM6onj7uImpuhFE+wD0isgbQ8+zGpaxCW3aa sw2kE2X3yVrWuq90T53p/sIDOEXhtgQU4Vf9wuG/5U23mlmCohtv9UO2qe8q20Fe90TyxpkU8f8 qowWjR0S9JbySEOii+u9dGH8Y2fZXk0gyfnm3Fm1hMw9pqDxGdYHwzNcVfrP1g+uQct2rPON9lq AKAGcl7H2/ESXxYoI3QXV//i2WojvkxXEDd4qJ6bsmfQcjuKaRmHA1VsjRK8Tg6gVPm9eX7jOEg QnZqSgQ6uRiQJsIDdWdlOz+ito8FcRHERewRPSM0ZafJ4b8wxcRlDJSiGgDj9eHkDc3DYUzACn0 th3Hohw0XcRmbD4nIjf2+0f/pEEKirjOEq1DjWV3oOskcNPfwWDbC9Ugnxjn86Q6JFxnnfiohxc BQrQ30vXRw1gHLbBnYA== X-Authority-Analysis: v=2.4 cv=VZLH+lp9 c=1 sm=1 tr=0 ts=69f506fc cx=c_pps a=GFwsV6G8L6GxiO2Y/PsHdQ==:117 a=GFwsV6G8L6GxiO2Y/PsHdQ==:17 a=NGcC8JguVDcA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=V8glGbnc2Ofi9Qvn3v5h:22 a=VnNF1IyMAAAA:8 a=f_7aZsy8-PDlq5a6mJoA:9 X-Proofpoint-GUID: iKmMe7lmwB7SjmWYCxL8p4SSFByjXCjO 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-05-01_05,2026-04-30_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1011 suspectscore=0 adultscore=0 lowpriorityscore=0 phishscore=0 spamscore=0 malwarescore=0 bulkscore=0 priorityscore=1501 impostorscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2604200000 definitions=main-2605010195 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=148.163.158.5; envelope-from=oelghoul@linux.ibm.com; helo=mx0b-001b2d01.pphosted.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ibm.com) X-ZM-MESSAGEID: 1777665811143154100 Content-Type: text/plain; charset="utf-8" Renamed the default FMB format macro and added a comment explaining that it will be overwritten in the case of PCI passthrough devices when paired with a compatible kernel. Signed-off-by: Omar Elghoul --- hw/s390x/s390-pci-bus.c | 8 +++++++- include/hw/s390x/s390-pci-bus.h | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/hw/s390x/s390-pci-bus.c b/hw/s390x/s390-pci-bus.c index 4de7b587e8..128814f4c5 100644 --- a/hw/s390x/s390-pci-bus.c +++ b/hw/s390x/s390-pci-bus.c @@ -1486,7 +1486,13 @@ static void s390_pci_device_realize(DeviceState *dev= , Error **errp) } =20 zpci->state =3D ZPCI_FS_RESERVED; - zpci->fmb.format =3D ZPCI_FMB_FORMAT; + + /* + * For emulated devices, we use FMB format-0. For PCI passthrough + * devices paired with a compatible kernel, this will get overwritten + * by the VFIO-provided FMB. + */ + zpci->fmb.format =3D ZPCI_FMB_DEFAULT_FORMAT; } =20 static void s390_pci_device_reset(DeviceState *dev) diff --git a/include/hw/s390x/s390-pci-bus.h b/include/hw/s390x/s390-pci-bu= s.h index 9228523ce8..feaf6d4863 100644 --- a/include/hw/s390x/s390-pci-bus.h +++ b/include/hw/s390x/s390-pci-bus.h @@ -308,7 +308,7 @@ typedef struct ZpciFmbFmt0 { #define ZPCI_FMB_CNT_RPCIT 3 #define ZPCI_FMB_CNT_MAX 4 =20 -#define ZPCI_FMB_FORMAT 0 +#define ZPCI_FMB_DEFAULT_FORMAT 0 =20 typedef struct ZpciFmb { uint32_t format; --=20 2.52.0 From nobody Sat May 30 18:34:29 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1777665883; cv=none; d=zohomail.com; s=zohoarc; b=NC+Objlw4aHb8Xspppc9Yon3WhRmglsewBmgctfn6zPUeWZLh6QV8mYYM++F/fa10wo/uZeF2hXCP7ys+jjOF2+CIhlRNAYW2i/qWrDrND1ommIeO8rBNgzswAIYrnnsUI/1T5Vwg1/HfWHoORkB8mFmpb2nc5V+fOEzisTpntY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1777665883; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=IwvvP9MY8WoGYhdgJWzLy3S2sw6QZcbw07ZcxAXwF0I=; b=Y9//mjBJEgVK36Zjzf28Krd02TxJWcUEPCaWOpfHs4+n2Wo8YqDoGv3nQW2OyyPuYI4CEjqIFf/xFpwKK/fIxNeK2MpkUKnVjpDA2FHpMJAystHsuRxhG4DXPCJMuWas94fa4hNnz54IKI3nSB04/wmy/2uxm8TzECJuCHPSOZg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1777665882997225.00918575445462; Fri, 1 May 2026 13:04:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wIu67-0001TA-Jw; Fri, 01 May 2026 16:04:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wIu5M-0001C9-EP; Fri, 01 May 2026 16:03:52 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wIu5J-0001QO-DL; Fri, 01 May 2026 16:03:40 -0400 Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 641EkLAq2006058; Fri, 1 May 2026 20:03: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 4drn8vv61p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 01 May 2026 20:03:33 +0000 (GMT) Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.18.1.7/8.18.1.7) with ESMTP id 641Js0Jo019209; Fri, 1 May 2026 20:03:33 GMT Received: from smtprelay05.wdc07v.mail.ibm.com ([172.16.1.72]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4ds8aw91kk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 01 May 2026 20:03:33 +0000 (GMT) Received: from smtpav06.dal12v.mail.ibm.com (smtpav06.dal12v.mail.ibm.com [10.241.53.105]) by smtprelay05.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 641K3T9b63242744 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 1 May 2026 20:03:29 GMT Received: from smtpav06.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 87BCA58043; Fri, 1 May 2026 20:03:29 +0000 (GMT) Received: from smtpav06.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 629E158059; Fri, 1 May 2026 20:03:28 +0000 (GMT) Received: from Mac.ibm.com (unknown [9.61.247.25]) by smtpav06.dal12v.mail.ibm.com (Postfix) with ESMTP; Fri, 1 May 2026 20:03:28 +0000 (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=IwvvP9MY8WoGYhdgJ WzLy3S2sw6QZcbw07ZcxAXwF0I=; b=orD4z5+arMyNKir+beBy1SzHib6xjAfUd ABeVKu5cJRWkM0zRjXl7eMkmHc5csg8sHJdglin/DU0CVGI/gD1mzNkS8gfykPQt 2rRUY2P5g4EX3FKMM8Hb2x0Zs7VFKC4OJZH7KdRPRjgsvYFe6g40A7K/vU/lP8n+ MaODRc2wJhZ/zpl+VltwxEs4mtxw0PjU8yR9L4FhaWpwo1wahfLYEEb8ae07bSRZ ehpCZBH0XElLBq0Pf/l4RPmM06azyHerbvR8h6CZRtzrYcfmSuKa+7nJWseusQR1 g3P5z9AMvcN0s1oWzKKVPKcfQTVQCjkI41xHYAUuuGxc0S+yoAPrw== From: Omar Elghoul To: qemu-devel@nongnu.org, qemu-s390x@nongnu.org Cc: oelghoul@linux.ibm.com, mjrosato@linux.ibm.com, alifm@linux.ibm.com, farman@linux.ibm.com, pasic@linux.ibm.com, borntraeger@linux.ibm.com, richard.henderson@linaro.org, iii@linux.ibm.com, david@kernel.org, cohuck@redhat.com, mst@redhat.com, pbonzini@redhat.com, clg@redhat.com Subject: [RFC PATCH v1 3/5] hw/virtio: Add DMA counters for virtio-pci devices Date: Fri, 1 May 2026 16:00:24 -0400 Message-ID: <20260501200026.22784-4-oelghoul@linux.ibm.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260501200026.22784-1-oelghoul@linux.ibm.com> References: <20260501200026.22784-1-oelghoul@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Authority-Analysis: v=2.4 cv=CIIamxrD c=1 sm=1 tr=0 ts=69f50715 cx=c_pps a=5BHTudwdYE3Te8bg5FgnPg==:117 a=5BHTudwdYE3Te8bg5FgnPg==:17 a=NGcC8JguVDcA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=RzCfie-kr_QcCd8fBx8p:22 a=VnNF1IyMAAAA:8 a=456z7t5ePv1a_L0t-noA:9 X-Proofpoint-ORIG-GUID: jUlSoWcWBnFT_KLsUJPayO9F9xhYjKfW X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNTAxMDE5NSBTYWx0ZWRfXyGg/RRSSQxjs dBwExYQDxtalSUcB4LnfalVhB/hQLfgnzOMtDiilkdlBNzX1mcHo/U0qjz93uNnuvMs6ngcwUG2 9iXaXn3KIXnp9L5qcKQWoDq9GCfmKhXrx9Nv9WekHPvMR4GVdZwLRkThPmdqFYV5q+8LHj7q3wW ypBUgabiYGOg/I7gJEvklVRqc1rQeZMraPzs4zrP3S9Ol2uFJAWTGRuW9ZxdoSNCjNWR+jH/CYZ lb8GggUBrHvSY1WczqJG4tDiCwbE/Zbm+uS3tOvMyRC4mhqyrOgZ2EDFLtROx3KBCRxoOcugVnM eyQvQkR6I1pSVFo8/bu5LIB1Rft83I/rl9bWjh2A5v6ABckO7dyra8BAJgE+Pr5Q1AH4SbOI+T5 yc7Nal88cuxjXVcZr6bsyUE9+s1UnNjwOi7X/IX/smx7MfwcwD0y4Pw/mksycvkj+iGmTceETRL 8LPxB1Lkn+8O7ntQBpw== X-Proofpoint-GUID: jUlSoWcWBnFT_KLsUJPayO9F9xhYjKfW 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-05-01_05,2026-04-30_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 phishscore=0 malwarescore=0 suspectscore=0 adultscore=0 impostorscore=0 lowpriorityscore=0 clxscore=1011 bulkscore=0 priorityscore=1501 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2604200000 definitions=main-2605010195 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=148.163.158.5; envelope-from=oelghoul@linux.ibm.com; helo=mx0b-001b2d01.pphosted.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ibm.com) X-ZM-MESSAGEID: 1777665884127158500 Content-Type: text/plain; charset="utf-8" Internally track DMA read/write byte counters for virtio-pci devices by assigning them a DMA owner bus. This will allow an implementation of the FMB format-0 for zPCI. The assignment of an owner bus is also done from s390x-specific realization such that other architectures do not need to internally track unutilized counters. Signed-off-by: Omar Elghoul --- hw/s390x/s390-pci-bus.c | 7 +++++++ hw/virtio/virtio.c | 16 ++++++++++++++++ include/hw/pci/pci_device.h | 4 ++++ include/hw/virtio/virtio.h | 1 + 4 files changed, 28 insertions(+) diff --git a/hw/s390x/s390-pci-bus.c b/hw/s390x/s390-pci-bus.c index 128814f4c5..7eee1efeb7 100644 --- a/hw/s390x/s390-pci-bus.c +++ b/hw/s390x/s390-pci-bus.c @@ -20,6 +20,7 @@ #include "hw/s390x/s390-pci-kvm.h" #include "hw/s390x/s390-pci-vfio.h" #include "hw/s390x/s390-virtio-ccw.h" +#include "hw/virtio/virtio-pci.h" #include "hw/core/boards.h" #include "hw/pci/pci_bus.h" #include "hw/core/qdev-properties.h" @@ -1192,6 +1193,12 @@ static void s390_pcihost_plug(HotplugHandler *hotplu= g_dev, DeviceState *dev, pbdev->rtr_avail =3D false; } =20 + if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_PCI)) { + VirtIOPCIProxy *virtio_proxy =3D VIRTIO_PCI(pbdev->pdev); + VirtIODevice *vdev =3D virtio_bus_get_device(&virtio_proxy->bu= s); + vdev->dma_owner =3D OBJECT(virtio_proxy); + } + if (s390_pci_msix_init(pbdev) && !pbdev->interp) { error_setg(errp, "MSI-X support is mandatory " "in the S390 architecture"); diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 8fcf6cfd0b..f61ad57821 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -24,6 +24,7 @@ #include "qom/object_interfaces.h" #include "hw/core/cpu.h" #include "hw/virtio/virtio.h" +#include "hw/virtio/virtio-pci.h" #include "hw/virtio/vhost.h" #include "migration/qemu-file-types.h" #include "qemu/atomic.h" @@ -1617,9 +1618,16 @@ static bool virtqueue_map_desc(VirtIODevice *vdev, u= nsigned int *p_num_sg, hwaddr pa, size_t sz) { bool ok =3D false; + PCIDevice *pdev =3D NULL; unsigned num_sg =3D *p_num_sg; assert(num_sg <=3D max_num_sg); =20 + if (vdev->dma_owner && + object_dynamic_cast(vdev->dma_owner, TYPE_VIRTIO_PCI)) { + VirtIOPCIProxy *proxy =3D VIRTIO_PCI(vdev->dma_owner); + pdev =3D &proxy->pci_dev; + } + if (!sz) { virtio_error(vdev, "virtio: zero sized buffers are not allowed"); goto out; @@ -1650,6 +1658,14 @@ static bool virtqueue_map_desc(VirtIODevice *vdev, u= nsigned int *p_num_sg, sz -=3D len; pa +=3D len; num_sg++; + + if (pdev) { + if (is_write) { + pdev->dma_wbytes +=3D len; + } else { + pdev->dma_rbytes +=3D len; + } + } } ok =3D true; =20 diff --git a/include/hw/pci/pci_device.h b/include/hw/pci/pci_device.h index 5cac6e1688..5a4fd4f605 100644 --- a/include/hw/pci/pci_device.h +++ b/include/hw/pci/pci_device.h @@ -98,6 +98,10 @@ struct PCIDevice { MemoryRegion bus_master_container_region; MemoryRegion bus_master_enable_region; =20 + /* DMA statistics */ + uint64_t dma_rbytes; + uint64_t dma_wbytes; + /* do not access the following fields */ PCIConfigReadFunc *config_read; PCIConfigWriteFunc *config_write; diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index 6344bd7b68..e9e7e437f9 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -161,6 +161,7 @@ struct VirtIODevice */ bool use_guest_notifier_mask; AddressSpace *dma_as; + Object *dma_owner; QLIST_HEAD(, VirtQueue) *vector_queues; QTAILQ_ENTRY(VirtIODevice) next; /** --=20 2.52.0 From nobody Sat May 30 18:34:29 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1777665891; cv=none; d=zohomail.com; s=zohoarc; b=aRX33NFmIiW2k5CHzgqygS3wVdJVHpumU8MzK9Fx7cWcaxqLQkfer8jM9R3hncUABjXdrDgB4ZhZg7xW/RaMdGOsLN3cpXlckGc0YvYeo4OM0nnAqWl2iK3VUXw1n31elmna6/c+vHbd2kz9Lt5rNLBoFe4diLOYL5nUmnDQiqE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1777665891; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=KlGpvEC4RDK74fAGEyEIgsDl+lYkwifLPb2H0Dd9tLY=; b=Kd7Om4Oa+A9/E8PjaCutn6wT+WOtdsSjDE0oWlb2Obp35kmViVREFCCbCsBqlyCse3zHV8q0TnIwtWmOG0on6qN6AKXnbytUympUdXtLRfCArB5TsKPdlPb2O3QyVuugcCzo3hhMNAg/EujRG6aZq+q6zMOdi4m6hrqUwEpQaqw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1777665891449553.2902722086726; Fri, 1 May 2026 13:04:51 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wIu68-0001W2-0Y; Fri, 01 May 2026 16:04:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wIu5w-0001K4-E1; Fri, 01 May 2026 16:04:21 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wIu5s-0001VB-Qq; Fri, 01 May 2026 16:04:16 -0400 Received: from pps.filterd (m0353729.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 641F1BxZ3060766; Fri, 1 May 2026 20:04:07 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 4drn9rp5uj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 01 May 2026 20:04:07 +0000 (GMT) Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.18.1.7/8.18.1.7) with ESMTP id 641Jrs3G000757; Fri, 1 May 2026 20:04:06 GMT Received: from smtprelay04.dal12v.mail.ibm.com ([172.16.1.6]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4ds9ehrucg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 01 May 2026 20:04:06 +0000 (GMT) Received: from smtpav06.dal12v.mail.ibm.com (smtpav06.dal12v.mail.ibm.com [10.241.53.105]) by smtprelay04.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 641K438Z31916704 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 1 May 2026 20:04:03 GMT Received: from smtpav06.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4B23D58043; Fri, 1 May 2026 20:04:03 +0000 (GMT) Received: from smtpav06.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2DA7C58055; Fri, 1 May 2026 20:04:02 +0000 (GMT) Received: from Mac.ibm.com (unknown [9.61.247.25]) by smtpav06.dal12v.mail.ibm.com (Postfix) with ESMTP; Fri, 1 May 2026 20:04:02 +0000 (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=KlGpvEC4RDK74fAGE yEIgsDl+lYkwifLPb2H0Dd9tLY=; b=I/llce4RLFMSnf0nfRinO6R9njgkgUNL2 TXBv2EgTdHRBs8Qk08UyfeI7t5qUmS1Zxp4POLCZx7O4EGQ2poUUVEeymxhkm4fB 9wbSQ2J5QJkkWWhYtAGRrYCB3uOjl786CZ/LOLiCbyTw4sfvVqAnezyAz1jLmIuM IgyGViyjzjMLcPtEOCOlDaRy+jCCjZ14Tfg9LecHUYKcXMTZEsf6/tplj0NredSy YoYeueW/+DC0hOR44OF4Ro76sh3FNTGc7ulYEeqmQ64c5b5E1f1dSV480rJlOoJJ 28tD3Rri+RJ4W7oQnZ46f8mKX40dUoM2JtDvHmO8stL44xX3xpOOQ== From: Omar Elghoul To: qemu-devel@nongnu.org, qemu-s390x@nongnu.org Cc: oelghoul@linux.ibm.com, mjrosato@linux.ibm.com, alifm@linux.ibm.com, farman@linux.ibm.com, pasic@linux.ibm.com, borntraeger@linux.ibm.com, richard.henderson@linaro.org, iii@linux.ibm.com, david@kernel.org, cohuck@redhat.com, mst@redhat.com, pbonzini@redhat.com, clg@redhat.com Subject: [RFC PATCH v1 4/5] hw/s390x: Internal support for FMB passthrough Date: Fri, 1 May 2026 16:00:25 -0400 Message-ID: <20260501200026.22784-5-oelghoul@linux.ibm.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260501200026.22784-1-oelghoul@linux.ibm.com> References: <20260501200026.22784-1-oelghoul@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: QCgjdcwJE6JZFuXGzB2h9KzUVfNCWFze X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNTAxMDE5NSBTYWx0ZWRfX9RN79WnRGezD 3DERqgp+H6BOq3s/oTU+IFuWxyZ0c1kZ5fGmtEpW5DB/qIU7ajU0lRS6tq4/EkjZ3MBEhCxiwPv 2VwiCSlPScLWm64IJ18mgghxpgA8t+W5MMk0Yp6LL7JOch+tAtBQu/yd/ApYT7MI4G+MeXOn9ki M6Z3y5yTQ5bHuvqVBmSiTq+m7VJGYl9XVI/S723kmZ7gzMT6os3y5N2ghxzoke8CTJuEg+D/riN 372AYHOm4sO2A+JJ+jpBnA4aHkf3LWLj1l/GKVQdtg289XfsbrZim70jmqqx8O5QJC2/B0rNzrx Djku8wWTvAgwIlEZ/ANwIgoSsdmtrw0GZeTTNsHgzKFXyBHolNoJB2Bh3Ja+nCvDKmz2J5s5Ba+ zqQyo4qVe+W0bKoYPWuXEcxi6T/GvuvMSLQsnZKYtvvD6Q9gPSoHZUx+iG8gT4qwGjeCZG6xGtv 1Ee1G3b6ewrKo4ew+Sg== X-Authority-Analysis: v=2.4 cv=Kc7idwYD c=1 sm=1 tr=0 ts=69f50737 cx=c_pps a=3Bg1Hr4SwmMryq2xdFQyZA==:117 a=3Bg1Hr4SwmMryq2xdFQyZA==:17 a=NGcC8JguVDcA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=uAbxVGIbfxUO_5tXvNgY:22 a=VnNF1IyMAAAA:8 a=47rX_IKMaOKvU8u4J60A:9 X-Proofpoint-ORIG-GUID: QCgjdcwJE6JZFuXGzB2h9KzUVfNCWFze 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-05-01_05,2026-04-30_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 phishscore=0 bulkscore=0 adultscore=0 spamscore=0 malwarescore=0 impostorscore=0 priorityscore=1501 lowpriorityscore=0 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2604200000 definitions=main-2605010195 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=148.163.156.1; envelope-from=oelghoul@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ibm.com) X-ZM-MESSAGEID: 1777665892021158500 Content-Type: text/plain; charset="utf-8" Detect the FMB passthrough at runtime by probing for the VFIO FMB device feature and setting a flag indicating its presence. If present, during an FMB update cycle, read the device feature and add the VFIO-provided counters to QEMU's intercepted statistics, to account for operations that may be run without interpretation. If the device feature is not found, gracefully and silently fall back to QEMU's pre-existing intercepted FMB implementation. Introduce helper functions to allow enabling or disabling the FMB of the host device. These functions will allow QEMU to cascade FMB state and guarantee that the counters restart from zero when the guest expects them to after a new FMB (re-)enablement. Finally, remove the reduced aperture size for PCI ISM devices. This is necessary due to the kernel working around a firmware bug and incrementing the DMA limit by one full page when the PFT is reported correctly. Signed-off-by: Omar Elghoul --- hw/s390x/s390-pci-bus.c | 2 + hw/s390x/s390-pci-inst.c | 7 ++ hw/s390x/s390-pci-vfio-stubs.c | 16 ++++ hw/s390x/s390-pci-vfio.c | 128 ++++++++++++++++++++++++++----- include/hw/s390x/s390-pci-bus.h | 27 ++++++- include/hw/s390x/s390-pci-vfio.h | 4 + 6 files changed, 165 insertions(+), 19 deletions(-) diff --git a/hw/s390x/s390-pci-bus.c b/hw/s390x/s390-pci-bus.c index 7eee1efeb7..88540a9eb6 100644 --- a/hw/s390x/s390-pci-bus.c +++ b/hw/s390x/s390-pci-bus.c @@ -1185,6 +1185,8 @@ static void s390_pcihost_plug(HotplugHandler *hotplug= _dev, DeviceState *dev, pbdev->shutdown_notifier.notify =3D s390_pci_shutdown_noti= fier; qemu_register_shutdown_notifier(&pbdev->shutdown_notifier); } + /* Detect VFIO FMB passthrough */ + s390_pci_get_fmb_info(pbdev); } else { pbdev->fh |=3D FH_SHM_EMUL; /* Always intercept emulated devices */ diff --git a/hw/s390x/s390-pci-inst.c b/hw/s390x/s390-pci-inst.c index 10066ca618..b22144751e 100644 --- a/hw/s390x/s390-pci-inst.c +++ b/hw/s390x/s390-pci-inst.c @@ -1313,9 +1313,16 @@ int mpcifc_service_call(S390CPU *cpu, uint8_t r1, ui= nt64_t fiba, uint8_t ar, if (!fmb_addr) { /* Stop updating FMB. */ fmb_timer_free(pbdev); + if (pbdev->has_vfio_fmb) { + s390_pci_disable_vfio_fmb(pbdev); + } break; } =20 + if (pbdev->has_vfio_fmb) { + s390_pci_enable_vfio_fmb(pbdev); + } + if (!pbdev->fmb_timer) { pbdev->fmb_timer =3D timer_new_ms(QEMU_CLOCK_VIRTUAL, fmb_update, pbdev); diff --git a/hw/s390x/s390-pci-vfio-stubs.c b/hw/s390x/s390-pci-vfio-stubs.c index d9882b7aad..774a6615c6 100644 --- a/hw/s390x/s390-pci-vfio-stubs.c +++ b/hw/s390x/s390-pci-vfio-stubs.c @@ -30,3 +30,19 @@ bool s390_pci_get_host_fh(S390PCIBusDevice *pbdev, uint3= 2_t *fh) void s390_pci_get_clp_info(S390PCIBusDevice *pbdev) { } + +void s390_pci_get_fmb_info(S390PCIBusDevice *pbdev) +{ +} + +void s390_pci_update_vfio_fmb(S390PCIBusDevice *pbdev) +{ +} + +void s390_pci_disable_vfio_fmb(S390PCIBusDevice *pbdev) +{ +} + +void s390_pci_enable_vfio_fmb(S390PCIBusDevice *pbdev) +{ +} diff --git a/hw/s390x/s390-pci-vfio.c b/hw/s390x/s390-pci-vfio.c index 7c754b656d..d749c8c80a 100644 --- a/hw/s390x/s390-pci-vfio.c +++ b/hw/s390x/s390-pci-vfio.c @@ -10,6 +10,7 @@ */ =20 #include "qemu/osdep.h" +#include "qemu/error-report.h" =20 #include #include @@ -110,7 +111,6 @@ static void s390_pci_read_base(S390PCIBusDevice *pbdev, struct vfio_info_cap_header *hdr; struct vfio_device_info_cap_zpci_base *cap; VFIOPCIDevice *vpci =3D VFIO_PCI_DEVICE(pbdev->pdev); - uint64_t vfio_size; =20 hdr =3D vfio_get_device_info_cap(info, VFIO_DEVICE_INFO_CAP_ZPCI_BASE); =20 @@ -140,22 +140,6 @@ static void s390_pci_read_base(S390PCIBusDevice *pbdev, if (pbdev->pft =3D=3D ZPCI_PFT_ISM) { pbdev->rtr_avail =3D false; } - - /* - * If appropriate, reduce the size of the supported DMA aperture repor= ted - * to the guest based upon the vfio DMA limit. This is applicable for - * devices that are guaranteed to not use relaxed translation. If the - * device is capable of relaxed translation then we must advertise the - * full aperture. In this case, if translation is used then we will - * rely on the vfio DMA limit counting and use RPCIT CC1 / status 16 - * to request that the guest free DMA mappings as necessary. - */ - if (!pbdev->rtr_avail) { - vfio_size =3D pbdev->iommu->max_dma_limit << qemu_target_page_bits= (); - if (vfio_size > 0 && vfio_size < cap->end_dma - cap->start_dma + 1= ) { - pbdev->zpci_fn.edma =3D cap->start_dma + vfio_size - 1; - } - } } =20 static bool get_host_fh(S390PCIBusDevice *pbdev, struct vfio_device_info *= info, @@ -248,7 +232,7 @@ static void s390_pci_read_group(S390PCIBusDevice *pbdev, } resgrp->dasm =3D cap->dasm; resgrp->msia =3D cap->msi_addr; - resgrp->mui =3D cap->mui; + resgrp->mui =3D cap->mui > DEFAULT_MUI ? cap->mui : DEFAULT_MUI; resgrp->i =3D cap->noi; if (pbdev->interp && hdr->version >=3D 2) { resgrp->maxstbl =3D cap->imaxstbl; @@ -370,3 +354,111 @@ void s390_pci_get_clp_info(S390PCIBusDevice *pbdev) s390_pci_read_util(pbdev, info); s390_pci_read_pfip(pbdev, info); } + +void s390_pci_get_fmb_info(S390PCIBusDevice *pbdev) +{ + VFIOPCIDevice *vpdev =3D VFIO_PCI_DEVICE(pbdev->pdev); + int fd =3D vpdev->vbasedev.fd; + int ret; + struct vfio_device_feature probe =3D { + .argsz =3D sizeof(probe), + .flags =3D VFIO_DEVICE_FEATURE_PROBE | VFIO_DEVICE_FEATURE_ZPCI_FMB + }; + + ret =3D ioctl(fd, VFIO_DEVICE_FEATURE, &probe); + pbdev->has_vfio_fmb =3D !ret; +} + +static void s390_pci_set_vfio_fmb(S390PCIBusDevice *pbdev, int enabled) +{ + VFIOPCIDevice *vpdev =3D VFIO_PCI_DEVICE(pbdev->pdev); + size_t size =3D sizeof(struct vfio_device_feature_zpci_fmb) + + sizeof(struct vfio_device_feature); + g_autofree struct vfio_device_feature *set =3D g_malloc(size); + struct vfio_device_feature_zpci_fmb *set_fmb; + + set->argsz =3D size; + set->flags =3D VFIO_DEVICE_FEATURE_SET | VFIO_DEVICE_FEATURE_ZPCI_FMB; + set_fmb =3D (struct vfio_device_feature_zpci_fmb *) set->data; + if (enabled) { + set_fmb->flags |=3D VFIO_DEVICE_FEATURE_ZPCI_FMB_FLAGS_ENABLED; + } else { + set_fmb->flags &=3D ~VFIO_DEVICE_FEATURE_ZPCI_FMB_FLAGS_ENABLED; + } + ioctl(vpdev->vbasedev.fd, VFIO_DEVICE_FEATURE, set); +} + +void s390_pci_enable_vfio_fmb(S390PCIBusDevice *pbdev) +{ + s390_pci_set_vfio_fmb(pbdev, 1); +} + +void s390_pci_disable_vfio_fmb(S390PCIBusDevice *pbdev) +{ + s390_pci_set_vfio_fmb(pbdev, 0); +} + +void s390_pci_update_vfio_fmb(S390PCIBusDevice *pbdev) +{ + VFIOPCIDevice *vpdev =3D VFIO_PCI_DEVICE(pbdev->pdev); + size_t size =3D sizeof(struct vfio_device_feature_zpci_fmb) + + sizeof(struct vfio_device_feature); + g_autofree struct vfio_device_feature *get =3D g_malloc(size); + struct vfio_device_feature_zpci_fmb *get_fmb; + ZpciFmb fmb; + int ret; + MemTxResult memtx_ret; + + get->argsz =3D size; + get->flags =3D VFIO_DEVICE_FEATURE_GET | VFIO_DEVICE_FEATURE_ZPCI_FMB; + ret =3D ioctl(vpdev->vbasedev.fd, VFIO_DEVICE_FEATURE, get); + if (ret < 0) { + return; + } + + get_fmb =3D (struct vfio_device_feature_zpci_fmb *) get->data; + if (!get_fmb->flags & VFIO_DEVICE_FEATURE_ZPCI_FMB_FLAGS_ENABLED) { + error_report_once("s390-pci-vfio: FMB is disabled on the host devi= ce."); + return; + } + fmb.format =3D (get_fmb->format << 24) | get_fmb->fmt_ind; + fmb.sample =3D get_fmb->samples; + fmb.last_update =3D get_fmb->last_update; + fmb.counter[ZPCI_FMB_CNT_LD] =3D get_fmb->ld_ops; + fmb.counter[ZPCI_FMB_CNT_ST] =3D get_fmb->st_ops; + fmb.counter[ZPCI_FMB_CNT_STB] =3D get_fmb->stb_ops; + fmb.counter[ZPCI_FMB_CNT_RPCIT] =3D get_fmb->rpcit_ops; + + switch (get_fmb->format) { + case 0: + fmb.fmt0.dma_rbytes =3D get_fmb->fmt0.dma_rbytes; + fmb.fmt0.dma_wbytes =3D get_fmb->fmt0.dma_wbytes; + break; + case 1: + fmb.fmt1.rx_bytes =3D get_fmb->fmt1.rx_bytes; + fmb.fmt1.rx_packets =3D get_fmb->fmt1.rx_packets; + fmb.fmt1.tx_bytes =3D get_fmb->fmt1.tx_bytes; + fmb.fmt1.tx_packets =3D get_fmb->fmt1.tx_packets; + break; + case 2: + fmb.fmt2.consumed_work_units =3D get_fmb->fmt2.consumed_work_units; + fmb.fmt2.max_work_units =3D get_fmb->fmt2.max_work_units; + break; + case 3: + fmb.fmt3.tx_bytes =3D get_fmb->fmt3.tx_bytes; + break; + } + + for (int i =3D 0; i < ZPCI_FMB_CNT_MAX; i++) { + fmb.counter[i] +=3D pbdev->fmb.counter[i]; + } + + for (int i =3D 0; i < pbdev->zpci_fn.fmbl >> 2; i++) { + address_space_stl_be(&address_space_memory, pbdev->fmb_addr + (i <= < 2), + ((uint32_t *) &fmb)[i], MEMTXATTRS_UNSPECIFIED, &memtx_ret); + + if (memtx_ret !=3D MEMTX_OK) { + break; + } + } +} diff --git a/include/hw/s390x/s390-pci-bus.h b/include/hw/s390x/s390-pci-bu= s.h index feaf6d4863..050e7fda99 100644 --- a/include/hw/s390x/s390-pci-bus.h +++ b/include/hw/s390x/s390-pci-bus.h @@ -302,6 +302,22 @@ typedef struct ZpciFmbFmt0 { uint64_t dma_wbytes; } ZpciFmbFmt0; =20 +typedef struct ZpciFmbFmt1 { + uint64_t rx_bytes; + uint64_t rx_packets; + uint64_t tx_bytes; + uint64_t tx_packets; +} ZpciFmbFmt1; + +typedef struct ZpciFmbFmt2 { + uint64_t consumed_work_units; + uint64_t max_work_units; +} ZpciFmbFmt2; + +typedef struct ZpciFmbFmt3 { + uint64_t tx_bytes; +} ZpciFmbFmt3; + #define ZPCI_FMB_CNT_LD 0 #define ZPCI_FMB_CNT_ST 1 #define ZPCI_FMB_CNT_STB 2 @@ -309,13 +325,21 @@ typedef struct ZpciFmbFmt0 { #define ZPCI_FMB_CNT_MAX 4 =20 #define ZPCI_FMB_DEFAULT_FORMAT 0 +#define ZPCI_FMB_COMMON_SIZE 48 +#define ZPCI_FMB_FORMAT(f) ((f >> 24) & 0xFF) +#define ZPCI_FMB_DMA_COUNTER_VALID (1 << 23) =20 typedef struct ZpciFmb { uint32_t format; uint32_t sample; uint64_t last_update; uint64_t counter[ZPCI_FMB_CNT_MAX]; - ZpciFmbFmt0 fmt0; + union { + ZpciFmbFmt0 fmt0; + ZpciFmbFmt1 fmt1; + ZpciFmbFmt2 fmt2; + ZpciFmbFmt3 fmt3; + }; } ZpciFmb; QEMU_BUILD_BUG_MSG(offsetof(ZpciFmb, fmt0) !=3D 48, "padding in ZpciFmb"); =20 @@ -364,6 +388,7 @@ struct S390PCIBusDevice { bool forwarding_assist; bool aif; bool rtr_avail; + bool has_vfio_fmb; QTAILQ_ENTRY(S390PCIBusDevice) link; }; =20 diff --git a/include/hw/s390x/s390-pci-vfio.h b/include/hw/s390x/s390-pci-v= fio.h index f7d6149daf..4a19747d7c 100644 --- a/include/hw/s390x/s390-pci-vfio.h +++ b/include/hw/s390x/s390-pci-vfio.h @@ -20,5 +20,9 @@ S390PCIDMACount *s390_pci_start_dma_count(S390pciState *s, void s390_pci_end_dma_count(S390pciState *s, S390PCIDMACount *cnt); bool s390_pci_get_host_fh(S390PCIBusDevice *pbdev, uint32_t *fh); void s390_pci_get_clp_info(S390PCIBusDevice *pbdev); +void s390_pci_get_fmb_info(S390PCIBusDevice *pbdev); +void s390_pci_update_vfio_fmb(S390PCIBusDevice *pbdev); +void s390_pci_disable_vfio_fmb(S390PCIBusDevice *pbdev); +void s390_pci_enable_vfio_fmb(S390PCIBusDevice *pbdev); =20 #endif --=20 2.52.0 From nobody Sat May 30 18:34:29 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1777665888; cv=none; d=zohomail.com; s=zohoarc; b=g+uybC5XIez8sVstXSvgExwINrBP/UtYzNrfrsoKHK6vQFPtB1CcvzbLyE6AhtOPUJEYJVx6d6H6Y2uXTeo7toPM0KrwKQc7r+C/gddgg8Mz5dBGGAbwriD9mLjFvIfKPb7KL4EJhAecNL4cVVupSYCo9Q7V5MWcIG96NYxWs0E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1777665888; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=1Mthas14dUCzArtmPBHd0kOVwbr1CPycXWbV3rNFn9E=; b=iMaIzmZqvj1TNaNB8lfim3KkkngkEcQpbK3XEoGYew22XrEt8fG6uuMRZnsEUI1WyWGzsGvwKGrRQRS3lSr6nVWefxzOSzNtyI2rNwhmVFl1tShX2M9qiLs//dR6749rAvAKSUB5Dko61njesje21ENvjtrfcJQQ03zcI1I2iZo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1777665888135415.8511497261719; Fri, 1 May 2026 13:04:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wIu6E-0001r3-Fh; Fri, 01 May 2026 16:04:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wIu6B-0001k6-FS; Fri, 01 May 2026 16:04:31 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wIu69-0001ei-NF; Fri, 01 May 2026 16:04:31 -0400 Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 641EjivY2840313; Fri, 1 May 2026 20:04:26 GMT 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 4drn8vv63q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 01 May 2026 20:04:26 +0000 (GMT) Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.18.1.7/8.18.1.7) with ESMTP id 641JcjSM023096; Fri, 1 May 2026 20:04:25 GMT Received: from smtprelay06.wdc07v.mail.ibm.com ([172.16.1.73]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 4dsamyrqrd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 01 May 2026 20:04:25 +0000 (GMT) Received: from smtpav06.dal12v.mail.ibm.com (smtpav06.dal12v.mail.ibm.com [10.241.53.105]) by smtprelay06.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 641K4MFf32244260 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 1 May 2026 20:04:22 GMT Received: from smtpav06.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5714B58043; Fri, 1 May 2026 20:04:22 +0000 (GMT) Received: from smtpav06.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 399CA58059; Fri, 1 May 2026 20:04:21 +0000 (GMT) Received: from Mac.ibm.com (unknown [9.61.247.25]) by smtpav06.dal12v.mail.ibm.com (Postfix) with ESMTP; Fri, 1 May 2026 20:04:21 +0000 (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=1Mthas14dUCzArtmP BHd0kOVwbr1CPycXWbV3rNFn9E=; b=NcmrTnxXIgN0jgRp5cZSBR3nZyFXHcebN Mjw/N3W6mr+NbZOaeH8giEGDuHC1s41DGeTRxC8vcBorX49rZ1IYLvKuqJ+MD8Af sSYwyUDn+uIrf3wCUvpPFWRbnLnaak1tMYVijm0I7HTSA38AZX7L9/rVUZ66AXuI lI8D5pZprW8wq9aUCbTCypwWCnrBrOM4jPcZiMocjXFrkSAOKp7k7fy/LoOtEV6e /zkpW8oWcicGqCzOikdWz+COQ697wNr68no6w7+r6NvL07mURgmySb1N7wsLUu0J L9wF5dizI/CIJKYnCjifgmB2v6b/5Pkh++N4KsTjVGQfmcC2ofAzw== From: Omar Elghoul To: qemu-devel@nongnu.org, qemu-s390x@nongnu.org Cc: oelghoul@linux.ibm.com, mjrosato@linux.ibm.com, alifm@linux.ibm.com, farman@linux.ibm.com, pasic@linux.ibm.com, borntraeger@linux.ibm.com, richard.henderson@linaro.org, iii@linux.ibm.com, david@kernel.org, cohuck@redhat.com, mst@redhat.com, pbonzini@redhat.com, clg@redhat.com Subject: [RFC PATCH v1 5/5] hw/s390x: Report FMB passthrough and/or FMB DMA counters to the guest Date: Fri, 1 May 2026 16:00:26 -0400 Message-ID: <20260501200026.22784-6-oelghoul@linux.ibm.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260501200026.22784-1-oelghoul@linux.ibm.com> References: <20260501200026.22784-1-oelghoul@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Authority-Analysis: v=2.4 cv=CIIamxrD c=1 sm=1 tr=0 ts=69f5074a cx=c_pps a=aDMHemPKRhS1OARIsFnwRA==:117 a=aDMHemPKRhS1OARIsFnwRA==:17 a=NGcC8JguVDcA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=RzCfie-kr_QcCd8fBx8p:22 a=VnNF1IyMAAAA:8 a=i_3ZhW82j95uuV7xZWQA:9 X-Proofpoint-ORIG-GUID: X75OfkJzypko5NRi3CMG-1B3je4RkAGK X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNTAxMDE5NSBTYWx0ZWRfXz4H/9MW1LOHI HnII2MpVDCK8yl6GGUuwxFVBEh/qDKLD4vhlEsnUGJtgehJ7LQ5LYipm1+Ir3xUBCetxmgR7V8F e4DbDVEuY0jpcPlwOrtHjRYhHj9252oREg2cdsq3fpbu/nrMlH1064P0zfKRzQBHPyDfCiLfKTs 3AJ2vH2zE24zimcAqMdC2nWEcsBD1yu0sYpYTJCPACAnD4Go1OhrOiir4TDFRiWSB8g5bexfSkl VpK521WaXOQMbB8ccKyZBhKaMiAE5SshVfL9QrdQJSBtQ5B2HsK4wDnb2wVBG0xnROmf94/tJm9 Otzrh8D4qfuFP/uYJBRt7mwabkJGq/bJ1Ar1VEAQYfByJ5b4KGFgLtvrOqgG8dTf/sGpuLYAwH2 cmswwdLzeLNCZXA92E/zS6VS4cW8cADNneTc0gbe/TdRz92uNIAXQI+Hhd4mZF+3aojIkZBc5o2 zpDmvtc8zj5/spejWNA== X-Proofpoint-GUID: X75OfkJzypko5NRi3CMG-1B3je4RkAGK 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-05-01_05,2026-04-30_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 phishscore=0 malwarescore=0 suspectscore=0 adultscore=0 impostorscore=0 lowpriorityscore=0 clxscore=1015 bulkscore=0 priorityscore=1501 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2604200000 definitions=main-2605010195 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=148.163.158.5; envelope-from=oelghoul@linux.ibm.com; helo=mx0b-001b2d01.pphosted.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ibm.com) X-ZM-MESSAGEID: 1777665889923158501 Content-Type: text/plain; charset="utf-8" Report the correct FMB length to the guest and report a more accurate snapshot of the FMB using the VFIO feature in the PCI passthrough case or the emulated counters in the emulated case. To preserve the behavior of earlier QEMU versions, do not report the PFT or the FMB length to the guest in the case where FMB passthrough is unavailable. Signed-off-by: Omar Elghoul --- hw/s390x/s390-pci-inst.c | 58 +++++++++++++++++++++++++++++++++++++--- hw/s390x/s390-pci-vfio.c | 5 ++-- 2 files changed, 57 insertions(+), 6 deletions(-) diff --git a/hw/s390x/s390-pci-inst.c b/hw/s390x/s390-pci-inst.c index b22144751e..767c5b5cef 100644 --- a/hw/s390x/s390-pci-inst.c +++ b/hw/s390x/s390-pci-inst.c @@ -20,6 +20,7 @@ #include "system/hw_accel.h" #include "hw/core/boards.h" #include "hw/pci/pci_device.h" +#include "hw/vfio/pci.h" #include "hw/s390x/s390-pci-inst.h" #include "hw/s390x/s390-pci-bus.h" #include "hw/s390x/s390-pci-kvm.h" @@ -296,8 +297,13 @@ int clp_service_call(S390CPU *cpu, uint8_t r2, uintptr= _t ra) stw_be_p(&resquery->vfn, pbdev->zpci_fn.vfn); resquery->flags =3D pbdev->zpci_fn.flags; resquery->pfgid =3D pbdev->zpci_fn.pfgid; - resquery->pft =3D pbdev->zpci_fn.pft; - resquery->fmbl =3D pbdev->zpci_fn.fmbl; + if (pbdev->has_vfio_fmb) { + resquery->pft =3D pbdev->zpci_fn.pft; + resquery->fmbl =3D pbdev->zpci_fn.fmbl >> 2; + } else { + resquery->pft =3D 0; + resquery->fmbl =3D 0; + } stl_be_p(&resquery->fid, pbdev->zpci_fn.fid); stl_be_p(&resquery->uid, pbdev->zpci_fn.uid); memcpy(resquery->pfip, pbdev->zpci_fn.pfip, CLP_PFIP_NR_SEGMENTS); @@ -1096,6 +1102,9 @@ static void fmb_update(void *opaque) { S390PCIBusDevice *pbdev =3D opaque; int64_t t =3D qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL); + VFIOPCIDevice *vpdev; + PCIDevice *pci =3D pbdev->pdev; + uint8_t format =3D ZPCI_FMB_FORMAT(pbdev->fmb.format); int i; =20 /* Update U bit */ @@ -1107,6 +1116,48 @@ static void fmb_update(void *opaque) return; } =20 + /* Check for VFIO device */ + vpdev =3D (VFIOPCIDevice *) object_dynamic_cast(OBJECT(pbdev->pdev), + TYPE_VFIO_PCI_DEVICE); + + if (vpdev && pbdev->has_vfio_fmb) { + s390_pci_update_vfio_fmb(pbdev); + goto update_timer; + } + + /* Update FMB format-specific counters */ + switch (format) { + case 0: + if (pci->dma_rbytes || pci->dma_wbytes) { + pbdev->fmb.fmt0.dma_rbytes =3D pci->dma_rbytes; + pbdev->fmb.fmt0.dma_wbytes =3D pci->dma_wbytes; + pbdev->fmb.format |=3D ZPCI_FMB_DMA_COUNTER_VALID; + } + + if (fmb_do_update(pbdev, + offsetof(ZpciFmbFmt0, dma_rbytes) + offsetof(ZpciFmb, fmt0), + pbdev->fmb.fmt0.dma_rbytes, + sizeof(pbdev->fmb.fmt0.dma_rbytes))) { + return; + } + + if (fmb_do_update(pbdev, + offsetof(ZpciFmbFmt0, dma_wbytes) + offsetof(ZpciFmb, fmt0), + pbdev->fmb.fmt0.dma_wbytes, + sizeof(pbdev->fmb.fmt0.dma_wbytes))) { + return; + } + default: + break; + } + + /* Update format and DMA validity bit */ + if (fmb_do_update(pbdev, offsetof(ZpciFmb, format), + pbdev->fmb.format, + sizeof(pbdev->fmb.format))) { + return; + } + /* Update FMB sample count */ if (fmb_do_update(pbdev, offsetof(ZpciFmb, sample), pbdev->fmb.sample++, @@ -1114,7 +1165,7 @@ static void fmb_update(void *opaque) return; } =20 - /* Update FMB counters */ + /* Update FMB generic counters */ for (i =3D 0; i < ZPCI_FMB_CNT_MAX; i++) { if (fmb_do_update(pbdev, offsetof(ZpciFmb, counter[i]), pbdev->fmb.counter[i], @@ -1123,6 +1174,7 @@ static void fmb_update(void *opaque) } } =20 +update_timer: /* Clear U bit and update the time */ pbdev->fmb.last_update =3D time2tod(qemu_clock_get_ns(QEMU_CLOCK_VIRTU= AL)); pbdev->fmb.last_update *=3D 2; diff --git a/hw/s390x/s390-pci-vfio.c b/hw/s390x/s390-pci-vfio.c index d749c8c80a..da630b23be 100644 --- a/hw/s390x/s390-pci-vfio.c +++ b/hw/s390x/s390-pci-vfio.c @@ -127,9 +127,8 @@ static void s390_pci_read_base(S390PCIBusDevice *pbdev, pbdev->zpci_fn.pchid =3D cap->pchid; pbdev->zpci_fn.vfn =3D cap->vfn; pbdev->zpci_fn.pfgid =3D cap->gid; - /* The following values remain 0 until we support other FMB formats */ - pbdev->zpci_fn.fmbl =3D 0; - pbdev->zpci_fn.pft =3D 0; + pbdev->zpci_fn.fmbl =3D cap->fmb_length; + pbdev->zpci_fn.pft =3D cap->pft; /* Store function type separately for type-specific behavior */ pbdev->pft =3D cap->pft; =20 --=20 2.52.0