Unverified Commit 96f54a86 authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!6783 [OLK-5.10] fix HEST memory usage is too high

Merge Pull Request from: @kile2009 
 
Before:
wwk@localhost:~$ sudo cat /proc/vmallocinfo | grep ghes
0xffa0000003279000-0xffa00000033fb000 1581056 ghes_estatus_pool_init+0x3a/0xa0 pages=385 vmalloc N0=385
0xffa0000020001000-0xffa0000050083000 805838848 ghes_estatus_pool_init+0x3a/0xa0 pages=196737 vmalloc vpages N0=196737

After:
wwk@localhost:~$ sudo cat /proc/vmallocinfo | grep ghes
0xff60622282c29000-0xff60622282cab000  532480 ghes_estatus_pool_init+0x36/0x90 pages=129 vmalloc N0=129
 
 
Link:https://gitee.com/openeuler/kernel/pulls/6783

 

Reviewed-by: default avatarZhang Peng <zhangpeng362@huawei.com>
Reviewed-by: default avatarXiongfeng Wang <wangxiongfeng2@huawei.com>
Reviewed-by: default avatarXiaoFei Tan <tanxiaofei@huawei.com>
Signed-off-by: default avatarJialin Zhang <zhangjialin11@huawei.com>
parents 8a1f541c 1ea83ecc
Loading
Loading
Loading
Loading
+51 −0
Original line number Diff line number Diff line
@@ -37,6 +37,20 @@ EXPORT_SYMBOL_GPL(hest_disable);

static struct acpi_table_hest *__read_mostly hest_tab;

/*
 * Since GHES_ASSIST is not supported, skip initialization of GHES_ASSIST
 * structures for MCA.
 * During HEST parsing, detected MCA error sources are cached from early
 * table entries so that the Flags and Source Id fields from these cached
 * values are then referred to in later table entries to determine if the
 * encountered GHES_ASSIST structure should be initialized.
 */
static struct {
	struct acpi_hest_ia_corrected *cmc;
	struct acpi_hest_ia_machine_check *mc;
	struct acpi_hest_ia_deferred_check *dmc;
} mces;

static const int hest_esrc_len_tab[ACPI_HEST_TYPE_RESERVED] = {
	[ACPI_HEST_TYPE_IA32_CHECK] = -1,	/* need further calculation */
	[ACPI_HEST_TYPE_IA32_CORRECTED_CHECK] = -1,
@@ -64,22 +78,54 @@ static int hest_esrc_len(struct acpi_hest_header *hest_hdr)
		cmc = (struct acpi_hest_ia_corrected *)hest_hdr;
		len = sizeof(*cmc) + cmc->num_hardware_banks *
			sizeof(struct acpi_hest_ia_error_bank);
		mces.cmc = cmc;
	} else if (hest_type == ACPI_HEST_TYPE_IA32_CHECK) {
		struct acpi_hest_ia_machine_check *mc;
		mc = (struct acpi_hest_ia_machine_check *)hest_hdr;
		len = sizeof(*mc) + mc->num_hardware_banks *
			sizeof(struct acpi_hest_ia_error_bank);
		mces.mc = mc;
	} else if (hest_type == ACPI_HEST_TYPE_IA32_DEFERRED_CHECK) {
		struct acpi_hest_ia_deferred_check *mc;
		mc = (struct acpi_hest_ia_deferred_check *)hest_hdr;
		len = sizeof(*mc) + mc->num_hardware_banks *
			sizeof(struct acpi_hest_ia_error_bank);
		mces.dmc = mc;
	}
	BUG_ON(len == -1);

	return len;
};

/*
 * GHES and GHESv2 structures share the same format, starting from
 * Source Id and ending in Error Status Block Length (inclusive).
 */
static bool is_ghes_assist_struct(struct acpi_hest_header *hest_hdr)
{
	struct acpi_hest_generic *ghes;
	u16 related_source_id;

	if (hest_hdr->type != ACPI_HEST_TYPE_GENERIC_ERROR &&
	    hest_hdr->type != ACPI_HEST_TYPE_GENERIC_ERROR_V2)
		return false;

	ghes = (struct acpi_hest_generic *)hest_hdr;
	related_source_id = ghes->related_source_id;

	if (mces.cmc && mces.cmc->flags & ACPI_HEST_GHES_ASSIST &&
	    related_source_id == mces.cmc->header.source_id)
		return true;
	if (mces.mc && mces.mc->flags & ACPI_HEST_GHES_ASSIST &&
	    related_source_id == mces.mc->header.source_id)
		return true;
	if (mces.dmc && mces.dmc->flags & ACPI_HEST_GHES_ASSIST &&
	    related_source_id == mces.dmc->header.source_id)
		return true;

	return false;
}

int apei_hest_parse(apei_hest_func_t func, void *data)
{
	struct acpi_hest_header *hest_hdr;
@@ -106,6 +152,11 @@ int apei_hest_parse(apei_hest_func_t func, void *data)
			return -EINVAL;
		}

		if (is_ghes_assist_struct(hest_hdr)) {
			hest_hdr = (void *)hest_hdr + len;
			continue;
		}

		rc = func(hest_hdr, data);
		if (rc)
			return rc;