[ofw] [Patch 13/62] Reference implementation of NDv2
Fab Tillier
ftillier at microsoft.com
Wed Feb 20 17:27:39 PST 2013
Use KPROCESSOR_MODE when registering memory.
Signed-off-by: Fab Tillier <ftillier at microsoft.com>
diff -dwup3 -x *svn* -r c:\dev\openib\ofw\gen1\branches\mlx4_30\trunk\hw\mlx4\kernel\bus\core\iobuf.c .\hw\mlx4\kernel\bus\core\iobuf.c
--- c:\dev\openib\ofw\gen1\branches\mlx4_30\trunk\hw\mlx4\kernel\bus\core\iobuf.c Thu May 31 11:22:18 2012
+++ .\hw\mlx4\kernel\bus\core\iobuf.c Wed May 23 18:26:47 2012
@@ -142,20 +142,19 @@ typedef struct _iobuf_seg {
u64 va; /* virtual address of the buffer */
u64 size; /* size in bytes of the buffer */
u32 nr_pages;
- int is_user;
+
} iobuf_seg_t;
// Returns: 0 on success, -ENOMEM or -EACCESS on error
static int register_segment(
IN u64 va,
IN u64 size,
- IN int is_user,
+ IN KPROCESSOR_MODE mode,
IN enum ib_access_flags acc,
OUT iobuf_seg_t **iobuf_seg)
{
PMDL mdl_p;
int rc;
- KPROCESSOR_MODE mode;
iobuf_seg_t * new_iobuf;
static ULONG cnt=0;
LOCK_OPERATION Operation;
@@ -181,13 +180,8 @@ static int register_segment(
}
// make context-dependent things
- if (is_user) {
+ if (mode == UserMode) {
ASSERT(KeGetCurrentIrql() < DISPATCH_LEVEL);
- mode = UserMode;
- }
- else { /* Mapping to kernel virtual address */
- // MmBuildMdlForNonPagedPool(mdl_p); // fill MDL ??? - should we do that really ?
- mode = KernelMode;
}
__try { /* try */
@@ -196,7 +190,7 @@ static int register_segment(
__except (EXCEPTION_EXECUTE_HANDLER) {
MLX4_PRINT(TRACE_LEVEL_ERROR, MLX4_DBG_MEMORY,
- ("MOSAL_iobuf_register: Exception 0x%x on MmProbeAndLockPages(), va %I64d, sz %I64d\n",
+ ("register_segment: Exception 0x%x on MmProbeAndLockPages(), va %I64d, sz %I64d\n",
GetExceptionCode(), va, size));
rc = -EACCES;
goto err_probe;
@@ -207,7 +201,6 @@ static int register_segment(
new_iobuf->size= size;
new_iobuf->nr_pages = ADDRESS_AND_SIZE_TO_SPAN_PAGES( va, size );
new_iobuf->mdl_p = mdl_p;
- new_iobuf->is_user = is_user;
*iobuf_seg = new_iobuf;
return 0;
@@ -222,12 +215,10 @@ err_nomem:
void iobuf_init(
IN u64 va,
IN u64 size,
- IN int is_user,
IN OUT iobuf_t *iobuf_p)
{
iobuf_p->va = va;
iobuf_p->size= size;
- iobuf_p->is_user = is_user;
InitializeListHead( &iobuf_p->seg_que );
iobuf_p->seg_num = 0;
iobuf_p->nr_pages = 0;
@@ -237,7 +228,7 @@ void iobuf_init(
static int iobuf_register(
IN u64 va,
IN u64 size,
- IN int is_user,
+ IN KPROCESSOR_MODE mode,
IN enum ib_access_flags acc,
IN OUT iobuf_t *iobuf_p)
{
@@ -262,7 +253,7 @@ static int iobuf_register(
// allocate segments
while (rdc > 0) {
// map a segment
- rc = register_segment(seg_va, seg_size, is_user, acc, &new_iobuf );
+ rc = register_segment(seg_va, seg_size, mode, acc, &new_iobuf );
// success - move to another segment
if (!rc) {
@@ -339,7 +330,7 @@ static void __iobuf_copy(
int iobuf_register_with_cash(
IN u64 vaddr,
IN u64 size,
- IN int is_user,
+ IN KPROCESSOR_MODE mode,
IN OUT enum ib_access_flags *acc_p,
IN OUT iobuf_t *iobuf_p)
{
@@ -356,14 +347,14 @@ int iobuf_register_with_cash(
mutex_lock(&g_pa_mutex);
// register memory for read access to bring pages into the memory
- rc = iobuf_register( vaddr, size, is_user, (ib_access_flags)0, iobuf_p);
+ rc = iobuf_register( vaddr, size, mode, (ib_access_flags)0, iobuf_p);
// on error or read access - exit
if (rc || !(*acc_p & IB_ACCESS_LOCAL_WRITE))
goto exit;
// re-register buffer with the correct access rights
- iobuf_init( (u64)vaddr, size, is_user, &sec_iobuf );
+ iobuf_init( (u64)vaddr, size, &sec_iobuf );
nr_pages = ADDRESS_AND_SIZE_TO_SPAN_PAGES( vaddr, size );
subregion_start = va = (char*)(ULONG_PTR)vaddr;
rdc = size;
@@ -401,7 +392,7 @@ int iobuf_register_with_cash(
subregion_size = rdc;
// register the subregion
- rc = iobuf_register( (ULONG_PTR)subregion_start, subregion_size, is_user, acc, &sec_iobuf);
+ rc = iobuf_register( (ULONG_PTR)subregion_start, subregion_size, mode, acc, &sec_iobuf);
if (rc)
goto cleanup;
@@ -428,7 +419,7 @@ int iobuf_register_with_cash(
subregion_size = rdc;
// register the subregion
- rc = iobuf_register( (ULONG_PTR)subregion_start, subregion_size, is_user, acc, &sec_iobuf);
+ rc = iobuf_register( (ULONG_PTR)subregion_start, subregion_size, mode, acc, &sec_iobuf);
if (rc)
goto cleanup;
diff -dwup3 -x *svn* -r c:\dev\openib\ofw\gen1\branches\mlx4_30\trunk\hw\mlx4\kernel\inc\iobuf.h .\hw\mlx4\kernel\inc\iobuf.h
--- c:\dev\openib\ofw\gen1\branches\mlx4_30\trunk\hw\mlx4\kernel\inc\iobuf.h Thu Mar 29 00:15:29 2012
+++ .\hw\mlx4\kernel\inc\iobuf.h Wed May 23 15:14:37 2012
@@ -5,7 +5,6 @@ typedef struct {
u64 size; /* size in bytes of the buffer */
LIST_ENTRY seg_que;
u32 nr_pages;
- int is_user;
int seg_num;
int is_cashed;
} iobuf_t;
@@ -23,13 +22,12 @@ void iobuf_deregister(IN iobuf_t *iobuf_
void iobuf_init(
IN u64 va,
IN u64 size,
- IN int is_user,
IN OUT iobuf_t *iobuf_p);
int iobuf_register_with_cash(
IN u64 vaddr,
IN u64 size,
- IN int is_user,
+ IN KPROCESSOR_MODE mode,
IN OUT enum ib_access_flags *acc_p,
IN OUT iobuf_t *iobuf_p);
diff -dwup3 -x *svn* -r c:\dev\openib\ofw\gen1\branches\mlx4_30\trunk\hw\mlx4\kernel\l2w\l2w_umem.c .\hw\mlx4\kernel\l2w\l2w_umem.c
--- c:\dev\openib\ofw\gen1\branches\mlx4_30\trunk\hw\mlx4\kernel\l2w\l2w_umem.c Thu Mar 29 00:15:27 2012
+++ .\hw\mlx4\kernel\l2w\l2w_umem.c Thu May 24 13:05:42 2012
@@ -47,18 +47,27 @@ void ib_umem_release(struct ib_umem *p_i
{
int err;
struct ib_umem *p_ib_umem;
+ KPROCESSOR_MODE mode;
// create the object
p_ib_umem = (struct ib_umem *)kzalloc(sizeof *p_ib_umem, GFP_KERNEL);
- if (!p_ib_umem)
- goto err_nomem;
+ if (!p_ib_umem) {
+ err = -ENOMEM;
+ goto err;
+ }
p_ib_umem->p_uctx = context;
p_ib_umem->page_size = PAGE_SIZE;
+ if( context == NULL ){
+ mode = KernelMode;
+ } else {
+ mode = context->x.mode;
+ }
+
// register the memory
- iobuf_init( addr, (u64)size, !!context, &p_ib_umem->iobuf);
- err = iobuf_register_with_cash( addr, (u64)size, !!context,
+ iobuf_init( addr, (u64)size, &p_ib_umem->iobuf);
+ err = iobuf_register_with_cash( addr, (u64)size, mode,
&access, &p_ib_umem->iobuf );
if (err)
goto err_reg_mem;
@@ -67,27 +76,31 @@ struct ib_umem *ib_umem_get(struct ib_uc
// TODO: map the memory for DMA
// secure memory
- if (!context || ((access & IB_ACCESS_NO_SECURE) != 0) ) {
+ if ( mode == KernelMode || ((access & IB_ACCESS_NO_SECURE) != 0) ) {
p_ib_umem->secure_handle = NULL;
goto done;
}
__try {
p_ib_umem->secure_handle = MmSecureVirtualMemory (
(PVOID)(ULONG_PTR)addr, size,
(access & IB_ACCESS_LOCAL_WRITE) ? PAGE_READWRITE : PAGE_READONLY );
- if (p_ib_umem->secure_handle == NULL)
+ if (p_ib_umem->secure_handle == NULL) {
+ err = -ENOMEM;
goto err_secure;
+ }
}
__except (EXCEPTION_EXECUTE_HANDLER) {
NTSTATUS Status = GetExceptionCode();
UNUSED_PARAM_WOWPP(Status);
L2W_PRINT(TRACE_LEVEL_ERROR ,L2W ,
"Exception 0x%x on MmSecureVirtualMemory(), addr %I64x, size %I64x, access %#x\n",
Status, addr, (u64)size, access );
+ err = -EACCES;
goto err_secure;
}
- goto done;
+done:
+ return p_ib_umem;
err_secure:
iobuf_deregister(&p_ib_umem->iobuf);
@@ -95,11 +108,10 @@ err_secure:
err_reg_mem:
kfree(p_ib_umem);
-err_nomem:
- p_ib_umem = (struct ib_umem *)ERR_PTR(-ENOMEM);
+err:
+ p_ib_umem = (struct ib_umem *)ERR_PTR(err);
-done:
- return p_ib_umem;
+ goto done;
}
int ib_umem_page_count(struct ib_umem *p_ib_umem)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ndv2.13.patch
Type: application/octet-stream
Size: 7720 bytes
Desc: ndv2.13.patch
URL: <http://lists.openfabrics.org/pipermail/ofw/attachments/20130221/dbc6c0f3/attachment.obj>
More information about the ofw
mailing list