mirror of
git://nv-tegra.nvidia.com/linux-nvgpu.git
synced 2025-12-24 10:34:43 +03:00
gpu: nvgpu: fix ecc counter free
ECC counter structures are freed without removing the node from the stats_list. This can lead to invalid access due to dangling pointers. Update the ecc counter free logic to set them to NULL upon free, to remove them from stats_list and free them by validation. Also updated some of the ecc init paths where error was not propa- gated to callers and full ecc counters deallocation was not done. Now, calling unit ecc_free from any context (with counters alloc- ated or not) is harmless as requisite checks are in place. bug 3326612 bug 3345977 Change-Id: I05eb6ed226cff9197ad37776912da9dcb7e0716d Signed-off-by: Sagar Kamble <skamble@nvidia.com> Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2565264 Tested-by: Ashish Mhetre <amhetre@nvidia.com> Tested-by: mobile promotions <svcmobile_promotions@nvidia.com> Reviewed-by: svc_kernel_abi <svc_kernel_abi@nvidia.com> Reviewed-by: Konsta Holtta <kholtta@nvidia.com> Reviewed-by: Deepak Nibade <dnibade@nvidia.com> Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com> GVS: Gerrit_Virtual_Submit
This commit is contained in:
committed by
mobile promotions
parent
2887d06e3b
commit
40064ef1ec
@@ -77,6 +77,7 @@
|
||||
|
||||
#include <nvgpu/types.h>
|
||||
#include <nvgpu/list.h>
|
||||
#include <nvgpu/lock.h>
|
||||
|
||||
#define NVGPU_ECC_STAT_NAME_MAX_SIZE 100UL
|
||||
|
||||
@@ -268,6 +269,8 @@ struct nvgpu_ecc {
|
||||
|
||||
/** Contains the head to the list of error statistics. */
|
||||
struct nvgpu_list_node stats_list;
|
||||
/** Lock to protect the stats_list updates. */
|
||||
struct nvgpu_mutex stats_lock;
|
||||
/** Contains the number of error statistics. */
|
||||
int stats_count;
|
||||
/**
|
||||
@@ -281,29 +284,50 @@ struct nvgpu_ecc {
|
||||
* @brief Allocates, initializes an error counter with specified name.
|
||||
*
|
||||
* @param g [in] The GPU driver struct.
|
||||
* @param stat [out] Pointer to array of tpc error counters.
|
||||
* @param statp [out] Pointer to error counter pointer.
|
||||
* @param name [in] Unique name for error counter.
|
||||
*
|
||||
* Allocate memory for one error counter, initializes the counter with 0 and the
|
||||
* specified string identifier. Finally the counter is added to the status_list
|
||||
* specified string identifier. Finally the counter is added to the stats_list
|
||||
* of struct nvgpu_ecc.
|
||||
*
|
||||
* @return 0 in case of success, less than 0 for failure.
|
||||
* @return -ENOMEM if there is not enough memory to allocate ecc stats.
|
||||
*/
|
||||
int nvgpu_ecc_counter_init(struct gk20a *g,
|
||||
struct nvgpu_ecc_stat **stat, const char *name);
|
||||
struct nvgpu_ecc_stat **statp, const char *name);
|
||||
|
||||
/**
|
||||
* @brief Concatenates the error counter to status list.
|
||||
* @brief Deallocates an error counter.
|
||||
*
|
||||
* @param g [in] The GPU driver struct.
|
||||
* @param statp [in] Pointer to error counter pointer.
|
||||
*
|
||||
* Delete the counter from the nvgpu_ecc stats_list. Deallocate memory for the
|
||||
* error counter.
|
||||
*/
|
||||
void nvgpu_ecc_counter_deinit(struct gk20a *g, struct nvgpu_ecc_stat **statp);
|
||||
|
||||
/**
|
||||
* @brief Concatenates the error counter to stats list.
|
||||
*
|
||||
* @param g [in] The GPU driver struct.
|
||||
* @param stat [in] Pointer to error counter.
|
||||
*
|
||||
* The counter is added to the status_list of struct nvgpu_ecc.
|
||||
* The counter is added to the stats_list of struct nvgpu_ecc.
|
||||
*/
|
||||
void nvgpu_ecc_stat_add(struct gk20a *g, struct nvgpu_ecc_stat *stat);
|
||||
|
||||
/**
|
||||
* @brief Deletes the error counter from the stats list.
|
||||
*
|
||||
* @param g [in] The GPU driver struct.
|
||||
* @param stat [in] Pointer to error counter.
|
||||
*
|
||||
* The counter is removed from the stats_list of struct nvgpu_ecc.
|
||||
*/
|
||||
void nvgpu_ecc_stat_del(struct gk20a *g, struct nvgpu_ecc_stat *stat);
|
||||
|
||||
/**
|
||||
* @brief Release memory associated with all error counters.
|
||||
*
|
||||
|
||||
@@ -105,6 +105,27 @@ struct gops_gr_ecc {
|
||||
*/
|
||||
int (*fecs_ecc_init)(struct gk20a *g);
|
||||
|
||||
/**
|
||||
* @brief Deinitialize GR unit ECC support.
|
||||
*
|
||||
* @param g [in] Pointer to GPU driver struct.
|
||||
*
|
||||
* This function deallocates memory to track the ecc error counts
|
||||
* for GR unit and subunits of GR (like GPCs, TPCs etc) and removes
|
||||
* it from global list.
|
||||
*/
|
||||
void (*gpc_tpc_ecc_deinit)(struct gk20a *g);
|
||||
|
||||
/**
|
||||
* @brief Deinitialize GR unit ECC support.
|
||||
*
|
||||
* @param g [in] Pointer to GPU driver struct.
|
||||
*
|
||||
* This function deallocates memory to track the ecc error counts
|
||||
* for FECS in GR and removes it from global list.
|
||||
*/
|
||||
void (*fecs_ecc_deinit)(struct gk20a *g);
|
||||
|
||||
/**
|
||||
* @brief Detect ECC enabled units in GR engine.
|
||||
*
|
||||
|
||||
@@ -49,7 +49,7 @@ int nvgpu_ecc_counter_init_per_tpc(struct gk20a *g,
|
||||
* @param stat [in] Address of pointer to struct nvgpu_ecc_stat.
|
||||
*
|
||||
*/
|
||||
#define NVGPU_ECC_COUNTER_INIT_PER_TPC(stat) \
|
||||
#define NVGPU_ECC_COUNTER_INIT_PER_TPC_OR_RETURN(stat) \
|
||||
do { \
|
||||
int err = 0; \
|
||||
err = nvgpu_ecc_counter_init_per_tpc(g, \
|
||||
@@ -59,6 +59,27 @@ int nvgpu_ecc_counter_init_per_tpc(struct gk20a *g,
|
||||
} \
|
||||
} while (false)
|
||||
|
||||
/**
|
||||
* @brief Free error counter of all tpc instances in all gpc instances.
|
||||
*
|
||||
* @param g [in] The GPU driver struct.
|
||||
* @param stats_p [out] Pointer to 2D array of error counters in tpcs in gpcs.
|
||||
*
|
||||
* Removes the error counter of all gpc instances from stats_list in struct
|
||||
* nvgpu_ecc and frees the memory allocated for it.
|
||||
*/
|
||||
void nvgpu_ecc_counter_deinit_per_tpc(struct gk20a *g,
|
||||
struct nvgpu_ecc_stat ***stats_p);
|
||||
|
||||
/*
|
||||
* @brief Frees counters for memories shared across a TPCs in GPCs.
|
||||
*
|
||||
* @param stat [in] error counter member from g->ecc.gr.
|
||||
*
|
||||
*/
|
||||
#define NVGPU_ECC_COUNTER_DEINIT_PER_TPC(stat) \
|
||||
nvgpu_ecc_counter_deinit_per_tpc(g, &g->ecc.gr.stat)
|
||||
|
||||
/**
|
||||
* @brief Allocate and initialize error counter specified by name for all gpc
|
||||
* instances.
|
||||
@@ -79,12 +100,33 @@ int nvgpu_ecc_counter_init_per_gpc(struct gk20a *g,
|
||||
/*
|
||||
* @brief Allocate and initialize counters for memories shared across a GPC.
|
||||
*
|
||||
* @param stat [in] Address of pointer to struct nvgpu_ecc_stat.
|
||||
* @param stat [in] error counter member from g->ecc.gr.
|
||||
*
|
||||
*/
|
||||
#define NVGPU_ECC_COUNTER_INIT_PER_GPC(stat) \
|
||||
nvgpu_ecc_counter_init_per_gpc(g, &g->ecc.gr.stat, #stat)
|
||||
|
||||
/**
|
||||
* @brief Free error counter of all gpc instances.
|
||||
*
|
||||
* @param g [in] The GPU driver struct.
|
||||
* @param stats_p [out] Pointer to array of gpc error counters.
|
||||
*
|
||||
* Removes the error counter of all gpc instances from stats_list in struct
|
||||
* nvgpu_ecc and frees the memory allocated for it.
|
||||
*/
|
||||
void nvgpu_ecc_counter_deinit_per_gpc(struct gk20a *g,
|
||||
struct nvgpu_ecc_stat **stats_p);
|
||||
|
||||
/*
|
||||
* @brief Frees counters for memories shared across a GPC.
|
||||
*
|
||||
* @param stat [in] error counter member from g->ecc.gr.
|
||||
*
|
||||
*/
|
||||
#define NVGPU_ECC_COUNTER_DEINIT_PER_GPC(stat) \
|
||||
nvgpu_ecc_counter_deinit_per_gpc(g, &g->ecc.gr.stat)
|
||||
|
||||
/**
|
||||
* @brief Allocate and initialize error counter specified by name for all gr
|
||||
* instances.
|
||||
@@ -107,9 +149,30 @@ int nvgpu_ecc_counter_init_per_gr(struct gk20a *g,
|
||||
* @param stat [in] Address of pointer to struct nvgpu_ecc_stat.
|
||||
*
|
||||
*/
|
||||
#define NVGPU_ECC_COUNTER_INIT_GR(stat) \
|
||||
#define NVGPU_ECC_COUNTER_INIT_PER_GR(stat) \
|
||||
nvgpu_ecc_counter_init_per_gr(g, &g->ecc.gr.stat, #stat)
|
||||
|
||||
/**
|
||||
* @brief Free error counter of all gr instances.
|
||||
*
|
||||
* @param g [in] The GPU driver struct.
|
||||
* @param stats_p [out] Pointer to array of gr error counters.
|
||||
*
|
||||
* Removes the error counter of all gr instances from stats_list in struct
|
||||
* nvgpu_ecc and frees the memory allocated for it.
|
||||
*/
|
||||
void nvgpu_ecc_counter_deinit_per_gr(struct gk20a *g,
|
||||
struct nvgpu_ecc_stat **stats_p);
|
||||
|
||||
/*
|
||||
* @brief Frees counters for memories shared across a GR instances.
|
||||
*
|
||||
* @param stat [in] error counter member from g->ecc.gr.
|
||||
*
|
||||
*/
|
||||
#define NVGPU_ECC_COUNTER_DEINIT_PER_GR(stat) \
|
||||
nvgpu_ecc_counter_deinit_per_gr(g, &g->ecc.gr.stat)
|
||||
|
||||
/**
|
||||
* @brief Release all GR ECC stats counters.
|
||||
*
|
||||
|
||||
@@ -528,7 +528,7 @@ int nvgpu_pmu_early_init(struct gk20a *g);
|
||||
void nvgpu_pmu_remove_support(struct gk20a *g, struct nvgpu_pmu *pmu);
|
||||
|
||||
/*
|
||||
* @brief Allocate and initialize counter for memories within PMU.
|
||||
* @brief Allocate and initialize ECC counter for memories within PMU.
|
||||
*
|
||||
* @param stat [in] Address of pointer to struct nvgpu_ecc_stat.
|
||||
*
|
||||
@@ -536,5 +536,14 @@ void nvgpu_pmu_remove_support(struct gk20a *g, struct nvgpu_pmu *pmu);
|
||||
#define NVGPU_ECC_COUNTER_INIT_PMU(stat) \
|
||||
nvgpu_ecc_counter_init(g, &g->ecc.pmu.stat, #stat)
|
||||
|
||||
/*
|
||||
* @brief Remove ECC counter from the list and free the counter.
|
||||
*
|
||||
* @param stat [in] Address of pointer to struct nvgpu_ecc_stat.
|
||||
*
|
||||
*/
|
||||
#define NVGPU_ECC_COUNTER_FREE_PMU(stat) \
|
||||
nvgpu_ecc_counter_deinit(g, &g->ecc.pmu.stat)
|
||||
|
||||
#endif /* NVGPU_PMU_H */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user