Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

psp: add stats from psp spec to driver facing api

Provide a driver api for reporting device statistics required by the
"Implementation Requirements" section of the PSP Architecture
Specification. Use a warning to ensure drivers report stats required
by the spec.

Signed-off-by: Daniel Zahka <daniel.zahka@gmail.com>
Link: https://patch.msgid.link/20251106002608.1578518-4-daniel.zahka@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+108 -2
+55
Documentation/netlink/specs/psp.yaml
··· 98 98 Number of times a socket's Rx got shut down due to using 99 99 a key which went stale (fully rotated out). 100 100 Kernel statistic. 101 + - 102 + name: rx-packets 103 + type: uint 104 + doc: | 105 + Number of successfully processed and authenticated PSP packets. 106 + Device statistic (from the PSP spec). 107 + - 108 + name: rx-bytes 109 + type: uint 110 + doc: | 111 + Number of successfully authenticated PSP bytes received, counting from 112 + the first byte after the IV through the last byte of payload. 113 + The fixed initial portion of the PSP header (16 bytes) 114 + and the PSP trailer/ICV (16 bytes) are not included in this count. 115 + Device statistic (from the PSP spec). 116 + - 117 + name: rx-auth-fail 118 + type: uint 119 + doc: | 120 + Number of received PSP packets with unsuccessful authentication. 121 + Device statistic (from the PSP spec). 122 + - 123 + name: rx-error 124 + type: uint 125 + doc: | 126 + Number of received PSP packets with length/framing errors. 127 + Device statistic (from the PSP spec). 128 + - 129 + name: rx-bad 130 + type: uint 131 + doc: | 132 + Number of received PSP packets with miscellaneous errors 133 + (invalid master key indicated by SPI, unsupported version, etc.) 134 + Device statistic (from the PSP spec). 135 + - 136 + name: tx-packets 137 + type: uint 138 + doc: | 139 + Number of successfully processed PSP packets for transmission. 140 + Device statistic (from the PSP spec). 141 + - 142 + name: tx-bytes 143 + type: uint 144 + doc: | 145 + Number of successfully processed PSP bytes for transmit, counting from 146 + the first byte after the IV through the last byte of payload. 147 + The fixed initial portion of the PSP header (16 bytes) 148 + and the PSP trailer/ICV (16 bytes) are not included in this count. 149 + Device statistic (from the PSP spec). 150 + - 151 + name: tx-error 152 + type: uint 153 + doc: | 154 + Number of PSP packets for transmission with errors. 155 + Device statistic (from the PSP spec). 101 156 102 157 operations: 103 158 list:
+23
include/net/psp/types.h
··· 150 150 u8 drv_data[] __aligned(8); 151 151 }; 152 152 153 + struct psp_dev_stats { 154 + union { 155 + struct { 156 + u64 rx_packets; 157 + u64 rx_bytes; 158 + u64 rx_auth_fail; 159 + u64 rx_error; 160 + u64 rx_bad; 161 + u64 tx_packets; 162 + u64 tx_bytes; 163 + u64 tx_error; 164 + }; 165 + DECLARE_FLEX_ARRAY(u64, required); 166 + }; 167 + }; 168 + 153 169 /** 154 170 * struct psp_dev_ops - netdev driver facing PSP callbacks 155 171 */ ··· 204 188 * Remove an association from the device. 205 189 */ 206 190 void (*tx_key_del)(struct psp_dev *psd, struct psp_assoc *pas); 191 + 192 + /** 193 + * @get_stats: get statistics from the device 194 + * Stats required by the spec must be maintained and filled in. 195 + * Stats must be filled in member-by-member, never memset the struct. 196 + */ 197 + void (*get_stats)(struct psp_dev *psd, struct psp_dev_stats *stats); 207 198 }; 208 199 209 200 #endif /* __NET_PSP_H */
+8
include/uapi/linux/psp.h
··· 49 49 PSP_A_STATS_DEV_ID = 1, 50 50 PSP_A_STATS_KEY_ROTATIONS, 51 51 PSP_A_STATS_STALE_EVENTS, 52 + PSP_A_STATS_RX_PACKETS, 53 + PSP_A_STATS_RX_BYTES, 54 + PSP_A_STATS_RX_AUTH_FAIL, 55 + PSP_A_STATS_RX_ERROR, 56 + PSP_A_STATS_RX_BAD, 57 + PSP_A_STATS_TX_PACKETS, 58 + PSP_A_STATS_TX_BYTES, 59 + PSP_A_STATS_TX_ERROR, 52 60 53 61 __PSP_A_STATS_MAX, 54 62 PSP_A_STATS_MAX = (__PSP_A_STATS_MAX - 1)
+2 -1
net/psp/psp_main.c
··· 60 60 !psd_ops->key_rotate || 61 61 !psd_ops->rx_spi_alloc || 62 62 !psd_ops->tx_key_add || 63 - !psd_ops->tx_key_del)) 63 + !psd_ops->tx_key_del || 64 + !psd_ops->get_stats)) 64 65 return ERR_PTR(-EINVAL); 65 66 66 67 psd = kzalloc(sizeof(*psd), GFP_KERNEL);
+20 -1
net/psp/psp_nl.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0-only 2 2 3 + #include <linux/ethtool.h> 3 4 #include <linux/skbuff.h> 4 5 #include <linux/xarray.h> 5 6 #include <net/genetlink.h> ··· 510 509 psp_nl_stats_fill(struct psp_dev *psd, struct sk_buff *rsp, 511 510 const struct genl_info *info) 512 511 { 512 + unsigned int required_cnt = sizeof(struct psp_dev_stats) / sizeof(u64); 513 + struct psp_dev_stats stats; 513 514 void *hdr; 515 + int i; 516 + 517 + memset(&stats, 0xff, sizeof(stats)); 518 + psd->ops->get_stats(psd, &stats); 519 + 520 + for (i = 0; i < required_cnt; i++) 521 + if (WARN_ON_ONCE(stats.required[i] == ETHTOOL_STAT_NOT_SET)) 522 + return -EOPNOTSUPP; 514 523 515 524 hdr = genlmsg_iput(rsp, info); 516 525 if (!hdr) ··· 529 518 if (nla_put_u32(rsp, PSP_A_STATS_DEV_ID, psd->id) || 530 519 nla_put_uint(rsp, PSP_A_STATS_KEY_ROTATIONS, 531 520 psd->stats.rotations) || 532 - nla_put_uint(rsp, PSP_A_STATS_STALE_EVENTS, psd->stats.stales)) 521 + nla_put_uint(rsp, PSP_A_STATS_STALE_EVENTS, psd->stats.stales) || 522 + nla_put_uint(rsp, PSP_A_STATS_RX_PACKETS, stats.rx_packets) || 523 + nla_put_uint(rsp, PSP_A_STATS_RX_BYTES, stats.rx_bytes) || 524 + nla_put_uint(rsp, PSP_A_STATS_RX_AUTH_FAIL, stats.rx_auth_fail) || 525 + nla_put_uint(rsp, PSP_A_STATS_RX_ERROR, stats.rx_error) || 526 + nla_put_uint(rsp, PSP_A_STATS_RX_BAD, stats.rx_bad) || 527 + nla_put_uint(rsp, PSP_A_STATS_TX_PACKETS, stats.tx_packets) || 528 + nla_put_uint(rsp, PSP_A_STATS_TX_BYTES, stats.tx_bytes) || 529 + nla_put_uint(rsp, PSP_A_STATS_TX_ERROR, stats.tx_error)) 533 530 goto err_cancel_msg; 534 531 535 532 genlmsg_end(rsp, hdr);