mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Stan Iliev <stani@google.com>
To: Tony Nguyen <anthony.l.nguyen@intel.com>,
	 Przemek Kitszel <przemyslaw.kitszel@intel.com>,
	"David S. Miller" <davem@davemloft.net>,
	 Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	 Andrew Lunn <andrew+netdev@lunn.ch>,
	intel-wired-lan@lists.osuosl.org
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	 David Decotigny <decot@google.com>,
	Madhu Chittim <madhu.chittim@intel.com>,
	 Emil Tantilov <emil.s.tantilov@intel.com>,
	Sridhar Samudrala <sridhar.samudrala@intel.com>,
	 Brian Vazquez <brianvv@google.com>, Li Li <boolli@google.com>,
	 Alexander Lobakin <aleksander.lobakin@intel.com>,
	Daniel Zahka <daniel.zahka@gmail.com>,
	 Willem de Bruijn <willemdebruijn.kernel@gmail.com>,
	Kees Cook <kees@kernel.org>,
	 "Gustavo A. R. Silva" <gustavoars@kernel.org>,
	linux-hardening@vger.kernel.org
Subject: [PATCH iwl-next 06/15] idpf: psp: add support for psp capabilities
Date: Tue, 17 Nov 2026 14:55:12 +0000	[thread overview]
Message-ID: <20261117145522.1910636-7-stani@google.com> (raw)
In-Reply-To: <20261117145522.1910636-1-stani@google.com>

Add support for negotiating the PSP capabilities:
- Introduce VIRTCHNL2_OP_PSP_GET_CAPS (565), enum virtchnl2_psp_caps
  and struct virtchnl2_psp_get_caps (64 bytes, sent from the stack).
- Introduce the common PSP key definitions:
  enum virtchnl2_psp_key_type, VIRTCHNL2_PSP_KEY_SIZE_V0/V1,
  enum virtchnl2_psp_domain_type and struct virtchnl2_psp_key_domain.
- Implement idpf_send_get_psp_caps(), which requests all PSP
  capabilities, and call it from idpf_psp_negotiate_caps(). PSP stays
  disabled unless PSP version 0 keys are granted. The granted
  capabilities are stored in adapter->psp.psp_caps.

Signed-off-by: Stan Iliev <stani@google.com>
---
 drivers/net/ethernet/intel/idpf/idpf_psp.c    | 15 ++++-
 .../net/ethernet/intel/idpf/idpf_psp_def.h    |  3 +
 .../ethernet/intel/idpf/idpf_psp_virtchnl.c   | 66 +++++++++++++++++++
 .../ethernet/intel/idpf/idpf_psp_virtchnl.h   |  2 +
 include/linux/net/intel/virtchnl2.h           | 65 ++++++++++++++++++
 5 files changed, 150 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/intel/idpf/idpf_psp.c b/drivers/net/ethernet/intel/idpf/idpf_psp.c
index c4f46f7337ef..252ddb773cf5 100644
--- a/drivers/net/ethernet/intel/idpf/idpf_psp.c
+++ b/drivers/net/ethernet/intel/idpf/idpf_psp.c
@@ -18,8 +18,9 @@
 static int idpf_psp_negotiate_caps(struct idpf_adapter *adapter)
 {
 	struct virtchnl2_crypto_get_caps crypto_caps = { };
+	struct virtchnl2_psp_get_caps psp_caps = { };
 	struct device *dev = &adapter->pdev->dev;
-	u32 sadb_entries;
+	u32 caps, sadb_entries;
 	int err;
 
 	err = idpf_send_get_crypto_caps(adapter, &crypto_caps);
@@ -51,6 +52,18 @@ static int idpf_psp_negotiate_caps(struct idpf_adapter *adapter)
 		return -EOPNOTSUPP;
 	}
 
+	err = idpf_send_get_psp_caps(adapter, &psp_caps);
+	if (err)
+		return err;
+
+	/* The driver only allocates and inserts PSP version 0 keys */
+	caps = le32_to_cpu(psp_caps.psp_caps);
+	if (!(caps & VIRTCHNL2_CAP_PSP_PROTO_V0)) {
+		dev_notice(dev, "PSP version 0 keys not granted by CP\n");
+		return -EOPNOTSUPP;
+	}
+
+	adapter->psp.psp_caps = caps;
 	adapter->psp.sadb_entries = sadb_entries;
 	adapter->psp.saidx_width = crypto_caps.saidx_width;
 
