2024-02-22 23:52:27 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* Implementation of the extensible bitmap type.
|
|
|
|
*
|
2023-07-19 15:12:50 +00:00
|
|
|
* Author : Stephen Smalley, <stephen.smalley.work@gmail.com>
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
2006-08-05 06:17:57 +00:00
|
|
|
/*
|
2011-08-01 11:10:33 +00:00
|
|
|
* Updated: Hewlett-Packard <paul@paul-moore.com>
|
2024-02-22 23:52:27 +00:00
|
|
|
* Added support to import/export the NetLabel category bitmap
|
|
|
|
* (c) Copyright Hewlett-Packard Development Company, L.P., 2006
|
2006-08-05 06:17:57 +00:00
|
|
|
*
|
SELinux: improve performance when AVC misses.
* We add ebitmap_for_each_positive_bit() which enables to walk on
any positive bit on the given ebitmap, to improve its performance
using common bit-operations defined in linux/bitops.h.
In the previous version, this logic was implemented using a combination
of ebitmap_for_each_bit() and ebitmap_node_get_bit(), but is was worse
in performance aspect.
This logic is most frequestly used to compute a new AVC entry,
so this patch can improve SELinux performance when AVC misses are happen.
* struct ebitmap_node is redefined as an array of "unsigned long", to get
suitable for using find_next_bit() which is fasted than iteration of
shift and logical operation, and to maximize memory usage allocated
from general purpose slab.
* Any ebitmap_for_each_bit() are repleced by the new implementation
in ss/service.c and ss/mls.c. Some of related implementation are
changed, however, there is no incompatibility with the previous
version.
* The width of any new line are less or equal than 80-chars.
The following benchmark shows the effect of this patch, when we
access many files which have different security context one after
another. The number is more than /selinux/avc/cache_threshold, so
any access always causes AVC misses.
selinux-2.6 selinux-2.6-ebitmap
AVG: 22.763 [s] 8.750 [s]
STD: 0.265 0.019
------------------------------------------
1st: 22.558 [s] 8.786 [s]
2nd: 22.458 [s] 8.750 [s]
3rd: 22.478 [s] 8.754 [s]
4th: 22.724 [s] 8.745 [s]
5th: 22.918 [s] 8.748 [s]
6th: 22.905 [s] 8.764 [s]
7th: 23.238 [s] 8.726 [s]
8th: 22.822 [s] 8.729 [s]
Signed-off-by: KaiGai Kohei <kaigai@ak.jp.nec.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: James Morris <jmorris@namei.org>
2007-09-28 17:20:55 +00:00
|
|
|
* Updated: KaiGai Kohei <kaigai@ak.jp.nec.com>
|
2024-02-22 23:52:27 +00:00
|
|
|
* Applied standard bit operations to improve bitmap scanning.
|
SELinux: improve performance when AVC misses.
* We add ebitmap_for_each_positive_bit() which enables to walk on
any positive bit on the given ebitmap, to improve its performance
using common bit-operations defined in linux/bitops.h.
In the previous version, this logic was implemented using a combination
of ebitmap_for_each_bit() and ebitmap_node_get_bit(), but is was worse
in performance aspect.
This logic is most frequestly used to compute a new AVC entry,
so this patch can improve SELinux performance when AVC misses are happen.
* struct ebitmap_node is redefined as an array of "unsigned long", to get
suitable for using find_next_bit() which is fasted than iteration of
shift and logical operation, and to maximize memory usage allocated
from general purpose slab.
* Any ebitmap_for_each_bit() are repleced by the new implementation
in ss/service.c and ss/mls.c. Some of related implementation are
changed, however, there is no incompatibility with the previous
version.
* The width of any new line are less or equal than 80-chars.
The following benchmark shows the effect of this patch, when we
access many files which have different security context one after
another. The number is more than /selinux/avc/cache_threshold, so
any access always causes AVC misses.
selinux-2.6 selinux-2.6-ebitmap
AVG: 22.763 [s] 8.750 [s]
STD: 0.265 0.019
------------------------------------------
1st: 22.558 [s] 8.786 [s]
2nd: 22.458 [s] 8.750 [s]
3rd: 22.478 [s] 8.754 [s]
4th: 22.724 [s] 8.745 [s]
5th: 22.918 [s] 8.748 [s]
6th: 22.905 [s] 8.764 [s]
7th: 23.238 [s] 8.726 [s]
8th: 22.822 [s] 8.729 [s]
Signed-off-by: KaiGai Kohei <kaigai@ak.jp.nec.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: James Morris <jmorris@namei.org>
2007-09-28 17:20:55 +00:00
|
|
|
*/
|
2006-08-05 06:17:57 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/errno.h>
|
2020-04-17 08:11:56 +00:00
|
|
|
#include <linux/jhash.h>
|
2006-11-29 18:18:18 +00:00
|
|
|
#include <net/netlabel.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include "ebitmap.h"
|
|
|
|
#include "policydb.h"
|
|
|
|
|
2024-03-15 17:32:28 +00:00
|
|
|
#define BITS_PER_U64 ((u32)(sizeof(u64) * 8))
|
2010-10-13 21:50:25 +00:00
|
|
|
|
2021-01-06 13:26:21 +00:00
|
|
|
static struct kmem_cache *ebitmap_node_cachep __ro_after_init;
|
2017-06-08 04:18:09 +00:00
|
|
|
|
2022-08-30 15:52:49 +00:00
|
|
|
int ebitmap_cmp(const struct ebitmap *e1, const struct ebitmap *e2)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2022-08-30 15:52:49 +00:00
|
|
|
const struct ebitmap_node *n1, *n2;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (e1->highbit != e2->highbit)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
n1 = e1->node;
|
|
|
|
n2 = e2->node;
|
2024-02-22 23:52:27 +00:00
|
|
|
while (n1 && n2 && (n1->startbit == n2->startbit) &&
|
SELinux: improve performance when AVC misses.
* We add ebitmap_for_each_positive_bit() which enables to walk on
any positive bit on the given ebitmap, to improve its performance
using common bit-operations defined in linux/bitops.h.
In the previous version, this logic was implemented using a combination
of ebitmap_for_each_bit() and ebitmap_node_get_bit(), but is was worse
in performance aspect.
This logic is most frequestly used to compute a new AVC entry,
so this patch can improve SELinux performance when AVC misses are happen.
* struct ebitmap_node is redefined as an array of "unsigned long", to get
suitable for using find_next_bit() which is fasted than iteration of
shift and logical operation, and to maximize memory usage allocated
from general purpose slab.
* Any ebitmap_for_each_bit() are repleced by the new implementation
in ss/service.c and ss/mls.c. Some of related implementation are
changed, however, there is no incompatibility with the previous
version.
* The width of any new line are less or equal than 80-chars.
The following benchmark shows the effect of this patch, when we
access many files which have different security context one after
another. The number is more than /selinux/avc/cache_threshold, so
any access always causes AVC misses.
selinux-2.6 selinux-2.6-ebitmap
AVG: 22.763 [s] 8.750 [s]
STD: 0.265 0.019
------------------------------------------
1st: 22.558 [s] 8.786 [s]
2nd: 22.458 [s] 8.750 [s]
3rd: 22.478 [s] 8.754 [s]
4th: 22.724 [s] 8.745 [s]
5th: 22.918 [s] 8.748 [s]
6th: 22.905 [s] 8.764 [s]
7th: 23.238 [s] 8.726 [s]
8th: 22.822 [s] 8.729 [s]
Signed-off-by: KaiGai Kohei <kaigai@ak.jp.nec.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: James Morris <jmorris@namei.org>
2007-09-28 17:20:55 +00:00
|
|
|
!memcmp(n1->maps, n2->maps, EBITMAP_SIZE / 8)) {
|
2005-04-16 22:20:36 +00:00
|
|
|
n1 = n1->next;
|
|
|
|
n2 = n2->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n1 || n2)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2022-08-30 15:52:49 +00:00
|
|
|
int ebitmap_cpy(struct ebitmap *dst, const struct ebitmap *src)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2022-08-30 15:52:49 +00:00
|
|
|
struct ebitmap_node *new, *prev;
|
|
|
|
const struct ebitmap_node *n;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
ebitmap_init(dst);
|
|
|
|
n = src->node;
|
|
|
|
prev = NULL;
|
|
|
|
while (n) {
|
2017-06-08 04:18:09 +00:00
|
|
|
new = kmem_cache_zalloc(ebitmap_node_cachep, GFP_ATOMIC);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!new) {
|
|
|
|
ebitmap_destroy(dst);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
new->startbit = n->startbit;
|
SELinux: improve performance when AVC misses.
* We add ebitmap_for_each_positive_bit() which enables to walk on
any positive bit on the given ebitmap, to improve its performance
using common bit-operations defined in linux/bitops.h.
In the previous version, this logic was implemented using a combination
of ebitmap_for_each_bit() and ebitmap_node_get_bit(), but is was worse
in performance aspect.
This logic is most frequestly used to compute a new AVC entry,
so this patch can improve SELinux performance when AVC misses are happen.
* struct ebitmap_node is redefined as an array of "unsigned long", to get
suitable for using find_next_bit() which is fasted than iteration of
shift and logical operation, and to maximize memory usage allocated
from general purpose slab.
* Any ebitmap_for_each_bit() are repleced by the new implementation
in ss/service.c and ss/mls.c. Some of related implementation are
changed, however, there is no incompatibility with the previous
version.
* The width of any new line are less or equal than 80-chars.
The following benchmark shows the effect of this patch, when we
access many files which have different security context one after
another. The number is more than /selinux/avc/cache_threshold, so
any access always causes AVC misses.
selinux-2.6 selinux-2.6-ebitmap
AVG: 22.763 [s] 8.750 [s]
STD: 0.265 0.019
------------------------------------------
1st: 22.558 [s] 8.786 [s]
2nd: 22.458 [s] 8.750 [s]
3rd: 22.478 [s] 8.754 [s]
4th: 22.724 [s] 8.745 [s]
5th: 22.918 [s] 8.748 [s]
6th: 22.905 [s] 8.764 [s]
7th: 23.238 [s] 8.726 [s]
8th: 22.822 [s] 8.729 [s]
Signed-off-by: KaiGai Kohei <kaigai@ak.jp.nec.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: James Morris <jmorris@namei.org>
2007-09-28 17:20:55 +00:00
|
|
|
memcpy(new->maps, n->maps, EBITMAP_SIZE / 8);
|
2005-04-16 22:20:36 +00:00
|
|
|
new->next = NULL;
|
|
|
|
if (prev)
|
|
|
|
prev->next = new;
|
|
|
|
else
|
|
|
|
dst->node = new;
|
|
|
|
prev = new;
|
|
|
|
n = n->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
dst->highbit = src->highbit;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-02-22 23:52:27 +00:00
|
|
|
int ebitmap_and(struct ebitmap *dst, const struct ebitmap *e1,
|
|
|
|
const struct ebitmap *e2)
|
2019-09-04 21:03:23 +00:00
|
|
|
{
|
|
|
|
struct ebitmap_node *n;
|
2024-03-15 17:32:28 +00:00
|
|
|
u32 bit;
|
|
|
|
int rc;
|
2019-09-04 21:03:23 +00:00
|
|
|
|
|
|
|
ebitmap_init(dst);
|
|
|
|
|
2024-02-22 23:52:27 +00:00
|
|
|
ebitmap_for_each_positive_bit(e1, n, bit)
|
|
|
|
{
|
2019-09-04 21:03:23 +00:00
|
|
|
if (ebitmap_get_bit(e2, bit)) {
|
|
|
|
rc = ebitmap_set_bit(dst, bit, 1);
|
|
|
|
if (rc < 0)
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-11-29 18:18:18 +00:00
|
|
|
#ifdef CONFIG_NETLABEL
|
2006-08-05 06:17:57 +00:00
|
|
|
/**
|
2006-11-29 18:18:18 +00:00
|
|
|
* ebitmap_netlbl_export - Export an ebitmap into a NetLabel category bitmap
|
|
|
|
* @ebmap: the ebitmap to export
|
|
|
|
* @catmap: the NetLabel category bitmap
|
2006-08-05 06:17:57 +00:00
|
|
|
*
|
|
|
|
* Description:
|
2006-11-29 18:18:18 +00:00
|
|
|
* Export a SELinux extensibile bitmap into a NetLabel category bitmap.
|
|
|
|
* Returns zero on success, negative values on error.
|
2006-08-05 06:17:57 +00:00
|
|
|
*
|
|
|
|
*/
|
2006-11-29 18:18:18 +00:00
|
|
|
int ebitmap_netlbl_export(struct ebitmap *ebmap,
|
2014-08-01 15:17:37 +00:00
|
|
|
struct netlbl_lsm_catmap **catmap)
|
2006-08-05 06:17:57 +00:00
|
|
|
{
|
2006-11-29 18:18:18 +00:00
|
|
|
struct ebitmap_node *e_iter = ebmap->node;
|
2014-08-01 15:17:17 +00:00
|
|
|
unsigned long e_map;
|
|
|
|
u32 offset;
|
|
|
|
unsigned int iter;
|
|
|
|
int rc;
|
2006-11-29 18:18:18 +00:00
|
|
|
|
|
|
|
if (e_iter == NULL) {
|
|
|
|
*catmap = NULL;
|
2006-10-11 23:10:48 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-08-01 15:17:17 +00:00
|
|
|
if (*catmap != NULL)
|
2014-08-01 15:17:37 +00:00
|
|
|
netlbl_catmap_free(*catmap);
|
2014-08-01 15:17:17 +00:00
|
|
|
*catmap = NULL;
|
2006-11-29 18:18:18 +00:00
|
|
|
|
2008-08-07 00:18:20 +00:00
|
|
|
while (e_iter) {
|
2014-08-01 15:17:17 +00:00
|
|
|
offset = e_iter->startbit;
|
|
|
|
for (iter = 0; iter < EBITMAP_UNIT_NUMS; iter++) {
|
|
|
|
e_map = e_iter->maps[iter];
|
|
|
|
if (e_map != 0) {
|
2024-02-22 23:52:27 +00:00
|
|
|
rc = netlbl_catmap_setlong(catmap, offset,
|
|
|
|
e_map, GFP_ATOMIC);
|
2014-08-01 15:17:17 +00:00
|
|
|
if (rc != 0)
|
SELinux: improve performance when AVC misses.
* We add ebitmap_for_each_positive_bit() which enables to walk on
any positive bit on the given ebitmap, to improve its performance
using common bit-operations defined in linux/bitops.h.
In the previous version, this logic was implemented using a combination
of ebitmap_for_each_bit() and ebitmap_node_get_bit(), but is was worse
in performance aspect.
This logic is most frequestly used to compute a new AVC entry,
so this patch can improve SELinux performance when AVC misses are happen.
* struct ebitmap_node is redefined as an array of "unsigned long", to get
suitable for using find_next_bit() which is fasted than iteration of
shift and logical operation, and to maximize memory usage allocated
from general purpose slab.
* Any ebitmap_for_each_bit() are repleced by the new implementation
in ss/service.c and ss/mls.c. Some of related implementation are
changed, however, there is no incompatibility with the previous
version.
* The width of any new line are less or equal than 80-chars.
The following benchmark shows the effect of this patch, when we
access many files which have different security context one after
another. The number is more than /selinux/avc/cache_threshold, so
any access always causes AVC misses.
selinux-2.6 selinux-2.6-ebitmap
AVG: 22.763 [s] 8.750 [s]
STD: 0.265 0.019
------------------------------------------
1st: 22.558 [s] 8.786 [s]
2nd: 22.458 [s] 8.750 [s]
3rd: 22.478 [s] 8.754 [s]
4th: 22.724 [s] 8.745 [s]
5th: 22.918 [s] 8.748 [s]
6th: 22.905 [s] 8.764 [s]
7th: 23.238 [s] 8.726 [s]
8th: 22.822 [s] 8.729 [s]
Signed-off-by: KaiGai Kohei <kaigai@ak.jp.nec.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: James Morris <jmorris@namei.org>
2007-09-28 17:20:55 +00:00
|
|
|
goto netlbl_export_failure;
|
|
|
|
}
|
2014-08-01 15:17:17 +00:00
|
|
|
offset += EBITMAP_UNIT_SIZE;
|
2006-11-29 18:18:18 +00:00
|
|
|
}
|
2007-11-06 16:17:16 +00:00
|
|
|
e_iter = e_iter->next;
|
2006-11-29 18:18:18 +00:00
|
|
|
}
|
2006-08-05 06:17:57 +00:00
|
|
|
|
|
|
|
return 0;
|
2006-11-29 18:18:18 +00:00
|
|
|
|
|
|
|
netlbl_export_failure:
|
2014-08-01 15:17:37 +00:00
|
|
|
netlbl_catmap_free(*catmap);
|
2006-11-29 18:18:18 +00:00
|
|
|
return -ENOMEM;
|
2006-08-05 06:17:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-11-29 18:18:18 +00:00
|
|
|
* ebitmap_netlbl_import - Import a NetLabel category bitmap into an ebitmap
|
SELinux: improve performance when AVC misses.
* We add ebitmap_for_each_positive_bit() which enables to walk on
any positive bit on the given ebitmap, to improve its performance
using common bit-operations defined in linux/bitops.h.
In the previous version, this logic was implemented using a combination
of ebitmap_for_each_bit() and ebitmap_node_get_bit(), but is was worse
in performance aspect.
This logic is most frequestly used to compute a new AVC entry,
so this patch can improve SELinux performance when AVC misses are happen.
* struct ebitmap_node is redefined as an array of "unsigned long", to get
suitable for using find_next_bit() which is fasted than iteration of
shift and logical operation, and to maximize memory usage allocated
from general purpose slab.
* Any ebitmap_for_each_bit() are repleced by the new implementation
in ss/service.c and ss/mls.c. Some of related implementation are
changed, however, there is no incompatibility with the previous
version.
* The width of any new line are less or equal than 80-chars.
The following benchmark shows the effect of this patch, when we
access many files which have different security context one after
another. The number is more than /selinux/avc/cache_threshold, so
any access always causes AVC misses.
selinux-2.6 selinux-2.6-ebitmap
AVG: 22.763 [s] 8.750 [s]
STD: 0.265 0.019
------------------------------------------
1st: 22.558 [s] 8.786 [s]
2nd: 22.458 [s] 8.750 [s]
3rd: 22.478 [s] 8.754 [s]
4th: 22.724 [s] 8.745 [s]
5th: 22.918 [s] 8.748 [s]
6th: 22.905 [s] 8.764 [s]
7th: 23.238 [s] 8.726 [s]
8th: 22.822 [s] 8.729 [s]
Signed-off-by: KaiGai Kohei <kaigai@ak.jp.nec.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: James Morris <jmorris@namei.org>
2007-09-28 17:20:55 +00:00
|
|
|
* @ebmap: the ebitmap to import
|
2006-11-29 18:18:18 +00:00
|
|
|
* @catmap: the NetLabel category bitmap
|
2006-08-05 06:17:57 +00:00
|
|
|
*
|
|
|
|
* Description:
|
2006-11-29 18:18:18 +00:00
|
|
|
* Import a NetLabel category bitmap into a SELinux extensibile bitmap.
|
|
|
|
* Returns zero on success, negative values on error.
|
2006-08-05 06:17:57 +00:00
|
|
|
*
|
|
|
|
*/
|
2006-11-29 18:18:18 +00:00
|
|
|
int ebitmap_netlbl_import(struct ebitmap *ebmap,
|
2014-08-01 15:17:37 +00:00
|
|
|
struct netlbl_lsm_catmap *catmap)
|
2006-08-05 06:17:57 +00:00
|
|
|
{
|
2014-08-01 15:17:17 +00:00
|
|
|
int rc;
|
2006-11-29 18:18:18 +00:00
|
|
|
struct ebitmap_node *e_iter = NULL;
|
2014-08-01 15:17:17 +00:00
|
|
|
struct ebitmap_node *e_prev = NULL;
|
|
|
|
u32 offset = 0, idx;
|
|
|
|
unsigned long bitmap;
|
|
|
|
|
|
|
|
for (;;) {
|
2014-08-01 15:17:37 +00:00
|
|
|
rc = netlbl_catmap_getlong(catmap, &offset, &bitmap);
|
2014-08-01 15:17:17 +00:00
|
|
|
if (rc < 0)
|
|
|
|
goto netlbl_import_failure;
|
|
|
|
if (offset == (u32)-1)
|
|
|
|
return 0;
|
|
|
|
|
2015-07-09 18:20:36 +00:00
|
|
|
/* don't waste ebitmap space if the netlabel bitmap is empty */
|
|
|
|
if (bitmap == 0) {
|
|
|
|
offset += EBITMAP_UNIT_SIZE;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-08-01 15:17:17 +00:00
|
|
|
if (e_iter == NULL ||
|
|
|
|
offset >= e_iter->startbit + EBITMAP_SIZE) {
|
|
|
|
e_prev = e_iter;
|
2024-02-22 23:52:27 +00:00
|
|
|
e_iter = kmem_cache_zalloc(ebitmap_node_cachep,
|
|
|
|
GFP_ATOMIC);
|
2014-08-01 15:17:17 +00:00
|
|
|
if (e_iter == NULL)
|
|
|
|
goto netlbl_import_failure;
|
2016-06-09 14:40:37 +00:00
|
|
|
e_iter->startbit = offset - (offset % EBITMAP_SIZE);
|
2014-08-01 15:17:17 +00:00
|
|
|
if (e_prev == NULL)
|
|
|
|
ebmap->node = e_iter;
|
|
|
|
else
|
|
|
|
e_prev->next = e_iter;
|
|
|
|
ebmap->highbit = e_iter->startbit + EBITMAP_SIZE;
|
2006-11-29 18:18:18 +00:00
|
|
|
}
|
2006-08-05 06:17:57 +00:00
|
|
|
|
2014-08-01 15:17:17 +00:00
|
|
|
/* offset will always be aligned to an unsigned long */
|
|
|
|
idx = EBITMAP_NODE_INDEX(e_iter, offset);
|
|
|
|
e_iter->maps[idx] = bitmap;
|
|
|
|
|
|
|
|
/* next */
|
|
|
|
offset += EBITMAP_UNIT_SIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* NOTE: we should never reach this return */
|
2006-08-05 06:17:57 +00:00
|
|
|
return 0;
|
2006-11-29 18:18:18 +00:00
|
|
|
|
|
|
|
netlbl_import_failure:
|
|
|
|
ebitmap_destroy(ebmap);
|
|
|
|
return -ENOMEM;
|
2006-08-05 06:17:57 +00:00
|
|
|
}
|
2006-11-29 18:18:18 +00:00
|
|
|
#endif /* CONFIG_NETLABEL */
|
2006-08-05 06:17:57 +00:00
|
|
|
|
2013-07-23 21:38:41 +00:00
|
|
|
/*
|
|
|
|
* Check to see if all the bits set in e2 are also set in e1. Optionally,
|
|
|
|
* if last_e2bit is non-zero, the highest set bit in e2 cannot exceed
|
|
|
|
* last_e2bit.
|
|
|
|
*/
|
2024-02-22 23:52:27 +00:00
|
|
|
int ebitmap_contains(const struct ebitmap *e1, const struct ebitmap *e2,
|
|
|
|
u32 last_e2bit)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2022-08-30 15:52:49 +00:00
|
|
|
const struct ebitmap_node *n1, *n2;
|
SELinux: improve performance when AVC misses.
* We add ebitmap_for_each_positive_bit() which enables to walk on
any positive bit on the given ebitmap, to improve its performance
using common bit-operations defined in linux/bitops.h.
In the previous version, this logic was implemented using a combination
of ebitmap_for_each_bit() and ebitmap_node_get_bit(), but is was worse
in performance aspect.
This logic is most frequestly used to compute a new AVC entry,
so this patch can improve SELinux performance when AVC misses are happen.
* struct ebitmap_node is redefined as an array of "unsigned long", to get
suitable for using find_next_bit() which is fasted than iteration of
shift and logical operation, and to maximize memory usage allocated
from general purpose slab.
* Any ebitmap_for_each_bit() are repleced by the new implementation
in ss/service.c and ss/mls.c. Some of related implementation are
changed, however, there is no incompatibility with the previous
version.
* The width of any new line are less or equal than 80-chars.
The following benchmark shows the effect of this patch, when we
access many files which have different security context one after
another. The number is more than /selinux/avc/cache_threshold, so
any access always causes AVC misses.
selinux-2.6 selinux-2.6-ebitmap
AVG: 22.763 [s] 8.750 [s]
STD: 0.265 0.019
------------------------------------------
1st: 22.558 [s] 8.786 [s]
2nd: 22.458 [s] 8.750 [s]
3rd: 22.478 [s] 8.754 [s]
4th: 22.724 [s] 8.745 [s]
5th: 22.918 [s] 8.748 [s]
6th: 22.905 [s] 8.764 [s]
7th: 23.238 [s] 8.726 [s]
8th: 22.822 [s] 8.729 [s]
Signed-off-by: KaiGai Kohei <kaigai@ak.jp.nec.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: James Morris <jmorris@namei.org>
2007-09-28 17:20:55 +00:00
|
|
|
int i;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (e1->highbit < e2->highbit)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
n1 = e1->node;
|
|
|
|
n2 = e2->node;
|
2013-07-23 21:38:41 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
while (n1 && n2 && (n1->startbit <= n2->startbit)) {
|
|
|
|
if (n1->startbit < n2->startbit) {
|
|
|
|
n1 = n1->next;
|
|
|
|
continue;
|
|
|
|
}
|
2024-02-22 23:52:27 +00:00
|
|
|
for (i = EBITMAP_UNIT_NUMS - 1; (i >= 0) && !n2->maps[i];)
|
|
|
|
i--; /* Skip trailing NULL map entries */
|
2013-07-23 21:38:41 +00:00
|
|
|
if (last_e2bit && (i >= 0)) {
|
|
|
|
u32 lastsetbit = n2->startbit + i * EBITMAP_UNIT_SIZE +
|
|
|
|
__fls(n2->maps[i]);
|
|
|
|
if (lastsetbit > last_e2bit)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (i >= 0) {
|
SELinux: improve performance when AVC misses.
* We add ebitmap_for_each_positive_bit() which enables to walk on
any positive bit on the given ebitmap, to improve its performance
using common bit-operations defined in linux/bitops.h.
In the previous version, this logic was implemented using a combination
of ebitmap_for_each_bit() and ebitmap_node_get_bit(), but is was worse
in performance aspect.
This logic is most frequestly used to compute a new AVC entry,
so this patch can improve SELinux performance when AVC misses are happen.
* struct ebitmap_node is redefined as an array of "unsigned long", to get
suitable for using find_next_bit() which is fasted than iteration of
shift and logical operation, and to maximize memory usage allocated
from general purpose slab.
* Any ebitmap_for_each_bit() are repleced by the new implementation
in ss/service.c and ss/mls.c. Some of related implementation are
changed, however, there is no incompatibility with the previous
version.
* The width of any new line are less or equal than 80-chars.
The following benchmark shows the effect of this patch, when we
access many files which have different security context one after
another. The number is more than /selinux/avc/cache_threshold, so
any access always causes AVC misses.
selinux-2.6 selinux-2.6-ebitmap
AVG: 22.763 [s] 8.750 [s]
STD: 0.265 0.019
------------------------------------------
1st: 22.558 [s] 8.786 [s]
2nd: 22.458 [s] 8.750 [s]
3rd: 22.478 [s] 8.754 [s]
4th: 22.724 [s] 8.745 [s]
5th: 22.918 [s] 8.748 [s]
6th: 22.905 [s] 8.764 [s]
7th: 23.238 [s] 8.726 [s]
8th: 22.822 [s] 8.729 [s]
Signed-off-by: KaiGai Kohei <kaigai@ak.jp.nec.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: James Morris <jmorris@namei.org>
2007-09-28 17:20:55 +00:00
|
|
|
if ((n1->maps[i] & n2->maps[i]) != n2->maps[i])
|
|
|
|
return 0;
|
2013-07-23 21:38:41 +00:00
|
|
|
i--;
|
SELinux: improve performance when AVC misses.
* We add ebitmap_for_each_positive_bit() which enables to walk on
any positive bit on the given ebitmap, to improve its performance
using common bit-operations defined in linux/bitops.h.
In the previous version, this logic was implemented using a combination
of ebitmap_for_each_bit() and ebitmap_node_get_bit(), but is was worse
in performance aspect.
This logic is most frequestly used to compute a new AVC entry,
so this patch can improve SELinux performance when AVC misses are happen.
* struct ebitmap_node is redefined as an array of "unsigned long", to get
suitable for using find_next_bit() which is fasted than iteration of
shift and logical operation, and to maximize memory usage allocated
from general purpose slab.
* Any ebitmap_for_each_bit() are repleced by the new implementation
in ss/service.c and ss/mls.c. Some of related implementation are
changed, however, there is no incompatibility with the previous
version.
* The width of any new line are less or equal than 80-chars.
The following benchmark shows the effect of this patch, when we
access many files which have different security context one after
another. The number is more than /selinux/avc/cache_threshold, so
any access always causes AVC misses.
selinux-2.6 selinux-2.6-ebitmap
AVG: 22.763 [s] 8.750 [s]
STD: 0.265 0.019
------------------------------------------
1st: 22.558 [s] 8.786 [s]
2nd: 22.458 [s] 8.750 [s]
3rd: 22.478 [s] 8.754 [s]
4th: 22.724 [s] 8.745 [s]
5th: 22.918 [s] 8.748 [s]
6th: 22.905 [s] 8.764 [s]
7th: 23.238 [s] 8.726 [s]
8th: 22.822 [s] 8.729 [s]
Signed-off-by: KaiGai Kohei <kaigai@ak.jp.nec.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: James Morris <jmorris@namei.org>
2007-09-28 17:20:55 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
n1 = n1->next;
|
|
|
|
n2 = n2->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n2)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2024-03-15 17:32:28 +00:00
|
|
|
int ebitmap_get_bit(const struct ebitmap *e, u32 bit)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2022-08-30 15:52:49 +00:00
|
|
|
const struct ebitmap_node *n;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (e->highbit < bit)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
n = e->node;
|
|
|
|
while (n && (n->startbit <= bit)) {
|
SELinux: improve performance when AVC misses.
* We add ebitmap_for_each_positive_bit() which enables to walk on
any positive bit on the given ebitmap, to improve its performance
using common bit-operations defined in linux/bitops.h.
In the previous version, this logic was implemented using a combination
of ebitmap_for_each_bit() and ebitmap_node_get_bit(), but is was worse
in performance aspect.
This logic is most frequestly used to compute a new AVC entry,
so this patch can improve SELinux performance when AVC misses are happen.
* struct ebitmap_node is redefined as an array of "unsigned long", to get
suitable for using find_next_bit() which is fasted than iteration of
shift and logical operation, and to maximize memory usage allocated
from general purpose slab.
* Any ebitmap_for_each_bit() are repleced by the new implementation
in ss/service.c and ss/mls.c. Some of related implementation are
changed, however, there is no incompatibility with the previous
version.
* The width of any new line are less or equal than 80-chars.
The following benchmark shows the effect of this patch, when we
access many files which have different security context one after
another. The number is more than /selinux/avc/cache_threshold, so
any access always causes AVC misses.
selinux-2.6 selinux-2.6-ebitmap
AVG: 22.763 [s] 8.750 [s]
STD: 0.265 0.019
------------------------------------------
1st: 22.558 [s] 8.786 [s]
2nd: 22.458 [s] 8.750 [s]
3rd: 22.478 [s] 8.754 [s]
4th: 22.724 [s] 8.745 [s]
5th: 22.918 [s] 8.748 [s]
6th: 22.905 [s] 8.764 [s]
7th: 23.238 [s] 8.726 [s]
8th: 22.822 [s] 8.729 [s]
Signed-off-by: KaiGai Kohei <kaigai@ak.jp.nec.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: James Morris <jmorris@namei.org>
2007-09-28 17:20:55 +00:00
|
|
|
if ((n->startbit + EBITMAP_SIZE) > bit)
|
|
|
|
return ebitmap_node_get_bit(n, bit);
|
2005-04-16 22:20:36 +00:00
|
|
|
n = n->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-03-15 17:32:28 +00:00
|
|
|
int ebitmap_set_bit(struct ebitmap *e, u32 bit, int value)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct ebitmap_node *n, *prev, *new;
|
|
|
|
|
|
|
|
prev = NULL;
|
|
|
|
n = e->node;
|
|
|
|
while (n && n->startbit <= bit) {
|
SELinux: improve performance when AVC misses.
* We add ebitmap_for_each_positive_bit() which enables to walk on
any positive bit on the given ebitmap, to improve its performance
using common bit-operations defined in linux/bitops.h.
In the previous version, this logic was implemented using a combination
of ebitmap_for_each_bit() and ebitmap_node_get_bit(), but is was worse
in performance aspect.
This logic is most frequestly used to compute a new AVC entry,
so this patch can improve SELinux performance when AVC misses are happen.
* struct ebitmap_node is redefined as an array of "unsigned long", to get
suitable for using find_next_bit() which is fasted than iteration of
shift and logical operation, and to maximize memory usage allocated
from general purpose slab.
* Any ebitmap_for_each_bit() are repleced by the new implementation
in ss/service.c and ss/mls.c. Some of related implementation are
changed, however, there is no incompatibility with the previous
version.
* The width of any new line are less or equal than 80-chars.
The following benchmark shows the effect of this patch, when we
access many files which have different security context one after
another. The number is more than /selinux/avc/cache_threshold, so
any access always causes AVC misses.
selinux-2.6 selinux-2.6-ebitmap
AVG: 22.763 [s] 8.750 [s]
STD: 0.265 0.019
------------------------------------------
1st: 22.558 [s] 8.786 [s]
2nd: 22.458 [s] 8.750 [s]
3rd: 22.478 [s] 8.754 [s]
4th: 22.724 [s] 8.745 [s]
5th: 22.918 [s] 8.748 [s]
6th: 22.905 [s] 8.764 [s]
7th: 23.238 [s] 8.726 [s]
8th: 22.822 [s] 8.729 [s]
Signed-off-by: KaiGai Kohei <kaigai@ak.jp.nec.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: James Morris <jmorris@namei.org>
2007-09-28 17:20:55 +00:00
|
|
|
if ((n->startbit + EBITMAP_SIZE) > bit) {
|
2005-04-16 22:20:36 +00:00
|
|
|
if (value) {
|
SELinux: improve performance when AVC misses.
* We add ebitmap_for_each_positive_bit() which enables to walk on
any positive bit on the given ebitmap, to improve its performance
using common bit-operations defined in linux/bitops.h.
In the previous version, this logic was implemented using a combination
of ebitmap_for_each_bit() and ebitmap_node_get_bit(), but is was worse
in performance aspect.
This logic is most frequestly used to compute a new AVC entry,
so this patch can improve SELinux performance when AVC misses are happen.
* struct ebitmap_node is redefined as an array of "unsigned long", to get
suitable for using find_next_bit() which is fasted than iteration of
shift and logical operation, and to maximize memory usage allocated
from general purpose slab.
* Any ebitmap_for_each_bit() are repleced by the new implementation
in ss/service.c and ss/mls.c. Some of related implementation are
changed, however, there is no incompatibility with the previous
version.
* The width of any new line are less or equal than 80-chars.
The following benchmark shows the effect of this patch, when we
access many files which have different security context one after
another. The number is more than /selinux/avc/cache_threshold, so
any access always causes AVC misses.
selinux-2.6 selinux-2.6-ebitmap
AVG: 22.763 [s] 8.750 [s]
STD: 0.265 0.019
------------------------------------------
1st: 22.558 [s] 8.786 [s]
2nd: 22.458 [s] 8.750 [s]
3rd: 22.478 [s] 8.754 [s]
4th: 22.724 [s] 8.745 [s]
5th: 22.918 [s] 8.748 [s]
6th: 22.905 [s] 8.764 [s]
7th: 23.238 [s] 8.726 [s]
8th: 22.822 [s] 8.729 [s]
Signed-off-by: KaiGai Kohei <kaigai@ak.jp.nec.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: James Morris <jmorris@namei.org>
2007-09-28 17:20:55 +00:00
|
|
|
ebitmap_node_set_bit(n, bit);
|
2005-04-16 22:20:36 +00:00
|
|
|
} else {
|
2024-03-15 17:32:28 +00:00
|
|
|
u32 s;
|
SELinux: improve performance when AVC misses.
* We add ebitmap_for_each_positive_bit() which enables to walk on
any positive bit on the given ebitmap, to improve its performance
using common bit-operations defined in linux/bitops.h.
In the previous version, this logic was implemented using a combination
of ebitmap_for_each_bit() and ebitmap_node_get_bit(), but is was worse
in performance aspect.
This logic is most frequestly used to compute a new AVC entry,
so this patch can improve SELinux performance when AVC misses are happen.
* struct ebitmap_node is redefined as an array of "unsigned long", to get
suitable for using find_next_bit() which is fasted than iteration of
shift and logical operation, and to maximize memory usage allocated
from general purpose slab.
* Any ebitmap_for_each_bit() are repleced by the new implementation
in ss/service.c and ss/mls.c. Some of related implementation are
changed, however, there is no incompatibility with the previous
version.
* The width of any new line are less or equal than 80-chars.
The following benchmark shows the effect of this patch, when we
access many files which have different security context one after
another. The number is more than /selinux/avc/cache_threshold, so
any access always causes AVC misses.
selinux-2.6 selinux-2.6-ebitmap
AVG: 22.763 [s] 8.750 [s]
STD: 0.265 0.019
------------------------------------------
1st: 22.558 [s] 8.786 [s]
2nd: 22.458 [s] 8.750 [s]
3rd: 22.478 [s] 8.754 [s]
4th: 22.724 [s] 8.745 [s]
5th: 22.918 [s] 8.748 [s]
6th: 22.905 [s] 8.764 [s]
7th: 23.238 [s] 8.726 [s]
8th: 22.822 [s] 8.729 [s]
Signed-off-by: KaiGai Kohei <kaigai@ak.jp.nec.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: James Morris <jmorris@namei.org>
2007-09-28 17:20:55 +00:00
|
|
|
|
|
|
|
ebitmap_node_clr_bit(n, bit);
|
|
|
|
|
|
|
|
s = find_first_bit(n->maps, EBITMAP_SIZE);
|
|
|
|
if (s < EBITMAP_SIZE)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* drop this node from the bitmap */
|
|
|
|
if (!n->next) {
|
|
|
|
/*
|
|
|
|
* this was the highest map
|
|
|
|
* within the bitmap
|
|
|
|
*/
|
2005-04-16 22:20:36 +00:00
|
|
|
if (prev)
|
2024-02-22 23:52:27 +00:00
|
|
|
e->highbit = prev->startbit +
|
|
|
|
EBITMAP_SIZE;
|
2005-04-16 22:20:36 +00:00
|
|
|
else
|
SELinux: improve performance when AVC misses.
* We add ebitmap_for_each_positive_bit() which enables to walk on
any positive bit on the given ebitmap, to improve its performance
using common bit-operations defined in linux/bitops.h.
In the previous version, this logic was implemented using a combination
of ebitmap_for_each_bit() and ebitmap_node_get_bit(), but is was worse
in performance aspect.
This logic is most frequestly used to compute a new AVC entry,
so this patch can improve SELinux performance when AVC misses are happen.
* struct ebitmap_node is redefined as an array of "unsigned long", to get
suitable for using find_next_bit() which is fasted than iteration of
shift and logical operation, and to maximize memory usage allocated
from general purpose slab.
* Any ebitmap_for_each_bit() are repleced by the new implementation
in ss/service.c and ss/mls.c. Some of related implementation are
changed, however, there is no incompatibility with the previous
version.
* The width of any new line are less or equal than 80-chars.
The following benchmark shows the effect of this patch, when we
access many files which have different security context one after
another. The number is more than /selinux/avc/cache_threshold, so
any access always causes AVC misses.
selinux-2.6 selinux-2.6-ebitmap
AVG: 22.763 [s] 8.750 [s]
STD: 0.265 0.019
------------------------------------------
1st: 22.558 [s] 8.786 [s]
2nd: 22.458 [s] 8.750 [s]
3rd: 22.478 [s] 8.754 [s]
4th: 22.724 [s] 8.745 [s]
5th: 22.918 [s] 8.748 [s]
6th: 22.905 [s] 8.764 [s]
7th: 23.238 [s] 8.726 [s]
8th: 22.822 [s] 8.729 [s]
Signed-off-by: KaiGai Kohei <kaigai@ak.jp.nec.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: James Morris <jmorris@namei.org>
2007-09-28 17:20:55 +00:00
|
|
|
e->highbit = 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
SELinux: improve performance when AVC misses.
* We add ebitmap_for_each_positive_bit() which enables to walk on
any positive bit on the given ebitmap, to improve its performance
using common bit-operations defined in linux/bitops.h.
In the previous version, this logic was implemented using a combination
of ebitmap_for_each_bit() and ebitmap_node_get_bit(), but is was worse
in performance aspect.
This logic is most frequestly used to compute a new AVC entry,
so this patch can improve SELinux performance when AVC misses are happen.
* struct ebitmap_node is redefined as an array of "unsigned long", to get
suitable for using find_next_bit() which is fasted than iteration of
shift and logical operation, and to maximize memory usage allocated
from general purpose slab.
* Any ebitmap_for_each_bit() are repleced by the new implementation
in ss/service.c and ss/mls.c. Some of related implementation are
changed, however, there is no incompatibility with the previous
version.
* The width of any new line are less or equal than 80-chars.
The following benchmark shows the effect of this patch, when we
access many files which have different security context one after
another. The number is more than /selinux/avc/cache_threshold, so
any access always causes AVC misses.
selinux-2.6 selinux-2.6-ebitmap
AVG: 22.763 [s] 8.750 [s]
STD: 0.265 0.019
------------------------------------------
1st: 22.558 [s] 8.786 [s]
2nd: 22.458 [s] 8.750 [s]
3rd: 22.478 [s] 8.754 [s]
4th: 22.724 [s] 8.745 [s]
5th: 22.918 [s] 8.748 [s]
6th: 22.905 [s] 8.764 [s]
7th: 23.238 [s] 8.726 [s]
8th: 22.822 [s] 8.729 [s]
Signed-off-by: KaiGai Kohei <kaigai@ak.jp.nec.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: James Morris <jmorris@namei.org>
2007-09-28 17:20:55 +00:00
|
|
|
if (prev)
|
|
|
|
prev->next = n->next;
|
|
|
|
else
|
|
|
|
e->node = n->next;
|
2017-06-08 04:18:09 +00:00
|
|
|
kmem_cache_free(ebitmap_node_cachep, n);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
prev = n;
|
|
|
|
n = n->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!value)
|
|
|
|
return 0;
|
|
|
|
|
2017-06-08 04:18:09 +00:00
|
|
|
new = kmem_cache_zalloc(ebitmap_node_cachep, GFP_ATOMIC);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!new)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
SELinux: improve performance when AVC misses.
* We add ebitmap_for_each_positive_bit() which enables to walk on
any positive bit on the given ebitmap, to improve its performance
using common bit-operations defined in linux/bitops.h.
In the previous version, this logic was implemented using a combination
of ebitmap_for_each_bit() and ebitmap_node_get_bit(), but is was worse
in performance aspect.
This logic is most frequestly used to compute a new AVC entry,
so this patch can improve SELinux performance when AVC misses are happen.
* struct ebitmap_node is redefined as an array of "unsigned long", to get
suitable for using find_next_bit() which is fasted than iteration of
shift and logical operation, and to maximize memory usage allocated
from general purpose slab.
* Any ebitmap_for_each_bit() are repleced by the new implementation
in ss/service.c and ss/mls.c. Some of related implementation are
changed, however, there is no incompatibility with the previous
version.
* The width of any new line are less or equal than 80-chars.
The following benchmark shows the effect of this patch, when we
access many files which have different security context one after
another. The number is more than /selinux/avc/cache_threshold, so
any access always causes AVC misses.
selinux-2.6 selinux-2.6-ebitmap
AVG: 22.763 [s] 8.750 [s]
STD: 0.265 0.019
------------------------------------------
1st: 22.558 [s] 8.786 [s]
2nd: 22.458 [s] 8.750 [s]
3rd: 22.478 [s] 8.754 [s]
4th: 22.724 [s] 8.745 [s]
5th: 22.918 [s] 8.748 [s]
6th: 22.905 [s] 8.764 [s]
7th: 23.238 [s] 8.726 [s]
8th: 22.822 [s] 8.729 [s]
Signed-off-by: KaiGai Kohei <kaigai@ak.jp.nec.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: James Morris <jmorris@namei.org>
2007-09-28 17:20:55 +00:00
|
|
|
new->startbit = bit - (bit % EBITMAP_SIZE);
|
|
|
|
ebitmap_node_set_bit(new, bit);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (!n)
|
|
|
|
/* this node will be the highest map within the bitmap */
|
SELinux: improve performance when AVC misses.
* We add ebitmap_for_each_positive_bit() which enables to walk on
any positive bit on the given ebitmap, to improve its performance
using common bit-operations defined in linux/bitops.h.
In the previous version, this logic was implemented using a combination
of ebitmap_for_each_bit() and ebitmap_node_get_bit(), but is was worse
in performance aspect.
This logic is most frequestly used to compute a new AVC entry,
so this patch can improve SELinux performance when AVC misses are happen.
* struct ebitmap_node is redefined as an array of "unsigned long", to get
suitable for using find_next_bit() which is fasted than iteration of
shift and logical operation, and to maximize memory usage allocated
from general purpose slab.
* Any ebitmap_for_each_bit() are repleced by the new implementation
in ss/service.c and ss/mls.c. Some of related implementation are
changed, however, there is no incompatibility with the previous
version.
* The width of any new line are less or equal than 80-chars.
The following benchmark shows the effect of this patch, when we
access many files which have different security context one after
another. The number is more than /selinux/avc/cache_threshold, so
any access always causes AVC misses.
selinux-2.6 selinux-2.6-ebitmap
AVG: 22.763 [s] 8.750 [s]
STD: 0.265 0.019
------------------------------------------
1st: 22.558 [s] 8.786 [s]
2nd: 22.458 [s] 8.750 [s]
3rd: 22.478 [s] 8.754 [s]
4th: 22.724 [s] 8.745 [s]
5th: 22.918 [s] 8.748 [s]
6th: 22.905 [s] 8.764 [s]
7th: 23.238 [s] 8.726 [s]
8th: 22.822 [s] 8.729 [s]
Signed-off-by: KaiGai Kohei <kaigai@ak.jp.nec.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: James Morris <jmorris@namei.org>
2007-09-28 17:20:55 +00:00
|
|
|
e->highbit = new->startbit + EBITMAP_SIZE;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (prev) {
|
|
|
|
new->next = prev->next;
|
|
|
|
prev->next = new;
|
|
|
|
} else {
|
|
|
|
new->next = e->node;
|
|
|
|
e->node = new;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ebitmap_destroy(struct ebitmap *e)
|
|
|
|
{
|
|
|
|
struct ebitmap_node *n, *temp;
|
|
|
|
|
|
|
|
if (!e)
|
|
|
|
return;
|
|
|
|
|
|
|
|
n = e->node;
|
|
|
|
while (n) {
|
|
|
|
temp = n;
|
|
|
|
n = n->next;
|
2017-06-08 04:18:09 +00:00
|
|
|
kmem_cache_free(ebitmap_node_cachep, temp);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
e->highbit = 0;
|
|
|
|
e->node = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ebitmap_read(struct ebitmap *e, void *fp)
|
|
|
|
{
|
SELinux: improve performance when AVC misses.
* We add ebitmap_for_each_positive_bit() which enables to walk on
any positive bit on the given ebitmap, to improve its performance
using common bit-operations defined in linux/bitops.h.
In the previous version, this logic was implemented using a combination
of ebitmap_for_each_bit() and ebitmap_node_get_bit(), but is was worse
in performance aspect.
This logic is most frequestly used to compute a new AVC entry,
so this patch can improve SELinux performance when AVC misses are happen.
* struct ebitmap_node is redefined as an array of "unsigned long", to get
suitable for using find_next_bit() which is fasted than iteration of
shift and logical operation, and to maximize memory usage allocated
from general purpose slab.
* Any ebitmap_for_each_bit() are repleced by the new implementation
in ss/service.c and ss/mls.c. Some of related implementation are
changed, however, there is no incompatibility with the previous
version.
* The width of any new line are less or equal than 80-chars.
The following benchmark shows the effect of this patch, when we
access many files which have different security context one after
another. The number is more than /selinux/avc/cache_threshold, so
any access always causes AVC misses.
selinux-2.6 selinux-2.6-ebitmap
AVG: 22.763 [s] 8.750 [s]
STD: 0.265 0.019
------------------------------------------
1st: 22.558 [s] 8.786 [s]
2nd: 22.458 [s] 8.750 [s]
3rd: 22.478 [s] 8.754 [s]
4th: 22.724 [s] 8.745 [s]
5th: 22.918 [s] 8.748 [s]
6th: 22.905 [s] 8.764 [s]
7th: 23.238 [s] 8.726 [s]
8th: 22.822 [s] 8.729 [s]
Signed-off-by: KaiGai Kohei <kaigai@ak.jp.nec.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: James Morris <jmorris@namei.org>
2007-09-28 17:20:55 +00:00
|
|
|
struct ebitmap_node *n = NULL;
|
2024-03-15 17:32:28 +00:00
|
|
|
u32 mapunit, count, startbit, index, i;
|
2019-05-08 06:21:17 +00:00
|
|
|
__le32 ebitmap_start;
|
SELinux: improve performance when AVC misses.
* We add ebitmap_for_each_positive_bit() which enables to walk on
any positive bit on the given ebitmap, to improve its performance
using common bit-operations defined in linux/bitops.h.
In the previous version, this logic was implemented using a combination
of ebitmap_for_each_bit() and ebitmap_node_get_bit(), but is was worse
in performance aspect.
This logic is most frequestly used to compute a new AVC entry,
so this patch can improve SELinux performance when AVC misses are happen.
* struct ebitmap_node is redefined as an array of "unsigned long", to get
suitable for using find_next_bit() which is fasted than iteration of
shift and logical operation, and to maximize memory usage allocated
from general purpose slab.
* Any ebitmap_for_each_bit() are repleced by the new implementation
in ss/service.c and ss/mls.c. Some of related implementation are
changed, however, there is no incompatibility with the previous
version.
* The width of any new line are less or equal than 80-chars.
The following benchmark shows the effect of this patch, when we
access many files which have different security context one after
another. The number is more than /selinux/avc/cache_threshold, so
any access always causes AVC misses.
selinux-2.6 selinux-2.6-ebitmap
AVG: 22.763 [s] 8.750 [s]
STD: 0.265 0.019
------------------------------------------
1st: 22.558 [s] 8.786 [s]
2nd: 22.458 [s] 8.750 [s]
3rd: 22.478 [s] 8.754 [s]
4th: 22.724 [s] 8.745 [s]
5th: 22.918 [s] 8.748 [s]
6th: 22.905 [s] 8.764 [s]
7th: 23.238 [s] 8.726 [s]
8th: 22.822 [s] 8.729 [s]
Signed-off-by: KaiGai Kohei <kaigai@ak.jp.nec.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: James Morris <jmorris@namei.org>
2007-09-28 17:20:55 +00:00
|
|
|
u64 map;
|
2019-05-08 06:21:17 +00:00
|
|
|
__le64 mapbits;
|
2005-09-03 22:55:17 +00:00
|
|
|
__le32 buf[3];
|
2024-03-15 17:32:28 +00:00
|
|
|
int rc;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
ebitmap_init(e);
|
|
|
|
|
|
|
|
rc = next_entry(buf, fp, sizeof buf);
|
|
|
|
if (rc < 0)
|
|
|
|
goto out;
|
|
|
|
|
SELinux: improve performance when AVC misses.
* We add ebitmap_for_each_positive_bit() which enables to walk on
any positive bit on the given ebitmap, to improve its performance
using common bit-operations defined in linux/bitops.h.
In the previous version, this logic was implemented using a combination
of ebitmap_for_each_bit() and ebitmap_node_get_bit(), but is was worse
in performance aspect.
This logic is most frequestly used to compute a new AVC entry,
so this patch can improve SELinux performance when AVC misses are happen.
* struct ebitmap_node is redefined as an array of "unsigned long", to get
suitable for using find_next_bit() which is fasted than iteration of
shift and logical operation, and to maximize memory usage allocated
from general purpose slab.
* Any ebitmap_for_each_bit() are repleced by the new implementation
in ss/service.c and ss/mls.c. Some of related implementation are
changed, however, there is no incompatibility with the previous
version.
* The width of any new line are less or equal than 80-chars.
The following benchmark shows the effect of this patch, when we
access many files which have different security context one after
another. The number is more than /selinux/avc/cache_threshold, so
any access always causes AVC misses.
selinux-2.6 selinux-2.6-ebitmap
AVG: 22.763 [s] 8.750 [s]
STD: 0.265 0.019
------------------------------------------
1st: 22.558 [s] 8.786 [s]
2nd: 22.458 [s] 8.750 [s]
3rd: 22.478 [s] 8.754 [s]
4th: 22.724 [s] 8.745 [s]
5th: 22.918 [s] 8.748 [s]
6th: 22.905 [s] 8.764 [s]
7th: 23.238 [s] 8.726 [s]
8th: 22.822 [s] 8.729 [s]
Signed-off-by: KaiGai Kohei <kaigai@ak.jp.nec.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: James Morris <jmorris@namei.org>
2007-09-28 17:20:55 +00:00
|
|
|
mapunit = le32_to_cpu(buf[0]);
|
2005-04-16 22:20:36 +00:00
|
|
|
e->highbit = le32_to_cpu(buf[1]);
|
|
|
|
count = le32_to_cpu(buf[2]);
|
|
|
|
|
2010-10-13 21:50:25 +00:00
|
|
|
if (mapunit != BITS_PER_U64) {
|
2018-06-12 08:09:01 +00:00
|
|
|
pr_err("SELinux: ebitmap: map size %u does not "
|
2024-03-15 17:32:28 +00:00
|
|
|
"match my size %u (high bit was %u)\n",
|
2010-10-13 21:50:25 +00:00
|
|
|
mapunit, BITS_PER_U64, e->highbit);
|
2005-04-16 22:20:36 +00:00
|
|
|
goto bad;
|
|
|
|
}
|
SELinux: improve performance when AVC misses.
* We add ebitmap_for_each_positive_bit() which enables to walk on
any positive bit on the given ebitmap, to improve its performance
using common bit-operations defined in linux/bitops.h.
In the previous version, this logic was implemented using a combination
of ebitmap_for_each_bit() and ebitmap_node_get_bit(), but is was worse
in performance aspect.
This logic is most frequestly used to compute a new AVC entry,
so this patch can improve SELinux performance when AVC misses are happen.
* struct ebitmap_node is redefined as an array of "unsigned long", to get
suitable for using find_next_bit() which is fasted than iteration of
shift and logical operation, and to maximize memory usage allocated
from general purpose slab.
* Any ebitmap_for_each_bit() are repleced by the new implementation
in ss/service.c and ss/mls.c. Some of related implementation are
changed, however, there is no incompatibility with the previous
version.
* The width of any new line are less or equal than 80-chars.
The following benchmark shows the effect of this patch, when we
access many files which have different security context one after
another. The number is more than /selinux/avc/cache_threshold, so
any access always causes AVC misses.
selinux-2.6 selinux-2.6-ebitmap
AVG: 22.763 [s] 8.750 [s]
STD: 0.265 0.019
------------------------------------------
1st: 22.558 [s] 8.786 [s]
2nd: 22.458 [s] 8.750 [s]
3rd: 22.478 [s] 8.754 [s]
4th: 22.724 [s] 8.745 [s]
5th: 22.918 [s] 8.748 [s]
6th: 22.905 [s] 8.764 [s]
7th: 23.238 [s] 8.726 [s]
8th: 22.822 [s] 8.729 [s]
Signed-off-by: KaiGai Kohei <kaigai@ak.jp.nec.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: James Morris <jmorris@namei.org>
2007-09-28 17:20:55 +00:00
|
|
|
|
|
|
|
/* round up e->highbit */
|
|
|
|
e->highbit += EBITMAP_SIZE - 1;
|
|
|
|
e->highbit -= (e->highbit % EBITMAP_SIZE);
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!e->highbit) {
|
|
|
|
e->node = NULL;
|
|
|
|
goto ok;
|
|
|
|
}
|
SELinux: improve performance when AVC misses.
* We add ebitmap_for_each_positive_bit() which enables to walk on
any positive bit on the given ebitmap, to improve its performance
using common bit-operations defined in linux/bitops.h.
In the previous version, this logic was implemented using a combination
of ebitmap_for_each_bit() and ebitmap_node_get_bit(), but is was worse
in performance aspect.
This logic is most frequestly used to compute a new AVC entry,
so this patch can improve SELinux performance when AVC misses are happen.
* struct ebitmap_node is redefined as an array of "unsigned long", to get
suitable for using find_next_bit() which is fasted than iteration of
shift and logical operation, and to maximize memory usage allocated
from general purpose slab.
* Any ebitmap_for_each_bit() are repleced by the new implementation
in ss/service.c and ss/mls.c. Some of related implementation are
changed, however, there is no incompatibility with the previous
version.
* The width of any new line are less or equal than 80-chars.
The following benchmark shows the effect of this patch, when we
access many files which have different security context one after
another. The number is more than /selinux/avc/cache_threshold, so
any access always causes AVC misses.
selinux-2.6 selinux-2.6-ebitmap
AVG: 22.763 [s] 8.750 [s]
STD: 0.265 0.019
------------------------------------------
1st: 22.558 [s] 8.786 [s]
2nd: 22.458 [s] 8.750 [s]
3rd: 22.478 [s] 8.754 [s]
4th: 22.724 [s] 8.745 [s]
5th: 22.918 [s] 8.748 [s]
6th: 22.905 [s] 8.764 [s]
7th: 23.238 [s] 8.726 [s]
8th: 22.822 [s] 8.729 [s]
Signed-off-by: KaiGai Kohei <kaigai@ak.jp.nec.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: James Morris <jmorris@namei.org>
2007-09-28 17:20:55 +00:00
|
|
|
|
2016-08-23 20:49:23 +00:00
|
|
|
if (e->highbit && !count)
|
|
|
|
goto bad;
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
for (i = 0; i < count; i++) {
|
2019-05-08 06:21:17 +00:00
|
|
|
rc = next_entry(&ebitmap_start, fp, sizeof(u32));
|
2005-04-16 22:20:36 +00:00
|
|
|
if (rc < 0) {
|
2018-06-12 08:09:01 +00:00
|
|
|
pr_err("SELinux: ebitmap: truncated map\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
goto bad;
|
|
|
|
}
|
2019-05-08 06:21:17 +00:00
|
|
|
startbit = le32_to_cpu(ebitmap_start);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
SELinux: improve performance when AVC misses.
* We add ebitmap_for_each_positive_bit() which enables to walk on
any positive bit on the given ebitmap, to improve its performance
using common bit-operations defined in linux/bitops.h.
In the previous version, this logic was implemented using a combination
of ebitmap_for_each_bit() and ebitmap_node_get_bit(), but is was worse
in performance aspect.
This logic is most frequestly used to compute a new AVC entry,
so this patch can improve SELinux performance when AVC misses are happen.
* struct ebitmap_node is redefined as an array of "unsigned long", to get
suitable for using find_next_bit() which is fasted than iteration of
shift and logical operation, and to maximize memory usage allocated
from general purpose slab.
* Any ebitmap_for_each_bit() are repleced by the new implementation
in ss/service.c and ss/mls.c. Some of related implementation are
changed, however, there is no incompatibility with the previous
version.
* The width of any new line are less or equal than 80-chars.
The following benchmark shows the effect of this patch, when we
access many files which have different security context one after
another. The number is more than /selinux/avc/cache_threshold, so
any access always causes AVC misses.
selinux-2.6 selinux-2.6-ebitmap
AVG: 22.763 [s] 8.750 [s]
STD: 0.265 0.019
------------------------------------------
1st: 22.558 [s] 8.786 [s]
2nd: 22.458 [s] 8.750 [s]
3rd: 22.478 [s] 8.754 [s]
4th: 22.724 [s] 8.745 [s]
5th: 22.918 [s] 8.748 [s]
6th: 22.905 [s] 8.764 [s]
7th: 23.238 [s] 8.726 [s]
8th: 22.822 [s] 8.729 [s]
Signed-off-by: KaiGai Kohei <kaigai@ak.jp.nec.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: James Morris <jmorris@namei.org>
2007-09-28 17:20:55 +00:00
|
|
|
if (startbit & (mapunit - 1)) {
|
2024-03-27 19:25:57 +00:00
|
|
|
pr_err("SELinux: ebitmap start bit (%u) is "
|
2007-10-03 14:42:56 +00:00
|
|
|
"not a multiple of the map unit size (%u)\n",
|
SELinux: improve performance when AVC misses.
* We add ebitmap_for_each_positive_bit() which enables to walk on
any positive bit on the given ebitmap, to improve its performance
using common bit-operations defined in linux/bitops.h.
In the previous version, this logic was implemented using a combination
of ebitmap_for_each_bit() and ebitmap_node_get_bit(), but is was worse
in performance aspect.
This logic is most frequestly used to compute a new AVC entry,
so this patch can improve SELinux performance when AVC misses are happen.
* struct ebitmap_node is redefined as an array of "unsigned long", to get
suitable for using find_next_bit() which is fasted than iteration of
shift and logical operation, and to maximize memory usage allocated
from general purpose slab.
* Any ebitmap_for_each_bit() are repleced by the new implementation
in ss/service.c and ss/mls.c. Some of related implementation are
changed, however, there is no incompatibility with the previous
version.
* The width of any new line are less or equal than 80-chars.
The following benchmark shows the effect of this patch, when we
access many files which have different security context one after
another. The number is more than /selinux/avc/cache_threshold, so
any access always causes AVC misses.
selinux-2.6 selinux-2.6-ebitmap
AVG: 22.763 [s] 8.750 [s]
STD: 0.265 0.019
------------------------------------------
1st: 22.558 [s] 8.786 [s]
2nd: 22.458 [s] 8.750 [s]
3rd: 22.478 [s] 8.754 [s]
4th: 22.724 [s] 8.745 [s]
5th: 22.918 [s] 8.748 [s]
6th: 22.905 [s] 8.764 [s]
7th: 23.238 [s] 8.726 [s]
8th: 22.822 [s] 8.729 [s]
Signed-off-by: KaiGai Kohei <kaigai@ak.jp.nec.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: James Morris <jmorris@namei.org>
2007-09-28 17:20:55 +00:00
|
|
|
startbit, mapunit);
|
|
|
|
goto bad;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
SELinux: improve performance when AVC misses.
* We add ebitmap_for_each_positive_bit() which enables to walk on
any positive bit on the given ebitmap, to improve its performance
using common bit-operations defined in linux/bitops.h.
In the previous version, this logic was implemented using a combination
of ebitmap_for_each_bit() and ebitmap_node_get_bit(), but is was worse
in performance aspect.
This logic is most frequestly used to compute a new AVC entry,
so this patch can improve SELinux performance when AVC misses are happen.
* struct ebitmap_node is redefined as an array of "unsigned long", to get
suitable for using find_next_bit() which is fasted than iteration of
shift and logical operation, and to maximize memory usage allocated
from general purpose slab.
* Any ebitmap_for_each_bit() are repleced by the new implementation
in ss/service.c and ss/mls.c. Some of related implementation are
changed, however, there is no incompatibility with the previous
version.
* The width of any new line are less or equal than 80-chars.
The following benchmark shows the effect of this patch, when we
access many files which have different security context one after
another. The number is more than /selinux/avc/cache_threshold, so
any access always causes AVC misses.
selinux-2.6 selinux-2.6-ebitmap
AVG: 22.763 [s] 8.750 [s]
STD: 0.265 0.019
------------------------------------------
1st: 22.558 [s] 8.786 [s]
2nd: 22.458 [s] 8.750 [s]
3rd: 22.478 [s] 8.754 [s]
4th: 22.724 [s] 8.745 [s]
5th: 22.918 [s] 8.748 [s]
6th: 22.905 [s] 8.764 [s]
7th: 23.238 [s] 8.726 [s]
8th: 22.822 [s] 8.729 [s]
Signed-off-by: KaiGai Kohei <kaigai@ak.jp.nec.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: James Morris <jmorris@namei.org>
2007-09-28 17:20:55 +00:00
|
|
|
if (startbit > e->highbit - mapunit) {
|
2024-03-27 19:25:57 +00:00
|
|
|
pr_err("SELinux: ebitmap start bit (%u) is "
|
2007-10-03 14:42:56 +00:00
|
|
|
"beyond the end of the bitmap (%u)\n",
|
SELinux: improve performance when AVC misses.
* We add ebitmap_for_each_positive_bit() which enables to walk on
any positive bit on the given ebitmap, to improve its performance
using common bit-operations defined in linux/bitops.h.
In the previous version, this logic was implemented using a combination
of ebitmap_for_each_bit() and ebitmap_node_get_bit(), but is was worse
in performance aspect.
This logic is most frequestly used to compute a new AVC entry,
so this patch can improve SELinux performance when AVC misses are happen.
* struct ebitmap_node is redefined as an array of "unsigned long", to get
suitable for using find_next_bit() which is fasted than iteration of
shift and logical operation, and to maximize memory usage allocated
from general purpose slab.
* Any ebitmap_for_each_bit() are repleced by the new implementation
in ss/service.c and ss/mls.c. Some of related implementation are
changed, however, there is no incompatibility with the previous
version.
* The width of any new line are less or equal than 80-chars.
The following benchmark shows the effect of this patch, when we
access many files which have different security context one after
another. The number is more than /selinux/avc/cache_threshold, so
any access always causes AVC misses.
selinux-2.6 selinux-2.6-ebitmap
AVG: 22.763 [s] 8.750 [s]
STD: 0.265 0.019
------------------------------------------
1st: 22.558 [s] 8.786 [s]
2nd: 22.458 [s] 8.750 [s]
3rd: 22.478 [s] 8.754 [s]
4th: 22.724 [s] 8.745 [s]
5th: 22.918 [s] 8.748 [s]
6th: 22.905 [s] 8.764 [s]
7th: 23.238 [s] 8.726 [s]
8th: 22.822 [s] 8.729 [s]
Signed-off-by: KaiGai Kohei <kaigai@ak.jp.nec.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: James Morris <jmorris@namei.org>
2007-09-28 17:20:55 +00:00
|
|
|
startbit, (e->highbit - mapunit));
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!n || startbit >= n->startbit + EBITMAP_SIZE) {
|
|
|
|
struct ebitmap_node *tmp;
|
2024-02-22 23:52:27 +00:00
|
|
|
tmp = kmem_cache_zalloc(ebitmap_node_cachep,
|
|
|
|
GFP_KERNEL);
|
SELinux: improve performance when AVC misses.
* We add ebitmap_for_each_positive_bit() which enables to walk on
any positive bit on the given ebitmap, to improve its performance
using common bit-operations defined in linux/bitops.h.
In the previous version, this logic was implemented using a combination
of ebitmap_for_each_bit() and ebitmap_node_get_bit(), but is was worse
in performance aspect.
This logic is most frequestly used to compute a new AVC entry,
so this patch can improve SELinux performance when AVC misses are happen.
* struct ebitmap_node is redefined as an array of "unsigned long", to get
suitable for using find_next_bit() which is fasted than iteration of
shift and logical operation, and to maximize memory usage allocated
from general purpose slab.
* Any ebitmap_for_each_bit() are repleced by the new implementation
in ss/service.c and ss/mls.c. Some of related implementation are
changed, however, there is no incompatibility with the previous
version.
* The width of any new line are less or equal than 80-chars.
The following benchmark shows the effect of this patch, when we
access many files which have different security context one after
another. The number is more than /selinux/avc/cache_threshold, so
any access always causes AVC misses.
selinux-2.6 selinux-2.6-ebitmap
AVG: 22.763 [s] 8.750 [s]
STD: 0.265 0.019
------------------------------------------
1st: 22.558 [s] 8.786 [s]
2nd: 22.458 [s] 8.750 [s]
3rd: 22.478 [s] 8.754 [s]
4th: 22.724 [s] 8.745 [s]
5th: 22.918 [s] 8.748 [s]
6th: 22.905 [s] 8.764 [s]
7th: 23.238 [s] 8.726 [s]
8th: 22.822 [s] 8.729 [s]
Signed-off-by: KaiGai Kohei <kaigai@ak.jp.nec.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: James Morris <jmorris@namei.org>
2007-09-28 17:20:55 +00:00
|
|
|
if (!tmp) {
|
2018-06-12 08:09:01 +00:00
|
|
|
pr_err("SELinux: ebitmap: out of memory\n");
|
SELinux: improve performance when AVC misses.
* We add ebitmap_for_each_positive_bit() which enables to walk on
any positive bit on the given ebitmap, to improve its performance
using common bit-operations defined in linux/bitops.h.
In the previous version, this logic was implemented using a combination
of ebitmap_for_each_bit() and ebitmap_node_get_bit(), but is was worse
in performance aspect.
This logic is most frequestly used to compute a new AVC entry,
so this patch can improve SELinux performance when AVC misses are happen.
* struct ebitmap_node is redefined as an array of "unsigned long", to get
suitable for using find_next_bit() which is fasted than iteration of
shift and logical operation, and to maximize memory usage allocated
from general purpose slab.
* Any ebitmap_for_each_bit() are repleced by the new implementation
in ss/service.c and ss/mls.c. Some of related implementation are
changed, however, there is no incompatibility with the previous
version.
* The width of any new line are less or equal than 80-chars.
The following benchmark shows the effect of this patch, when we
access many files which have different security context one after
another. The number is more than /selinux/avc/cache_threshold, so
any access always causes AVC misses.
selinux-2.6 selinux-2.6-ebitmap
AVG: 22.763 [s] 8.750 [s]
STD: 0.265 0.019
------------------------------------------
1st: 22.558 [s] 8.786 [s]
2nd: 22.458 [s] 8.750 [s]
3rd: 22.478 [s] 8.754 [s]
4th: 22.724 [s] 8.745 [s]
5th: 22.918 [s] 8.748 [s]
6th: 22.905 [s] 8.764 [s]
7th: 23.238 [s] 8.726 [s]
8th: 22.822 [s] 8.729 [s]
Signed-off-by: KaiGai Kohei <kaigai@ak.jp.nec.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: James Morris <jmorris@namei.org>
2007-09-28 17:20:55 +00:00
|
|
|
rc = -ENOMEM;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
/* round down */
|
|
|
|
tmp->startbit = startbit - (startbit % EBITMAP_SIZE);
|
2008-04-18 21:38:30 +00:00
|
|
|
if (n)
|
SELinux: improve performance when AVC misses.
* We add ebitmap_for_each_positive_bit() which enables to walk on
any positive bit on the given ebitmap, to improve its performance
using common bit-operations defined in linux/bitops.h.
In the previous version, this logic was implemented using a combination
of ebitmap_for_each_bit() and ebitmap_node_get_bit(), but is was worse
in performance aspect.
This logic is most frequestly used to compute a new AVC entry,
so this patch can improve SELinux performance when AVC misses are happen.
* struct ebitmap_node is redefined as an array of "unsigned long", to get
suitable for using find_next_bit() which is fasted than iteration of
shift and logical operation, and to maximize memory usage allocated
from general purpose slab.
* Any ebitmap_for_each_bit() are repleced by the new implementation
in ss/service.c and ss/mls.c. Some of related implementation are
changed, however, there is no incompatibility with the previous
version.
* The width of any new line are less or equal than 80-chars.
The following benchmark shows the effect of this patch, when we
access many files which have different security context one after
another. The number is more than /selinux/avc/cache_threshold, so
any access always causes AVC misses.
selinux-2.6 selinux-2.6-ebitmap
AVG: 22.763 [s] 8.750 [s]
STD: 0.265 0.019
------------------------------------------
1st: 22.558 [s] 8.786 [s]
2nd: 22.458 [s] 8.750 [s]
3rd: 22.478 [s] 8.754 [s]
4th: 22.724 [s] 8.745 [s]
5th: 22.918 [s] 8.748 [s]
6th: 22.905 [s] 8.764 [s]
7th: 23.238 [s] 8.726 [s]
8th: 22.822 [s] 8.729 [s]
Signed-off-by: KaiGai Kohei <kaigai@ak.jp.nec.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: James Morris <jmorris@namei.org>
2007-09-28 17:20:55 +00:00
|
|
|
n->next = tmp;
|
2008-04-18 21:38:30 +00:00
|
|
|
else
|
SELinux: improve performance when AVC misses.
* We add ebitmap_for_each_positive_bit() which enables to walk on
any positive bit on the given ebitmap, to improve its performance
using common bit-operations defined in linux/bitops.h.
In the previous version, this logic was implemented using a combination
of ebitmap_for_each_bit() and ebitmap_node_get_bit(), but is was worse
in performance aspect.
This logic is most frequestly used to compute a new AVC entry,
so this patch can improve SELinux performance when AVC misses are happen.
* struct ebitmap_node is redefined as an array of "unsigned long", to get
suitable for using find_next_bit() which is fasted than iteration of
shift and logical operation, and to maximize memory usage allocated
from general purpose slab.
* Any ebitmap_for_each_bit() are repleced by the new implementation
in ss/service.c and ss/mls.c. Some of related implementation are
changed, however, there is no incompatibility with the previous
version.
* The width of any new line are less or equal than 80-chars.
The following benchmark shows the effect of this patch, when we
access many files which have different security context one after
another. The number is more than /selinux/avc/cache_threshold, so
any access always causes AVC misses.
selinux-2.6 selinux-2.6-ebitmap
AVG: 22.763 [s] 8.750 [s]
STD: 0.265 0.019
------------------------------------------
1st: 22.558 [s] 8.786 [s]
2nd: 22.458 [s] 8.750 [s]
3rd: 22.478 [s] 8.754 [s]
4th: 22.724 [s] 8.745 [s]
5th: 22.918 [s] 8.748 [s]
6th: 22.905 [s] 8.764 [s]
7th: 23.238 [s] 8.726 [s]
8th: 22.822 [s] 8.729 [s]
Signed-off-by: KaiGai Kohei <kaigai@ak.jp.nec.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: James Morris <jmorris@namei.org>
2007-09-28 17:20:55 +00:00
|
|
|
e->node = tmp;
|
|
|
|
n = tmp;
|
|
|
|
} else if (startbit <= n->startbit) {
|
2024-03-27 19:25:57 +00:00
|
|
|
pr_err("SELinux: ebitmap: start bit %u"
|
|
|
|
" comes after start bit %u\n",
|
SELinux: improve performance when AVC misses.
* We add ebitmap_for_each_positive_bit() which enables to walk on
any positive bit on the given ebitmap, to improve its performance
using common bit-operations defined in linux/bitops.h.
In the previous version, this logic was implemented using a combination
of ebitmap_for_each_bit() and ebitmap_node_get_bit(), but is was worse
in performance aspect.
This logic is most frequestly used to compute a new AVC entry,
so this patch can improve SELinux performance when AVC misses are happen.
* struct ebitmap_node is redefined as an array of "unsigned long", to get
suitable for using find_next_bit() which is fasted than iteration of
shift and logical operation, and to maximize memory usage allocated
from general purpose slab.
* Any ebitmap_for_each_bit() are repleced by the new implementation
in ss/service.c and ss/mls.c. Some of related implementation are
changed, however, there is no incompatibility with the previous
version.
* The width of any new line are less or equal than 80-chars.
The following benchmark shows the effect of this patch, when we
access many files which have different security context one after
another. The number is more than /selinux/avc/cache_threshold, so
any access always causes AVC misses.
selinux-2.6 selinux-2.6-ebitmap
AVG: 22.763 [s] 8.750 [s]
STD: 0.265 0.019
------------------------------------------
1st: 22.558 [s] 8.786 [s]
2nd: 22.458 [s] 8.750 [s]
3rd: 22.478 [s] 8.754 [s]
4th: 22.724 [s] 8.745 [s]
5th: 22.918 [s] 8.748 [s]
6th: 22.905 [s] 8.764 [s]
7th: 23.238 [s] 8.726 [s]
8th: 22.822 [s] 8.729 [s]
Signed-off-by: KaiGai Kohei <kaigai@ak.jp.nec.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: James Morris <jmorris@namei.org>
2007-09-28 17:20:55 +00:00
|
|
|
startbit, n->startbit);
|
|
|
|
goto bad;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
SELinux: improve performance when AVC misses.
* We add ebitmap_for_each_positive_bit() which enables to walk on
any positive bit on the given ebitmap, to improve its performance
using common bit-operations defined in linux/bitops.h.
In the previous version, this logic was implemented using a combination
of ebitmap_for_each_bit() and ebitmap_node_get_bit(), but is was worse
in performance aspect.
This logic is most frequestly used to compute a new AVC entry,
so this patch can improve SELinux performance when AVC misses are happen.
* struct ebitmap_node is redefined as an array of "unsigned long", to get
suitable for using find_next_bit() which is fasted than iteration of
shift and logical operation, and to maximize memory usage allocated
from general purpose slab.
* Any ebitmap_for_each_bit() are repleced by the new implementation
in ss/service.c and ss/mls.c. Some of related implementation are
changed, however, there is no incompatibility with the previous
version.
* The width of any new line are less or equal than 80-chars.
The following benchmark shows the effect of this patch, when we
access many files which have different security context one after
another. The number is more than /selinux/avc/cache_threshold, so
any access always causes AVC misses.
selinux-2.6 selinux-2.6-ebitmap
AVG: 22.763 [s] 8.750 [s]
STD: 0.265 0.019
------------------------------------------
1st: 22.558 [s] 8.786 [s]
2nd: 22.458 [s] 8.750 [s]
3rd: 22.478 [s] 8.754 [s]
4th: 22.724 [s] 8.745 [s]
5th: 22.918 [s] 8.748 [s]
6th: 22.905 [s] 8.764 [s]
7th: 23.238 [s] 8.726 [s]
8th: 22.822 [s] 8.729 [s]
Signed-off-by: KaiGai Kohei <kaigai@ak.jp.nec.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: James Morris <jmorris@namei.org>
2007-09-28 17:20:55 +00:00
|
|
|
|
2019-05-08 06:21:17 +00:00
|
|
|
rc = next_entry(&mapbits, fp, sizeof(u64));
|
2005-04-16 22:20:36 +00:00
|
|
|
if (rc < 0) {
|
2018-06-12 08:09:01 +00:00
|
|
|
pr_err("SELinux: ebitmap: truncated map\n");
|
SELinux: improve performance when AVC misses.
* We add ebitmap_for_each_positive_bit() which enables to walk on
any positive bit on the given ebitmap, to improve its performance
using common bit-operations defined in linux/bitops.h.
In the previous version, this logic was implemented using a combination
of ebitmap_for_each_bit() and ebitmap_node_get_bit(), but is was worse
in performance aspect.
This logic is most frequestly used to compute a new AVC entry,
so this patch can improve SELinux performance when AVC misses are happen.
* struct ebitmap_node is redefined as an array of "unsigned long", to get
suitable for using find_next_bit() which is fasted than iteration of
shift and logical operation, and to maximize memory usage allocated
from general purpose slab.
* Any ebitmap_for_each_bit() are repleced by the new implementation
in ss/service.c and ss/mls.c. Some of related implementation are
changed, however, there is no incompatibility with the previous
version.
* The width of any new line are less or equal than 80-chars.
The following benchmark shows the effect of this patch, when we
access many files which have different security context one after
another. The number is more than /selinux/avc/cache_threshold, so
any access always causes AVC misses.
selinux-2.6 selinux-2.6-ebitmap
AVG: 22.763 [s] 8.750 [s]
STD: 0.265 0.019
------------------------------------------
1st: 22.558 [s] 8.786 [s]
2nd: 22.458 [s] 8.750 [s]
3rd: 22.478 [s] 8.754 [s]
4th: 22.724 [s] 8.745 [s]
5th: 22.918 [s] 8.748 [s]
6th: 22.905 [s] 8.764 [s]
7th: 23.238 [s] 8.726 [s]
8th: 22.822 [s] 8.729 [s]
Signed-off-by: KaiGai Kohei <kaigai@ak.jp.nec.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: James Morris <jmorris@namei.org>
2007-09-28 17:20:55 +00:00
|
|
|
goto bad;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2019-05-08 06:21:17 +00:00
|
|
|
map = le64_to_cpu(mapbits);
|
2024-03-15 17:28:44 +00:00
|
|
|
if (!map) {
|
|
|
|
pr_err("SELinux: ebitmap: empty map\n");
|
|
|
|
goto bad;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
SELinux: improve performance when AVC misses.
* We add ebitmap_for_each_positive_bit() which enables to walk on
any positive bit on the given ebitmap, to improve its performance
using common bit-operations defined in linux/bitops.h.
In the previous version, this logic was implemented using a combination
of ebitmap_for_each_bit() and ebitmap_node_get_bit(), but is was worse
in performance aspect.
This logic is most frequestly used to compute a new AVC entry,
so this patch can improve SELinux performance when AVC misses are happen.
* struct ebitmap_node is redefined as an array of "unsigned long", to get
suitable for using find_next_bit() which is fasted than iteration of
shift and logical operation, and to maximize memory usage allocated
from general purpose slab.
* Any ebitmap_for_each_bit() are repleced by the new implementation
in ss/service.c and ss/mls.c. Some of related implementation are
changed, however, there is no incompatibility with the previous
version.
* The width of any new line are less or equal than 80-chars.
The following benchmark shows the effect of this patch, when we
access many files which have different security context one after
another. The number is more than /selinux/avc/cache_threshold, so
any access always causes AVC misses.
selinux-2.6 selinux-2.6-ebitmap
AVG: 22.763 [s] 8.750 [s]
STD: 0.265 0.019
------------------------------------------
1st: 22.558 [s] 8.786 [s]
2nd: 22.458 [s] 8.750 [s]
3rd: 22.478 [s] 8.754 [s]
4th: 22.724 [s] 8.745 [s]
5th: 22.918 [s] 8.748 [s]
6th: 22.905 [s] 8.764 [s]
7th: 23.238 [s] 8.726 [s]
8th: 22.822 [s] 8.729 [s]
Signed-off-by: KaiGai Kohei <kaigai@ak.jp.nec.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: James Morris <jmorris@namei.org>
2007-09-28 17:20:55 +00:00
|
|
|
index = (startbit - n->startbit) / EBITMAP_UNIT_SIZE;
|
|
|
|
while (map) {
|
2007-10-03 14:42:56 +00:00
|
|
|
n->maps[index++] = map & (-1UL);
|
|
|
|
map = EBITMAP_SHIFT_UNIT_SIZE(map);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
2024-03-15 17:28:44 +00:00
|
|
|
|
|
|
|
if (n && n->startbit + EBITMAP_SIZE != e->highbit) {
|
2024-03-27 19:25:57 +00:00
|
|
|
pr_err("SELinux: ebitmap: high bit %u is not equal to the expected value %zu\n",
|
2024-03-15 17:28:44 +00:00
|
|
|
e->highbit, n->startbit + EBITMAP_SIZE);
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
ok:
|
|
|
|
rc = 0;
|
|
|
|
out:
|
|
|
|
return rc;
|
|
|
|
bad:
|
|
|
|
if (!rc)
|
|
|
|
rc = -EINVAL;
|
|
|
|
ebitmap_destroy(e);
|
|
|
|
goto out;
|
|
|
|
}
|
2010-10-13 21:50:25 +00:00
|
|
|
|
2022-08-30 15:52:49 +00:00
|
|
|
int ebitmap_write(const struct ebitmap *e, void *fp)
|
2010-10-13 21:50:25 +00:00
|
|
|
{
|
|
|
|
struct ebitmap_node *n;
|
2024-03-15 17:32:28 +00:00
|
|
|
u32 bit, count, last_bit, last_startbit;
|
2010-10-13 21:50:25 +00:00
|
|
|
__le32 buf[3];
|
|
|
|
u64 map;
|
2024-03-15 17:32:28 +00:00
|
|
|
int rc;
|
2010-10-13 21:50:25 +00:00
|
|
|
|
|
|
|
buf[0] = cpu_to_le32(BITS_PER_U64);
|
|
|
|
|
|
|
|
count = 0;
|
|
|
|
last_bit = 0;
|
2024-03-15 17:32:28 +00:00
|
|
|
last_startbit = U32_MAX;
|
2024-02-22 23:52:27 +00:00
|
|
|
ebitmap_for_each_positive_bit(e, n, bit)
|
|
|
|
{
|
2024-03-15 17:32:28 +00:00
|
|
|
if (last_startbit == U32_MAX ||
|
|
|
|
rounddown(bit, BITS_PER_U64) > last_startbit) {
|
2010-10-13 21:50:25 +00:00
|
|
|
count++;
|
|
|
|
last_startbit = rounddown(bit, BITS_PER_U64);
|
|
|
|
}
|
|
|
|
last_bit = roundup(bit + 1, BITS_PER_U64);
|
|
|
|
}
|
|
|
|
buf[1] = cpu_to_le32(last_bit);
|
|
|
|
buf[2] = cpu_to_le32(count);
|
|
|
|
|
|
|
|
rc = put_entry(buf, sizeof(u32), 3, fp);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
map = 0;
|
2024-03-15 17:32:28 +00:00
|
|
|
last_startbit = U32_MAX;
|
2024-02-22 23:52:27 +00:00
|
|
|
ebitmap_for_each_positive_bit(e, n, bit)
|
|
|
|
{
|
2024-03-15 17:32:28 +00:00
|
|
|
if (last_startbit == U32_MAX ||
|
|
|
|
rounddown(bit, BITS_PER_U64) > last_startbit) {
|
2010-10-13 21:50:25 +00:00
|
|
|
__le64 buf64[1];
|
|
|
|
|
|
|
|
/* this is the very first bit */
|
|
|
|
if (!map) {
|
|
|
|
last_startbit = rounddown(bit, BITS_PER_U64);
|
|
|
|
map = (u64)1 << (bit - last_startbit);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* write the last node */
|
|
|
|
buf[0] = cpu_to_le32(last_startbit);
|
|
|
|
rc = put_entry(buf, sizeof(u32), 1, fp);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
buf64[0] = cpu_to_le64(map);
|
|
|
|
rc = put_entry(buf64, sizeof(u64), 1, fp);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
/* set up for the next node */
|
|
|
|
map = 0;
|
|
|
|
last_startbit = rounddown(bit, BITS_PER_U64);
|
|
|
|
}
|
|
|
|
map |= (u64)1 << (bit - last_startbit);
|
|
|
|
}
|
|
|
|
/* write the last node */
|
|
|
|
if (map) {
|
|
|
|
__le64 buf64[1];
|
|
|
|
|
|
|
|
/* write the last node */
|
|
|
|
buf[0] = cpu_to_le32(last_startbit);
|
|
|
|
rc = put_entry(buf, sizeof(u32), 1, fp);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
buf64[0] = cpu_to_le64(map);
|
|
|
|
rc = put_entry(buf64, sizeof(u64), 1, fp);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2017-06-08 04:18:09 +00:00
|
|
|
|
2020-04-17 08:11:56 +00:00
|
|
|
u32 ebitmap_hash(const struct ebitmap *e, u32 hash)
|
|
|
|
{
|
|
|
|
struct ebitmap_node *node;
|
|
|
|
|
|
|
|
/* need to change hash even if ebitmap is empty */
|
|
|
|
hash = jhash_1word(e->highbit, hash);
|
|
|
|
for (node = e->node; node; node = node->next) {
|
|
|
|
hash = jhash_1word(node->startbit, hash);
|
|
|
|
hash = jhash(node->maps, sizeof(node->maps), hash);
|
|
|
|
}
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
|
2018-03-01 23:48:02 +00:00
|
|
|
void __init ebitmap_cache_init(void)
|
2017-06-08 04:18:09 +00:00
|
|
|
{
|
|
|
|
ebitmap_node_cachep = kmem_cache_create("ebitmap_node",
|
2024-02-22 23:52:27 +00:00
|
|
|
sizeof(struct ebitmap_node), 0,
|
|
|
|
SLAB_PANIC, NULL);
|
2017-06-08 04:18:09 +00:00
|
|
|
}
|