From patchwork Mon May 31 05:04:55 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 54067 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 3900AB7D5E for ; Mon, 31 May 2010 15:05:32 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752123Ab0EaFFF (ORCPT ); Mon, 31 May 2010 01:05:05 -0400 Received: from mail-wy0-f174.google.com ([74.125.82.174]:51653 "EHLO mail-wy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751506Ab0EaFFB (ORCPT ); Mon, 31 May 2010 01:05:01 -0400 Received: by wyb36 with SMTP id 36so1020808wyb.19 for ; Sun, 30 May 2010 22:04:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:subject:from:to:cc :in-reply-to:references:content-type:date:message-id:mime-version :x-mailer:content-transfer-encoding; bh=WPVE4E7k4WYjPpG6T7GLRqmpxtQ8ZN4RAqO9TD5+0ik=; b=SaV24bdZ8zN4FwsZjpMMYLnPgjzDhXxR0Ggn84g7mVm2uxE39kv7Duxs/7ngezwZPj fgHwsflhV1lFYxwEPbrjerQI6Rjy41kTckSx0GQOcVwNcIxqWLPqio9ITjrvOy6U9CPs jcrg2wrwh7TjTbow7+Nuwec8GzDWDiLAdKaFs= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=subject:from:to:cc:in-reply-to:references:content-type:date :message-id:mime-version:x-mailer:content-transfer-encoding; b=LhNaZ1ltVWwBvdzW5IaSCxkm8OXAPQx+cAjc1w2QHzr25jKMrgBM5j6TZ+kyC0rOrq Z9nGE+OEpxVskvGb4q6tXfOM5S+7dt66jxbpxUllplTmx0ed0cutM8TtCkppXmGy7DtU MHkK8HiUjri60yPXoRW1Ky/Pej3NBz4gLIq1w= Received: by 10.227.138.134 with SMTP id a6mr3674541wbu.14.1275282299154; Sun, 30 May 2010 22:04:59 -0700 (PDT) Received: from [127.0.0.1] ([85.17.35.125]) by mx.google.com with ESMTPS id r35sm8508624wbv.11.2010.05.30.22.04.57 (version=SSLv3 cipher=RC4-MD5); Sun, 30 May 2010 22:04:58 -0700 (PDT) Subject: [PATCH] ipv6: get rid of ipip6_prl_lock From: Eric Dumazet To: Julia Lawall Cc: "David S. Miller" , Alexey Kuznetsov , "Pekka Savola (ipv6)" , James Morris , Hideaki YOSHIFUJI , Patrick McHardy , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org In-Reply-To: References: <1275250288.2472.21.camel@edumazet-laptop> <1275252912.2472.23.camel@edumazet-laptop> Date: Mon, 31 May 2010 07:04:55 +0200 Message-ID: <1275282295.2472.34.camel@edumazet-laptop> Mime-Version: 1.0 X-Mailer: Evolution 2.28.3 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Le dimanche 30 mai 2010 à 23:09 +0200, Julia Lawall a écrit : > On Sun, 30 May 2010, Eric Dumazet wrote: > > > Le dimanche 30 mai 2010 à 22:50 +0200, Julia Lawall a écrit : > > > > > I think the proposed patch does not work, because the for loop overwrites > > > p. That use of p looks like it is completely local to the for loop, so > > > perhaps a new variable p1 could be added to be used there? > > > > Please do so. > > > > I just wanted to tell you changing GFP_KERNEL to GFP_ATOMIC is not an > > appropriate way to solve this kind of problems. My patch was to get an > > idea, not a full and tested patch :) > > Looking at it again, there is still a problem, because in the original > code, the loop: > ... > > could exit with success without the kzalloc ever being called. If the > kzalloc is moved up, it could fail and then it returns immediately without > executing the loop. A solution could be to leave the NULL test on p where > it is, and only move up the kzalloc. Or perhaps the change in behavior > doesn't matter? > [PATCH] ipv6: get rid of ipip6_prl_lock As noticed by Julia Lawall, ipip6_tunnel_add_prl() incorrectly calls kzallloc(..., GFP_KERNEL) while a spinlock is held. He provided a patch to use GFP_ATOMIC instead. One possibility would be to convert this spinlock to a mutex, or preallocate the thing before taking the lock. After RCU conversion, it appears we dont need this lock, since caller already holds RTNL Signed-off-by: Eric Dumazet --- net/ipv6/sit.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c index e51e650..702c532 100644 --- a/net/ipv6/sit.c +++ b/net/ipv6/sit.c @@ -249,8 +249,6 @@ failed: return NULL; } -static DEFINE_SPINLOCK(ipip6_prl_lock); - #define for_each_prl_rcu(start) \ for (prl = rcu_dereference(start); \ prl; \ @@ -340,7 +338,7 @@ ipip6_tunnel_add_prl(struct ip_tunnel *t, struct ip_tunnel_prl *a, int chg) if (a->addr == htonl(INADDR_ANY)) return -EINVAL; - spin_lock(&ipip6_prl_lock); + ASSERT_RTNL(); for (p = t->prl; p; p = p->next) { if (p->addr == a->addr) { @@ -370,7 +368,6 @@ ipip6_tunnel_add_prl(struct ip_tunnel *t, struct ip_tunnel_prl *a, int chg) t->prl_count++; rcu_assign_pointer(t->prl, p); out: - spin_unlock(&ipip6_prl_lock); return err; } @@ -397,7 +394,7 @@ ipip6_tunnel_del_prl(struct ip_tunnel *t, struct ip_tunnel_prl *a) struct ip_tunnel_prl_entry *x, **p; int err = 0; - spin_lock(&ipip6_prl_lock); + ASSERT_RTNL(); if (a && a->addr != htonl(INADDR_ANY)) { for (p = &t->prl; *p; p = &(*p)->next) { @@ -419,7 +416,6 @@ ipip6_tunnel_del_prl(struct ip_tunnel *t, struct ip_tunnel_prl *a) } } out: - spin_unlock(&ipip6_prl_lock); return err; }