generic radix trees; drop flex arrays
Subsystems (10)
cover generic radix trees; drop flex arrays
this has been sitting on my todo list for far too long; let's try and get it merged before flex arrays grow any new users.
The only significant change since the last time I mailed this out is that it's now safe to use a genradix from multiple threads, including when new nodes are being allocated.
Since we never _free_ nodes on a genradix while it's in use (only when the entire tree is being freed), this adds very little code - we just use cmpxchg for adding pointers to new nodes, there's no need to use rcu_read_lock() or anything like that. And for the types of things we seem to want to use it for it's quite useful.
Andrew, would you mind picking up this series, or would someone else be more suitable? The patch series has been sent out a few times and seen a fair amoun of review.
Kent Overstreet (7):
openvswitch: convert to kvmalloc
md: convert to kvmalloc
selinux: convert to kvmalloc
Generic radix trees
proc: commit to genradix
sctp: Convert to genradix
Drop flex_arrays
Documentation/core-api/flexible-arrays.rst | 130 ------ Documentation/core-api/generic-radix-tree.rst | 12 + Documentation/core-api/index.rst | 1 + Documentation/flexible-arrays.txt | 123 ------ drivers/md/raid5-ppl.c | 6 +- drivers/md/raid5.c | 87 ++-- drivers/md/raid5.h | 9 +- fs/proc/base.c | 43 +- include/linux/flex_array.h | 149 ------- include/linux/generic-radix-tree.h | 231 ++++++++++ include/linux/poison.h | 3 - include/net/sctp/structs.h | 15 +- lib/Makefile | 5 +- lib/flex_array.c | 398 ------------------ lib/generic-radix-tree.c | 217 ++++++++++ net/openvswitch/flow.h | 1 - net/openvswitch/flow_netlink.h | 1 - net/openvswitch/flow_table.c | 51 +-- net/openvswitch/flow_table.h | 3 +- net/sctp/stream.c | 106 +---- net/sctp/stream_interleave.c | 2 +- security/selinux/ss/avtab.c | 40 +- security/selinux/ss/avtab.h | 4 +- security/selinux/ss/conditional.c | 6 +- security/selinux/ss/policydb.c | 122 ++---- security/selinux/ss/policydb.h | 12 +- security/selinux/ss/services.c | 22 +- tools/include/linux/poison.h | 3 - 28 files changed, 628 insertions(+), 1174 deletions(-) delete mode 100644 Documentation/core-api/flexible-arrays.rst create mode 100644 Documentation/core-api/generic-radix-tree.rst delete mode 100644 Documentation/flexible-arrays.txt delete mode 100644 include/linux/flex_array.h create mode 100644 include/linux/generic-radix-tree.h delete mode 100644 lib/flex_array.c create mode 100644 lib/generic-radix-tree.c
Signature · 1 line
2.20.1
PATCH 1/7 openvswitch: convert to kvmalloc
There was no real need for this code to be using flexarrays, it's just implementing a hash table - ideally it would be using rhashtables, but that conversion would be significantly more complicated.
--- net/openvswitch/flow.h | 1 - net/openvswitch/flow_netlink.h | 1 - net/openvswitch/flow_table.c | 51 ++++++++-------------------------- net/openvswitch/flow_table.h | 3 +- 4 files changed, 13 insertions(+), 43 deletions(-)
net/openvswitch/flow.h +0 -1
@@ -30,7 +30,6 @@#include <linux/in6.h> #include <linux/jiffies.h> #include <linux/time.h> -#include <linux/flex_array.h> #include <linux/cpumask.h> #include <net/inet_ecn.h> #include <net/ip_tunnels.h>
net/openvswitch/flow_netlink.h +0 -1
@@ -30,7 +30,6 @@#include <linux/in6.h> #include <linux/jiffies.h> #include <linux/time.h> -#include <linux/flex_array.h> #include <net/inet_ecn.h> #include <net/ip_tunnels.h>
net/openvswitch/flow_table.c +12 -39
103 lines not on this page · raw message
net/openvswitch/flow_table.h +1 -2
@@ -29,7 +29,6 @@#include <linux/in6.h> #include <linux/jiffies.h> #include <linux/time.h> -#include <linux/flex_array.h> #include <net/inet_ecn.h> #include <net/ip_tunnels.h>
@@ -37,7 +36,7 @@#include "flow.h" struct table_instance { -struct flex_array *buckets; +struct hlist_head *buckets;unsigned int n_buckets;struct rcu_head rcu;int node_ver;
Signature · 1 line
2.20.1
PATCH 2/7 md: convert to kvmalloc
In reply to Kent OverstreetThe code really just wants a big flat buffer, so just do that.
--- drivers/md/raid5-ppl.c | 6 +-- drivers/md/raid5.c | 87 +++++++++++++++++++----------------------- drivers/md/raid5.h | 9 +++-- 3 files changed, 46 insertions(+), 56 deletions(-)
drivers/md/raid5-ppl.c +2 -4
@@ -16,7 +16,6 @@#include <linux/blkdev.h> #include <linux/slab.h> #include <linux/crc32c.h> -#include <linux/flex_array.h> #include <linux/async_tx.h> #include <linux/raid/md_p.h> #include "md.h"
@@ -165,7 +164,7 @@ ops_run_partial_parity(struct stripe_head *sh, struct raid5_percpu *percpu, struct dma_async_tx_descriptor *tx) {int disks = sh->disks; -struct page **srcs =flex_array_get (percpu->scribble,0 ); +struct page **srcs = percpu->scribble;int count =0 , pd_idx = sh->pd_idx, i;struct async_submit_ctl submit;
@@ -196,8 +195,7 @@ ops_run_partial_parity(struct stripe_head *sh, struct raid5_percpu *percpu, }init_async_submit (&submit,ASYNC_TX_FENCE |ASYNC_TX_XOR_ZERO_DST , tx, -NULL , sh,flex_array_get (percpu->scribble,0 ) - +sizeof (struct page *) * (sh->disks +2 )); +NULL , sh, (void *) (srcs + sh->disks +2 ));if (count ==1 ) tx = async_memcpy(sh->ppl_page, srcs[0], 0, 0, PAGE_SIZE,
drivers/md/raid5.c +39 -48
137 lines not on this page · raw message
drivers/md/raid5.h +5 -4
@@ -638,10 +638,11 @@ struct r5conf {/* per cpu variables */ struct raid5_percpu {struct page *spare_page;/* Used when checking P/Q in raid6 */ -struct flex_array *scribble;/* space for constructing buffer -* lists and performing address -* conversions -*/ +void *scribble;/* space for constructing buffer +* lists and performing address +* conversions +*/ +int scribble_obj_size; }__percpu *percpu;int scribble_disks;int scribble_sectors;
Signature · 1 line
2.20.1
PATCH 3/7 selinux: convert to kvmalloc
In reply to Kent OverstreetThe flex arrays were being used for constant sized arrays, so there's no benefit to using flex_arrays over something simpler.
--- security/selinux/ss/avtab.c | 40 +++++----- security/selinux/ss/avtab.h | 4 +- security/selinux/ss/conditional.c | 6 +- security/selinux/ss/policydb.c | 122 ++++++++---------------------- security/selinux/ss/policydb.h | 12 +-- security/selinux/ss/services.c | 22 ++---- 6 files changed, 62 insertions(+), 144 deletions(-)
security/selinux/ss/avtab.c +19 -21
@@ -93,12 +93,10 @@ avtab_insert_node(struct avtab *h, int hvalue, newnode->next = prev->next; prev->next = newnode; }else { - newnode->next =flex_array_get_ptr (h->htable, hvalue); -if (flex_array_put_ptr (h->htable, hvalue, newnode, -GFP_KERNEL |__GFP_ZERO)) { -kmem_cache_free (avtab_node_cachep, newnode); -return NULL ; - } +struct avtab_node **n = &h->htable[hvalue]; + + newnode->next = *n; + *n = newnode; } h->nel++;
@@ -111,11 +109,11 @@ static int avtab_insert(struct avtab *h, struct avtab_key *key, struct avtab_datstruct avtab_node *prev, *cur, *newnode;u16 specified = key->specified & ~(AVTAB_ENABLED |AVTAB_ENABLED_OLD ); -if (!h || !h->htable) +if (!h)return -EINVAL ; hvalue =avtab_hash (key, h->mask); -for (prev =NULL , cur =flex_array_get_ptr (h->htable, hvalue); +for (prev =NULL , cur = h->htable[hvalue]; cur; prev = cur, cur = cur->next) { if (key->source_type == cur->key.source_type &&
@@ -156,10 +154,10 @@ avtab_insert_nonunique(struct avtab *h, struct avtab_key *key, struct avtab_datustruct avtab_node *prev, *cur;u16 specified = key->specified & ~(AVTAB_ENABLED |AVTAB_ENABLED_OLD ); -if (!h || !h->htable) +if (!h)return NULL ; hvalue =avtab_hash (key, h->mask); -for (prev =NULL , cur =flex_array_get_ptr (h->htable, hvalue); +for (prev =NULL , cur = h->htable[hvalue]; cur; prev = cur, cur = cur->next) { if (key->source_type == cur->key.source_type &&
@@ -186,11 +184,11 @@ struct avtab_datum *avtab_search(struct avtab *h, struct avtab_key *key)struct avtab_node *cur;u16 specified = key->specified & ~(AVTAB_ENABLED |AVTAB_ENABLED_OLD ); -if (!h || !h->htable) +if (!h)return NULL ; hvalue =avtab_hash (key, h->mask); -for (cur =flex_array_get_ptr (h->htable, hvalue); cur; +for (cur = h->htable[hvalue]; cur; cur = cur->next) { if (key->source_type == cur->key.source_type && key->target_type == cur->key.target_type &&
@@ -222,11 +220,11 @@ avtab_search_node(struct avtab *h, struct avtab_key *key)struct avtab_node *cur;u16 specified = key->specified & ~(AVTAB_ENABLED |AVTAB_ENABLED_OLD ); -if (!h || !h->htable) +if (!h)return NULL ; hvalue =avtab_hash (key, h->mask); -for (cur =flex_array_get_ptr (h->htable, hvalue); cur; +for (cur = h->htable[hvalue]; cur; cur = cur->next) { if (key->source_type == cur->key.source_type && key->target_type == cur->key.target_type &&
@@ -281,11 +279,11 @@ void avtab_destroy(struct avtab *h)int i;struct avtab_node *cur, *temp; -if (!h || !h->htable) +if (!h)return ;for (i =0 ; i < h->nslot; i++) { - cur =flex_array_get_ptr (h->htable, i); + cur = h->htable[i];while (cur) { temp = cur; cur = cur->next;
@@ -295,7 +293,7 @@ void avtab_destroy(struct avtab *h)kmem_cache_free (avtab_node_cachep, temp); } } -flex_array_free (h->htable); +kvfree (h->htable); h->htable =NULL ; h->nslot =0 ; h->mask =0 ;
@@ -303,6 +301,7 @@ void avtab_destroy(struct avtab *h)int avtab_init (struct avtab *h) { +kvfree (h->htable); h->htable =NULL ; h->nel =0 ;return 0 ;
@@ -329,8 +328,7 @@ int avtab_alloc(struct avtab *h, u32 nrules) nslot =MAX_AVTAB_HASH_BUCKETS ; mask = nslot -1 ; - h->htable =flex_array_alloc (sizeof (struct avtab_node *), nslot, -GFP_KERNEL | __GFP_ZERO); + h->htable =kvcalloc (nslot,sizeof (void *),GFP_KERNEL );if (!h->htable)return -ENOMEM ;
@@ -353,7 +351,7 @@ void avtab_hash_eval(struct avtab *h, char *tag) max_chain_len =0 ; chain2_len_sum =0 ;for (i =0 ; i < h->nslot; i++) { - cur =flex_array_get_ptr (h->htable, i); + cur = h->htable[i];if (cur) { slots_used++; chain_len =0 ;
@@ -646,7 +644,7 @@ int avtab_write(struct policydb *p, struct avtab *a, void *fp)return rc;for (i =0 ; i < a->nslot; i++) { -for (cur =flex_array_get_ptr (a->htable, i); cur; +for (cur = a->htable[i]; cur; cur = cur->next) { rc =avtab_write_item (p, cur, fp);if (rc)
security/selinux/ss/avtab.h +1 -3
@@ -24,7 +24,6 @@#define _SS_AVTAB_H_#include "security.h" -#include <linux/flex_array.h> struct avtab_key {u16 source_type;/* source type */
@@ -84,11 +83,10 @@ struct avtab_node { };struct avtab { -struct flex_array *htable; +struct avtab_node **htable;u32 nel;/* number of elements */ u32 nslot;/* number of hash slots */ u32 mask;/* mask to compute hash func */ - };int avtab_init (struct avtab *);
security/selinux/ss/conditional.c +1 -5
@@ -195,7 +195,6 @@ int cond_index_bool(void *key, void *datum, void *datap) {struct policydb *p;struct cond_bool_datum *booldatum; -struct flex_array *fa; booldatum = datum; p = datap;
@@ -203,10 +202,7 @@ int cond_index_bool(void *key, void *datum, void *datap)if (!booldatum->value || booldatum->value > p->p_bools.nprim)return -EINVAL ; - fa = p->sym_val_to_name[SYM_BOOLS ]; -if (flex_array_put_ptr (fa, booldatum->value -1 , key, -GFP_KERNEL | __GFP_ZERO)) -BUG (); + p->sym_val_to_name[SYM_BOOLS ][booldatum->value -1 ] = key; p->bool_val_to_struct[booldatum->value -1 ] = booldatum;return 0 ;
security/selinux/ss/policydb.c +30 -92
268 lines not on this page · raw message
security/selinux/ss/policydb.h +4 -8
@@ -24,8 +24,6 @@#ifndef _SS_POLICYDB_H_#define _SS_POLICYDB_H_ -#include <linux/flex_array.h> -#include "symtab.h" #include "avtab.h" #include "sidtab.h"
@@ -251,13 +249,13 @@ struct policydb {#define p_cats symtab[SYM_CATS]/* symbol names indexed by (value - 1) */ -struct flex_array *sym_val_to_name[SYM_NUM ]; +char **sym_val_to_name[SYM_NUM ];/* class, role, and user attributes indexed by (value - 1) */ struct class_datum **class_val_to_struct;struct role_datum **role_val_to_struct;struct user_datum **user_val_to_struct; -struct flex_array *type_val_to_struct_array; +struct type_datum **type_val_to_struct_array;/* type enforcement access vectors and transitions */ struct avtab te_avtab;
@@ -294,7 +292,7 @@ struct policydb {struct hashtab *range_tr;/* type -> attribute reverse mapping */ -struct flex_array *type_attr_map_array; +struct ebitmap *type_attr_map_array;struct ebitmap policycaps;
@@ -369,9 +367,7 @@ static inline int put_entry(const void *buf, size_t bytes, int num, struct policstatic inline char *sym_name (struct policydb *p,unsigned int sym_num,unsigned int element_nr) { -struct flex_array *fa = p->sym_val_to_name[sym_num]; - -return flex_array_get_ptr (fa, element_nr); +return p->sym_val_to_name[sym_num][element_nr]; }extern u16 string_to_security_class (struct policydb *p,const char *name);
security/selinux/ss/services.c +7 -15
@@ -50,7 +50,6 @@#include <linux/audit.h> #include <linux/mutex.h> #include <linux/selinux.h> -#include <linux/flex_array.h> #include <linux/vmalloc.h> #include <net/netlabel.h>
@@ -546,15 +545,13 @@ static void type_attribute_bounds_av(struct policydb *policydb,struct type_datum *target;u32 masked =0 ; - source =flex_array_get_ptr (policydb->type_val_to_struct_array, - scontext->type -1 ); + source = policydb->type_val_to_struct_array[scontext->type -1 ];BUG_ON (!source);if (!source->bounds)return ; - target =flex_array_get_ptr (policydb->type_val_to_struct_array, - tcontext->type -1 ); + target = policydb->type_val_to_struct_array[tcontext->type -1 ];BUG_ON (!target);memset (&lo_avd,0 ,sizeof (lo_avd));
@@ -654,11 +651,9 @@ static void context_struct_compute_av(struct policydb *policydb,*/ avkey.target_class = tclass; avkey.specified =AVTAB_AV |AVTAB_XPERMS ; - sattr =flex_array_get (policydb->type_attr_map_array, - scontext->type -1 ); + sattr = &policydb->type_attr_map_array[scontext->type -1 ];BUG_ON (!sattr); - tattr =flex_array_get (policydb->type_attr_map_array, - tcontext->type -1 ); + tattr = &policydb->type_attr_map_array[tcontext->type -1 ];BUG_ON (!tattr);ebitmap_for_each_positive_bit (sattr, snode, i) {ebitmap_for_each_positive_bit (tattr, tnode, j) {
@@ -901,8 +896,7 @@ int security_bounded_transition(struct selinux_state *state, index = new_context->type;while (true) { - type =flex_array_get_ptr (policydb->type_val_to_struct_array, - index -1 ); + type = policydb->type_val_to_struct_array[index -1 ];BUG_ON (!type);/* not bounded anymore */
@@ -1065,11 +1059,9 @@ void security_compute_xperms_decision(struct selinux_state *state, avkey.target_class = tclass; avkey.specified =AVTAB_XPERMS ; - sattr =flex_array_get (policydb->type_attr_map_array, - scontext->type -1 ); + sattr = &policydb->type_attr_map_array[scontext->type -1 ];BUG_ON (!sattr); - tattr =flex_array_get (policydb->type_attr_map_array, - tcontext->type -1 ); + tattr = &policydb->type_attr_map_array[tcontext->type -1 ];BUG_ON (!tattr);ebitmap_for_each_positive_bit (sattr, snode, i) {ebitmap_for_each_positive_bit (tattr, tnode, j) {
Signature · 1 line
2.20.1
PATCH 3/7 selinux: convert to kvmalloc
-------- Forwarded Message --------
Subject: [PATCH 3/7] selinux: convert to kvmalloc
Date: Mon, 17 Dec 2018 08:19:25 -0500
From: Kent Overstreet <[email protected]>
To: [email protected], [email protected]
CC: Kent Overstreet <[email protected]>, [email protected]
The flex arrays were being used for constant sized arrays, so there's no benefit to using flex_arrays over something simpler.
--- security/selinux/ss/avtab.c | 40 +++++----- security/selinux/ss/avtab.h | 4 +- security/selinux/ss/conditional.c | 6 +- security/selinux/ss/policydb.c | 122 ++++++++---------------------- security/selinux/ss/policydb.h | 12 +-- security/selinux/ss/services.c | 22 ++---- 6 files changed, 62 insertions(+), 144 deletions(-)
security/selinux/ss/avtab.c +17 -13
@@ -93,12 +93,10 @@ avtab_insert_node(struct avtab *h, int hvalue, newnode->next = prev->next; prev->next = newnode; }else { - newnode->next =flex_array_get_ptr (h->htable, hvalue); -if (flex_array_put_ptr (h->htable, hvalue, newnode, -GFP_KERNEL |__GFP_ZERO)) { -kmem_cache_free (avtab_node_cachep, newnode); -return NULL ; - } +struct avtab_node **n = &h->htable[hvalue]; + + newnode->next = *n; + *n = newnode; } h->nel++;
@@ -111,11 +109,11 @@ static int avtab_insert(struct avtab *h, struct avtab_key *key, struct avtab_datstruct avtab_node *prev, *cur, *newnode;u16 specified = key->specified & ~(AVTAB_ENABLED |AVTAB_ENABLED_OLD ); - if (!h || !h->htable) +if (!h)return -EINVAL ; hvalue =avtab_hash (key, h->mask); -for (prev =NULL , cur =flex_array_get_ptr (h->htable, hvalue); +for (prev =NULL , cur = h->htable[hvalue]; cur; prev = cur, cur = cur->next) { if (key->source_type == cur->key.source_type &&
@@ -156,10 +154,10 @@ avtab_insert_nonunique(struct avtab *h, struct avtab_key *key, struct avtab_datustruct avtab_node *prev, *cur;u16 specified = key->specified & ~(AVTAB_ENABLED |AVTAB_ENABLED_OLD ); - if (!h || !h->htable) +if (!h)return NULL ; hvalue =avtab_hash (key, h->mask); -for (prev =NULL , cur =flex_array_get_ptr (h->htable, hvalue); +for (prev =NULL , cur = h->htable[hvalue]; cur; prev = cur, cur = cur->next) { if (key->source_type == cur->key.source_type &&
@@ -186,11 +184,11 @@ struct avtab_datum *avtab_search(struct avtab *h, struct avtab_key *key)struct avtab_node *cur;u16 specified = key->specified & ~(AVTAB_ENABLED |AVTAB_ENABLED_OLD ); - if (!h || !h->htable) +if (!h)return NULL ; hvalue =avtab_hash (key, h->mask); -for (cur =flex_array_get_ptr (h->htable, hvalue); cur; +for (cur = h->htable[hvalue]; cur; cur = cur->next) { if (key->source_type == cur->key.source_type && key->target_type == cur->key.target_type &&
@@ -222,11 +220,11 @@ avtab_search_node(struct avtab *h, struct avtab_key *key)struct avtab_node *cur;u16 specified = key->specified & ~(AVTAB_ENABLED |AVTAB_ENABLED_OLD ); - if (!h || !h->htable) +if (!h)return NULL ; hvalue =avtab_hash (key, h->mask); -for (cur =flex_array_get_ptr (h->htable, hvalue); cur; +for (cur = h->htable[hvalue]; cur; cur = cur->next) { if (key->source_type == cur->key.source_type && key->target_type == cur->key.target_type &&
@@ -281,11 +279,11 @@ void avtab_destroy(struct avtab *h)int i;struct avtab_node *cur, *temp; - if (!h || !h->htable) +if (!h)return ;for (i =0 ; i < h->nslot; i++) { - cur =flex_array_get_ptr (h->htable, i); + cur = h->htable[i];while (cur) { temp = cur; cur = cur->next;
@@ -295,7 +293,7 @@ void avtab_destroy(struct avtab *h)kmem_cache_free (avtab_node_cachep, temp); } } -flex_array_free (h->htable); +kvfree (h->htable); h->htable =NULL ; h->nslot =0 ; h->mask =0 ;
@@ -303,6 +301,7 @@ void avtab_destroy(struct avtab *h)int avtab_init (struct avtab *h) { +kvfree (h->htable); h->htable =NULL ; h->nel =0 ;return 0 ;
@@ -329,8 +328,7 @@ int avtab_alloc(struct avtab *h, u32 nrules) nslot =MAX_AVTAB_HASH_BUCKETS ; mask = nslot -1 ; - h->htable =flex_array_alloc (sizeof (struct avtab_node *), nslot, -GFP_KERNEL | __GFP_ZERO); + h->htable = kvcalloc(nslot, sizeof(void *), GFP_KERNEL);if (!h->htable)return -ENOMEM ; @@ -353,7 +351,7 @@ void avtab_hash_eval(struct avtab *h, char *tag)
max_chain_len = 0;
chain2_len_sum = 0;
for (i = 0; i < h->nslot; i++) {
- cur = flex_array_get_ptr(h->htable, i);
+ cur = h->htable[i];
if (cur) {
slots_used++;
chain_len = 0;
@@ -646,7 +644,7 @@ int avtab_write(struct policydb *p, struct avtab *a, void *fp)
return rc;
for (i = 0; i < a->nslot; i++) {
- for (cur = flex_array_get_ptr(a->htable, i); cur;
+ for (cur = a->htable[i]; cur;
cur = cur->next) {
rc = avtab_write_item(p, cur, fp);
if (rc)
security/selinux/ss/avtab.h +1 -3
@@ -24,7 +24,6 @@#define _SS_AVTAB_H_#include "security.h" -#include <linux/flex_array.h> struct avtab_key {u16 source_type;/* source type */
@@ -84,11 +83,10 @@ struct avtab_node { };struct avtab { -struct flex_array *htable; +struct avtab_node **htable;u32 nel;/* number of elements */ u32 nslot;/* number of hash slots */ u32 mask;/* mask to compute hash func */ - };int avtab_init (struct avtab *);
security/selinux/ss/conditional.c +1 -4
@@ -195,7 +195,6 @@ int cond_index_bool(void *key, void *datum, void *datap) {struct policydb *p;struct cond_bool_datum *booldatum; -struct flex_array *fa; booldatum = datum; p = datap;
@@ -203,10 +202,7 @@ int cond_index_bool(void *key, void *datum, void *datap)if (!booldatum->value || booldatum->value > p->p_bools.nprim)return -EINVAL ; - fa = p->sym_val_to_name[SYM_BOOLS ]; -if (flex_array_put_ptr (fa, booldatum->value -1 , key, -GFP_KERNEL | __GFP_ZERO)) -BUG (); + p->sym_val_to_name[SYM_BOOLS ][booldatum->value -1 ] = key; p->bool_val_to_struct[booldatum->value -1 ] = booldatum;return 0 ;
security/selinux/ss/policydb.c +2 -5
@@ -36,7 +36,6 @@#include <linux/string.h> #include <linux/errno.h> #include <linux/audit.h> -#include <linux/flex_array.h> #include "security.h" #include "policydb.h"
@@ -341,17 +340,14 @@ static int common_index(void *key, void *datum, void *datap) {struct policydb *p;struct common_datum *comdatum; -struct flex_array *fa; comdatum = datum; p = datap;if (!comdatum->value || comdatum->value > p->p_commons.nprim)return -EINVAL ; - fa = p->sym_val_to_name[SYM_COMMONS ]; -if (flex_array_put_ptr (fa, comdatum->value -1 , key, -GFP_KERNEL | __GFP_ZERO)) -BUG (); + p->sym_val_to_name[SYM_COMMONS ][comdatum->value -1 ] = key; +return 0 ; } @@ -359,16 +355,13 @@ static int class_index(void *key, void *datum,
void *datap)
{
struct policydb *p;
struct class_datum *cladatum;
- struct flex_array *fa;
cladatum = datum;
p = datap;
if (!cladatum->value || cladatum->value > p->p_classes.nprim)
return -EINVAL;
- fa = p->sym_val_to_name[SYM_CLASSES];
- if (flex_array_put_ptr(fa, cladatum->value - 1, key,
- GFP_KERNEL | __GFP_ZERO))
- BUG();
+
+ p->sym_val_to_name[SYM_CLASSES][cladatum->value - 1] = key;
p->class_val_to_struct[cladatum->value - 1] = cladatum; return 0;
}
@@ -377,7 +370,6 @@ static int role_index(void *key, void *datum, void *datap)
{
struct policydb *p;
struct role_datum *role;
- struct flex_array *fa;
role = datum;
p = datap;
@@ -386,10 +378,7 @@ static int role_index(void *key, void *datum, void *datap)
|| role->bounds > p->p_roles.nprim)
return -EINVAL;
- fa = p->sym_val_to_name[SYM_ROLES];
- if (flex_array_put_ptr(fa, role->value - 1, key,
- GFP_KERNEL | __GFP_ZERO))
- BUG();
+ p->sym_val_to_name[SYM_ROLES][role->value - 1] = key;
p->role_val_to_struct[role->value - 1] = role;
return 0;
}
@@ -398,7 +387,6 @@ static int type_index(void *key, void *datum, void *datap)
{
struct policydb *p;
struct type_datum *typdatum;
- struct flex_array *fa;
typdatum = datum;
p = datap;
@@ -408,15 +396,8 @@ static int type_index(void *key, void *datum, void *datap)
|| typdatum->value > p->p_types.nprim || typdatum->bounds > p->p_types.nprim)
return -EINVAL;
- fa = p->sym_val_to_name[SYM_TYPES];
- if (flex_array_put_ptr(fa, typdatum->value - 1, key,
- GFP_KERNEL | __GFP_ZERO))
- BUG();
-
- fa = p->type_val_to_struct_array;
- if (flex_array_put_ptr(fa, typdatum->value - 1, typdatum,
- GFP_KERNEL | __GFP_ZERO))
- BUG();
+ p->sym_val_to_name[SYM_TYPES][typdatum->value - 1] = key;
+ p->type_val_to_struct_array[typdatum->value - 1] = typdatum;
}
return 0;
@@ -426,7 +407,6 @@ static int user_index(void *key, void *datum, void *datap)
{
struct policydb *p;
struct user_datum *usrdatum;
- struct flex_array *fa;
usrdatum = datum;
p = datap;
@@ -435,10 +415,7 @@ static int user_index(void *key, void *datum, void *datap)
|| usrdatum->bounds > p->p_users.nprim)
return -EINVAL;
- fa = p->sym_val_to_name[SYM_USERS];
- if (flex_array_put_ptr(fa, usrdatum->value - 1, key,
- GFP_KERNEL | __GFP_ZERO))
- BUG();
+ p->sym_val_to_name[SYM_USERS][usrdatum->value - 1] = key;
p->user_val_to_struct[usrdatum->value - 1] = usrdatum;
return 0;
}
@@ -447,7 +424,6 @@ static int sens_index(void *key, void *datum, void *datap)
{
struct policydb *p;
struct level_datum *levdatum;
- struct flex_array *fa;
levdatum = datum;
p = datap;
@@ -456,10 +432,8 @@ static int sens_index(void *key, void *datum, void *datap)
if (!levdatum->level->sens ||
levdatum->level->sens > p->p_levels.nprim)
return -EINVAL;
- fa = p->sym_val_to_name[SYM_LEVELS];
- if (flex_array_put_ptr(fa, levdatum->level->sens - 1, key,
- GFP_KERNEL | __GFP_ZERO))
- BUG();
+
+ p->sym_val_to_name[SYM_LEVELS][levdatum->level->sens - 1] = key;
}
return 0;
@@ -469,7 +443,6 @@ static int cat_index(void *key, void *datum, void *datap)
{
struct policydb *p;
struct cat_datum *catdatum;
- struct flex_array *fa;
catdatum = datum;
p = datap;
@@ -477,10 +450,8 @@ static int cat_index(void *key, void *datum, void *datap)
if (!catdatum->isalias) {
if (!catdatum->value || catdatum->value > p->p_cats.nprim)
return -EINVAL;
- fa = p->sym_val_to_name[SYM_CATS];
- if (flex_array_put_ptr(fa, catdatum->value - 1, key,
- GFP_KERNEL | __GFP_ZERO))
- BUG();
+
+ p->sym_val_to_name[SYM_CATS][catdatum->value - 1] = key;
}
return 0;
@@ -568,35 +539,23 @@ static int policydb_index(struct policydb *p)
if (!p->user_val_to_struct)
return -ENOMEM;
- /* Yes, I want the sizeof the pointer, not the structure */
- p->type_val_to_struct_array = flex_array_alloc(sizeof(struct type_datum *),
- p->p_types.nprim,
- GFP_KERNEL | __GFP_ZERO);
+ p->type_val_to_struct_array = kvcalloc(p->p_types.nprim,
+ sizeof(*p->type_val_to_struct_array),
+ GFP_KERNEL);
if (!p->type_val_to_struct_array)
return -ENOMEM;
- rc = flex_array_prealloc(p->type_val_to_struct_array, 0,
- p->p_types.nprim, GFP_KERNEL | __GFP_ZERO);
- if (rc)
- goto out;
-
rc = cond_init_bool_indexes(p);
if (rc)
goto out;
for (i = 0; i < SYM_NUM; i++) {
- p->sym_val_to_name[i] = flex_array_alloc(sizeof(char *),
- p->symtab[i].nprim,
- GFP_KERNEL | __GFP_ZERO);
+ p->sym_val_to_name[i] = kvcalloc(p->symtab[i].nprim,
+ sizeof(char *),
+ GFP_KERNEL);
if (!p->sym_val_to_name[i])
return -ENOMEM;
- rc = flex_array_prealloc(p->sym_val_to_name[i],
- 0, p->symtab[i].nprim,
- GFP_KERNEL | __GFP_ZERO);
- if (rc)
- goto out;
-
rc = hashtab_map(p->symtab[i].table, index_f[i], p);
if (rc)
goto out;
@@ -809,16 +768,13 @@ void policydb_destroy(struct policydb *p)
hashtab_destroy(p->symtab[i].table);
}
- for (i = 0; i < SYM_NUM; i++) {
- if (p->sym_val_to_name[i])
- flex_array_free(p->sym_val_to_name[i]);
- }
+ for (i = 0; i < SYM_NUM; i++)
+ kvfree(p->sym_val_to_name[i]);
kfree(p->class_val_to_struct);
kfree(p->role_val_to_struct);
kfree(p->user_val_to_struct);
- if (p->type_val_to_struct_array)
- flex_array_free(p->type_val_to_struct_array);
+ kvfree(p->type_val_to_struct_array);
avtab_destroy(&p->te_avtab);
@@ -871,17 +827,9 @@ void policydb_destroy(struct policydb *p)
hashtab_map(p->range_tr, range_tr_destroy, NULL); hashtab_destroy(p->range_tr);
- if (p->type_attr_map_array) {
- for (i = 0; i < p->p_types.nprim; i++) {
- struct ebitmap *e;
-
- e = flex_array_get(p->type_attr_map_array, i);
- if (!e)
- continue;
- ebitmap_destroy(e);
- }
- flex_array_free(p->type_attr_map_array);
- }
+ for (i = 0; i < p->p_types.nprim; i++)
+ ebitmap_destroy(&p->type_attr_map_array[i]);
+ kvfree(p->type_attr_map_array);
ebitmap_destroy(&p->filename_trans_ttypes); ebitmap_destroy(&p->policycaps);
@@ -1761,8 +1709,7 @@ static int type_bounds_sanity_check(void *key, void *datum, void *datap)
return -EINVAL;
}
- upper = flex_array_get_ptr(p->type_val_to_struct_array,
- upper->bounds - 1);
+ upper = p->type_val_to_struct_array[upper->bounds - 1];
BUG_ON(!upper);
if (upper->attribute) {
@@ -2519,23 +2466,15 @@ int policydb_read(struct policydb *p, void *fp)
if (rc)
goto bad;
- rc = -ENOMEM;
- p->type_attr_map_array = flex_array_alloc(sizeof(struct ebitmap),
- p->p_types.nprim,
- GFP_KERNEL | __GFP_ZERO);
+ p->type_attr_map_array = kvcalloc(p->p_types.nprim,
+ sizeof(*p->type_attr_map_array),
+ GFP_KERNEL);
if (!p->type_attr_map_array)
goto bad;
- /* preallocate so we don't have to worry about the put ever failing */
- rc = flex_array_prealloc(p->type_attr_map_array, 0, p->p_types.nprim,
- GFP_KERNEL | __GFP_ZERO);
- if (rc)
- goto bad;
-
for (i = 0; i < p->p_types.nprim; i++) {
- struct ebitmap *e = flex_array_get(p->type_attr_map_array, i);
+ struct ebitmap *e = &p->type_attr_map_array[i];
- BUG_ON(!e);
ebitmap_init(e);
if (p->policyvers >= POLICYDB_VERSION_AVTAB) {
rc = ebitmap_read(e, fp);
@@ -3524,9 +3463,8 @@ int policydb_write(struct policydb *p, void *fp)
return rc;
for (i = 0; i < p->p_types.nprim; i++) {
- struct ebitmap *e = flex_array_get(p->type_attr_map_array, i);
+ struct ebitmap *e = &p->type_attr_map_array[i];
- BUG_ON(!e);
rc = ebitmap_write(e, fp);
if (rc)
return rc;
security/selinux/ss/policydb.h +3 -4
@@ -24,8 +24,6 @@#ifndef _SS_POLICYDB_H_#define _SS_POLICYDB_H_ -#include <linux/flex_array.h> -#include "symtab.h" #include "avtab.h" #include "sidtab.h"
@@ -251,13 +249,13 @@ struct policydb {#define p_cats symtab[SYM_CATS]/* symbol names indexed by (value - 1) */ -struct flex_array *sym_val_to_name[SYM_NUM ]; +char **sym_val_to_name[SYM_NUM ];/* class, role, and user attributes indexed by (value - 1) */ struct class_datum **class_val_to_struct;struct role_datum **role_val_to_struct;struct user_datum **user_val_to_struct; -struct flex_array *type_val_to_struct_array; +struct type_datum **type_val_to_struct_array;/* type enforcement access vectors and transitions */ struct avtab te_avtab;
@@ -294,7 +292,7 @@ struct policydb {struct hashtab *range_tr;/* type -> attribute reverse mapping */ -struct flex_array *type_attr_map_array; +struct ebitmap *type_attr_map_array;struct ebitmap policycaps; @@ -369,9 +367,7 @@ static inline int put_entry(const void *buf,
size_t bytes, int num, struct polic
static inline char *sym_name(struct policydb *p, unsigned intsym_num, unsigned int element_nr)
{
- struct flex_array *fa = p->sym_val_to_name[sym_num];
-
- return flex_array_get_ptr(fa, element_nr);
+ return p->sym_val_to_name[sym_num][element_nr];
}
extern u16 string_to_security_class(struct policydb *p, const char
*name);
security/selinux/ss/services.c +0 -1
@@ -50,7 +50,6 @@#include <linux/audit.h> #include <linux/mutex.h> #include <linux/selinux.h> -#include <linux/flex_array.h> #include <linux/vmalloc.h> #include <net/netlabel.h> @@ -546,15 +545,13 @@ static void type_attribute_bounds_av(struct
policydb *policydb,
struct type_datum *target;
u32 masked = 0;
- source = flex_array_get_ptr(policydb->type_val_to_struct_array,
- scontext->type - 1);
+ source = policydb->type_val_to_struct_array[scontext->type - 1];
BUG_ON(!source);
if (!source->bounds)
return;
- target = flex_array_get_ptr(policydb->type_val_to_struct_array,
- tcontext->type - 1);
+ target = policydb->type_val_to_struct_array[tcontext->type - 1];
BUG_ON(!target);
memset(&lo_avd, 0, sizeof(lo_avd));
@@ -654,11 +651,9 @@ static void context_struct_compute_av(struct policydb *policydb,
*/
avkey.target_class = tclass;
avkey.specified = AVTAB_AV | AVTAB_XPERMS;
- sattr = flex_array_get(policydb->type_attr_map_array,
- scontext->type - 1);
+ sattr = &policydb->type_attr_map_array[scontext->type - 1];
BUG_ON(!sattr);
- tattr = flex_array_get(policydb->type_attr_map_array,
- tcontext->type - 1);
+ tattr = &policydb->type_attr_map_array[tcontext->type - 1];
BUG_ON(!tattr);
ebitmap_for_each_positive_bit(sattr, snode, i) {
ebitmap_for_each_positive_bit(tattr, tnode, j) {
@@ -901,8 +896,7 @@ int security_bounded_transition(struct selinux_state *state,
index = new_context->type;
while (true) {
- type = flex_array_get_ptr(policydb->type_val_to_struct_array,
- index - 1);
+ type = policydb->type_val_to_struct_array[index - 1];
BUG_ON(!type);
/* not bounded anymore */
@@ -1065,11 +1059,9 @@ void security_compute_xperms_decision(struct selinux_state *state,
avkey.target_class = tclass;
avkey.specified = AVTAB_XPERMS;
- sattr = flex_array_get(policydb->type_attr_map_array,
- scontext->type - 1);
+ sattr = &policydb->type_attr_map_array[scontext->type - 1];
BUG_ON(!sattr);
- tattr = flex_array_get(policydb->type_attr_map_array,
- tcontext->type - 1);
+ tattr = &policydb->type_attr_map_array[tcontext->type - 1];
BUG_ON(!tattr);
ebitmap_for_each_positive_bit(sattr, snode, i) {
ebitmap_for_each_positive_bit(tattr, tnode, j) {
Signature · 1 line
2.20.1
Re: Fwd: [PATCH 3/7] selinux: convert to kvmalloc
Quoted 533 lines · Stephen Smalley
-------- Forwarded Message --------
Subject: [PATCH 3/7] selinux: convert to kvmalloc
Date: Mon, 17 Dec 2018 08:19:25 -0500
From: Kent Overstreet <[email protected]>
To: [email protected], [email protected]
CC: Kent Overstreet <[email protected]>, [email protected]The flex arrays were being used for constant sized arrays, so there's no benefit to using
flex_arraysover something simpler.Signed-off-by Kent Overstreet <[email protected]>---
security/selinux/ss/avtab.c | 40 +++++----- security/selinux/ss/avtab.h | 4 +-security/selinux/ss/conditional.c| 6 +-security/selinux/ss/policydb.c | 122 ++++++++---------------------- security/selinux/ss/policydb.h | 12 +-- security/selinux/ss/services.c | 22 ++---- 6 files changed, 62 insertions(+), 144 deletions(-)security/selinux/ss/avtab.c +6
-7@@ -93,12 +93,10 @@ avtab_insert_node(struct avtab *h, int hvalue, newnode->next = prev->next; prev->next = newnode; } else { - newnode->next = flex_array_get_ptr(h->htable, hvalue); - if (flex_array_put_ptr(h->htable, hvalue, newnode, - GFP_KERNEL|__GFP_ZERO)) { - kmem_cache_free(avtab_node_cachep, newnode); - return NULL; - } + struct avtab_node **n = &h->htable[hvalue]; + + newnode->next = *n; + *n = newnode; } h->nel++;@@ -111,11 +109,11 @@ static int avtab_insert(struct avtab *h, struct avtab_key *key, struct avtab_dat struct avtab_node *prev, *cur, *newnode; u16 specified = key->specified & ~(AVTAB_ENABLED|AVTAB_ENABLED_OLD); - if (!h || !h->htable) + if (!h) return -EINVAL; hvalue = avtab_hash(key, h->mask); - for (prev = NULL, cur = flex_array_get_ptr(h->htable, hvalue); + for (prev = NULL, cur = h->htable[hvalue]; cur; prev = cur, cur = cur->next) {if (
key->source_type==cur->key.source_type&&security/selinux/ss/avtab.c +2
-1@@ -156,10 +154,10 @@ avtab_insert_nonunique(struct avtab *h, struct avtab_key *key, struct avtab_datu struct avtab_node *prev, *cur; u16 specified = key->specified & ~(AVTAB_ENABLED|AVTAB_ENABLED_OLD); - if (!h || !h->htable) + if (!h) return NULL; hvalue = avtab_hash(key, h->mask); - for (prev = NULL, cur = flex_array_get_ptr(h->htable, hvalue); + for (prev = NULL, cur = h->htable[hvalue]; cur; prev = cur, cur = cur->next) {if (
key->source_type==cur->key.source_type&&security/selinux/ss/avtab.c +2
-1@@ -186,11 +184,11 @@ struct avtab_datum *avtab_search(struct avtab *h, struct avtab_key *key) struct avtab_node *cur; u16 specified = key->specified & ~(AVTAB_ENABLED|AVTAB_ENABLED_OLD); - if (!h || !h->htable) + if (!h) return NULL; hvalue = avtab_hash(key, h->mask); - for (cur = flex_array_get_ptr(h->htable, hvalue); cur; + for (cur = h->htable[hvalue]; cur; cur = cur->next) {if (
key->source_type==cur->key.source_type&&key->target_type==cur->key.target_type&&security/selinux/ss/avtab.c +2
-1@@ -222,11 +220,11 @@ avtab_search_node(struct avtab *h, struct avtab_key *key) struct avtab_node *cur; u16 specified = key->specified & ~(AVTAB_ENABLED|AVTAB_ENABLED_OLD); - if (!h || !h->htable) + if (!h) return NULL; hvalue = avtab_hash(key, h->mask); - for (cur = flex_array_get_ptr(h->htable, hvalue); cur; + for (cur = h->htable[hvalue]; cur; cur = cur->next) {if (
key->source_type==cur->key.source_type&&key->target_type==cur->key.target_type&&security/selinux/ss/avtab.c +5
-3@@ -281,11 +279,11 @@ void avtab_destroy(struct avtab *h) int i; struct avtab_node *cur, *temp; - if (!h || !h->htable) + if (!h) return; for (i = 0; i < h->nslot; i++) { - cur = flex_array_get_ptr(h->htable, i); + cur = h->htable[i]; while (cur) { temp = cur; cur = cur->next;@@ -295,7 +293,7 @@ void avtab_destroy(struct avtab *h) kmem_cache_free(avtab_node_cachep, temp); } } - flex_array_free(h->htable); + kvfree(h->htable); h->htable = NULL; h->nslot = 0; h->mask = 0;@@ -303,6 +301,7 @@ void avtab_destroy(struct avtab *h) int avtab_init(struct avtab *h) { + kvfree(h->htable); h->htable = NULL; h->nel = 0; return 0;@@ -329,8 +328,7 @@ int avtab_alloc(struct avtab *h, u32 nrules) nslot = MAX_AVTAB_HASH_BUCKETS; mask = nslot - 1; - h->htable = flex_array_alloc(sizeof(struct avtab_node *), nslot, - GFP_KERNEL | __GFP_ZERO); + h->htable = kvcalloc(nslot, sizeof(void *), GFP_KERNEL); if (!h->htable) return -ENOMEM; @@ -353,7 +351,7 @@ void avtab_hash_eval(struct avtab *h, char *tag)
max_chain_len= 0;
chain2_len_sum= 0;
for (i = 0; i <h->nslot; i++) {
- cur =flex_array_get_ptr(h->htable, i);
+ cur = h->htable[i];
if (cur) {
slots_used++;
chain_len= 0;security/selinux/ss/avtab.c +1
-1@@ -646,7 +644,7 @@ int avtab_write(struct policydb *p, struct avtab *a, void *fp) return rc; for (i = 0; i < a->nslot; i++) { - for (cur = flex_array_get_ptr(a->htable, i); cur; + for (cur = a->htable[i]; cur; cur = cur->next) { rc = avtab_write_item(p, cur, fp); if (rc)security/selinux/ss/avtab.h +0
-1@@ -24,7 +24,6 @@ #define _SS_AVTAB_H_ #include "security.h" -#include <linux/flex_array.h> struct avtab_key {u16 source_type; /* source type */
security/selinux/ss/avtab.h +1
-1@@ -84,11 +83,10 @@ struct avtab_node { }; struct avtab { - struct flex_array *htable; + struct avtab_node **htable;u32 nel; /* number of elements */ u32 nslot; /* number of hash slots */ u32 mask; /* mask to compute hash func */ -
};
intavtab_init(struct avtab *);security/selinux/ss/conditional.c +1
-4@@ -195,7 +195,6 @@ int cond_index_bool(void *key, void *datum, void *datap) { struct policydb *p; struct cond_bool_datum *booldatum; - struct flex_array *fa; booldatum = datum; p = datap;@@ -203,10 +202,7 @@ int cond_index_bool(void *key, void *datum, void *datap) if (!booldatum->value || booldatum->value > p->p_bools.nprim) return -EINVAL; - fa = p->sym_val_to_name[SYM_BOOLS]; - if (flex_array_put_ptr(fa, booldatum->value - 1, key, - GFP_KERNEL | __GFP_ZERO)) - BUG(); + p->sym_val_to_name[SYM_BOOLS][booldatum->value - 1] = key; p->bool_val_to_struct[booldatum->value - 1] = booldatum; return 0;security/selinux/ss/policydb.c +2
-5@@ -36,7 +36,6 @@ #include <linux/string.h> #include <linux/errno.h> #include <linux/audit.h> -#include <linux/flex_array.h> #include "security.h" #include "policydb.h"@@ -341,17 +340,14 @@ static int common_index(void *key, void *datum, void *datap) { struct policydb *p; struct common_datum *comdatum; - struct flex_array *fa; comdatum = datum; p = datap; if (!comdatum->value || comdatum->value > p->p_commons.nprim) return -EINVAL; - fa = p->sym_val_to_name[SYM_COMMONS]; - if (flex_array_put_ptr(fa, comdatum->value - 1, key, - GFP_KERNEL | __GFP_ZERO)) - BUG(); + p->sym_val_to_name[SYM_COMMONS][comdatum->value - 1] = key; + return 0; } @@ -359,16 +355,13 @@ static int class_index(void *key, void *datum, void *datap) {struct policydb *p;
structclass_datum*cladatum;
- structflex_array*fa;
cladatum = datum;
p = datap;
if (!cladatum->value ||cladatum->value>p->p_classes.nprim) return-EINVAL;
- fa = p->sym_val_to_name[SYM_CLASSES];
- if (flex_array_put_ptr(fa, cladatum->value - 1, key, - GFP_KERNEL | __GFP_ZERO))
-BUG();
+
+ p->sym_val_to_name[SYM_CLASSES][cladatum->value - 1] = key; p->class_val_to_struct[cladatum->value - 1] = cladatum; return 0;
}security/selinux/ss/policydb.c +1
-5@@ -377,7 +370,6 @@ static int role_index(void *key, void *datum, void *datap) { struct policydb *p; struct role_datum *role; - struct flex_array *fa; role = datum; p = datap;@@ -386,10 +378,7 @@ static int role_index(void *key, void *datum, void *datap) || role->bounds > p->p_roles.nprim) return -EINVAL; - fa = p->sym_val_to_name[SYM_ROLES]; - if (flex_array_put_ptr(fa, role->value - 1, key, - GFP_KERNEL | __GFP_ZERO)) - BUG(); + p->sym_val_to_name[SYM_ROLES][role->value - 1] = key; p->role_val_to_struct[role->value - 1] = role; return 0; }@@ -398,7 +387,6 @@ static int type_index(void *key, void *datum, void *datap) { struct policydb *p; struct type_datum *typdatum; - struct flex_array *fa; typdatum = datum; p = datap;@@ -408,15 +396,8 @@ static int type_index(void *key, void *datum, void *datap)|| typdatum->value > p->p_types.nprim || typdatum->bounds > p->p_types.nprim)return
-EINVAL;
- fa = p->sym_val_to_name[SYM_TYPES];
- if (flex_array_put_ptr(fa,typdatum->value- 1, key, -GFP_KERNEL|__GFP_ZERO))
-BUG();
-
- fa =p->type_val_to_struct_array;
- if (flex_array_put_ptr(fa,typdatum->value- 1, typdatum, -GFP_KERNEL|__GFP_ZERO))
-BUG();
+ p->sym_val_to_name[SYM_TYPES][typdatum->value - 1] = key; + p->type_val_to_struct_array[typdatum->value - 1] = typdatum; }
return 0;security/selinux/ss/policydb.c +1
-5@@ -426,7 +407,6 @@ static int user_index(void *key, void *datum, void *datap) { struct policydb *p; struct user_datum *usrdatum; - struct flex_array *fa; usrdatum = datum; p = datap;@@ -435,10 +415,7 @@ static int user_index(void *key, void *datum, void *datap) || usrdatum->bounds > p->p_users.nprim) return -EINVAL; - fa = p->sym_val_to_name[SYM_USERS]; - if (flex_array_put_ptr(fa, usrdatum->value - 1, key, - GFP_KERNEL | __GFP_ZERO)) - BUG(); + p->sym_val_to_name[SYM_USERS][usrdatum->value - 1] = key; p->user_val_to_struct[usrdatum->value - 1] = usrdatum; return 0; }@@ -447,7 +424,6 @@ static int sens_index(void *key, void *datum, void *datap) { struct policydb *p; struct level_datum *levdatum; - struct flex_array *fa; levdatum = datum; p = datap;@@ -456,10 +432,8 @@ static int sens_index(void *key, void *datum, void *datap)if (!levdatum->level->sens ||
levdatum->level->sens>p->p_levels.nprim) return-EINVAL;
- fa = p->sym_val_to_name[SYM_LEVELS];
- if (flex_array_put_ptr(fa,levdatum->level->sens- 1, key, -GFP_KERNEL|__GFP_ZERO))
-BUG();
+
+ p->sym_val_to_name[SYM_LEVELS][levdatum->level->sens - 1] = key; }
return 0;security/selinux/ss/policydb.c +2
-5@@ -469,7 +443,6 @@ static int cat_index(void *key, void *datum, void *datap) { struct policydb *p; struct cat_datum *catdatum; - struct flex_array *fa; catdatum = datum; p = datap;@@ -477,10 +450,8 @@ static int cat_index(void *key, void *datum, void *datap) if (!catdatum->isalias) { if (!catdatum->value || catdatum->value > p->p_cats.nprim) return -EINVAL; - fa = p->sym_val_to_name[SYM_CATS]; - if (flex_array_put_ptr(fa, catdatum->value - 1, key, - GFP_KERNEL | __GFP_ZERO)) - BUG(); + + p->sym_val_to_name[SYM_CATS][catdatum->value - 1] = key; } return 0;@@ -568,35 +539,23 @@ static int policydb_index(struct policydb *p) if (!p->user_val_to_struct) return -ENOMEM;- /* Yes, I want the sizeof the pointer, not the structure */
-p->type_val_to_struct_array= flex_array_alloc(sizeof(structtype_datum*), -p->p_types.nprim,
-GFP_KERNEL|__GFP_ZERO);
+p->type_val_to_struct_array= kvcalloc(p->p_types.nprim,
+sizeof(*p->type_val_to_struct_array),
+GFP_KERNEL);
if (!p->type_val_to_struct_array)
return-ENOMEM;
- rc = flex_array_prealloc(p->type_val_to_struct_array, 0,
-p->p_types.nprim,GFP_KERNEL|__GFP_ZERO);
- if (rc)
- goto out;
-
rc =cond_init_bool_indexes(p);
if (rc)
goto out;
for (i = 0; i <SYM_NUM; i++) {
- p->sym_val_to_name[i] = flex_array_alloc(sizeof(char *),
- p->symtab[i].nprim,
-GFP_KERNEL|__GFP_ZERO);
+ p->sym_val_to_name[i] = kvcalloc(p->symtab[i].nprim,
+sizeof(char *),
+GFP_KERNEL);
if (!p->sym_val_to_name[i])
return-ENOMEM;
- rc = flex_array_prealloc(p->sym_val_to_name[i],
- 0, p->symtab[i].nprim,
-GFP_KERNEL|__GFP_ZERO);
- if (rc)
- goto out;
-
rc =hashtab_map(p->symtab[i].table, index_f[i], p);
if (rc)
goto out;security/selinux/ss/policydb.c +3
-5@@ -809,16 +768,13 @@ void policydb_destroy(struct policydb *p) hashtab_destroy(p->symtab[i].table); } - for (i = 0; i < SYM_NUM; i++) { - if (p->sym_val_to_name[i]) - flex_array_free(p->sym_val_to_name[i]); - } + for (i = 0; i < SYM_NUM; i++) + kvfree(p->sym_val_to_name[i]); kfree(p->class_val_to_struct); kfree(p->role_val_to_struct); kfree(p->user_val_to_struct); - if (p->type_val_to_struct_array) - flex_array_free(p->type_val_to_struct_array); + kvfree(p->type_val_to_struct_array); avtab_destroy(&p->te_avtab); @@ -871,17 +827,9 @@ void policydb_destroy(struct policydb *p) hashtab_map(p->range_tr, range_tr_destroy, NULL); hashtab_destroy(p->range_tr);- if (
p->type_attr_map_array) {
- for (i = 0; i <p->p_types.nprim; i++) { - struct ebitmap *e;
-
- e =flex_array_get(p->type_attr_map_array, i); - if (!e)
- continue;
-ebitmap_destroy(e);
- }
-flex_array_free(p->type_attr_map_array); - }
+ for (i = 0; i <p->p_types.nprim; i++)
+ebitmap_destroy(&p->type_attr_map_array[i]); +kvfree(p->type_attr_map_array);ebitmap_destroy(&p->filename_trans_ttypes);ebitmap_destroy(&p->policycaps);security/selinux/ss/policydb.c +4
-4@@ -1761,8 +1709,7 @@ static int type_bounds_sanity_check(void *key, void *datum, void *datap) return -EINVAL; } - upper = flex_array_get_ptr(p->type_val_to_struct_array, - upper->bounds - 1); + upper = p->type_val_to_struct_array[upper->bounds - 1]; BUG_ON(!upper); if (upper->attribute) {@@ -2519,23 +2466,15 @@ int policydb_read(struct policydb *p, void *fp) if (rc) goto bad; - rc = -ENOMEM; - p->type_attr_map_array = flex_array_alloc(sizeof(struct ebitmap), - p->p_types.nprim, - GFP_KERNEL | __GFP_ZERO); + p->type_attr_map_array = kvcalloc(p->p_types.nprim, + sizeof(*p->type_attr_map_array), + GFP_KERNEL); if (!p->type_attr_map_array) goto bad;- /* preallocate so we don't have to worry about the put ever failing */ - rc = flex_array_prealloc(p->type_attr_map_array, 0,
p->p_types.nprim, -GFP_KERNEL|__GFP_ZERO);
- if (rc)
- goto bad;
-
for (i = 0; i <p->p_types.nprim; i++) {
- struct ebitmap *e =flex_array_get(p->type_attr_map_array, i); + struct ebitmap *e = &p->type_attr_map_array[i];
-BUG_ON(!e);
ebitmap_init(e);
if (p->policyvers>=POLICYDB_VERSION_AVTAB) {
rc =ebitmap_read(e, fp);security/selinux/ss/policydb.c +1
-1@@ -3524,9 +3463,8 @@ int policydb_write(struct policydb *p, void *fp) return rc; for (i = 0; i < p->p_types.nprim; i++) { - struct ebitmap *e = flex_array_get(p->type_attr_map_array, i); + struct ebitmap *e = &p->type_attr_map_array[i]; - BUG_ON(!e); rc = ebitmap_write(e, fp); if (rc) return rc;security/selinux/ss/policydb.h +0
-0@@ -24,8 +24,6 @@ #ifndef _SS_POLICYDB_H_ #define _SS_POLICYDB_H_-#include <
linux/flex_array.h>
-
#include "symtab.h"
#include "avtab.h"
#include "sidtab.h"security/selinux/ss/policydb.h +3
-3@@ -251,13 +249,13 @@ struct policydb { #define p_cats symtab[SYM_CATS] /* symbol names indexed by (value - 1) */ - struct flex_array *sym_val_to_name[SYM_NUM]; + char **sym_val_to_name[SYM_NUM]; /* class, role, and user attributes indexed by (value - 1) */ struct class_datum **class_val_to_struct; struct role_datum **role_val_to_struct; struct user_datum **user_val_to_struct; - struct flex_array *type_val_to_struct_array; + struct type_datum **type_val_to_struct_array; /* type enforcement access vectors and transitions */ struct avtab te_avtab;@@ -294,7 +292,7 @@ struct policydb { struct hashtab *range_tr; /* type -> attribute reverse mapping */ - struct flex_array *type_attr_map_array; + struct ebitmap *type_attr_map_array; struct ebitmap policycaps;@@ -369,9 +367,7 @@ static inline int put_entry(const void *buf,
size_tbytes, int num, struct polic static inline char *sym_name(struct policydb *p, unsigned intsym_num, unsigned intelement_nr) {
- structflex_array*fa = p->sym_val_to_name[sym_num];
-
- returnflex_array_get_ptr(fa, element_nr);
+ return p->sym_val_to_name[sym_num][element_nr];
}
extern u16string_to_security_class(struct policydb *p, const char *name);security/selinux/ss/services.c +0
-1@@ -50,7 +50,6 @@ #include <linux/audit.h> #include <linux/mutex.h> #include <linux/selinux.h> -#include <linux/flex_array.h> #include <linux/vmalloc.h> #include <net/netlabel.h> @@ -546,15 +545,13 @@ static void type_attribute_bounds_av(struct policydb *policydb,struct
type_datum*target;
u32 masked = 0;
- source =flex_array_get_ptr(policydb->type_val_to_struct_array, - scontext->type - 1);
+ source = policydb->type_val_to_struct_array[scontext->type - 1];BUG_ON(!source);
if (!source->bounds)
return;
- target =flex_array_get_ptr(policydb->type_val_to_struct_array, - tcontext->type - 1);
+ target = policydb->type_val_to_struct_array[tcontext->type - 1];BUG_ON(!target);
memset(&lo_avd, 0, sizeof(lo_avd));security/selinux/ss/services.c +3
-6@@ -654,11 +651,9 @@ static void context_struct_compute_av(struct policydb *policydb,*/ avkey.target_class = tclass; avkey.specified = AVTAB_AV | AVTAB_XPERMS; - sattr = flex_array_get(policydb->type_attr_map_array, - scontext->type - 1); + sattr = &policydb->type_attr_map_array[scontext->type - 1]; BUG_ON(!sattr); - tattr = flex_array_get(policydb->type_attr_map_array, - tcontext->type - 1); + tattr = &policydb->type_attr_map_array[tcontext->type - 1]; BUG_ON(!tattr); ebitmap_for_each_positive_bit(sattr, snode, i) { ebitmap_for_each_positive_bit(tattr, tnode, j) {@@ -901,8 +896,7 @@ int security_bounded_transition(struct selinux_state *state, index = new_context->type; while (true) { - type = flex_array_get_ptr(policydb->type_val_to_struct_array, - index - 1); + type = policydb->type_val_to_struct_array[index - 1]; BUG_ON(!type); /* not bounded anymore */@@ -1065,11 +1059,9 @@ void security_compute_xperms_decision(struct selinux_state *state, avkey.target_class = tclass; avkey.specified = AVTAB_XPERMS;
security/selinux/ss/services.c void security_compute_xperms_decision(struct selinux_state *state, · line 1066
Quoted 10 lines
security/selinux/ss/services.c +2
-4- sattr = flex_array_get(policydb->type_attr_map_array, - scontext->type - 1); + sattr = &policydb->type_attr_map_array[scontext->type - 1]; BUG_ON(!sattr); - tattr = flex_array_get(policydb->type_attr_map_array, - tcontext->type - 1); + tattr = &policydb->type_attr_map_array[tcontext->type - 1]; BUG_ON(!tattr); ebitmap_for_each_positive_bit(sattr, snode, i) { ebitmap_for_each_positive_bit(tattr, tnode, j) {
Im not sure that this is good way. Surely it looks better, but it will be harder to get it to work with rcu locks. And I think we will have a performance penalty on small system were it will be mapped in the same way as vmalloc.
PATCH 4/7 Generic radix trees
In reply to Kent OverstreetVery simple radix tree implementation that supports storing arbitrary size entries, up to PAGE_SIZE - upcoming patches will convert existing flex_array users to genradixes. The new genradix code has a much simpler API and implementation, and doesn't have a hard limit on the number of elements like flex_array does.
--- Documentation/core-api/generic-radix-tree.rst | 12 + Documentation/core-api/index.rst | 1 + include/linux/generic-radix-tree.h | 231 ++++++++++++++++++ lib/Makefile | 3 +- lib/generic-radix-tree.c | 217 ++++++++++++++++ 5 files changed, 463 insertions(+), 1 deletion(-) create mode 100644 Documentation/core-api/generic-radix-tree.rst create mode 100644 include/linux/generic-radix-tree.h create mode 100644 lib/generic-radix-tree.c
Documentation/core-api/generic-radix-tree.rst new file +12 -0
@@ -0,0 +1,12 @@ +================================= +Generic radix trees/sparse arrays +================================= + +.. kernel-doc:: include/linux/generic-radix-tree.h + :doc: Generic radix trees/sparse arrays + +generic radix tree functions +---------------------------- + +.. kernel-doc:: include/linux/generic-radix-tree.h + :functions:
Documentation/core-api/index.rst +1 -0
@@ -28,6 +28,7 @@ Core utilities errseq printk-formats circular-buffers + generic-radix-tree memory-allocation mm-api gfp_mask-from-fs-io
include/linux/generic-radix-tree.h new file +231 -0
231 lines not on this page · raw message
lib/Makefile +2 -1
@@ -38,7 +38,8 @@ obj-y += bcd.o div64.o sort.o parser.o debug_locks.o random32.o \ gcd.o lcm.o list_sort.o uuid.o flex_array.o iov_iter.o clz_ctz.o \ bsearch.o find_bit.o llist.o memweight.o kfifo.o \ percpu-refcount.o rhashtable.o reciprocal_div.o \ - once.o refcount.o usercopy.o errseq.o bucket_locks.o + once.o refcount.o usercopy.o errseq.o bucket_locks.o \ + generic-radix-tree.o obj-$(CONFIG_STRING_SELFTEST) += test_string.o obj-y += string_helpers.o obj-$(CONFIG_TEST_STRING_HELPERS) += test-string_helpers.o
lib/generic-radix-tree.c new file +217 -0
217 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH 5/7 proc: commit to genradix
In reply to Kent Overstreetthe new generic radix trees have a simpler API and implementation, and no limitations on number of elements, so all flex_array users are being converted
--- fs/proc/base.c | 43 +++++++++++++++---------------------------- 1 file changed, 15 insertions(+), 28 deletions(-)
fs/proc/base.c +15 -28
@@ -59,6 +59,7 @@#include <linux/capability.h> #include <linux/file.h> #include <linux/fdtable.h> +#include <linux/generic-radix-tree.h> #include <linux/string.h> #include <linux/seq_file.h> #include <linux/namei.h>
@@ -92,7 +93,6 @@#include <linux/sched/coredump.h> #include <linux/sched/debug.h> #include <linux/sched/stat.h> -#include <linux/flex_array.h> #include <linux/posix-timers.h> #include <trace/events/oom.h> #include "internal.h"
@@ -2140,11 +2140,12 @@ proc_map_files_readdir(struct file *file, struct dir_context *ctx)struct task_struct *task;struct mm_struct *mm;unsigned long nr_files, pos, i; -struct flex_array *fa =NULL ; -struct map_files_info info; +GENRADIX (struct map_files_info ) fa;struct map_files_info *p;int ret; +genradix_init (&fa); + ret = -ENOENT ; task =get_proc_task (file_inode (file));if (!task)
@@ -2176,35 +2177,22 @@ proc_map_files_readdir(struct file *file, struct dir_context *ctx)*/ for (vma = mm->mmap, pos =2 ; vma; vma = vma->vm_next) { -if (vma->vm_file && ++pos > ctx->pos) - nr_files++; - } +if (!vma->vm_file) +continue ; +if (++pos <= ctx->pos) +continue ; -if (nr_files) { - fa =flex_array_alloc (sizeof (info), nr_files, -GFP_KERNEL ); -if (!fa ||flex_array_prealloc (fa,0 , nr_files, -GFP_KERNEL )) { + p =genradix_ptr_alloc (&fa, nr_files++,GFP_KERNEL ); +if (!p) { ret = -ENOMEM ; -if (fa) -flex_array_free (fa);up_read (&mm->mmap_sem);mmput (mm); goto out_put_task; } -for (i =0 , vma = mm->mmap, pos =2 ; vma; - vma = vma->vm_next) { -if (!vma->vm_file) -continue ; -if (++pos <= ctx->pos) -continue ; - info.start = vma->vm_start; - info.end = vma->vm_end; - info.mode = vma->vm_file->f_mode; -if (flex_array_put (fa, i++, &info,GFP_KERNEL )) -BUG (); - } + p->start = vma->vm_start; + p->end = vma->vm_end; + p->mode = vma->vm_file->f_mode; }up_read (&mm->mmap_sem);mmput (mm);
@@ -2213,7 +2201,7 @@ proc_map_files_readdir(struct file *file, struct dir_context *ctx)char buf[4 *sizeof (long ) +2 ];/* max: %lx-%lx\0 */ unsigned int len; - p =flex_array_get (fa, i); + p =genradix_ptr (&fa, i); len =snprintf (buf,sizeof (buf),"%lx-%lx" , p->start, p->end); if (!proc_fill_cache(file, ctx, buf, len,
@@ -2223,12 +2211,11 @@ proc_map_files_readdir(struct file *file, struct dir_context *ctx)break ; ctx->pos++; } -if (fa) -flex_array_free (fa); out_put_task:put_task_struct (task); out: +genradix_free (&fa);return ret; }
Signature · 1 line
2.20.1
PATCH 6/7 sctp: Convert to genradix
In reply to Kent OverstreetThis also makes sctp_stream_alloc_(out|in) saner, in that they no longer allocate new flex_arrays/genradixes, they just preallocate more elements.
This code does however have a suspicious lack of locking.
--- include/net/sctp/structs.h | 15 ++--- net/sctp/stream.c | 106 +++++++---------------------------- net/sctp/stream_interleave.c | 2 +- 3 files changed, 28 insertions(+), 95 deletions(-)
include/net/sctp/structs.h +8 -7
@@ -48,6 +48,7 @@#define __sctp_structs_h__#include <linux/ktime.h> +#include <linux/generic-radix-tree.h> #include <linux/rhashtable-types.h> #include <linux/socket.h> /* linux/in.h needs this!! */ #include <linux/in.h> /* We get struct sockaddr_in. */
@@ -57,7 +58,6 @@#include <linux/atomic.h> /* This gets us atomic counters. */ #include <linux/skbuff.h> /* We need sk_buff_head. */ #include <linux/workqueue.h> /* We need tq_struct. */ -#include <linux/flex_array.h> /* We need flex_array. */ #include <linux/sctp.h> /* We need sctp* header structs. */ #include <net/sctp/auth.h> /* We need auth specific structs */ #include <net/ip.h> /* For inet_skb_parm */
@@ -1441,8 +1441,9 @@ struct sctp_stream_in { };struct sctp_stream { -struct flex_array *out; -struct flex_array *in; +GENRADIX (struct sctp_stream_out ) out; +GENRADIX (struct sctp_stream_in ) in; +__u16 outcnt;__u16 incnt;/* Current stream being sent, if any */
@@ -1465,17 +1466,17 @@ struct sctp_stream { };static inline struct sctp_stream_out *sctp_stream_out ( -const struct sctp_stream *stream, +struct sctp_stream *stream,__u16 sid) { -return flex_array_get (stream->out, sid); +return genradix_ptr (&stream->out, sid); }static inline struct sctp_stream_in *sctp_stream_in ( -const struct sctp_stream *stream, +struct sctp_stream *stream,__u16 sid) { -return flex_array_get (stream->in, sid); +return genradix_ptr (&stream->in, sid); }#define SCTP_SO (s, i) sctp_stream_out((s), (i))
net/sctp/stream.c +19 -87
164 lines not on this page · raw message
net/sctp/stream_interleave.c +1 -1
@@ -101,7 +101,7 @@ static void sctp_chunk_assign_mid(struct sctp_chunk *chunk)static bool sctp_validate_data (struct sctp_chunk *chunk) { -const struct sctp_stream *stream; +struct sctp_stream *stream;__u16 sid, ssn;if (chunk->chunk_hdr->type !=SCTP_CID_DATA )
Signature · 1 line
2.20.1
Andrew Morton
maintainerRe: [PATCH 6/7] sctp: Convert to genradix
net/sctp/stream.c int sctp_send_add_streams(struct sctp_association *asoc, · line 474
Quoted 9 lines · On Mon, 17 Dec 2018 08:19:28 -0500 Kent Overstreet <[email protected]>…
net/sctp/stream.c +0
-3@@ -535,9 +470,6 @@ int sctp_send_add_streams(struct sctp_association *asoc, goto out; } - stream->incnt = incnt; - stream->outcnt = outcnt; - asoc->strreset_outstanding = !!out + !!in;
I'm seeing a reject here for some reason. Using todays's linux-next, but there are no changes against net/sctp/stream.c in -next. The assignment to stream->incnt has disappeared. I did this:
@@ -535,8 +470,6 @@ int sctp_send_add_streams(struct sctp_as
goto out;
}
- stream->outcnt = outcnt;
-
asoc->strreset_outstanding = !!out + !!in;
out:
We're at 4.20-rc7 and this series is rather large. I'll merge them all to see what happens, but I don't think it's 4.21-rc1 material?
Marcelo Ricardo Leitner
maintainerRe: [PATCH 6/7] sctp: Convert to genradix
Quoted 17 lines · Andrew Morton
net/sctp/stream.c int sctp_send_add_streams(struct sctp_association *asoc, · line 474
Quoted 9 lines · On Mon, 17 Dec 2018 08:19:28 -0500 Kent Overstreet <[email protected]>…
net/sctp/stream.c +0
-3@@ -535,9 +470,6 @@ int sctp_send_add_streams(struct sctp_association *asoc, goto out; } - stream->incnt = incnt; - stream->outcnt = outcnt; - asoc->strreset_outstanding = !!out + !!in;I'm seeing a reject here for some reason. Using todays's linux-next, but there are no changes against
net/sctp/stream.cin -next. The assignment tostream->incnthas disappeared. I did this:
net/sctp/stream.c int sctp_send_add_streams(struct sctp_as · line 475
Quoted 8 lines
net/sctp/stream.c +0
-2@@ -535,8 +470,6 @@ int sctp_send_add_streams(struct sctp_as goto out; } - stream->outcnt = outcnt; - asoc->strreset_outstanding = !!out + !!in; out:
That's because ofe1e46479847e ("sctp: not increase stream's incnt before sending addstrm_in request")
https://www.mail-archive.com/[email protected]/msg255306.html
and what you did is the right merge fix for this.
Quoted 4 lines
We're at 4.20-rc7 and this series is rather large. I'll merge them all to see what happens, but I don't think it's 4.21-rc1 material?
Would be nice to be conservative here. It's the first time this change is being proposed for SCTP stack and testing was probably very limited.
Re: [PATCH 6/7] sctp: Convert to genradix
In reply to Andrew MortonQuoted 27 lines · Andrew Morton
net/sctp/stream.c int sctp_send_add_streams(struct sctp_association *asoc, · line 474
Quoted 9 lines · On Mon, 17 Dec 2018 08:19:28 -0500 Kent Overstreet <[email protected]>…
net/sctp/stream.c +0
-3@@ -535,9 +470,6 @@ int sctp_send_add_streams(struct sctp_association *asoc, goto out; } - stream->incnt = incnt; - stream->outcnt = outcnt; - asoc->strreset_outstanding = !!out + !!in;I'm seeing a reject here for some reason. Using todays's linux-next, but there are no changes against
net/sctp/stream.cin -next. The assignment tostream->incnthas disappeared. I did this:net/sctp/stream.c +0
-2@@ -535,8 +470,6 @@ int sctp_send_add_streams(struct sctp_as goto out; } - stream->outcnt = outcnt; - asoc->strreset_outstanding = !!out + !!in; out:
Quoted 2 lines
We're at 4.20-rc7 and this series is rather large. I'll merge them all to see what happens, but I don't think it's 4.21-rc1 material?
Yeah, agreed. Thanks!
Marcelo Ricardo Leitner
maintainerRe: [PATCH 6/7] sctp: Convert to genradix
Quoted 25 lines · Kent Overstreet
Quoted 24 lines · Andrew Morton
net/sctp/stream.c int sctp_send_add_streams(struct sctp_association *asoc, · line 474
Quoted 9 lines · On Mon, 17 Dec 2018 08:19:28 -0500 Kent Overstreet <[email protected]>…
net/sctp/stream.c +0
-3@@ -535,9 +470,6 @@ int sctp_send_add_streams(struct sctp_association *asoc, goto out; } - stream->incnt = incnt; - stream->outcnt = outcnt; - asoc->strreset_outstanding = !!out + !!in;I'm seeing a reject here for some reason. Using todays's linux-next, but there are no changes against
net/sctp/stream.cin -next. The assignment tostream->incnthas disappeared. I did this:net/sctp/stream.c +0
-2@@ -535,8 +470,6 @@ int sctp_send_add_streams(struct sctp_as goto out; } - stream->outcnt = outcnt; - asoc->strreset_outstanding = !!out + !!in;
Quoted 7 lines
Quoted 5 lines
(quoted diff) +0
-0out:We're at 4.20-rc7 and this series is rather large. I'll merge them all to see what happens, but I don't think it's 4.21-rc1 material?
Yeah, agreed. Thanks!
Ping? Where did this go?
Marcelo
Re: [PATCH 6/7] sctp: Convert to genradix
Quoted 29 lines · Marcelo Ricardo Leitner
Quoted 28 lines · Kent Overstreet
Quoted 27 lines · Andrew Morton
net/sctp/stream.c int sctp_send_add_streams(struct sctp_association *asoc, · line 474
Quoted 9 lines · On Mon, 17 Dec 2018 08:19:28 -0500 Kent Overstreet <[email protected]>…
net/sctp/stream.c +0
-3@@ -535,9 +470,6 @@ int sctp_send_add_streams(struct sctp_association *asoc, goto out; } - stream->incnt = incnt; - stream->outcnt = outcnt; - asoc->strreset_outstanding = !!out + !!in;I'm seeing a reject here for some reason. Using todays's linux-next, but there are no changes against
net/sctp/stream.cin -next. The assignment tostream->incnthas disappeared. I did this:net/sctp/stream.c +0
-2@@ -535,8 +470,6 @@ int sctp_send_add_streams(struct sctp_as goto out; } - stream->outcnt = outcnt; - asoc->strreset_outstanding = !!out + !!in; out:
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
We're at 4.20-rc7 and this series is rather large. I'll merge them all to see what happens, but I don't think it's 4.21-rc1 material?
Yeah, agreed. Thanks!
Ping? Where did this go?
As I recall kent reposted his series convirting flex_arrays to radix trees such that it included sctp's uses.
I think xin needs to repost the sctp reallocation patch to make use of those radix trees appropriately still (assuming any additional work still needs to be done)
Neil
Quoted 2 lines
Marcelo
Marcelo Ricardo Leitner
maintainerRe: [PATCH 6/7] sctp: Convert to genradix
Quoted 35 lines · Neil Horman
Quoted 34 lines · Marcelo Ricardo Leitner
Quoted 32 lines · Kent Overstreet
Quoted 27 lines · Andrew Morton
net/sctp/stream.c int sctp_send_add_streams(struct sctp_association *asoc, · line 474
Quoted 9 lines · On Mon, 17 Dec 2018 08:19:28 -0500 Kent Overstreet <[email protected]>…
net/sctp/stream.c +0
-3@@ -535,9 +470,6 @@ int sctp_send_add_streams(struct sctp_association *asoc, goto out; } - stream->incnt = incnt; - stream->outcnt = outcnt; - asoc->strreset_outstanding = !!out + !!in;I'm seeing a reject here for some reason. Using todays's linux-next, but there are no changes against
net/sctp/stream.cin -next. The assignment tostream->incnthas disappeared. I did this:net/sctp/stream.c +0
-2@@ -535,8 +470,6 @@ int sctp_send_add_streams(struct sctp_as goto out; } - stream->outcnt = outcnt; - asoc->strreset_outstanding = !!out + !!in; out:Quoted 2 lines
We're at 4.20-rc7 and this series is rather large. I'll merge them all to see what happens, but I don't think it's 4.21-rc1 material?
Yeah, agreed. Thanks!
Quoted 4 lines
Quoted 2 lines
Ping? Where did this go?
As I recall kent reposted his series convirting
flex_arraysto radix trees such that it included sctp's uses.
That should be this patchset already. Or you mean another (re)post, v2 or so? If yes then I missed it somehow but I still see the flex_array in v5.0-rc2:
net-next]$ git ls-tree v5.0-rc2 -- lib/flex_array.c
100644 blob 2eed22fa507c7cb0756d7ef643f8a3454eb455ec lib/flex_array.c
and missing the convertion on sctp stack.
Current patch is the only one I could find with sctp being included:
https://lore.kernel.org/lkml/20181217210021.GA7144@kmo-pixel/T/#re4f8656af37431a376044399681a8771375a4405
Quoted 4 lines
I think xin needs to repost the sctp reallocation patch to make use of those radix trees appropriately still (assuming any additional work still needs to be done)
This came up on another converstation with him and the lack of this convertion is blocking him on at least one fix, on one that the fix using flex_arrays is one and genradix is another.
Marcelo
Quoted 5 lines
Neil
Quoted 2 lines
Marcelo
Re: [PATCH 6/7] sctp: Convert to genradix
Quoted 45 lines · Marcelo Ricardo Leitner
Quoted 35 lines · Neil Horman
Quoted 34 lines · Marcelo Ricardo Leitner
Quoted 32 lines · Kent Overstreet
Quoted 27 lines · Andrew Morton
net/sctp/stream.c int sctp_send_add_streams(struct sctp_association *asoc, · line 474
Quoted 9 lines · On Mon, 17 Dec 2018 08:19:28 -0500 Kent Overstreet <[email protected]>…
net/sctp/stream.c +0
-3@@ -535,9 +470,6 @@ int sctp_send_add_streams(struct sctp_association *asoc, goto out; } - stream->incnt = incnt; - stream->outcnt = outcnt; - asoc->strreset_outstanding = !!out + !!in;I'm seeing a reject here for some reason. Using todays's linux-next, but there are no changes against
net/sctp/stream.cin -next. The assignment tostream->incnthas disappeared. I did this:net/sctp/stream.c +0
-2@@ -535,8 +470,6 @@ int sctp_send_add_streams(struct sctp_as goto out; } - stream->outcnt = outcnt; - asoc->strreset_outstanding = !!out + !!in; out:Quoted 2 lines
We're at 4.20-rc7 and this series is rather large. I'll merge them all to see what happens, but I don't think it's 4.21-rc1 material?
Yeah, agreed. Thanks!
Quoted 4 lines
Quoted 2 lines
Ping? Where did this go?
As I recall kent reposted his series convirting
flex_arraysto radix trees such that it included sctp's uses.That should be this patchset already. Or you mean another (re)post, v2 or so? If yes then I missed it somehow but I still see the
flex_arrayin v5.0-rc2:
Quoted 8 lines
net-next]$ git ls-tree v5.0-rc2 --
lib/flex_array.c
100644 blob2eed22fa507c7cb0756d7ef643f8a3454eb455eclib/flex_array.cand missing the convertion on sctp stack.
Current patch is the only one I could find with sctp being included:
https://lore.kernel.org/lkml/20181217210021.GA7144@kmo-pixel/T/#re4f8656af37431a376044399681a8771375a4405
Correct, and it doesn't seem to be included yet, though I acked Kents patch as I recall. not sure what the hold up is at this point
Neil
Quoted 17 lines
Quoted 4 lines
I think xin needs to repost the sctp reallocation patch to make use of those radix trees appropriately still (assuming any additional work still needs to be done)
This came up on another converstation with him and the lack of this convertion is blocking him on at least one fix, on one that the fix using
flex_arraysis one and genradix is another.Marcelo
Quoted 5 lines
Neil
Quoted 2 lines
Marcelo
PATCH 7/7 Drop flex_arrays
In reply to Kent OverstreetAll existing users have been converted to generic radix trees
--- Documentation/core-api/flexible-arrays.rst | 130 ------- Documentation/flexible-arrays.txt | 123 ------- include/linux/flex_array.h | 149 -------- include/linux/poison.h | 3 - lib/Makefile | 2 +- lib/flex_array.c | 398 --------------------- tools/include/linux/poison.h | 3 - 7 files changed, 1 insertion(+), 807 deletions(-) delete mode 100644 Documentation/core-api/flexible-arrays.rst delete mode 100644 Documentation/flexible-arrays.txt delete mode 100644 include/linux/flex_array.h delete mode 100644 lib/flex_array.c
Documentation/core-api/flexible-arrays.rst deleted +0 -130
@@ -1,130 +0,0 @@ - -=================================== -Using flexible arrays in the kernel -=================================== - -Large contiguous memory allocations can be unreliable in the Linux kernel. -Kernel programmers will sometimes respond to this problem by allocating -pages with :c:func:`vmalloc()`. This solution not ideal, though. On 32-bit -systems, memory from vmalloc() must be mapped into a relatively small address -space; it's easy to run out. On SMP systems, the page table changes required -by vmalloc() allocations can require expensive cross-processor interrupts on -all CPUs. And, on all systems, use of space in the vmalloc() range increases -pressure on the translation lookaside buffer (TLB), reducing the performance -of the system. - -In many cases, the need for memory from vmalloc() can be eliminated by piecing -together an array from smaller parts; the flexible array library exists to make -this task easier. - -A flexible array holds an arbitrary (within limits) number of fixed-sized -objects, accessed via an integer index. Sparse arrays are handled -reasonably well. Only single-page allocations are made, so memory -allocation failures should be relatively rare. The down sides are that the -arrays cannot be indexed directly, individual object size cannot exceed the -system page size, and putting data into a flexible array requires a copy -operation. It's also worth noting that flexible arrays do no internal -locking at all; if concurrent access to an array is possible, then the -caller must arrange for appropriate mutual exclusion. - -The creation of a flexible array is done with :c:func:`flex_array_alloc()`:: - - #include <linux/flex_array.h> - - struct flex_array *flex_array_alloc(int element_size, - unsigned int total, - gfp_t flags); - -The individual object size is provided by ``element_size``, while total is the -maximum number of objects which can be stored in the array. The flags -argument is passed directly to the internal memory allocation calls. With -the current code, using flags to ask for high memory is likely to lead to -notably unpleasant side effects. - -It is also possible to define flexible arrays at compile time with:: - - DEFINE_FLEX_ARRAY(name, element_size, total); - -This macro will result in a definition of an array with the given name; the -element size and total will be checked for validity at compile time. - -Storing data into a flexible array is accomplished with a call to -:c:func:`flex_array_put()`:: - - int flex_array_put(struct flex_array *array, unsigned int element_nr, - void *src, gfp_t flags); - -This call will copy the data from src into the array, in the position -indicated by ``element_nr`` (which must be less than the maximum specified when -the array was created). If any memory allocations must be performed, flags -will be used. The return value is zero on success, a negative error code -otherwise. - -There might possibly be a need to store data into a flexible array while -running in some sort of atomic context; in this situation, sleeping in the -memory allocator would be a bad thing. That can be avoided by using -``GFP_ATOMIC`` for the flags value, but, often, there is a better way. The -trick is to ensure that any needed memory allocations are done before -entering atomic context, using :c:func:`flex_array_prealloc()`:: - - int flex_array_prealloc(struct flex_array *array, unsigned int start, - unsigned int nr_elements, gfp_t flags); - -This function will ensure that memory for the elements indexed in the range -defined by ``start`` and ``nr_elements`` has been allocated. Thereafter, a -``flex_array_put()`` call on an element in that range is guaranteed not to -block. - -Getting data back out of the array is done with :c:func:`flex_array_get()`:: - - void *flex_array_get(struct flex_array *fa, unsigned int element_nr); - -The return value is a pointer to the data element, or NULL if that -particular element has never been allocated. - -Note that it is possible to get back a valid pointer for an element which -has never been stored in the array. Memory for array elements is allocated -one page at a time; a single allocation could provide memory for several -adjacent elements. Flexible array elements are normally initialized to the -value ``FLEX_ARRAY_FREE`` (defined as 0x6c in <linux/poison.h>), so errors -involving that number probably result from use of unstored array entries. -Note that, if array elements are allocated with ``__GFP_ZERO``, they will be -initialized to zero and this poisoning will not happen. - -Individual elements in the array can be cleared with -:c:func:`flex_array_clear()`:: - - int flex_array_clear(struct flex_array *array, unsigned int element_nr); - -This function will set the given element to ``FLEX_ARRAY_FREE`` and return -zero. If storage for the indicated element is not allocated for the array, -``flex_array_clear()`` will return ``-EINVAL`` instead. Note that clearing an -element does not release the storage associated with it; to reduce the -allocated size of an array, call :c:func:`flex_array_shrink()`:: - - int flex_array_shrink(struct flex_array *array); - -The return value will be the number of pages of memory actually freed. -This function works by scanning the array for pages containing nothing but -``FLEX_ARRAY_FREE`` bytes, so (1) it can be expensive, and (2) it will not work -if the array's pages are allocated with ``__GFP_ZERO``. - -It is possible to remove all elements of an array with a call to -:c:func:`flex_array_free_parts()`:: - - void flex_array_free_parts(struct flex_array *array); - -This call frees all elements, but leaves the array itself in place. -Freeing the entire array is done with :c:func:`flex_array_free()`:: - - void flex_array_free(struct flex_array *array); - -As of this writing, there are no users of flexible arrays in the mainline -kernel. The functions described here are also not exported to modules; -that will probably be fixed when somebody comes up with a need for it. - - -Flexible array functions ------------------------- - -.. kernel-doc:: include/linux/flex_array.h
Documentation/flexible-arrays.txt deleted +0 -123
123 lines not on this page · raw message
include/linux/flex_array.h deleted +0 -149
149 lines not on this page · raw message
include/linux/poison.h +0 -3
@@ -83,9 +83,6 @@#define MUTEX_DEBUG_FREE 0x22#define MUTEX_POISON_WW_CTX ((void *) 0x500 + POISON_POINTER_DELTA) -/********** lib/flex_array.c **********/ -#define FLEX_ARRAY_FREE 0x6c/* for use-after-free poisoning */ -/********** security/ **********/ #define KEY_DESTROY 0xbd
lib/Makefile +1 -1
@@ -35,7 +35,7 @@ obj-y += lockref.o obj-y += bcd.o div64.o sort.o parser.o debug_locks.o random32.o \ bust_spinlocks.o kasprintf.o bitmap.o scatterlist.o \ - gcd.o lcm.o list_sort.o uuid.o flex_array.o iov_iter.o clz_ctz.o \ + gcd.o lcm.o list_sort.o uuid.o iov_iter.o clz_ctz.o \ bsearch.o find_bit.o llist.o memweight.o kfifo.o \ percpu-refcount.o rhashtable.o reciprocal_div.o \ once.o refcount.o usercopy.o errseq.o bucket_locks.o \
lib/flex_array.c deleted +0 -398
398 lines not on this page · raw message
tools/include/linux/poison.h +0 -3
@@ -87,9 +87,6 @@#define MUTEX_DEBUG_INIT 0x11#define MUTEX_DEBUG_FREE 0x22 -/********** lib/flex_array.c **********/ -#define FLEX_ARRAY_FREE 0x6c/* for use-after-free poisoning */ -/********** security/ **********/ #define KEY_DESTROY 0xbd
Signature · 1 line
2.20.1