Skip to contentSkip to conversation

Moorestown RAR Handler driver, MRST 2.6.31-rc3

PATCH In review Ossama Othman 5 participants 9 messages Jul 31, 2009 – Aug 8, 2009 Char and misc drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Moorestown RAR Handler driver, MRST 2.6.31-rc3

This driver implements an allocator interface for Moorestown restricted access regions (RAR), which are regions of RAM that are inaccessible by the CPU when locked down. It is implemented in the kernel space since both user space applications and kernel drivers will be allocating buffers in Moorestown RARs.

The canonical kernel allocators (slab, etc) are not used since they are too tightly coupled with paging. The CPU will not be accessing the memory, meaning an allocation mechanism that does not place metadata in the RAR memory area in question was needed. The simple allocator included in this patch satisfies my needs. However, I was recently made aware of the existence of the lib/genalloc.c allocator. It appears promising in terms of the RAR handler driver needs, so I may use it instead.

Work is still ongoing with this driver so I appreciate any constructive feedback regarding the implementation, particularly with respect to the allocator (or alternatives) since it is a critical part of the functionality. Thanks!!

Note this driver depends on the (previously submitted) Moorestown rar_register driver (RAR_REGISTER).

---
 drivers/misc/Kconfig            |   12 +
 drivers/misc/Makefile           |    2 +
 drivers/misc/memrar_allocator.c |  337 ++++++++++++++++++++
 drivers/misc/memrar_allocator.h |  162 ++++++++++
 drivers/misc/memrar_handler.c   |  669 +++++++++++++++++++++++++++++++++++++++
 include/linux/rar/memrar.h      |  172 ++++++++++
 kernel-mrst-alpha2.config       |    8 +-
 7 files changed, 1361 insertions(+), 1 deletions(-)
 create mode 100644 drivers/misc/memrar_allocator.c
 create mode 100644 drivers/misc/memrar_allocator.h
 create mode 100644 drivers/misc/memrar_handler.c
 create mode 100644 include/linux/rar/memrar.h
drivers/misc/Kconfig +12 -0
index b9e5010..3e36269 100644
@@ -150,6 +150,18 @@ config ATMEL_SSC
 
 	  If unsure, say N.
 
+config MRST_RAR_HANDLER
+	tristate "RAR handler driver for Intel Moorestown platform"
+	depends on X86
+	select RAR_REGISTER
+	default n
+	---help---
+	  This driver provides a memory management interface to
+	  restricted access regions available in the Intel Moorestown
+	  platform.
+
+	  If unsure, say N.
+
 config MRST_VIB
 	tristate "vibrator driver for Intel Moorestown platform"
 	help
drivers/misc/Makefile +2 -0
index 0238835..a69bc26 100644
@@ -14,6 +14,8 @@ obj-$(CONFIG_TIFM_7XX1)       	+= tifm_7xx1.o
 obj-$(CONFIG_PHANTOM)		+= phantom.o
 obj-$(CONFIG_SGI_IOC4)		+= ioc4.o
 obj-$(CONFIG_MSTWN_POWER_MGMT)	+= moorestown/
+obj-$(CONFIG_MRST_RAR_HANDLER)	+= memrar.o
+memrar-objs			:= memrar_allocator.o memrar_handler.o
 obj-$(CONFIG_MRST_VIB)		+= mrst_vib.o
 obj-$(CONFIG_ENCLOSURE_SERVICES) += enclosure.o
 obj-$(CONFIG_KGDB_TESTS)	+= kgdbts.o
drivers/misc/memrar_allocator.c new file +337 -0

337 lines not on this page · raw message

drivers/misc/memrar_allocator.h new file +162 -0

162 lines not on this page · raw message

drivers/misc/memrar_handler.c new file +669 -0

669 lines not on this page · raw message

include/linux/rar/memrar.h new file +172 -0

172 lines not on this page · raw message

kernel-mrst-alpha2.config +7 -1
index 1f73364..8fb9626 100644
@@ -1,7 +1,7 @@
 #
 # Automatically generated make config: don't edit
 # Linux kernel version: 2.6.31-rc1
-# Wed Jul 22 08:39:33 2009
+# Wed Jul 29 02:59:24 2009
 #
 # CONFIG_64BIT is not set
 CONFIG_X86_32=y
