From patchwork Thu Aug 22 21:25:36 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pravin B Shelar X-Patchwork-Id: 269210 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 0EEBF2C00AD for ; Fri, 23 Aug 2013 07:25:44 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753772Ab3HVVZk (ORCPT ); Thu, 22 Aug 2013 17:25:40 -0400 Received: from na3sys009aog131.obsmtp.com ([74.125.149.247]:58307 "HELO na3sys009aog131.obsmtp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1753195Ab3HVVZj (ORCPT ); Thu, 22 Aug 2013 17:25:39 -0400 Received: from mail-pb0-f44.google.com ([209.85.160.44]) (using TLSv1) by na3sys009aob131.postini.com ([74.125.148.12]) with SMTP ID DSNKUhaB01jqQ8Kb4oc0mzP4EVysVyx4gh3O@postini.com; Thu, 22 Aug 2013 14:25:39 PDT Received: by mail-pb0-f44.google.com with SMTP id xa7so2363069pbc.17 for ; Thu, 22 Aug 2013 14:25:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=KBjJnrFW8urWNGBBwMBNg+tHdHRpPQyqKSfqh8mIkfQ=; b=OxzkEZMVxDNICgBN+jarTnPrzS1kXGlxaLa6kGnwaNPrdZBRLF31sP3V+gM1/orb1j /35+XiX7R0MAmGcyXAcg2zSMe6Qg8isntYWCmc9wf4yq0QW6kwJALYoGJWY3pT1JQ3II B0raT14E9dTP9OiYWpc84fL+ZamtxIVMikruRqY4djPOGzmVNjISJ8akRdd/+GpGfzr0 nLH00WHB3Auc+myyNu+2zv5A98vw3c1pO104QWVW/IyRjs1wIeU5NpqvjfU7BO5HnKYn GKNMISD6cRAsgMwiBy0mh5vHORIIBzIua/J9I+P8y9lqaVn+1Sj213oUVCIqyl/xtT73 +8YQ== X-Gm-Message-State: ALoCoQnuJI9VVFqvGg1cEe3oXvsw35Gm7zglV7gr0oHBYERG73dp5m+FjyHdN6w1SFP1ixAiwugWTsCvJsN84qqIFGx0zBE0TPFltMiTajf6mHj5r+q/pfktnIeCe3Yc9L+ewHLXN5BmhxrqBd/dRuS/ZIQQI0ZMIaHrOh4U9gjwvoeUK8dYYBw= X-Received: by 10.67.30.100 with SMTP id kd4mr17614653pad.24.1377206739082; Thu, 22 Aug 2013 14:25:39 -0700 (PDT) X-Received: by 10.67.30.100 with SMTP id kd4mr17614645pad.24.1377206738973; Thu, 22 Aug 2013 14:25:38 -0700 (PDT) Received: from localhost ([75.98.92.113]) by mx.google.com with ESMTPSA id ia5sm16916047pbc.42.1969.12.31.16.00.00 (version=TLSv1.1 cipher=RC4-SHA bits=128/128); Thu, 22 Aug 2013 14:25:38 -0700 (PDT) From: Pravin B Shelar To: netdev@vger.kernel.org Cc: Pravin B Shelar , Jesse Gross , Johannes Berg Subject: [PATCH 1/2] genl: Fix genl dumpit() locking. Date: Thu, 22 Aug 2013 14:25:36 -0700 Message-Id: <1377206736-18357-1-git-send-email-pshelar@nicira.com> X-Mailer: git-send-email 1.8.2.135.g7b592fa Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org In case of genl-family with parallel ops off, dumpif() callback is expected to run under genl_lock, But commit def3117493eafd9df (genl: Allow concurrent genl callbacks.) changed this behaviour where only first dumpit() op was called under genl-lock. For subsequent dump, only nlk->cb_lock was taken. Following patch fixes it by defining locked dumpit() and done() callback which takes care of genl-locking. CC: Jesse Gross CC: Johannes Berg Signed-off-by: Pravin B Shelar --- v1-v2: No change. --- net/netlink/genetlink.c | 46 +++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 41 insertions(+), 5 deletions(-) diff --git a/net/netlink/genetlink.c b/net/netlink/genetlink.c index f85f8a2..3669039 100644 --- a/net/netlink/genetlink.c +++ b/net/netlink/genetlink.c @@ -544,6 +544,28 @@ void *genlmsg_put(struct sk_buff *skb, u32 portid, u32 seq, } EXPORT_SYMBOL(genlmsg_put); +static int genl_lock_dumpit(struct sk_buff *skb, struct netlink_callback *cb) +{ + struct genl_ops *ops = cb->data; + int rc; + + genl_lock(); + rc = ops->dumpit(skb, cb); + genl_unlock(); + return rc; +} + +static int genl_lock_done(struct netlink_callback *cb) +{ + struct genl_ops *ops = cb->data; + int rc; + + genl_lock(); + rc = ops->done(cb); + genl_unlock(); + return rc; +} + static int genl_family_rcv_msg(struct genl_family *family, struct sk_buff *skb, struct nlmsghdr *nlh) @@ -572,15 +594,29 @@ static int genl_family_rcv_msg(struct genl_family *family, return -EPERM; if ((nlh->nlmsg_flags & NLM_F_DUMP) == NLM_F_DUMP) { - struct netlink_dump_control c = { - .dump = ops->dumpit, - .done = ops->done, - }; + struct netlink_dump_control c; + int rc; if (ops->dumpit == NULL) return -EOPNOTSUPP; - return netlink_dump_start(net->genl_sock, skb, nlh, &c); + memset(&c, 0, sizeof(c)); + if (!family->parallel_ops) { + genl_unlock(); + c.data = ops; + c.dump = genl_lock_dumpit; + if (ops->done) + c.done = genl_lock_done; + } else { + c.dump = ops->dumpit; + c.done = ops->done; + } + + rc = netlink_dump_start(net->genl_sock, skb, nlh, &c); + if (!family->parallel_ops) + genl_lock(); + return rc; + } if (ops->doit == NULL)