public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2/2] devscgroup: relax task to dev_cgroup conversion
@ 2008-06-04  7:39 Pavel Emelyanov
  2008-06-04  9:20 ` Paul Menage
  0 siblings, 1 reply; 3+ messages in thread
From: Pavel Emelyanov @ 2008-06-04  7:39 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Serge Hallyn, Paul Menage, Linux Kernel Mailing List

Two functions, that need to get a device_cgroup from a task (they
are devcgroup_inode_permission and devcgroup_inode_mknod) make it
in a strange way:

They get a css_set from task, then a subsys_state from css_set,
then a cgroup from the state and then a subsys_state again from
the cgroup. Besides, the devices_subsys_id is read from memory,
whilst there's a enum-ed constant for it.

Optimize this part a bit:
1. Get the subsys_stats form the task and be done - no 2 extra
   dereferences,
2. Use the device_subsys_id constant, not the value from memory
   (i.e. one less dereference).

Found while preparing 2.6.26 OpenVZ port.

Signed-off-by: Pavel Emelyanov <xemul@openvz.org>

---
 security/device_cgroup.c |   10 ++++------
 1 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/security/device_cgroup.c b/security/device_cgroup.c
index 15f2f80..f9941a7 100644
--- a/security/device_cgroup.c
+++ b/security/device_cgroup.c
@@ -506,7 +506,6 @@ struct cgroup_subsys devices_subsys = {
 
 int devcgroup_inode_permission(struct inode *inode, int mask)
 {
-	struct cgroup *cgroup;
 	struct dev_cgroup *dev_cgroup;
 	struct dev_whitelist_item *wh;
 
@@ -515,8 +514,8 @@ int devcgroup_inode_permission(struct inode *inode, int mask)
 		return 0;
 	if (!S_ISBLK(inode->i_mode) && !S_ISCHR(inode->i_mode))
 		return 0;
-	cgroup = task_cgroup(current, devices_subsys.subsys_id);
-	dev_cgroup = cgroup_to_devcgroup(cgroup);
+	dev_cgroup = css_to_devcgroup(task_subsys_state(current,
+				devices_subsys_id));
 	if (!dev_cgroup)
 		return 0;
 
@@ -547,12 +546,11 @@ acc_check:
 
 int devcgroup_inode_mknod(int mode, dev_t dev)
 {
-	struct cgroup *cgroup;
 	struct dev_cgroup *dev_cgroup;
 	struct dev_whitelist_item *wh;
 
-	cgroup = task_cgroup(current, devices_subsys.subsys_id);
-	dev_cgroup = cgroup_to_devcgroup(cgroup);
+	dev_cgroup = css_to_devcgroup(task_subsys_state(current,
+				devices_subsys_id));
 	if (!dev_cgroup)
 		return 0;
 
-- 
1.5.3.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 2/2] devscgroup: relax task to dev_cgroup conversion
  2008-06-04  7:39 [PATCH 2/2] devscgroup: relax task to dev_cgroup conversion Pavel Emelyanov
@ 2008-06-04  9:20 ` Paul Menage
  2008-06-04  9:23   ` Pavel Emelyanov
  0 siblings, 1 reply; 3+ messages in thread
From: Paul Menage @ 2008-06-04  9:20 UTC (permalink / raw)
  To: Pavel Emelyanov; +Cc: Andrew Morton, Serge Hallyn, Linux Kernel Mailing List

On Wed, Jun 4, 2008 at 12:39 AM, Pavel Emelyanov <xemul@openvz.org> wrote:
> Two functions, that need to get a device_cgroup from a task (they
> are devcgroup_inode_permission and devcgroup_inode_mknod) make it
> in a strange way:
>
> They get a css_set from task, then a subsys_state from css_set,
> then a cgroup from the state and then a subsys_state again from
> the cgroup. Besides, the devices_subsys_id is read from memory,
> whilst there's a enum-ed constant for it.
>
> Optimize this part a bit:
> 1. Get the subsys_stats form the task and be done - no 2 extra
>   dereferences,
> 2. Use the device_subsys_id constant, not the value from memory
>   (i.e. one less dereference).
>
> Found while preparing 2.6.26 OpenVZ port.
>
> Signed-off-by: Pavel Emelyanov <xemul@openvz.org>

Acked-by: Paul Menage <menage@google.com>

Yes, that's more how the css_set pointers are meant to be used. Maybe
improve it further by extracting a task_to_devcgroup() inline
function?

Paul

>
> ---
>  security/device_cgroup.c |   10 ++++------
>  1 files changed, 4 insertions(+), 6 deletions(-)
>
> diff --git a/security/device_cgroup.c b/security/device_cgroup.c
> index 15f2f80..f9941a7 100644
> --- a/security/device_cgroup.c
> +++ b/security/device_cgroup.c
> @@ -506,7 +506,6 @@ struct cgroup_subsys devices_subsys = {
>
>  int devcgroup_inode_permission(struct inode *inode, int mask)
>  {
> -       struct cgroup *cgroup;
>        struct dev_cgroup *dev_cgroup;
>        struct dev_whitelist_item *wh;
>
> @@ -515,8 +514,8 @@ int devcgroup_inode_permission(struct inode *inode, int mask)
>                return 0;
>        if (!S_ISBLK(inode->i_mode) && !S_ISCHR(inode->i_mode))
>                return 0;
> -       cgroup = task_cgroup(current, devices_subsys.subsys_id);
> -       dev_cgroup = cgroup_to_devcgroup(cgroup);
> +       dev_cgroup = css_to_devcgroup(task_subsys_state(current,
> +                               devices_subsys_id));
>        if (!dev_cgroup)
>                return 0;
>
> @@ -547,12 +546,11 @@ acc_check:
>
>  int devcgroup_inode_mknod(int mode, dev_t dev)
>  {
> -       struct cgroup *cgroup;
>        struct dev_cgroup *dev_cgroup;
>        struct dev_whitelist_item *wh;
>
> -       cgroup = task_cgroup(current, devices_subsys.subsys_id);
> -       dev_cgroup = cgroup_to_devcgroup(cgroup);
> +       dev_cgroup = css_to_devcgroup(task_subsys_state(current,
> +                               devices_subsys_id));
>        if (!dev_cgroup)
>                return 0;
>
> --
> 1.5.3.4
>
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 2/2] devscgroup: relax task to dev_cgroup conversion
  2008-06-04  9:20 ` Paul Menage
