From patchwork Fri Aug 3 16:16:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sreekanth Reddy X-Patchwork-Id: 10555261 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 8DAB713BF for ; Fri, 3 Aug 2018 16:17:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7D8B82BEAE for ; Fri, 3 Aug 2018 16:17:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 71D1B2BEB2; Fri, 3 Aug 2018 16:17:00 +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 63CF02BEAE for ; Fri, 3 Aug 2018 16:16:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727809AbeHCSN4 (ORCPT ); Fri, 3 Aug 2018 14:13:56 -0400 Received: from mail-qt0-f195.google.com ([209.85.216.195]:32910 "EHLO mail-qt0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727144AbeHCSN4 (ORCPT ); Fri, 3 Aug 2018 14:13:56 -0400 Received: by mail-qt0-f195.google.com with SMTP id c15-v6so6769674qtp.0 for ; Fri, 03 Aug 2018 09:16:57 -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=PKD0UVdY/pE0jcrDblzhJupogLMTlHAjI1bPFBqYgPA=; b=Za1uHUdZGhVKSS0Ca0Cl8Mw0CAtVrnV8vlpxgEHpuno9PKECRbEYcCzAYvnTAtpUSe OmP4aRIbmRLe+gLiUltt2pLeEbhAZyTDKKvxexWbxjBh+xQh6r2e/X0UIr5Rq+NDqjDP u5EKxs+jzEQmFDYhXQ6VhJaQfsnnbZuVRg8ko= 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=PKD0UVdY/pE0jcrDblzhJupogLMTlHAjI1bPFBqYgPA=; b=fbskVHvuGG7fchZPQg954YCzIhzS9iBrrVGJ4RG6QDRh3aiJacuRYSp2yqJmFKrXyR p95LN5ElAYRp0L1Zx/eP01J8XZXvXJ794rbUSG1HPa/hlqVJufxEYPuSIJdu2uEB+Obx MAnmByflNEvL6SqCDgyHmE1QQWIfe9mxFWtc62rUW5Pl3PnUFzofKfsVHSwAIVPueYvz 2ftuWVuy6u3I6lCSHQVmfuXw+fKjg7MskZxSEi9Q2zSAaj82j1G7eSgPCZ0N5JSFChJG d/EMl5hWnsaOqCJqnsM5DMD7eoh4HtRjIWmH71/yq/tItRkjXitAMwXseCGZ5UKd5wIt YQhQ== X-Gm-Message-State: AOUpUlGZOrAjAeOGn5vWwhcEsZAF8X0JA2QUc6c1yp7n8AzuWpCprW2/ ynDEAYvps30f/2AtW1QRKb6qMQ== X-Google-Smtp-Source: AAOMgpfKCC/Fsq37qzszV0/DyLNsAPVJkAby87gblZ38p5Fg/zqf1GFM+1upeXoHdMEtqSl9SztBMQ== X-Received: by 2002:ac8:404c:: with SMTP id j12-v6mr4544724qtl.333.1533313017357; Fri, 03 Aug 2018 09:16:57 -0700 (PDT) Received: from localhost.localdomain.localdomain ([192.19.234.250]) by smtp.gmail.com with ESMTPSA id l188-v6sm2744864qke.83.2018.08.03.09.16.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 Aug 2018 09:16:56 -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 v3] mpt3sas: correct reset of smid while clearing scsi tracker Date: Fri, 3 Aug 2018 12:16:43 -0400 Message-Id: <1533313003-30186-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 reset 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. v3 changelog: Replaced smp_mb__before_atomic() & smp_mb__after_atomic() APIs with smp_mb() APIs. Used smp_mb() 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() 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 Reviewed-by: Bart Van Assche --- drivers/scsi/mpt3sas/mpt3sas_base.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c index 902610d..2c5a5b4 100644 --- a/drivers/scsi/mpt3sas/mpt3sas_base.c +++ b/drivers/scsi/mpt3sas/mpt3sas_base.c @@ -1702,6 +1702,13 @@ 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(); atomic_inc(&ioc->chain_lookup[smid - 1].chain_offset); return chain_req; } @@ -3283,8 +3290,15 @@ 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(); + st->smid = 0; } /**