summaryrefslogtreecommitdiffstats
path: root/mm/vmalloc.c
diff options
context:
space:
mode:
authorAl Viro2013-03-11 01:14:08 +0100
committerAl Viro2013-03-11 02:18:21 +0100
commit32fcfd40715ed13f7a80cbde49d097ddae20c8e2 (patch)
treee4c211c1135a48ee853b3ec4d00623686317293a /mm/vmalloc.c
parentLinux 3.9-rc1 (diff)
downloadkernel-qcow2-linux-32fcfd40715ed13f7a80cbde49d097ddae20c8e2.tar.gz
kernel-qcow2-linux-32fcfd40715ed13f7a80cbde49d097ddae20c8e2.tar.xz
kernel-qcow2-linux-32fcfd40715ed13f7a80cbde49d097ddae20c8e2.zip
make vfree() safe to call from interrupt contexts
A bunch of RCU callbacks want to be able to do vfree() and end up with rather kludgy schemes. Just let vfree() do the right thing - put the victim on llist and schedule actual __vunmap() via schedule_work(), so that it runs from non-interrupt context. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'mm/vmalloc.c')
-rw-r--r--mm/vmalloc.c45
1 files changed, 40 insertions, 5 deletions
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 0f751f2068c3..ef9bdf742273 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -27,10 +27,30 @@
#include <linux/pfn.h>
#include <linux/kmemleak.h>
#include <linux/atomic.h>
+#include <linux/llist.h>
#include <asm/uaccess.h>
#include <asm/tlbflush.h>
#include <asm/shmparam.h>
+struct vfree_deferred {
+ struct llist_head list;
+ struct work_struct wq;
+};
+static DEFINE_PER_CPU(struct vfree_deferred, vfree_deferred);
+
+static void __vunmap(const void *, int);
+
+static void free_work(struct work_struct *w)
+{
+ struct vfree_deferred *p = container_of(w, struct vfree_deferred, wq);
+ struct llist_node *llnode = llist_del_all(&p->list);
+ while (llnode) {
+ void *p = llnode;
+ llnode = llist_next(llnode);
+ __vunmap(p, 1);
+ }
+}
+
/*** Page table manipulation functions ***/
static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
@@ -1184,10 +1204,14 @@ void __init vmalloc_init(void)
for_each_possible_cpu(i) {
struct vmap_block_queue *vbq;
+ struct vfree_deferred *p;
vbq = &per_cpu(vmap_block_queue, i);
spin_lock_init(&vbq->lock);
INIT_LIST_HEAD(&vbq->free);
+ p = &per_cpu(vfree_deferred, i);
+ init_llist_head(&p->list);
+ INIT_WORK(&p->wq, free_work);
}
/* Import existing vmlist entries. */
@@ -1511,7 +1535,7 @@ static void __vunmap(const void *addr, int deallocate_pages)
kfree(area);
return;
}
-
+
/**
* vfree - release memory allocated by vmalloc()
* @addr: memory base address
@@ -1520,15 +1544,25 @@ static void __vunmap(const void *addr, int deallocate_pages)
* obtained from vmalloc(), vmalloc_32() or __vmalloc(). If @addr is
* NULL, no operation is performed.
*
- * Must not be called in interrupt context.
+ * Must not be called in NMI context (strictly speaking, only if we don't
+ * have CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG, but making the calling
+ * conventions for vfree() arch-depenedent would be a really bad idea)
+ *
*/
void vfree(const void *addr)
{
- BUG_ON(in_interrupt());
+ BUG_ON(in_nmi());
kmemleak_free(addr);
- __vunmap(addr, 1);
+ if (!addr)
+ return;
+ if (unlikely(in_interrupt())) {
+ struct vfree_deferred *p = &__get_cpu_var(vfree_deferred);
+ llist_add((struct llist_node *)addr, &p->list);
+ schedule_work(&p->wq);
+ } else
+ __vunmap(addr, 1);
}
EXPORT_SYMBOL(vfree);
@@ -1545,7 +1579,8 @@ void vunmap(const void *addr)
{
BUG_ON(in_interrupt());
might_sleep();
- __vunmap(addr, 0);
+ if (addr)
+ __vunmap(addr, 0);
}
EXPORT_SYMBOL(vunmap);
title='Blame the previous revision' href='/openslx/kernel-qcow2-linux.git/blame/net/nfc/nfc.h?id=43472fffb4628773397297f7e365983accd4a0ef'>^
d646960f7986 ^




73167ced31d1 ^





52feb444a903 ^




d646960f7986 ^










23b7869c0fd0 ^


c7fe3b52c128 ^




3e256b8f8dfa ^


4d12b8b129f1 ^






8112a5c91d78 ^
4d12b8b129f1 ^



1ed28f610653 ^



fc40a8c1a06a ^


95c961747284 ^
3e256b8f8dfa ^
























8b3fe7b591b3 ^



fe7c58007328 ^
3e256b8f8dfa ^


47807d3dbb62 ^
1ed28f610653 ^


3e256b8f8dfa ^



0a40acb24602 ^