@@ -832,6 +832,7 @@ CONFIG_MISC_DEVICES=y
 CONFIG_TIFM_CORE=m
 # CONFIG_TIFM_7XX1 is not set
 # CONFIG_ICS932S401 is not set
+CONFIG_MRST_RAR_HANDLER=y
 CONFIG_MRST_VIB=y
 # CONFIG_ENCLOSURE_SERVICES is not set
 # CONFIG_HP_ILO is not set
@@ -2489,6 +2490,11 @@ CONFIG_LINE6_USB=m
 CONFIG_X86_PLATFORM_DEVICES=y
 
 #
+# RAR Register Driver
+#
+CONFIG_RAR_REGISTER=y
+
+#
 # Firmware Drivers
 #
 # CONFIG_EDD is not set
Signature · 1 line
1.6.0.4
#1 lore raw
Quoted 6 lines
drivers/misc/Kconfig +0 -0
index b9e5010..3e36269 100644

drivers/misc/Kconfig config ATMEL_SSC · line 157

Quoted 8 lines
drivers/misc/Kconfig +5 -0
@@ -150,6 +150,18 @@ config ATMEL_SSC
 
 	  If unsure, say N.
 
+config MRST_RAR_HANDLER
+	tristate "RAR handler driver for Intel Moorestown platform"
+	depends on X86
+	select RAR_REGISTER
+	default n

n is default - so no need to spell it out.

Quoted 15 lines
drivers/misc/Kconfig +7 -0
+	---help---
+	  This driver provides a memory management interface to
+	  restricted access regions available in the Intel Moorestown
+	  platform.
+
+	  If unsure, say N.
+
 config MRST_VIB
 	tristate "vibrator driver for Intel Moorestown platform"
 	help
drivers/misc/Makefile +0 -0
index 0238835..a69bc26 100644

drivers/misc/Makefile obj-$(CONFIG_TIFM_7XX1) += tifm_7xx1.o · line 18

Quoted 5 lines
drivers/misc/Makefile +2 -0
@@ -14,6 +14,8 @@ obj-$(CONFIG_TIFM_7XX1)       	+= tifm_7xx1.o
 obj-$(CONFIG_PHANTOM)		+= phantom.o
 obj-$(CONFIG_SGI_IOC4)		+= ioc4.o
 obj-$(CONFIG_MSTWN_POWER_MGMT)	+= moorestown/
+obj-$(CONFIG_MRST_RAR_HANDLER)	+= memrar.o
+memrar-objs			:= memrar_allocator.o memrar_handler.o

Please use:
+ memrar-y := memrar_allocator.o memrar_handler.o

The foo-objs syntax is deprecated.

drivers/misc/Makefile obj-$(CONFIG_TIFM_7XX1) += tifm_7xx1.o

Quoted 5 lines
drivers/misc/Makefile +5 -0
+
+
+#include "memrar_allocator.h"
+#include <linux/slab.h>
+#include <linux/bug.h>

<linux/...> comes _before_ you own includes.
And an empty line in between.

drivers/misc/Makefile

Quoted 7 lines
drivers/misc/Makefile +7 -0
+
+
+struct memrar_allocator *memrar_create_allocator(unsigned long base,
+						 size_t capacity,
+						 size_t block_size)
+{
+	struct memrar_allocator *allocator = 0;

It is recommended to separate definition,
and assignment.
So this should look like this:

	struct memrar_allocator *allocator;

	allocator = 0;

drivers/misc/Makefile

Quoted 11 lines
drivers/misc/Makefile +11 -0
+
+	/* Validate parameters. */
+	if (/*
+	     * Make sure we can allocate the entire memory allocator
+	     * space.
+	     */
+		ULONG_MAX - capacity >= base
+
+		/* Zero capacity or block size are obviously invalid. */
+		&& capacity != 0
+		&& block_size != 0) {

Very ugly way to comment your if (..) IMHO
Put the comment abvoe the if.

drivers/misc/Makefile

Quoted 8 lines
drivers/misc/Makefile +8 -0
+		/*
+		 * There isn't much point in creating a memory
+		 * allocator that is only capable of holding one block
+		 * but we'll allow, and issue a diagnostic.
+		 */
+		WARN(capacity < block_size * 2,
+		     "Memory allocator is only large enough to "
+		     "hold one block.\n");

Try to avoid breaking your printable line.
It is much easier to grep for the line when it is on a sinlge line.
If you violate the 80 chars per line rule do to this then accept that grepable lines is better than keeping them 80 or less wide.

This comment applies in several places.

drivers/misc/Makefile

Quoted 4 lines
drivers/misc/Makefile +4 -0
+			INIT_LIST_HEAD(&allocator->free_list.list);
+
+			first_node =
+				kmalloc(sizeof(*first_node), GFP_KERNEL);

No need to break up this line.

Quoted 6 lines
drivers/misc/Makefile +6 -0
+			if (first_node != 0) {
+				/* Full range of blocks is available. */
+				first_node->begin = base;
+				first_node->end =
+					base + allocator->capacity;
+				list_add(&first_node->list,

drivers/misc/Makefile

Quoted 10 lines
drivers/misc/Makefile +10 -0
+					 &allocator->free_list.list);
+			} else {
+				kfree(allocator);
+				allocator = 0;
+			}
+		}
+	}
+
+	return allocator;
+}

