Commit dae4a923 authored by Jakub Kicinski's avatar Jakub Kicinski
Browse files

psp: report basic stats from the core



Track and report stats common to all psp devices from the core. A
'stale-event' is when the core marks the rx state of an active
psp_assoc as incapable of authenticating psp encapsulated data.

Signed-off-by: default avatarDaniel Zahka <daniel.zahka@gmail.com>
Link: https://patch.msgid.link/20251106002608.1578518-2-daniel.zahka@gmail.com


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent f73e0f46
Loading
Loading
Loading
Loading
+40 −0
Original line number Diff line number Diff line
@@ -76,6 +76,28 @@ attribute-sets:
        name: spi
        doc: Security Parameters Index (SPI) of the association.
        type: u32
  -
    name: stats
    attributes:
      -
        name: dev-id
        doc: PSP device ID.
        type: u32
        checks:
          min: 1
      -
        name: key-rotations
        type: uint
        doc: |
          Number of key rotations during the lifetime of the device.
          Kernel statistic.
      -
        name: stale-events
        type: uint
        doc: |
          Number of times a socket's Rx got shut down due to using
          a key which went stale (fully rotated out).
          Kernel statistic.

operations:
  list:
@@ -177,6 +199,24 @@ operations:
        pre: psp-assoc-device-get-locked
        post: psp-device-unlock

    -
      name: get-stats
      doc: Get device statistics.
      attribute-set: stats
      do:
        request:
          attributes:
            - dev-id
        reply: &stats-all
          attributes:
            - dev-id
            - key-rotations
            - stale-events
        pre: psp-device-get-locked
        post: psp-device-unlock
      dump:
        reply: *stats-all

mcast-groups:
  list:
    -
+9 −0
Original line number Diff line number Diff line
@@ -59,6 +59,10 @@ struct psp_dev_config {
 *			device key
 * @stale_assocs:	associations which use a rotated out key
 *
 * @stats:	statistics maintained by the core
 * @stats.rotations:	See stats attr key-rotations
 * @stats.stales:	See stats attr stale-events
 *
 * @rcu:	RCU head for freeing the structure
 */
struct psp_dev {
@@ -81,6 +85,11 @@ struct psp_dev {
	struct list_head prev_assocs;
	struct list_head stale_assocs;

	struct {
		unsigned long rotations;
		unsigned long stales;
	} stats;

	struct rcu_head rcu;
};

+10 −0
Original line number Diff line number Diff line
@@ -45,6 +45,15 @@ enum {
	PSP_A_KEYS_MAX = (__PSP_A_KEYS_MAX - 1)
};

enum {
	PSP_A_STATS_DEV_ID = 1,
	PSP_A_STATS_KEY_ROTATIONS,
	PSP_A_STATS_STALE_EVENTS,

	__PSP_A_STATS_MAX,
	PSP_A_STATS_MAX = (__PSP_A_STATS_MAX - 1)
};

enum {
	PSP_CMD_DEV_GET = 1,
	PSP_CMD_DEV_ADD_NTF,
@@ -55,6 +64,7 @@ enum {
	PSP_CMD_KEY_ROTATE_NTF,
	PSP_CMD_RX_ASSOC,
	PSP_CMD_TX_ASSOC,
	PSP_CMD_GET_STATS,

	__PSP_CMD_MAX,
	PSP_CMD_MAX = (__PSP_CMD_MAX - 1)
+19 −0
Original line number Diff line number Diff line
@@ -47,6 +47,11 @@ static const struct nla_policy psp_tx_assoc_nl_policy[PSP_A_ASSOC_SOCK_FD + 1] =
	[PSP_A_ASSOC_SOCK_FD] = { .type = NLA_U32, },
};

/* PSP_CMD_GET_STATS - do */
static const struct nla_policy psp_get_stats_nl_policy[PSP_A_STATS_DEV_ID + 1] = {
	[PSP_A_STATS_DEV_ID] = NLA_POLICY_MIN(NLA_U32, 1),
};

/* Ops table for psp */
static const struct genl_split_ops psp_nl_ops[] = {
	{
@@ -99,6 +104,20 @@ static const struct genl_split_ops psp_nl_ops[] = {
		.maxattr	= PSP_A_ASSOC_SOCK_FD,
		.flags		= GENL_CMD_CAP_DO,
	},
	{
		.cmd		= PSP_CMD_GET_STATS,
		.pre_doit	= psp_device_get_locked,
		.doit		= psp_nl_get_stats_doit,
		.post_doit	= psp_device_unlock,
		.policy		= psp_get_stats_nl_policy,
		.maxattr	= PSP_A_STATS_DEV_ID,
		.flags		= GENL_CMD_CAP_DO,
	},
	{
		.cmd	= PSP_CMD_GET_STATS,
		.dumpit	= psp_nl_get_stats_dumpit,
		.flags	= GENL_CMD_CAP_DUMP,
	},
};

static const struct genl_multicast_group psp_nl_mcgrps[] = {
+2 −0
Original line number Diff line number Diff line
@@ -28,6 +28,8 @@ int psp_nl_dev_set_doit(struct sk_buff *skb, struct genl_info *info);
int psp_nl_key_rotate_doit(struct sk_buff *skb, struct genl_info *info);
int psp_nl_rx_assoc_doit(struct sk_buff *skb, struct genl_info *info);
int psp_nl_tx_assoc_doit(struct sk_buff *skb, struct genl_info *info);
int psp_nl_get_stats_doit(struct sk_buff *skb, struct genl_info *info);
int psp_nl_get_stats_dumpit(struct sk_buff *skb, struct netlink_callback *cb);

enum {
	PSP_NLGRP_MGMT,
Loading