diff mbox series

[v4,1/7] landlock: Optimize the number of calls to get_access_mask slightly

Message ID 20231103155717.78042-2-gnoack@google.com (mailing list archive)
State Handled Elsewhere
Headers show
Series Landlock: IOCTL support | expand

Commit Message

Günther Noack Nov. 3, 2023, 3:57 p.m. UTC
This call is now going through a function pointer,
and it is not as obvious any more that it will be inlined.

Signed-off-by: Günther Noack <gnoack@google.com>
---
 security/landlock/ruleset.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Mickaël Salaün Nov. 16, 2023, 9:49 p.m. UTC | #1
On Fri, Nov 03, 2023 at 04:57:11PM +0100, Günther Noack wrote:
> This call is now going through a function pointer,
> and it is not as obvious any more that it will be inlined.
> 
> Signed-off-by: Günther Noack <gnoack@google.com>
> ---
>  security/landlock/ruleset.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/security/landlock/ruleset.c b/security/landlock/ruleset.c
> index ffedc99f2b68..fd348633281c 100644
> --- a/security/landlock/ruleset.c
> +++ b/security/landlock/ruleset.c
> @@ -724,10 +724,11 @@ landlock_init_layer_masks(const struct landlock_ruleset *const domain,
>  	for (layer_level = 0; layer_level < domain->num_layers; layer_level++) {
>  		const unsigned long access_req = access_request;
>  		unsigned long access_bit;
> +		access_mask_t access_mask =

You can make it const and move it below the other const.

> +			get_access_mask(domain, layer_level);
>  
>  		for_each_set_bit(access_bit, &access_req, num_access) {
> -			if (BIT_ULL(access_bit) &
> -			    get_access_mask(domain, layer_level)) {
> +			if (BIT_ULL(access_bit) & access_mask) {
>  				(*layer_masks)[access_bit] |=
>  					BIT_ULL(layer_level);
>  				handled_accesses |= BIT_ULL(access_bit);
> -- 
> 2.42.0.869.gea05f2083d-goog
>
Günther Noack Nov. 17, 2023, 10:54 a.m. UTC | #2
On Thu, Nov 16, 2023 at 04:49:46PM -0500, Micka�l Sala�n wrote:
> On Fri, Nov 03, 2023 at 04:57:11PM +0100, G�nther Noack wrote:
> > This call is now going through a function pointer,
> > and it is not as obvious any more that it will be inlined.
> > 
> > Signed-off-by: G�nther Noack <gnoack@google.com>
> > ---
> >  security/landlock/ruleset.c | 5 +++--
> >  1 file changed, 3 insertions(+), 2 deletions(-)
> > 
> > diff --git a/security/landlock/ruleset.c b/security/landlock/ruleset.c
> > index ffedc99f2b68..fd348633281c 100644
> > --- a/security/landlock/ruleset.c
> > +++ b/security/landlock/ruleset.c
> > @@ -724,10 +724,11 @@ landlock_init_layer_masks(const struct landlock_ruleset *const domain,
> >  	for (layer_level = 0; layer_level < domain->num_layers; layer_level++) {
> >  		const unsigned long access_req = access_request;
> >  		unsigned long access_bit;
> > +		access_mask_t access_mask =
> 
> You can make it const and move it below the other const.

Done.

> > +			get_access_mask(domain, layer_level);
> >  
> >  		for_each_set_bit(access_bit, &access_req, num_access) {
> > -			if (BIT_ULL(access_bit) &
> > -			    get_access_mask(domain, layer_level)) {
> > +			if (BIT_ULL(access_bit) & access_mask) {
> >  				(*layer_masks)[access_bit] |=
> >  					BIT_ULL(layer_level);
> >  				handled_accesses |= BIT_ULL(access_bit);
> > -- 
> > 2.42.0.869.gea05f2083d-goog
> >
diff mbox series

Patch

diff --git a/security/landlock/ruleset.c b/security/landlock/ruleset.c
index ffedc99f2b68..fd348633281c 100644
--- a/security/landlock/ruleset.c
+++ b/security/landlock/ruleset.c
@@ -724,10 +724,11 @@  landlock_init_layer_masks(const struct landlock_ruleset *const domain,
 	for (layer_level = 0; layer_level < domain->num_layers; layer_level++) {
 		const unsigned long access_req = access_request;
 		unsigned long access_bit;
+		access_mask_t access_mask =
+			get_access_mask(domain, layer_level);
 
 		for_each_set_bit(access_bit, &access_req, num_access) {
-			if (BIT_ULL(access_bit) &
-			    get_access_mask(domain, layer_level)) {
+			if (BIT_ULL(access_bit) & access_mask) {
 				(*layer_masks)[access_bit] |=
 					BIT_ULL(layer_level);
 				handled_accesses |= BIT_ULL(access_bit);