I'm short on time - so this is the comments for today...

Sam

#2 lore raw
Quoted 5 lines · Sam Ravnborg

drivers/misc/memrar_allocator.c line 40

Quoted 3 lines
drivers/misc/memrar_allocator.c new file +3 -0
+#include "memrar_allocator.h"
+#include <linux/slab.h>
+#include <linux/bug.h>

<linux/...> comes _before_ you own includes.

The use of pr_fmt might change this guideline.

Quoted 9 lines

drivers/misc/memrar_allocator.c line 66

Quoted 3 lines
drivers/misc/memrar_allocator.c new file +3 -0
+		WARN(capacity < block_size * 2,
+		     "Memory allocator is only large enough to "
+		     "hold one block.\n");

Try to avoid breaking your printable line.
It is much easier to grep for the line when it is on a single line.
If you violate the 80 chars per line rule do to this then accept that grepable lines is better than keeping them 80 or less wide.

Maybe it's better to ignore the indent guideline here as well. An outdent might be preferable to having the line exceed 80 chars.

Maybe:

		WARN(capacity < block_size * 2,
	"Memory allocator is only large enough to hold one block.\n");

or
WARN(capacity < block_size * 2,
"Memory allocator is only large enough to hold one block.\n");

Any format string longer than 80 chars is likely a poor log entry.

#3 lore raw

Hi Joe,

Quoted 10 lines · Sam Ravnborg
Quoted 5 lines

Try to avoid breaking your printable line.
It is much easier to grep for the line when it is on a single line.
If you violate the 80 chars per line rule do to this then accept that grepable lines is better than keeping them 80 or less wide.

Maybe it's better to ignore the indent guideline here as well. An outdent might be preferable to having the line exceed 80 chars.

Quoted 6 lines

Maybe:

		WARN(capacity < block_size * 2,
	"Memory allocator is only large enough to hold one block.\n");

or
WARN(capacity < block_size * 2,
"Memory allocator is only large enough to hold one block.\n");

Okay, I'll see what I can do improve the readability and grep-ability of these log messages.

Quoted 1 line

Any format string longer than 80 chars is likely a poor log entry.

Agreed!

Thanks Joe!
-Ossama

#4 lore raw
In reply to Sam Ravnborg

Hi Sam,

Quoted 4 lines

Please use:
+ memrar-y := memrar_allocator.o memrar_handler.o

The foo-objs syntax is deprecated.

Thanks! I'll make that change.

