1
0
Fork 0
mirror of https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git synced 2025-01-22 07:53:11 -05:00

net/ncsi: fix locking in Get MAC Address handling

Obtaining RTNL lock in a response handler is not allowed since it runs
in an atomic softirq context. Postpone setting the MAC address by adding
a dedicated step to the configuration FSM.

Fixes: 790071347a ("net/ncsi: change from ndo_set_mac_address to dev_set_mac_address")
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/20241129-potin-revert-ncsi-set-mac-addr-v1-1-94ea2cb596af@gmail.com
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Tested-by: Potin Lai <potin.lai.pt@gmail.com>
Link: https://patch.msgid.link/20250109145054.30925-1-fercerpav@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Paul Fertser 2025-01-09 17:50:54 +03:00 committed by Jakub Kicinski
parent 76201b5979
commit 9e2bbab94b
3 changed files with 22 additions and 15 deletions

View file

@ -289,6 +289,7 @@ enum {
ncsi_dev_state_config_sp = 0x0301, ncsi_dev_state_config_sp = 0x0301,
ncsi_dev_state_config_cis, ncsi_dev_state_config_cis,
ncsi_dev_state_config_oem_gma, ncsi_dev_state_config_oem_gma,
ncsi_dev_state_config_apply_mac,
ncsi_dev_state_config_clear_vids, ncsi_dev_state_config_clear_vids,
ncsi_dev_state_config_svf, ncsi_dev_state_config_svf,
ncsi_dev_state_config_ev, ncsi_dev_state_config_ev,
@ -322,6 +323,7 @@ struct ncsi_dev_priv {
#define NCSI_DEV_RESHUFFLE 4 #define NCSI_DEV_RESHUFFLE 4
#define NCSI_DEV_RESET 8 /* Reset state of NC */ #define NCSI_DEV_RESET 8 /* Reset state of NC */
unsigned int gma_flag; /* OEM GMA flag */ unsigned int gma_flag; /* OEM GMA flag */
struct sockaddr pending_mac; /* MAC address received from GMA */
spinlock_t lock; /* Protect the NCSI device */ spinlock_t lock; /* Protect the NCSI device */
unsigned int package_probe_id;/* Current ID during probe */ unsigned int package_probe_id;/* Current ID during probe */
unsigned int package_num; /* Number of packages */ unsigned int package_num; /* Number of packages */

View file

@ -1038,7 +1038,7 @@ static void ncsi_configure_channel(struct ncsi_dev_priv *ndp)
: ncsi_dev_state_config_clear_vids; : ncsi_dev_state_config_clear_vids;
break; break;
case ncsi_dev_state_config_oem_gma: case ncsi_dev_state_config_oem_gma:
nd->state = ncsi_dev_state_config_clear_vids; nd->state = ncsi_dev_state_config_apply_mac;
nca.package = np->id; nca.package = np->id;
nca.channel = nc->id; nca.channel = nc->id;
@ -1050,10 +1050,22 @@ static void ncsi_configure_channel(struct ncsi_dev_priv *ndp)
nca.type = NCSI_PKT_CMD_OEM; nca.type = NCSI_PKT_CMD_OEM;
ret = ncsi_gma_handler(&nca, nc->version.mf_id); ret = ncsi_gma_handler(&nca, nc->version.mf_id);
} }
if (ret < 0) if (ret < 0) {
nd->state = ncsi_dev_state_config_clear_vids;
schedule_work(&ndp->work); schedule_work(&ndp->work);
}
break; break;
case ncsi_dev_state_config_apply_mac:
rtnl_lock();
ret = dev_set_mac_address(dev, &ndp->pending_mac, NULL);
rtnl_unlock();
if (ret < 0)
netdev_warn(dev, "NCSI: 'Writing MAC address to device failed\n");
nd->state = ncsi_dev_state_config_clear_vids;
fallthrough;
case ncsi_dev_state_config_clear_vids: case ncsi_dev_state_config_clear_vids:
case ncsi_dev_state_config_svf: case ncsi_dev_state_config_svf:
case ncsi_dev_state_config_ev: case ncsi_dev_state_config_ev:

View file

@ -628,16 +628,14 @@ static int ncsi_rsp_handler_snfc(struct ncsi_request *nr)
static int ncsi_rsp_handler_oem_gma(struct ncsi_request *nr, int mfr_id) static int ncsi_rsp_handler_oem_gma(struct ncsi_request *nr, int mfr_id)
{ {
struct ncsi_dev_priv *ndp = nr->ndp; struct ncsi_dev_priv *ndp = nr->ndp;
struct sockaddr *saddr = &ndp->pending_mac;
struct net_device *ndev = ndp->ndev.dev; struct net_device *ndev = ndp->ndev.dev;
struct ncsi_rsp_oem_pkt *rsp; struct ncsi_rsp_oem_pkt *rsp;
struct sockaddr saddr;
u32 mac_addr_off = 0; u32 mac_addr_off = 0;
int ret = 0;
/* Get the response header */ /* Get the response header */
rsp = (struct ncsi_rsp_oem_pkt *)skb_network_header(nr->rsp); rsp = (struct ncsi_rsp_oem_pkt *)skb_network_header(nr->rsp);
saddr.sa_family = ndev->type;
ndev->priv_flags |= IFF_LIVE_ADDR_CHANGE; ndev->priv_flags |= IFF_LIVE_ADDR_CHANGE;
if (mfr_id == NCSI_OEM_MFR_BCM_ID) if (mfr_id == NCSI_OEM_MFR_BCM_ID)
mac_addr_off = BCM_MAC_ADDR_OFFSET; mac_addr_off = BCM_MAC_ADDR_OFFSET;
@ -646,22 +644,17 @@ static int ncsi_rsp_handler_oem_gma(struct ncsi_request *nr, int mfr_id)
else if (mfr_id == NCSI_OEM_MFR_INTEL_ID) else if (mfr_id == NCSI_OEM_MFR_INTEL_ID)
mac_addr_off = INTEL_MAC_ADDR_OFFSET; mac_addr_off = INTEL_MAC_ADDR_OFFSET;
memcpy(saddr.sa_data, &rsp->data[mac_addr_off], ETH_ALEN); saddr->sa_family = ndev->type;
memcpy(saddr->sa_data, &rsp->data[mac_addr_off], ETH_ALEN);
if (mfr_id == NCSI_OEM_MFR_BCM_ID || mfr_id == NCSI_OEM_MFR_INTEL_ID) if (mfr_id == NCSI_OEM_MFR_BCM_ID || mfr_id == NCSI_OEM_MFR_INTEL_ID)
eth_addr_inc((u8 *)saddr.sa_data); eth_addr_inc((u8 *)saddr->sa_data);
if (!is_valid_ether_addr((const u8 *)saddr.sa_data)) if (!is_valid_ether_addr((const u8 *)saddr->sa_data))
return -ENXIO; return -ENXIO;
/* Set the flag for GMA command which should only be called once */ /* Set the flag for GMA command which should only be called once */
ndp->gma_flag = 1; ndp->gma_flag = 1;
rtnl_lock(); return 0;
ret = dev_set_mac_address(ndev, &saddr, NULL);
rtnl_unlock();
if (ret < 0)
netdev_warn(ndev, "NCSI: 'Writing mac address to device failed\n");
return ret;
} }
/* Response handler for Mellanox card */ /* Response handler for Mellanox card */