diff --git a/drivers/net/ethernet/intel/idpf/idpf_psp_def.h b/drivers/net/ethernet/intel/idpf/idpf_psp_def.h
index 3a9e40284106..0829d0bbd92b 100644
--- a/drivers/net/ethernet/intel/idpf/idpf_psp_def.h
+++ b/drivers/net/ethernet/intel/idpf/idpf_psp_def.h
@@ -17,6 +17,8 @@
  *	     idpf_is_psp_ena()
  * @sadb_entries: SADB size granted by VIRTCHNL2_OP_CRYPTO_GET_CAPS
  * @saidx_width: SA index width granted by VIRTCHNL2_OP_CRYPTO_GET_CAPS
+ * @psp_caps: PSP capabilities granted by VIRTCHNL2_OP_PSP_GET_CAPS, see
+ *	      enum virtchnl2_psp_caps
  * @psp_dev: the PSP device, see idpf_psp_register()
  * @caps: capabilities of @psp_dev
  */
@@ -24,6 +26,7 @@ struct idpf_adapter_psp {
 	bool enabled;
 	u32 sadb_entries;
 	u8 saidx_width;
+	u32 psp_caps;
 	struct psp_dev *psp_dev;
 	struct psp_dev_caps caps;
 };
diff --git a/drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.c b/drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.c
index 65f7a9f63f90..ba114324d818 100644
--- a/drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.c
+++ b/drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.c
@@ -69,3 +69,69 @@ int idpf_send_get_crypto_caps(struct idpf_adapter *adapter,
 	libie_ctlq_release_rx_buf(&xn_params.recv_mem);
 	return err;
 }
+
+/**
+ * idpf_print_psp_caps - Print values inside virtchnl2_psp_get_caps
+ * @adapter: Driver specific private structure
+ * @caps: Pointer to virtchnl2_psp_get_caps structure
+ */
+static void idpf_print_psp_caps(struct idpf_adapter *adapter,
+				const struct virtchnl2_psp_get_caps *caps)
+{
+	u32 psp_caps = le32_to_cpu(caps->psp_caps);
+
+	dev_dbg(&adapter->pdev->dev,
+		"virtchnl2_psp_get_caps: psp_caps=0x%08x (PROTO_V0=%u, PROTO_V1=%u, REQUEST_ROTATION=%u, DOMAIN=%u)\n",
+		psp_caps,
+		!!(psp_caps & VIRTCHNL2_CAP_PSP_PROTO_V0),
+		!!(psp_caps & VIRTCHNL2_CAP_PSP_PROTO_V1),
+		!!(psp_caps & VIRTCHNL2_CAP_PSP_REQUEST_ROTATION),
+		!!(psp_caps & VIRTCHNL2_CAP_PSP_DOMAIN));
+}
+
+/**
+ * idpf_send_get_psp_caps - Send VIRTCHNL2_OP_PSP_GET_CAPS request to CP
+ * @adapter: Driver specific private structure
+ * @caps: Output buffer for virtchnl2_psp_get_caps
+ *
+ * Request all PSP capabilities, PSP capabilities that are not requested are
+ * not available.
+ *
+ * Return: 0 on success, negative on failure.
+ */
+int idpf_send_get_psp_caps(struct idpf_adapter *adapter,
+			   struct virtchnl2_psp_get_caps *caps)
+{
+	struct libie_ctlq_xn_send_params xn_params = {
+		.chnl_opcode	= VIRTCHNL2_OP_PSP_GET_CAPS,
+		.timeout_ms	= IDPF_VC_XN_DEFAULT_TIMEOUT_MSEC,
+	};
+	struct virtchnl2_psp_get_caps send_caps = {
+		.psp_caps = cpu_to_le32(VIRTCHNL2_CAP_PSP_PROTO_V0 |
+					VIRTCHNL2_CAP_PSP_PROTO_V1 |
+					VIRTCHNL2_CAP_PSP_REQUEST_ROTATION |
+					VIRTCHNL2_CAP_PSP_DOMAIN),
+	};
+	int err;
+
+	err = idpf_send_mb_msg_stack(adapter, &xn_params, &send_caps);
+	if (err) {
+		dev_err(&adapter->pdev->dev, "Failed to get PSP caps: %d\n",
+			err);
+		return err;
+	}
+
+	if (xn_params.recv_mem.iov_len < sizeof(*caps)) {
+		dev_err(&adapter->pdev->dev, "Invalid PSP caps reply size: %zu\n",
+			xn_params.recv_mem.iov_len);
+		err = -EIO;
+		goto release_rx;
+	}
+
+	memcpy(caps, xn_params.recv_mem.iov_base, sizeof(*caps));
+	idpf_print_psp_caps(adapter, caps);
+
+release_rx:
+	libie_ctlq_release_rx_buf(&xn_params.recv_mem);
+	return err;
+}
diff --git a/drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.h b/drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.h
index cf82ac9182ef..b1c64575b417 100644
--- a/drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.h
+++ b/drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.h
@@ -9,5 +9,7 @@
 
 int idpf_send_get_crypto_caps(struct idpf_adapter *adapter,
 			      struct virtchnl2_crypto_get_caps *caps);