The file `Documentation/kbuild/makefiles.txt' doesn't mention the deprecation, AFAICT. Can you tell me where it is documented?

Quoted 8 lines

drivers/misc/memrar_allocator.c line 40

Quoted 5 lines
drivers/misc/memrar_allocator.c new file +5 -0
+
+
+#include "memrar_allocator.h"
+#include <linux/slab.h>
+#include <linux/bug.h>

<linux/...> comes _before_ you own includes.
And an empty line in between.

Will do!

This guideline doesn't appear in Documentation/CodingStyle. Should it?

Quoted 12 lines

drivers/misc/memrar_allocator.c line 47

Quoted 7 lines
drivers/misc/memrar_allocator.c new file +7 -0
+
+
+struct memrar_allocator *memrar_create_allocator(unsigned long base,
+						 size_t capacity,
+						 size_t block_size)
+{
+	struct memrar_allocator *allocator = 0;

It is recommended to separate definition,
and assignment.
So this should look like this:

Quoted 3 lines
	struct memrar_allocator *allocator;

	allocator = 0;

Okay, I'll fix that, too. Should this go into Documentation/CodingStyle, too?

Quoted 6 lines
Quoted 6 lines
drivers/misc/memrar_allocator.c new file +6 -0
+
+	/* Validate parameters. */
+	if (/*
+	     * Make sure we can allocate the entire memory allocator
+	     * space.
+	     */
Quoted 8 lines

drivers/misc/memrar_allocator.c line 58

Quoted 5 lines
drivers/misc/memrar_allocator.c new file +5 -0
+		ULONG_MAX - capacity >= base
+
+		/* Zero capacity or block size are obviously invalid. */
+		&& capacity != 0
+		&& block_size != 0) {

Very ugly way to comment your if (..) IMHO
Put the comment abvoe the if.

You're not the only that has mentioned that :). I'll fix this in the next revision, as well.

Quoted 1 line

I'm short on time - so this is the comments for today...

Thanks a lot for the feedback, Sam! I'll address all of your comments in the next revision!

-Ossama

#5 lore raw
Quoted 6 lines · Ossama
Quoted 5 lines

It is recommended to separate definition,
and assignment.
So this should look like this:

	struct memrar_allocator *allocator;
	allocator = 0;

Okay, I'll fix that, too. Should this go into Documentation/CodingStyle, too?

I don't agree with that at all, neither does a lot of the kernel source.

Automatic structs with initializers:

$ grep -rP --include=*.c "^\s+struct\s+\w+\s*\*\s*\w+\s*=\s*\w+\s*;" * | wc -l
9498

I think it should be struct memrar_allocator *allocator = NULL;

#6 lore raw
Quoted 8 lines
Quoted 6 lines
Quoted 5 lines

It is recommended to separate definition,
and assignment.
So this should look like this:

	struct memrar_allocator *allocator;
	allocator = 0;

Okay, I'll fix that, too. Should this go into Documentation/CodingStyle,

too?

Quoted 8 lines

I don't agree with that at all, neither does a lot of the kernel source.

Automatic structs with initializers:

$ grep -rP --include=*.c "^\s+struct\s+\w+\s*\*\s*\w+\s*=\s*\w+\s*;" * | wc
-l
9498

I think it should be struct memrar_allocator *allocator = NULL;

Got it. I've already started changing all zero pointer initializations to NULL instead. I'll also leave the declaration and initialization on the same line for now.

Thanks again!
-Ossama

#7 lore raw
In reply to Othman, Ossama
Quoted 1 line

This guideline doesn't appear in Documentation/CodingStyle. Should it?

Possibly - the thing is there are several cases where its used deliberately the other way around.

Quoted 11 lines
Quoted 9 lines
Quoted 1 line

Review

Quoted 1 line
(quoted diff) +1 -0
+	struct memrar_allocator *allocator = 0;

It is recommended to separate definition,
and assignment.
So this should look like this:

	struct memrar_allocator *allocator;

	allocator = 0;

Okay, I'll fix that, too. Should this go into Documentation/CodingStyle, too?

This is nonsense to put it politely. It's a pointer so it should be = NULL but the formatting is just fine. It's not in the coding style because its bunkum 8)

Alan

#8 lore raw
In reply to Ossama Othman

Hi!

Quoted 5 lines

This driver implements an allocator interface for Moorestown restricted access regions (RAR), which are regions of RAM that are inaccessible by the CPU when locked down. It is implemented in the kernel space since both user space applications and kernel drivers will be allocating buffers in Moorestown RARs.

How will userland applications use memory that's not even accessible to CPU? This is rather new user/kernel API so a documentation would be nice.

kernel-mrst-alpha2.config line 5

Quoted 10 lines

index 1f73364..8fb9626 100644

kernel-mrst-alpha2.config +1 -1
@@ -1,7 +1,7 @@
 #
 # Automatically generated make config: don't edit
 # Linux kernel version: 2.6.31-rc1
-# Wed Jul 22 08:39:33 2009
+# Wed Jul 29 02:59:24 2009
 #

Stray diff? This file is unlikely to be in kernel.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html