From patchwork Thu Sep 5 02:58:38 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 2853892 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 98AE5C0AB5 for ; Thu, 5 Sep 2013 02:59:06 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id ADF9420308 for ; Thu, 5 Sep 2013 02:59:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8F18420319 for ; Thu, 5 Sep 2013 02:59:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752862Ab3IEC7C (ORCPT ); Wed, 4 Sep 2013 22:59:02 -0400 Received: from mx11.netapp.com ([216.240.18.76]:43487 "EHLO mx11.netapp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1761976Ab3IEC7B (ORCPT ); Wed, 4 Sep 2013 22:59:01 -0400 X-IronPort-AV: E=Sophos;i="4.90,843,1371106800"; d="scan'208";a="47019209" Received: from vmwexceht03-prd.hq.netapp.com ([10.106.76.241]) by mx11-out.netapp.com with ESMTP; 04 Sep 2013 19:58:45 -0700 Received: from smtp1.corp.netapp.com (10.57.156.124) by VMWEXCEHT03-PRD.hq.netapp.com (10.106.76.241) with Microsoft SMTP Server id 14.3.123.3; Wed, 4 Sep 2013 19:58:45 -0700 Received: from leira.trondhjem.org.com (leira.trondhjem.org.vpn.netapp.com [10.55.78.83]) by smtp1.corp.netapp.com (8.13.1/8.13.1/NTAP-1.6) with ESMTP id r852will023426; Wed, 4 Sep 2013 19:58:44 -0700 (PDT) From: Trond Myklebust To: Subject: [PATCH 1/3] SUNRPC: Ensure that task->tk_pid is unique... Date: Wed, 4 Sep 2013 22:58:38 -0400 Message-ID: <1378349920-31206-1-git-send-email-Trond.Myklebust@netapp.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Spam-Status: No, score=-9.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham 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 Replace the task->tk_pid with a guaranteed unique parameter. Signed-off-by: Trond Myklebust --- include/linux/sunrpc/sched.h | 3 ++- net/sunrpc/sched.c | 57 +++++++++++++++++++++++++++++++++++++------- 2 files changed, 51 insertions(+), 9 deletions(-) diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h index 8ebb7c0..6e8657c 100644 --- a/include/linux/sunrpc/sched.h +++ b/include/linux/sunrpc/sched.h @@ -80,7 +80,7 @@ struct rpc_task { unsigned short tk_timeouts; /* maj timeouts */ #if defined(RPC_DEBUG) || defined(RPC_TRACEPOINTS) - unsigned short tk_pid; /* debugging aid */ + unsigned int tk_pid; /* debugging aid */ #endif unsigned char tk_priority : 2,/* Task priority */ tk_garb_retry : 2, @@ -133,6 +133,7 @@ struct rpc_task_setup { #define RPC_TASK_RUNNING 0 #define RPC_TASK_QUEUED 1 #define RPC_TASK_ACTIVE 2 +#define RPC_TASK_PID 3 #define RPC_IS_RUNNING(t) test_bit(RPC_TASK_RUNNING, &(t)->tk_runstate) #define rpc_set_running(t) set_bit(RPC_TASK_RUNNING, &(t)->tk_runstate) diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c index ff3cc4b..fd15110 100644 --- a/net/sunrpc/sched.c +++ b/net/sunrpc/sched.c @@ -259,24 +259,55 @@ static int rpc_wait_bit_killable(void *word) } #if defined(RPC_DEBUG) || defined(RPC_TRACEPOINTS) -static void rpc_task_set_debuginfo(struct rpc_task *task) +static DEFINE_IDA(rpc_pids); + +static int rpc_task_alloc_pid(struct rpc_task *task) { - static atomic_t rpc_pid; + int pid; + + pid = ida_simple_get(&rpc_pids, 0, 0, GFP_NOFS); + if (pid < 0) + return pid; + task->tk_pid = pid; + set_bit(RPC_TASK_PID, &task->tk_runstate); + return 0; +} - task->tk_pid = atomic_inc_return(&rpc_pid); +static bool rpc_task_need_free_pid(struct rpc_task *task) +{ + return test_and_clear_bit(RPC_TASK_PID, &task->tk_runstate) != 0; +} + +static void rpc_task_free_pid(int pid) +{ + ida_simple_remove(&rpc_pids, pid); } #else -static inline void rpc_task_set_debuginfo(struct rpc_task *task) +static int rpc_task_alloc_pid(struct rpc_task *task) +{ + return 0; +} + +static bool rpc_task_need_free_pid(struct rpc_task *task) +{ + return false; +} + +static void rpc_task_free_pid(int pid) { } #endif -static void rpc_set_active(struct rpc_task *task) +static int rpc_set_active(struct rpc_task *task) { - trace_rpc_task_begin(task->tk_client, task, NULL); + int ret; - rpc_task_set_debuginfo(task); + ret = rpc_task_alloc_pid(task); + if (ret < 0) + return ret; + trace_rpc_task_begin(task->tk_client, task, NULL); set_bit(RPC_TASK_ACTIVE, &task->tk_runstate); + return 0; } /* @@ -811,8 +842,14 @@ static void __rpc_execute(struct rpc_task *task) void rpc_execute(struct rpc_task *task) { bool is_async = RPC_IS_ASYNC(task); + int ret; - rpc_set_active(task); + ret = rpc_set_active(task); + if (ret < 0) { + task->tk_status = ret; + rpc_release_task(task); + return; + } rpc_make_runnable(task); if (!is_async) __rpc_execute(task); @@ -970,6 +1007,8 @@ struct rpc_task *rpc_new_task(const struct rpc_task_setup *setup_data) static void rpc_free_task(struct rpc_task *task) { unsigned short tk_flags = task->tk_flags; + bool free_pid = rpc_task_need_free_pid(task); + int pid = task->tk_pid; rpc_release_calldata(task->tk_ops, task->tk_calldata); @@ -977,6 +1016,8 @@ static void rpc_free_task(struct rpc_task *task) dprintk("RPC: %5u freeing task\n", task->tk_pid); mempool_free(task, rpc_task_mempool); } + if (free_pid) + rpc_task_free_pid(pid); } static void rpc_async_release(struct work_struct *work)