Received: from canpmsgout09.his.huawei.com (canpmsgout09.his.huawei.com [113.46.200.224]) (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 6B07231AAB8; Fri, 8 May 2026 06:41:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.224 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778222480; cv=none; b=bctzgwdXR+LGvq+bLhp/eaSjKpFDGwEg46m31gpg/Yj5wI3sBg0IY4TrkvAACqnO9vW/a9dv4Vg7ccjCn9Vl93GlUzbjJ+/rEsSAkQAXjOE2EXlE1q7MS6iqpqKksXckHhHfwiE3snuz7ho0cVgH49N6/uhpYs2IsM+aOd/3he0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778222480; c=relaxed/simple; bh=xGRZ4OmQ0KuvcjKHeUJmCWEEs9vMlK4loRI41L5P5g4=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=Xbk2K4E1J/bwejBqIRQM12jcDmEh023oA3vltVuKPc0qupkJe+hgtWc1PzTjFMiw0vnal183dBCw2lQKOz8tWrwBDSYKyexwRvSvxhA5gxLHTs/NH/6b3Q1o7o5jLxAec3MLeaWvS4kuJxcTRPAWXU7wPAx+z/G2193WOMnJ4J0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=ArCIBStd; arc=none smtp.client-ip=113.46.200.224 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="ArCIBStd" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=nyHR0B63wyTaTh8o4kUl/34N5xi2G3wRGQ5CBNhUZEc=; b=ArCIBStduRjJXjzwZS0UshBaz55ml9Whqk9SIwPvpQ9w10TUQQKomUmfUzyYHaf0Q5LWEYAqf E3dwpWpLQg2vKLKeTt41a62QV8EDeXSuzwBD6wTMuMaLIz45GkIqkYsirbQlNWcLbBGWnlc3yAZ 9y8pmyJ5rP4Uwe5VWc3yB5U= Received: from mail.maildlp.com (unknown [172.19.163.15]) by canpmsgout09.his.huawei.com (SkyGuard) with ESMTPS id 4gBfT44tJpz1cyPS; Fri, 8 May 2026 14:33:28 +0800 (CST) Received: from kwepemk500009.china.huawei.com (unknown [7.202.194.94]) by mail.maildlp.com (Postfix) with ESMTPS id 58AC240539; Fri, 8 May 2026 14:41:01 +0800 (CST) Received: from localhost.localdomain (10.50.163.32) by kwepemk500009.china.huawei.com (7.202.194.94) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 8 May 2026 14:41:00 +0800 From: Chengwen Feng To: , CC: , , , , , , , Subject: [PATCH v8 0/7] vfio/pci: Add PCIe TPH support Date: Fri, 8 May 2026 14:40:46 +0800 Message-ID: <20260508064053.37529-1-fengchengwen@huawei.com> X-Mailer: git-send-email 2.17.1 Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain X-ClientProxiedBy: kwepems100002.china.huawei.com (7.221.188.206) To kwepemk500009.china.huawei.com (7.202.194.94) This patchset enables userspace control over PCIe TPH steering tags, motivated by the following considerations: 1. Why userspace needs the capability to control steering tags: When PCIe devices are fully owned by userspace workloads such as DPDK and SPDK, only userspace has full knowledge of core binding policies and traffic distribution strategies. Without this series, userspace cannot enable TPH or configure steering tags, leaving built-in PCIe performance optimizations unused in high-throughput polling I/O scenarios. 2. Why this interface must be implemented in VFIO: VFIO is the standard, secure community solution for granting full PCIe device ownership to userspace. Existing kernel TPH interfaces are designed purely for in-kernel drivers. For user-owned devices, VFIO provides the only isolated and correct path to expose per-device TPH management. TPH supports both IV and DS modes. Since device-specific (DS) TPH mode introduces cross-VM isolation risks such as untrusted guests programming arbitrary steering tags to impact other domains, so a new module parameter `enable_unsafe_tph_ds_mode` is added. It defaults to off, and blocks all unsafe DS-mode TPH operations when disabled. To restrict abuse of SET_ST and prevent arbitrary steering tag programming from userspace, the interface only accepts explicit CPU ID, memory type and index inputs. The kernel resolves the corresponding steering tag internally before programming, limiting userspace to controlled, index-based configuration. Based on earlier RFC work by Wathsala Vithanage v8: - Make GET_ST op could retrieve CPU's steer tags for DS mode. note: the original impl could for DS mode + No ST Table, the backgroud is that we found one netcard defined ST table with DS mode, but also need to config set ST by device-specific way. - Support verify index when SET_ST. - Fix Sashiko review comments: 1. Add fix pcie_tph_get_st_table_size for msi-x table commit 2. Add argsz validation for GET/SET_ST copy st 3. Verify mem-type when SET_ST with cpu=U32_MAX v7: - Address Bjorn's comment on [1/6] commit. - Don't report ds mode defaultly (enable_unsafe_tph_ds_mode=0) - Fix Sashiko review comments: 1. pcie_tph_get_st_table_loc()'s stub return 0 2. Tph ioctl argsz validation wrong use offsetofend 3. Disable TPH when device was taken-over/close to/by userspace 4. Serialize all TPH operations under vdev->igate to prevent hardware control and bitfield races. 5. Check unused ioctl field to be zero. v6: - Address Alex's comment on [1/6] commit. - Fix Sashiko review comments: Add tph_cap validation for pcie_tph_get_st_modes/st_table_loc. Add argsz validation for each op cmd. Move disable tph from ioctl-reset to register. Verify reserved field for get/set ST op. Fix ABI mismatch due to pointer arithmetic of get/st ST op. Chengwen Feng (7): PCI/TPH: Fix pcie_tph_get_st_table_loc() field extraction PCI/TPH: Export pcie_tph_get_st_modes() for external use PCI/TPH: Fix pcie_tph_get_st_table_size() for MSI-X table location vfio/pci: Add PCIe TPH interface with capability query vfio/pci: Add PCIe TPH enable/disable support vfio/pci: Add PCIe TPH GET_ST interface vfio/pci: Add PCIe TPH SET_ST interface drivers/pci/tph.c | 31 ++-- drivers/vfio/pci/vfio_pci.c | 13 +- drivers/vfio/pci/vfio_pci_core.c | 270 ++++++++++++++++++++++++++++++- include/linux/pci-tph.h | 7 + include/linux/vfio_pci_core.h | 3 +- include/uapi/linux/vfio.h | 133 +++++++++++++++ 6 files changed, 444 insertions(+), 13 deletions(-) -- 2.17.1