+int idpf_send_get_psp_caps(struct idpf_adapter *adapter,
+			   struct virtchnl2_psp_get_caps *caps);
 
 #endif /* !_IDPF_PSP_VIRTCHNL_H_ */
diff --git a/include/linux/net/intel/virtchnl2.h b/include/linux/net/intel/virtchnl2.h
index 59c379afcb71..45cdfc0651e3 100644
--- a/include/linux/net/intel/virtchnl2.h
+++ b/include/linux/net/intel/virtchnl2.h
@@ -86,6 +86,7 @@ enum virtchnl2_op {
 	VIRTCHNL2_OP_DEL_FLOW_RULE			= 553,
 	/* Crypto/PSP opcodes */
 	VIRTCHNL2_OP_CRYPTO_GET_CAPS			= 564,
+	VIRTCHNL2_OP_PSP_GET_CAPS			= 565,
 };
 
 /**
@@ -1843,4 +1844,68 @@ struct virtchnl2_crypto_get_caps {
 };
 VIRTCHNL2_CHECK_STRUCT_LEN(256, virtchnl2_crypto_get_caps);
 
+/* PSP capability flags */
+enum virtchnl2_psp_caps {
+	/* PSP capability 0 is reserved */
+	VIRTCHNL2_CAP_PSP_PROTO_V0			= BIT(1),
+	VIRTCHNL2_CAP_PSP_PROTO_V1			= BIT(2),
+	VIRTCHNL2_CAP_PSP_REQUEST_ROTATION		= BIT(3),
+	/* If not granted, the domain field of PSP requests is ignored */
+	VIRTCHNL2_CAP_PSP_DOMAIN			= BIT(4),
+	/* PSP capabilities 16 and above are reserved for OEM */
+};
+
+/**
+ * struct virtchnl2_psp_get_caps - PSP global capabilities
+ * @psp_caps: See enum virtchnl2_psp_caps
+ * @padding: Padding to 64 bytes
+ *
+ * Request and response of VIRTCHNL2_OP_PSP_GET_CAPS. PSP capabilities are set
+ * per function: a capability that is not requested is not available.
+ */
+struct virtchnl2_psp_get_caps {
+	__le32 psp_caps;
+	u8 padding[60];
+};
+VIRTCHNL2_CHECK_STRUCT_LEN(64, virtchnl2_psp_get_caps);
+
+enum virtchnl2_psp_key_type {
+	VIRTCHNL2_PSP_KEY_TYPE_V0			= 1,
+	VIRTCHNL2_PSP_KEY_TYPE_V1			= 2,
+};
+
+#define VIRTCHNL2_PSP_KEY_SIZE_V0			16
+#define VIRTCHNL2_PSP_KEY_SIZE_V1			32
+
+/* PSP key domain types. Types VIRTCHNL2_PSP_DOMAIN_RESERVED_START to
+ * VIRTCHNL2_PSP_DOMAIN_RESERVED_END are reserved for future versions of the
+ * API, types VIRTCHNL2_PSP_DOMAIN_OEM_START to VIRTCHNL2_PSP_DOMAIN_OEM_END
+ * are OEM specific.
+ */
+enum virtchnl2_psp_domain_type {
+	VIRTCHNL2_PSP_DOMAIN_NONE			= 0,
+	VIRTCHNL2_PSP_DOMAIN_RESERVED_START		= 1,
+	VIRTCHNL2_PSP_DOMAIN_RESERVED_END		= 0x7fff,
+	VIRTCHNL2_PSP_DOMAIN_OEM_START			= 0x8000,
+	VIRTCHNL2_PSP_DOMAIN_OEM_END			= 0xffff,
+};
+
+/**
+ * struct virtchnl2_psp_key_domain - PSP key domain
+ * @type: See enum virtchnl2_psp_domain_type
+ * @pad: Reserved/padding
+ * @value: Security context used as part of the PSP SPI binding, must be 0
+ *	   if @type is VIRTCHNL2_PSP_DOMAIN_NONE
+ *
+ * Key domains prevent steering attacks: PSP does not authenticate the IP
+ * header, so a compromised VM changing the destination IP address must not
+ * be able to decrypt the packets of another VM on the same host.
+ */
+struct virtchnl2_psp_key_domain {
+	__le16 type;
+	u8 pad[6];
+	__le64 value;
+};
+VIRTCHNL2_CHECK_STRUCT_LEN(16, virtchnl2_psp_key_domain);
+
 #endif /* _VIRTCHNL_2_H_ */
