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] [day] [month] [year] [list]
Message-ID: <39127609.24822.1411048990717.JavaMail.zimbra@efficios.com>
Date:	Thu, 18 Sep 2014 14:03:10 +0000 (UTC)
From:	Mathieu Desnoyers <mathieu.desnoyers@...icios.com>
To:	Omar Sandoval <osandov@...ndov.com>
Cc:	Chris Mason <clm@...com>, Josef Bacik <jbacik@...com>,
	linux-btrfs@...r.kernel.org,
	"Paul E. McKenney" <paulmck@...ux.vnet.ibm.com>,
	Josh Triplett <josh@...htriplett.org>,
	Steven Rostedt <rostedt@...dmis.org>,
	Lai Jiangshan <laijs@...fujitsu.com>,
	linux-kernel@...r.kernel.org
Subject: Re: [PATCH] Move BTRFS RCU string to common library

----- Original Message -----
> From: "Omar Sandoval" <osandov@...ndov.com>
> To: "Chris Mason" <clm@...com>, "Josef Bacik" <jbacik@...com>, linux-btrfs@...r.kernel.org, "Paul E. McKenney"
> <paulmck@...ux.vnet.ibm.com>, "Josh Triplett" <josh@...htriplett.org>, "Steven Rostedt" <rostedt@...dmis.org>,
> "Mathieu Desnoyers" <mathieu.desnoyers@...icios.com>, "Lai Jiangshan" <laijs@...fujitsu.com>,
> linux-kernel@...r.kernel.org
> Sent: Thursday, September 18, 2014 5:28:11 AM
> Subject: [PATCH] Move BTRFS RCU string to common library
> 
> The RCU-friendy string API used internally by BTRFS is generic enough for
> common use. This doesn't add any new functionality, but instead just moves
> the
> code and documents the existing API.
> 
> Signed-off-by: Omar Sandoval <osandov@...ndov.com>

[...]
> --- /dev/null
> +++ b/include/linux/rcustring.h
> @@ -0,0 +1,84 @@
> +/*
> + * RCU-friendly strings
> + *
> + * Copyright (C) 2012 Red Hat.  All rights reserved.
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, you can access it online at
> + * http://www.gnu.org/licenses/gpl-2.0.html.
> + */
> +
> +#ifndef _LINUX_RCUSTRING_H
> +#define _LINUX_RCUSTRING_H
> +
> +struct rcu_string {
> +	struct rcu_head rcu;
> +	char str[0];
> +};
> +
> +/**
> + * rcu_string_strdup() - create an RCU string from a string
> + * @src: The string to copy
> + * @flags: Flags for kmalloc
> + */
> +static inline struct rcu_string *rcu_string_strdup(const char *src, gfp_t
> flags)
> +{
> +	size_t len = strlen(src) + 1;
> +	struct rcu_string *ret = kmalloc(sizeof(struct rcu_string) +
> +					 (len * sizeof(char)), flags);

Just a nit: not sure if we want that much code within declarations ?

Splitting declarations and non-trivial initial assignments might be a
bit clearer in this case.


> +	if (!ret)
> +		return ret;
> +	memcpy(ret->str, src, len);
> +	return ret;
> +}
> +
> +/**
> + * rcu_string_free() - free an RCU string
> + * @str: The string
> + */
> +static inline void rcu_string_free(struct rcu_string *str)
> +{
> +	if (str)
> +		kfree_rcu(str, rcu);
> +}
> +
> +/*
> + * rcu_string_dereference() - dereference an RCU string
> + * @str: The string
> + *
> + * Like rcu_dereference, this must be done in an RCU critical section.
> + */
> +static inline char *rcu_string_dereference(struct rcu_string *rcu_str)
> +{
> +	return rcu_dereference(rcu_str)->str;
> +}
> +
> +/**
> + * printk_in_rcu() - printk in an RCU read-side critical section

printk returns an integer, perhaps this macro should take it into
account ?

> + */
> +#define printk_in_rcu(fmt, ...) do {	\
> +	rcu_read_lock();		\
> +	printk(fmt, __VA_ARGS__);	\
> +	rcu_read_unlock();		\
> +} while (0)

The usual coding style for those define (using tabs to end lines):

#define printk_in_rcu(fmt, ...)    \
do {                               \
   ....                            \
} while (0)

> +
> +/**
> + * printk_ratelimited_in_rcu() - printk in an RCU read-side critical section

Same as above: printk_ratelimit returns an integer.

Thanks,

Mathieu

> + */
> +#define printk_ratelimited_in_rcu(fmt, ...) do {	\
> +	rcu_read_lock();				\
> +	printk_ratelimited(fmt, __VA_ARGS__);		\
> +	rcu_read_unlock();				\
> +} while (0)
> +
> +#endif
> --
> 2.1.0
> 
> 

-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
--
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