@ 2008-06-04  9:23   ` Pavel Emelyanov
  0 siblings, 0 replies; 3+ messages in thread
From: Pavel Emelyanov @ 2008-06-04  9:23 UTC (permalink / raw)
  To: Paul Menage; +Cc: Andrew Morton, Serge Hallyn, Linux Kernel Mailing List

Paul Menage wrote:
> On Wed, Jun 4, 2008 at 12:39 AM, Pavel Emelyanov <xemul@openvz.org> wrote:
>> Two functions, that need to get a device_cgroup from a task (they
>> are devcgroup_inode_permission and devcgroup_inode_mknod) make it
>> in a strange way:
>>
>> They get a css_set from task, then a subsys_state from css_set,
>> then a cgroup from the state and then a subsys_state again from
>> the cgroup. Besides, the devices_subsys_id is read from memory,
>> whilst there's a enum-ed constant for it.
>>
>> Optimize this part a bit:
>> 1. Get the subsys_stats form the task and be done - no 2 extra
>>   dereferences,
>> 2. Use the device_subsys_id constant, not the value from memory
>>   (i.e. one less dereference).
>>
>> Found while preparing 2.6.26 OpenVZ port.
>>
>> Signed-off-by: Pavel Emelyanov <xemul@openvz.org>
> 
> Acked-by: Paul Menage <menage@google.com>
> 
> Yes, that's more how the css_set pointers are meant to be used. Maybe
> improve it further by extracting a task_to_devcgroup() inline
> function?

Well... Maybe. I'll make a 3rd patch a bit later. 
I'm now testing RCU-protected whitelists.

> Paul
> 
>> ---
>>  security/device_cgroup.c |   10 ++++------
>>  1 files changed, 4 insertions(+), 6 deletions(-)
>>
>> diff --git a/security/device_cgroup.c b/security/device_cgroup.c
>> index 15f2f80..f9941a7 100644
>> --- a/security/device_cgroup.c
>> +++ b/security/device_cgroup.c
>> @@ -506,7 +506,6 @@ struct cgroup_subsys devices_subsys = {
>>
>>  int devcgroup_inode_permission(struct inode *inode, int mask)
>>  {
>> -       struct cgroup *cgroup;
>>        struct dev_cgroup *dev_cgroup;
>>        struct dev_whitelist_item *wh;
>>
>> @@ -515,8 +514,8 @@ int devcgroup_inode_permission(struct inode *inode, int mask)
>>                return 0;
>>        if (!S_ISBLK(inode->i_mode) && !S_ISCHR(inode->i_mode))
>>                return 0;
>> -       cgroup = task_cgroup(current, devices_subsys.subsys_id);
>> -       dev_cgroup = cgroup_to_devcgroup(cgroup);
>> +       dev_cgroup = css_to_devcgroup(task_subsys_state(current,
>> +                               devices_subsys_id));
>>        if (!dev_cgroup)
>>                return 0;
>>
>> @@ -547,12 +546,11 @@ acc_check:
>>
>>  int devcgroup_inode_mknod(int mode, dev_t dev)
>>  {
>> -       struct cgroup *cgroup;
>>        struct dev_cgroup *dev_cgroup;
>>        struct dev_whitelist_item *wh;
>>
>> -       cgroup = task_cgroup(current, devices_subsys.subsys_id);
>> -       dev_cgroup = cgroup_to_devcgroup(cgroup);
>> +       dev_cgroup = css_to_devcgroup(task_subsys_state(current,
>> +                               devices_subsys_id));
>>        if (!dev_cgroup)
>>                return 0;
>>
>> --
>> 1.5.3.4
>>
>>
> 


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-06-04  9:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-04  7:39 [PATCH 2/2] devscgroup: relax task to dev_cgroup conversion Pavel Emelyanov
2008-06-04  9:20 ` Paul Menage
2008-06-04  9:23   ` Pavel Emelyanov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox