From patchwork Fri Aug 3 10:31:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sreekanth Reddy X-Patchwork-Id: 10554925 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E7B4813BB for ; Fri, 3 Aug 2018 10:32:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DA5402C156 for ; Fri, 3 Aug 2018 10:32:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CC7422C17F; Fri, 3 Aug 2018 10:32:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 733C72C156 for ; Fri, 3 Aug 2018 10:32:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732327AbeHCM1x (ORCPT ); Fri, 3 Aug 2018 08:27:53 -0400 Received: from mail-qk0-f193.google.com ([209.85.220.193]:35575 "EHLO mail-qk0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730783AbeHCM1w (ORCPT ); Fri, 3 Aug 2018 08:27:52 -0400 Received: by mail-qk0-f193.google.com with SMTP id u21-v6so3667070qku.2 for ; Fri, 03 Aug 2018 03:32:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id; bh=D7ZKqgmSn/DMJT7qrrcI4sKo5Rlayt9wXtb67h6WHMk=; b=UUzjOsk4DKKLUVYDD3B/U3nsoSj7MQscH6Cf32ofPC7OqlX0XNsT5HkVcqWHUEkor5 cipyoc7NGgESvMQZwdBhrjj4IxfbJXV1FQizCehxJZzcIjAZ75zqN79bWTi3+eYi68A1 TNyhDg3TDYJk/UFaRmR/KOR6VRmOhhYptmQHA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=D7ZKqgmSn/DMJT7qrrcI4sKo5Rlayt9wXtb67h6WHMk=; b=DKLmpUf5akMS/AEFeuSV19IWzGL85oJr5rExz2XKnbrHpAivff3LQQOqMHyR3/EUg3 X8EFNh316vSA5cJRJ0/G/FKtaCYxBfdY/KLxGHk+/AdYeUsfJrdwUvWZi+AJuHWMRIy8 w7VC6zT/SGbWW0FbDPILV0GVcQrzIGtS2nYeLhhrndXvi/Xe+hLBdqfQzae1BwuLA01e fRYbLvG3oKo0J2rOtVwGY+Cg1FMl9ws0jbcR9mjVh9LI0fRVp6XFaehGB+UOMBuJEcu6 nx7vXWJ4dIC1S9M4cP+FRskBPVfmye04BRrYTOLN3zHtqi5c9zIoX9JXh0GJq0bx3qZl vtvA== X-Gm-Message-State: AOUpUlHueO+GcQIulEKgcPvrymzMvC9heTVpsbigaG3w1goXGhIvYhSc gqK/9z+kNFR/NiTzocCSrPZ25A== X-Google-Smtp-Source: AAOMgpfIY+cuXUYg4v16EH1jc22UmNZGD07I0IdGxdPAPCMOqSVYsuJYlGDmyZnNo56J2hnh+TxCBQ== X-Received: by 2002:a37:9b03:: with SMTP id d3-v6mr2915340qke.122.1533292330372; Fri, 03 Aug 2018 03:32:10 -0700 (PDT) Received: from localhost.localdomain.localdomain ([192.19.234.250]) by smtp.gmail.com with ESMTPSA id n41-v6sm4424161qtn.73.2018.08.03.03.32.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 Aug 2018 03:32:09 -0700 (PDT) From: Sreekanth Reddy To: martin.petersen@oracle.com Cc: linux-scsi@vger.kernel.org, sathya.prakash@broadcom.com, thenzl@redhat.com, Bart.VanAssche@wdc.com, Sreekanth Reddy Subject: [PATCH v2] mpt3sas: correct reset of smid while clearing scsi tracker Date: Fri, 3 Aug 2018 06:31:56 -0400 Message-Id: <1533292316-16076-1-git-send-email-sreekanth.reddy@broadcom.com> X-Mailer: git-send-email 1.8.3.1 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In mpt3sas_base_clear_st() function smid value is reseted in wrong line, i.e. driver should reset smid value to zero after decrementing chain_offset counter in chain_lookup table but in current code, driver is resetting smid value before decrementing the chain_offset counter. which we are correcting with this patch. v1 changelog: Added memory barriers before & after atomic_set() API. v2 changelog: Added proper comments to describe the need of using smp_mb__before_atomic() & smp_mb__after_atomic() APIs in the driver before calling these APIs. Used smp_mb__after_atomic() API in mpt3sas_base_clear_st() to make sure that smid is reset to zero only after corresponding smid pool's chain_offset in chain lookup table is reset to zero. Used smp_mb__before_atomic() API in _base_get_chain_buffer_tracker() to make sure that proper chain tracker is retrieved from the corresponding smid's pool from chain table before incrementing smid pool's chain offset value. Signed-off-by: Sreekanth Reddy --- drivers/scsi/mpt3sas/mpt3sas_base.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c index 902610d..94f7236 100644 --- a/drivers/scsi/mpt3sas/mpt3sas_base.c +++ b/drivers/scsi/mpt3sas/mpt3sas_base.c @@ -1702,6 +1702,11 @@ static int mpt3sas_remove_dead_ioc_func(void *arg) return NULL; chain_req = &ioc->chain_lookup[smid - 1].chains_per_smid[chain_offset]; + /* Added memory barrier to make sure that correct chain tracker + * is retrieved before incrementing the smid pool's chain_offset + * value in chain lookup table. + */ + smp_mb__before_atomic(); atomic_inc(&ioc->chain_lookup[smid - 1].chain_offset); return chain_req; } @@ -3283,8 +3288,13 @@ void mpt3sas_base_clear_st(struct MPT3SAS_ADAPTER *ioc, return; st->cb_idx = 0xFF; st->direct_io = 0; - st->smid = 0; atomic_set(&ioc->chain_lookup[st->smid - 1].chain_offset, 0); + /* Added memory barrier to make sure that smid is set to zero + * only after resetting corresponding smid pool's chain_offset to zero + * in chain lookup table. + */ + smp_mb__after_atomic(); + st->smid = 0; } /**