Skip to contentSkip to conversation

mei: validate the message header only in first fragment.

PATCH In review Tomas Winkler 2 participants 5 messages Jun 12, 2017 – Jun 13, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/3 mei: validate the message header only in first fragment.

RX message header is received in the first fragment of the message and saved side and it is not modified after that, we don't need to validate it upon each fragment.

---
 drivers/misc/mei/interrupt.c | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)
drivers/misc/mei/interrupt.c +19 -7
index c14e35201721..b0b8f18a85e3 100644
@@ -235,6 +235,17 @@ static inline bool hdr_is_fixed(struct mei_msg_hdr *mei_hdr)
 	return mei_hdr->host_addr == 0 && mei_hdr->me_addr != 0;
 }
 
+static inline int hdr_is_valid(u32 msg_hdr)
+{
+	struct mei_msg_hdr *mei_hdr;
+
+	mei_hdr = (struct mei_msg_hdr *)&msg_hdr;
+	if (!msg_hdr || mei_hdr->reserved)
+		return -EBADMSG;
+
+	return 0;
+}
+
 /**
  * mei_irq_read_handler - bottom half read routine after ISR to
  * handle the read processing.
@@ -256,17 +267,18 @@ int mei_irq_read_handler(struct mei_device *dev,
 		dev->rd_msg_hdr = mei_read_hdr(dev);
 		(*slots)--;
 		dev_dbg(dev->dev, "slots =%08x.\n", *slots);
-	}
-	mei_hdr = (struct mei_msg_hdr *) &dev->rd_msg_hdr;
-	dev_dbg(dev->dev, MEI_HDR_FMT, MEI_HDR_PRM(mei_hdr));
 
-	if (mei_hdr->reserved || !dev->rd_msg_hdr) {
-		dev_err(dev->dev, "corrupted message header 0x%08X\n",
+		ret = hdr_is_valid(dev->rd_msg_hdr);
+		if (ret) {
+			dev_err(dev->dev, "corrupted message header 0x%08X\n",
 				dev->rd_msg_hdr);
-		ret = -EBADMSG;
-		goto end;
+			goto end;
+		}
 	}
 
+	mei_hdr = (struct mei_msg_hdr *)&dev->rd_msg_hdr;
+	dev_dbg(dev->dev, MEI_HDR_FMT, MEI_HDR_PRM(mei_hdr));
+
 	if (mei_slots2data(*slots) < mei_hdr->length) {
 		dev_err(dev->dev, "less data available than length=%08x.\n",
 				*slots);
Signature · 1 line
2.9.4
#1 lore raw

PATCH 2/3 mei: drop unreachable code in mei_start

From: Alexander Usyskin <[email protected]>

Device disabled state is caught inside the retry loop, so there is no need to check it once again afterwards.

---
 drivers/misc/mei/init.c | 6 ------
 1 file changed, 6 deletions(-)
drivers/misc/mei/init.c +0 -6
index c8ad9ee7cb80..d2f691424dd1 100644
@@ -215,12 +215,6 @@ int mei_start(struct mei_device *dev)
 		}
 	} while (ret);
 
-	/* we cannot start the device w/o hbm start message completed */
-	if (dev->dev_state == MEI_DEV_DISABLED) {
-		dev_err(dev->dev, "reset failed");
-		goto err;
-	}
-
 	if (mei_hbm_start_wait(dev)) {
 		dev_err(dev->dev, "HBM haven't started");
 		goto err;
Signature · 1 line
2.9.4
#2 lore raw

PATCH 3/3 mei: me: use an index instead of a pointer for private data

In reply to Tomas Winkler

Device 'new_id' interface is useful for testing of not yet published hardware on older kernels and for internally used device ids on simulation platforms.
However currently with the device configuration held in device_id driver data as a pointer to mei_cfg structure it is hard, as one need to locate the address of the correct structure.
A recommended way of doing that is to use and index instead of a pointer.
This patch adds a new list of configuration mei_cfg_list[] indexed via enum mei_cfg_idx.

---
 drivers/misc/mei/hw-me.c  |  32 +++++++++++---
 drivers/misc/mei/hw-me.h  |  21 +++++----
 drivers/misc/mei/pci-me.c | 107 ++++++++++++++++++++++++----------------------
 3 files changed, 94 insertions(+), 66 deletions(-)
drivers/misc/mei/hw-me.c +26 -6
index 71216affcab1..171d471fe66f 100644
@@ -1376,38 +1376,58 @@ static bool mei_me_fw_type_sps(struct pci_dev *pdev)
 	.fw_status.status[5] = PCI_CFG_HFS_6
 
 /* ICH Legacy devices */
-const struct mei_cfg mei_me_legacy_cfg = {
+static const struct mei_cfg mei_me_legacy_cfg = {
 	MEI_CFG_LEGACY_HFS,
 };
 
 /* ICH devices */
-const struct mei_cfg mei_me_ich_cfg = {
+static const struct mei_cfg mei_me_ich_cfg = {
 	MEI_CFG_ICH_HFS,
 };
 
 /* PCH devices */
-const struct mei_cfg mei_me_pch_cfg = {
+static const struct mei_cfg mei_me_pch_cfg = {
 	MEI_CFG_PCH_HFS,
 };
 
 
 /* PCH Cougar Point and Patsburg with quirk for Node Manager exclusion */
-const struct mei_cfg mei_me_pch_cpt_pbg_cfg = {
+static const struct mei_cfg mei_me_pch_cpt_pbg_cfg = {
 	MEI_CFG_PCH_HFS,
 	MEI_CFG_FW_NM,
 };
 
 /* PCH8 Lynx Point and newer devices */
-const struct mei_cfg mei_me_pch8_cfg = {
+static const struct mei_cfg mei_me_pch8_cfg = {
 	MEI_CFG_PCH8_HFS,
 };
 
 /* PCH8 Lynx Point with quirk for SPS Firmware exclusion */
-const struct mei_cfg mei_me_pch8_sps_cfg = {
+static const struct mei_cfg mei_me_pch8_sps_cfg = {
 	MEI_CFG_PCH8_HFS,
 	MEI_CFG_FW_SPS,
 };
 
+static const struct mei_cfg *const mei_cfg_list[] = {
+	NULL,
+	&mei_me_legacy_cfg,
+	&mei_me_ich_cfg,
+	&mei_me_pch_cfg,
+	&mei_me_pch_cpt_pbg_cfg,
+	&mei_me_pch8_cfg,
+	&mei_me_pch8_sps_cfg,
+};
+
+const struct mei_cfg *mei_me_get_cfg(kernel_ulong_t idx)
+{
+	BUILD_BUG_ON(ARRAY_SIZE(mei_cfg_list) != MEI_ME_NUM_CFG);
+
+	if (idx >= MEI_ME_NUM_CFG)
+		return NULL;
+
+	return mei_cfg_list[idx];
+};
+
 /**
  * mei_me_dev_init - allocates and initializes the mei device structure
  *
drivers/misc/mei/hw-me.h +13 -8
index cf64847a35b9..5fda83619044 100644
@@ -41,8 +41,7 @@ struct mei_cfg {
 #define MEI_PCI_DEVICE(dev, cfg) \
 	.vendor = PCI_VENDOR_ID_INTEL, .device = (dev), \
 	.subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID, \
-	.driver_data = (kernel_ulong_t)&(cfg)
-
+	.driver_data = (kernel_ulong_t)(cfg),
 
 #define MEI_ME_RPM_TIMEOUT    500 /* ms */
 
@@ -63,12 +62,18 @@ struct mei_me_hw {
 
 #define to_me_hw(dev) (struct mei_me_hw *)((dev)->hw)
 
-extern const struct mei_cfg mei_me_legacy_cfg;
-extern const struct mei_cfg mei_me_ich_cfg;
-extern const struct mei_cfg mei_me_pch_cfg;
-extern const struct mei_cfg mei_me_pch_cpt_pbg_cfg;
-extern const struct mei_cfg mei_me_pch8_cfg;
-extern const struct mei_cfg mei_me_pch8_sps_cfg;
+enum mei_cfg_idx {
+	MEI_ME_UNDEF_CFG,
+	MEI_ME_LEGACY_CFG,
+	MEI_ME_ICH_CFG,
+	MEI_ME_PCH_CFG,
+	MEI_ME_PCH_CPT_PBG_CFG,
+	MEI_ME_PCH8_CFG,
+	MEI_ME_PCH8_SPS_CFG,
+	MEI_ME_NUM_CFG,
+};
+
+const struct mei_cfg *mei_me_get_cfg(kernel_ulong_t idx);
 
 struct mei_device *mei_me_dev_init(struct pci_dev *pdev,
 				   const struct mei_cfg *cfg);
drivers/misc/mei/pci-me.c +55 -52

124 lines not on this page · raw message

Signature · 1 line
2.9.4
#3 lore raw

Re: [char-misc-next 3/3] mei: me: use an index instead of a pointer for private data

drivers/misc/mei/hw-me.c static bool mei_me_fw_type_sps(struct pci_dev *pdev) · line 1419

Quoted 9 lines · Tomas Winkler
drivers/misc/mei/hw-me.c +9 -0
+static const struct mei_cfg *const mei_cfg_list[] = {
+	NULL,
+	&mei_me_legacy_cfg,
+	&mei_me_ich_cfg,
+	&mei_me_pch_cfg,
+	&mei_me_pch_cpt_pbg_cfg,
+	&mei_me_pch8_cfg,
+	&mei_me_pch8_sps_cfg,
+};

Does this structure have to keep in sync with:

drivers/misc/mei/hw-me.h struct mei_me_hw { · line 74

Quoted 10 lines
drivers/misc/mei/hw-me.h +10 -0
+enum mei_cfg_idx {
+	MEI_ME_UNDEF_CFG,
+	MEI_ME_LEGACY_CFG,
+	MEI_ME_ICH_CFG,
+	MEI_ME_PCH_CFG,
+	MEI_ME_PCH_CPT_PBG_CFG,
+	MEI_ME_PCH8_CFG,
+	MEI_ME_PCH8_SPS_CFG,
+	MEI_ME_NUM_CFG,
+};

That value?

If so, why not make it automatic and have the array use the enum values? That way you know you get it right.

At the very least, document the heck out of this...

thanks,

greg k-h

#4 lore raw

RE: [char-misc-next 3/3] mei: me: use an index instead of a pointer for private data

Quoted 37 lines

-----Original Message-----
From: Greg Kroah-Hartman [mailto:[email protected]]
Sent: Tuesday, June 13, 2017 16:46
To: Winkler, Tomas <[email protected]>
Cc: Usyskin, Alexander <[email protected]>; linux- [email protected]
Subject: Re: [char-misc-next 3/3] mei: me: use an index instead of a pointer for private data

drivers/misc/mei/hw-me.c static bool mei_me_fw_type_sps(struct pci_dev *pdev) · line 1419

Quoted 9 lines · Tomas Winkler
drivers/misc/mei/hw-me.c +9 -0
+static const struct mei_cfg *const mei_cfg_list[] = {
+	NULL,
+	&mei_me_legacy_cfg,
+	&mei_me_ich_cfg,
+	&mei_me_pch_cfg,
+	&mei_me_pch_cpt_pbg_cfg,
+	&mei_me_pch8_cfg,
+	&mei_me_pch8_sps_cfg,
+};

Does this structure have to keep in sync with:

drivers/misc/mei/hw-me.h struct mei_me_hw { · line 74

Quoted 10 lines
drivers/misc/mei/hw-me.h +10 -0
+enum mei_cfg_idx {
+	MEI_ME_UNDEF_CFG,
+	MEI_ME_LEGACY_CFG,
+	MEI_ME_ICH_CFG,
+	MEI_ME_PCH_CFG,
+	MEI_ME_PCH_CPT_PBG_CFG,
+	MEI_ME_PCH8_CFG,
+	MEI_ME_PCH8_SPS_CFG,
+	MEI_ME_NUM_CFG,
+};

That value?

Quoted 2 lines

If so, why not make it automatic and have the array use the enum values? That way you know you get it right.

Do you mean 'designated Initializers'? I didn't know it's supported.. neat feature.

Quoted 1 line

At the very least, document the heck out of this...

Will do

Thanks
Tomas