Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1594273pxb; Tue, 8 Feb 2022 23:29:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJyRgajelE1xyl65khlGayc0szEGJX0bHuS7v2Mq+uqLcrlC7uSi/IAkksw72R/9+CqoeTjx X-Received: by 2002:a05:6402:22eb:: with SMTP id dn11mr1038644edb.331.1644391798670; Tue, 08 Feb 2022 23:29:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644391798; cv=none; d=google.com; s=arc-20160816; b=FzHEck9lvrP23rJM/aru8NAs2GLzivdf7dxtndq/D66kLlW6GcnBPKvf3Ymzrk7lEG a+jizgvgZPVNV+MEQlWGggt4YqvG1SMOHJyK6rszq/Ax7CU3miTftFiE/hP/N1lyjEdG wN1SJc3GKdXHSYqTBZeKNpgjfGXtvnynyiXPCSZj2eIpGs2Ve/jBoTQV1Vsw21Wi74d9 6b8ED9sEO4byuVr+4tkTorTXYsv8hbE3+Mpc9WBjhqYS5BPoaY4PdB8NOMf9FjhA4P2O H3q+X+6hQafPhVeSEQXKDNWouHrEfEdAVgwjf9nqGwOXefZtV3oq8RyCWQ7qKlfj9PkC nyBw== 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=PdSRdV3c8UeTyMp4cnemzMHJX8cboQgklcWN6pLxDpI=; b=YczzNC2sp/WzXqHdAxYYDbSZkQ8V4uevmuS3/bhh6jq4hp+ms+HWd2vY8Mzejyo9yj LjKIYJoGwhYGqwZI0rApsRJZjybWzaso1cT6VyruDiQoI9dPn809bmjD2xaLE8nJskHm AFXO4H2FR5rRWV8ltradrl2kgsDYjpAILP4NQc0R4BEPzMk440mH4KakIKr7r+k/FVac vNHgmjoe9kHP9y6ptDKi1OFWsJO8zDLAT1oHDJe4rnZaemiJ8y3Ouv0XjQBzn7SYONHl 5BUnhaJBoTrPAwwYmV/Lx3QOgv01ezqXNS94LLIzsE0K+u0FtvrPLOvIf720BIRSV+ux l3IA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=LHR6QKx+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b9si931601ede.136.2022.02.08.23.29.33; Tue, 08 Feb 2022 23:29:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=LHR6QKx+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.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: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383408AbiBGLW0 (ORCPT + 99 others); Mon, 7 Feb 2022 06:22:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381923AbiBGLRk (ORCPT ); Mon, 7 Feb 2022 06:17:40 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61E7EC03E95A; Mon, 7 Feb 2022 03:17:36 -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 dfw.source.kernel.org (Postfix) with ESMTPS id B55166126D; Mon, 7 Feb 2022 11:17:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7A782C004E1; Mon, 7 Feb 2022 11:17:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1644232655; bh=VluB2J+kIM9oj76n7AMWSOUEqAaEMZUSLTxgMykkH/4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LHR6QKx+2J15ogZTLvG++lo3WNzE9NC0eW7F8Xpu5ibeGoMmaj/pbEPyYj3TR9uxV Z3dnbPS/j1Ss4qXptr+1aXW8nOmcYfnDtRJVKFZFBiSaoFyi59WCS9NvWrYTuyRi7z 9aBP62DmrwTqZkTkzYG7F/dpuj5WWYsQg7M+0jyg= 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 4.19 80/86] scsi: bnx2fc: Make bnx2fc_recv_frame() mp safe Date: Mon, 7 Feb 2022 12:06:43 +0100 Message-Id: <20220207103800.300079572@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220207103757.550973048@linuxfoundation.org> References: <20220207103757.550973048@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=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 @@ -515,7 +515,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; @@ -549,6 +550,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; @@ -631,16 +637,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; }