Skip to contentSkip to conversation

ibmvnic: process HMC disable command

PATCH In review Dany Madden 2 participants 4 messages Nov 23, 2020 – Dec 3, 2020 3 messages not in the archive

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

PATCH v2 1/1 ibmvnic: process HMC disable command

Currently ibmvnic does not support the "Disable vNIC" command from the Hardware Management Console. The HMC uses this command to disconnect the adapter from the network if the adapter is misbehaving or sending malicious traffic. The effect of this command is equivalent to setting the link to the "down" state on the linux client.

Enable support in ibmvnic driver for the Disable vNIC command.

---
V2 changes based on Jakub Kicinski's feedback:
- Broke from "[PATCH net 00/15] ibmvnic: assorted bug fixes" sent by Lijun Pan.
- Expanded on the description
- Submitting to net-next

---
 drivers/net/ethernet/ibm/ibmvnic.c | 40 ++++++++++++++++++++++++++++++
 drivers/net/ethernet/ibm/ibmvnic.h |  3 ++-
 2 files changed, 42 insertions(+), 1 deletion(-)
drivers/net/ethernet/ibm/ibmvnic.c +40 -0
index 63b39744a07a..47446e5f8ec5 100644
@@ -109,6 +109,8 @@ static void release_crq_queue(struct ibmvnic_adapter *);
 static int __ibmvnic_set_mac(struct net_device *, u8 *);
 static int init_crq_queue(struct ibmvnic_adapter *adapter);
 static int send_query_phys_parms(struct ibmvnic_adapter *adapter);
+static void ibmvnic_disable(struct ibmvnic_adapter *adapter);
+static int ibmvnic_close(struct net_device *netdev);
 
 struct ibmvnic_stat {
 	char name[ETH_GSTRING_LEN];
@@ -1207,6 +1209,42 @@ static int ibmvnic_open(struct net_device *netdev)
 	return rc;
 }
 
