
From: Feng Tang <feng.tang@intel.com> mainline inclusion from mainline-v5.19-rc5 commit b4c9bf178ace26c52c9cac36f265ba95132a221d bugzilla: https://gitee.com/openeuler/kernel/issues/I8KS9A CVE: NA Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?i... ------------------------------------------- kmalloc will round up the request size to power of 2, and current iova_magazine's size is 1032 (1024+8) bytes, so each instance allocated will get 2048 bytes from kmalloc, causing around 1KB waste. Change IOVA_MAG_SIZE from 128 to 127 to make size of 'iova_magazine' 1024 bytes so that no memory will be wasted. Signed-off-by: Feng Tang <feng.tang@intel.com> Acked-by: Robin Murphy <robin.murphy@arm.com> Link: https://lore.kernel.org/r/20220703114450.15184-1-feng.tang@intel.com Signed-off-by: Joerg Roedel <jroedel@suse.de> Signed-off-by: Zhang Zekun <zhangzekun11@huawei.com> --- drivers/iommu/iova.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/iova.c b/drivers/iommu/iova.c index 203331b54970..2caf2aec9f56 100644 --- a/drivers/iommu/iova.c +++ b/drivers/iommu/iova.c @@ -792,7 +792,12 @@ split_and_remove_iova(struct iova_domain *iovad, struct iova *iova, * dynamic size tuning described in the paper. */ -#define IOVA_MAG_SIZE 128 +/* + * As kmalloc's buffer size is fixed to power of 2, 127 is chosen to + * assure size of 'iova_magazine' to be 1024 bytes, so that no memory + * will be wasted. + */ +#define IOVA_MAG_SIZE 127 struct iova_magazine { unsigned long size; -- 2.17.1