From patchwork Wed Dec 18 01:07:37 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasesh Mody X-Patchwork-Id: 302594 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id C4DFA2C00AE for ; Wed, 18 Dec 2013 12:08:45 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752551Ab3LRBIl (ORCPT ); Tue, 17 Dec 2013 20:08:41 -0500 Received: from mx0a-000f0801.pphosted.com ([67.231.144.122]:42885 "EHLO mx0a-000f0801.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752286Ab3LRBIk (ORCPT ); Tue, 17 Dec 2013 20:08:40 -0500 Received: from pps.filterd (m0000542 [127.0.0.1]) by mx0a-000f0801.pphosted.com (8.14.5/8.14.5) with SMTP id rBI0JBUT007416; Tue, 17 Dec 2013 17:08:40 -0800 Received: from hq1wp-exchub01.corp.brocade.com ([144.49.131.13]) by mx0a-000f0801.pphosted.com with ESMTP id 1gtmfd8t02-1 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NOT); Tue, 17 Dec 2013 17:08:39 -0800 Received: from blc-10-1.brocade.com (10.70.4.101) by HQ1WP-EXCHUB01.corp.brocade.com (10.70.36.101) with Microsoft SMTP Server (TLS) id 14.3.123.3; Tue, 17 Dec 2013 17:08:39 -0800 Received: from blc-10-1.brocade.com (localhost.localdomain [127.0.0.1]) by blc-10-1.brocade.com (8.13.1/8.13.8) with ESMTP id rBI18drQ027356; Tue, 17 Dec 2013 17:08:39 -0800 Received: (from rmody@localhost) by blc-10-1.brocade.com (8.13.1/8.13.8/Submit) id rBI18dsj027353; Tue, 17 Dec 2013 17:08:39 -0800 From: Rasesh Mody To: CC: , , Rasesh Mody Subject: [net-next 07/12] bna: CQ Read Fix Date: Tue, 17 Dec 2013 17:07:37 -0800 Message-ID: <1387328862-27213-8-git-send-email-rmody@brocade.com> X-Mailer: git-send-email 1.8.3.rc2 In-Reply-To: <1387328862-27213-1-git-send-email-rmody@brocade.com> References: <1387328862-27213-1-git-send-email-rmody@brocade.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.11.87, 1.0.14, 0.0.0000 definitions=2013-12-17_05:2013-12-17, 2013-12-17, 1970-01-01 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 suspectscore=1 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=7.0.1-1305240000 definitions=main-1312170196 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Valid bit check for completion needs read fence, so that it does not get reordered with other loads. Signed-off-by: Rasesh Mody --- drivers/net/ethernet/brocade/bna/bnad.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/brocade/bna/bnad.c b/drivers/net/ethernet/brocade/bna/bnad.c index 03fa4a6..7394d46 100644 --- a/drivers/net/ethernet/brocade/bna/bnad.c +++ b/drivers/net/ethernet/brocade/bna/bnad.c @@ -601,7 +601,18 @@ bnad_cq_process(struct bnad *bnad, struct bna_ccb *ccb, int budget) cq = ccb->sw_q; cmpl = &cq[ccb->producer_index]; - while (cmpl->valid && (packets < budget)) { + while (packets < budget) { + if (!cmpl->valid) + break; + /* The 'valid' field is set by the adapter, only after writing + * the other fields of completion entry. Hence, do not load + * other fields of completion entry *before* the 'valid' is + * loaded. Adding the rmb() here prevents the compiler and/or + * CPU from reordering the reads which would potentially result + * in reading stale values in completion entry. + */ + rmb(); + BNA_UPDATE_PKT_CNT(pkt_rt, ntohs(cmpl->length)); if (bna_is_small_rxq(cmpl->rxq_id)) @@ -641,6 +652,16 @@ bnad_cq_process(struct bnad *bnad, struct bna_ccb *ccb, int budget) if (!next_cmpl->valid) break; + /* The 'valid' field is set by the adapter, only + * after writing the other fields of completion + * entry. Hence, do not load other fields of + * completion entry *before* the 'valid' is + * loaded. Adding the rmb() here prevents the + * compiler and/or CPU from reordering the reads + * which would potentially result in reading + * stale values in completion entry. + */ + rmb(); len = ntohs(next_cmpl->length); flags = ntohl(next_cmpl->flags);