+static void ibmvnic_disable(struct ibmvnic_adapter *adapter)
+{
+	struct list_head *entry, *tmp_entry;
+	struct net_device *netdev = adapter->netdev;
+	int rc = 0;
+
+	/* cancel all pending resets in the queue */
+	if (!list_empty(&adapter->rwi_list)) {
+		list_for_each_safe(entry, tmp_entry, &adapter->rwi_list)
+			list_del(entry);
+	}
+
+	/* wait for current reset to finish */
+	flush_work(&adapter->ibmvnic_reset);
+	flush_delayed_work(&adapter->ibmvnic_delayed_reset);
+
+	if (test_bit(0, &adapter->resetting) ||
+	    adapter->state == VNIC_PROBED ||
+	    adapter->state == VNIC_OPEN ||
+	    adapter->state == VNIC_OPENING) {
+		rc = ibmvnic_close(netdev);
+		/* Expect -EINVAL when crq is no longer active. Set link down
+		 * would fail.
+		 */
+		if (rc && rc != -EINVAL) {
+			netdev_err(netdev, "Failed to disable adapter, rc=%d\n", rc);
+			return;
+		}
+	} else {
+		netdev_dbg(netdev, "Disable adapter request ignored (state=%d)\n", adapter->state);
+		return;
+	}
+
+	netdev_dbg(netdev, "Adapter disabled\n");
+}
+
 static void clean_rx_pools(struct ibmvnic_adapter *adapter)
 {
 	struct ibmvnic_rx_pool *rx_pool;
@@ -4825,6 +4863,8 @@ static void ibmvnic_handle_crq(union ibmvnic_crq *crq,
 		} else if (gen_crq->cmd == IBMVNIC_DEVICE_FAILOVER) {
 			dev_info(dev, "Backing device failover detected\n");
 			adapter->failover_pending = true;
+		} else if (gen_crq->cmd == IBMVNIC_DEVICE_DISABLE) {
+			ibmvnic_disable(adapter);
 		} else {
 			/* The adapter lost the connection */
 			dev_err(dev, "Virtual Adapter failed (rc=%d)\n",
drivers/net/ethernet/ibm/ibmvnic.h +2 -1
index b21092f5f9c1..d15866cbc2a6 100644
@@ -834,10 +834,11 @@ enum ibmvnic_crq_type {
 	IBMVNIC_CRQ_XPORT_EVENT		= 0xFF,
 };
 
-enum ibmvfc_crq_format {
+enum ibmvnic_crq_format {
 	IBMVNIC_CRQ_INIT                 = 0x01,
 	IBMVNIC_CRQ_INIT_COMPLETE        = 0x02,
 	IBMVNIC_PARTITION_MIGRATED       = 0x06,
+	IBMVNIC_DEVICE_DISABLE		 = 0x07,
 	IBMVNIC_DEVICE_FAILOVER          = 0x08,
 };
 
Signature · 1 line
2.26.2
maintainer
#1 lore raw
Quoted 9 lines · On Mon, 23 Nov 2020 18:58:41 -0500 Dany Madden wrote:

Currently ibmvnic does not support the "Disable vNIC" command from the Hardware Management Console. The HMC uses this command to disconnect the adapter from the network if the adapter is misbehaving or sending malicious traffic. The effect of this command is equivalent to setting the link to the "down" state on the linux client.

Enable support in ibmvnic driver for the Disable vNIC command.

It seems that (a) user looking at the system where NIC was disabled has no idea why netdev is not working even tho it's UP, and (b) AFAICT nothing prevents the user from bringing the device down and back up again.

You said this is to disable misbehaving and/or sending malicious vnic, obviously the guest can ignore the command so it's not very dependable, anyway.

Would it not be sufficient to mark the carrier state as down to cut the vnic off?

#5 lore raw
In reply to a message not in the archive
Quoted 44 lines · drt
Quoted 37 lines · drt
Quoted 36 lines · drt
Quoted 7 lines · Jakub Kicinski
Quoted 6 lines · On Mon, 23 Nov 2020 18:58:41 -0500 Dany Madden wrote:

Currently ibmvnic does not support the "Disable vNIC" command from the Hardware Management Console. The HMC uses this command to disconnect the adapter from the network if the adapter is misbehaving or sending malicious traffic. The effect of this command is equivalent to setting the link to the "down" state on the linux client.

Quoted 8 lines
Quoted 3 lines

Enable support in ibmvnic driver for the Disable vNIC command.

It seems that (a) user looking at the system where NIC was disabled has no idea why netdev is not working even tho it's UP, and (b) AFAICT nothing prevents the user from bringing the device down and back up again.

User would see the interface as DOWN. ibmvnic_close() requests the vnicserver to do a link down. The vnicserver responds with a link state indication CRQ message with logical link down, client would then do netif_carrier_off().

You are correct, nothing is preventing the user from bringing the device back online.

Quoted 4 lines

You said this is to disable misbehaving and/or sending malicious vnic, obviously the guest can ignore the command so it's not very dependable, anyway.

Without this patch, ibmvnic would ignore the command. With this patch, it will handle the disable command from the HMC. If the guest insists on being bad, the HMC does have the ability to remove vnic adapter from the guest.

Quoted 1 line
Quoted 5 lines
Quoted 3 lines
Quoted 2 lines

Would it not be sufficient to mark the carrier state as down to cut the vnic off?

Essentially, this is what ibmvnic_disable does.

Hello Jakub, did I address your concern? If not, please let me know.

Quoted 7 lines

Hello Jakub,

I am pulling this patch. Suka pointed out that rwi lock is not being held when it walks the rwi_list, also the reset bit is incorrectly checked. We will send a v3.

Apologize for any inconvenient.

It appears that my email is not showing up in the mailing archive because of email aliases. I hope this is going thru.

Please do not commit this patch.

Quoted 5 lines

thanks you!
Dany

Quoted 2 lines

Thanks!

maintainer
#6 lore raw
Quoted 60 lines · On Wed, 02 Dec 2020 15:50:58 -0800 Dany Madden wrote:
Quoted 59 lines · drt
Quoted 45 lines · drt
Quoted 44 lines · drt
Quoted 12 lines · Jakub Kicinski
Quoted 11 lines · On Mon, 23 Nov 2020 18:58:41 -0500 Dany Madden wrote:

Currently ibmvnic does not support the "Disable vNIC" command from the Hardware Management Console. The HMC uses this command to disconnect
the adapter from the network if the adapter is misbehaving or sending
malicious traffic. The effect of this command is equivalent to setting
the link to the "down" state on the linux client.

Enable support in ibmvnic driver for the Disable vNIC command.

Quoted 7 lines
Quoted 1 line

It seems that (a) user looking at the system where NIC was disabled has
no idea why netdev is not working even tho it's UP, and (b) AFAICT nothing prevents the user from bringing the device down and back up again.

User would see the interface as DOWN. ibmvnic_close() requests the vnicserver to do a link down. The vnicserver responds with a link state indication CRQ message with logical link down, client would then
do netif_carrier_off().

You are correct, nothing is preventing the user from bringing the device back online.

Quoted 6 lines

You said this is to disable misbehaving and/or sending malicious vnic,
obviously the guest can ignore the command so it's not very dependable,
anyway.

Without this patch, ibmvnic would ignore the command. With this patch,
it will handle the disable command from the HMC. If the guest insists on being bad, the HMC does have the ability to remove vnic adapter from the guest.

Quoted 1 line
Quoted 6 lines
Quoted 4 lines
Quoted 3 lines

Would it not be sufficient to mark the carrier state as down to cut the
vnic off?

Essentially, this is what ibmvnic_disable does.

Hello Jakub, did I address your concern? If not, please let me know.

Hello Jakub,

I am pulling this patch. Suka pointed out that rwi lock is not being held when it walks the rwi_list, also the reset bit is incorrectly checked. We will send a v3.

Quoted 6 lines
Quoted 1 line

Apologize for any inconvenient.

It appears that my email is not showing up in the mailing archive because of email aliases. I hope this is going thru.

Please do not commit this patch.

FWIW you can check the status of active patches in patchwork:

https://patchwork.kernel.org/project/netdevbpf/list/

This one has already been made inactive so it won't be applied in its current form.