From f268ba79f69f9e52c4af143b61aa41cc48d9a3b1 Mon Sep 17 00:00:00 2001 From: Alex Markuze Date: Mon, 17 Mar 2025 15:30:31 +0000 Subject: [PATCH] pf spin lock --- include/linux/ceph/ceph_san_pagefrag.h | 2 ++ net/ceph/ceph_san_logger.c | 12 +++++++----- net/ceph/ceph_san_pagefrag.c | 4 ++++ 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/include/linux/ceph/ceph_san_pagefrag.h b/include/linux/ceph/ceph_san_pagefrag.h index faeba5dcce0ce..85248b851b643 100644 --- a/include/linux/ceph/ceph_san_pagefrag.h +++ b/include/linux/ceph/ceph_san_pagefrag.h @@ -3,6 +3,7 @@ #include #include +#include #define CEPHSAN_PAGEFRAG_SIZE (1<<21) /* 2MB */ #define CEPHSAN_PAGEFRAG_MASK (CEPHSAN_PAGEFRAG_SIZE - 1) @@ -11,6 +12,7 @@ struct cephsan_pagefrag { struct page *pages; void *buffer; + spinlock_t lock; /* protects head and tail */ unsigned int head; unsigned int tail; }; diff --git a/net/ceph/ceph_san_logger.c b/net/ceph/ceph_san_logger.c index 16fee904102ab..88e056058da6f 100644 --- a/net/ceph/ceph_san_logger.c +++ b/net/ceph/ceph_san_logger.c @@ -131,7 +131,8 @@ void ceph_san_log(const char *file, unsigned int line, const char *fmt, ...) va_end(args); needed_size = sizeof(*entry) + len + 1; - /* Allocate entry from pagefrag */ //We need a spinlock here to protect printing + /* Allocate entry from pagefrag - We need a spinlock here to protect access iterators */ + spin_lock(&ctx->pf.lock); alloc = cephsan_pagefrag_alloc(&ctx->pf, needed_size); while (!alloc) { entry = cephsan_pagefrag_get_ptr_from_tail(&ctx->pf); @@ -149,16 +150,17 @@ void ceph_san_log(const char *file, unsigned int line, const char *fmt, ...) } entry = cephsan_pagefrag_get_ptr(&ctx->pf, alloc); - /* Copy to entry buffer */ - memcpy(entry->buffer, buf, len + 1); - entry->buffer[len] = '\0'; - /* Fill in entry details */ entry->debug_poison = CEPH_SAN_LOG_ENTRY_POISON; entry->ts = jiffies; entry->line = line; entry->file = file; entry->len = cephsan_pagefrag_get_alloc_size(alloc); + spin_unlock(&ctx->pf.lock); + + /* Copy to entry buffer */ + memcpy(entry->buffer, buf, len + 1); + entry->buffer[len] = '\0'; } EXPORT_SYMBOL(ceph_san_log); diff --git a/net/ceph/ceph_san_pagefrag.c b/net/ceph/ceph_san_pagefrag.c index 282b236376f61..80d34d0458546 100644 --- a/net/ceph/ceph_san_pagefrag.c +++ b/net/ceph/ceph_san_pagefrag.c @@ -12,6 +12,7 @@ */ int cephsan_pagefrag_init(struct cephsan_pagefrag *pf) { + spin_lock_init(&pf->lock); pf->pages = alloc_pages(GFP_KERNEL, get_order(CEPHSAN_PAGEFRAG_SIZE)); if (!pf->pages) return -ENOMEM; @@ -33,6 +34,7 @@ EXPORT_SYMBOL(cephsan_pagefrag_init); */ int cephsan_pagefrag_init_with_buffer(struct cephsan_pagefrag *pf, void *buffer, size_t size) { + spin_lock_init(&pf->lock); pf->pages = NULL; /* No pages allocated, using provided buffer */ pf->buffer = buffer; pf->head = 0; @@ -151,7 +153,9 @@ EXPORT_SYMBOL(cephsan_pagefrag_deinit); */ void cephsan_pagefrag_reset(struct cephsan_pagefrag *pf) { + spin_lock(&pf->lock); pf->head = 0; pf->tail = 0; + spin_unlock(&pf->lock); } EXPORT_SYMBOL(cephsan_pagefrag_reset); -- 2.39.5