summaryrefslogtreecommitdiffstats
path: root/pcilib
diff options
context:
space:
mode:
authorSuren A. Chilingaryan <csa@suren.me>2015-08-05 18:11:59 +0200
committerSuren A. Chilingaryan <csa@suren.me>2015-08-05 18:11:59 +0200
commit7c5897933f4f64594602b2e38264af705c061754 (patch)
treeb6051387f6e2ff6c995141ba9bcb6960ecdd0b6a /pcilib
parentf2e47ba725cc7ba477d3a788addc974f2b18d36f (diff)
downloadpcitool-7c5897933f4f64594602b2e38264af705c061754.tar.gz
pcitool-7c5897933f4f64594602b2e38264af705c061754.tar.bz2
pcitool-7c5897933f4f64594602b2e38264af705c061754.tar.xz
pcitool-7c5897933f4f64594602b2e38264af705c061754.zip
Use global locks to protect kmem allocation to prevent race while allocating simmultaneously locking kmem pages and any other type of kmem
Diffstat (limited to 'pcilib')
-rw-r--r--pcilib/bar.c9
-rw-r--r--pcilib/kmem.c6
-rw-r--r--pcilib/lock.c5
-rw-r--r--pcilib/locking.c6
-rw-r--r--pcilib/locking.h2
5 files changed, 14 insertions, 14 deletions
diff --git a/pcilib/bar.c b/pcilib/bar.c
index 17828a8..418f864 100644
--- a/pcilib/bar.c
+++ b/pcilib/bar.c
@@ -80,7 +80,7 @@ void *pcilib_map_bar(pcilib_t *ctx, pcilib_bar_t bar) {
if (ctx->bar_space[bar]) return ctx->bar_space[bar];
- err = pcilib_lock(ctx->locks.mmap);
+ err = pcilib_lock_global(ctx);
if (err) {
pcilib_error("Error (%i) acquiring mmap lock", err);
return NULL;
@@ -88,14 +88,14 @@ void *pcilib_map_bar(pcilib_t *ctx, pcilib_bar_t bar) {
ret = ioctl( ctx->handle, PCIDRIVER_IOC_MMAP_MODE, PCIDRIVER_MMAP_PCI );
if (ret) {
- pcilib_unlock(ctx->locks.mmap);
+ pcilib_unlock_global(ctx);
pcilib_error("PCIDRIVER_IOC_MMAP_MODE ioctl have failed", bar);
return NULL;
}
ret = ioctl( ctx->handle, PCIDRIVER_IOC_MMAP_AREA, PCIDRIVER_BAR0 + bar );
if (ret) {
- pcilib_unlock(ctx->locks.mmap);
+ pcilib_unlock_global(ctx);
pcilib_error("PCIDRIVER_IOC_MMAP_AREA ioctl have failed for bank %i", bar);
return NULL;
}
@@ -106,7 +106,8 @@ void *pcilib_map_bar(pcilib_t *ctx, pcilib_bar_t bar) {
#else
res = mmap( 0, board_info->bar_length[bar], PROT_WRITE | PROT_READ, MAP_SHARED, ctx->handle, 0 );
#endif
- pcilib_unlock(ctx->locks.mmap);
+
+ pcilib_unlock_global(ctx);
if ((!res)||(res == MAP_FAILED)) {
pcilib_error("Failed to mmap data bank %i", bar);
diff --git a/pcilib/kmem.c b/pcilib/kmem.c
index 469c63a..b1d2c5c 100644
--- a/pcilib/kmem.c
+++ b/pcilib/kmem.c
@@ -80,7 +80,7 @@ pcilib_kmem_handle_t *pcilib_alloc_kernel_memory(pcilib_t *ctx, pcilib_kmem_type
memset(kbuf, 0, sizeof(pcilib_kmem_list_t) + nmemb * sizeof(pcilib_kmem_addr_t));
- err = pcilib_lock(ctx->locks.mmap);
+ err = pcilib_lock_global(ctx);
if (err) {
pcilib_error("Error (%i) acquiring mmap lock", err);
return NULL;
@@ -88,7 +88,7 @@ pcilib_kmem_handle_t *pcilib_alloc_kernel_memory(pcilib_t *ctx, pcilib_kmem_type
ret = ioctl( ctx->handle, PCIDRIVER_IOC_MMAP_MODE, PCIDRIVER_MMAP_KMEM );
if (ret) {
- pcilib_unlock(ctx->locks.mmap);
+ pcilib_unlock_global(ctx);
pcilib_error("PCIDRIVER_IOC_MMAP_MODE ioctl have failed");
return NULL;
}
@@ -176,7 +176,7 @@ pcilib_kmem_handle_t *pcilib_alloc_kernel_memory(pcilib_t *ctx, pcilib_kmem_type
kbuf->buf.blocks[i].mmap_offset = kh.pa & ctx->page_mask;
}
- pcilib_unlock(ctx->locks.mmap);
+ pcilib_unlock_global(ctx);
//This is possible in the case of error (nothing is allocated yet) or if buffers are not reused
diff --git a/pcilib/lock.c b/pcilib/lock.c
index f1cbc56..13e363a 100644
--- a/pcilib/lock.c
+++ b/pcilib/lock.c
@@ -140,7 +140,10 @@ const char *pcilib_lock_get_name(pcilib_lock_t *lock) {
int pcilib_lock_custom(pcilib_lock_t *lock, pcilib_lock_flags_t flags, pcilib_timeout_t timeout) {
int err;
- if (!lock) return 0;
+ if (!lock) {
+ pcilib_error("The null lock pointer is passed to lock function");
+ return PCILIB_ERROR_INVALID_ARGUMENT;
+ }
struct timespec tm;
diff --git a/pcilib/locking.c b/pcilib/locking.c
index ffd05ce..7a32605 100644
--- a/pcilib/locking.c
+++ b/pcilib/locking.c
@@ -46,11 +46,10 @@ int pcilib_init_locking(pcilib_t* ctx) {
}
ctx->locks.locking = pcilib_get_lock(ctx, PCILIB_LOCK_FLAG_UNLOCKED, "locking");
- ctx->locks.mmap = pcilib_get_lock(ctx, PCILIB_LOCK_FLAG_UNLOCKED, "mmap");
pcilib_unlock_global(ctx);
- if ((!ctx->locks.locking)||(!ctx->locks.mmap)) {
+ if ((!ctx->locks.locking)) {
pcilib_error("Locking subsystem has failed to initialized mandatory global locks");
return PCILIB_ERROR_FAILED;
}
@@ -62,9 +61,6 @@ int pcilib_init_locking(pcilib_t* ctx) {
* this functions destroy all locks and then free the kernel memory allocated for them
*/
void pcilib_free_locking(pcilib_t *ctx) {
- if (ctx->locks.mmap)
- pcilib_return_lock(ctx, PCILIB_LOCK_FLAGS_DEFAULT, ctx->locks.mmap);
-
if (ctx->locks.locking)
pcilib_return_lock(ctx, PCILIB_LOCK_FLAGS_DEFAULT, ctx->locks.locking);
diff --git a/pcilib/locking.h b/pcilib/locking.h
index ae2f368..ccacd63 100644
--- a/pcilib/locking.h
+++ b/pcilib/locking.h
@@ -20,7 +20,7 @@ typedef struct pcilib_locking_s pcilib_locking_t;
struct pcilib_locking_s {
pcilib_kmem_handle_t *kmem; /**< kmem used to store mutexes */
pcilib_lock_t *locking; /**< lock used while intializing other locks */
- pcilib_lock_t *mmap; /**< lock used to protect mmap operation */
+// pcilib_lock_t *mmap; /**< lock used to protect mmap operation */
};
#ifdef __cplusplus