From 8bb4b4a8adc916ebe57638af949152b069d7b58a Mon Sep 17 00:00:00 2001 From: Alex Markuze Date: Mon, 3 Mar 2025 16:51:54 +0000 Subject: [PATCH] cephsan: bug fixes --- include/linux/ceph/ceph_san.h | 5 +++-- net/ceph/ceph_san.c | 19 +++++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/include/linux/ceph/ceph_san.h b/include/linux/ceph/ceph_san.h index 33aa9945dd1a8..e91e14efa3df0 100644 --- a/include/linux/ceph/ceph_san.h +++ b/include/linux/ceph/ceph_san.h @@ -112,7 +112,7 @@ struct ceph_san_log_entry_tls { char *buf; }; struct histogram { - u64 counters[16]; + u64 counters[32]; }; struct ceph_san_percore_logger { @@ -130,8 +130,9 @@ struct ceph_san_tls_logger { /* Bundled TLS context containing both logger and memory caches */ struct tls_ceph_san_context { - struct ceph_san_tls_logger logger; + u64 sig; struct list_head list; /* For global list of contexts */ + struct ceph_san_tls_logger logger; /* We no longer use pagefrag for log entries */ }; diff --git a/net/ceph/ceph_san.c b/net/ceph/ceph_san.c index e23e50045610c..77e7cc8aaf890 100644 --- a/net/ceph/ceph_san.c +++ b/net/ceph/ceph_san.c @@ -29,7 +29,7 @@ static inline void *cephsan_pagefrag_get_ptr(struct cephsan_pagefrag *pf, u64 va * have been moved to cephsan.h (under CONFIG_DEBUG_FS) to avoid duplication. */ - +#define CEPH_SAN_SIG 0xDEADC0DE /* Release function for TLS storage */ static void ceph_san_tls_release(void *ptr) { @@ -37,6 +37,10 @@ static void ceph_san_tls_release(void *ptr) if (!context) return; + if (context->sig != CEPH_SAN_SIG) + pr_err("sig is wrong %p %llx != %llx", context, context->sig, CEPH_SAN_SIG); + return; + /* Remove from global list with lock protection */ spin_lock(&g_ceph_san_contexts_lock); list_del(&context->list); @@ -78,14 +82,16 @@ static struct tls_ceph_san_context *get_cephsan_context(void) { /* Initialize list entry */ INIT_LIST_HEAD(&context->list); + context->sig = CEPH_SAN_SIG; + + current->tls.state = context; + current->tls.release = ceph_san_tls_release; /* Add to global list with lock protection */ spin_lock(&g_ceph_san_contexts_lock); list_add(&context->list, &g_ceph_san_contexts); spin_unlock(&g_ceph_san_contexts_lock); - current->tls.state = context; - current->tls.release = ceph_san_tls_release; return context; } @@ -119,7 +125,7 @@ void log_cephsan_tls(char *buf) { /* Allocate new buffer from appropriate cache */ if (len <= LOG_BUF_SMALL) { new_buf = kmem_cache_alloc(ceph_san_log_128_cache, GFP_KERNEL); - entry->ts = jiffies | 0x0; + entry->ts = jiffies & ~0x1; } else { new_buf = kmem_cache_alloc(ceph_san_log_256_cache, GFP_KERNEL); entry->ts = jiffies | 0x1; @@ -160,7 +166,7 @@ static void log_cephsan_percore(char *buf) { buf_idx = cephsan_pagefrag_alloc(pf, len); if (buf_idx) { pc->head_idx = head_idx; - pc->histogram.counters[len >> 3]++; + pc->histogram.counters[(len >= 256) ? 31 : len >> 3]++; pc->logs[head_idx].len = len; pc->logs[head_idx].buf = cephsan_pagefrag_get_ptr(pf, buf_idx); memcpy(pc->logs[head_idx].buf, buf, len); @@ -188,7 +194,7 @@ void cephsan_cleanup(void) pc->pages = NULL; } } - +#if 0 /* Let the TLS contexts cleanup lazily */ if (ceph_san_tls_logger_cache) { kmem_cache_destroy(ceph_san_tls_logger_cache); @@ -204,6 +210,7 @@ void cephsan_cleanup(void) kmem_cache_destroy(ceph_san_log_256_cache); ceph_san_log_256_cache = NULL; } +#endif } EXPORT_SYMBOL(cephsan_cleanup); -- 2.39.5