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>
This commit is contained in:
Jakub Kicinski
2025-11-05 16:26:04 -08:00
parent 2098cec328
commit f05d26198c
5 changed files with 108 additions and 2 deletions

View File

@@ -98,6 +98,61 @@ attribute-sets:
Number of times a socket's Rx got shut down due to using
a key which went stale (fully rotated out).
Kernel statistic.
-
name: rx-packets
type: uint
doc: |
Number of successfully processed and authenticated PSP packets.
Device statistic (from the PSP spec).
-
name: rx-bytes
type: uint
doc: |
Number of successfully authenticated PSP bytes received, counting from
the first byte after the IV through the last byte of payload.
The fixed initial portion of the PSP header (16 bytes)
and the PSP trailer/ICV (16 bytes) are not included in this count.
Device statistic (from the PSP spec).
-
name: rx-auth-fail
type: uint
doc: |
Number of received PSP packets with unsuccessful authentication.
Device statistic (from the PSP spec).
-
name: rx-error
type: uint
doc: |
Number of received PSP packets with length/framing errors.
Device statistic (from the PSP spec).
-
name: rx-bad
type: uint
doc: |
Number of received PSP packets with miscellaneous errors
(invalid master key indicated by SPI, unsupported version, etc.)
Device statistic (from the PSP spec).
-
name: tx-packets
type: uint
doc: |
Number of successfully processed PSP packets for transmission.
Device statistic (from the PSP spec).
-
name: tx-bytes
type: uint
doc: |
Number of successfully processed PSP bytes for transmit, counting from
the first byte after the IV through the last byte of payload.
The fixed initial portion of the PSP header (16 bytes)
and the PSP trailer/ICV (16 bytes) are not included in this count.
Device statistic (from the PSP spec).
-
name: tx-error
type: uint
doc: |
Number of PSP packets for transmission with errors.
Device statistic (from the PSP spec).
operations:
list:

View File

@@ -150,6 +150,22 @@ struct psp_assoc {
u8 drv_data[] __aligned(8);
};
struct psp_dev_stats {
union {
struct {
u64 rx_packets;
u64 rx_bytes;
u64 rx_auth_fail;
u64 rx_error;
u64 rx_bad;
u64 tx_packets;
u64 tx_bytes;
u64 tx_error;
};
DECLARE_FLEX_ARRAY(u64, required);
};
};
/**
* struct psp_dev_ops - netdev driver facing PSP callbacks
*/
@@ -188,6 +204,13 @@ struct psp_dev_ops {
* Remove an association from the device.
*/
void (*tx_key_del)(struct psp_dev *psd, struct psp_assoc *pas);
/**
* @get_stats: get statistics from the device
* Stats required by the spec must be maintained and filled in.
* Stats must be filled in member-by-member, never memset the struct.
*/
void (*get_stats)(struct psp_dev *psd, struct psp_dev_stats *stats);
};
#endif /* __NET_PSP_H */

View File

@@ -49,6 +49,14 @@ enum {
PSP_A_STATS_DEV_ID = 1,
PSP_A_STATS_KEY_ROTATIONS,
PSP_A_STATS_STALE_EVENTS,
PSP_A_STATS_RX_PACKETS,
PSP_A_STATS_RX_BYTES,
PSP_A_STATS_RX_AUTH_FAIL,
PSP_A_STATS_RX_ERROR,
PSP_A_STATS_RX_BAD,
PSP_A_STATS_TX_PACKETS,
PSP_A_STATS_TX_BYTES,
PSP_A_STATS_TX_ERROR,
__PSP_A_STATS_MAX,
PSP_A_STATS_MAX = (__PSP_A_STATS_MAX - 1)

View File

@@ -60,7 +60,8 @@ psp_dev_create(struct net_device *netdev,
!psd_ops->key_rotate ||
!psd_ops->rx_spi_alloc ||
!psd_ops->tx_key_add ||
!psd_ops->tx_key_del))
!psd_ops->tx_key_del ||
!psd_ops->get_stats))
return ERR_PTR(-EINVAL);
psd = kzalloc(sizeof(*psd), GFP_KERNEL);

View File

@@ -1,5 +1,6 @@
// SPDX-License-Identifier: GPL-2.0-only
#include <linux/ethtool.h>
#include <linux/skbuff.h>
#include <linux/xarray.h>
#include <net/genetlink.h>
@@ -509,7 +510,17 @@ static int
psp_nl_stats_fill(struct psp_dev *psd, struct sk_buff *rsp,
const struct genl_info *info)
{
unsigned int required_cnt = sizeof(struct psp_dev_stats) / sizeof(u64);
struct psp_dev_stats stats;
void *hdr;
int i;
memset(&stats, 0xff, sizeof(stats));
psd->ops->get_stats(psd, &stats);
for (i = 0; i < required_cnt; i++)
if (WARN_ON_ONCE(stats.required[i] == ETHTOOL_STAT_NOT_SET))
return -EOPNOTSUPP;
hdr = genlmsg_iput(rsp, info);
if (!hdr)
@@ -518,7 +529,15 @@ psp_nl_stats_fill(struct psp_dev *psd, struct sk_buff *rsp,
if (nla_put_u32(rsp, PSP_A_STATS_DEV_ID, psd->id) ||
nla_put_uint(rsp, PSP_A_STATS_KEY_ROTATIONS,
psd->stats.rotations) ||
nla_put_uint(rsp, PSP_A_STATS_STALE_EVENTS, psd->stats.stales))
nla_put_uint(rsp, PSP_A_STATS_STALE_EVENTS, psd->stats.stales) ||
nla_put_uint(rsp, PSP_A_STATS_RX_PACKETS, stats.rx_packets) ||
nla_put_uint(rsp, PSP_A_STATS_RX_BYTES, stats.rx_bytes) ||
nla_put_uint(rsp, PSP_A_STATS_RX_AUTH_FAIL, stats.rx_auth_fail) ||
nla_put_uint(rsp, PSP_A_STATS_RX_ERROR, stats.rx_error) ||
nla_put_uint(rsp, PSP_A_STATS_RX_BAD, stats.rx_bad) ||
nla_put_uint(rsp, PSP_A_STATS_TX_PACKETS, stats.tx_packets) ||
nla_put_uint(rsp, PSP_A_STATS_TX_BYTES, stats.tx_bytes) ||
nla_put_uint(rsp, PSP_A_STATS_TX_ERROR, stats.tx_error))
goto err_cancel_msg;
genlmsg_end(rsp, hdr);