Add trusted VF support
Subsystems (4)
cover Add trusted VF support
This series adds support for trusted VF. The trusted VF support allows VFs to perform priviliged operations such as setting VF interface in promiscuous mode, all-multicast mode and also changing the VF MAC address even if it was asssigned by PF.
Patches #1 and #2 provides the necessary functionality for supporting promiscuous and multicast packets on both the PF and VF.
Patches #3 and #4 enable trusted VF configuration support.
Hariprasad Kelam (2):
octeontx2-af: add new mailbox to configure VF trust mode
octeontx2-pf: add support for ndo_set_vf_trust
Naveen Mamindlapalli (2):
octeontx2-af: add support for multicast/promisc packet replication
feature
octeontx2-nicvf: add ndo_set_rx_mode support for multicast & promisc
drivers/net/ethernet/marvell/octeontx2/af/common.h | 5 + drivers/net/ethernet/marvell/octeontx2/af/mbox.h | 14 +- drivers/net/ethernet/marvell/octeontx2/af/npc.h | 3 +- drivers/net/ethernet/marvell/octeontx2/af/rvu.c | 42 +++ drivers/net/ethernet/marvell/octeontx2/af/rvu.h | 55 +++- .../ethernet/marvell/octeontx2/af/rvu_debugfs.c | 5 +- .../net/ethernet/marvell/octeontx2/af/rvu_nix.c | 270 ++++++++++++++---- .../net/ethernet/marvell/octeontx2/af/rvu_npc.c | 308 ++++++++++++++------- .../net/ethernet/marvell/octeontx2/af/rvu_npc_fs.c | 21 +- .../ethernet/marvell/octeontx2/nic/otx2_common.h | 6 + .../net/ethernet/marvell/octeontx2/nic/otx2_pf.c | 132 +++++++-- .../net/ethernet/marvell/octeontx2/nic/otx2_vf.c | 58 +++- 12 files changed, 729 insertions(+), 190 deletions(-)
Signature · 1 line
2.16.5
PATCH 1/4 octeontx2-af: add support for multicast/promisc packet replication feature
Currently, multicast packet filtering is accomplished by installing MCAM rule that matches all-multicast MAC address and has its NPC_RX_ACTION set to unicast to PF. Similarly promisc feature is achieved by installing MCAM rule that matches all the traffic received by the channel and unicast the packets to PF. This approach only applies to PF and is not scalable across VFs.
This patch adds support for PF/VF multicast and promisc feature by reserving NIX_RX_MCE_S entries from the global MCE list allocated during NIX block initialization. The NIX_RX_MCE_S entries create a linked list with a flag indicating the end of the list, and each entry points to a PF_FUNC (either PF or VF). When a packet NPC_RX_ACTION is set to MCAST, the corresponding NIX_RX_MCE_S list is traversed and the packet is queued to each PF_FUNC available on the list.
The PF or VF driver adds the multicast/promisc packet match entry and updates the MCE list with correspondng PF_FUNC. When a PF or VF interface is disabled, the corresponding NIX_RX_MCE_S entry is removed from the MCE list and the MCAM entry will be disabled if the list is empty.
--- drivers/net/ethernet/marvell/octeontx2/af/common.h | 5 + drivers/net/ethernet/marvell/octeontx2/af/mbox.h | 5 +- drivers/net/ethernet/marvell/octeontx2/af/npc.h | 3 +- drivers/net/ethernet/marvell/octeontx2/af/rvu.h | 49 +++- .../ethernet/marvell/octeontx2/af/rvu_debugfs.c | 5 +- .../net/ethernet/marvell/octeontx2/af/rvu_nix.c | 254 +++++++++++++---- .../net/ethernet/marvell/octeontx2/af/rvu_npc.c | 308 ++++++++++++++------- .../net/ethernet/marvell/octeontx2/af/rvu_npc_fs.c | 7 +- .../net/ethernet/marvell/octeontx2/nic/otx2_pf.c | 4 +- 9 files changed, 482 insertions(+), 158 deletions(-)
drivers/net/ethernet/marvell/octeontx2/af/common.h +5 -0
@@ -197,6 +197,11 @@ enum nix_scheduler {#define SDP_CHANNELS 256 +/* The mask is to extract lower 10-bits of channel number +* which CPT will pass to X2P. +*/ +#define NIX_CHAN_CPT_X2P_MASK (0x3ffull) +/* NIX LSO format indices. * As of now TSO is the only one using, so statically assigning indices. */
drivers/net/ethernet/marvell/octeontx2/af/mbox.h +4 -1
@@ -611,7 +611,9 @@ enum nix_af_status {NIX_AF_INVAL_SSO_PF_FUNC =-420 ,NIX_AF_ERR_TX_VTAG_NOSPC =-421 ,NIX_AF_ERR_RX_VTAG_INUSE =-422 , - NIX_AF_ERR_NPC_KEY_NOT_SUPP = -423, +NIX_AF_ERR_PTP_CONFIG_FAIL =-423 , +NIX_AF_ERR_NPC_KEY_NOT_SUPP =-424 , + NIX_AF_ERR_INVALID_NIXBLK = -425, };/* For NIX RX vtag action */
@@ -913,6 +915,7 @@ struct nix_rx_mode {#define NIX_RX_MODE_UCAST BIT(0)#define NIX_RX_MODE_PROMISC BIT(1)#define NIX_RX_MODE_ALLMULTI BIT(2) +#define NIX_RX_MODE_USE_MCE BIT(3)u16 mode; };
drivers/net/ethernet/marvell/octeontx2/af/npc.h +2 -1
@@ -438,7 +438,8 @@ struct nix_tx_action {/* NPC MCAM reserved entry index per nixlf */ #define NIXLF_UCAST_ENTRY 0#define NIXLF_BCAST_ENTRY 1 -#define NIXLF_PROMISC_ENTRY 2 +#define NIXLF_ALLMULTI_ENTRY 2 +#define NIXLF_PROMISC_ENTRY 3struct npc_coalesced_kpu_prfl {#define NPC_SIGN 0x00666f727063706e
drivers/net/ethernet/marvell/octeontx2/af/rvu.h +41 -8
96 lines not on this page · raw message
drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c +4 -1
@@ -2132,6 +2132,7 @@ static int rvu_dbg_npc_mcam_show_rules(struct seq_file *s, void *unused)struct rvu *rvu = s->private;struct npc_mcam *mcam;int pf, vf =-1 ; +bool enabled;int blkaddr;u16 target;u64 hits;
@@ -2173,7 +2174,9 @@ static int rvu_dbg_npc_mcam_show_rules(struct seq_file *s, void *unused) }rvu_dbg_npc_mcam_show_action (s, iter); -seq_printf (s,"\tenabled: %s\n" , iter->enable ?"yes" :"no" ); + + enabled =is_mcam_entry_enabled (rvu, mcam, blkaddr, iter->entry); +seq_printf (s,"\tenabled: %s\n" , enabled ?"yes" :"no" );if (!iter->has_cntr)continue ;
drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c +203 -51
414 lines not on this page · raw message
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c +215 -93
486 lines not on this page · raw message
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_fs.c +5 -2
@@ -1177,9 +1177,12 @@ int rvu_mbox_handler_npc_install_flow(struct rvu *rvu, } err =nix_get_nixlf (rvu, target, &nixlf,NULL ); +if (err) +return -EINVAL ; -/* If interface is uninitialized then do not enable entry */ -if (err || (!req->default_rule && !pfvf->def_ucast_rule)) +/* don't enable rule when nixlf not attached or initialized */ +if (!(is_nixlf_attached (rvu, target) && +test_bit (NIXLF_INITIALIZED , &pfvf->flags))) enable = false;/* Packets reaching NPC in Tx path implies that a
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +3 -1
@@ -1820,9 +1820,11 @@ static void otx2_do_set_rx_mode(struct work_struct *work)if (promisc) req->mode |=NIX_RX_MODE_PROMISC ; -else if (netdev->flags & (IFF_ALLMULTI |IFF_MULTICAST )) +if (netdev->flags & (IFF_ALLMULTI |IFF_MULTICAST )) req->mode |=NIX_RX_MODE_ALLMULTI ; + req->mode |=NIX_RX_MODE_USE_MCE ; +otx2_sync_mbox_msg (&pf->mbox);mutex_unlock (&pf->mbox.lock); }
Signature · 1 line
2.16.5
PATCH 2/4 octeontx2-nicvf: add ndo_set_rx_mode support for multicast & promisc
In reply to Naveen MamindlapalliAdd ndo_set_rx_mode callback handler to configure promisc, multicast and allmulti options for VF driver. Also, modified PF driver ndo_set_rx_mode handler to support multicast and promisc mode independently.
--- .../net/ethernet/marvell/octeontx2/nic/otx2_vf.c | 58 +++++++++++++++++++++- 1 file changed, 56 insertions(+), 2 deletions(-)
drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c +56 -2
@@ -395,6 +395,42 @@ static netdev_tx_t otx2vf_xmit(struct sk_buff *skb, struct net_device *netdev)return NETDEV_TX_OK ; } +static void otx2vf_set_rx_mode (struct net_device *netdev) +{ +struct otx2_nic *vf =netdev_priv (netdev); + +queue_work (vf->otx2_wq, &vf->rx_mode_work); +} + +static void otx2vf_do_set_rx_mode (struct work_struct *work) +{ + struct otx2_nic *vf = container_of(work, struct otx2_nic, rx_mode_work); +struct net_device *netdev = vf->netdev; +unsigned int flags = netdev->flags; +struct nix_rx_mode *req; + +mutex_lock (&vf->mbox.lock); + + req =otx2_mbox_alloc_msg_nix_set_rx_mode (&vf->mbox); +if (!req) { +mutex_unlock (&vf->mbox.lock); +return ; + } + + req->mode =NIX_RX_MODE_UCAST ; + +if (flags &IFF_PROMISC ) + req->mode |=NIX_RX_MODE_PROMISC ; +if (flags & (IFF_ALLMULTI |IFF_MULTICAST )) + req->mode |=NIX_RX_MODE_ALLMULTI ; + + req->mode |=NIX_RX_MODE_USE_MCE ; + +otx2_sync_mbox_msg (&vf->mbox); + +mutex_unlock (&vf->mbox.lock); +} +static int otx2vf_change_mtu (struct net_device *netdev,int new_mtu) {bool if_up =netif_running (netdev);
@@ -432,12 +468,24 @@ static const struct net_device_ops otx2vf_netdev_ops = { .ndo_open = otx2vf_open, .ndo_stop = otx2vf_stop, .ndo_start_xmit = otx2vf_xmit, + .ndo_set_rx_mode = otx2vf_set_rx_mode, .ndo_set_mac_address = otx2_set_mac_address, .ndo_change_mtu = otx2vf_change_mtu, .ndo_get_stats64 = otx2_get_stats64, .ndo_tx_timeout = otx2_tx_timeout, }; +static int otx2_wq_init (struct otx2_nic *vf) +{ + vf->otx2_wq =create_singlethread_workqueue ("otx2vf_wq" ); +if (!vf->otx2_wq) +return -ENOMEM ; + +INIT_WORK (&vf->rx_mode_work, otx2vf_do_set_rx_mode); +INIT_WORK (&vf->reset_task, otx2vf_reset_task); +return 0 ; +} +static int otx2vf_realloc_msix_vectors (struct otx2_nic *vf) {struct otx2_hw *hw = &vf->hw;
@@ -588,8 +636,6 @@ static int otx2vf_probe(struct pci_dev *pdev, const struct pci_device_id *id) netdev->min_mtu =OTX2_MIN_MTU ; netdev->max_mtu =otx2_get_max_mtu (vf); -INIT_WORK (&vf->reset_task, otx2vf_reset_task); -/* To distinguish, for LBK VFs set netdev name explicitly */ if (is_otx2_lbkvf (vf->pdev)) {int n;
@@ -606,6 +652,10 @@ static int otx2vf_probe(struct pci_dev *pdev, const struct pci_device_id *id) goto err_detach_rsrc; } + err =otx2_wq_init (vf); +if (err) + goto err_unreg_netdev; +otx2vf_set_ethtool_ops (netdev);/* Enable pause frames by default */
@@ -614,6 +664,8 @@ static int otx2vf_probe(struct pci_dev *pdev, const struct pci_device_id *id)return 0 ; +err_unreg_netdev: +unregister_netdev (netdev); err_detach_rsrc:if (hw->lmt_base)iounmap (hw->lmt_base);
@@ -644,6 +696,8 @@ static void otx2vf_remove(struct pci_dev *pdev)cancel_work_sync (&vf->reset_task);unregister_netdev (netdev); +if (vf->otx2_wq) +destroy_workqueue (vf->otx2_wq);otx2vf_disable_mbox_intr (vf);otx2_detach_resources (&vf->mbox);
Signature · 1 line
2.16.5
PATCH 3/4 octeontx2-af: add new mailbox to configure VF trust mode
In reply to Naveen MamindlapalliFrom: Hariprasad Kelam <[email protected]>
Add new mailbox to enable PF to configure VF as trusted VF. Trusted VF feature allows VFs to perform priviliged operations such as enabling VF promiscuous mode, all-multicast mode and changing the VF MAC address configured by PF. Refactored the VF interface flags maintained by the AF driver such that the flags do not overlap for various configurations.
--- drivers/net/ethernet/marvell/octeontx2/af/mbox.h | 9 +++++ drivers/net/ethernet/marvell/octeontx2/af/rvu.c | 42 ++++++++++++++++++++++ drivers/net/ethernet/marvell/octeontx2/af/rvu.h | 6 +++- .../net/ethernet/marvell/octeontx2/af/rvu_nix.c | 16 +++++++-- .../net/ethernet/marvell/octeontx2/af/rvu_npc_fs.c | 16 +++++++-- 5 files changed, 83 insertions(+), 6 deletions(-)
drivers/net/ethernet/marvell/octeontx2/af/mbox.h +9 -0
@@ -134,6 +134,7 @@ M(MSIX_OFFSET, 0x005, msix_offset, msg_req, msix_offset_rsp) \ M(VF_FLR, 0x006, vf_flr, msg_req, msg_rsp) \ M(PTP_OP, 0x007, ptp_op, ptp_req, ptp_rsp) \ M(GET_HW_CAP, 0x008, get_hw_cap, msg_req, get_hw_cap_rsp) \ +M (SET_VF_PERM ,0x00b , set_vf_perm, set_vf_perm, msg_rsp) \ /* CGX mbox IDs (range 0x200 - 0x3FF) */ \ M(CGX_START_RXTX, 0x200, cgx_start_rxtx, msg_req, msg_rsp) \M (CGX_STOP_RXTX ,0x201 , cgx_stop_rxtx, msg_req, msg_rsp) \
@@ -1231,6 +1232,14 @@ struct ptp_rsp {u64 clk; }; +struct set_vf_perm { +struct mbox_msghdr hdr; +u16 vf; +#define RESET_VF_PERM BIT_ULL(0) +#define VF_TRUSTED BIT_ULL(1) +u64 flags; +}; +/* CPT mailbox error codes * Range 901 - 1000. */
drivers/net/ethernet/marvell/octeontx2/af/rvu.c +42 -0
48 lines not on this page · raw message
drivers/net/ethernet/marvell/octeontx2/af/rvu.h +5 -1
@@ -223,7 +223,6 @@ struct rvu_pfvf {u16 maxlen;u16 minlen; -u8 pf_set_vf_cfg;u8 mac_addr[ETH_ALEN ];/* MAC address of this PF/VF */ u8 default_mac[ETH_ALEN ];/* MAC address from FWdata */
@@ -249,8 +248,13 @@ struct rvu_pfvf {enum rvu_pfvf_flags {NIXLF_INITIALIZED =0 , +PF_SET_VF_MAC , +PF_SET_VF_CFG , +PF_SET_VF_TRUSTED , }; +#define RVU_CLEAR_VF_PERM ~GENMASK(PF_SET_VF_TRUSTED, PF_SET_VF_MAC) +struct nix_txsch {struct rsrc_bmap schq;u8 lvl;
drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c +14 -2
@@ -3137,15 +3137,22 @@ int rvu_mbox_handler_nix_set_mac_addr(struct rvu *rvu, pfvf =rvu_get_pfvf (rvu, pcifunc); -/* VF can't overwrite admin(PF) changes */ -if (from_vf && pfvf->pf_set_vf_cfg) +/* untrusted VF can't overwrite admin(PF) changes */ +if (!test_bit (PF_SET_VF_TRUSTED , &pfvf->flags) && + (from_vf &&test_bit (PF_SET_VF_MAC , &pfvf->flags))) { +dev_warn (rvu->dev, +"MAC address set by admin(PF) cannot be overwritten by untrusted VF" );return -EPERM ; + }ether_addr_copy (pfvf->mac_addr, req->mac_addr);rvu_npc_install_ucast_entry (rvu, pcifunc, nixlf, pfvf->rx_chan_base, req->mac_addr); +if (test_bit (PF_SET_VF_TRUSTED , &pfvf->flags) && from_vf) +ether_addr_copy (pfvf->default_mac, req->mac_addr); +return 0 ; }
@@ -3188,6 +3195,11 @@ int rvu_mbox_handler_nix_set_rx_mode(struct rvu *rvu, struct nix_rx_mode *req,return 0 ; } +/* untrusted VF can't configure promisc/allmulti */ +if (is_vf (pcifunc) && !test_bit (PF_SET_VF_TRUSTED , &pfvf->flags) && + (promisc || allmulti)) +return 0 ; + err =nix_get_nixlf (rvu, pcifunc, &nixlf,NULL );if (err)return err;
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_fs.c +13 -3
@@ -1103,9 +1103,11 @@ static int npc_install_flow(struct rvu *rvu, int blkaddr, u16 target,if (pf_set_vfs_mac) {ether_addr_copy (pfvf->default_mac, req->packet.dmac);ether_addr_copy (pfvf->mac_addr, req->packet.dmac); +set_bit (PF_SET_VF_MAC , &pfvf->flags); } -if (pfvf->pf_set_vf_cfg && req->vtag0_type ==NIX_AF_LFX_RX_VTAG_TYPE7 ) +if (test_bit (PF_SET_VF_CFG , &pfvf->flags) && + req->vtag0_type ==NIX_AF_LFX_RX_VTAG_TYPE7 ) rule->vfvlan_cfg = true;return 0 ;
@@ -1167,7 +1169,7 @@ int rvu_mbox_handler_npc_install_flow(struct rvu *rvu,/* PF installing for its VF */ if (req->hdr.pcifunc && !from_vf && req->vf) - pfvf->pf_set_vf_cfg =1 ; +set_bit (PF_SET_VF_CFG , &pfvf->flags);/* update req destination mac addr */ if ((req->features & BIT_ULL(NPC_DMAC)) && is_npc_intf_rx(req->intf) &&
@@ -1177,7 +1179,7 @@ int rvu_mbox_handler_npc_install_flow(struct rvu *rvu, } err =nix_get_nixlf (rvu, target, &nixlf,NULL ); -if (err) +if (err &&is_npc_intf_rx (req->intf) && !pf_set_vfs_mac)return -EINVAL ;/* don't enable rule when nixlf not attached or initialized */
@@ -1196,6 +1198,14 @@ int rvu_mbox_handler_npc_install_flow(struct rvu *rvu,if (from_vf && !enable)return -EINVAL ; +/* PF sets VF mac & VF NIXLF is not attached, update the mac addr */ +if (pf_set_vfs_mac && !enable) { +ether_addr_copy (pfvf->default_mac, req->packet.dmac); +ether_addr_copy (pfvf->mac_addr, req->packet.dmac); +set_bit (PF_SET_VF_MAC , &pfvf->flags); +return 0 ; + } +/* If message is from VF then its flow should not overlap with * reserved unicast flow. */
Signature · 1 line
2.16.5
PATCH 4/4 octeontx2-pf: add support for ndo_set_vf_trust
In reply to Naveen MamindlapalliFrom: Hariprasad Kelam <[email protected]>
Add support for setting a VF as a trusted VF by PF admin. Trusted VF feature allows VFs to perform priviliged operations such as enabling VF promiscuous mode, all-multicast mode and changing the VF MAC address even if it was assigned by PF.
--- .../ethernet/marvell/octeontx2/nic/otx2_common.h | 6 + .../net/ethernet/marvell/octeontx2/nic/otx2_pf.c | 128 +++++++++++++++++---- 2 files changed, 109 insertions(+), 25 deletions(-)
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +6 -0
@@ -223,6 +223,11 @@ struct otx2_hw {u64 *nix_lmt_base; }; +enum vfperm { +OTX2_RESET_VF_PERM , +OTX2_TRUSTED_VF , +}; +struct otx2_vf_config {struct otx2_nic *pf;struct delayed_work link_event_work;
@@ -230,6 +235,7 @@ struct otx2_vf_config {u8 mac[ETH_ALEN ];u16 vlan;int tx_vtag_idx; +bool trusted; };struct flr_work {
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +103 -25
218 lines not on this page · raw message
Signature · 1 line
2.16.5
This series was applied to netdev/net-next.git (refs/heads/master):
Hello:
This series was applied to netdev/net-next.git (refs/heads/master):
Quoted 9 lines · On Fri, 11 Jun 2021 15:12:01 +0530 you wrote:
This series adds support for trusted VF. The trusted VF support allows VFs to perform priviliged operations such as setting VF interface in promiscuous mode, all-multicast mode and also changing the VF MAC address even if it was asssigned by PF.
Patches #1 and #2 provides the necessary functionality for supporting promiscuous and multicast packets on both the PF and VF.
[...]
Here is the summary with links:
- [net-next,1/4] octeontx2-af: add support for multicast/promisc packet replication feature
https://git.kernel.org/netdev/net-next/c/967db3529eca - [net-next,2/4] octeontx2-nicvf: add ndo_set_rx_mode support for multicast & promisc https://git.kernel.org/netdev/net-next/c/cbc100aa2205 - [net-next,3/4] octeontx2-af: add new mailbox to configure VF trust mode https://git.kernel.org/netdev/net-next/c/bd4302b8fd16 - [net-next,4/4] octeontx2-pf: add support for ndo_set_vf_trust https://git.kernel.org/netdev/net-next/c/b1dc20407b59
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html