Re: [TOMOYO 05/15](repost) Domain transition handler functions.

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Tetsuo Handa
Date: Tuesday, October 2, 2007 - 5:44 am

Hello.

Thank you for your comment.

James Morris wrote:

I don't need to use spinlocks here.
What I need to do here is avoid read/write reordering,
so mb() will be appropriate here.

struct something {
  struct something *next;
  void *data;
};

struct something *prev_ptr = ...;
struct something *new_ptr = kmalloc(sizeof(*new_ptr), GFP_KERNEL);
new_ptr->next = NULL;
new_ptr->data = some_value;
mb();
prev_ptr->next = new_ptr;

TOMOYO Linux doesn't use locks for reading singly-linked list.
Thus, new_ptr->data has to be made visible to other CPUs
before new_ptr is appended at the tail of singly-linked list.
Otherwise, other CPU may read undefined new_ptr->data values.

Performance is not critical because this mb() is called
only when appending new entry to the singly-linked list.


Since new_ptr never be removed, new_ptr needn't to know
it's previous element's address, thus having only ->next pointer is enough.
new_ptr->next is assigned *only once*
(initialized with NULL, and assigned non-NULL later),
indicating "if ptr->next == NULL, ptr is the last element" and
"if ptr->next != NULL, ptr is not the last element".

If I use "struct hlist_node" which has two pointers,
it needs more memory than "struct something" which has one pointer.
It is possible to use API defined in include/linux/list.h ,
but to reduce memory usage, I dare not use these API.
Singly-linked list's rule in TOMOYO Linux is quite simple,
"ptr->next is NULL if the last element" and "non-NULL if not".

Regards.

-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[TOMOYO 06/15](repost) Auditing interface., Kentaro Takeda, (Tue Oct 2, 12:33 am)
[TOMOYO 07/15](repost) File access control functions., Kentaro Takeda, (Tue Oct 2, 12:34 am)
[TOMOYO 08/15](repost) Argv[0] access control functions., Kentaro Takeda, (Tue Oct 2, 12:35 am)
[TOMOYO 12/15](repost) LSM adapter for TOMOYO., Kentaro Takeda, (Tue Oct 2, 12:38 am)
[TOMOYO 13/15](repost) Conditional permission support., Kentaro Takeda, (Tue Oct 2, 12:39 am)
[TOMOYO 14/15](repost) LSM expansion for TOMOYO Linux., Kentaro Takeda, (Tue Oct 2, 12:39 am)
Re: [TOMOYO 05/15](repost) Domain transition handler funct ..., Tetsuo Handa, (Tue Oct 2, 5:44 am)
Re: [TOMOYO 05/15](repost) Domain transition handler funct ..., YOSHIFUJI Hideaki / , (Tue Oct 2, 6:00 am)
Re: [TOMOYO 05/15](repost) Domain transition handler funct ..., YOSHIFUJI Hideaki / , (Wed Oct 3, 4:43 am)
Re: [TOMOYO 05/15](repost) Domain transition handler funct ..., YOSHIFUJI Hideaki / , (Wed Oct 3, 6:11 am)
Re: [TOMOYO 05/15](repost) Domain transition handler funct ..., YOSHIFUJI Hideaki / , (Wed Oct 3, 7:32 am)
Sleeping in RCU list traversal, Tetsuo Handa, (Sun Oct 7, 3:38 am)