Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751183AbWHBU4w (ORCPT ); Wed, 2 Aug 2006 16:56:52 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751199AbWHBU4w (ORCPT ); Wed, 2 Aug 2006 16:56:52 -0400 Received: from e2.ny.us.ibm.com ([32.97.182.142]:17821 "EHLO e2.ny.us.ibm.com") by vger.kernel.org with ESMTP id S1751183AbWHBU4v (ORCPT ); Wed, 2 Aug 2006 16:56:51 -0400 Date: Wed, 2 Aug 2006 13:57:30 -0700 From: "Paul E. McKenney" To: Alan Stern Cc: Andrew Morton , Jesse Brandeburg , Kernel development list Subject: Re: [PATCH 1/2] SRCU: report out-of-memory errors Message-ID: <20060802205730.GD1292@us.ibm.com> Reply-To: paulmck@us.ibm.com References: <4807377b0608021257p27882866i69a5a0a4a1f05dda@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.1i Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3074 Lines: 82 On Wed, Aug 02, 2006 at 04:38:28PM -0400, Alan Stern wrote: > Currently the init_srcu_struct() routine has no way to report > out-of-memory errors. This patch (as761) makes it return -ENOMEM when the > per-cpu data allocation fails. > > The patch also makes srcu_init_notifier_head() report a BUG if a notifier > head can't be initialized. Perhaps it should return -ENOMEM instead, but > in the most likely cases where this might occur I don't think any recovery > is possible. Notifier chains generally are not created dynamically. Acked-by: Paul E. McKenney > Signed-off-by: Alan Stern > > --- > > Paul, I trust you will agree with the changes this makes to the SRCU code. Indeed I do... Good catch!!! Thanx, Paul > The second part of this patch series will convert the cpufreq transition > notifier chain to use SRCU, with the initialization occuring in a > core_initcall routine. Although I haven't actually tried it, it seems > very likely that an attempt to use the notifier chain before it has been > initialized will cause a memory-address fault. > > Alan Stern > > > Index: 2.6.18-rc2-mm1/kernel/sys.c > =================================================================== > --- 2.6.18-rc2-mm1.orig/kernel/sys.c > +++ 2.6.18-rc2-mm1/kernel/sys.c > @@ -516,7 +516,7 @@ EXPORT_SYMBOL_GPL(srcu_notifier_call_cha > void srcu_init_notifier_head(struct srcu_notifier_head *nh) > { > mutex_init(&nh->mutex); > - init_srcu_struct(&nh->srcu); > + BUG_ON(init_srcu_struct(&nh->srcu) < 0); > nh->head = NULL; > } > > Index: 2.6.18-rc2-mm1/kernel/srcu.c > =================================================================== > --- 2.6.18-rc2-mm1.orig/kernel/srcu.c > +++ 2.6.18-rc2-mm1/kernel/srcu.c > @@ -42,11 +42,12 @@ > * to any other function. Each srcu_struct represents a separate domain > * of SRCU protection. > */ > -void init_srcu_struct(struct srcu_struct *sp) > +int init_srcu_struct(struct srcu_struct *sp) > { > sp->completed = 0; > - sp->per_cpu_ref = alloc_percpu(struct srcu_struct_array); > mutex_init(&sp->mutex); > + sp->per_cpu_ref = alloc_percpu(struct srcu_struct_array); > + return (sp->per_cpu_ref ? 0 : -ENOMEM); > } > > /* > Index: 2.6.18-rc2-mm1/include/linux/srcu.h > =================================================================== > --- 2.6.18-rc2-mm1.orig/include/linux/srcu.h > +++ 2.6.18-rc2-mm1/include/linux/srcu.h > @@ -43,7 +43,7 @@ struct srcu_struct { > #define srcu_barrier() > #endif /* #else #ifndef CONFIG_PREEMPT */ > > -void init_srcu_struct(struct srcu_struct *sp); > +int init_srcu_struct(struct srcu_struct *sp); > void cleanup_srcu_struct(struct srcu_struct *sp); > int srcu_read_lock(struct srcu_struct *sp); > void srcu_read_unlock(struct srcu_struct *sp, int idx); > - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/