Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1697664pxb; Wed, 9 Feb 2022 02:29:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJyoGJ1dJMM/AsnwoEj+LRLHkpQH6vl76gsa5hSAJbBv72ZoRswaf56RV5CxiTF9IPWwyYwE X-Received: by 2002:a62:7c92:: with SMTP id x140mr607156pfc.35.1644402551921; Wed, 09 Feb 2022 02:29:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644402551; cv=none; d=google.com; s=arc-20160816; b=s7WE0QJuLMpWiq33xIsft8KR746mo/KXM9qFFB2dTRivTmXZZG61PrrV7fTB5q450O XHGk9UPPqOR1E8ch7aiJCw04Y27SiWRx8JAX6FaZHatbD2mAKMHNhpc8gvmT1s0q+AjX eHWtBic4sUhcg/vI6CZLDVboD/hP7b07IB0+J0BCY/1OyScTmvTkZMuOyDCDmUKfcvWz 6eXNXy9+qhZsvG8PDSF8v5C+/gDKDxQM4QA0tirYTgSQM6FhX1UFpcg396YUDWcBBla8 BqSbOEWNNuLCvIQcgUW97/yBOVCdou5NpyjDZpn2jWrVO6VYHYHE8yy/h/Te2kmYTGgV bVAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=cQ7AVMgMqI0j0OZdjYJ+yAnePGXfbOM/BhwvXyKnOSM=; b=JjklWNOpNSGfIfEufds/d3igxIchP86uAQEMKYVSyALXtWuqN9Nokvb22SIGedRWwO /ci0RBUAzwNncmI56/rd2OTE4Dy/qoswPgcPYBft4PDQhFofT+upITOWGwE3XRZq/zHW +hNNYwsE3V3jEpeE9Ta2eBNHQtPhntpWPxMOlor5GpUpsJUWIlWTOb7Y41QAWYknbAZ1 DBVZvS2uWVo5QSEmRcZggpIHEJlNeQbH0ni+etdGaXCUi0ZDvK4HDWYH/GVo7Q/tDPYf Ar7HFzL6IAlJyeTGvyhzswP7ScJF0sG9eYAcbxjtPUUQj1RNC+foy1Q40LSoechIwAfY 3aWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=k23FOMvL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id g5si16355350pgc.136.2022.02.09.02.29.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 02:29:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=k23FOMvL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id AE50CE01ABAE; Wed, 9 Feb 2022 01:21:20 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1391510AbiBGMCD (ORCPT + 99 others); Mon, 7 Feb 2022 07:02:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386796AbiBGLhF (ORCPT ); Mon, 7 Feb 2022 06:37:05 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 151E8C043188; Mon, 7 Feb 2022 03:37:05 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id C5698B8112C; Mon, 7 Feb 2022 11:37:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E8170C004E1; Mon, 7 Feb 2022 11:37:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1644233822; bh=dDv+O0Tzmkl7n2hL6tah/Kh7Z2X5dd7k5qI4BVpOqWQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k23FOMvLZS1geTYfhGMuytgHJTAExTZsN9nJrjST35y46Bj78bv3gV+YMpmDqZ1Q0 h1YfZoHEB80JN6VPxK+T9w9fPEYKBQrh4qTU102X8/JFAxkrwPwMok5aDVZE2DqSE1 Zb+5ClnIeXt0v9SBtfKzff6epJIc6lLhgSRlhod0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Guangwu Zhang , Saurav Kashyap , John Meneghini , "Martin K. Petersen" Subject: [PATCH 5.16 098/126] scsi: bnx2fc: Make bnx2fc_recv_frame() mp safe Date: Mon, 7 Feb 2022 12:07:09 +0100 Message-Id: <20220207103807.462139400@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220207103804.053675072@linuxfoundation.org> References: <20220207103804.053675072@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: John Meneghini commit 936bd03405fc83ba039d42bc93ffd4b88418f1d3 upstream. Running tests with a debug kernel shows that bnx2fc_recv_frame() is modifying the per_cpu lport stats counters in a non-mpsafe way. Just boot a debug kernel and run the bnx2fc driver with the hardware enabled. [ 1391.699147] BUG: using smp_processor_id() in preemptible [00000000] code: bnx2fc_ [ 1391.699160] caller is bnx2fc_recv_frame+0xbf9/0x1760 [bnx2fc] [ 1391.699174] CPU: 2 PID: 4355 Comm: bnx2fc_l2_threa Kdump: loaded Tainted: G B [ 1391.699180] Hardware name: HP ProLiant DL120 G7, BIOS J01 07/01/2013 [ 1391.699183] Call Trace: [ 1391.699188] dump_stack_lvl+0x57/0x7d [ 1391.699198] check_preemption_disabled+0xc8/0xd0 [ 1391.699205] bnx2fc_recv_frame+0xbf9/0x1760 [bnx2fc] [ 1391.699215] ? do_raw_spin_trylock+0xb5/0x180 [ 1391.699221] ? bnx2fc_npiv_create_vports.isra.0+0x4e0/0x4e0 [bnx2fc] [ 1391.699229] ? bnx2fc_l2_rcv_thread+0xb7/0x3a0 [bnx2fc] [ 1391.699240] bnx2fc_l2_rcv_thread+0x1af/0x3a0 [bnx2fc] [ 1391.699250] ? bnx2fc_ulp_init+0xc0/0xc0 [bnx2fc] [ 1391.699258] kthread+0x364/0x420 [ 1391.699263] ? _raw_spin_unlock_irq+0x24/0x50 [ 1391.699268] ? set_kthread_struct+0x100/0x100 [ 1391.699273] ret_from_fork+0x22/0x30 Restore the old get_cpu/put_cpu code with some modifications to reduce the size of the critical section. Link: https://lore.kernel.org/r/20220124145110.442335-1-jmeneghi@redhat.com Fixes: d576a5e80cd0 ("bnx2fc: Improve stats update mechanism") Tested-by: Guangwu Zhang Acked-by: Saurav Kashyap Signed-off-by: John Meneghini Signed-off-by: Martin K. Petersen Signed-off-by: Greg Kroah-Hartman --- drivers/scsi/bnx2fc/bnx2fc_fcoe.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) --- a/drivers/scsi/bnx2fc/bnx2fc_fcoe.c +++ b/drivers/scsi/bnx2fc/bnx2fc_fcoe.c @@ -508,7 +508,8 @@ static int bnx2fc_l2_rcv_thread(void *ar static void bnx2fc_recv_frame(struct sk_buff *skb) { - u32 fr_len; + u64 crc_err; + u32 fr_len, fr_crc; struct fc_lport *lport; struct fcoe_rcv_info *fr; struct fc_stats *stats; @@ -542,6 +543,11 @@ static void bnx2fc_recv_frame(struct sk_ skb_pull(skb, sizeof(struct fcoe_hdr)); fr_len = skb->len - sizeof(struct fcoe_crc_eof); + stats = per_cpu_ptr(lport->stats, get_cpu()); + stats->RxFrames++; + stats->RxWords += fr_len / FCOE_WORD_TO_BYTE; + put_cpu(); + fp = (struct fc_frame *)skb; fc_frame_init(fp); fr_dev(fp) = lport; @@ -624,16 +630,15 @@ static void bnx2fc_recv_frame(struct sk_ return; } - stats = per_cpu_ptr(lport->stats, smp_processor_id()); - stats->RxFrames++; - stats->RxWords += fr_len / FCOE_WORD_TO_BYTE; + fr_crc = le32_to_cpu(fr_crc(fp)); - if (le32_to_cpu(fr_crc(fp)) != - ~crc32(~0, skb->data, fr_len)) { - if (stats->InvalidCRCCount < 5) + if (unlikely(fr_crc != ~crc32(~0, skb->data, fr_len))) { + stats = per_cpu_ptr(lport->stats, get_cpu()); + crc_err = (stats->InvalidCRCCount++); + put_cpu(); + if (crc_err < 5) printk(KERN_WARNING PFX "dropping frame with " "CRC error\n"); - stats->InvalidCRCCount++; kfree_skb(skb); return; }