[PATCH 4/8] amdgpu: limit maximum BAR0 size when attempting to enlarge (v2)
Darren Salt
devspam at moreofthesa.me.uk
Sun Dec 13 22:53:19 UTC 2020
This is coarse, applying to all dGPUs.
v2: If there are no advertised sizes small enough, limit to the smallest
available.
---
drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 +
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 31 ++++++++++++++++++----
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 9 +++++++
3 files changed, 36 insertions(+), 5 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index 327a0daf4a1d..c0e3e402023e 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -194,6 +194,7 @@ static const bool debug_evictions; /* = false */
extern int amdgpu_tmz;
extern int amdgpu_reset_method;
+extern int amdgpu_max_bar_size;
#ifdef CONFIG_DRM_AMDGPU_SI
extern int amdgpu_si_support;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index b0f8ad603147..c6495a86b280 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -909,6 +909,7 @@ void amdgpu_device_wb_free(struct amdgpu_device *adev, u32 wb)
int amdgpu_device_resize_fb_bar(struct amdgpu_device *adev)
{
int rbar_size, current_size;
+ int max_size = -1;
u64 current_bytes;
u32 available_sizes;
struct pci_bus *root;
@@ -924,13 +925,20 @@ int amdgpu_device_resize_fb_bar(struct amdgpu_device *adev)
current_bytes = pci_resource_len(adev->pdev, 0);
- /* Skip if the BIOS has already enabled large BAR, covering the VRAM */
- if (current_bytes >= adev->gmc.real_vram_size)
- return 0;
-
current_size = current_bytes ? pci_rebar_bytes_to_size(current_bytes) : -1;
rbar_size = pci_rebar_bytes_to_size(adev->gmc.real_vram_size);
+ if (amdgpu_max_bar_size >= 0) {
+ max_size = max(amdgpu_max_bar_size, 8); /* clamp to min. 256MB */
+ /* Skip if the maximum size is the current size */
+ if (current_size == max_size)
+ return 0;
+ rbar_size = max_size;
+ }
+ else if (current_bytes >= adev->gmc.real_vram_size)
+ /* Skip if the BIOS has already enabled large BAR, covering the VRAM */
+ return 0;
+
/* Check if the root BUS has 64bit memory resources */
root = adev->pdev->bus;
while (root->parent)
@@ -947,6 +955,19 @@ int amdgpu_device_resize_fb_bar(struct amdgpu_device *adev)
return 0;
available_sizes = pci_rebar_get_possible_sizes(adev->pdev, 0);
+ if (max_size >= 0) {
+ /* Cause larger sizes to be ignored unless that would leave
+ * no advertised sizes (which shouldn't happen).
+ */
+ r = available_sizes & ~(-1 << (max_size + 1));
+ if (!r) {
+ /* No smaller sizes, so use the smallest advertised */
+ r = ffs(r);
+ if (r)
+ r = 1 << (r - 1);
+ }
+ available_sizes = r;
+ }
if (available_sizes == 0)
return 0;
@@ -971,7 +992,7 @@ int amdgpu_device_resize_fb_bar(struct amdgpu_device *adev)
pci_release_resource(adev->pdev, 0);
for (;
- rbar_size >= 0 && rbar_size > current_size;
+ rbar_size >= 0;
rbar_size = fls(available_sizes & ~(-1 << rbar_size)) - 1
) {
r = pci_resize_resource(adev->pdev, 0, rbar_size);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index 06a5b6ae1c43..74baa8dafa5f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
@@ -150,6 +150,7 @@ int amdgpu_noretry;
int amdgpu_force_asic_type = -1;
int amdgpu_tmz = 0;
int amdgpu_reset_method = -1; /* auto */
+int amdgpu_max_bar_size = -1;
struct amdgpu_mgpu_info mgpu_info = {
.mutex = __MUTEX_INITIALIZER(mgpu_info.mutex),
@@ -765,6 +766,14 @@ module_param_named(tmz, amdgpu_tmz, int, 0444);
MODULE_PARM_DESC(reset_method, "GPU reset method (-1 = auto (default), 0 = legacy, 1 = mode0, 2 = mode1, 3 = mode2, 4 = baco)");
module_param_named(reset_method, amdgpu_reset_method, int, 0444);
+/**
+ * DOC: max_bar_size (int)
+ * The maximum BAR size, in megabytes. Only affects BARs which the BIOS hasn't already made larger.
+ * Unlimited by default.
+ */
+module_param_named(max_bar_size, amdgpu_max_bar_size, int, 0444);
+MODULE_PARM_DESC(max_bar_size, "Maximum FB BAR size, log2(megabytes) (default = -1, meaning unlimited; minimum is 8 for 256MB).");
+
static const struct pci_device_id pciidlist[] = {
#ifdef CONFIG_DRM_AMDGPU_SI
{0x1002, 0x6780, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TAHITI},
--
2.20.1
More information about the amd-gfx
mailing list