Linux CXL
 help / color / mirror / Atom feed
From: Dave Jiang <dave.jiang@intel.com>
To: linux-cxl@vger.kernel.org
Cc: dan.j.williams@intel.com, ira.weiny@intel.com,
	vishal.l.verma@intel.com, alison.schofield@intel.com,
	Jonathan.Cameron@huawei.com, dave@stgolabs.net, jgg@nvidia.com,
	shiju.jose@huawei.com
Subject: [RFC PATCH v2 16/20] fwctl/cxl: Add support to filter exclusive features
Date: Fri, 15 Nov 2024 14:25:49 -0700	[thread overview]
Message-ID: <20241115212745.869552-17-dave.jiang@intel.com> (raw)
In-Reply-To: <20241115212745.869552-1-dave.jiang@intel.com>

Add support to allow filtering of CXL features that are exclusive to the
kernel and make them not visible to user space. The "get supported
features" mailbox command returned to the userspace is emulated and
will skip the features that is marked exclusive for the kernel. The
exclusion allows certain the feature setting of certain commands such
as claimed by RAS to be exclusive to the kernel.

Signed-off-by: Dave Jiang <dave.jiang@intel.com>
---
 drivers/cxl/core/mbox.c | 115 ++++++++++++++++++++++++++++++++++++----
 drivers/fwctl/cxl/cxl.c |   7 +--
 include/cxl/features.h  |  52 ++++++++++++++++++
 include/cxl/mailbox.h   |   8 ++-
 4 files changed, 168 insertions(+), 14 deletions(-)
 create mode 100644 include/cxl/features.h

diff --git a/drivers/cxl/core/mbox.c b/drivers/cxl/core/mbox.c
index e7c5c709ac79..12ace2951f7c 100644
--- a/drivers/cxl/core/mbox.c
+++ b/drivers/cxl/core/mbox.c
@@ -5,6 +5,7 @@
 #include <linux/ktime.h>
 #include <linux/mutex.h>
 #include <linux/unaligned.h>
+#include <cxl/features.h>
 #include <cxl/mailbox.h>
 #include <cxlpci.h>
 #include <cxlmem.h>
@@ -897,6 +898,78 @@ static int handle_mailbox_cmd_from_fwctl(struct cxl_mailbox *cxl_mbox,
 	return 0;
 }
 
+/*
+ * Emulate the 'get supported features' mailbox command and only copy out the
+ * features that are not marked as exclusive for kernel.
+ */
+static void cxl_mbox_get_supported_features_filtered(struct cxl_mailbox *cxl_mbox,
+						     struct cxl_mbox_cmd *mbox_cmd)
+{
+	struct cxl_mbox_get_sup_feats_in *feat_in = mbox_cmd->payload_in;
+	struct cxl_mbox_get_sup_feats_out *feat_out = mbox_cmd->payload_out;
+	const int feat_out_size = sizeof(*feat_out);
+	struct cxl_feat_entry *pos;
+	const int feat_ent_size = sizeof(*pos);
+	int out_count, ents, u;
+	u32 count;
+	u16 start;
+
+	count = le32_to_cpu(feat_in->count);
+	start = le16_to_cpu(feat_in->start_idx);
+	ents = count / sizeof(struct cxl_feat_entry);
+	ents -= start;
+	if (ents < 0) {
+		mbox_cmd->size_out = 0;
+		mbox_cmd->return_code = CXL_MBOX_CMD_RC_INPUT;
+		return;
+	}
+
+	if (mbox_cmd->size_out < feat_out_size) {
+		mbox_cmd->size_out = 0;
+		mbox_cmd->return_code = CXL_MBOX_CMD_RC_INPUT;
+		return;
+	}
+
+	feat_out->supported_feats =
+		cpu_to_le16(cxl_mbox->num_user_feats);
+	if (ents == 0) {
+		feat_out->num_entries = cpu_to_le16(0);
+		mbox_cmd->size_out = feat_out_size;
+		mbox_cmd->return_code = CXL_MBOX_CMD_RC_SUCCESS;
+		return;
+	}
+
+	pos = &feat_out->ents[0];
+	out_count = feat_out_size;
+	for (int i = 0, u = 0; i < cxl_mbox->num_features; i++) {
+		struct cxl_feature *feat = &cxl_mbox->entries[i];
+
+		if (feat->exclusive)
+			continue;
+
+		if (u < start) {
+			u++;
+			continue;
+		}
+
+		memcpy(pos, &feat->entry, feat_ent_size);
+		out_count += feat_ent_size;
+		pos++;
+		u++;
+
+		if (u == count)
+			break;
+
+		/* Make sure it does not go over total output buffer size */
+		if (out_count + feat_ent_size >= mbox_cmd->size_out)
+			break;
+	}
+
+	feat_out->num_entries = cpu_to_le16(u);
+	mbox_cmd->size_out = out_count;
+	mbox_cmd->return_code = CXL_MBOX_CMD_RC_SUCCESS;
+}
+
 int cxl_mbox_send_cmd(struct cxl_mailbox *cxl_mbox,
 		      struct fwctl_rpc_cxl *rpc_in,
 		      struct cxl_mbox_cmd *mbox_cmd, size_t *out_len)
