diff mbox series

[net,1/4] ice: Prevent probing virtual functions

Message ID 20210809171402.17838-2-anthony.l.nguyen@intel.com
State New
Headers show
Series Intel Wired LAN Driver Updates 2021-08-09 | expand

Commit Message

Tony Nguyen Aug. 9, 2021, 5:13 p.m. UTC
From: Anirudh Venkataramanan <anirudh.venkataramanan@intel.com>

The userspace utility "driverctl" can be used to change/override the
system's default driver choices. This is useful in some situations
(buggy driver, old driver missing a device ID, trying a workaround,
etc.) where the user needs to load a different driver.

However, this is also prone to user error, where a driver is mapped
to a device it's not designed to drive. For example, if the ice driver
is mapped to driver iavf devices, the ice driver crashes.

Add a check to return an error if the ice driver is being used to
probe a virtual function.

Fixes: 837f08fdecbe ("ice: Add basic driver framework for Intel(R) E800 Series")
Signed-off-by: Anirudh Venkataramanan <anirudh.venkataramanan@intel.com>
Tested-by: Gurucharan G <gurucharanx.g@intel.com>
Tested-by: Konrad Jankowski <konrad0.jankowski@intel.com>
Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
---
 drivers/net/ethernet/intel/ice/ice_main.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Jakub Kicinski Aug. 9, 2021, 10:56 p.m. UTC | #1
On Mon,  9 Aug 2021 10:13:59 -0700 Tony Nguyen wrote:
> The userspace utility "driverctl" can be used to change/override the
> system's default driver choices. This is useful in some situations
> (buggy driver, old driver missing a device ID, trying a workaround,
> etc.) where the user needs to load a different driver.
> 
> However, this is also prone to user error, where a driver is mapped
> to a device it's not designed to drive. For example, if the ice driver
> is mapped to driver iavf devices, the ice driver crashes.
> 
> Add a check to return an error if the ice driver is being used to
> probe a virtual function.

This seems too selective. Also drivers should not trust the HW is sane
and crash the kernel. Please fix the crashes and fail probe gracefully
in all cases without resorting to duct tape.
diff mbox series

Patch

diff --git a/drivers/net/ethernet/intel/ice/ice_main.c b/drivers/net/ethernet/intel/ice/ice_main.c
index ef8d1815af56..a9506041eb42 100644
--- a/drivers/net/ethernet/intel/ice/ice_main.c
+++ b/drivers/net/ethernet/intel/ice/ice_main.c
@@ -4194,6 +4194,11 @@  ice_probe(struct pci_dev *pdev, const struct pci_device_id __always_unused *ent)
 	struct ice_hw *hw;
 	int i, err;
 
+	if (pdev->is_virtfn) {
+		dev_err(dev, "can't probe a virtual function\n");
+		return -EINVAL;
+	}
+
 	/* this driver uses devres, see
 	 * Documentation/driver-api/driver-model/devres.rst
 	 */