From patchwork Tue Aug 9 23:39:18 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Matthew R. Ochs" X-Patchwork-Id: 657545 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3s89lJ3fMfz9sRB for ; Wed, 10 Aug 2016 09:41:00 +1000 (AEST) Received: from ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3s89lJ2gb5zDrFL for ; Wed, 10 Aug 2016 09:41:00 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3s89jh4RpdzDrFm for ; Wed, 10 Aug 2016 09:39:36 +1000 (AEST) Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.11/8.16.0.11) with SMTP id u79Nd1bA069572 for ; Tue, 9 Aug 2016 19:39:35 -0400 Received: from e38.co.us.ibm.com (e38.co.us.ibm.com [32.97.110.159]) by mx0a-001b2d01.pphosted.com with ESMTP id 24qm9sa8xj-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 09 Aug 2016 19:39:34 -0400 Received: from localhost by e38.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 9 Aug 2016 17:39:33 -0600 Received: from d03dlp02.boulder.ibm.com (9.17.202.178) by e38.co.us.ibm.com (192.168.1.138) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 9 Aug 2016 17:39:29 -0600 X-IBM-Helo: d03dlp02.boulder.ibm.com X-IBM-MailFrom: mrochs@linux.vnet.ibm.com Received: from b03cxnp08027.gho.boulder.ibm.com (b03cxnp08027.gho.boulder.ibm.com [9.17.130.19]) by d03dlp02.boulder.ibm.com (Postfix) with ESMTP id 29D693E40041; Tue, 9 Aug 2016 17:39:29 -0600 (MDT) Received: from b03ledav002.gho.boulder.ibm.com (b03ledav002.gho.boulder.ibm.com [9.17.130.233]) by b03cxnp08027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u79NdR745243352; Tue, 9 Aug 2016 16:39:27 -0700 Received: from b03ledav002.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id ACF7B136043; Tue, 9 Aug 2016 17:39:27 -0600 (MDT) Received: from p8tul1-build.aus.stglabs.ibm.com (unknown [9.3.141.206]) by b03ledav002.gho.boulder.ibm.com (Postfix) with ESMTP id D6A2C13603C; Tue, 9 Aug 2016 17:39:26 -0600 (MDT) From: "Matthew R. Ochs" To: linux-scsi@vger.kernel.org, James Bottomley , "Martin K. Petersen" , Uma Krishnan , "Manoj N. Kumar" , Al Viro Subject: [PATCH 1/6] cxlflash: Avoid mutex when destroying context Date: Tue, 9 Aug 2016 18:39:18 -0500 X-Mailer: git-send-email 2.1.0 In-Reply-To: <1470785888-9112-1-git-send-email-mrochs@linux.vnet.ibm.com> References: <1470785888-9112-1-git-send-email-mrochs@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16080923-0028-0000-0000-00000556E170 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00005571; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000178; SDB=6.00742429; UDB=6.00349471; IPR=6.00514986; BA=6.00004652; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00012282; XFM=3.00000011; UTC=2016-08-09 23:39:33 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16080923-0029-0000-0000-00002E3CD95C Message-Id: <1470785958-9152-1-git-send-email-mrochs@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-08-09_10:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=2 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1604210000 definitions=main-1608090248 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Christophe Lombard , "Matthew R. Ochs" , Frederic Barrat , Ian Munsie , Andrew Donnellan , Brian King , linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Context information structures are protected by a mutex that is held when accessing/manipulating the context. When the code that manages these structures was authored, a decision was made to include taking the mutex as part of the allocation/initialization sequence and also handle the scenario where the mutex was already held when freeing the context. While not a problem outright, this design decision has been deemed as too flexible and the code should be made more rigid to avoid future bugs. In addition, further review of the code yields that the existing mutex manipulations in both of these context management paths are superfluous. This commit removes the obtaining of the context mutex in the context initialization routine and assumes the mutex is not held in the context free path. Inspired-by: Al Viro Signed-off-by: Matthew R. Ochs Acked-by: Manoj N. Kumar --- drivers/scsi/cxlflash/superpipe.c | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/drivers/scsi/cxlflash/superpipe.c b/drivers/scsi/cxlflash/superpipe.c index ce15070..ab5c893 100644 --- a/drivers/scsi/cxlflash/superpipe.c +++ b/drivers/scsi/cxlflash/superpipe.c @@ -709,14 +709,13 @@ int cxlflash_disk_release(struct scsi_device *sdev, * @cfg: Internal structure associated with the host. * @ctxi: Context to release. * - * This routine is safe to be called with a a non-initialized context - * and is tolerant of being called with the context's mutex held (it - * will be unlocked if necessary before freeing). Also note that the - * routine conditionally checks for the existence of the context control - * map before clearing the RHT registers and context capabilities because - * it is possible to destroy a context while the context is in the error - * state (previous mapping was removed [so there is no need to worry about - * clearing] and context is waiting for a new mapping). + * This routine is safe to be called with a a non-initialized context. + * Also note that the routine conditionally checks for the existence + * of the context control map before clearing the RHT registers and + * context capabilities because it is possible to destroy a context + * while the context is in the error state (previous mapping was + * removed [so there is no need to worry about clearing] and context + * is waiting for a new mapping). */ static void destroy_context(struct cxlflash_cfg *cfg, struct ctx_info *ctxi) @@ -732,9 +731,6 @@ static void destroy_context(struct cxlflash_cfg *cfg, writeq_be(0, &ctxi->ctrl_map->rht_cnt_id); writeq_be(0, &ctxi->ctrl_map->ctx_cap); } - - if (mutex_is_locked(&ctxi->mutex)) - mutex_unlock(&ctxi->mutex); } /* Free memory associated with context */ @@ -795,9 +791,6 @@ err: * @adap_fd: Previously obtained adapter fd associated with CXL context. * @file: Previously obtained file associated with CXL context. * @perms: User-specified permissions. - * - * Upon return, the context is marked as initialized and the context's mutex - * is locked. */ static void init_context(struct ctx_info *ctxi, struct cxlflash_cfg *cfg, struct cxl_context *ctx, int ctxid, int adap_fd, @@ -816,8 +809,6 @@ static void init_context(struct ctx_info *ctxi, struct cxlflash_cfg *cfg, mutex_init(&ctxi->mutex); INIT_LIST_HEAD(&ctxi->luns); INIT_LIST_HEAD(&ctxi->list); /* initialize for list_empty() */ - - mutex_lock(&ctxi->mutex); } /** @@ -1445,7 +1436,6 @@ static int cxlflash_disk_attach(struct scsi_device *sdev, * knows about us yet; we can be the only one holding our mutex. */ list_add(&lun_access->list, &ctxi->luns); - mutex_unlock(&ctxi->mutex); mutex_lock(&cfg->ctx_tbl_list_mutex); mutex_lock(&ctxi->mutex); cfg->ctx_tbl[ctxid] = ctxi; @@ -1494,7 +1484,7 @@ err: file = NULL; } - /* Cleanup our context; safe to call even with mutex locked */ + /* Cleanup our context */ if (ctxi) { destroy_context(cfg, ctxi); ctxi = NULL;