-- 
2.56.0.679.gc527c65306-goog


  parent reply	other threads:[~2026-11-17 14:55 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17 14:55 [PATCH iwl-next 00/15] idpf: add PSP offload support, part 1 Stan Iliev
2026-11-17 14:55 ` [PATCH iwl-next 01/15] libie: wipe copied small send buffers on release Stan Iliev
2026-11-17 14:55 ` [PATCH iwl-next 02/15] idpf: wipe mailbox " Stan Iliev
2026-11-17 14:55 ` [PATCH iwl-next 03/15] idpf: make the mailbox workqueue visible in sysfs Stan Iliev
2026-11-17 14:55 ` [PATCH iwl-next 04/15] idpf: psp: add psp offload initialization Stan Iliev
2026-11-17 14:55 ` [PATCH iwl-next 05/15] idpf: psp: add support for crypto capabilities Stan Iliev
2026-11-17 14:55 ` Stan Iliev [this message]
2026-11-17 14:55 ` [PATCH iwl-next 07/15] idpf: psp: add support for fips compliance status Stan Iliev
2026-11-17 14:55 ` [PATCH iwl-next 08/15] idpf: psp: add support for psp rx key allocation Stan Iliev
2026-11-17 14:55 ` [PATCH iwl-next 09/15] idpf: psp: add support for psp key rotation Stan Iliev
2026-11-17 14:55 ` [PATCH iwl-next 10/15] idpf: psp: add support for psp statistics Stan Iliev
2026-11-17 14:55 ` [PATCH iwl-next 11/15] idpf: psp: add psp tx key state Stan Iliev
2026-11-17 14:55 ` [PATCH iwl-next 12/15] idpf: psp: add support for psp tx key deletion Stan Iliev
2026-11-17 14:55 ` [PATCH iwl-next 13/15] idpf: psp: add psp work and tx key insertion completion Stan Iliev
2026-11-17 14:55 ` [PATCH iwl-next 14/15] idpf: psp: add support for psp tx key insertion Stan Iliev
2026-11-17 14:55 ` [PATCH iwl-next 15/15] idpf: psp: add psp tx key registration Stan Iliev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261117145522.1910636-7-stani@google.com \
    --to=stani@google.com \
    --cc=aleksander.lobakin@intel.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=anthony.l.nguyen@intel.com \
    --cc=boolli@google.com \
    --cc=brianvv@google.com \
    --cc=daniel.zahka@gmail.com \
    --cc=davem@davemloft.net \
    --cc=decot@google.com \
    --cc=edumazet@kernel.org \
    --cc=emil.s.tantilov@intel.com \
    --cc=gustavoars@kernel.org \
    --cc=intel-wired-lan@lists.osuosl.org \
    --cc=kees@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=madhu.chittim@intel.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=przemyslaw.kitszel@intel.com \
    --cc=sridhar.samudrala@intel.com \
    --cc=willemdebruijn.kernel@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®