3e256b8f8dfa ^

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192

























                                                                       
                        
                     
 




                                                           
                                                            

  










                                                                             







                                                                   
                                                                           
                                                                     
                                                                




                               
                                                            


 
                                                                          
                                                               











                                                                  

                                                             



                 
                                                                             




                    





                                                             




                                                                             










                                      


                              




                                                                


                                      






                                                         
                                                              



                                                 



                                                                   


                                                             
                                                 
























                                                                               



                                      
                                                                            


                                       
                                                                       


                                           



                                                                           

                                                                               

                          
/*
 * Copyright (C) 2011 Instituto Nokia de Tecnologia
 *
 * Authors:
 *    Lauro Ramos Venancio <lauro.venancio@openbossa.org>
 *    Aloisio Almeida Jr <aloisio.almeida@openbossa.org>
 *
 * 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, write to the
 * Free Software Foundation, Inc.,
 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#ifndef __LOCAL_NFC_H
#define __LOCAL_NFC_H

#include <net/nfc/nfc.h>
#include <net/sock.h>

struct nfc_protocol {
	int id;
	struct proto *proto;
	struct module *owner;
	int (*create)(struct net *net, struct socket *sock,
		      const struct nfc_protocol *nfc_proto);
};

struct nfc_rawsock {
	struct sock sk;
	struct nfc_dev *dev;
	u32 target_idx;
	struct work_struct tx_work;
	bool tx_work_scheduled;
};
#define nfc_rawsock(sk) ((struct nfc_rawsock *) sk)
#define to_rawsock_sk(_tx_work) \
	((struct sock *) container_of(_tx_work, struct nfc_rawsock, tx_work))

#ifdef CONFIG_NFC_LLCP

void nfc_llcp_mac_is_down(struct nfc_dev *dev);
void nfc_llcp_mac_is_up(struct nfc_dev *dev, u32 target_idx,
			u8 comm_mode, u8 rf_mode);
int nfc_llcp_register_device(struct nfc_dev *dev);
void nfc_llcp_unregister_device(struct nfc_dev *dev);
int nfc_llcp_set_remote_gb(struct nfc_dev *dev, u8 *gb, u8 gb_len);
u8 *nfc_llcp_general_bytes(struct nfc_dev *dev, size_t *general_bytes_len);
int nfc_llcp_data_received(struct nfc_dev *dev, struct sk_buff *skb);
struct nfc_llcp_local *nfc_llcp_find_local(struct nfc_dev *dev);
int __init nfc_llcp_init(void);
void nfc_llcp_exit(void);

#else

static inline void nfc_llcp_mac_is_down(struct nfc_dev *dev)
{
}

static inline void nfc_llcp_mac_is_up(struct nfc_dev *dev, u32 target_idx,
				      u8 comm_mode, u8 rf_mode)
{
}

static inline int nfc_llcp_register_device(struct nfc_dev *dev)
{
	return 0;
}

static inline void nfc_llcp_unregister_device(struct nfc_dev *dev)
{
}

static inline int nfc_llcp_set_remote_gb(struct nfc_dev *dev,
					 u8 *gb, u8 gb_len)
{
	return 0;
}

static inline u8 *nfc_llcp_general_bytes(struct nfc_dev *dev, size_t *gb_len)
{
	*gb_len = 0;
	return NULL;
}

static inline int nfc_llcp_data_received(struct nfc_dev *dev,
					 struct sk_buff *skb)
{
	return 0;
}

static inline struct nfc_llcp_local *nfc_llcp_find_local(struct nfc_dev *dev)
{
	return NULL;
}

static inline int nfc_llcp_init(void)
{
	return 0;
}

static inline void nfc_llcp_exit(void)
{
}

#endif

int __init rawsock_init(void);
void rawsock_exit(void);

int __init af_nfc_init(void);
void af_nfc_exit(void);
int nfc_proto_register(const struct nfc_protocol *nfc_proto);
void nfc_proto_unregister(const struct nfc_protocol *nfc_proto);

extern int nfc_devlist_generation;
extern struct mutex nfc_devlist_mutex;

int __init nfc_genl_init(void);
void nfc_genl_exit(void);

void nfc_genl_data_init(struct nfc_genl_data *genl_data);
void nfc_genl_data_exit(struct nfc_genl_data *genl_data);

int nfc_genl_targets_found(struct nfc_dev *dev);
int nfc_genl_target_lost(struct nfc_dev *dev, u32 target_idx);

int nfc_genl_device_added(struct nfc_dev *dev);
int nfc_genl_device_removed(struct nfc_dev *dev);

int nfc_genl_dep_link_up_event(struct nfc_dev *dev, u32 target_idx,
			       u8 comm_mode, u8 rf_mode);
int nfc_genl_dep_link_down_event(struct nfc_dev *dev);

int nfc_genl_tm_activated(struct nfc_dev *dev, u32 protocol);
int nfc_genl_tm_deactivated(struct nfc_dev *dev);

struct nfc_dev *nfc_get_device(unsigned int idx);

static inline void nfc_put_device(struct nfc_dev *dev)
{
	put_device(&dev->dev);
}

static inline void nfc_device_iter_init(struct class_dev_iter *iter)
{
	class_dev_iter_init(iter, &nfc_class, NULL, NULL);
}

static inline struct nfc_dev *nfc_device_iter_next(struct class_dev_iter *iter)
{
	struct device *d = class_dev_iter_next(iter);
	if (!d)
		return NULL;

	return to_nfc_dev(d);
}

static inline void nfc_device_iter_exit(struct class_dev_iter *iter)
{
	class_dev_iter_exit(iter);
}

int nfc_dev_up(struct nfc_dev *dev);

int nfc_dev_down(struct nfc_dev *dev);

int nfc_start_poll(struct nfc_dev *dev, u32 im_protocols, u32 tm_protocols);

int nfc_stop_poll(struct nfc_dev *dev);

int nfc_dep_link_up(struct nfc_dev *dev, int target_idx, u8 comm_mode);

int nfc_dep_link_down(struct nfc_dev *dev);

int nfc_activate_target(struct nfc_dev *dev, u32 target_idx, u32 protocol);

int nfc_deactivate_target(struct nfc_dev *dev, u32 target_idx);

int nfc_data_exchange(struct nfc_dev *dev, u32 target_idx, struct sk_buff *skb,
		      data_exchange_cb_t cb, void *cb_context);

#endif /* __LOCAL_NFC_H */