From patchwork Mon Nov 16 22:32:39 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ira Weiny X-Patchwork-Id: 7631271 Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 05E80BF90C for ; Mon, 16 Nov 2015 22:33:12 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 26C4B205B1 for ; Mon, 16 Nov 2015 22:33:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2596E205C4 for ; Mon, 16 Nov 2015 22:33:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752013AbbKPWdI (ORCPT ); Mon, 16 Nov 2015 17:33:08 -0500 Received: from mga03.intel.com ([134.134.136.65]:4086 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752814AbbKPWdH (ORCPT ); Mon, 16 Nov 2015 17:33:07 -0500 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga103.jf.intel.com with ESMTP; 16 Nov 2015 14:33:07 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,304,1444719600"; d="scan'208";a="852403284" Received: from phlsvsds.ph.intel.com ([10.228.195.38]) by fmsmga002.fm.intel.com with ESMTP; 16 Nov 2015 14:33:06 -0800 Received: from phlsvsds.ph.intel.com (localhost.localdomain [127.0.0.1]) by phlsvsds.ph.intel.com (8.13.8/8.13.8) with ESMTP id tAGMX5GB025236; Mon, 16 Nov 2015 17:33:05 -0500 Received: (from iweiny@localhost) by phlsvsds.ph.intel.com (8.13.8/8.13.8/Submit) id tAGMX5m3025233; Mon, 16 Nov 2015 17:33:05 -0500 X-Authentication-Warning: phlsvsds.ph.intel.com: iweiny set sender to ira.weiny@intel.com using -f From: ira.weiny@intel.com To: gregkh@linuxfoundation.org, devel@driverdev.osuosl.org Cc: dledford@redhat.com, linux-rdma@vger.kernel.org, mike.marciniszyn@intel.com, Dennis Dalessandro , Ira Weiny Subject: [PATCH v2 6/7] staging/rdma/hfi1: Reduce snoop locking scope in IOCTL handler. Date: Mon, 16 Nov 2015 17:32:39 -0500 Message-Id: <1447713160-24858-7-git-send-email-ira.weiny@intel.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1447713160-24858-1-git-send-email-ira.weiny@intel.com> References: <1447713160-24858-1-git-send-email-ira.weiny@intel.com> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Dennis Dalessandro This patch avoids issues while calling into copy from/to user while holding the lock by only taking the lock when it is absolutely required. The only commands which require the snoop lock are: *Set Filter *Clear Filter *Clear Queue Reviewed-by: Mike Marciniszyn Signed-off-by: Dennis Dalessandro Signed-off-by: Ira Weiny --- Changes from V1: Adjust to add the done label which can't be removed until a later patch Removed SETLINKSTATE drivers/staging/rdma/hfi1/diag.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/staging/rdma/hfi1/diag.c b/drivers/staging/rdma/hfi1/diag.c index 2bfb455d3ca4..a4dd4cbc2bea 100644 --- a/drivers/staging/rdma/hfi1/diag.c +++ b/drivers/staging/rdma/hfi1/diag.c @@ -1004,8 +1004,6 @@ static long hfi1_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) */ return -EINVAL; - spin_lock_irqsave(&dd->hfi1_snoop.snoop_lock, flags); - switch (cmd) { case HFI1_SNOOP_IOCSETLINKSTATE_EXTRA: memset(&link_info, 0, sizeof(link_info)); @@ -1122,11 +1120,14 @@ static long hfi1_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) case HFI1_SNOOP_IOCCLEARQUEUE: snoop_dbg("Clearing snoop queue"); + spin_lock_irqsave(&dd->hfi1_snoop.snoop_lock, flags); drain_snoop_list(&dd->hfi1_snoop.queue); + spin_unlock_irqrestore(&dd->hfi1_snoop.snoop_lock, flags); break; case HFI1_SNOOP_IOCCLEARFILTER: snoop_dbg("Clearing filter"); + spin_lock_irqsave(&dd->hfi1_snoop.snoop_lock, flags); if (dd->hfi1_snoop.filter_callback) { /* Drain packets first */ drain_snoop_list(&dd->hfi1_snoop.queue); @@ -1134,6 +1135,7 @@ static long hfi1_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) } kfree(dd->hfi1_snoop.filter_value); dd->hfi1_snoop.filter_value = NULL; + spin_unlock_irqrestore(&dd->hfi1_snoop.snoop_lock, flags); break; case HFI1_SNOOP_IOCSETFILTER: @@ -1170,13 +1172,14 @@ static long hfi1_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) break; } /* Drain packets first */ + spin_lock_irqsave(&dd->hfi1_snoop.snoop_lock, flags); drain_snoop_list(&dd->hfi1_snoop.queue); dd->hfi1_snoop.filter_callback = hfi1_filters[filter_cmd.opcode].filter; /* just in case we see back to back sets */ kfree(dd->hfi1_snoop.filter_value); dd->hfi1_snoop.filter_value = filter_value; - + spin_unlock_irqrestore(&dd->hfi1_snoop.snoop_lock, flags); break; case HFI1_SNOOP_IOCGETVERSION: value = SNOOP_CAPTURE_VERSION; @@ -1200,7 +1203,6 @@ static long hfi1_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) break; } done: - spin_unlock_irqrestore(&dd->hfi1_snoop.snoop_lock, flags); return ret; }