Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1772907pxb; Wed, 9 Feb 2022 04:17:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJzcVvYqBflac8bdYowq84C9nNkrsW/brValyYTXLjp0Ap3S0FtYEd5s92uYM1n4+RU/qnQG X-Received: by 2002:a65:6093:: with SMTP id t19mr1640717pgu.584.1644409042177; Wed, 09 Feb 2022 04:17:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644409042; cv=none; d=google.com; s=arc-20160816; b=acqs0lUJ+1VSkzD1lqudBzsgfsB/H7GbqWjABxoWSZ0Yez90tSaeMdxlx1H6unZnUL uqFL7hVockE34TvhlIaR00AYUhXM0+31s4X1S4sJ0O1u81qRiDuhgPlA4HPPB8+XyXqp aKhXa7V+yMduAoc+9AVZXEnFWxqq5f/YkEeRZEQfWZU3E0H9+S4YmnflHhnCM7d4vyFe LLe/fSUDtGFOP6QeBKd0ZV5N+82vOnilxZ9guLypdKaOMcABX39B+iwypkLWJWsdJKHY DHO5E3wTf5FJse7X9RElRjtoY3boixPi/dh4BU0CbFXi7S4l348DLaCvIBPCPV6LdsEK sOYA== 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=vl+4TJKjtSyd0p8d+c/nPXSzMDrCRLKkiByQ4PcsbFY=; b=P+bXyHQFJBcsk5cYyGt5dxtTqDKaKsCp3ORxl6AV9/Dg0iFis0I1iymDYGYR4JM3xP CizK8hfCBpcuoDUCFpWSGz9fmjFqaJI3x8FSIw2ztkDdniHYNDxWPTIq8Xi558p8PIMp tGzGfhMldQlDHhs6Q86zcD3qj+F8fDVwDHzTKkAJiMWEjTJpl5xZdFwPKI1zNN5xFfPu BmgKRpovu8MWjKT52q1fUt/iK8iqbYRSpJLX0s/dB3UC0J/DSVQ0xvs0sFfj5SostVyl N8GROcXF/J8nd2x15yhhZuXJCYEw/iRIqES0wpKqa7RClxIAqia2K43XTp8J3044MFMO mPXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2jzMkgG5; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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. [23.128.96.19]) by mx.google.com with ESMTPS id i186si15383139pge.146.2022.02.09.04.17.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 04:17:22 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2jzMkgG5; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 606CAE11272E; Wed, 9 Feb 2022 02:12:33 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1385217AbiBGLbX (ORCPT + 99 others); Mon, 7 Feb 2022 06:31:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1382811AbiBGLUw (ORCPT ); Mon, 7 Feb 2022 06:20:52 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66D47C03E90A; Mon, 7 Feb 2022 03:20:37 -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 1549BB81028; Mon, 7 Feb 2022 11:20:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4E227C004E1; Mon, 7 Feb 2022 11:20:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1644232826; bh=jIwfAxVEMGhpnFVreXI7ObayC/K7pZmZBtoSvlANXFU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2jzMkgG5Wvn8ETq+aQCSh+xCGG+tQojRvfGXojXMNVY4ELnDfgYaKkZnDmshigR6G HrS4FKClV28oRmiTzBFcBwHxlIsFdGbvAIz3Tx5FtOVXJpZaFsY6nVCJedWsBZzOeJ gylW4ivFbnkjIUTdiYBof0oFyCYQVdf5SPyzyQRg= 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.4 37/44] scsi: bnx2fc: Make bnx2fc_recv_frame() mp safe Date: Mon, 7 Feb 2022 12:06:53 +0100 Message-Id: <20220207103754.362566762@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220207103753.155627314@linuxfoundation.org> References: <20220207103753.155627314@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 @@ -506,7 +506,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; @@ -540,6 +541,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; @@ -622,16 +628,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; }