@@ -925,9 +998,13 @@ int cxl_mbox_send_cmd(struct cxl_mailbox *cxl_mbox,
 		return rc;
 
 	guard(rwsem_read)(&cxl_memdev_rwsem);
-	rc = cxl_mbox->mbox_send(cxl_mbox, mbox_cmd);
-	if (rc)
-		return rc;
+	if (send_cmd.raw.opcode != CXL_MBOX_OP_GET_SUPPORTED_FEATURES) {
+		rc = cxl_mbox->mbox_send(cxl_mbox, mbox_cmd);
+		if (rc)
+			return rc;
+	} else {
+		cxl_mbox_get_supported_features_filtered(cxl_mbox, mbox_cmd);
+	}
 
 	*out_len = mbox_cmd->size_out;
 
@@ -1128,6 +1205,18 @@ static int cxl_get_supported_features_count(struct cxl_dev_state *cxlds)
 	return 0;
 }
 
+static bool is_feature_exclusive(struct cxl_feature *feat)
+{
+	int i;
+
+	for (i = 0; i < CXL_FEAT_UUID_MAX; i++) {
+		if (uuid_equal(&feat->entry.uuid, &cxl_exclusive_feats[i]))
+			return true;
+	}
+
+	return false;
+}
+
 int cxl_get_supported_features(struct cxl_dev_state *cxlds)
 {
 	struct cxl_mbox_get_sup_feats_out *mbox_out __free(kvfree) = NULL;
@@ -1138,7 +1227,7 @@ int cxl_get_supported_features(struct cxl_dev_state *cxlds)
 	int hdr_size = sizeof(*mbox_out);
 	struct cxl_mbox_cmd mbox_cmd;
 	struct cxl_mem_command *cmd;
-	struct cxl_feat_entry *entry;
+	struct cxl_feature *feat;
 
 	/* Get supported features is optional, need to check */
 	cmd = cxl_mem_find_command(CXL_MBOX_OP_GET_SUPPORTED_FEATURES);
@@ -1156,7 +1245,7 @@ int cxl_get_supported_features(struct cxl_dev_state *cxlds)
 		return 0;
 	}
 
-	struct cxl_feat_entry *entries __free(kvfree) =
+	struct cxl_feature *entries __free(kvfree) =
 		kvmalloc(cxl_mbox->num_features * feat_size, GFP_KERNEL);
 
 	if (!entries)
@@ -1165,7 +1254,7 @@ int cxl_get_supported_features(struct cxl_dev_state *cxlds)
 	max_size = cxl_mbox->payload_size - hdr_size;
 	/* max feat entries that can fit in mailbox max payload size */
 	max_feats = max_size / feat_size;
-	entry = &entries[0];
+	feat = &entries[0];
 
 	mbox_out = kvmalloc(cxl_mbox->payload_size, GFP_KERNEL);
 	if (!mbox_out)
@@ -1228,8 +1317,13 @@ int cxl_get_supported_features(struct cxl_dev_state *cxlds)
 			goto err;
 		}
 
