Commit f018b73a authored by Joe Eykholt's avatar Joe Eykholt Committed by James Bottomley

[SCSI] libfc, libfcoe, fcoe: use smp_processor_id() only when preempt disabled

When the kernel is configured for preemption, using smp_processor_id()
when preemption is enabled causes a warning backtrace and is wrong
since we could move off of that CPU as soon as we get the ID,
and we would be referencing the wrong CPU, and possibly an invalid one
if it could be hotswapped out.

Remove the fc_lport_get_stats() function and explicitly use per_cpu_ptr()
to get the statistics.  Where preemption has been disabled by holding
a _bh lock continue to use smp_processor_id(), but otherwise use
get_cpu()/put_cpu().

In fcoe_recv_frame() also changed the cases where we return in the
middle to do a goto to the code which bumps ErrorFrames and does
a put_cpu().  Two of these cases didn't bump ErrorFrames before, but
doing so is harmless because they "can't happen", due to prior length
checks.

Also rearranged code in fcoe_recv_frame() to have only one call to
fc_exch_recv().  It's just as efficient and saves a call to put_cpu().

In fc_fcp.c, adjusted a FIXME comment for code which doesn't need fixing.
Signed-off-by: default avatarJoe Eykholt <jeykholt@cisco.com>
Signed-off-by: default avatarRobert Love <robert.w.love@intel.com>
Signed-off-by: default avatarJames Bottomley <James.Bottomley@suse.de>
parent b3ef990c
...@@ -1075,7 +1075,7 @@ static void fcoe_percpu_thread_destroy(unsigned int cpu) ...@@ -1075,7 +1075,7 @@ static void fcoe_percpu_thread_destroy(unsigned int cpu)
struct sk_buff *skb; struct sk_buff *skb;
#ifdef CONFIG_SMP #ifdef CONFIG_SMP
struct fcoe_percpu_s *p0; struct fcoe_percpu_s *p0;
unsigned targ_cpu = smp_processor_id(); unsigned targ_cpu = get_cpu();
#endif /* CONFIG_SMP */ #endif /* CONFIG_SMP */
FCOE_DBG("Destroying receive thread for CPU %d\n", cpu); FCOE_DBG("Destroying receive thread for CPU %d\n", cpu);
...@@ -1131,6 +1131,7 @@ static void fcoe_percpu_thread_destroy(unsigned int cpu) ...@@ -1131,6 +1131,7 @@ static void fcoe_percpu_thread_destroy(unsigned int cpu)
kfree_skb(skb); kfree_skb(skb);
spin_unlock_bh(&p->fcoe_rx_list.lock); spin_unlock_bh(&p->fcoe_rx_list.lock);
} }
put_cpu();
#else #else
/* /*
* This a non-SMP scenario where the singular Rx thread is * This a non-SMP scenario where the singular Rx thread is
...@@ -1299,8 +1300,8 @@ int fcoe_rcv(struct sk_buff *skb, struct net_device *netdev, ...@@ -1299,8 +1300,8 @@ int fcoe_rcv(struct sk_buff *skb, struct net_device *netdev,
return 0; return 0;
err: err:
fc_lport_get_stats(lport)->ErrorFrames++; per_cpu_ptr(lport->dev_stats, get_cpu())->ErrorFrames++;
put_cpu();
err2: err2:
kfree_skb(skb); kfree_skb(skb);
return -1; return -1;
...@@ -1529,9 +1530,10 @@ int fcoe_xmit(struct fc_lport *lport, struct fc_frame *fp) ...@@ -1529,9 +1530,10 @@ int fcoe_xmit(struct fc_lport *lport, struct fc_frame *fp)
skb_shinfo(skb)->gso_size = 0; skb_shinfo(skb)->gso_size = 0;
} }
/* update tx stats: regardless if LLD fails */ /* update tx stats: regardless if LLD fails */
stats = fc_lport_get_stats(lport); stats = per_cpu_ptr(lport->dev_stats, get_cpu());
stats->TxFrames++; stats->TxFrames++;
stats->TxWords += wlen; stats->TxWords += wlen;
put_cpu();
/* send down to lld */ /* send down to lld */
fr_dev(fp) = lport; fr_dev(fp) = lport;
...@@ -1595,7 +1597,7 @@ static void fcoe_recv_frame(struct sk_buff *skb) ...@@ -1595,7 +1597,7 @@ static void fcoe_recv_frame(struct sk_buff *skb)
hp = (struct fcoe_hdr *) skb_network_header(skb); hp = (struct fcoe_hdr *) skb_network_header(skb);
fh = (struct fc_frame_header *) skb_transport_header(skb); fh = (struct fc_frame_header *) skb_transport_header(skb);
stats = fc_lport_get_stats(lport); stats = per_cpu_ptr(lport->dev_stats, get_cpu());
if (unlikely(FC_FCOE_DECAPS_VER(hp) != FC_FCOE_VER)) { if (unlikely(FC_FCOE_DECAPS_VER(hp) != FC_FCOE_VER)) {
if (stats->ErrorFrames < 5) if (stats->ErrorFrames < 5)
printk(KERN_WARNING "fcoe: FCoE version " printk(KERN_WARNING "fcoe: FCoE version "
...@@ -1604,9 +1606,7 @@ static void fcoe_recv_frame(struct sk_buff *skb) ...@@ -1604,9 +1606,7 @@ static void fcoe_recv_frame(struct sk_buff *skb)
"initiator supports version " "initiator supports version "
"%x\n", FC_FCOE_DECAPS_VER(hp), "%x\n", FC_FCOE_DECAPS_VER(hp),
FC_FCOE_VER); FC_FCOE_VER);
stats->ErrorFrames++; goto drop;
kfree_skb(skb);
return;
} }
skb_pull(skb, sizeof(struct fcoe_hdr)); skb_pull(skb, sizeof(struct fcoe_hdr));
...@@ -1621,16 +1621,12 @@ static void fcoe_recv_frame(struct sk_buff *skb) ...@@ -1621,16 +1621,12 @@ static void fcoe_recv_frame(struct sk_buff *skb)
fr_sof(fp) = hp->fcoe_sof; fr_sof(fp) = hp->fcoe_sof;
/* Copy out the CRC and EOF trailer for access */ /* Copy out the CRC and EOF trailer for access */
if (skb_copy_bits(skb, fr_len, &crc_eof, sizeof(crc_eof))) { if (skb_copy_bits(skb, fr_len, &crc_eof, sizeof(crc_eof)))
kfree_skb(skb); goto drop;
return;
}
fr_eof(fp) = crc_eof.fcoe_eof; fr_eof(fp) = crc_eof.fcoe_eof;
fr_crc(fp) = crc_eof.fcoe_crc32; fr_crc(fp) = crc_eof.fcoe_crc32;
if (pskb_trim(skb, fr_len)) { if (pskb_trim(skb, fr_len))
kfree_skb(skb); goto drop;
return;
}
/* /*
* We only check CRC if no offload is available and if it is * We only check CRC if no offload is available and if it is
...@@ -1644,25 +1640,27 @@ static void fcoe_recv_frame(struct sk_buff *skb) ...@@ -1644,25 +1640,27 @@ static void fcoe_recv_frame(struct sk_buff *skb)
fr_flags(fp) |= FCPHF_CRC_UNCHECKED; fr_flags(fp) |= FCPHF_CRC_UNCHECKED;
fh = fc_frame_header_get(fp); fh = fc_frame_header_get(fp);
if (fh->fh_r_ctl == FC_RCTL_DD_SOL_DATA && if ((fh->fh_r_ctl != FC_RCTL_DD_SOL_DATA ||
fh->fh_type == FC_TYPE_FCP) { fh->fh_type != FC_TYPE_FCP) &&
fc_exch_recv(lport, fp); (fr_flags(fp) & FCPHF_CRC_UNCHECKED)) {
return;
}
if (fr_flags(fp) & FCPHF_CRC_UNCHECKED) {
if (le32_to_cpu(fr_crc(fp)) != if (le32_to_cpu(fr_crc(fp)) !=
~crc32(~0, skb->data, fr_len)) { ~crc32(~0, skb->data, fr_len)) {
if (stats->InvalidCRCCount < 5) if (stats->InvalidCRCCount < 5)
printk(KERN_WARNING "fcoe: dropping " printk(KERN_WARNING "fcoe: dropping "
"frame with CRC error\n"); "frame with CRC error\n");
stats->InvalidCRCCount++; stats->InvalidCRCCount++;
stats->ErrorFrames++; goto drop;
fc_frame_free(fp);
return;
} }
fr_flags(fp) &= ~FCPHF_CRC_UNCHECKED; fr_flags(fp) &= ~FCPHF_CRC_UNCHECKED;
} }
put_cpu();
fc_exch_recv(lport, fp); fc_exch_recv(lport, fp);
return;
drop:
stats->ErrorFrames++;
put_cpu();
kfree_skb(skb);
} }
/** /**
...@@ -1835,8 +1833,9 @@ static int fcoe_device_notification(struct notifier_block *notifier, ...@@ -1835,8 +1833,9 @@ static int fcoe_device_notification(struct notifier_block *notifier,
if (link_possible && !fcoe_link_ok(lport)) if (link_possible && !fcoe_link_ok(lport))
fcoe_ctlr_link_up(&fcoe->ctlr); fcoe_ctlr_link_up(&fcoe->ctlr);
else if (fcoe_ctlr_link_down(&fcoe->ctlr)) { else if (fcoe_ctlr_link_down(&fcoe->ctlr)) {
stats = fc_lport_get_stats(lport); stats = per_cpu_ptr(lport->dev_stats, get_cpu());
stats->LinkFailureCount++; stats->LinkFailureCount++;
put_cpu();
fcoe_clean_pending_queue(lport); fcoe_clean_pending_queue(lport);
} }
out: out:
......
...@@ -550,7 +550,7 @@ EXPORT_SYMBOL(fcoe_ctlr_els_send); ...@@ -550,7 +550,7 @@ EXPORT_SYMBOL(fcoe_ctlr_els_send);
* fcoe_ctlr_age_fcfs() - Reset and free all old FCFs for a controller * fcoe_ctlr_age_fcfs() - Reset and free all old FCFs for a controller
* @fip: The FCoE controller to free FCFs on * @fip: The FCoE controller to free FCFs on
* *
* Called with lock held. * Called with lock held and preemption disabled.
* *
* An FCF is considered old if we have missed three advertisements. * An FCF is considered old if we have missed three advertisements.
* That is, there have been no valid advertisement from it for three * That is, there have been no valid advertisement from it for three
...@@ -567,17 +567,20 @@ static void fcoe_ctlr_age_fcfs(struct fcoe_ctlr *fip) ...@@ -567,17 +567,20 @@ static void fcoe_ctlr_age_fcfs(struct fcoe_ctlr *fip)
struct fcoe_fcf *next; struct fcoe_fcf *next;
unsigned long sel_time = 0; unsigned long sel_time = 0;
unsigned long mda_time = 0; unsigned long mda_time = 0;
struct fcoe_dev_stats *stats;
list_for_each_entry_safe(fcf, next, &fip->fcfs, list) { list_for_each_entry_safe(fcf, next, &fip->fcfs, list) {
mda_time = fcf->fka_period + (fcf->fka_period >> 1); mda_time = fcf->fka_period + (fcf->fka_period >> 1);
if ((fip->sel_fcf == fcf) && if ((fip->sel_fcf == fcf) &&
(time_after(jiffies, fcf->time + mda_time))) { (time_after(jiffies, fcf->time + mda_time))) {
mod_timer(&fip->timer, jiffies + mda_time); mod_timer(&fip->timer, jiffies + mda_time);
fc_lport_get_stats(fip->lp)->MissDiscAdvCount++; stats = per_cpu_ptr(fip->lp->dev_stats,
smp_processor_id());
stats->MissDiscAdvCount++;
printk(KERN_INFO "libfcoe: host%d: Missing Discovery " printk(KERN_INFO "libfcoe: host%d: Missing Discovery "
"Advertisement for fab %llx count %lld\n", "Advertisement for fab %llx count %lld\n",
fip->lp->host->host_no, fcf->fabric_name, fip->lp->host->host_no, fcf->fabric_name,
fc_lport_get_stats(fip->lp)->MissDiscAdvCount); stats->MissDiscAdvCount);
} }
if (time_after(jiffies, fcf->time + fcf->fka_period * 3 + if (time_after(jiffies, fcf->time + fcf->fka_period * 3 +
msecs_to_jiffies(FIP_FCF_FUZZ * 3))) { msecs_to_jiffies(FIP_FCF_FUZZ * 3))) {
...@@ -587,7 +590,9 @@ static void fcoe_ctlr_age_fcfs(struct fcoe_ctlr *fip) ...@@ -587,7 +590,9 @@ static void fcoe_ctlr_age_fcfs(struct fcoe_ctlr *fip)
WARN_ON(!fip->fcf_count); WARN_ON(!fip->fcf_count);
fip->fcf_count--; fip->fcf_count--;
kfree(fcf); kfree(fcf);
fc_lport_get_stats(fip->lp)->VLinkFailureCount++; stats = per_cpu_ptr(fip->lp->dev_stats,
smp_processor_id());
stats->VLinkFailureCount++;
} else if (fcoe_ctlr_mtu_valid(fcf) && } else if (fcoe_ctlr_mtu_valid(fcf) &&
(!sel_time || time_before(sel_time, fcf->time))) { (!sel_time || time_before(sel_time, fcf->time))) {
sel_time = fcf->time; sel_time = fcf->time;
...@@ -900,9 +905,10 @@ static void fcoe_ctlr_recv_els(struct fcoe_ctlr *fip, struct sk_buff *skb) ...@@ -900,9 +905,10 @@ static void fcoe_ctlr_recv_els(struct fcoe_ctlr *fip, struct sk_buff *skb)
fr_eof(fp) = FC_EOF_T; fr_eof(fp) = FC_EOF_T;
fr_dev(fp) = lport; fr_dev(fp) = lport;
stats = fc_lport_get_stats(lport); stats = per_cpu_ptr(lport->dev_stats, get_cpu());
stats->RxFrames++; stats->RxFrames++;
stats->RxWords += skb->len / FIP_BPW; stats->RxWords += skb->len / FIP_BPW;
put_cpu();
fc_exch_recv(lport, fp); fc_exch_recv(lport, fp);
return; return;
...@@ -1000,7 +1006,8 @@ static void fcoe_ctlr_recv_clr_vlink(struct fcoe_ctlr *fip, ...@@ -1000,7 +1006,8 @@ static void fcoe_ctlr_recv_clr_vlink(struct fcoe_ctlr *fip,
LIBFCOE_FIP_DBG(fip, "performing Clear Virtual Link\n"); LIBFCOE_FIP_DBG(fip, "performing Clear Virtual Link\n");
spin_lock_bh(&fip->lock); spin_lock_bh(&fip->lock);
fc_lport_get_stats(lport)->VLinkFailureCount++; per_cpu_ptr(lport->dev_stats,
smp_processor_id())->VLinkFailureCount++;
fcoe_ctlr_reset(fip); fcoe_ctlr_reset(fip);
spin_unlock_bh(&fip->lock); spin_unlock_bh(&fip->lock);
......
...@@ -676,9 +676,10 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport, ...@@ -676,9 +676,10 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
} }
memset(ep, 0, sizeof(*ep)); memset(ep, 0, sizeof(*ep));
cpu = smp_processor_id(); cpu = get_cpu();
pool = per_cpu_ptr(mp->pool, cpu); pool = per_cpu_ptr(mp->pool, cpu);
spin_lock_bh(&pool->lock); spin_lock_bh(&pool->lock);
put_cpu();
index = pool->next_index; index = pool->next_index;
/* allocate new exch from pool */ /* allocate new exch from pool */
while (fc_exch_ptr_get(pool, index)) { while (fc_exch_ptr_get(pool, index)) {
......
...@@ -484,13 +484,14 @@ static void fc_fcp_recv_data(struct fc_fcp_pkt *fsp, struct fc_frame *fp) ...@@ -484,13 +484,14 @@ static void fc_fcp_recv_data(struct fc_fcp_pkt *fsp, struct fc_frame *fp)
if (~crc != le32_to_cpu(fr_crc(fp))) { if (~crc != le32_to_cpu(fr_crc(fp))) {
crc_err: crc_err:
stats = fc_lport_get_stats(lport); stats = per_cpu_ptr(lport->dev_stats, get_cpu());
stats->ErrorFrames++; stats->ErrorFrames++;
/* FIXME - per cpu count, not total count! */ /* per cpu count, not total count, but OK for limit */
if (stats->InvalidCRCCount++ < 5) if (stats->InvalidCRCCount++ < 5)
printk(KERN_WARNING "libfc: CRC error on data " printk(KERN_WARNING "libfc: CRC error on data "
"frame for port (%6x)\n", "frame for port (%6x)\n",
fc_host_port_id(lport->host)); fc_host_port_id(lport->host));
put_cpu();
/* /*
* Assume the frame is total garbage. * Assume the frame is total garbage.
* We may have copied it over the good part * We may have copied it over the good part
...@@ -1819,7 +1820,7 @@ int fc_queuecommand(struct scsi_cmnd *sc_cmd, void (*done)(struct scsi_cmnd *)) ...@@ -1819,7 +1820,7 @@ int fc_queuecommand(struct scsi_cmnd *sc_cmd, void (*done)(struct scsi_cmnd *))
/* /*
* setup the data direction * setup the data direction
*/ */
stats = fc_lport_get_stats(lport); stats = per_cpu_ptr(lport->dev_stats, get_cpu());
if (sc_cmd->sc_data_direction == DMA_FROM_DEVICE) { if (sc_cmd->sc_data_direction == DMA_FROM_DEVICE) {
fsp->req_flags = FC_SRB_READ; fsp->req_flags = FC_SRB_READ;
stats->InputRequests++; stats->InputRequests++;
...@@ -1832,6 +1833,7 @@ int fc_queuecommand(struct scsi_cmnd *sc_cmd, void (*done)(struct scsi_cmnd *)) ...@@ -1832,6 +1833,7 @@ int fc_queuecommand(struct scsi_cmnd *sc_cmd, void (*done)(struct scsi_cmnd *))
fsp->req_flags = 0; fsp->req_flags = 0;
stats->ControlRequests++; stats->ControlRequests++;
} }
put_cpu();
fsp->tgt_flags = rpriv->flags; fsp->tgt_flags = rpriv->flags;
......
...@@ -917,15 +917,6 @@ static inline void fc_lport_free_stats(struct fc_lport *lport) ...@@ -917,15 +917,6 @@ static inline void fc_lport_free_stats(struct fc_lport *lport)
free_percpu(lport->dev_stats); free_percpu(lport->dev_stats);
} }
/**
* fc_lport_get_stats() - Get a local port's statistics
* @lport: The local port whose statistics are to be retreived
*/
static inline struct fcoe_dev_stats *fc_lport_get_stats(struct fc_lport *lport)
{
return per_cpu_ptr(lport->dev_stats, smp_processor_id());
}
/** /**
* lport_priv() - Return the private data from a local port * lport_priv() - Return the private data from a local port
* @lport: The local port whose private data is to be retreived * @lport: The local port whose private data is to be retreived
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment