From patchwork Wed Oct 28 13:44:27 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wan, Kaike" X-Patchwork-Id: 7511161 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 296B5BEEA4 for ; Wed, 28 Oct 2015 13:44:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5A42120818 for ; Wed, 28 Oct 2015 13:44:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6014220817 for ; Wed, 28 Oct 2015 13:44:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755930AbbJ1Nov (ORCPT ); Wed, 28 Oct 2015 09:44:51 -0400 Received: from mga14.intel.com ([192.55.52.115]:54881 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755929AbbJ1Nou (ORCPT ); Wed, 28 Oct 2015 09:44:50 -0400 Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga103.fm.intel.com with ESMTP; 28 Oct 2015 06:44:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,210,1444719600"; d="scan'208";a="589643650" Received: from sedona.ch.intel.com ([143.182.228.65]) by FMSMGA003.fm.intel.com with ESMTP; 28 Oct 2015 06:44:50 -0700 Received: from phlsvlogin01.ph.intel.com (phlsvlogin01.ph.intel.com [10.228.195.36]) by sedona.ch.intel.com (8.13.6/8.14.3/Standard MailSET/Hub) with ESMTP id t9SDinnh015454; Wed, 28 Oct 2015 06:44:49 -0700 Received: from phlsvlogin01.ph.intel.com (localhost [127.0.0.1]) by phlsvlogin01.ph.intel.com with ESMTP id t9SDimI5028021; Wed, 28 Oct 2015 09:44:49 -0400 Received: (from kaikewan@localhost) by phlsvlogin01.ph.intel.com with id t9SDim4R028017; Wed, 28 Oct 2015 09:44:48 -0400 X-Authentication-Warning: phlsvlogin01.ph.intel.com: kaikewan set sender to kaike.wan@intel.com using -f From: kaike.wan@intel.com To: linux-rdma@vger.kernel.org Cc: Kaike Wan Subject: [PATCH 1/1] IB/sa: Put netlink request into the request list before sending Date: Wed, 28 Oct 2015 09:44:27 -0400 Message-Id: <1446039867-27883-1-git-send-email-kaike.wan@intel.com> X-Mailer: git-send-email 1.8.2 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Spam-Status: No, score=-6.9 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: Kaike Wan It was found by Saurabh Sengar that the netlink code tried to allocate memory with GFP_KERNEL while holding a spinlock. While it is possible to fix the issue by replacing GFP_KERNEL with GFP_ATOMIC, it is better to get rid of the spinlock while sending the packet. However, in order to protect against a race condition that a quick response may be received before the request is put on the request list, we need to put the request on the list first. Signed-off-by: Kaike Wan --- drivers/infiniband/core/sa_query.c | 22 ++++++++++++---------- 1 files changed, 12 insertions(+), 10 deletions(-) diff --git a/drivers/infiniband/core/sa_query.c b/drivers/infiniband/core/sa_query.c index edcf568..240b57c 100644 --- a/drivers/infiniband/core/sa_query.c +++ b/drivers/infiniband/core/sa_query.c @@ -562,23 +562,25 @@ static int ib_nl_make_request(struct ib_sa_query *query) INIT_LIST_HEAD(&query->list); query->seq = (u32)atomic_inc_return(&ib_nl_sa_request_seq); + /* Put the request on the list first.*/ spin_lock_irqsave(&ib_nl_request_lock, flags); + delay = msecs_to_jiffies(sa_local_svc_timeout_ms); + query->timeout = delay + jiffies; + list_add_tail(&query->list, &ib_nl_request_list); + spin_unlock_irqrestore(&ib_nl_request_lock, flags); + ret = ib_nl_send_msg(query); + spin_lock_irqsave(&ib_nl_request_lock, flags); if (ret <= 0) { ret = -EIO; - goto request_out; + /* Remove the request */ + list_del(&query->list); } else { ret = 0; + /* Start the timeout if this is the only request */ + if (ib_nl_request_list.next == &query->list) + queue_delayed_work(ib_nl_wq, &ib_nl_timed_work, delay); } - - delay = msecs_to_jiffies(sa_local_svc_timeout_ms); - query->timeout = delay + jiffies; - list_add_tail(&query->list, &ib_nl_request_list); - /* Start the timeout if this is the only request */ - if (ib_nl_request_list.next == &query->list) - queue_delayed_work(ib_nl_wq, &ib_nl_timed_work, delay); - -request_out: spin_unlock_irqrestore(&ib_nl_request_lock, flags); return ret;