-		memcpy(entry, mbox_out->ents, retrieved);
-		entry++;
+		memcpy(&feat->entry, mbox_out->ents, retrieved);
+		if (is_feature_exclusive(feat))
+			feat->exclusive = true;
+		else
+			cxl_mbox->num_user_feats++;
+		feat++;
+
 		/*
 		 * If the number of output entries is less than expected, add the
 		 * remaining entries to the next batch.
@@ -1256,13 +1350,14 @@ int cxl_get_supported_feature_entry(struct cxl_dev_state *cxlds, const uuid_t *f
 				    struct cxl_feat_entry *feat_entry_out)
 {
 	struct cxl_mailbox *cxl_mbox = &cxlds->cxl_mbox;
-	struct cxl_feat_entry *feat_entry;
+	struct cxl_feature *feat_entry;
 	int count;
 
 	/* Check CXL dev supports the feature */
 	feat_entry = &cxl_mbox->entries[0];
 	for (count = 0; count < cxl_mbox->num_features; count++, feat_entry++) {
-		if (uuid_equal(&feat_entry->uuid, feat_uuid)) {
+		if (uuid_equal(&feat_entry->entry.uuid, feat_uuid) &&
+		    !is_feature_exclusive(feat_entry)) {
 			memcpy(feat_entry_out, feat_entry, sizeof(*feat_entry_out));
 			return 0;
 		}
diff --git a/drivers/fwctl/cxl/cxl.c b/drivers/fwctl/cxl/cxl.c
index 164f6774a2c1..3915a59c7408 100644
--- a/drivers/fwctl/cxl/cxl.c
+++ b/drivers/fwctl/cxl/cxl.c
@@ -81,7 +81,7 @@ static bool cxlctl_validate_set_features(struct cxl_mailbox *cxl_mbox,
 					 const struct fwctl_rpc_cxl *rpc_in,
 					 enum fwctl_rpc_scope scope)
 {
-	struct cxl_feat_entry *feat;
+	struct cxl_feature *feat;
 	bool found = false;
 	uuid_t uuid;
 	u16 effects, mask;
@@ -95,7 +95,8 @@ static bool cxlctl_validate_set_features(struct cxl_mailbox *cxl_mbox,
 
 	for (int i = 0; i < cxl_mbox->num_features; i++) {
 		feat = &cxl_mbox->entries[i];
-		if (uuid_equal(&uuid, &feat->uuid)) {
+		if (uuid_equal(&uuid, &feat->entry.uuid) &&
+		    !feat->exclusive) {
 			found = true;
 			break;
 		}
@@ -104,7 +105,7 @@ static bool cxlctl_validate_set_features(struct cxl_mailbox *cxl_mbox,
 	if (!found)
 		return false;
 
-	effects = le16_to_cpu(feat->effects);
+	effects = le16_to_cpu(feat->entry.effects);
 	/* Currently no user background command support */
 	if (effects & CXL_CMD_BACKGROUND)
 		return false;
diff --git a/include/cxl/features.h b/include/cxl/features.h
new file mode 100644
index 000000000000..6074a3f79d70
--- /dev/null
+++ b/include/cxl/features.h
@@ -0,0 +1,52 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Copyright(c) 2024 Intel Corporation. */
+#ifndef __CXL_FEATS_H_
+#define __CXL_FEATS_H_
+
+#include <linux/uuid.h>
+
+#define CXL_FEAT_PATROL_SCRUB_UUID						\
+	UUID_INIT(0x96dad7d6, 0xfde8, 0x482b, 0xa7, 0x33, 0x75, 0x77, 0x4e,	\
+		  0x06, 0xdb, 0x8a)
+
+#define CXL_FEAT_ECS_UUID							\
+	UUID_INIT(0xe5b13f22, 0x2328, 0x4a14, 0xb8, 0xba, 0xb9, 0x69, 0x1e,	\
+		  0x89, 0x33, 0x86)
+
+#define CXL_FEAT_SPPR_UUID							\
+	UUID_INIT(0x892ba475, 0xfad8, 0x474e, 0x9d, 0x3e, 0x69, 0x2c, 0x91,	\
+		  0x75, 0x68, 0xbb)
+
+#define CXL_FEAT_HPPR_UUID							\
+	UUID_INIT(0x80ea4521, 0x786f, 0x4127, 0xaf, 0xb1, 0xec, 0x74, 0x59,	\
+		  0xfb, 0x0e, 0x24)
+
+#define CXL_FEAT_CACHELINE_SPARING_UUID						\
+	UUID_INIT(0x96C33386, 0x91dd, 0x44c7, 0x9e, 0xcb, 0xfd, 0xaf, 0x65,	\
+		  0x03, 0xba, 0xc4)
+
+#define CXL_FEAT_ROW_SPARING_UUID						\
+	UUID_INIT(0x450ebf67, 0xb135, 0x4f97, 0xa4, 0x98, 0xc2, 0xd5, 0x7f,	\
+		  0x27, 0x9b, 0xed)
+
+#define CXL_FEAT_BANK_SPARING_UUID						\
+	UUID_INIT(0x78b79636, 0x90ac, 0x4b64, 0xa4, 0xef, 0xfa, 0xac, 0x5d,	\
+		  0x18, 0xa8, 0x63)
+
+#define CXL_FEAT_RANK_SPARING_UUID						\
+	UUID_INIT(0x34dbaff5, 0x0552, 0x4281, 0x8f, 0x76, 0xda, 0x0b, 0x5e,	\
+		  0x7a, 0x76, 0xa7)
+
+#define CXL_FEAT_UUID_MAX	8
+static uuid_t cxl_exclusive_feats[CXL_FEAT_UUID_MAX] = {
+	CXL_FEAT_PATROL_SCRUB_UUID,
+	CXL_FEAT_ECS_UUID,
+	CXL_FEAT_SPPR_UUID,
+	CXL_FEAT_HPPR_UUID,
+	CXL_FEAT_CACHELINE_SPARING_UUID,
+	CXL_FEAT_ROW_SPARING_UUID,
+	CXL_FEAT_BANK_SPARING_UUID,
+	CXL_FEAT_RANK_SPARING_UUID,
+};
+
+#endif
diff --git a/include/cxl/mailbox.h b/include/cxl/mailbox.h
index 3e5e9c9362f5..f44ac93ebdf4 100644
--- a/include/cxl/mailbox.h
+++ b/include/cxl/mailbox.h
@@ -80,7 +80,8 @@ struct cxl_mailbox {
 	struct mutex mbox_mutex; /* lock to protect mailbox context */
 	struct rcuwait mbox_wait;
 	int num_features;
-	struct cxl_feat_entry *entries;
+	int num_user_feats;
+	struct cxl_feature *entries;
 	int (*mbox_send)(struct cxl_mailbox *cxl_mbox, struct cxl_mbox_cmd *cmd);
 };
 
@@ -165,6 +166,11 @@ struct cxl_feat_entry {
 	u8 reserved[18];
 } __packed;
 
+struct cxl_feature {
+	bool exclusive;
+	struct cxl_feat_entry entry;
+};
+
 /**
  * struct cxl_mem_command - Driver representation of a memory device command
  * @info: Command information as it exists for the UAPI
-- 
2.47.0


  parent reply	other threads:[~2024-11-15 21:28 UTC|newest]

Thread overview: 79+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-15 21:25 [RFC PATCH v2 0/20] fwctl/cxl: Add CXL feature commands support via fwctl Dave Jiang
2024-11-15 21:25 ` [RFC PATCH v2 01/20] cxl: Refactor user ioctl command path from mds to mailbox Dave Jiang
2024-11-21 17:33   ` Jonathan Cameron
2024-12-06  0:00   ` Dan Williams
2024-11-15 21:25 ` [RFC PATCH v2 02/20] cxl: Add Get Supported Features command for kernel usage Dave Jiang
2024-11-21 17:42   ` Jonathan Cameron
2024-12-06  0:33   ` Dan Williams
2024-12-09 12:20     ` Shiju Jose
2024-11-15 21:25 ` [RFC PATCH v2 03/20] cxl/test: Add Get Supported Features mailbox command support Dave Jiang
2024-11-21 17:45   ` Jonathan Cameron
2024-12-06  0:36   ` Dan Williams
2024-11-15 21:25 ` [RFC PATCH v2 04/20] cxl/mbox: Add GET_FEATURE mailbox command Dave Jiang
2024-12-06  0:44   ` Dan Williams
2024-12-09 12:20     ` Shiju Jose
2024-11-15 21:25 ` [RFC PATCH v2 05/20] cxl: Add Get Feature command support for user submission Dave Jiang
2024-11-21 17:47   ` Jonathan Cameron
2024-11-22 20:14     ` Dave Jiang
2024-11-25 20:14       ` Shiju Jose
2024-12-06  0:45   ` Dan Williams
2024-11-15 21:25 ` [RFC PATCH v2 06/20] cxl/mbox: Add SET_FEATURE mailbox command Dave Jiang
2024-12-06  0:48   ` Dan Williams
2024-12-09 12:20     ` Shiju Jose
2024-11-15 21:25 ` [RFC PATCH v2 07/20] cxl: Add Set Feature command support for user submission Dave Jiang
2024-11-21 17:49   ` Jonathan Cameron
2024-11-21 18:08     ` Dave Jiang
2024-11-22 14:17       ` Jonathan Cameron
2024-12-06  0:53   ` Dan Williams
2024-11-15 21:25 ` [RFC PATCH v2 08/20] cxl: Move cxl_driver related bits to be usable by external drivers Dave Jiang
2024-11-21 17:55   ` Jonathan Cameron
2024-11-15 21:25 ` [RFC PATCH v2 09/20] fwctl/cxl: Add driver for CXL mailbox for handling CXL features commands Dave Jiang
2024-11-20 18:01   ` Jason Gunthorpe
2024-11-20 18:35     ` Dave Jiang
2024-11-21 18:02   ` Jonathan Cameron
2024-12-06  1:21   ` Dan Williams
2024-12-09 13:30     ` Jason Gunthorpe
2024-12-09 20:35       ` Dan Williams
2024-12-10 13:40         ` Jason Gunthorpe
2024-11-15 21:25 ` [RFC PATCH v2 10/20] fwctl/cxl: Add support for get driver information Dave Jiang
2024-11-20 18:05   ` Jason Gunthorpe
2024-11-21 18:11   ` Jonathan Cameron
2024-11-22 23:22     ` Dave Jiang
2024-11-25 18:06       ` Jonathan Cameron
2024-12-06  5:15   ` Dan Williams
2024-11-15 21:25 ` [RFC PATCH v2 11/20] fwctl: FWCTL_HW_INFO to return hardware information Dave Jiang
2024-11-20 18:53   ` Jason Gunthorpe
2024-11-21 18:20   ` Jonathan Cameron
2024-11-22 22:42     ` Dave Jiang
2024-12-06  5:32   ` Dan Williams
2024-12-06 18:39     ` Dave Jiang
2024-12-09 13:32       ` Jason Gunthorpe
2024-11-15 21:25 ` [RFC PATCH v2 12/20] cxl: Save Command Effects Log (CEL) effects for enabled commands Dave Jiang
2024-11-21 18:22   ` Jonathan Cameron
2024-11-15 21:25 ` [RFC PATCH v2 13/20] fwctl/cxl: Add hw_info callback Dave Jiang
2024-11-21 18:26   ` Jonathan Cameron
2024-12-06  5:40   ` Dan Williams
2024-11-15 21:25 ` [RFC PATCH v2 14/20] cxl: Move defines and error codes from cxlmem.h to cxl/mailbox.h Dave Jiang
2024-11-21 18:31   ` Jonathan Cameron
2024-12-06  5:50   ` Dan Williams
2024-11-15 21:25 ` [RFC PATCH v2 15/20] fwctl/cxl: Add support for fwctl RPC command to enable CXL feature commands Dave Jiang
2024-11-20 18:42   ` Jason Gunthorpe
2024-11-22 14:49   ` Jonathan Cameron
2024-12-06  6:13   ` Dan Williams
2024-11-15 21:25 ` Dave Jiang [this message]
2024-11-22 15:05   ` [RFC PATCH v2 16/20] fwctl/cxl: Add support to filter exclusive features Jonathan Cameron
2024-12-03 18:06     ` Dave Jiang
2024-11-15 21:25 ` [RFC PATCH v2 17/20] cxl/test: Add Get Feature support to cxl_test Dave Jiang
2024-11-22 15:19   ` Jonathan Cameron
2024-11-15 21:25 ` [RFC PATCH v2 18/20] cxl/test: Add Set " Dave Jiang
2024-11-22 15:20   ` Jonathan Cameron
2024-11-15 21:25 ` [RFC PATCH v2 19/20] fwctl: Move fwctl documentation to its own directory Dave Jiang
2024-11-20 17:52   ` Jason Gunthorpe
2024-11-15 21:25 ` [RFC PATCH v2 20/20] fwctl/cxl: Add documentation to FWCTL CXL Dave Jiang
2024-11-22 15:26   ` Jonathan Cameron
2024-12-03 21:07     ` Dave Jiang
2024-12-06 21:10       ` Dan Williams
2024-11-20 18:57 ` [RFC PATCH v2 0/20] fwctl/cxl: Add CXL feature commands support via fwctl Jason Gunthorpe
2024-11-21 18:38   ` Jonathan Cameron
2025-01-21 20:30 ` Jason Gunthorpe
2025-01-21 20:34   ` Dave Jiang

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=20241115212745.869552-17-dave.jiang@intel.com \
    --to=dave.jiang@intel.com \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=alison.schofield@intel.com \
    --cc=dan.j.williams@intel.com \
    --cc=dave@stgolabs.net \
    --cc=ira.weiny@intel.com \
    --cc=jgg@nvidia.com \
    --cc=linux-cxl@vger.kernel.org \
    --cc=shiju.jose@huawei.com \
    --cc=vishal.l.verma@intel.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