Message ID | 1307597376-5379-3-git-send-email-mchan@broadcom.com |
---|---|
State | Accepted, archived |
Delegated to: | David Miller |
Headers | show |
From: "Michael Chan" <mchan@broadcom.com> Date: Wed, 8 Jun 2011 22:29:34 -0700 > From: Eddie Wai <eddie.wai@broadcom.com> > > This reduces the likelihood of port re-use when re-loading the driver. > > Signed-off-by: Eddie Wai <eddie.wai@broadcom.com> > Signed-off-by: Michael Chan <mchan@broadcom.com> Applied. -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Wed, 8 Jun 2011 22:29:34 -0700 "Michael Chan" <mchan@broadcom.com> wrote: > static int cnic_cm_alloc_mem(struct cnic_dev *dev) > { > struct cnic_local *cp = dev->cnic_priv; > + u32 port_id; > > cp->csk_tbl = kzalloc(sizeof(struct cnic_sock) * MAX_CM_SK_TBL_SZ, > GFP_KERNEL); > if (!cp->csk_tbl) > return -ENOMEM; > > + get_random_bytes(&port_id, sizeof(port_id)); I think random32() or it's alias net_random() would be sufficient for your needs here. -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Thu, 2011-06-09 at 08:27 -0700, Stephen Hemminger wrote: > On Wed, 8 Jun 2011 22:29:34 -0700 > "Michael Chan" <mchan@broadcom.com> wrote: > > > static int cnic_cm_alloc_mem(struct cnic_dev *dev) > > { > > struct cnic_local *cp = dev->cnic_priv; > > + u32 port_id; > > > > cp->csk_tbl = kzalloc(sizeof(struct cnic_sock) * MAX_CM_SK_TBL_SZ, > > GFP_KERNEL); > > if (!cp->csk_tbl) > > return -ENOMEM; > > > > + get_random_bytes(&port_id, sizeof(port_id)); > > I think random32() or it's alias net_random() would be sufficient > for your needs here. > random32() is pseudo random so we can get the same number after reboot, right? One scenario is that we may be booting from an iSCSI target, but due to some failure, the user may be rebooting multiple times rapidly. We want to use a different port during each boot. -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Thu, 9 Jun 2011 18:08:00 -0700 "Michael Chan" <mchan@broadcom.com> wrote: > > On Thu, 2011-06-09 at 08:27 -0700, Stephen Hemminger wrote: > > On Wed, 8 Jun 2011 22:29:34 -0700 > > "Michael Chan" <mchan@broadcom.com> wrote: > > > > > static int cnic_cm_alloc_mem(struct cnic_dev *dev) > > > { > > > struct cnic_local *cp = dev->cnic_priv; > > > + u32 port_id; > > > > > > cp->csk_tbl = kzalloc(sizeof(struct cnic_sock) * MAX_CM_SK_TBL_SZ, > > > GFP_KERNEL); > > > if (!cp->csk_tbl) > > > return -ENOMEM; > > > > > > + get_random_bytes(&port_id, sizeof(port_id)); > > > > I think random32() or it's alias net_random() would be sufficient > > for your needs here. > > > > random32() is pseudo random so we can get the same number after reboot, > right? One scenario is that we may be booting from an iSCSI target, but > due to some failure, the user may be rebooting multiple times rapidly. > We want to use a different port during each boot. random32 is seeded off get_random_bytes at boot. -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Le jeudi 09 juin 2011 à 21:01 -0700, Stephen Hemminger a écrit : > On Thu, 9 Jun 2011 18:08:00 -0700 > "Michael Chan" <mchan@broadcom.com> wrote: > > > > > On Thu, 2011-06-09 at 08:27 -0700, Stephen Hemminger wrote: > > > On Wed, 8 Jun 2011 22:29:34 -0700 > > > "Michael Chan" <mchan@broadcom.com> wrote: > > > > > > > static int cnic_cm_alloc_mem(struct cnic_dev *dev) > > > > { > > > > struct cnic_local *cp = dev->cnic_priv; > > > > + u32 port_id; > > > > > > > > cp->csk_tbl = kzalloc(sizeof(struct cnic_sock) * MAX_CM_SK_TBL_SZ, > > > > GFP_KERNEL); > > > > if (!cp->csk_tbl) > > > > return -ENOMEM; > > > > > > > > + get_random_bytes(&port_id, sizeof(port_id)); > > > > > > I think random32() or it's alias net_random() would be sufficient > > > for your needs here. > > > > > > > random32() is pseudo random so we can get the same number after reboot, > > right? One scenario is that we may be booting from an iSCSI target, but > > due to some failure, the user may be rebooting multiple times rapidly. > > We want to use a different port during each boot. > > random32 is seeded off get_random_bytes at boot. cnic_cm_alloc_mem() is apparently called one time per boot, it seems OK to call get_random_bytes() in this case ? -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Stephen Hemminger wrote: > On Thu, 9 Jun 2011 18:08:00 -0700 > "Michael Chan" <mchan@broadcom.com> wrote: > > random32() is pseudo random so we can get the same number after reboot, > > right? One scenario is that we may be booting from an iSCSI target, but > > due to some failure, the user may be rebooting multiple times rapidly. > > We want to use a different port during each boot. > > random32 is seeded off get_random_bytes at boot. Thanks. We'll change it to random32() in our next patchset then. -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/drivers/net/cnic.c b/drivers/net/cnic.c index ea7245c..a529bde 100644 --- a/drivers/net/cnic.c +++ b/drivers/net/cnic.c @@ -605,11 +605,12 @@ static int cnic_unregister_device(struct cnic_dev *dev, int ulp_type) } EXPORT_SYMBOL(cnic_unregister_driver); -static int cnic_init_id_tbl(struct cnic_id_tbl *id_tbl, u32 size, u32 start_id) +static int cnic_init_id_tbl(struct cnic_id_tbl *id_tbl, u32 size, u32 start_id, + u32 next) { id_tbl->start = start_id; id_tbl->max = size; - id_tbl->next = 0; + id_tbl->next = next; spin_lock_init(&id_tbl->lock); id_tbl->table = kzalloc(DIV_ROUND_UP(size, 32) * 4, GFP_KERNEL); if (!id_tbl->table) @@ -3804,14 +3805,17 @@ static void cnic_cm_free_mem(struct cnic_dev *dev) static int cnic_cm_alloc_mem(struct cnic_dev *dev) { struct cnic_local *cp = dev->cnic_priv; + u32 port_id; cp->csk_tbl = kzalloc(sizeof(struct cnic_sock) * MAX_CM_SK_TBL_SZ, GFP_KERNEL); if (!cp->csk_tbl) return -ENOMEM; + get_random_bytes(&port_id, sizeof(port_id)); + port_id %= CNIC_LOCAL_PORT_RANGE; if (cnic_init_id_tbl(&cp->csk_port_tbl, CNIC_LOCAL_PORT_RANGE, - CNIC_LOCAL_PORT_MIN)) { + CNIC_LOCAL_PORT_MIN, port_id)) { cnic_cm_free_mem(dev); return -ENOMEM; } @@ -4829,7 +4833,7 @@ static int cnic_start_bnx2x_hw(struct cnic_dev *dev) pfid = cp->pfid; ret = cnic_init_id_tbl(&cp->cid_tbl, MAX_ISCSI_TBL_SZ, - cp->iscsi_start_cid); + cp->iscsi_start_cid, 0); if (ret) return -ENOMEM; @@ -4837,7 +4841,7 @@ static int cnic_start_bnx2x_hw(struct cnic_dev *dev) if (BNX2X_CHIP_IS_E2(cp->chip_id)) { ret = cnic_init_id_tbl(&cp->fcoe_cid_tbl, BNX2X_FCOE_NUM_CONNECTIONS, - cp->fcoe_start_cid); + cp->fcoe_start_cid, 0); if (ret) return -ENOMEM;