lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Thu, 28 May 2015 13:39:38 -0700
From:	josh@...htriplett.org
To:	Dan Streetman <ddstreet@...e.org>
Cc:	Andrew Morton <akpm@...ux-foundation.org>,
	"Paul E. McKenney" <paulmck@...ux.vnet.ibm.com>,
	Steven Rostedt <rostedt@...dmis.org>,
	Mathieu Desnoyers <mathieu.desnoyers@...icios.com>,
	Lai Jiangshan <laijs@...fujitsu.com>,
	linux-kernel@...r.kernel.org
Subject: Re: [PATCH 1/2] rcu: introduce list_last_or_null_rcu

On Thu, May 28, 2015 at 04:35:27PM -0400, Dan Streetman wrote:
> Add list_last_or_null_rcu(), to simplify getting the last entry from a
> rcu-protected list.  The standard list_last_entry() can't be used as it
> is not rcu-protected; the list may be modified concurrently.  And the
> ->prev pointer can't be used, as only the ->next pointers are protected
> by rcu.
> 
> This simply iterates forward through the entire list, to get to the last
> entry.  If the list is empty, it returns NULL.
> 
> Signed-off-by: Dan Streetman <ddstreet@...e.org>

The list iteration functions are macros because they introduce a loop
with attached loop block.  For this, is there any reason not to make it
an inline function instead of a macro?

>  include/linux/rculist.h | 21 +++++++++++++++++++++
>  1 file changed, 21 insertions(+)
> 
> diff --git a/include/linux/rculist.h b/include/linux/rculist.h
> index a18b16f..954fde5 100644
> --- a/include/linux/rculist.h
> +++ b/include/linux/rculist.h
> @@ -293,6 +293,27 @@ static inline void list_splice_init_rcu(struct list_head *list,
>  })
>  
>  /**
> + * list_last_or_null_rcu - get the last element from a list
> + * @ptr:        the list head to take the element from.
> + * @type:       the type of the struct this is embedded in.
> + * @member:     the name of the list_head within the struct.
> + *
> + * Note that if the list is empty, it returns NULL.
> + *
> + * This primitive may safely run concurrently with the _rcu list-mutation
> + * primitives such as list_add_rcu() as long as it's guarded by rcu_read_lock().
> + */
> +#define list_last_or_null_rcu(ptr, type, member) \
> +({ \
> +	struct list_head *__ptr = (ptr); \
> +	struct list_head *__last = __ptr; \
> +	struct list_head *__entry = list_next_rcu(__ptr); \
> +	for (; __entry != __ptr; __entry = list_next_rcu(__entry)) \
> +		__last = __entry; \
> +	likely(__ptr != __last) ? list_entry_rcu(__last, type, member) : NULL; \
> +})
> +
> +/**
>   * list_for_each_entry_rcu	-	iterate over rcu list of given type
>   * @pos:	the type * to use as a loop cursor.
>   * @head:	the head for your list.
> -- 
> 2.1.0
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