diff options
| author | Dustin Brown <dustinb@codeaurora.org> | 2017-07-10 13:02:47 -0700 |
|---|---|---|
| committer | snandini <snandini@codeaurora.org> | 2017-07-13 12:04:17 -0700 |
| commit | 549657460f49a563c0f876e4ba4ad37814461eed (patch) | |
| tree | f7a20d02999f6141d071e86dd9775f0a2a9fa009 | |
| parent | 6f8901ab69459dfa650ae9e9f3778da1d208eb62 (diff) | |
qcacld-3.0: Statically allocate wlan logging buffer
To aid in debugging memory leaks, and improve the robustness of log
recovery from crash dumps, statically allocate pglog_msg in the global
scope. This allows logs to be inspected even in cases where a crash
came late in the unload process. It also improves log recovery
robustness by removing the possibility of using a NULL pointer offset
under certain memory corruptions scenarios.
Change-Id: I7301254d3d3ff811b322e435962e78f997937c2b
CRs-Fixed: 2074611
| -rw-r--r-- | core/hdd/inc/wlan_hdd_cfg.h | 11 | ||||
| -rw-r--r-- | core/hdd/src/wlan_hdd_cfg.c | 7 | ||||
| -rw-r--r-- | core/hdd/src/wlan_hdd_main.c | 62 | ||||
| -rw-r--r-- | core/utils/logging/inc/wlan_logging_sock_svc.h | 6 | ||||
| -rw-r--r-- | core/utils/logging/src/wlan_logging_sock_svc.c | 72 |
5 files changed, 38 insertions, 120 deletions
diff --git a/core/hdd/inc/wlan_hdd_cfg.h b/core/hdd/inc/wlan_hdd_cfg.h index d57bc5f1275b..ad705f5881a7 100644 --- a/core/hdd/inc/wlan_hdd_cfg.h +++ b/core/hdd/inc/wlan_hdd_cfg.h @@ -7719,12 +7719,6 @@ enum hdd_link_speed_rpt_type { #define CFG_WLAN_LOGGING_CONSOLE_SUPPORT_ENABLE (1) #define CFG_WLAN_LOGGING_CONSOLE_SUPPORT_DISABLE (0) #define CFG_WLAN_LOGGING_CONSOLE_SUPPORT_DEFAULT (1) - -/* Number of buffers to be used for WLAN logging */ -#define CFG_WLAN_LOGGING_NUM_BUF_NAME "wlanLoggingNumBuf" -#define CFG_WLAN_LOGGING_NUM_BUF_MIN (4) -#define CFG_WLAN_LOGGING_NUM_BUF_MAX (512) -#define CFG_WLAN_LOGGING_NUM_BUF_DEFAULT (256) #endif /* WLAN_LOGGING_SOCK_SVC_ENABLE */ /* @@ -11821,9 +11815,8 @@ struct hdd_config { uint32_t IpaUcTxPartitionBase; #ifdef WLAN_LOGGING_SOCK_SVC_ENABLE /* WLAN Logging */ - uint32_t wlanLoggingEnable; - uint32_t wlanLoggingToConsole; - uint32_t wlanLoggingNumBuf; + bool wlanLoggingEnable; + bool wlanLoggingToConsole; #endif /* WLAN_LOGGING_SOCK_SVC_ENABLE */ uint8_t enableSifsBurst; diff --git a/core/hdd/src/wlan_hdd_cfg.c b/core/hdd/src/wlan_hdd_cfg.c index a4b5f16873e7..60dfeb9da671 100644 --- a/core/hdd/src/wlan_hdd_cfg.c +++ b/core/hdd/src/wlan_hdd_cfg.c @@ -3307,13 +3307,6 @@ struct reg_table_entry g_registry_table[] = { CFG_WLAN_LOGGING_CONSOLE_SUPPORT_DEFAULT, CFG_WLAN_LOGGING_CONSOLE_SUPPORT_DISABLE, CFG_WLAN_LOGGING_CONSOLE_SUPPORT_ENABLE), - - REG_VARIABLE(CFG_WLAN_LOGGING_NUM_BUF_NAME, WLAN_PARAM_Integer, - struct hdd_config, wlanLoggingNumBuf, - VAR_FLAGS_OPTIONAL | VAR_FLAGS_RANGE_CHECK_ASSUME_DEFAULT, - CFG_WLAN_LOGGING_NUM_BUF_DEFAULT, - CFG_WLAN_LOGGING_NUM_BUF_MIN, - CFG_WLAN_LOGGING_NUM_BUF_MAX), #endif /* WLAN_LOGGING_SOCK_SVC_ENABLE */ REG_VARIABLE(CFG_ENABLE_SIFS_BURST, WLAN_PARAM_Integer, diff --git a/core/hdd/src/wlan_hdd_main.c b/core/hdd/src/wlan_hdd_main.c index ca4685ce51ee..873bc209144c 100644 --- a/core/hdd/src/wlan_hdd_main.c +++ b/core/hdd/src/wlan_hdd_main.c @@ -5185,57 +5185,6 @@ static int hdd_wlan_register_ip6_notifier(hdd_context_t *hdd_ctx) } #endif -#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE -/** - * hdd_logging_sock_activate_svc() - Activate logging - * @hdd_ctx: HDD context - * - * Activates the logging service - * - * Return: Zero in case of success, negative value otherwise - */ -static int hdd_logging_sock_activate_svc(hdd_context_t *hdd_ctx) -{ - int ret; - struct hdd_config *config = hdd_ctx->config; - - if (!config->wlanLoggingEnable) - return 0; - - ret = wlan_logging_sock_activate_svc(config->wlanLoggingToConsole, - config->wlanLoggingNumBuf); - if (ret) - hdd_err("wlan_logging_sock_activate_svc failed: %d", ret); - return ret; -} - -/** - * wlan_hdd_logging_sock_deactivate_svc() - Deactivate logging - * @hdd_ctx: HDD context - * - * Deactivates the logging service - * - * Return: 0 on deactivating the logging service - */ -static int hdd_logging_sock_deactivate_svc(hdd_context_t *hdd_ctx) -{ - if (hdd_ctx && hdd_ctx->config->wlanLoggingEnable) - return wlan_logging_sock_deactivate_svc(); - - return 0; -} -#else -static inline int hdd_logging_sock_activate_svc(hdd_context_t *hdd_ctx) -{ - return 0; -} - -static inline int hdd_logging_sock_deactivate_svc(hdd_context_t *hdd_ctx) -{ - return 0; -} -#endif - /** * hdd_register_notifiers - Register netdev notifiers. * @hdd_ctx: HDD context @@ -5504,8 +5453,6 @@ static int hdd_context_deinit(hdd_context_t *hdd_ctx) static void hdd_context_destroy(hdd_context_t *hdd_ctx) { - hdd_logging_sock_deactivate_svc(hdd_ctx); - wlan_hdd_deinit_tx_rx_histogram(hdd_ctx); hdd_context_deinit(hdd_ctx); @@ -7538,10 +7485,8 @@ static hdd_context_t *hdd_context_create(struct device *dev) if (ret) goto err_deinit_hdd_context; - ret = hdd_logging_sock_activate_svc(hdd_ctx); - if (ret) - goto err_free_histogram; - + wlan_logging_set_log_to_console(hdd_ctx->config->wlanLoggingToConsole); + wlan_logging_set_active(hdd_ctx->config->wlanLoggingEnable); /* * Update QDF trace levels based upon the code. The multicast @@ -7556,9 +7501,6 @@ skip_multicast_logging: return hdd_ctx; -err_free_histogram: - wlan_hdd_deinit_tx_rx_histogram(hdd_ctx); - err_deinit_hdd_context: hdd_context_deinit(hdd_ctx); diff --git a/core/utils/logging/inc/wlan_logging_sock_svc.h b/core/utils/logging/inc/wlan_logging_sock_svc.h index 06d0b6fe0f0e..c75ddcf01d90 100644 --- a/core/utils/logging/inc/wlan_logging_sock_svc.h +++ b/core/utils/logging/inc/wlan_logging_sock_svc.h @@ -40,8 +40,6 @@ int wlan_logging_sock_init_svc(void); int wlan_logging_sock_deinit_svc(void); -int wlan_logging_sock_activate_svc(int log_fe_to_console, int num_buf); -int wlan_logging_sock_deactivate_svc(void); int wlan_log_to_user(QDF_TRACE_LEVEL log_level, char *to_be_sent, int length); #ifdef WLAN_LOGGING_SOCK_SVC_ENABLE @@ -49,6 +47,8 @@ void wlan_logging_set_per_pkt_stats(void); void wlan_logging_set_log_level(void); void wlan_logging_set_fw_flush_complete(void); void wlan_flush_host_logs_for_fatal(void); +void wlan_logging_set_active(bool active); +void wlan_logging_set_log_to_console(bool log_to_console); #else static inline void wlan_flush_host_logs_for_fatal(void) { @@ -62,6 +62,8 @@ static inline void wlan_logging_set_per_pkt_stats(void) static inline void wlan_logging_set_fw_flush_complete(void) { } +void wlan_logging_set_active(bool active) {} +void wlan_logging_set_log_to_console(bool log_to_console) {} #endif /* WLAN_LOGGING_SOCK_SVC_ENABLE */ #ifdef FEATURE_WLAN_DIAG_SUPPORT diff --git a/core/utils/logging/src/wlan_logging_sock_svc.c b/core/utils/logging/src/wlan_logging_sock_svc.c index 341eec694fe3..a7057c9fe6a5 100644 --- a/core/utils/logging/src/wlan_logging_sock_svc.c +++ b/core/utils/logging/src/wlan_logging_sock_svc.c @@ -88,6 +88,9 @@ static uint8_t grx_count; #define ANI_NL_MSG_LOG_TYPE 89 #define ANI_NL_MSG_READY_IND_TYPE 90 +#ifndef MAX_LOGMSG_COUNT +#define MAX_LOGMSG_COUNT 256 +#endif #define MAX_LOGMSG_LENGTH 2048 #define MAX_SKBMSG_LENGTH 4096 #define MAX_PKTSTATS_LENGTH 2048 @@ -142,7 +145,8 @@ struct wlan_logging { /* Log Fatal and ERROR to console */ bool log_to_console; /* Number of buffers to be used for logging */ - int num_buf; + uint32_t num_buf; + uint32_t buffer_length; /* Lock to synchronize access to shared logging resource */ spinlock_t spin_lock; /* Holds the free node which can be used for filling logs */ @@ -177,7 +181,7 @@ struct wlan_logging { }; static struct wlan_logging gwlan_logging; -static struct log_msg *gplog_msg; +static struct log_msg gplog_msg[MAX_LOGMSG_COUNT]; static struct pkt_stats_msg *gpkt_stats_buffers; /** @@ -397,8 +401,7 @@ int wlan_log_to_user(QDF_TRACE_LEVEL log_level, char *to_be_sent, int length) pfilled_length = &gwlan_logging.pcur_node->filled_length; /* Check if we can accomodate more log into current node/buffer */ - if ((MAX_LOGMSG_LENGTH <= (*pfilled_length + - sizeof(tAniNlHdr))) || + if ((MAX_LOGMSG_LENGTH <= (*pfilled_length + sizeof(tAniNlHdr))) || ((MAX_LOGMSG_LENGTH - (*pfilled_length + sizeof(tAniNlHdr))) < total_log_len)) { wake_up_thread = true; @@ -854,27 +857,33 @@ static int wlan_logging_thread(void *Arg) return 0; } -int wlan_logging_sock_activate_svc(int log_to_console, int num_buf) +void wlan_logging_set_active(bool active) { - int i = 0, j, pkt_stats_size; - unsigned long irq_flag; + gwlan_logging.is_active = active; +} - gplog_msg = (struct log_msg *)vmalloc(num_buf * sizeof(struct log_msg)); - if (!gplog_msg) { - pr_err("%s: Could not allocate memory\n", __func__); - return -ENOMEM; - } +void wlan_logging_set_log_to_console(bool log_to_console) +{ + gwlan_logging.log_to_console = log_to_console; +} - qdf_mem_zero(gplog_msg, (num_buf * sizeof(struct log_msg))); +int wlan_logging_sock_init_svc(void) +{ + int i, j, pkt_stats_size; + unsigned long irq_flag; - gwlan_logging.log_to_console = !!log_to_console; - gwlan_logging.num_buf = num_buf; + spin_lock_init(&gwlan_logging.spin_lock); + spin_lock_init(&gwlan_logging.pkt_stats_lock); + + gwlan_logging.log_to_console = true; + gwlan_logging.num_buf = MAX_LOGMSG_COUNT; + gwlan_logging.buffer_length = MAX_LOGMSG_LENGTH; spin_lock_irqsave(&gwlan_logging.spin_lock, irq_flag); INIT_LIST_HEAD(&gwlan_logging.free_list); INIT_LIST_HEAD(&gwlan_logging.filled_list); - for (i = 0; i < num_buf; i++) { + for (i = 0; i < gwlan_logging.num_buf; i++) { list_add(&gplog_msg[i].node, &gwlan_logging.free_list); gplog_msg[i].index = i; } @@ -956,17 +965,16 @@ err1: spin_lock_irqsave(&gwlan_logging.spin_lock, irq_flag); gwlan_logging.pcur_node = NULL; spin_unlock_irqrestore(&gwlan_logging.spin_lock, irq_flag); - vfree(gplog_msg); - gplog_msg = NULL; + return -ENOMEM; } -int wlan_logging_sock_deactivate_svc(void) +int wlan_logging_sock_deinit_svc(void) { unsigned long irq_flag; - int i = 0; + int i; - if (!gplog_msg) + if (!gwlan_logging.pcur_node) return 0; clear_default_logtoapp_log_level(); @@ -985,8 +993,6 @@ int wlan_logging_sock_deactivate_svc(void) spin_lock_irqsave(&gwlan_logging.spin_lock, irq_flag); gwlan_logging.pcur_node = NULL; spin_unlock_irqrestore(&gwlan_logging.spin_lock, irq_flag); - vfree(gplog_msg); - gplog_msg = NULL; spin_lock_irqsave(&gwlan_logging.pkt_stats_lock, irq_flag); gwlan_logging.pkt_stats_pcur_node = NULL; @@ -1004,24 +1010,6 @@ int wlan_logging_sock_deactivate_svc(void) return 0; } -int wlan_logging_sock_init_svc(void) -{ - spin_lock_init(&gwlan_logging.spin_lock); - spin_lock_init(&gwlan_logging.pkt_stats_lock); - gwlan_logging.pcur_node = NULL; - gwlan_logging.pkt_stats_pcur_node = NULL; - - return 0; -} - -int wlan_logging_sock_deinit_svc(void) -{ - gwlan_logging.pcur_node = NULL; - gwlan_logging.pkt_stats_pcur_node = NULL; - - return 0; -} - /** * wlan_logging_set_per_pkt_stats() - This function triggers per packet logging * @@ -1033,7 +1021,7 @@ int wlan_logging_sock_deinit_svc(void) */ void wlan_logging_set_per_pkt_stats(void) { - if (gwlan_logging.is_active == false) + if (!gwlan_logging.is_active) return; set_bit(HOST_LOG_PER_PKT_STATS, &gwlan_logging.eventFlag); |
