RE: [PATCH] drm/amdkfd: Remove Align VRAM allocations to 1MB on APU ASIC

2022-07-14 Thread Guo, Shikai
[AMD Official Use Only - General]

Thanks Felix comment, I will further debug this issue.

-Original Message-
From: Guo, Shikai 
Sent: Friday, July 15, 2022 11:21 AM
To: Kuehling, Felix ; amd-gfx@lists.freedesktop.org
Cc: Phillips, Daniel ; Ji, Ruili ; 
Liu, Aaron 
Subject: RE: [PATCH] drm/amdkfd: Remove Align VRAM allocations to 1MB on APU 
ASIC

[AMD Official Use Only - General]

This Felix comment, I will further debug this issue.

-Original Message-
From: Kuehling, Felix  
Sent: Wednesday, July 13, 2022 10:17 PM
To: Guo, Shikai ; amd-gfx@lists.freedesktop.org
Cc: Phillips, Daniel ; Ji, Ruili ; 
Liu, Aaron 
Subject: Re: [PATCH] drm/amdkfd: Remove Align VRAM allocations to 1MB on APU 
ASIC


Am 2022-07-13 um 05:14 schrieb shikai guo:
> From: Shikai Guo 
>
> While executing KFDMemoryTest.MMBench, test case will allocate 4KB size 
> memory 1000 times.
> Every time, user space will get 2M memory.APU VRAM is 512M, there is not 
> enough memory to be allocated.
> So the 2M aligned feature is not suitable for APU.
NAK. We can try to make the estimate of available VRAM more accurate. 
But in the end, this comes down to limitations of the VRAM manager and how it 
handles memory fragmentation.

A large discrepancy between total VRAM and available VRAM can have a few
reasons:

  * Big system memory means we need to reserve more space for page tables
  * Many small allocations causing lots of fragmentation. This may be
the result of memory leaks in previous tests

This patch can "fix" a situation where a leak caused excessive fragmentation. 
But that just papers over the leak. And it will cause the opposite problem for 
the new AvailableMemory test that checks that we can really allocate as much 
memory as we promised.

Regards,
   Felix


>
> guoshikai@guoshikai-MayanKD-RMB:~/linth/libhsakmt/tests/kfdtest/build$ 
> ./kfdtest --gtest_filter=KFDMemoryTest.MMBench
> [  ] Profile: Full Test
> [  ] HW capabilities: 0x9
> Note: Google Test filter = KFDMemoryTest.MMBench [==] Running 
> 1 test from 1 test case.
> [--] Global test environment set-up.
> [--] 1 test from KFDMemoryTest
> [ RUN  ] KFDMemoryTest.MMBench
> [  ] Found VRAM of 512MB.
> [  ] Available VRAM 328MB.
> [  ] Test (avg. ns) alloc   mapOne  umapOne   mapAll  umapAll 
> free
> [  ] 
> --
> [  ]   4K-SysMem-noSDMA 2656110350 5212 3787 3981 
>12372
> [  ]  64K-SysMem-noSDMA 42864 6648 3973 5223 3843 
>15100
> [  ]   2M-SysMem-noSDMA31290612614 4390 6254 4790 
>70260
> [  ]  32M-SysMem-noSDMA   4417812   130437216259768718500 
>   929562
> [  ]   1G-SysMem-noSDMA 132161000  2738000   583000  2181000   499000 
> 39091000
> [  ] 
> --
> /home/guoshikai/linth/libhsakmt/tests/kfdtest/src/KFDMemoryTest.cpp:92
> 2: Failure Value of: (hsaKmtAllocMemory(allocNode, bufSize, memFlags, 
> [i]))
>Actual: 6
> Expected: HSAKMT_STATUS_SUCCESS
> Which is: 0
> [  FAILED  ] KFDMemoryTest.MMBench (749 ms)
>
> fix this issue by adding different treatments for apu and dgpu
>
> Signed-off-by: ruili ji 
> Signed-off-by: shikai guo 
> ---
>   .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c   | 18 +-
>   1 file changed, 13 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> index d1657de5f875..2ad2cd5e3e8b 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> @@ -115,7 +115,9 @@ void amdgpu_amdkfd_reserve_system_mem(uint64_t size)
>* compromise that should work in most cases without reserving too
>* much memory for page tables unnecessarily (factor 16K, >> 14).
>*/
> -#define ESTIMATE_PT_SIZE(mem_size) max(((mem_size) >> 14), 
> AMDGPU_VM_RESERVED_VRAM)
> +
> +#define ESTIMATE_PT_SIZE(adev, mem_size)   (adev->flags & AMD_IS_APU) ? \
> +(mem_size >> 14) : max(((mem_size) >> 14), 
> +AMDGPU_VM_RESERVED_VRAM)
>   
>   static size_t amdgpu_amdkfd_acc_size(uint64_t size)
>   {
> @@ -142,7 +144,7 @@ static int amdgpu_amdkfd_reserve_mem_limit(struct 
> amdgpu_device *adev,
>   uint64_t size, u32 alloc_flag)
>   {
>   uint64_t reserved_for_pt =
> - ESTIMATE_PT_SIZE(amdgpu_amdkfd_total_mem_size);
> + ESTIMATE_PT_SIZE(adev, amdgpu_amdkfd_total_mem_size);
>   size_t acc_size, system_mem_needed, ttm_mem_needed, vram_needed;
>   int ret = 0;
>   
> @@ -156,12 +158,15 @@ static int amdgpu_amdkfd_reserve_mem_limit(struct 
> amdgpu_device *adev,
>   system_mem_needed = acc_size;
>   ttm_mem_needed = acc_size;
>   
> + if 

RE: [PATCH] drm/amdkfd: Remove Align VRAM allocations to 1MB on APU ASIC

2022-07-14 Thread Guo, Shikai
[AMD Official Use Only - General]

This Felix comment, I will further debug this issue.

-Original Message-
From: Kuehling, Felix  
Sent: Wednesday, July 13, 2022 10:17 PM
To: Guo, Shikai ; amd-gfx@lists.freedesktop.org
Cc: Phillips, Daniel ; Ji, Ruili ; 
Liu, Aaron 
Subject: Re: [PATCH] drm/amdkfd: Remove Align VRAM allocations to 1MB on APU 
ASIC


Am 2022-07-13 um 05:14 schrieb shikai guo:
> From: Shikai Guo 
>
> While executing KFDMemoryTest.MMBench, test case will allocate 4KB size 
> memory 1000 times.
> Every time, user space will get 2M memory.APU VRAM is 512M, there is not 
> enough memory to be allocated.
> So the 2M aligned feature is not suitable for APU.
NAK. We can try to make the estimate of available VRAM more accurate. 
But in the end, this comes down to limitations of the VRAM manager and how it 
handles memory fragmentation.

A large discrepancy between total VRAM and available VRAM can have a few
reasons:

  * Big system memory means we need to reserve more space for page tables
  * Many small allocations causing lots of fragmentation. This may be
the result of memory leaks in previous tests

This patch can "fix" a situation where a leak caused excessive fragmentation. 
But that just papers over the leak. And it will cause the opposite problem for 
the new AvailableMemory test that checks that we can really allocate as much 
memory as we promised.

Regards,
   Felix


>
> guoshikai@guoshikai-MayanKD-RMB:~/linth/libhsakmt/tests/kfdtest/build$ 
> ./kfdtest --gtest_filter=KFDMemoryTest.MMBench
> [  ] Profile: Full Test
> [  ] HW capabilities: 0x9
> Note: Google Test filter = KFDMemoryTest.MMBench [==] Running 
> 1 test from 1 test case.
> [--] Global test environment set-up.
> [--] 1 test from KFDMemoryTest
> [ RUN  ] KFDMemoryTest.MMBench
> [  ] Found VRAM of 512MB.
> [  ] Available VRAM 328MB.
> [  ] Test (avg. ns) alloc   mapOne  umapOne   mapAll  umapAll 
> free
> [  ] 
> --
> [  ]   4K-SysMem-noSDMA 2656110350 5212 3787 3981 
>12372
> [  ]  64K-SysMem-noSDMA 42864 6648 3973 5223 3843 
>15100
> [  ]   2M-SysMem-noSDMA31290612614 4390 6254 4790 
>70260
> [  ]  32M-SysMem-noSDMA   4417812   130437216259768718500 
>   929562
> [  ]   1G-SysMem-noSDMA 132161000  2738000   583000  2181000   499000 
> 39091000
> [  ] 
> --
> /home/guoshikai/linth/libhsakmt/tests/kfdtest/src/KFDMemoryTest.cpp:92
> 2: Failure Value of: (hsaKmtAllocMemory(allocNode, bufSize, memFlags, 
> [i]))
>Actual: 6
> Expected: HSAKMT_STATUS_SUCCESS
> Which is: 0
> [  FAILED  ] KFDMemoryTest.MMBench (749 ms)
>
> fix this issue by adding different treatments for apu and dgpu
>
> Signed-off-by: ruili ji 
> Signed-off-by: shikai guo 
> ---
>   .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c   | 18 +-
>   1 file changed, 13 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> index d1657de5f875..2ad2cd5e3e8b 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> @@ -115,7 +115,9 @@ void amdgpu_amdkfd_reserve_system_mem(uint64_t size)
>* compromise that should work in most cases without reserving too
>* much memory for page tables unnecessarily (factor 16K, >> 14).
>*/
> -#define ESTIMATE_PT_SIZE(mem_size) max(((mem_size) >> 14), 
> AMDGPU_VM_RESERVED_VRAM)
> +
> +#define ESTIMATE_PT_SIZE(adev, mem_size)   (adev->flags & AMD_IS_APU) ? \
> +(mem_size >> 14) : max(((mem_size) >> 14), 
> +AMDGPU_VM_RESERVED_VRAM)
>   
>   static size_t amdgpu_amdkfd_acc_size(uint64_t size)
>   {
> @@ -142,7 +144,7 @@ static int amdgpu_amdkfd_reserve_mem_limit(struct 
> amdgpu_device *adev,
>   uint64_t size, u32 alloc_flag)
>   {
>   uint64_t reserved_for_pt =
> - ESTIMATE_PT_SIZE(amdgpu_amdkfd_total_mem_size);
> + ESTIMATE_PT_SIZE(adev, amdgpu_amdkfd_total_mem_size);
>   size_t acc_size, system_mem_needed, ttm_mem_needed, vram_needed;
>   int ret = 0;
>   
> @@ -156,12 +158,15 @@ static int amdgpu_amdkfd_reserve_mem_limit(struct 
> amdgpu_device *adev,
>   system_mem_needed = acc_size;
>   ttm_mem_needed = acc_size;
>   
> + if (adev->flags & AMD_IS_APU)
> + vram_needed = size;
> + else
>   /*
>* Conservatively round up the allocation requirement to 2 MB
>* to avoid fragmentation caused by 4K allocations in the tail
>* 2M BO chunk.
>*/
> - vram_needed = ALIGN(size, 

Re: [PATCH 01/12] drm/amdgpu: Write masked value to control register

2022-07-14 Thread André Almeida
Às 13:44 de 14/07/22, Maíra Canal escreveu:
> On the dce_v6_0 and dce_v8_0 hpd tear down callback, the tmp variable
> should be written into the control register instead of 0.
> 
> Fixes: b00861b9 ("drm/amd/amdgpu: port of DCE v6 to new headers (v3)")
> Fixes: 2285b91c ("drm/amdgpu/dce8: simplify hpd code")
> Signed-off-by: Maíra Canal 

Series is Reviewed-by: André Almeida 


Re: Linux 5.19-rc6

2022-07-14 Thread Russell Currey
Hi Linus,

On Wed, 2022-07-13 at 14:32 -0700, Linus Torvalds wrote:
> On Wed, Jul 13, 2022 at 2:01 PM Alex Deucher 
> wrote:
> > 
> > If you want to apply Guenter's patch original patch:
> > https://patchwork.freedesktop.org/patch/490184/
> > That's fine with me.
> 
> Honestly, by this time I feel that it's too little, too late.
> 
> The ppc people apparently didn't care at all about the fact that this
> driver didn't compile.
> 
> At least Michael Ellerman and Daniel Axtens were cc'd on that thread
> with the proposed fix originally.
> 
> I don't see any replies from ppc people as to why it happened, even
> though apparently a bog-standard "make allmodconfig" just doesn't
> build.

I believe Michael Ellerman has been on holiday for some time, and
Daniel Axtens no longer works on powerpc (and wasn't the one that
submitted the patch, it was submitted by Paul Mackerras, who wasn't on
CC).

The proposed fix didn't get sent to linuxppc-dev either, so it's
unlikely many ppc people knew about it.

We certainly should have noticed allmodconfig was broken, and should
have more than just Michael keeping an eye on all his automated builds.

I would count this case as ignorance rather than apathy.

- ruscur


Re: [PATCH v2 05/29] drm/nouveau: Don't register backlight when another backlight should be used

2022-07-14 Thread Lyude Paul
Reviewed-by: Lyude Paul 

You also have permission to push this to drm-misc-whatever

On Tue, 2022-07-12 at 21:38 +0200, Hans de Goede wrote:
> Before this commit when we want userspace to use the acpi_video backlight
> device we register both the GPU's native backlight device and acpi_video's
> firmware acpi_video# backlight device. This relies on userspace preferring
> firmware type backlight devices over native ones.
> 
> Registering 2 backlight devices for a single display really is
> undesirable, don't register the GPU's native backlight device when
> another backlight device should be used.
> 
> Reviewed-by: Lyude Paul 
> Signed-off-by: Hans de Goede 
> ---
>  drivers/gpu/drm/nouveau/nouveau_backlight.c | 7 +++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/drivers/gpu/drm/nouveau/nouveau_backlight.c
> b/drivers/gpu/drm/nouveau/nouveau_backlight.c
> index a2141d3d9b1d..91c504c7b82c 100644
> --- a/drivers/gpu/drm/nouveau/nouveau_backlight.c
> +++ b/drivers/gpu/drm/nouveau/nouveau_backlight.c
> @@ -34,6 +34,8 @@
>  #include 
>  #include 
>  
> +#include 
> +
>  #include "nouveau_drv.h"
>  #include "nouveau_reg.h"
>  #include "nouveau_encoder.h"
> @@ -405,6 +407,11 @@ nouveau_backlight_init(struct drm_connector *connector)
> goto fail_alloc;
> }
>  
> +   if (!acpi_video_backlight_use_native()) {
> +   NV_INFO(drm, "Skipping nv_backlight registration\n");
> +   goto fail_alloc;
> +   }
> +
> if (!nouveau_get_backlight_name(backlight_name, bl)) {
> NV_ERROR(drm, "Failed to retrieve a unique name for the
> backlight interface\n");
> goto fail_alloc;

-- 
Cheers,
 Lyude Paul (she/her)
 Software Engineer at Red Hat



[pull] amdgpu, amdkfd, radeon drm-next-5.20

2022-07-14 Thread Alex Deucher
Hi Dave, Daniel,

A few more new things for 5.20.

The following changes since commit c5da61cf5bab30059f22ea368702c445ee87171a:

  drm/amdgpu/display: add missing FP_START/END checks dcn32_clk_mgr.c 
(2022-06-30 19:35:21 -0400)

are available in the Git repository at:

  https://gitlab.freedesktop.org/agd5f/linux.git 
tags/amd-drm-next-5.20-2022-07-14

for you to fetch changes up to b7be3ae759160aa3355ebeb0583f67fb9bda4dae:

  drm/amd/display: remove duplicate dcn314 includes (2022-07-13 20:57:05 -0400)


amd-drm-next-5.20-2022-07-14:

amdgpu:
- DCN3.2 updates
- DC SubVP support
- DP MST fixes
- Audio fixes
- DC code cleanup
- SMU13 updates
- Adjust GART size on newer APUs for S/G display
- Soft reset for GFX 11
- Soft reset for SDMA 6
- Add gfxoff status query for vangogh
- Improve BO domain pinning
- Fix timestamps for cursor only commits
- MES fixes
- DCN 3.1.4 support
- Misc fixes
- Misc code cleanup

amdkfd:
- Simplify GPUVM validation
- Unified memory for CWSR save/restore area
- fix possible list corruption on queue failure

radeon:
- Fix bogus power of two warning

UAPI:
- Unified memory for CWSR save/restore area for KFD
  Proposed userspace: 
https://lists.freedesktop.org/archives/amd-gfx/2022-June/080952.html


Alan Liu (1):
  drm/amd/display: Program ACP related register

Alex Deucher (11):
  drm/amdgpu: keep fbdev buffers pinned during suspend
  drm/amdgpu/display: disable prefer_shadow for generic fb helpers
  drm/amd/display: remove set but unused variable
  drm/amd/display: make get_refresh_rate() static
  drm/amd/display: fix non-x86/PPC64 compilation
  drm/amd/display: fix 32 bit compilation errors in dc_dmub_srv.c
  drm/amdgpu/gmc10: adjust gart size for parts that support S/G display
  drm/amdgpu: fix file permissions on some files
  drm/amd/display: make some dc_dmub_srv functions static
  drm/amd/display: attempt to fix the logic in commit_planes_for_stream()
  drm/amd/display: remove duplicate dcn314 includes

Alvin Lee (6):
  drm/amd/display: Add SubVP required code
  drm/amd/display: Change DET policy for MPO cases
  drm/amd/display: Make OPTC3 function accessible to other DCN
  drm/amd/display: Don't set dram clock change requirement for SubVP
  drm/amd/display: Maintain old audio programming sequence
  drm/amd/display: Exit SubVP if MPO in use

André Almeida (2):
  drm/amdpgu/debugfs: Simplify some exit paths
  drm/amd/pm: Implement get GFXOFF status for vangogh

Aric Cyr (3):
  drm/amd/display: 3.2.192
  drm/amd/display: 3.2.193
  drm/amd/display: 3.2.194

Aurabindo Pillai (5):
  drm/amd: Add debug mask for subviewport mclk switch
  drm/amd/display: remove stale debug setting
  drm/amd/display: Add callback to set dig mode
  drm/amd/display: Enable ODM combine default policy
  drm/amd/display: Add NBIO reg offsets to DC

Charlene Liu (1):
  drm/amd/display: add system info table log

Chris Park (4):
  drm/amd/display: Switch to correct DTO on HDMI
  drm/amd/display: Indicate stream change on ODM change
  drm/amd/display: OVT Update on InfoFrame and Mode Management
  drm/amd/display: Reduce SCDC Status Flags Definition

Dmytro Laktyushkin (2):
  drm/amd/display: disable timing sync b/w odm halves
  drm/amd/display: disable otg toggle w/a on boot

Duncan Ma (1):
  drm/amd/display: Add flag to modify MST delay

Eric Bernstein (3):
  drm/amd/display: Add function to set pixels per cycle
  drm/amd/display: Update gpuvm_max_page_table_levels IP param
  drm/amd/display: Fix null timing generator resource

Eric Huang (4):
  drm/amdkfd: add new flag for svm
  drm/amdkfd: change svm range evict
  drm/amdkfd: optimize svm range evict
  drm/amdkfd: bump KFD version for unified ctx save/restore memory

Ethan Wellenreiter (1):
  drm/amd/display: Re-implementing ARGB16161616 pixel format as 22

Evan Quan (2):
  drm/amd/pm: update SMU 13.0.0 driver_if header
  drm/amd/display: correct idle_power_optimizations disablement return value

Evgenii Krasnikov (1):
  drm/amd/display: add an option to skip wait for HPD when powering on eDP 
panel

Fangzhi Zuo (2):
  drm/amd/display: Fix dmub soft hang for PSR 1
  drm/amd/display: Ignore First MST Sideband Message Return Error

Guo Zhengkui (1):
  drm/amd/display: remove repeated includes

Hamza Mahfooz (2):
  drm/amd/display: enable PCON SST support for newer ASICs
  drm/amd/display: rename hdmi_frl_pcon_support

Harry Wentland (2):
  drm/amd/display: Move all linux includes into OS types
  drm/amd/display: Add DCN reg offsets to DC

Ilya Bakoulin (1):
  drm/amd/display: Fix black screen when disabling Freesync in OSD

Jack Xiao (7):
  drm/amdgpu/mes11: fix to unmap legacy queue
  drm/amdgpu/mes: fix 

[PATCH] drm/amdgpu: align between libdrm and drm api

2022-07-14 Thread Ruijing Dong
define HW_IP_VCN_UNIFIED the same as HW_IP_VCN_ENC

Signed-off-by: Ruijing Dong 
---
 include/uapi/drm/amdgpu_drm.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/uapi/drm/amdgpu_drm.h b/include/uapi/drm/amdgpu_drm.h
index 18d3246d636e..fe33db8441bc 100644
--- a/include/uapi/drm/amdgpu_drm.h
+++ b/include/uapi/drm/amdgpu_drm.h
@@ -560,6 +560,7 @@ struct drm_amdgpu_gem_va {
 #define AMDGPU_HW_IP_UVD_ENC  5
 #define AMDGPU_HW_IP_VCN_DEC  6
 #define AMDGPU_HW_IP_VCN_ENC  7
+#define AMDGPU_HW_IP_VCN_UNIFIED  AMDGPU_HW_IP_VCN_ENC
 #define AMDGPU_HW_IP_VCN_JPEG 8
 #define AMDGPU_HW_IP_NUM  9
 
-- 
2.25.1



Re: [PATCH v2 00/29] drm/kms: Stop registering multiple /sys/class/backlight devs for a single display

2022-07-14 Thread Lyude Paul
I assume you're probably good on review for the non-nouveau stuff, but if you
end up needing any help with that feel free to poke me!

On Tue, 2022-07-12 at 21:38 +0200, Hans de Goede wrote:
> Hi All,
> 
> As mentioned in my RFC titled "drm/kms: control display brightness through
> drm_connector properties":
> https://lore.kernel.org/dri-devel/0d188965-d809-81b5-74ce-7d30c49fe...@redhat.com/
> 
> The first step towards this is to deal with some existing technical debt
> in backlight handling on x86/ACPI boards, specifically we need to stop
> registering multiple /sys/class/backlight devs for a single display.
> 
> This series implements my RFC describing my plan for these cleanups:
> https://lore.kernel.org/dri-devel/98519ba0-7f18-201a-ea34-652f50343...@redhat.com/
> 
> This new version addresses the few small remarks made on version 1 (mainly
> changing patch 1/29) and more importantly this finishes the refactoring by
> else addressing all the bits from the "Other issues" section of
> the refactor RFC (resulting in patches 15-29 which are new in v2).
> 
> Please review and test! I hope to be able to make an immutable branch
> based on 5.20-rc1 + this series available for merging into the various
> touched subsystems once 5.20-rc2 is out.
> 
> Regards,
> 
> Hans
> 
> 
> Hans de Goede (29):
>   ACPI: video: Add acpi_video_backlight_use_native() helper
>   drm/i915: Don't register backlight when another backlight should be
>     used
>   drm/amdgpu: Don't register backlight when another backlight should be
>     used
>   drm/radeon: Don't register backlight when another backlight should be
>     used
>   drm/nouveau: Don't register backlight when another backlight should be
>     used
>   ACPI: video: Drop backlight_device_get_by_type() call from
>     acpi_video_get_backlight_type()
>   ACPI: video: Remove acpi_video_bus from list before tearing it down
>   ACPI: video: Simplify acpi_video_unregister_backlight()
>   ACPI: video: Make backlight class device registration a separate step
>   ACPI: video: Remove code to unregister acpi_video backlight when a
>     native backlight registers
>   drm/i915: Call acpi_video_register_backlight() (v2)
>   drm/nouveau: Register ACPI video backlight when nv_backlight
>     registration fails
>   drm/amdgpu: Register ACPI video backlight when skipping amdgpu
>     backlight registration
>   drm/radeon: Register ACPI video backlight when skipping radeon
>     backlight registration
>   ACPI: video: Refactor acpi_video_get_backlight_type() a bit
>   ACPI: video: Add Nvidia WMI EC brightness control detection
>   ACPI: video: Add Apple GMUX brightness control detection
>   platform/x86: apple-gmux: Stop calling acpi/video.h functions
>   platform/x86: toshiba_acpi: Stop using
>     acpi_video_set_dmi_backlight_type()
>   platform/x86: acer-wmi: Move backlight DMI quirks to
>     acpi/video_detect.c
>   platform/x86: asus-wmi: Drop DMI chassis-type check from backlight
>     handling
>   platform/x86: asus-wmi: Move acpi_backlight=vendor quirks to ACPI
>     video_detect.c
>   platform/x86: asus-wmi: Move acpi_backlight=native quirks to ACPI
>     video_detect.c
>   platform/x86: samsung-laptop: Move acpi_backlight=[vendor|native]
>     quirks to ACPI video_detect.c
>   ACPI: video: Remove acpi_video_set_dmi_backlight_type()
>   ACPI: video: Drop "Samsung X360" acpi_backlight=native quirk
>   ACPI: video: Drop Clevo/TUXEDO NL5xRU and NL5xNU acpi_backlight=native
>     quirks
>   ACPI: video: Fix indentation of video_detect_dmi_table[] entries
>   drm/todo: Add entry about dealing with brightness control on devices
>     with > 1 panel
> 
>  Documentation/gpu/todo.rst    |  68 +++
>  drivers/acpi/Kconfig  |   1 +
>  drivers/acpi/acpi_video.c |  59 ++-
>  drivers/acpi/video_detect.c   | 415 +++---
>  drivers/gpu/drm/Kconfig   |  12 +
>  .../gpu/drm/amd/amdgpu/atombios_encoders.c    |  14 +-
>  .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c |   9 +
>  drivers/gpu/drm/gma500/Kconfig    |   2 +
>  drivers/gpu/drm/i915/Kconfig  |   2 +
>  .../gpu/drm/i915/display/intel_backlight.c    |   7 +
>  drivers/gpu/drm/i915/display/intel_display.c  |   8 +
>  drivers/gpu/drm/i915/display/intel_panel.c    |   3 +
>  drivers/gpu/drm/i915/i915_drv.h   |   2 +
>  drivers/gpu/drm/nouveau/nouveau_backlight.c   |  14 +
>  drivers/gpu/drm/radeon/atombios_encoders.c    |   7 +
>  drivers/gpu/drm/radeon/radeon_encoders.c  |  11 +-
>  .../gpu/drm/radeon/radeon_legacy_encoders.c   |   7 +
>  drivers/platform/x86/acer-wmi.c   |  66 ---
>  drivers/platform/x86/apple-gmux.c |   3 -
>  drivers/platform/x86/asus-nb-wmi.c    |  21 -
>  drivers/platform/x86/asus-wmi.c   |  13 -
>  drivers/platform/x86/asus-wmi.h   |   2 -
>  drivers/platform/x86/eeepc-wmi.c  |  25 +-
>  

[PATCH] drm/ttm: fix missing NULL check in ttm_device_swapout

2022-07-14 Thread Felix Kuehling
Backport of Christian's patch 81b0d0e4f811 to amd-staging-drm-next. This
branch may be nearly obsolete, but this patch may still be worth
applying as it can serve as a template for backports to some release
branches. It fixes intermittent kernel oopses when memory is severely
overcommitted.

Signed-off-by: Felix Kuehling 
---
 drivers/gpu/drm/ttm/ttm_device.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/gpu/drm/ttm/ttm_device.c b/drivers/gpu/drm/ttm/ttm_device.c
index be24bb6cefd0..165a6cbb45d5 100644
--- a/drivers/gpu/drm/ttm/ttm_device.c
+++ b/drivers/gpu/drm/ttm/ttm_device.c
@@ -157,6 +157,9 @@ int ttm_device_swapout(struct ttm_device *bdev, struct 
ttm_operation_ctx *ctx,
list_for_each_entry(bo, >lru[j], lru) {
uint32_t num_pages = PFN_UP(bo->base.size);
 
+   if (!bo->resource)
+   continue;
+
ret = ttm_bo_swapout(bo, ctx, gfp_flags);
/* ttm_bo_swapout has dropped the lru_lock */
if (!ret)
-- 
2.32.0



Re: [PATCH] drm/amd/display: Add missing hard-float compile flags for PPC64 builds

2022-07-14 Thread Guenter Roeck

On 7/14/22 11:49, Melissa Wen wrote:

O 07/13, Alex Deucher wrote:

On Wed, Jul 13, 2022 at 7:09 PM Guenter Roeck  wrote:


On Wed, Jul 13, 2022 at 05:20:40PM -0400, Alex Deucher wrote:


The problem is not the FPU operations, but the fact that soft-float
and hard-float compiled code is linked together. The soft-float and
hard-float ABIs on powerpc are not compatible, so one ends up with
an object file which is partially soft-float and partially hard-float
compiled and thus uses different ABIs. That can only create chaos,
so the linker complains about it.


I get that, I just don't see why only DCN 3.1.x files have this
problem.  The DCN 2.x files should as well.



Seen in drivers/gpu/drm/amd/display/dc/clk_mgr/Makefile:

# prevent build errors regarding soft-float vs hard-float FP ABI tags
# this code is currently unused on ppc64, as it applies to Renoir APUs only
ifdef CONFIG_PPC64
CFLAGS_$(AMDDALPATH)/dc/clk_mgr/dcn21/rn_clk_mgr.o := $(call 
cc-option,-mno-gnu-attribute)
endif

Does that explain it ?


I would expect to see it in dcn20_resource.c and dcn30_clk_mgr.c for
example.  They follow the same pattern as the dcn 3.1.x files.  They
call functions that use FP, but maybe there is some FP code still in
those functions that we missed somehow.


Hi,

I'm a little late here, but I'm not able to reproduce the issue yet.
I have this setup:
- gcc 11.3.0
- binutils 2.38.50
- mainline kernel (torvalds) version: 5.19.0-rc6 (cross-compiling)
   -> make ARCH=powerpc CROSS_COMPILE=powerpc64-linux-gnu- allmodconfig
 => DRM_AMD_DC [=y] && HAS_IOMEM [=y] && DRM [=m] && DRM_AMDGPU [=m] && (X86 || 
PPC64 [=y]) && (!KCOV_INSTRUMENT_ALL [=n] || !KCOV_ENABLE_COMPARISONS [=n])
   -> make -j16 ARCH=powerpc CROSS_COMPILE=powerpc64-linux-gnu-

Am I missing something?

So, as Alex mentioned the possibility of some non-isolated FPU code in
3.1, I reviewed dcn31 code and my best bet so far is that the issue
is here:

https://github.com/torvalds/linux/blob/master/drivers/gpu/drm/amd/display/dc/dcn31/dcn31_resource.c#L1721

Although dcn31_update_soc_for_wm_a() is only called inside
dml/dcn31/dcn31_fpu:
- dc->res_pool->funcs->update_soc_for_wm_a(dc, context);

it's declared in dcn31_resource and has FPU code. So, we should move it
to dml/dcn31/dcn31_fpu.

However, as I can't reproduce the issue, I don't know if it addresses
the problem reported here and also if everything will be clean after
moving it.



I don't think that would solve anything. As I have tried to point out,
the problem is that code compiled with hard-float is linked together
with code compiled with soft-float. An alternate fix might be something
like the one attached below, but I don't know if that would be correct
and/or complete.


Guenter,

Can you provide more info about your setup: cross-compile or not, any
flags, branch, etc?



Nothing special. Same compile options as the ones you use, and it is a
cross-compile environment. I tried gcc 11.2.0 with binutils 2.36.1
and gcc 11.3.0 with binutils 2.38.

Guenter

---
diff --git a/drivers/gpu/drm/amd/display/dc/dcn31/Makefile 
b/drivers/gpu/drm/amd/display/dc/dcn31/Makefile
index ec041e3cda30..44ff6f196860 100644
--- a/drivers/gpu/drm/amd/display/dc/dcn31/Makefile
+++ b/drivers/gpu/drm/amd/display/dc/dcn31/Makefile
@@ -10,6 +10,8 @@
 #
 # Makefile for dcn31.

+CFLAGS_$(AMDDALPATH)/dc/dcn31/dcn31_resource.o := $(call 
cc-option,-mno-gnu-attribute)
+
 DCN31 = dcn31_resource.o dcn31_hubbub.o dcn31_hwseq.o dcn31_init.o 
dcn31_hubp.o \
dcn31_dccg.o dcn31_optc.o dcn31_dio_link_encoder.o dcn31_panel_cntl.o \
dcn31_apg.o dcn31_hpo_dp_stream_encoder.o dcn31_hpo_dp_link_encoder.o \
diff --git a/drivers/gpu/drm/amd/display/dc/dcn315/Makefile 
b/drivers/gpu/drm/amd/display/dc/dcn315/Makefile
index 59381d24800b..55fcae2d2aae 100644
--- a/drivers/gpu/drm/amd/display/dc/dcn315/Makefile
+++ b/drivers/gpu/drm/amd/display/dc/dcn315/Makefile
@@ -25,6 +25,8 @@

 DCN315 = dcn315_resource.o

+CFLAGS_$(AMDDALPATH)/dc/dcn315/$(DCN315) := $(call 
cc-option,-mno-gnu-attribute)
+
 AMD_DAL_DCN315 = $(addprefix $(AMDDALPATH)/dc/dcn315/,$(DCN315))

 AMD_DISPLAY_FILES += $(AMD_DAL_DCN315)
diff --git a/drivers/gpu/drm/amd/display/dc/dcn316/Makefile 
b/drivers/gpu/drm/amd/display/dc/dcn316/Makefile
index 819d44a9439b..7251ef9c1afb 100644
--- a/drivers/gpu/drm/amd/display/dc/dcn316/Makefile
+++ b/drivers/gpu/drm/amd/display/dc/dcn316/Makefile
@@ -25,6 +25,8 @@

 DCN316 = dcn316_resource.o

+CFLAGS_$(AMDDALPATH)/dc/dcn316/$(DCN316) := $(call 
cc-option,-mno-gnu-attribute)
+
 AMD_DAL_DCN316 = $(addprefix $(AMDDALPATH)/dc/dcn316/,$(DCN316))

 AMD_DISPLAY_FILES += $(AMD_DAL_DCN316)


Re: [PATCH v2 27/29] ACPI: video: Drop Clevo/TUXEDO NL5xRU and NL5xNU acpi_backlight=native quirks

2022-07-14 Thread Hans de Goede
Hi,

On 7/13/22 19:21, Limonciello, Mario wrote:
> [Public]
> 
> 
> 
>> -Original Message-
>> From: Werner Sembach 
>> Sent: Wednesday, July 13, 2022 12:08
>> To: Hans de Goede ; Ben Skeggs
>> ; Karol Herbst ; Lyude
>> ; Daniel Dadap ; Maarten
>> Lankhorst ; Maxime Ripard
>> ; Thomas Zimmermann ;
>> Jani Nikula ; Joonas Lahtinen
>> ; Rodrigo Vivi ;
>> Tvrtko Ursulin ; Deucher, Alexander
>> ; Koenig, Christian
>> ; p...@vger.kernel.org; Pan, Xinhui
>> ; Rafael J . Wysocki ; Mika
>> Westerberg ; Lukas Wunner
>> ; Mark Gross ; Andy
>> Shevchenko 
>> Cc: nouv...@lists.freedesktop.org; Daniel Vetter ; David
>> Airlie ; intel-gfx ; dri-
>> de...@lists.freedesktop.org; amd-gfx@lists.freedesktop.org; Len Brown
>> ; linux-a...@vger.kernel.org; platform-driver-
>> x...@vger.kernel.org
>> Subject: Re: [PATCH v2 27/29] ACPI: video: Drop Clevo/TUXEDO NL5xRU and
>> NL5xNU acpi_backlight=native quirks
>>
>> Hi,
>>
>> On 7/12/22 21:39, Hans de Goede wrote:
>>> acpi_backlight=native is the default for these, but as the comment
>>> explains the quirk was still necessary because even briefly registering
>>> the acpi_video0 backlight; and then unregistering it once the native
>>> driver showed up, was leading to issues.
>>>
>>> After the "ACPI: video: Make backlight class device registration
>>> a separate step" patch from earlier in this patch-series, we no
>>> longer briefly register the acpi_video0 backlight on systems where
>>> the native driver should be used.
>>>
>>> So this is no longer an issue an the quirks are no longer needed.
>>>
>>> Cc: Werner Sembach 
>>> Signed-off-by: Hans de Goede 
>>
>> Tested and can confirm: The quirks are no longer needed with this Patchset.
>>
>> Tested-by: Werner Sembach 
> 
> Probably should include this link tag in this commit too then as it fixes
> the Tong Fang systems too.
> 
> Link: https://bugzilla.kernel.org/show_bug.cgi?id=215683

Good point, I've added this to the version in my personal tree.

Regards,

Hans




> 
>>
>> Kind Regards,
>>
>> Werner Sembach
>>
>>> ---
>>>   drivers/acpi/video_detect.c | 75 -
>>>   1 file changed, 75 deletions(-)
>>>
>>> diff --git a/drivers/acpi/video_detect.c b/drivers/acpi/video_detect.c
>>> index 2a4d376a703e..4b9395d1bda7 100644
>>> --- a/drivers/acpi/video_detect.c
>>> +++ b/drivers/acpi/video_detect.c
>>> @@ -599,81 +599,6 @@ static const struct dmi_system_id
>> video_detect_dmi_table[] = {
>>> DMI_MATCH(DMI_BOARD_NAME, "N250P"),
>>> },
>>> },
>>> -   /*
>>> -* Clevo NL5xRU and NL5xNU/TUXEDO Aura 15 Gen1 and Gen2 have
>> both a
>>> -* working native and video interface. However the default detection
>>> -* mechanism first registers the video interface before unregistering
>>> -* it again and switching to the native interface during boot. This
>>> -* results in a dangling SBIOS request for backlight change for some
>>> -* reason, causing the backlight to switch to ~2% once per boot on
>> the
>>> -* first power cord connect or disconnect event. Setting the native
>>> -* interface explicitly circumvents this buggy behaviour, by avoiding
>>> -* the unregistering process.
>>> -*/
>>> -   {
>>> -   .callback = video_detect_force_native,
>>> -   .ident = "Clevo NL5xRU",
>>> -   .matches = {
>>> -   DMI_MATCH(DMI_SYS_VENDOR, "TUXEDO"),
>>> -   DMI_MATCH(DMI_BOARD_NAME, "NL5xRU"),
>>> -   },
>>> -   },
>>> -   {
>>> -   .callback = video_detect_force_native,
>>> -   .ident = "Clevo NL5xRU",
>>> -   .matches = {
>>> -   DMI_MATCH(DMI_SYS_VENDOR,
>> "SchenkerTechnologiesGmbH"),
>>> -   DMI_MATCH(DMI_BOARD_NAME, "NL5xRU"),
>>> -   },
>>> -   },
>>> -   {
>>> -   .callback = video_detect_force_native,
>>> -   .ident = "Clevo NL5xRU",
>>> -   .matches = {
>>> -   DMI_MATCH(DMI_SYS_VENDOR, "Notebook"),
>>> -   DMI_MATCH(DMI_BOARD_NAME, "NL5xRU"),
>>> -   },
>>> -   },
>>> -   {
>>> -   .callback = video_detect_force_native,
>>> -   .ident = "Clevo NL5xRU",
>>> -   .matches = {
>>> -   DMI_MATCH(DMI_SYS_VENDOR, "TUXEDO"),
>>> -   DMI_MATCH(DMI_BOARD_NAME, "AURA1501"),
>>> -   },
>>> -   },
>>> -   {
>>> -   .callback = video_detect_force_native,
>>> -   .ident = "Clevo NL5xRU",
>>> -   .matches = {
>>> -   DMI_MATCH(DMI_SYS_VENDOR, "TUXEDO"),
>>> -   DMI_MATCH(DMI_BOARD_NAME, "EDUBOOK1502"),
>>> -   },
>>> -   },
>>> -   {
>>> -   .callback = video_detect_force_native,
>>> -   .ident = "Clevo NL5xNU",
>>> -   .matches = {
>>> -   DMI_MATCH(DMI_SYS_VENDOR, "TUXEDO"),
>>> -   DMI_MATCH(DMI_BOARD_NAME, "NL5xNU"),
>>> -   },
>>> -   },
>>> -   {
>>> -   .callback = video_detect_force_native,
>>> -   .ident = "Clevo NL5xNU",
>>> -   .matches = {
>>> -   DMI_MATCH(DMI_SYS_VENDOR,
>> "SchenkerTechnologiesGmbH"),
>>> -   DMI_MATCH(DMI_BOARD_NAME, "NL5xNU"),
>>> -   },
>>> -   },
>>> -   

Re: [PATCH 09/10] drm/amdgpu: add gang submit backend

2022-07-14 Thread Luben Tuikov
Inlined:

On 2022-07-14 06:39, Christian König wrote:
> Allows submitting jobs as gang which needs to run on multiple
> engines at the same time.
> 
> Basic idea is that we have a global gang submit fence representing when the
> gang leader is finally pushed to run on the hardware last.
> 
> Jobs submitted as gang are never re-submitted in case of a GPU reset since 
> this
> won't work and will just deadlock the hardware immediately again.
> 
> Signed-off-by: Christian König 
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu.h|  3 ++
>  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 34 ++
>  drivers/gpu/drm/amd/amdgpu/amdgpu_job.c| 28 --
>  drivers/gpu/drm/amd/amdgpu/amdgpu_job.h|  3 ++
>  4 files changed, 66 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> index 2871a3e3801f..19308db52984 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> @@ -881,6 +881,7 @@ struct amdgpu_device {
>   u64 fence_context;
>   unsignednum_rings;
>   struct amdgpu_ring  *rings[AMDGPU_MAX_RINGS];
> + struct dma_fence __rcu  *gang_submit;
>   boolib_pool_ready;
>   struct amdgpu_sa_managerib_pools[AMDGPU_IB_POOL_MAX];
>   struct amdgpu_sched 
> gpu_sched[AMDGPU_HW_IP_NUM][AMDGPU_RING_PRIO_MAX];
> @@ -1288,6 +1289,8 @@ u32 amdgpu_device_pcie_port_rreg(struct amdgpu_device 
> *adev,
>   u32 reg);
>  void amdgpu_device_pcie_port_wreg(struct amdgpu_device *adev,
>   u32 reg, u32 v);
> +struct dma_fence *amdgpu_device_switch_gang(struct amdgpu_device *adev,
> + struct dma_fence *gang);
>  
>  /* atpx handler */
>  #if defined(CONFIG_VGA_SWITCHEROO)
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> index e1c9587f659b..f80beb7208c0 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> @@ -3499,6 +3499,7 @@ int amdgpu_device_init(struct amdgpu_device *adev,
>   adev->gmc.gart_size = 512 * 1024 * 1024;
>   adev->accel_working = false;
>   adev->num_rings = 0;
> + RCU_INIT_POINTER(adev->gang_submit, dma_fence_get_stub());
>   adev->mman.buffer_funcs = NULL;
>   adev->mman.buffer_funcs_ring = NULL;
>   adev->vm_manager.vm_pte_funcs = NULL;
> @@ -3979,6 +3980,7 @@ void amdgpu_device_fini_sw(struct amdgpu_device *adev)
>   release_firmware(adev->firmware.gpu_info_fw);
>   adev->firmware.gpu_info_fw = NULL;
>   adev->accel_working = false;
> + dma_fence_put(rcu_dereference_protected(adev->gang_submit, true));
>  
>   amdgpu_reset_fini(adev);
>  
> @@ -5905,3 +5907,35 @@ void amdgpu_device_pcie_port_wreg(struct amdgpu_device 
> *adev,
>   (void)RREG32(data);
>   spin_unlock_irqrestore(>pcie_idx_lock, flags);
>  }
> +
> +/**
> + * amdgpu_device_switch_gang - switch to a new gang
> + * @adev: amdgpu_device pointer
> + * @gang: the gang to switch to
> + *
> + * Try to switch to a new gang or return a reference to the current gang if 
> that
> + * isn't possible.

If you're redoing this patch (as it seems you would given Andrey's comment),
I'd drop mentioning the return result as it makes it a bit confusing being at 
the end
and referring to something mentioned earlier in the sentence. Perhaps just this
would suffice:

 Try to switch to a new gang.

> + * Returns: Either NULL if we switched correctly or a reference to the 
> existing
> + * gang.

Here you explain the return result, I'd drop the "Either" and say this:

 Returns NULL if we switched to the new gang, or a reference to
 the current gang.

No need for a semi-colon.

Regards,
Luben

> + */
> +struct dma_fence *amdgpu_device_switch_gang(struct amdgpu_device *adev,
> + struct dma_fence *gang)
> +{
> + struct dma_fence *old = NULL;
> +
> + do {
> + dma_fence_put(old);
> + old = dma_fence_get_rcu_safe(>gang_submit);
> +
> + if (old == gang)
> + break;
> +
> + if (!dma_fence_is_signaled(old))
> + return old;
> +
> + } while (cmpxchg((struct dma_fence __force **)>gang_submit,
> +  old, gang) != old);
> +
> + dma_fence_put(old);
> + return NULL;
> +}
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
> index 3255b2fca611..f3a1fdbd41a3 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
> @@ -180,11 +180,29 @@ static void amdgpu_job_free_cb(struct drm_sched_job 
> *s_job)
>   kfree(job);
>  }
>  
> +void 

Re: [PATCH 01/12] drm/amdgpu: Write masked value to control register

2022-07-14 Thread André Almeida
Às 16:14 de 14/07/22, Alex Deucher escreveu:
> On Thu, Jul 14, 2022 at 3:05 PM André Almeida  wrote:
>>
>> Hi Maíra,
>>
>> Thank you for your patch,
>>
>> Às 13:44 de 14/07/22, Maíra Canal escreveu:
>>> On the dce_v6_0 and dce_v8_0 hpd tear down callback, the tmp variable
>>> should be written into the control register instead of 0.
>>>
>>
>> Why? I do see that tmp was unused before your patch, but why should we
>> write it into this register? Did you manage to test this somehow?
> 
> The patch is correct.  We should only be clearing the enable bit in
> this case, not the entire register.  Clearing the other fields could
> cause spurious hotplug events as it affects the short and long pulse
> times for the HPD pin.
> 

Got it, nice catch Maíra :) Next time, please add this kind of
information in the commit message.


[PATCH v2 2/2] Documentation/gpu: Add GFXOFF section

2022-07-14 Thread André Almeida
Add a GFXOFF section at "GPU Power Controls" file, explaining what it is
and how userspace can interact with it.

Signed-off-by: André Almeida 
---
Changes from v1: file created

 Documentation/gpu/amdgpu/thermal.rst | 41 
 1 file changed, 41 insertions(+)

diff --git a/Documentation/gpu/amdgpu/thermal.rst 
b/Documentation/gpu/amdgpu/thermal.rst
index 8aeb0186c9ef..14c0fb874cf6 100644
--- a/Documentation/gpu/amdgpu/thermal.rst
+++ b/Documentation/gpu/amdgpu/thermal.rst
@@ -63,3 +63,44 @@ gpu_metrics
 
 .. kernel-doc:: drivers/gpu/drm/amd/pm/amdgpu_pm.c
:doc: gpu_metrics
+
+GFXOFF
+==
+
+GFXOFF is a feature found in some mobile GPUs that saves power consumption. The
+card's firmware uses RLC (RunList Controller) to power off the gfx engine
+dynamically when there is no workload on gfx pipe and puts gfx into "idle"
+state. GFXOFF is on by default on supported GPUs.
+
+Userspace can interact with GFXOFF through a debugfs interface:
+
+``amdgpu_gfxoff``
+-
+
+Use it to enable/disable GFXOFF, and to check if it's current 
enabled/disabled::
+
+  $ xxd -l1 -p /sys/kernel/debug/dri/0/amdgpu_gfxoff
+  01
+
+- Write 0 to disable it, and 1 to enable it.
+- Read 0 means it's disabled, 1 it's enabled.
+
+If it's enabled, that means that the GPU is free to enter into GFXOFF mode as
+needed. Disabled means that it will never enter GFXOFF mode.
+
+``amdgpu_gfxoff_status``
+
+
+Read it to check current GFXOFF's status of a GPU::
+
+  $ xxd -l1 -p /sys/kernel/debug/dri/0/amdgpu_gfxoff_status
+  02
+
+- 0: GPU is in GFXOFF state, the gfx engine is powered down.
+- 1: Transition out of GFXOFF state
+- 2: Not in GFXOFF state
+- 3: Transition into GFXOFF state
+
+If GFXOFF is enabled, the value will be transitioning around [0, 3], always
+getting into 0 when possible. When it's disabled, it's always at 2. Returns
+``-EINVAL`` if it's not supported.
-- 
2.37.0



[PATCH v2 1/2] drm/amd/debugfs: Expose GFXOFF state to userspace

2022-07-14 Thread André Almeida
GFXOFF has two different "state" values: one to define if the GPU is
allowed/disallowed to enter GFXOFF, usually called state; and another
one to define if currently GFXOFF is being used, usually called status.
Even when GFXOFF is allowed, GPU firmware can decide to not used it
accordingly to the GPU load.

Userspace can allow/disallow GPUs to enter into GFXOFF via debugfs. The
kernel maintains a counter of requests for GFXOFF (gfx_off_req_count)
that should be decreased to allow GFXOFF and increased to disallow.

The issue with this interface is that userspace can't be sure if GFXOFF
is currently allowed. Even by checking amdgpu_gfxoff file, one might get
an ambiguous 2, that means that GPU is currently out of GFXOFF, but that
can be either because it's currently disallowed or because it's allowed
but given the current GPU load it's enabled. Then, userspace needs to
rely on the fact that GFXOFF is enabled by default on boot and to track
this information.

To make userspace life easier and GFXOFF more reliable, return the
current state of GFXOFF to userspace when reading amdgpu_gfxoff with the
same semantics of writing: 0 means not allowed, not 0 means allowed.

Expose the current status of GFXOFF through a new file,
amdgpu_gfxoff_status.

Signed-off-by: André Almeida 
---
Changes from v1: none

 drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 49 -
 1 file changed, 47 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
index f3b3c688e4e7..e2eec985adb3 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
@@ -1117,13 +1117,50 @@ static ssize_t amdgpu_debugfs_gfxoff_read(struct file 
*f, char __user *buf,
}
 
while (size) {
-   uint32_t value;
+   u32 value = adev->gfx.gfx_off_state;
+
+   r = put_user(value, (u32 *)buf);
+   if (r)
+   goto out;
+
+   result += 4;
+   buf += 4;
+   *pos += 4;
+   size -= 4;
+   }
+
+   r = result;
+out:
+   pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
+   pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
+
+   return r;
+}
+
+static ssize_t amdgpu_debugfs_gfxoff_status_read(struct file *f, char __user 
*buf,
+size_t size, loff_t *pos)
+{
+   struct amdgpu_device *adev = file_inode(f)->i_private;
+   ssize_t result = 0;
+   int r;
+
+   if (size & 0x3 || *pos & 0x3)
+   return -EINVAL;
+
+   r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
+   if (r < 0) {
+   pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
+   return r;
+   }
+
+   while (size) {
+   u32 value;
 
r = amdgpu_get_gfx_off_status(adev, );
if (r)
goto out;
 
-   r = put_user(value, (uint32_t *)buf);
+   r = put_user(value, (u32 *)buf);
if (r)
goto out;
 
@@ -1206,6 +1243,12 @@ static const struct file_operations 
amdgpu_debugfs_gfxoff_fops = {
.llseek = default_llseek
 };
 
+static const struct file_operations amdgpu_debugfs_gfxoff_status_fops = {
+   .owner = THIS_MODULE,
+   .read = amdgpu_debugfs_gfxoff_status_read,
+   .llseek = default_llseek
+};
+
 static const struct file_operations *debugfs_regs[] = {
_debugfs_regs_fops,
_debugfs_regs2_fops,
@@ -1217,6 +1260,7 @@ static const struct file_operations *debugfs_regs[] = {
_debugfs_wave_fops,
_debugfs_gpr_fops,
_debugfs_gfxoff_fops,
+   _debugfs_gfxoff_status_fops,
 };
 
 static const char *debugfs_regs_names[] = {
@@ -1230,6 +1274,7 @@ static const char *debugfs_regs_names[] = {
"amdgpu_wave",
"amdgpu_gpr",
"amdgpu_gfxoff",
+   "amdgpu_gfxoff_status",
 };
 
 /**
-- 
2.37.0



Re: [PATCH 01/12] drm/amdgpu: Write masked value to control register

2022-07-14 Thread Alex Deucher
On Thu, Jul 14, 2022 at 3:05 PM André Almeida  wrote:
>
> Hi Maíra,
>
> Thank you for your patch,
>
> Às 13:44 de 14/07/22, Maíra Canal escreveu:
> > On the dce_v6_0 and dce_v8_0 hpd tear down callback, the tmp variable
> > should be written into the control register instead of 0.
> >
>
> Why? I do see that tmp was unused before your patch, but why should we
> write it into this register? Did you manage to test this somehow?

The patch is correct.  We should only be clearing the enable bit in
this case, not the entire register.  Clearing the other fields could
cause spurious hotplug events as it affects the short and long pulse
times for the HPD pin.

Alex

>
> > Fixes: b00861b9 ("drm/amd/amdgpu: port of DCE v6 to new headers (v3)")
> > Fixes: 2285b91c ("drm/amdgpu/dce8: simplify hpd code")
>
> Checking both commits, I can see that 0 is written at `mmDC_HPD1_CONTROL
> + N` register in _hpd_fini() in them, so if you are trying to fix the
> commit that inserted that behavior, I think aren't those ones. For instance:
>
> $ git show 2285b91c
>
> [...]
>
> @@ -479,28 +372,11 @@ static void dce_v8_0_hpd_fini(struct amdgpu_device
> *adev)
> list_for_each_entry(connector, >mode_config.connector_list,
> head) {
> struct amdgpu_connector *amdgpu_connector =
> to_amdgpu_connector(connector);
>
> -   switch (amdgpu_connector->hpd.hpd) {
> -   case AMDGPU_HPD_1:
> -   WREG32(mmDC_HPD1_CONTROL, 0);
> -   break;
> -   case AMDGPU_HPD_2:
> -   WREG32(mmDC_HPD2_CONTROL, 0);
> -   break;
> -   case AMDGPU_HPD_3:
> -   WREG32(mmDC_HPD3_CONTROL, 0);
> -   break;
> -   case AMDGPU_HPD_4:
> -   WREG32(mmDC_HPD4_CONTROL, 0);
> -   break;
> -   case AMDGPU_HPD_5:
> -   WREG32(mmDC_HPD5_CONTROL, 0);
> -   break;
> -   case AMDGPU_HPD_6:
> -   WREG32(mmDC_HPD6_CONTROL, 0);
> -   break;
> -   default:
> -   break;
> -   }
> +   if (amdgpu_connector->hpd.hpd >= adev->mode_info.num_hpd)
> +   continue;
> +
> +   WREG32(mmDC_HPD1_CONTROL +
> hpd_offsets[amdgpu_connector->hpd.hpd], 0);
> +
>
> 0 was the valued written here before this commit. The commit basically
> replaces the switch case with a sum in this snippet.
>
> thanks,
> andré


Re: [PATCH 10/10] drm/amdgpu: add gang submit frontend v2

2022-07-14 Thread Andrey Grodzovsky

Acked-by: Andrey Grodzovsky 

Andrey

On 2022-07-14 06:39, Christian König wrote:

Allows submitting jobs as gang which needs to run on multiple engines at the
same time.

All members of the gang get the same implicit, explicit and VM dependencies. So
no gang member will start running until everything else is ready.

The last job is considered the gang leader (usually a submission to the GFX
ring) and used for signaling output dependencies.

Each job is remembered individually as user of a buffer object, so there is no
joining of work at the end.

v2: rebase and fix review comments from Andrey and Yogesh

Signed-off-by: Christian König 
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c| 256 ++
  drivers/gpu/drm/amd/amdgpu/amdgpu_cs.h|  10 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h |  12 +-
  3 files changed, 183 insertions(+), 95 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
index 88f491dc7ca2..e1c41db20efb 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
@@ -69,6 +69,7 @@ static int amdgpu_cs_p1_ib(struct amdgpu_cs_parser *p,
   unsigned int *num_ibs)
  {
struct drm_sched_entity *entity;
+   unsigned int i;
int r;
  
  	r = amdgpu_ctx_get_entity(p->ctx, chunk_ib->ip_type,

@@ -77,17 +78,28 @@ static int amdgpu_cs_p1_ib(struct amdgpu_cs_parser *p,
if (r)
return r;
  
-	/* Abort if there is no run queue associated with this entity.

-* Possibly because of disabled HW IP*/
+   /*
+* Abort if there is no run queue associated with this entity.
+* Possibly because of disabled HW IP.
+*/
if (entity->rq == NULL)
return -EINVAL;
  
-	/* Currently we don't support submitting to multiple entities */

-   if (p->entity && p->entity != entity)
+   /* Check if we can add this IB to some existing job */
+   for (i = 0; i < p->gang_size; ++i) {
+   if (p->entities[i] == entity)
+   goto found;
+   }
+
+   /* If not increase the gang size if possible */
+   if (i == AMDGPU_CS_GANG_SIZE)
return -EINVAL;
  
-	p->entity = entity;

-   ++(*num_ibs);
+   p->entities[i] = entity;
+   p->gang_size = i + 1;
+
+found:
+   ++(num_ibs[i]);
return 0;
  }
  
@@ -161,11 +173,12 @@ static int amdgpu_cs_pass1(struct amdgpu_cs_parser *p,

   union drm_amdgpu_cs *cs)
  {
struct amdgpu_fpriv *fpriv = p->filp->driver_priv;
+   unsigned int num_ibs[AMDGPU_CS_GANG_SIZE] = { };
struct amdgpu_vm *vm = >vm;
uint64_t *chunk_array_user;
uint64_t *chunk_array;
-   unsigned size, num_ibs = 0;
uint32_t uf_offset = 0;
+   unsigned int size;
int ret;
int i;
  
@@ -231,7 +244,7 @@ static int amdgpu_cs_pass1(struct amdgpu_cs_parser *p,

if (size < sizeof(struct drm_amdgpu_cs_chunk_ib))
goto free_partial_kdata;
  
-			ret = amdgpu_cs_p1_ib(p, p->chunks[i].kdata, _ibs);

+   ret = amdgpu_cs_p1_ib(p, p->chunks[i].kdata, num_ibs);
if (ret)
goto free_partial_kdata;
break;
@@ -268,21 +281,28 @@ static int amdgpu_cs_pass1(struct amdgpu_cs_parser *p,
}
}
  
-	ret = amdgpu_job_alloc(p->adev, num_ibs, >job, vm);

-   if (ret)
-   goto free_all_kdata;
+   if (!p->gang_size)
+   return -EINVAL;
  
-	ret = drm_sched_job_init(>job->base, p->entity, >vm);

-   if (ret)
-   goto free_all_kdata;
+   for (i = 0; i < p->gang_size; ++i) {
+   ret = amdgpu_job_alloc(p->adev, num_ibs[i], >jobs[i], vm);
+   if (ret)
+   goto free_all_kdata;
+
+   ret = drm_sched_job_init(>jobs[i]->base, p->entities[i],
+>vm);
+   if (ret)
+   goto free_all_kdata;
+   }
+   p->gang_leader = p->jobs[p->gang_size - 1];
  
-	if (p->ctx->vram_lost_counter != p->job->vram_lost_counter) {

+   if (p->ctx->vram_lost_counter != p->gang_leader->vram_lost_counter) {
ret = -ECANCELED;
goto free_all_kdata;
}
  
  	if (p->uf_entry.tv.bo)

-   p->job->uf_addr = uf_offset;
+   p->gang_leader->uf_addr = uf_offset;
kvfree(chunk_array);
  
  	/* Use this opportunity to fill in task info for the vm */

@@ -304,22 +324,18 @@ static int amdgpu_cs_pass1(struct amdgpu_cs_parser *p,
return ret;
  }
  
-static int amdgpu_cs_p2_ib(struct amdgpu_cs_parser *p,

-  struct amdgpu_cs_chunk *chunk,
-  unsigned int *num_ibs,
-  unsigned int *ce_preempt,
-  

Re: [PATCH 02/10] drm/amdgpu: Protect the amdgpu_bo_list list with a mutex v2

2022-07-14 Thread Luben Tuikov
Tested-by: Luben Tuikov 

This passes all IGT amd_cs_nop tests.

Regards,
Luben

On 2022-07-14 06:38, Christian König wrote:
> From: Luben Tuikov 
> 
> Protect the struct amdgpu_bo_list with a mutex. This is used during command
> submission in order to avoid buffer object corruption as recorded in
> the link below.
> 
> v2 (chk): Keep the mutex looked for the whole CS to avoid using the
> list from multiple CS threads at the same time.
> 
> Suggested-by: Christian König 
> Cc: Alex Deucher 
> Cc: Andrey Grodzovsky 
> Cc: Vitaly Prosyak 
> Link: 
> https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgitlab.freedesktop.org%2Fdrm%2Famd%2F-%2Fissues%2F2048data=05%7C01%7Cluben.tuikov%40amd.com%7C13c905354c8b49ca582c08da658514fe%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637933919507590618%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7Csdata=CIO%2B%2BfexpAQFjyyy%2B6ZeTXQEEyrR9RIei3wEFq4OIaI%3Dreserved=0
> Signed-off-by: Luben Tuikov 
> Signed-off-by: Christian König 
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c |  3 ++-
>  drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h |  4 
>  drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c  | 16 +---
>  3 files changed, 19 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
> index 714178f1b6c6..2168163aad2d 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
> @@ -40,7 +40,7 @@ static void amdgpu_bo_list_free_rcu(struct rcu_head *rcu)
>  {
>   struct amdgpu_bo_list *list = container_of(rcu, struct amdgpu_bo_list,
>  rhead);
> -
> + mutex_destroy(>bo_list_mutex);
>   kvfree(list);
>  }
>  
> @@ -136,6 +136,7 @@ int amdgpu_bo_list_create(struct amdgpu_device *adev, 
> struct drm_file *filp,
>  
>   trace_amdgpu_cs_bo_status(list->num_entries, total_size);
>  
> + mutex_init(>bo_list_mutex);
>   *result = list;
>   return 0;
>  
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h
> index 529d52a204cf..9caea1688fc3 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h
> @@ -47,6 +47,10 @@ struct amdgpu_bo_list {
>   struct amdgpu_bo *oa_obj;
>   unsigned first_userptr;
>   unsigned num_entries;
> +
> + /* Protect access during command submission.
> +  */
> + struct mutex bo_list_mutex;
>  };
>  
>  int amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id,
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> index b28af04b0c3e..d8f1335bc68f 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> @@ -519,6 +519,8 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser 
> *p,
>   return r;
>   }
>  
> + mutex_lock(>bo_list->bo_list_mutex);
> +
>   /* One for TTM and one for the CS job */
>   amdgpu_bo_list_for_each_entry(e, p->bo_list)
>   e->tv.num_shared = 2;
> @@ -651,6 +653,7 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser 
> *p,
>   kvfree(e->user_pages);
>   e->user_pages = NULL;
>   }
> + mutex_unlock(>bo_list->bo_list_mutex);
>   }
>   return r;
>  }
> @@ -690,9 +693,11 @@ static void amdgpu_cs_parser_fini(struct 
> amdgpu_cs_parser *parser, int error,
>  {
>   unsigned i;
>  
> - if (error && backoff)
> + if (error && backoff) {
>   ttm_eu_backoff_reservation(>ticket,
>  >validated);
> + mutex_unlock(>bo_list->bo_list_mutex);
> + }
>  
>   for (i = 0; i < parser->num_post_deps; i++) {
>   drm_syncobj_put(parser->post_deps[i].syncobj);
> @@ -832,12 +837,16 @@ static int amdgpu_cs_vm_handling(struct 
> amdgpu_cs_parser *p)
>   continue;
>  
>   r = amdgpu_vm_bo_update(adev, bo_va, false);
> - if (r)
> + if (r) {
> + mutex_unlock(>bo_list->bo_list_mutex);
>   return r;
> + }
>  
>   r = amdgpu_sync_fence(>job->sync, bo_va->last_pt_update);
> - if (r)
> + if (r) {
> + mutex_unlock(>bo_list->bo_list_mutex);
>   return r;
> + }
>   }
>  
>   r = amdgpu_vm_handle_moved(adev, vm);
> @@ -1278,6 +1287,7 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p,
>  
>   ttm_eu_fence_buffer_objects(>ticket, >validated, p->fence);
>   mutex_unlock(>adev->notifier_lock);
> + mutex_unlock(>bo_list->bo_list_mutex);
>  
>   return 0;
>  

Regards,
-- 
Luben


Re: [PATCH 01/12] drm/amdgpu: Write masked value to control register

2022-07-14 Thread André Almeida
Hi Maíra,

Thank you for your patch,

Às 13:44 de 14/07/22, Maíra Canal escreveu:
> On the dce_v6_0 and dce_v8_0 hpd tear down callback, the tmp variable
> should be written into the control register instead of 0.
> 

Why? I do see that tmp was unused before your patch, but why should we
write it into this register? Did you manage to test this somehow?

> Fixes: b00861b9 ("drm/amd/amdgpu: port of DCE v6 to new headers (v3)")
> Fixes: 2285b91c ("drm/amdgpu/dce8: simplify hpd code")

Checking both commits, I can see that 0 is written at `mmDC_HPD1_CONTROL
+ N` register in _hpd_fini() in them, so if you are trying to fix the
commit that inserted that behavior, I think aren't those ones. For instance:

$ git show 2285b91c

[...]

@@ -479,28 +372,11 @@ static void dce_v8_0_hpd_fini(struct amdgpu_device
*adev)
list_for_each_entry(connector, >mode_config.connector_list,
head) {
struct amdgpu_connector *amdgpu_connector =
to_amdgpu_connector(connector);

-   switch (amdgpu_connector->hpd.hpd) {
-   case AMDGPU_HPD_1:
-   WREG32(mmDC_HPD1_CONTROL, 0);
-   break;
-   case AMDGPU_HPD_2:
-   WREG32(mmDC_HPD2_CONTROL, 0);
-   break;
-   case AMDGPU_HPD_3:
-   WREG32(mmDC_HPD3_CONTROL, 0);
-   break;
-   case AMDGPU_HPD_4:
-   WREG32(mmDC_HPD4_CONTROL, 0);
-   break;
-   case AMDGPU_HPD_5:
-   WREG32(mmDC_HPD5_CONTROL, 0);
-   break;
-   case AMDGPU_HPD_6:
-   WREG32(mmDC_HPD6_CONTROL, 0);
-   break;
-   default:
-   break;
-   }
+   if (amdgpu_connector->hpd.hpd >= adev->mode_info.num_hpd)
+   continue;
+
+   WREG32(mmDC_HPD1_CONTROL +
hpd_offsets[amdgpu_connector->hpd.hpd], 0);
+

0 was the valued written here before this commit. The commit basically
replaces the switch case with a sum in this snippet.

thanks,
andré


Re: Linux 5.19-rc6

2022-07-14 Thread Guenter Roeck

On 7/14/22 09:48, Linus Torvalds wrote:

On Thu, Jul 14, 2022 at 12:23 AM Geert Uytterhoeven
 wrote:


Oh, it's not just this one. The lists of build regressions between v5.18
and v5.19-rc1 [1] resp. v5.19-rc6 [2] look surprisingly similar :-(

[1] https://lore.kernel.org/all/20220606082201.2792145-1-ge...@linux-m68k.org
[2] https://lore.kernel.org/all/20220711064425.3084093-1-ge...@linux-m68k.org


Hmm.

Some of them are because UM ends up defining and exposing helper
functions like "to_phys()", which it just shouldn't do. Very generic
name - so when some driver ends up using the same name, you get those
errors.


We can't use virt_to_phys() and phys_to_virt() because they are defined for
the underlying architecture. Would uml_to_phys() and uml_to_virt() be
acceptable ? If so, I'll submit a patch.



And some look positively strange. Like that

   drivers/mfd/asic3.c: error: unused variable 'asic'
[-Werror=unused-variable]:  => 941:23

which is clearly used three lines later by

 iounmap(asic->tmio_cnf);

and I can't find any case of 'iounmap()' having been defined to an
empty macro or anything like that to explain it. The error in
drivers/tty/serial/sh-sci.c looks to be exactly the same issue, just
with ioremap() instead of iounmap().

It would be good to have some way to find which build/architecture it
is, because right now it just looks bogus.

Do you perhaps use some broken compiler that complains when the empty
inline functions don't use their arguments? Because that's what those
ioremap/iounmap() ones look like to me, but there might be some
magical architecture / config that has issues that aren't obvious.

IOW, I'd love to get those fixed, but I would also want a little bit more info.


Geert gave the necessary hint - it looks like sh-nommu used defines
for iomap() and iounmap(), which made the variable unused. According
to Geert that was fixed a couple of days ago.

Guenter


Re: [PATCH] drm/amd/display: Enable building new display engine with KCOV enabled

2022-07-14 Thread Guenter Roeck

On 7/14/22 09:29, Alex Deucher wrote:

Applied.  Thanks!

On Wed, Jul 13, 2022 at 4:03 PM Harry Wentland  wrote:


On 2022-07-12 18:42, Guenter Roeck wrote:

The new display engine uses floating point math, which is not supported
by KCOV. Commit 9d1d02ff3678 ("drm/amd/display: Don't build DCN1 when kcov
is enabled") tried to work around the problem by disabling
CONFIG_DRM_AMD_DC_DCN if KCOV_INSTRUMENT_ALL and KCOV_ENABLE_COMPARISONS
are enabled. The result is that KCOV can not be enabled on systems which
require this display engine. A much simpler and less invasive solution is
to disable KCOV selectively when compiling the display enagine while


"enagine". Outch.

Anyway, thanks for applying.

Guenter


keeping it enabled for the rest of the kernel.

Fixes: 9d1d02ff3678 ("drm/amd/display: Don't build DCN1 when kcov is enabled")
Cc: Arnd Bergmann 
Cc: Leo Li 
Signed-off-by: Guenter Roeck 


Reviewed-by: Harry Wentland 

Harry


---
  drivers/gpu/drm/amd/display/Kconfig | 2 +-
  drivers/gpu/drm/amd/display/dc/Makefile | 3 +++
  2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/display/Kconfig 
b/drivers/gpu/drm/amd/display/Kconfig
index b4029c0d5d8c..96cbc87f7b6b 100644
--- a/drivers/gpu/drm/amd/display/Kconfig
+++ b/drivers/gpu/drm/amd/display/Kconfig
@@ -6,7 +6,7 @@ config DRM_AMD_DC
   bool "AMD DC - Enable new display engine"
   default y
   select SND_HDA_COMPONENT if SND_HDA_CORE
- select DRM_AMD_DC_DCN if (X86 || PPC64) && !(KCOV_INSTRUMENT_ALL && 
KCOV_ENABLE_COMPARISONS)
+ select DRM_AMD_DC_DCN if (X86 || PPC64)
   help
 Choose this option if you want to use the new display engine
 support for AMDGPU. This adds required support for Vega and
diff --git a/drivers/gpu/drm/amd/display/dc/Makefile 
b/drivers/gpu/drm/amd/display/dc/Makefile
index b4eca0236435..b801973749d2 100644
--- a/drivers/gpu/drm/amd/display/dc/Makefile
+++ b/drivers/gpu/drm/amd/display/dc/Makefile
@@ -26,6 +26,9 @@
  DC_LIBS = basics bios dml clk_mgr dce gpio irq link virtual

  ifdef CONFIG_DRM_AMD_DC_DCN
+
+KCOV_INSTRUMENT := n
+
  DC_LIBS += dcn20
  DC_LIBS += dsc
  DC_LIBS += dcn10






Re: Linux 5.19-rc6

2022-07-14 Thread Linus Torvalds
On Thu, Jul 14, 2022 at 10:24 AM Guenter Roeck  wrote:
>
> We can't use virt_to_phys() and phys_to_virt() because they are defined for
> the underlying architecture. Would uml_to_phys() and uml_to_virt() be
> acceptable ? If so, I'll submit a patch.

Sure, that would be good, and make th uml helpers clearly be in the
uml namespace.

Another more traditional approach is to use underscored versions, but
exactly because that's the normal thing, things like that may then
clash with the "native architecture" version, so for uml using an
explicit uml namespace might be the better option.

   Linus


Re: [PATCH] drm/amd/display: Add missing hard-float compile flags for PPC64 builds

2022-07-14 Thread Melissa Wen
O 07/13, Alex Deucher wrote:
> On Wed, Jul 13, 2022 at 7:09 PM Guenter Roeck  wrote:
> >
> > On Wed, Jul 13, 2022 at 05:20:40PM -0400, Alex Deucher wrote:
> > > >
> > > > The problem is not the FPU operations, but the fact that soft-float
> > > > and hard-float compiled code is linked together. The soft-float and
> > > > hard-float ABIs on powerpc are not compatible, so one ends up with
> > > > an object file which is partially soft-float and partially hard-float
> > > > compiled and thus uses different ABIs. That can only create chaos,
> > > > so the linker complains about it.
> > >
> > > I get that, I just don't see why only DCN 3.1.x files have this
> > > problem.  The DCN 2.x files should as well.
> > >
> >
> > Seen in drivers/gpu/drm/amd/display/dc/clk_mgr/Makefile:
> >
> > # prevent build errors regarding soft-float vs hard-float FP ABI tags
> > # this code is currently unused on ppc64, as it applies to Renoir APUs only
> > ifdef CONFIG_PPC64
> > CFLAGS_$(AMDDALPATH)/dc/clk_mgr/dcn21/rn_clk_mgr.o := $(call 
> > cc-option,-mno-gnu-attribute)
> > endif
> >
> > Does that explain it ?
> 
> I would expect to see it in dcn20_resource.c and dcn30_clk_mgr.c for
> example.  They follow the same pattern as the dcn 3.1.x files.  They
> call functions that use FP, but maybe there is some FP code still in
> those functions that we missed somehow.

Hi,

I'm a little late here, but I'm not able to reproduce the issue yet.
I have this setup:
- gcc 11.3.0
- binutils 2.38.50
- mainline kernel (torvalds) version: 5.19.0-rc6 (cross-compiling)
  -> make ARCH=powerpc CROSS_COMPILE=powerpc64-linux-gnu- allmodconfig
=> DRM_AMD_DC [=y] && HAS_IOMEM [=y] && DRM [=m] && DRM_AMDGPU [=m] && (X86 
|| PPC64 [=y]) && (!KCOV_INSTRUMENT_ALL [=n] || !KCOV_ENABLE_COMPARISONS [=n])
  -> make -j16 ARCH=powerpc CROSS_COMPILE=powerpc64-linux-gnu-

Am I missing something?

So, as Alex mentioned the possibility of some non-isolated FPU code in
3.1, I reviewed dcn31 code and my best bet so far is that the issue
is here:

https://github.com/torvalds/linux/blob/master/drivers/gpu/drm/amd/display/dc/dcn31/dcn31_resource.c#L1721

Although dcn31_update_soc_for_wm_a() is only called inside
dml/dcn31/dcn31_fpu:
- dc->res_pool->funcs->update_soc_for_wm_a(dc, context);

it's declared in dcn31_resource and has FPU code. So, we should move it
to dml/dcn31/dcn31_fpu.

However, as I can't reproduce the issue, I don't know if it addresses
the problem reported here and also if everything will be clean after
moving it. 

Guenter,

Can you provide more info about your setup: cross-compile or not, any
flags, branch, etc?

Best Regards,

Melissa

> 
> Alex


signature.asc
Description: PGP signature


Re: [PATCH v2 00/29] drm/kms: Stop registering multiple /sys/class/backlight devs for a single display

2022-07-14 Thread Rafael J. Wysocki
On Tue, Jul 12, 2022 at 9:39 PM Hans de Goede  wrote:
>
> Hi All,
>
> As mentioned in my RFC titled "drm/kms: control display brightness through
> drm_connector properties":
> https://lore.kernel.org/dri-devel/0d188965-d809-81b5-74ce-7d30c49fe...@redhat.com/
>
> The first step towards this is to deal with some existing technical debt
> in backlight handling on x86/ACPI boards, specifically we need to stop
> registering multiple /sys/class/backlight devs for a single display.
>
> This series implements my RFC describing my plan for these cleanups:
> https://lore.kernel.org/dri-devel/98519ba0-7f18-201a-ea34-652f50343...@redhat.com/
>
> This new version addresses the few small remarks made on version 1 (mainly
> changing patch 1/29) and more importantly this finishes the refactoring by
> else addressing all the bits from the "Other issues" section of
> the refactor RFC (resulting in patches 15-29 which are new in v2).
>
> Please review and test! I hope to be able to make an immutable branch
> based on 5.20-rc1 + this series available for merging into the various
> touched subsystems once 5.20-rc2 is out.

Please feel free to add

Acked-by: Rafael J. Wysocki 

to all of the ACPI video patches in this series.

Thanks!

> Hans de Goede (29):
>   ACPI: video: Add acpi_video_backlight_use_native() helper
>   drm/i915: Don't register backlight when another backlight should be
> used
>   drm/amdgpu: Don't register backlight when another backlight should be
> used
>   drm/radeon: Don't register backlight when another backlight should be
> used
>   drm/nouveau: Don't register backlight when another backlight should be
> used
>   ACPI: video: Drop backlight_device_get_by_type() call from
> acpi_video_get_backlight_type()
>   ACPI: video: Remove acpi_video_bus from list before tearing it down
>   ACPI: video: Simplify acpi_video_unregister_backlight()
>   ACPI: video: Make backlight class device registration a separate step
>   ACPI: video: Remove code to unregister acpi_video backlight when a
> native backlight registers
>   drm/i915: Call acpi_video_register_backlight() (v2)
>   drm/nouveau: Register ACPI video backlight when nv_backlight
> registration fails
>   drm/amdgpu: Register ACPI video backlight when skipping amdgpu
> backlight registration
>   drm/radeon: Register ACPI video backlight when skipping radeon
> backlight registration
>   ACPI: video: Refactor acpi_video_get_backlight_type() a bit
>   ACPI: video: Add Nvidia WMI EC brightness control detection
>   ACPI: video: Add Apple GMUX brightness control detection
>   platform/x86: apple-gmux: Stop calling acpi/video.h functions
>   platform/x86: toshiba_acpi: Stop using
> acpi_video_set_dmi_backlight_type()
>   platform/x86: acer-wmi: Move backlight DMI quirks to
> acpi/video_detect.c
>   platform/x86: asus-wmi: Drop DMI chassis-type check from backlight
> handling
>   platform/x86: asus-wmi: Move acpi_backlight=vendor quirks to ACPI
> video_detect.c
>   platform/x86: asus-wmi: Move acpi_backlight=native quirks to ACPI
> video_detect.c
>   platform/x86: samsung-laptop: Move acpi_backlight=[vendor|native]
> quirks to ACPI video_detect.c
>   ACPI: video: Remove acpi_video_set_dmi_backlight_type()
>   ACPI: video: Drop "Samsung X360" acpi_backlight=native quirk
>   ACPI: video: Drop Clevo/TUXEDO NL5xRU and NL5xNU acpi_backlight=native
> quirks
>   ACPI: video: Fix indentation of video_detect_dmi_table[] entries
>   drm/todo: Add entry about dealing with brightness control on devices
> with > 1 panel
>
>  Documentation/gpu/todo.rst|  68 +++
>  drivers/acpi/Kconfig  |   1 +
>  drivers/acpi/acpi_video.c |  59 ++-
>  drivers/acpi/video_detect.c   | 415 +++---
>  drivers/gpu/drm/Kconfig   |  12 +
>  .../gpu/drm/amd/amdgpu/atombios_encoders.c|  14 +-
>  .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c |   9 +
>  drivers/gpu/drm/gma500/Kconfig|   2 +
>  drivers/gpu/drm/i915/Kconfig  |   2 +
>  .../gpu/drm/i915/display/intel_backlight.c|   7 +
>  drivers/gpu/drm/i915/display/intel_display.c  |   8 +
>  drivers/gpu/drm/i915/display/intel_panel.c|   3 +
>  drivers/gpu/drm/i915/i915_drv.h   |   2 +
>  drivers/gpu/drm/nouveau/nouveau_backlight.c   |  14 +
>  drivers/gpu/drm/radeon/atombios_encoders.c|   7 +
>  drivers/gpu/drm/radeon/radeon_encoders.c  |  11 +-
>  .../gpu/drm/radeon/radeon_legacy_encoders.c   |   7 +
>  drivers/platform/x86/acer-wmi.c   |  66 ---
>  drivers/platform/x86/apple-gmux.c |   3 -
>  drivers/platform/x86/asus-nb-wmi.c|  21 -
>  drivers/platform/x86/asus-wmi.c   |  13 -
>  drivers/platform/x86/asus-wmi.h   |   2 -
>  drivers/platform/x86/eeepc-wmi.c  |  25 +-
>  drivers/platform/x86/samsung-laptop.c |  87 
>  

Re: [PATCH 07/10] drm/amdgpu: move setting the job resources

2022-07-14 Thread Andrey Grodzovsky

Reviewed-by: Andrey Grodzovsky 

Andrey

On 2022-07-14 06:38, Christian König wrote:

Move setting the job resources into amdgpu_job.c

Signed-off-by: Christian König 
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c  | 21 ++---
  drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 17 +
  drivers/gpu/drm/amd/amdgpu/amdgpu_job.h |  2 ++
  3 files changed, 21 insertions(+), 19 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
index dfb7b4f46bc3..88f491dc7ca2 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
@@ -828,9 +828,6 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
struct amdgpu_vm *vm = >vm;
struct amdgpu_bo_list_entry *e;
struct list_head duplicates;
-   struct amdgpu_bo *gds;
-   struct amdgpu_bo *gws;
-   struct amdgpu_bo *oa;
int r;
  
  	INIT_LIST_HEAD(>validated);

@@ -947,22 +944,8 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
amdgpu_cs_report_moved_bytes(p->adev, p->bytes_moved,
 p->bytes_moved_vis);
  
-	gds = p->bo_list->gds_obj;

-   gws = p->bo_list->gws_obj;
-   oa = p->bo_list->oa_obj;
-
-   if (gds) {
-   p->job->gds_base = amdgpu_bo_gpu_offset(gds) >> PAGE_SHIFT;
-   p->job->gds_size = amdgpu_bo_size(gds) >> PAGE_SHIFT;
-   }
-   if (gws) {
-   p->job->gws_base = amdgpu_bo_gpu_offset(gws) >> PAGE_SHIFT;
-   p->job->gws_size = amdgpu_bo_size(gws) >> PAGE_SHIFT;
-   }
-   if (oa) {
-   p->job->oa_base = amdgpu_bo_gpu_offset(oa) >> PAGE_SHIFT;
-   p->job->oa_size = amdgpu_bo_size(oa) >> PAGE_SHIFT;
-   }
+   amdgpu_job_set_resources(p->job, p->bo_list->gds_obj,
+p->bo_list->gws_obj, p->bo_list->oa_obj);
  
  	if (p->uf_entry.tv.bo) {

struct amdgpu_bo *uf = ttm_to_amdgpu_bo(p->uf_entry.tv.bo);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
index 36c1be77bf8f..3255b2fca611 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
@@ -129,6 +129,23 @@ int amdgpu_job_alloc_with_ib(struct amdgpu_device *adev, 
unsigned size,
return r;
  }
  
+void amdgpu_job_set_resources(struct amdgpu_job *job, struct amdgpu_bo *gds,

+ struct amdgpu_bo *gws, struct amdgpu_bo *oa)
+{
+   if (gds) {
+   job->gds_base = amdgpu_bo_gpu_offset(gds) >> PAGE_SHIFT;
+   job->gds_size = amdgpu_bo_size(gds) >> PAGE_SHIFT;
+   }
+   if (gws) {
+   job->gws_base = amdgpu_bo_gpu_offset(gws) >> PAGE_SHIFT;
+   job->gws_size = amdgpu_bo_size(gws) >> PAGE_SHIFT;
+   }
+   if (oa) {
+   job->oa_base = amdgpu_bo_gpu_offset(oa) >> PAGE_SHIFT;
+   job->oa_size = amdgpu_bo_size(oa) >> PAGE_SHIFT;
+   }
+}
+
  void amdgpu_job_free_resources(struct amdgpu_job *job)
  {
struct amdgpu_ring *ring = to_amdgpu_ring(job->base.sched);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.h
index d599c0540b46..0bab8fe0d419 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.h
@@ -77,6 +77,8 @@ int amdgpu_job_alloc(struct amdgpu_device *adev, unsigned 
num_ibs,
 struct amdgpu_job **job, struct amdgpu_vm *vm);
  int amdgpu_job_alloc_with_ib(struct amdgpu_device *adev, unsigned size,
enum amdgpu_ib_pool_type pool, struct amdgpu_job **job);
+void amdgpu_job_set_resources(struct amdgpu_job *job, struct amdgpu_bo *gds,
+ struct amdgpu_bo *gws, struct amdgpu_bo *oa);
  void amdgpu_job_free_resources(struct amdgpu_job *job);
  void amdgpu_job_free(struct amdgpu_job *job);
  int amdgpu_job_submit(struct amdgpu_job *job, struct drm_sched_entity *entity,


Re: [PATCH 01/10] drm/sched: move calling drm_sched_entity_select_rq

2022-07-14 Thread Andrey Grodzovsky

Found the new use case from the 5/10 of reordering CS ioctl.

Reviewed-by: Andrey Grodzovsky 

Andrey

On 2022-07-14 12:26, Christian König wrote:

We need this for limiting codecs like AV1 to the first instance for VCN3.

Essentially the idea is that we first initialize the job with entity, 
id etc... and before we submit it we select a new rq for the entity. 
In the meantime the VCN3 inline parse will have modified the available 
rqs for the entity.


See the patch "revert "fix limiting AV1 to the first instance on 
VCN3"" as well.


Christian.

Am 14.07.22 um 17:43 schrieb Andrey Grodzovsky:
Can you please remind me of the use case that requires this ? I 
browsed through
related mails in the past but haven't found when is that needed. For 
amdgpu

drm_sched_job_init and drm_sched_job_arm are called together and amdgpu
is the only one who supports modifying entity priority on the fly as 
far as i see.


Andrey

On 2022-07-14 06:38, Christian König wrote:
We already discussed that the call to drm_sched_entity_select_rq() 
needs

to move to drm_sched_job_arm() to be able to set a new scheduler list
between _init() and _arm(). This was just not applied for some reason.

Signed-off-by: Christian König 
CC: Andrey Grodzovsky 
CC: dri-de...@lists.freedesktop.org
---
  drivers/gpu/drm/scheduler/sched_main.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/scheduler/sched_main.c 
b/drivers/gpu/drm/scheduler/sched_main.c

index 68317d3a7a27..e0ab14e0fb6b 100644
--- a/drivers/gpu/drm/scheduler/sched_main.c
+++ b/drivers/gpu/drm/scheduler/sched_main.c
@@ -592,7 +592,6 @@ int drm_sched_job_init(struct drm_sched_job *job,
 struct drm_sched_entity *entity,
 void *owner)
  {
-    drm_sched_entity_select_rq(entity);
  if (!entity->rq)
  return -ENOENT;
  @@ -628,7 +627,7 @@ void drm_sched_job_arm(struct drm_sched_job *job)
  struct drm_sched_entity *entity = job->entity;
    BUG_ON(!entity);
-
+    drm_sched_entity_select_rq(entity);
  sched = entity->rq->sched;
    job->sched = sched;




Re: Linux 5.19-rc6

2022-07-14 Thread Alex Deucher
On Wed, Jul 13, 2022 at 5:32 PM Linus Torvalds
 wrote:
>
> On Wed, Jul 13, 2022 at 2:01 PM Alex Deucher  wrote:
> >
> > If you want to apply Guenter's patch original patch:
> > https://patchwork.freedesktop.org/patch/490184/
> > That's fine with me.
>
> Honestly, by this time I feel that it's too little, too late.
>
> The ppc people apparently didn't care at all about the fact that this
> driver didn't compile.
>
> At least Michael Ellerman and Daniel Axtens were cc'd on that thread
> with the proposed fix originally.
>
> I don't see any replies from ppc people as to why it happened, even
> though apparently a bog-standard "make allmodconfig" just doesn't
> build.
>
> I'd try it myself, since I do have a cross-build environment for some
> earlier cross-build verification I did.
>
> But since my upgrade to F36 it now uses gcc-12, and possibly due to
> that I get hundreds of errors long before I get to any drm drivers:
>
>   Cannot find symbol for section 19: .text.create_section_mapping.
>   arch/powerpc/mm/mem.o: failed
>   ...
>   Cannot find symbol for section 19: .text.cpu_show_meltdown.
>   drivers/base/cpu.o: failed
>   Error: External symbol 'memset' referenced from prom_init.c
>
> this cross environment used to work for me, but something changed (I
> mention gcc-12, but honestly, that's based on nothing at all, except
> for the few problems it caused on x86-64. It could be something
> entirely unrelated, but it does look like some bad interaction with
> -ffunction-sections).
>
> So considering that the ppc people ignored this whole issue since the
> merge window, I think it's entirely unreasonable to then apply a
> ppc-specific patch for this at this time, when people literally asked
> "why is this needed", and there was no reply from the powerpc side.
>
> Does any of that sound like "we should support this driver on powerpc" to you?

Fair enough.  I don't have a strong opinion on the matter.  Users will
hopefully likely notice the failure after release because most people
don't test until after a release and then we'll apply the fix and
re-enable it for 5.20 so that would leave 5.19 broken for PPC64 users
which would not be ideal.  But as you said, no one has cared up to
this point.

Alex

>
>  Linus


Re: Linux 5.19-rc6

2022-07-14 Thread Linus Torvalds
On Thu, Jul 14, 2022 at 12:23 AM Geert Uytterhoeven
 wrote:
>
> Oh, it's not just this one. The lists of build regressions between v5.18
> and v5.19-rc1 [1] resp. v5.19-rc6 [2] look surprisingly similar :-(
>
> [1] https://lore.kernel.org/all/20220606082201.2792145-1-ge...@linux-m68k.org
> [2] https://lore.kernel.org/all/20220711064425.3084093-1-ge...@linux-m68k.org

Hmm.

Some of them are because UM ends up defining and exposing helper
functions like "to_phys()", which it just shouldn't do. Very generic
name - so when some driver ends up using the same name, you get those
errors.

And some look positively strange. Like that

  drivers/mfd/asic3.c: error: unused variable 'asic'
[-Werror=unused-variable]:  => 941:23

which is clearly used three lines later by

iounmap(asic->tmio_cnf);

and I can't find any case of 'iounmap()' having been defined to an
empty macro or anything like that to explain it. The error in
drivers/tty/serial/sh-sci.c looks to be exactly the same issue, just
with ioremap() instead of iounmap().

It would be good to have some way to find which build/architecture it
is, because right now it just looks bogus.

Do you perhaps use some broken compiler that complains when the empty
inline functions don't use their arguments? Because that's what those
ioremap/iounmap() ones look like to me, but there might be some
magical architecture / config that has issues that aren't obvious.

IOW, I'd love to get those fixed, but I would also want a little bit more info.

Linus


Re: [PATCH] drm/amd/debugfs: Expose GFXOFF state to userspace

2022-07-14 Thread Alex Deucher
On Thu, Jul 14, 2022 at 12:45 PM André Almeida  wrote:
>
>
>
> Às 13:42 de 14/07/22, Alex Deucher escreveu:
> > On Wed, Jul 13, 2022 at 11:15 AM André Almeida  
> > wrote:
> >>
> >> GFXOFF has two different "state" values: one to define if the GPU is
> >> allowed/disallowed to enter GFXOFF, usually called state; and another
> >> one to define if currently GFXOFF is being used, usually called status.
> >> Even when GFXOFF is allowed, GPU firmware can decide to not used it
> >> accordingly to the GPU load.
> >>
> >> Userspace can allow/disallow GPUs to enter into GFXOFF via debugfs. The
> >> kernel maintains a counter of requests for GFXOFF (gfx_off_req_count)
> >> that should be decreased to allow GFXOFF and increased to disallow.
> >>
> >> The issue with this interface is that userspace can't be sure if GFXOFF
> >> is currently allowed. Even by checking amdgpu_gfxoff file, one might get
> >> an ambiguous 2, that means that GPU is currently out of GFXOFF, but that
> >> can be either because it's currently disallowed or because it's allowed
> >> but given the current GPU load it's enabled. Then, userspace needs to
> >> rely on the fact that GFXOFF is enabled by default on boot and to track
> >> this information.
> >>
> >> To make userspace life easier and GFXOFF more reliable, return the
> >> current state of GFXOFF to userspace when reading amdgpu_gfxoff with the
> >> same semantics of writing: 0 means not allowed, not 0 means allowed.
> >>
> >
> > This looks good. Can you document this in the amdgpu kerneldoc?
> >
>
> Sure, let me send a v2 with that

While you are at it, if we are missing docs for the other gfxoff file
can you add that as well?

Thanks!

Alex

>
> > Alex
> >
> >> Expose the current status of GFXOFF through a new file,
> >> amdgpu_gfxoff_status.
> >>
> >> Signed-off-by: André Almeida 
> >> ---
> >>  drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 49 -
> >>  1 file changed, 47 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c 
> >> b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
> >> index f3b3c688e4e7..e2eec985adb3 100644
> >> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
> >> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
> >> @@ -1117,13 +1117,50 @@ static ssize_t amdgpu_debugfs_gfxoff_read(struct 
> >> file *f, char __user *buf,
> >> }
> >>
> >> while (size) {
> >> -   uint32_t value;
> >> +   u32 value = adev->gfx.gfx_off_state;
> >> +
> >> +   r = put_user(value, (u32 *)buf);
> >> +   if (r)
> >> +   goto out;
> >> +
> >> +   result += 4;
> >> +   buf += 4;
> >> +   *pos += 4;
> >> +   size -= 4;
> >> +   }
> >> +
> >> +   r = result;
> >> +out:
> >> +   pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
> >> +   pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
> >> +
> >> +   return r;
> >> +}
> >> +
> >> +static ssize_t amdgpu_debugfs_gfxoff_status_read(struct file *f, char 
> >> __user *buf,
> >> +size_t size, loff_t *pos)
> >> +{
> >> +   struct amdgpu_device *adev = file_inode(f)->i_private;
> >> +   ssize_t result = 0;
> >> +   int r;
> >> +
> >> +   if (size & 0x3 || *pos & 0x3)
> >> +   return -EINVAL;
> >> +
> >> +   r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
> >> +   if (r < 0) {
> >> +   pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
> >> +   return r;
> >> +   }
> >> +
> >> +   while (size) {
> >> +   u32 value;
> >>
> >> r = amdgpu_get_gfx_off_status(adev, );
> >> if (r)
> >> goto out;
> >>
> >> -   r = put_user(value, (uint32_t *)buf);
> >> +   r = put_user(value, (u32 *)buf);
> >> if (r)
> >> goto out;
> >>
> >> @@ -1206,6 +1243,12 @@ static const struct file_operations 
> >> amdgpu_debugfs_gfxoff_fops = {
> >> .llseek = default_llseek
> >>  };
> >>
> >> +static const struct file_operations amdgpu_debugfs_gfxoff_status_fops = {
> >> +   .owner = THIS_MODULE,
> >> +   .read = amdgpu_debugfs_gfxoff_status_read,
> >> +   .llseek = default_llseek
> >> +};
> >> +
> >>  static const struct file_operations *debugfs_regs[] = {
> >> _debugfs_regs_fops,
> >> _debugfs_regs2_fops,
> >> @@ -1217,6 +1260,7 @@ static const struct file_operations *debugfs_regs[] 
> >> = {
> >> _debugfs_wave_fops,
> >> _debugfs_gpr_fops,
> >> _debugfs_gfxoff_fops,
> >> +   _debugfs_gfxoff_status_fops,
> >>  };
> >>
> >>  static const char *debugfs_regs_names[] = {
> >> @@ -1230,6 +1274,7 @@ static const char *debugfs_regs_names[] = {
> >> "amdgpu_wave",
> >> "amdgpu_gpr",
> >> "amdgpu_gfxoff",
> >> +   "amdgpu_gfxoff_status",
> >>  };
> 

[PATCH 12/12] drm/amd/display: Rewrite CalculateWriteBackDISPCLK function

2022-07-14 Thread Maíra Canal
Based on the dml30_CalculateWriteBackDISPCLK, it separates the
DISPCLK calculations on three variables, making no functional changes, in order
to make it more readable and better express that three values are being compared
on dml_max.

Signed-off-by: Maíra Canal 
---
 .../drm/amd/display/dc/dml/display_mode_vba.c | 31 ---
 1 file changed, 20 insertions(+), 11 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/dc/dml/display_mode_vba.c 
b/drivers/gpu/drm/amd/display/dc/dml/display_mode_vba.c
index c5a0a3649e9a..5fc1d16a2e15 100644
--- a/drivers/gpu/drm/amd/display/dc/dml/display_mode_vba.c
+++ b/drivers/gpu/drm/amd/display/dc/dml/display_mode_vba.c
@@ -1113,20 +1113,29 @@ double CalculateWriteBackDISPCLK(
unsigned int HTotal,
unsigned int WritebackChromaLineBufferWidth)
 {
-   double CalculateWriteBackDISPCLK = 1.01 * PixelClock * dml_max(
-   dml_ceil(WritebackLumaHTaps / 4.0, 1) / WritebackHRatio,
-   dml_max((WritebackLumaVTaps * dml_ceil(1.0 / WritebackVRatio, 
1) * dml_ceil(WritebackDestinationWidth / 4.0, 1)
+
+   double DISPCLK_H = 0, DISPCLK_V = 0, DISPCLK_HB = 0;
+   double CalculateWriteBackDISPCLK = 0;
+
+   DISPCLK_H = dml_ceil(WritebackLumaHTaps / 4.0, 1) / WritebackHRatio;
+   DISPCLK_V = (WritebackLumaVTaps * dml_ceil(1.0 / WritebackVRatio, 1) * 
dml_ceil(WritebackDestinationWidth / 4.0, 1)
+ dml_ceil(WritebackDestinationWidth / 4.0, 1)) / 
(double) HTotal + dml_ceil(1.0 / WritebackVRatio, 1)
-   * (dml_ceil(WritebackLumaVTaps / 4.0, 1) + 4.0) / 
(double) HTotal,
-   dml_ceil(1.0 / WritebackVRatio, 1) * 
WritebackDestinationWidth / (double) HTotal));
+   * (dml_ceil(WritebackLumaVTaps / 4.0, 1) + 4.0) / 
(double) HTotal;
+   DISPCLK_HB = dml_ceil(1.0 / WritebackVRatio, 1) * 
WritebackDestinationWidth / (double) HTotal;
+
+   CalculateWriteBackDISPCLK = 1.01 * PixelClock * dml_max3(DISPCLK_H, 
DISPCLK_V, DISPCLK_HB);
+
if (WritebackPixelFormat != dm_444_32) {
-   CalculateWriteBackDISPCLK = dml_max(CalculateWriteBackDISPCLK, 
1.01 * PixelClock * dml_max(
-   dml_ceil(WritebackChromaHTaps / 2.0, 1) / (2 * 
WritebackHRatio),
-   dml_max((WritebackChromaVTaps * dml_ceil(1 / (2 * 
WritebackVRatio), 1) * dml_ceil(WritebackDestinationWidth / 2.0 / 2.0, 1)
-   + dml_ceil(WritebackDestinationWidth / 2.0 / 
WritebackChromaLineBufferWidth, 1)) / HTotal
-   + dml_ceil(1 / (2 * WritebackVRatio), 1) * 
(dml_ceil(WritebackChromaVTaps / 4.0, 1) + 4) / HTotal,
-   dml_ceil(1.0 / (2 * WritebackVRatio), 1) * 
WritebackDestinationWidth / 2.0 / HTotal)));
+   DISPCLK_H = dml_ceil(WritebackChromaHTaps / 2.0, 1) / (2 * 
WritebackHRatio);
+   DISPCLK_V = (WritebackChromaVTaps * dml_ceil(1 / (2 * 
WritebackVRatio), 1) *
+   dml_ceil(WritebackDestinationWidth / 4.0, 1) +
+   dml_ceil(WritebackDestinationWidth / 2.0 / 
WritebackChromaLineBufferWidth, 1)) / HTotal +
+   dml_ceil(1 / (2 * WritebackVRatio), 1) 
*(dml_ceil(WritebackChromaVTaps / 4.0, 1) + 4) / HTotal;
+   DISPCLK_HB = dml_ceil(1.0 / (2 * WritebackVRatio), 1) * 
WritebackDestinationWidth / 2.0 / HTotal;
+   CalculateWriteBackDISPCLK = dml_max(CalculateWriteBackDISPCLK,
+   1.01 * PixelClock * dml_max3(DISPCLK_H, 
DISPCLK_V, DISPCLK_HB));
}
+
return CalculateWriteBackDISPCLK;
 }
 
-- 
2.36.1



[PATCH 11/12] drm/amd/display: Remove duplicated CalculateWriteBackDISPCLK

2022-07-14 Thread Maíra Canal
The functions dml30_CalculateWriteBackDISPCLK and
dml31_CalculateWriteBackDISPCLK are identical. Therefor, to avoid
code duplication, dml31_CalculateWriteBackDISPCLK is removed and
replaced by dml30_CalculateWriteBackDISPCLK.

Signed-off-by: Maíra Canal 
---
 .../dc/dml/dcn31/display_mode_vba_31.c| 28 ++-
 .../dc/dml/dcn31/display_mode_vba_31.h| 11 
 2 files changed, 2 insertions(+), 37 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/dc/dml/dcn31/display_mode_vba_31.c 
b/drivers/gpu/drm/amd/display/dc/dml/dcn31/display_mode_vba_31.c
index 3fab19134480..804e45e22693 100644
--- a/drivers/gpu/drm/amd/display/dc/dml/dcn31/display_mode_vba_31.c
+++ b/drivers/gpu/drm/amd/display/dc/dml/dcn31/display_mode_vba_31.c
@@ -2085,11 +2085,9 @@ static void 
DISPCLKDPPCLKDCFCLKDeepSleepPrefetchParametersWatermarksAndPerforman
if (v->WritebackEnable[k]) {
v->WritebackDISPCLK = dml_max(
v->WritebackDISPCLK,
-   dml31_CalculateWriteBackDISPCLK(
-   
v->WritebackPixelFormat[k],
+   dml30_CalculateWriteBackDISPCLK(
v->PixelClock[k],
v->WritebackHRatio[k],
-   v->WritebackVRatio[k],
v->WritebackHTaps[k],
v->WritebackVTaps[k],

v->WritebackSourceWidth[k],
@@ -3470,26 +3468,6 @@ static double CalculateTWait(unsigned int PrefetchMode, 
double DRAMClockChangeLa
}
 }
 
-double dml31_CalculateWriteBackDISPCLK(
-   enum source_format_class WritebackPixelFormat,
-   double PixelClock,
-   double WritebackHRatio,
-   double WritebackVRatio,
-   unsigned int WritebackHTaps,
-   unsigned int WritebackVTaps,
-   long WritebackSourceWidth,
-   long WritebackDestinationWidth,
-   unsigned int HTotal,
-   unsigned int WritebackLineBufferSize)
-{
-   double DISPCLK_H, DISPCLK_V, DISPCLK_HB;
-
-   DISPCLK_H = PixelClock * dml_ceil(WritebackHTaps / 8.0, 1) / 
WritebackHRatio;
-   DISPCLK_V = PixelClock * (WritebackVTaps * 
dml_ceil(WritebackDestinationWidth / 6.0, 1) + 8.0) / HTotal;
-   DISPCLK_HB = PixelClock * WritebackVTaps * (WritebackDestinationWidth * 
WritebackVTaps - WritebackLineBufferSize / 57.0) / 6.0 / WritebackSourceWidth;
-   return dml_max3(DISPCLK_H, DISPCLK_V, DISPCLK_HB);
-}
-
 static double CalculateWriteBackDelay(
enum source_format_class WritebackPixelFormat,
double WritebackHRatio,
@@ -4055,11 +4033,9 @@ void dml31_ModeSupportAndSystemConfigurationFull(struct 
display_mode_lib *mode_l
if (v->WritebackEnable[k] == true) {
v->WritebackRequiredDISPCLK = dml_max(
v->WritebackRequiredDISPCLK,
-   dml31_CalculateWriteBackDISPCLK(
-   
v->WritebackPixelFormat[k],
+   dml30_CalculateWriteBackDISPCLK(
v->PixelClock[k],
v->WritebackHRatio[k],
-   v->WritebackVRatio[k],
v->WritebackHTaps[k],
v->WritebackVTaps[k],

v->WritebackSourceWidth[k],
diff --git a/drivers/gpu/drm/amd/display/dc/dml/dcn31/display_mode_vba_31.h 
b/drivers/gpu/drm/amd/display/dc/dml/dcn31/display_mode_vba_31.h
index 90be612f26b2..654362adcaa9 100644
--- a/drivers/gpu/drm/amd/display/dc/dml/dcn31/display_mode_vba_31.h
+++ b/drivers/gpu/drm/amd/display/dc/dml/dcn31/display_mode_vba_31.h
@@ -28,16 +28,5 @@
 
 void dml31_recalculate(struct display_mode_lib *mode_lib);
 void dml31_ModeSupportAndSystemConfigurationFull(struct display_mode_lib 
*mode_lib);
-double dml31_CalculateWriteBackDISPCLK(
-   enum source_format_class WritebackPixelFormat,
-   double PixelClock,
-   double WritebackHRatio,
-   double WritebackVRatio,
-   unsigned int WritebackHTaps,
-   unsigned int WritebackVTaps,
-   long   WritebackSourceWidth,
-   long   WritebackDestinationWidth,
-   unsigned int HTotal,
-   unsigned int WritebackLineBufferSize);
 
 #endif /* __DML31_DISPLAY_MODE_VBA_H__ */
-- 

[PATCH 10/12] drm/amd/display: Remove parameters from dml30_CalculateWriteBackDISPCLK

2022-07-14 Thread Maíra Canal
The parameters WritebackPixelFormat and WritebackVRatio are removed as
they are not used on the function dml30_CalculateWriteBackDISPCLK.

Signed-off-by: Maíra Canal 
---
 drivers/gpu/drm/amd/display/dc/dml/dcn30/dcn30_fpu.c| 2 --
 .../gpu/drm/amd/display/dc/dml/dcn30/display_mode_vba_30.c  | 6 --
 .../gpu/drm/amd/display/dc/dml/dcn30/display_mode_vba_30.h  | 2 --
 3 files changed, 10 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/dc/dml/dcn30/dcn30_fpu.c 
b/drivers/gpu/drm/amd/display/dc/dml/dcn30/dcn30_fpu.c
index a8db1306750e..746bb93ade6c 100644
--- a/drivers/gpu/drm/amd/display/dc/dml/dcn30/dcn30_fpu.c
+++ b/drivers/gpu/drm/amd/display/dc/dml/dcn30/dcn30_fpu.c
@@ -322,10 +322,8 @@ void dcn30_fpu_populate_dml_writeback_from_context(
 * parameters per pipe
 */
writeback_dispclk = 
dml30_CalculateWriteBackDISPCLK(
-   dout_wb.wb_pixel_format,

pipes[pipe_cnt].pipe.dest.pixel_rate_mhz,
dout_wb.wb_hratio,
-   dout_wb.wb_vratio,
dout_wb.wb_htaps_luma,
dout_wb.wb_vtaps_luma,
dout_wb.wb_src_width,
diff --git a/drivers/gpu/drm/amd/display/dc/dml/dcn30/display_mode_vba_30.c 
b/drivers/gpu/drm/amd/display/dc/dml/dcn30/display_mode_vba_30.c
index 876b321b30ca..37049daaab4c 100644
--- a/drivers/gpu/drm/amd/display/dc/dml/dcn30/display_mode_vba_30.c
+++ b/drivers/gpu/drm/amd/display/dc/dml/dcn30/display_mode_vba_30.c
@@ -1938,10 +1938,8 @@ static void 
DISPCLKDPPCLKDCFCLKDeepSleepPrefetchParametersWatermarksAndPerforman
if (v->WritebackEnable[k]) {
v->WritebackDISPCLK = dml_max(v->WritebackDISPCLK,
dml30_CalculateWriteBackDISPCLK(
-   v->WritebackPixelFormat[k],
v->PixelClock[k],
v->WritebackHRatio[k],
-   v->WritebackVRatio[k],
v->WritebackHTaps[k],
v->WritebackVTaps[k],
v->WritebackSourceWidth[k],
@@ -3284,10 +3282,8 @@ static double CalculateTWait(
 }
 
 double dml30_CalculateWriteBackDISPCLK(
-   enum source_format_class WritebackPixelFormat,
double PixelClock,
double WritebackHRatio,
-   double WritebackVRatio,
unsigned int WritebackHTaps,
unsigned int WritebackVTaps,
long   WritebackSourceWidth,
@@ -3794,10 +3790,8 @@ void dml30_ModeSupportAndSystemConfigurationFull(struct 
display_mode_lib *mode_l
if (v->WritebackEnable[k] == true) {
v->WritebackRequiredDISPCLK = 
dml_max(v->WritebackRequiredDISPCLK,
dml30_CalculateWriteBackDISPCLK(
-   
v->WritebackPixelFormat[k],
v->PixelClock[k],
v->WritebackHRatio[k],
-   v->WritebackVRatio[k],
v->WritebackHTaps[k],
v->WritebackVTaps[k],

v->WritebackSourceWidth[k],
diff --git a/drivers/gpu/drm/amd/display/dc/dml/dcn30/display_mode_vba_30.h 
b/drivers/gpu/drm/amd/display/dc/dml/dcn30/display_mode_vba_30.h
index daaf0883b84d..12c070434eee 100644
--- a/drivers/gpu/drm/amd/display/dc/dml/dcn30/display_mode_vba_30.h
+++ b/drivers/gpu/drm/amd/display/dc/dml/dcn30/display_mode_vba_30.h
@@ -29,10 +29,8 @@
 void dml30_recalculate(struct display_mode_lib *mode_lib);
 void dml30_ModeSupportAndSystemConfigurationFull(struct display_mode_lib 
*mode_lib);
 double dml30_CalculateWriteBackDISPCLK(
-   enum source_format_class WritebackPixelFormat,
double PixelClock,
double WritebackHRatio,
-   double WritebackVRatio,
unsigned int WritebackHTaps,
unsigned int WritebackVTaps,
long   WritebackSourceWidth,
-- 
2.36.1



[PATCH 09/12] drm/amd/display: Remove unused MaxUsedBW variable

2022-07-14 Thread Maíra Canal
Remove the variable MaxUsedBW from the function
DISPCLKDPPCLKDCFCLKDeepSleepPrefetchParametersWatermarksAndPerformanceCalculation.
As a side-effect, the variables MaxPerPlaneVActiveWRBandwidth and
WRBandwidth are also removed.

This was pointed by clang with the following warning:

drivers/gpu/drm/amd/amdgpu/../display/dc/dml/dcn30/display_mode_vba_30.c:3043:10:
warning: variable 'MaxUsedBW' set but not used [-Wunused-but-set-variable]
double MaxUsedBW = 0;
   ^
1 warning generated.

Signed-off-by: Maíra Canal 
---
 .../dc/dml/dcn30/display_mode_vba_30.c| 28 ---
 1 file changed, 28 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/dc/dml/dcn30/display_mode_vba_30.c 
b/drivers/gpu/drm/amd/display/dc/dml/dcn30/display_mode_vba_30.c
index 842eb94ebe04..876b321b30ca 100644
--- a/drivers/gpu/drm/amd/display/dc/dml/dcn30/display_mode_vba_30.c
+++ b/drivers/gpu/drm/amd/display/dc/dml/dcn30/display_mode_vba_30.c
@@ -3037,40 +3037,12 @@ static void 
DISPCLKDPPCLKDCFCLKDeepSleepPrefetchParametersWatermarksAndPerforman
 
{
//Maximum Bandwidth Used
-   double TotalWRBandwidth = 0;
-   double MaxPerPlaneVActiveWRBandwidth = 0;
-   double WRBandwidth = 0;
-   double MaxUsedBW = 0;
-   for (k = 0; k < v->NumberOfActivePlanes; ++k) {
-   if (v->WritebackEnable[k] == true
-   && v->WritebackPixelFormat[k] == 
dm_444_32) {
-   WRBandwidth = v->WritebackDestinationWidth[k] * 
v->WritebackDestinationHeight[k]
-   / (v->HTotal[k] * 
v->WritebackSourceHeight[k] / v->PixelClock[k]) * 4;
-   } else if (v->WritebackEnable[k] == true) {
-   WRBandwidth = v->WritebackDestinationWidth[k] * 
v->WritebackDestinationHeight[k]
-   / (v->HTotal[k] * 
v->WritebackSourceHeight[k] / v->PixelClock[k]) * 8;
-   }
-   TotalWRBandwidth = TotalWRBandwidth + WRBandwidth;
-   MaxPerPlaneVActiveWRBandwidth = 
dml_max(MaxPerPlaneVActiveWRBandwidth, WRBandwidth);
-   }
-
v->TotalDataReadBandwidth = 0;
for (k = 0; k < v->NumberOfActivePlanes; ++k) {
v->TotalDataReadBandwidth = v->TotalDataReadBandwidth
+ v->ReadBandwidthPlaneLuma[k]
+ v->ReadBandwidthPlaneChroma[k];
}
-
-   {
-   double MaxPerPlaneVActiveRDBandwidth = 0;
-   for (k = 0; k < v->NumberOfActivePlanes; ++k) {
-   MaxPerPlaneVActiveRDBandwidth = 
dml_max(MaxPerPlaneVActiveRDBandwidth,
-   v->ReadBandwidthPlaneLuma[k] + 
v->ReadBandwidthPlaneChroma[k]);
-
-   }
-   }
-
-   MaxUsedBW = MaxTotalRDBandwidth + TotalWRBandwidth;
}
 
// VStartup Margin
-- 
2.36.1



[PATCH 08/12] drm/amd/display: Remove unused variables from dcn10_stream_encoder

2022-07-14 Thread Maíra Canal
The variable regval from the function enc1_update_generic_info_packet
and the variables dynamic_range_rgb and dynamic_range_ycbcr from the
function enc1_stream_encoder_dp_set_stream_attribute are not currently
used.

This was pointed by clang with the following warnings:

drivers/gpu/drm/amd/amdgpu/../display/dc/dcn10/dcn10_stream_encoder.c:62:11:
warning: variable 'regval' set but not used [-Wunused-but-set-variable]
uint32_t regval;
 ^
drivers/gpu/drm/amd/amdgpu/../display/dc/dcn10/dcn10_stream_encoder.c:262:10:
warning: variable 'dynamic_range_rgb' set but not used 
[-Wunused-but-set-variable]
uint8_t dynamic_range_rgb = 0; /*full range*/
^
drivers/gpu/drm/amd/amdgpu/../display/dc/dcn10/dcn10_stream_encoder.c:263:10:
warning: variable 'dynamic_range_ycbcr' set but not used 
[-Wunused-but-set-variable]
uint8_t dynamic_range_ycbcr = 1; /*bt709*/
^
3 warnings generated.

Signed-off-by: Maíra Canal 
---
 .../drm/amd/display/dc/dcn10/dcn10_stream_encoder.c| 10 --
 1 file changed, 10 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/dc/dcn10/dcn10_stream_encoder.c 
b/drivers/gpu/drm/amd/display/dc/dcn10/dcn10_stream_encoder.c
index c99c6fababa9..484e7cdf00b8 100644
--- a/drivers/gpu/drm/amd/display/dc/dcn10/dcn10_stream_encoder.c
+++ b/drivers/gpu/drm/amd/display/dc/dcn10/dcn10_stream_encoder.c
@@ -59,7 +59,6 @@ void enc1_update_generic_info_packet(
uint32_t packet_index,
const struct dc_info_packet *info_packet)
 {
-   uint32_t regval;
/* TODOFPGA Figure out a proper number for max_retries polling for lock
 * use 50 for now.
 */
@@ -88,7 +87,6 @@ void enc1_update_generic_info_packet(
REG_UPDATE(AFMT_VBI_PACKET_CONTROL, AFMT_GENERIC_CONFLICT_CLR, 1);
 
/* choose which generic packet to use */
-   regval = REG_READ(AFMT_VBI_PACKET_CONTROL);
REG_UPDATE(AFMT_VBI_PACKET_CONTROL,
AFMT_GENERIC_INDEX, packet_index);
 
@@ -259,8 +257,6 @@ void enc1_stream_encoder_dp_set_stream_attribute(
uint32_t h_back_porch;
uint8_t synchronous_clock = 0; /* asynchronous mode */
uint8_t colorimetry_bpc;
-   uint8_t dynamic_range_rgb = 0; /*full range*/
-   uint8_t dynamic_range_ycbcr = 1; /*bt709*/
uint8_t dp_pixel_encoding = 0;
uint8_t dp_component_depth = 0;
 
@@ -372,18 +368,15 @@ void enc1_stream_encoder_dp_set_stream_attribute(
switch (output_color_space) {
case COLOR_SPACE_SRGB:
misc1 = misc1 & ~0x80; /* bit7 = 0*/
-   dynamic_range_rgb = 0; /*full range*/
break;
case COLOR_SPACE_SRGB_LIMITED:
misc0 = misc0 | 0x8; /* bit3=1 */
misc1 = misc1 & ~0x80; /* bit7 = 0*/
-   dynamic_range_rgb = 1; /*limited range*/
break;
case COLOR_SPACE_YCBCR601:
case COLOR_SPACE_YCBCR601_LIMITED:
misc0 = misc0 | 0x8; /* bit3=1, bit4=0 */
misc1 = misc1 & ~0x80; /* bit7 = 0*/
-   dynamic_range_ycbcr = 0; /*bt601*/
if (hw_crtc_timing.pixel_encoding == PIXEL_ENCODING_YCBCR422)
misc0 = misc0 | 0x2; /* bit2=0, bit1=1 */
else if (hw_crtc_timing.pixel_encoding == 
PIXEL_ENCODING_YCBCR444)
@@ -393,15 +386,12 @@ void enc1_stream_encoder_dp_set_stream_attribute(
case COLOR_SPACE_YCBCR709_LIMITED:
misc0 = misc0 | 0x18; /* bit3=1, bit4=1 */
misc1 = misc1 & ~0x80; /* bit7 = 0*/
-   dynamic_range_ycbcr = 1; /*bt709*/
if (hw_crtc_timing.pixel_encoding == PIXEL_ENCODING_YCBCR422)
misc0 = misc0 | 0x2; /* bit2=0, bit1=1 */
else if (hw_crtc_timing.pixel_encoding == 
PIXEL_ENCODING_YCBCR444)
misc0 = misc0 | 0x4; /* bit2=1, bit1=0 */
break;
case COLOR_SPACE_2020_RGB_LIMITEDRANGE:
-   dynamic_range_rgb = 1; /*limited range*/
-   break;
case COLOR_SPACE_2020_RGB_FULLRANGE:
case COLOR_SPACE_2020_YCBCR:
case COLOR_SPACE_XR_RGB:
-- 
2.36.1



[PATCH 07/12] drm/amd/display: Remove unused value0 variable

2022-07-14 Thread Maíra Canal
Remove the variable value0 from the function
dcn10_link_encoder_update_mst_stream_allocation_table.

This was pointed by clang with the following warning:

drivers/gpu/drm/amd/amdgpu/../display/dc/dcn10/dcn10_link_encoder.c:1223:11:
warning: variable 'value0' set but not used [-Wunused-but-set-variable]
uint32_t value0 = 0;
 ^
1 warning generated.

Signed-off-by: Maíra Canal 
---
 drivers/gpu/drm/amd/display/dc/dcn10/dcn10_link_encoder.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/dc/dcn10/dcn10_link_encoder.c 
b/drivers/gpu/drm/amd/display/dc/dcn10/dcn10_link_encoder.c
index fbccb7263ad2..ea7d89bc293f 100644
--- a/drivers/gpu/drm/amd/display/dc/dcn10/dcn10_link_encoder.c
+++ b/drivers/gpu/drm/amd/display/dc/dcn10/dcn10_link_encoder.c
@@ -1220,7 +1220,6 @@ void 
dcn10_link_encoder_update_mst_stream_allocation_table(
const struct link_mst_stream_allocation_table *table)
 {
struct dcn10_link_encoder *enc10 = TO_DCN10_LINK_ENC(enc);
-   uint32_t value0 = 0;
uint32_t value1 = 0;
uint32_t value2 = 0;
uint32_t slots = 0;
@@ -1322,8 +1321,6 @@ void 
dcn10_link_encoder_update_mst_stream_allocation_table(
do {
udelay(10);
 
-   value0 = REG_READ(DP_MSE_SAT_UPDATE);
-
REG_GET(DP_MSE_SAT_UPDATE,
DP_MSE_SAT_UPDATE, );
 
-- 
2.36.1



[PATCH 06/12] drm/amd/display: Remove unused variables from dml_rq_dlg_get_dlg_params

2022-07-14 Thread Maíra Canal
Remove the variables dispclk_delay_subtotal and dppclk_delay_subtotal from
the function dml_rq_dlg_get_dlg_params.

This was pointed by clang with the following warning:

drivers/gpu/drm/amd/amdgpu/../display/dc/dml/dcn31/display_rq_dlg_calc_31.c:920:15:
warning: variable 'dispclk_delay_subtotal' set but not used 
[-Wunused-but-set-variable]
unsigned int dispclk_delay_subtotal;
 ^
drivers/gpu/drm/amd/amdgpu/../display/dc/dml/dcn31/display_rq_dlg_calc_31.c:919:15:
warning: variable 'dppclk_delay_subtotal' set but not used 
[-Wunused-but-set-variable]
unsigned int dppclk_delay_subtotal;
 ^
2 warnings generated.

Signed-off-by: Maíra Canal 
---
 .../dc/dml/dcn31/display_rq_dlg_calc_31.c | 19 ---
 1 file changed, 19 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/dc/dml/dcn31/display_rq_dlg_calc_31.c 
b/drivers/gpu/drm/amd/display/dc/dml/dcn31/display_rq_dlg_calc_31.c
index c94cf6e01e25..66b82e4f05c6 100644
--- a/drivers/gpu/drm/amd/display/dc/dml/dcn31/display_rq_dlg_calc_31.c
+++ b/drivers/gpu/drm/amd/display/dc/dml/dcn31/display_rq_dlg_calc_31.c
@@ -866,7 +866,6 @@ static void dml_rq_dlg_get_dlg_params(
 {
const display_pipe_source_params_st *src = 
_pipe_param[pipe_idx].pipe.src;
const display_pipe_dest_params_st *dst = 
_pipe_param[pipe_idx].pipe.dest;
-   const display_output_params_st *dout = _pipe_param[pipe_idx].dout;
const display_clocks_and_cfg_st *clks = 
_pipe_param[pipe_idx].clks_cfg;
const scaler_ratio_depth_st *scl = 
_pipe_param[pipe_idx].pipe.scale_ratio_depth;
const scaler_taps_st *taps = _pipe_param[pipe_idx].pipe.scale_taps;
@@ -916,9 +915,6 @@ static void dml_rq_dlg_get_dlg_params(
unsigned int vupdate_width;
unsigned int vready_offset;
 
-   unsigned int dppclk_delay_subtotal;
-   unsigned int dispclk_delay_subtotal;
-
unsigned int vstartup_start;
unsigned int dst_x_after_scaler;
unsigned int dst_y_after_scaler;
@@ -1037,21 +1033,6 @@ static void dml_rq_dlg_get_dlg_params(
vupdate_width = dst->vupdate_width;
vready_offset = dst->vready_offset;
 
-   dppclk_delay_subtotal = mode_lib->ip.dppclk_delay_subtotal;
-   dispclk_delay_subtotal = mode_lib->ip.dispclk_delay_subtotal;
-
-   if (scl_enable)
-   dppclk_delay_subtotal += mode_lib->ip.dppclk_delay_scl;
-   else
-   dppclk_delay_subtotal += mode_lib->ip.dppclk_delay_scl_lb_only;
-
-   dppclk_delay_subtotal += mode_lib->ip.dppclk_delay_cnvc_formatter + 
src->num_cursors * mode_lib->ip.dppclk_delay_cnvc_cursor;
-
-   if (dout->dsc_enable) {
-   double dsc_delay = get_dsc_delay(mode_lib, e2e_pipe_param, 
num_pipes, pipe_idx); // FROM VBA
-   dispclk_delay_subtotal += dsc_delay;
-   }
-
vstartup_start = dst->vstartup_start;
if (interlaced) {
if (vstartup_start / 2.0 - (double) (vready_offset + 
vupdate_width + vupdate_offset) / htotal <= vblank_end / 2.0)
-- 
2.36.1



[PATCH 05/12] drm/amd/display: Remove unused NumberOfStates variable

2022-07-14 Thread Maíra Canal
Remove the unused unsigned int NumberOfStates from the file, which was
declared but never hooked up.

This was pointed by clang with the following warning:

drivers/gpu/drm/amd/amdgpu/../display/dc/dml/dcn32/display_mode_vba_32.c:33:27:
warning: unused variable 'NumberOfStates' [-Wunused-const-variable]
static const unsigned int NumberOfStates = DC__VOLTAGE_STATES;
  ^
1 warning generated.

Signed-off-by: Maíra Canal 
---
 drivers/gpu/drm/amd/display/dc/dml/dcn32/display_mode_vba_32.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/dc/dml/dcn32/display_mode_vba_32.c 
b/drivers/gpu/drm/amd/display/dc/dml/dcn32/display_mode_vba_32.c
index c6c3a9e6731a..dff8f8f27de4 100644
--- a/drivers/gpu/drm/amd/display/dc/dml/dcn32/display_mode_vba_32.c
+++ b/drivers/gpu/drm/amd/display/dc/dml/dcn32/display_mode_vba_32.c
@@ -30,8 +30,6 @@
 #include "../dml_inline_defs.h"
 #include "display_mode_vba_util_32.h"
 
-static const unsigned int NumberOfStates = DC__VOLTAGE_STATES;
-
 void dml32_recalculate(struct display_mode_lib *mode_lib);
 static void 
DISPCLKDPPCLKDCFCLKDeepSleepPrefetchParametersWatermarksAndPerformanceCalculation(
struct display_mode_lib *mode_lib);
-- 
2.36.1



Re: [PATCH] drm/amd/debugfs: Expose GFXOFF state to userspace

2022-07-14 Thread André Almeida



Às 13:42 de 14/07/22, Alex Deucher escreveu:
> On Wed, Jul 13, 2022 at 11:15 AM André Almeida  wrote:
>>
>> GFXOFF has two different "state" values: one to define if the GPU is
>> allowed/disallowed to enter GFXOFF, usually called state; and another
>> one to define if currently GFXOFF is being used, usually called status.
>> Even when GFXOFF is allowed, GPU firmware can decide to not used it
>> accordingly to the GPU load.
>>
>> Userspace can allow/disallow GPUs to enter into GFXOFF via debugfs. The
>> kernel maintains a counter of requests for GFXOFF (gfx_off_req_count)
>> that should be decreased to allow GFXOFF and increased to disallow.
>>
>> The issue with this interface is that userspace can't be sure if GFXOFF
>> is currently allowed. Even by checking amdgpu_gfxoff file, one might get
>> an ambiguous 2, that means that GPU is currently out of GFXOFF, but that
>> can be either because it's currently disallowed or because it's allowed
>> but given the current GPU load it's enabled. Then, userspace needs to
>> rely on the fact that GFXOFF is enabled by default on boot and to track
>> this information.
>>
>> To make userspace life easier and GFXOFF more reliable, return the
>> current state of GFXOFF to userspace when reading amdgpu_gfxoff with the
>> same semantics of writing: 0 means not allowed, not 0 means allowed.
>>
> 
> This looks good. Can you document this in the amdgpu kerneldoc?
> 

Sure, let me send a v2 with that

> Alex
> 
>> Expose the current status of GFXOFF through a new file,
>> amdgpu_gfxoff_status.
>>
>> Signed-off-by: André Almeida 
>> ---
>>  drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 49 -
>>  1 file changed, 47 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c 
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
>> index f3b3c688e4e7..e2eec985adb3 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
>> @@ -1117,13 +1117,50 @@ static ssize_t amdgpu_debugfs_gfxoff_read(struct 
>> file *f, char __user *buf,
>> }
>>
>> while (size) {
>> -   uint32_t value;
>> +   u32 value = adev->gfx.gfx_off_state;
>> +
>> +   r = put_user(value, (u32 *)buf);
>> +   if (r)
>> +   goto out;
>> +
>> +   result += 4;
>> +   buf += 4;
>> +   *pos += 4;
>> +   size -= 4;
>> +   }
>> +
>> +   r = result;
>> +out:
>> +   pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
>> +   pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
>> +
>> +   return r;
>> +}
>> +
>> +static ssize_t amdgpu_debugfs_gfxoff_status_read(struct file *f, char 
>> __user *buf,
>> +size_t size, loff_t *pos)
>> +{
>> +   struct amdgpu_device *adev = file_inode(f)->i_private;
>> +   ssize_t result = 0;
>> +   int r;
>> +
>> +   if (size & 0x3 || *pos & 0x3)
>> +   return -EINVAL;
>> +
>> +   r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
>> +   if (r < 0) {
>> +   pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
>> +   return r;
>> +   }
>> +
>> +   while (size) {
>> +   u32 value;
>>
>> r = amdgpu_get_gfx_off_status(adev, );
>> if (r)
>> goto out;
>>
>> -   r = put_user(value, (uint32_t *)buf);
>> +   r = put_user(value, (u32 *)buf);
>> if (r)
>> goto out;
>>
>> @@ -1206,6 +1243,12 @@ static const struct file_operations 
>> amdgpu_debugfs_gfxoff_fops = {
>> .llseek = default_llseek
>>  };
>>
>> +static const struct file_operations amdgpu_debugfs_gfxoff_status_fops = {
>> +   .owner = THIS_MODULE,
>> +   .read = amdgpu_debugfs_gfxoff_status_read,
>> +   .llseek = default_llseek
>> +};
>> +
>>  static const struct file_operations *debugfs_regs[] = {
>> _debugfs_regs_fops,
>> _debugfs_regs2_fops,
>> @@ -1217,6 +1260,7 @@ static const struct file_operations *debugfs_regs[] = {
>> _debugfs_wave_fops,
>> _debugfs_gpr_fops,
>> _debugfs_gfxoff_fops,
>> +   _debugfs_gfxoff_status_fops,
>>  };
>>
>>  static const char *debugfs_regs_names[] = {
>> @@ -1230,6 +1274,7 @@ static const char *debugfs_regs_names[] = {
>> "amdgpu_wave",
>> "amdgpu_gpr",
>> "amdgpu_gfxoff",
>> +   "amdgpu_gfxoff_status",
>>  };
>>
>>  /**
>> --
>> 2.37.0
>>


[PATCH 04/12] drm/amd/display: Remove unused dml32_CalculatedoublePipeDPPCLKAndSCLThroughput function

2022-07-14 Thread Maíra Canal
Remove dml32_CalculatedoublePipeDPPCLKAndSCLThroughput function, which is not 
used in
the codebase.

This was pointed by clang with the following warning:

drivers/gpu/drm/amd/amdgpu/../display/dc/dml/dcn32/display_mode_vba_util_32.c:393:6:
warning: no previous prototype for function
'dml32_CalculatedoublePipeDPPCLKAndSCLThroughput' [-Wmissing-prototypes]
void dml32_CalculatedoublePipeDPPCLKAndSCLThroughput(
 ^
drivers/gpu/drm/amd/amdgpu/../display/dc/dml/dcn32/display_mode_vba_util_32.c:393:1:
note: declare 'static' if the function is not intended to be used outside of
this translation unit
void dml32_CalculatedoublePipeDPPCLKAndSCLThroughput(
^
static
1 warning generated.

Signed-off-by: Maíra Canal 
---
 .../dc/dml/dcn32/display_mode_vba_util_32.c   | 54 ---
 1 file changed, 54 deletions(-)

diff --git 
a/drivers/gpu/drm/amd/display/dc/dml/dcn32/display_mode_vba_util_32.c 
b/drivers/gpu/drm/amd/display/dc/dml/dcn32/display_mode_vba_util_32.c
index 5a701d9df0f7..4d62ab0c1a78 100644
--- a/drivers/gpu/drm/amd/display/dc/dml/dcn32/display_mode_vba_util_32.c
+++ b/drivers/gpu/drm/amd/display/dc/dml/dcn32/display_mode_vba_util_32.c
@@ -390,60 +390,6 @@ void dml32_CalculateBytePerPixelAndBlockSizes(
 #endif
 } // CalculateBytePerPixelAndBlockSizes
 
-void dml32_CalculatedoublePipeDPPCLKAndSCLThroughput(
-   double HRatio,
-   double HRatioChroma,
-   double VRatio,
-   double VRatioChroma,
-   double MaxDCHUBToPSCLThroughput,
-   double MaxPSCLToLBThroughput,
-   double PixelClock,
-   enum source_format_class SourcePixelFormat,
-   unsigned int HTaps,
-   unsigned int HTapsChroma,
-   unsigned int VTaps,
-   unsigned int VTapsChroma,
-
-   /* output */
-   double *PSCL_THROUGHPUT,
-   double *PSCL_THROUGHPUT_CHROMA,
-   double *DPPCLKUsingdoubleDPP)
-{
-   double DPPCLKUsingdoubleDPPLuma;
-   double DPPCLKUsingdoubleDPPChroma;
-
-   if (HRatio > 1) {
-   *PSCL_THROUGHPUT = dml_min(MaxDCHUBToPSCLThroughput, 
MaxPSCLToLBThroughput * HRatio /
-   dml_ceil((double) HTaps / 6.0, 1.0));
-   } else {
-   *PSCL_THROUGHPUT = dml_min(MaxDCHUBToPSCLThroughput, 
MaxPSCLToLBThroughput);
-   }
-
-   DPPCLKUsingdoubleDPPLuma = PixelClock * dml_max3(VTaps / 6 * dml_min(1, 
HRatio), HRatio * VRatio /
-   *PSCL_THROUGHPUT, 1);
-
-   if ((HTaps > 6 || VTaps > 6) && DPPCLKUsingdoubleDPPLuma < 2 * 
PixelClock)
-   DPPCLKUsingdoubleDPPLuma = 2 * PixelClock;
-
-   if ((SourcePixelFormat != dm_420_8 && SourcePixelFormat != dm_420_10 && 
SourcePixelFormat != dm_420_12 &&
-   SourcePixelFormat != dm_rgbe_alpha)) {
-   *PSCL_THROUGHPUT_CHROMA = 0;
-   *DPPCLKUsingdoubleDPP = DPPCLKUsingdoubleDPPLuma;
-   } else {
-   if (HRatioChroma > 1) {
-   *PSCL_THROUGHPUT_CHROMA = 
dml_min(MaxDCHUBToPSCLThroughput, MaxPSCLToLBThroughput *
-   HRatioChroma / dml_ceil((double) 
HTapsChroma / 6.0, 1.0));
-   } else {
-   *PSCL_THROUGHPUT_CHROMA = 
dml_min(MaxDCHUBToPSCLThroughput, MaxPSCLToLBThroughput);
-   }
-   DPPCLKUsingdoubleDPPChroma = PixelClock * dml_max3(VTapsChroma 
/ 6 * dml_min(1, HRatioChroma),
-   HRatioChroma * VRatioChroma / 
*PSCL_THROUGHPUT_CHROMA, 1);
-   if ((HTapsChroma > 6 || VTapsChroma > 6) && 
DPPCLKUsingdoubleDPPChroma < 2 * PixelClock)
-   DPPCLKUsingdoubleDPPChroma = 2 * PixelClock;
-   *DPPCLKUsingdoubleDPP = dml_max(DPPCLKUsingdoubleDPPLuma, 
DPPCLKUsingdoubleDPPChroma);
-   }
-}
-
 void dml32_CalculateSwathAndDETConfiguration(
unsigned int DETSizeOverride[],
enum dm_use_mall_for_pstate_change_mode 
UseMALLForPStateChange[],
-- 
2.36.1



[PATCH 03/12] drm/amd/display: Remove unused clk_src variable

2022-07-14 Thread Maíra Canal
Remove the variable clk_src from the function dcn3_get_pix_clk_dividers.

This was pointed by clang with the following warning:

drivers/gpu/drm/amd/amdgpu/../display/dc/dce/dce_clock_source.c:1279:25: 
warning:
variable 'clk_src' set but not used [-Wunused-but-set-variable]
struct dce110_clk_src *clk_src;
   ^
1 warning generated.

Signed-off-by: Maíra Canal 
---
 drivers/gpu/drm/amd/display/dc/dce/dce_clock_source.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/dc/dce/dce_clock_source.c 
b/drivers/gpu/drm/amd/display/dc/dce/dce_clock_source.c
index 5cc7cc0b2f2d..d55da1ab1ac2 100644
--- a/drivers/gpu/drm/amd/display/dc/dce/dce_clock_source.c
+++ b/drivers/gpu/drm/amd/display/dc/dce/dce_clock_source.c
@@ -1276,9 +1276,7 @@ static uint32_t dcn3_get_pix_clk_dividers(
struct pll_settings *pll_settings)
 {
unsigned long long actual_pix_clk_100Hz = pix_clk_params ? 
pix_clk_params->requested_pix_clk_100hz : 0;
-   struct dce110_clk_src *clk_src;
 
-   clk_src = TO_DCE110_CLK_SRC(cs);
DC_LOGGER_INIT();
 
if (pix_clk_params == NULL || pll_settings == NULL
-- 
2.36.1



[PATCH 02/12] drm/amd/display: Change get_pipe_idx function scope

2022-07-14 Thread Maíra Canal
Turn previously global function into a static function as it is not used
outside the file.

Signed-off-by: Maíra Canal 
---
 drivers/gpu/drm/amd/display/dc/dml/display_mode_vba.c | 2 +-
 drivers/gpu/drm/amd/display/dc/dml/display_mode_vba.h | 1 -
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/dc/dml/display_mode_vba.c 
b/drivers/gpu/drm/amd/display/dc/dml/display_mode_vba.c
index 39f93072b5e0..c5a0a3649e9a 100644
--- a/drivers/gpu/drm/amd/display/dc/dml/display_mode_vba.c
+++ b/drivers/gpu/drm/amd/display/dc/dml/display_mode_vba.c
@@ -251,7 +251,7 @@ unsigned int get_total_surface_size_in_mall_bytes(
return size;
 }
 
-unsigned int get_pipe_idx(struct display_mode_lib *mode_lib, unsigned int 
plane_idx)
+static unsigned int get_pipe_idx(struct display_mode_lib *mode_lib, unsigned 
int plane_idx)
 {
int pipe_idx = -1;
int i;
diff --git a/drivers/gpu/drm/amd/display/dc/dml/display_mode_vba.h 
b/drivers/gpu/drm/amd/display/dc/dml/display_mode_vba.h
index 47b149d4bfcf..6e61b5382361 100644
--- a/drivers/gpu/drm/amd/display/dc/dml/display_mode_vba.h
+++ b/drivers/gpu/drm/amd/display/dc/dml/display_mode_vba.h
@@ -165,7 +165,6 @@ unsigned int get_total_surface_size_in_mall_bytes(
struct display_mode_lib *mode_lib,
const display_e2e_pipe_params_st *pipes,
unsigned int num_pipes);
-unsigned int get_pipe_idx(struct display_mode_lib *mode_lib, unsigned int 
plane_idx);
 
 bool get_is_phantom_pipe(struct display_mode_lib *mode_lib,
const display_e2e_pipe_params_st *pipes,
-- 
2.36.1



[PATCH 01/12] drm/amdgpu: Write masked value to control register

2022-07-14 Thread Maíra Canal
On the dce_v6_0 and dce_v8_0 hpd tear down callback, the tmp variable
should be written into the control register instead of 0.

Fixes: b00861b9 ("drm/amd/amdgpu: port of DCE v6 to new headers (v3)")
Fixes: 2285b91c ("drm/amdgpu/dce8: simplify hpd code")
Signed-off-by: Maíra Canal 
---
 drivers/gpu/drm/amd/amdgpu/dce_v6_0.c | 2 +-
 drivers/gpu/drm/amd/amdgpu/dce_v8_0.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c 
b/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c
index f5a29526684d..0a7b1c002822 100644
--- a/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c
@@ -339,7 +339,7 @@ static void dce_v6_0_hpd_fini(struct amdgpu_device *adev)
 
tmp = RREG32(mmDC_HPD1_CONTROL + 
hpd_offsets[amdgpu_connector->hpd.hpd]);
tmp &= ~DC_HPD1_CONTROL__DC_HPD1_EN_MASK;
-   WREG32(mmDC_HPD1_CONTROL + 
hpd_offsets[amdgpu_connector->hpd.hpd], 0);
+   WREG32(mmDC_HPD1_CONTROL + 
hpd_offsets[amdgpu_connector->hpd.hpd], tmp);
 
amdgpu_irq_put(adev, >hpd_irq, amdgpu_connector->hpd.hpd);
}
diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c 
b/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c
index 780a8aa972fe..f57f4a25cf5a 100644
--- a/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c
@@ -333,7 +333,7 @@ static void dce_v8_0_hpd_fini(struct amdgpu_device *adev)
 
tmp = RREG32(mmDC_HPD1_CONTROL + 
hpd_offsets[amdgpu_connector->hpd.hpd]);
tmp &= ~DC_HPD1_CONTROL__DC_HPD1_EN_MASK;
-   WREG32(mmDC_HPD1_CONTROL + 
hpd_offsets[amdgpu_connector->hpd.hpd], 0);
+   WREG32(mmDC_HPD1_CONTROL + 
hpd_offsets[amdgpu_connector->hpd.hpd], tmp);
 
amdgpu_irq_put(adev, >hpd_irq, amdgpu_connector->hpd.hpd);
}
-- 
2.36.1



Re: [PATCH] drm/amd/debugfs: Expose GFXOFF state to userspace

2022-07-14 Thread Alex Deucher
On Wed, Jul 13, 2022 at 11:15 AM André Almeida  wrote:
>
> GFXOFF has two different "state" values: one to define if the GPU is
> allowed/disallowed to enter GFXOFF, usually called state; and another
> one to define if currently GFXOFF is being used, usually called status.
> Even when GFXOFF is allowed, GPU firmware can decide to not used it
> accordingly to the GPU load.
>
> Userspace can allow/disallow GPUs to enter into GFXOFF via debugfs. The
> kernel maintains a counter of requests for GFXOFF (gfx_off_req_count)
> that should be decreased to allow GFXOFF and increased to disallow.
>
> The issue with this interface is that userspace can't be sure if GFXOFF
> is currently allowed. Even by checking amdgpu_gfxoff file, one might get
> an ambiguous 2, that means that GPU is currently out of GFXOFF, but that
> can be either because it's currently disallowed or because it's allowed
> but given the current GPU load it's enabled. Then, userspace needs to
> rely on the fact that GFXOFF is enabled by default on boot and to track
> this information.
>
> To make userspace life easier and GFXOFF more reliable, return the
> current state of GFXOFF to userspace when reading amdgpu_gfxoff with the
> same semantics of writing: 0 means not allowed, not 0 means allowed.
>

This looks good. Can you document this in the amdgpu kerneldoc?

Alex

> Expose the current status of GFXOFF through a new file,
> amdgpu_gfxoff_status.
>
> Signed-off-by: André Almeida 
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 49 -
>  1 file changed, 47 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
> index f3b3c688e4e7..e2eec985adb3 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
> @@ -1117,13 +1117,50 @@ static ssize_t amdgpu_debugfs_gfxoff_read(struct file 
> *f, char __user *buf,
> }
>
> while (size) {
> -   uint32_t value;
> +   u32 value = adev->gfx.gfx_off_state;
> +
> +   r = put_user(value, (u32 *)buf);
> +   if (r)
> +   goto out;
> +
> +   result += 4;
> +   buf += 4;
> +   *pos += 4;
> +   size -= 4;
> +   }
> +
> +   r = result;
> +out:
> +   pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
> +   pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
> +
> +   return r;
> +}
> +
> +static ssize_t amdgpu_debugfs_gfxoff_status_read(struct file *f, char __user 
> *buf,
> +size_t size, loff_t *pos)
> +{
> +   struct amdgpu_device *adev = file_inode(f)->i_private;
> +   ssize_t result = 0;
> +   int r;
> +
> +   if (size & 0x3 || *pos & 0x3)
> +   return -EINVAL;
> +
> +   r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
> +   if (r < 0) {
> +   pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
> +   return r;
> +   }
> +
> +   while (size) {
> +   u32 value;
>
> r = amdgpu_get_gfx_off_status(adev, );
> if (r)
> goto out;
>
> -   r = put_user(value, (uint32_t *)buf);
> +   r = put_user(value, (u32 *)buf);
> if (r)
> goto out;
>
> @@ -1206,6 +1243,12 @@ static const struct file_operations 
> amdgpu_debugfs_gfxoff_fops = {
> .llseek = default_llseek
>  };
>
> +static const struct file_operations amdgpu_debugfs_gfxoff_status_fops = {
> +   .owner = THIS_MODULE,
> +   .read = amdgpu_debugfs_gfxoff_status_read,
> +   .llseek = default_llseek
> +};
> +
>  static const struct file_operations *debugfs_regs[] = {
> _debugfs_regs_fops,
> _debugfs_regs2_fops,
> @@ -1217,6 +1260,7 @@ static const struct file_operations *debugfs_regs[] = {
> _debugfs_wave_fops,
> _debugfs_gpr_fops,
> _debugfs_gfxoff_fops,
> +   _debugfs_gfxoff_status_fops,
>  };
>
>  static const char *debugfs_regs_names[] = {
> @@ -1230,6 +1274,7 @@ static const char *debugfs_regs_names[] = {
> "amdgpu_wave",
> "amdgpu_gpr",
> "amdgpu_gfxoff",
> +   "amdgpu_gfxoff_status",
>  };
>
>  /**
> --
> 2.37.0
>


Re: [PATCH] drm/amd/display: Remove unnecessary NULL check in commit_planes_for_stream()

2022-07-14 Thread Alex Deucher
Applied.  Thanks!

Alex

On Wed, Jul 13, 2022 at 7:34 AM Dan Carpenter  wrote:
>
> Smatch complains that:
>
> drivers/gpu/drm/amd/amdgpu/../display/dc/core/dc.c:3369 
> commit_planes_for_stream()
> warn: variable dereferenced before check 'stream' (see line 3114)
>
> The 'stream' pointer cannot be NULL and the check can be removed.
>
> Signed-off-by: Dan Carpenter 
> ---
>  drivers/gpu/drm/amd/display/dc/core/dc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/amd/display/dc/core/dc.c 
> b/drivers/gpu/drm/amd/display/dc/core/dc.c
> index dc2c59995a19..76f9af2c5e19 100644
> --- a/drivers/gpu/drm/amd/display/dc/core/dc.c
> +++ b/drivers/gpu/drm/amd/display/dc/core/dc.c
> @@ -3366,7 +3366,7 @@ static void commit_planes_for_stream(struct dc *dc,
> top_pipe_to_program->stream_res.tg,
> CRTC_STATE_VACTIVE);
>
> -   if (stream && should_use_dmub_lock(stream->link)) {
> +   if (should_use_dmub_lock(stream->link)) {
> union dmub_hw_lock_flags hw_locks = { 0 };
> struct dmub_hw_lock_inst_flags inst_flags = { 
> 0 };
>
> --
> 2.35.1
>


Re: [PATCH] drm/amdgpu: Clarify asics naming in Kconfig options

2022-07-14 Thread Alex Deucher
Applied.  Thanks!

On Thu, Jul 14, 2022 at 9:50 AM André Almeida  wrote:
>
> Clarify which architecture those asics acronyms refers to.
>
> Signed-off-by: André Almeida 
> ---
>  drivers/gpu/drm/amd/amdgpu/Kconfig | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/Kconfig 
> b/drivers/gpu/drm/amd/amdgpu/Kconfig
> index 74a8105fd2c0..d55275de 100644
> --- a/drivers/gpu/drm/amd/amdgpu/Kconfig
> +++ b/drivers/gpu/drm/amd/amdgpu/Kconfig
> @@ -4,7 +4,7 @@ config DRM_AMDGPU_SI
> depends on DRM_AMDGPU
> help
>   Choose this option if you want to enable experimental support
> - for SI asics.
> + for SI (Southern Islands) asics.
>
>   SI is already supported in radeon. Experimental support for SI
>   in amdgpu will be disabled by default and is still provided by
> @@ -16,7 +16,8 @@ config DRM_AMDGPU_CIK
> bool "Enable amdgpu support for CIK parts"
> depends on DRM_AMDGPU
> help
> - Choose this option if you want to enable support for CIK asics.
> + Choose this option if you want to enable support for CIK (Sea
> + Islands) asics.
>
>   CIK is already supported in radeon. Support for CIK in amdgpu
>   will be disabled by default and is still provided by radeon.
> --
> 2.37.0
>


Re: [PATCH][next] drm/amd/display: Fix spelling mistake "supporing" -> "supporting"

2022-07-14 Thread Alex Deucher
Applied.  Thanks!

Alex

On Thu, Jul 14, 2022 at 6:34 AM Colin Ian King  wrote:
>
> There is a spelling mistake in a dml_print message. Fix it.
>
> Signed-off-by: Colin Ian King 
> ---
>  .../gpu/drm/amd/display/dc/dml/dcn314/display_mode_vba_314.c| 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/amd/display/dc/dml/dcn314/display_mode_vba_314.c 
> b/drivers/gpu/drm/amd/display/dc/dml/dcn314/display_mode_vba_314.c
> index 6101c962ab0a..fc4d7474c111 100644
> --- a/drivers/gpu/drm/amd/display/dc/dml/dcn314/display_mode_vba_314.c
> +++ b/drivers/gpu/drm/amd/display/dc/dml/dcn314/display_mode_vba_314.c
> @@ -2994,7 +2994,7 @@ static void 
> DISPCLKDPPCLKDCFCLKDeepSleepPrefetchParametersWatermarksAndPerforman
> for (k = 0; k < v->NumberOfActivePlanes; ++k) {
> if (v->ImmediateFlipSupportedForPipe[k] == 
> false) {
>  #ifdef __DML_VBA_DEBUG__
> -   dml_print("DML::%s: Pipe %0d not 
> supporing iflip\n", __func__, k);
> +   dml_print("DML::%s: Pipe %0d not 
> supporting iflip\n", __func__, k);
>  #endif
> v->ImmediateFlipSupported = false;
> }
> --
> 2.35.3
>


Re: [PATCH] drm/amd/display: Enable building new display engine with KCOV enabled

2022-07-14 Thread Alex Deucher
Applied.  Thanks!

On Wed, Jul 13, 2022 at 4:03 PM Harry Wentland  wrote:
>
> On 2022-07-12 18:42, Guenter Roeck wrote:
> > The new display engine uses floating point math, which is not supported
> > by KCOV. Commit 9d1d02ff3678 ("drm/amd/display: Don't build DCN1 when kcov
> > is enabled") tried to work around the problem by disabling
> > CONFIG_DRM_AMD_DC_DCN if KCOV_INSTRUMENT_ALL and KCOV_ENABLE_COMPARISONS
> > are enabled. The result is that KCOV can not be enabled on systems which
> > require this display engine. A much simpler and less invasive solution is
> > to disable KCOV selectively when compiling the display enagine while
> > keeping it enabled for the rest of the kernel.
> >
> > Fixes: 9d1d02ff3678 ("drm/amd/display: Don't build DCN1 when kcov is 
> > enabled")
> > Cc: Arnd Bergmann 
> > Cc: Leo Li 
> > Signed-off-by: Guenter Roeck 
>
> Reviewed-by: Harry Wentland 
>
> Harry
>
> > ---
> >  drivers/gpu/drm/amd/display/Kconfig | 2 +-
> >  drivers/gpu/drm/amd/display/dc/Makefile | 3 +++
> >  2 files changed, 4 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/gpu/drm/amd/display/Kconfig 
> > b/drivers/gpu/drm/amd/display/Kconfig
> > index b4029c0d5d8c..96cbc87f7b6b 100644
> > --- a/drivers/gpu/drm/amd/display/Kconfig
> > +++ b/drivers/gpu/drm/amd/display/Kconfig
> > @@ -6,7 +6,7 @@ config DRM_AMD_DC
> >   bool "AMD DC - Enable new display engine"
> >   default y
> >   select SND_HDA_COMPONENT if SND_HDA_CORE
> > - select DRM_AMD_DC_DCN if (X86 || PPC64) && !(KCOV_INSTRUMENT_ALL && 
> > KCOV_ENABLE_COMPARISONS)
> > + select DRM_AMD_DC_DCN if (X86 || PPC64)
> >   help
> > Choose this option if you want to use the new display engine
> > support for AMDGPU. This adds required support for Vega and
> > diff --git a/drivers/gpu/drm/amd/display/dc/Makefile 
> > b/drivers/gpu/drm/amd/display/dc/Makefile
> > index b4eca0236435..b801973749d2 100644
> > --- a/drivers/gpu/drm/amd/display/dc/Makefile
> > +++ b/drivers/gpu/drm/amd/display/dc/Makefile
> > @@ -26,6 +26,9 @@
> >  DC_LIBS = basics bios dml clk_mgr dce gpio irq link virtual
> >
> >  ifdef CONFIG_DRM_AMD_DC_DCN
> > +
> > +KCOV_INSTRUMENT := n
> > +
> >  DC_LIBS += dcn20
> >  DC_LIBS += dsc
> >  DC_LIBS += dcn10
>


Re: [PATCH 01/10] drm/sched: move calling drm_sched_entity_select_rq

2022-07-14 Thread Christian König

We need this for limiting codecs like AV1 to the first instance for VCN3.

Essentially the idea is that we first initialize the job with entity, id 
etc... and before we submit it we select a new rq for the entity. In the 
meantime the VCN3 inline parse will have modified the available rqs for 
the entity.


See the patch "revert "fix limiting AV1 to the first instance on VCN3"" 
as well.


Christian.

Am 14.07.22 um 17:43 schrieb Andrey Grodzovsky:
Can you please remind me of the use case that requires this ? I 
browsed through
related mails in the past but haven't found when is that needed. For 
amdgpu

drm_sched_job_init and drm_sched_job_arm are called together and amdgpu
is the only one who supports modifying entity priority on the fly as 
far as i see.


Andrey

On 2022-07-14 06:38, Christian König wrote:

We already discussed that the call to drm_sched_entity_select_rq() needs
to move to drm_sched_job_arm() to be able to set a new scheduler list
between _init() and _arm(). This was just not applied for some reason.

Signed-off-by: Christian König 
CC: Andrey Grodzovsky 
CC: dri-de...@lists.freedesktop.org
---
  drivers/gpu/drm/scheduler/sched_main.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/scheduler/sched_main.c 
b/drivers/gpu/drm/scheduler/sched_main.c

index 68317d3a7a27..e0ab14e0fb6b 100644
--- a/drivers/gpu/drm/scheduler/sched_main.c
+++ b/drivers/gpu/drm/scheduler/sched_main.c
@@ -592,7 +592,6 @@ int drm_sched_job_init(struct drm_sched_job *job,
 struct drm_sched_entity *entity,
 void *owner)
  {
-    drm_sched_entity_select_rq(entity);
  if (!entity->rq)
  return -ENOENT;
  @@ -628,7 +627,7 @@ void drm_sched_job_arm(struct drm_sched_job *job)
  struct drm_sched_entity *entity = job->entity;
    BUG_ON(!entity);
-
+    drm_sched_entity_select_rq(entity);
  sched = entity->rq->sched;
    job->sched = sched;




[PATCH] mm: move page zone helpers from mm.h to mmzone.h

2022-07-14 Thread Alex Sierra
[WHY]
It makes more sense to have these helpers in zone specific header
file, rather than the generic mm.h

Signed-off-by: Alex Sierra 
---
 include/linux/memremap.h |  2 +-
 include/linux/mm.h   | 78 ---
 include/linux/mmzone.h   | 80 
 3 files changed, 81 insertions(+), 79 deletions(-)

diff --git a/include/linux/memremap.h b/include/linux/memremap.h
index 8af304f6b504..77229165c914 100644
--- a/include/linux/memremap.h
+++ b/include/linux/memremap.h
@@ -2,7 +2,7 @@
 #ifndef _LINUX_MEMREMAP_H_
 #define _LINUX_MEMREMAP_H_
 
-#include 
+#include 
 #include 
 #include 
 #include 
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 3b31b33bd5be..2df8c2b98d36 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -1049,84 +1049,6 @@ vm_fault_t finish_mkwrite_fault(struct vm_fault *vmf);
  *   back into memory.
  */
 
-/*
- * The zone field is never updated after free_area_init_core()
- * sets it, so none of the operations on it need to be atomic.
- */
-
-/* Page flags: | [SECTION] | [NODE] | ZONE | [LAST_CPUPID] | ... | FLAGS | */
-#define SECTIONS_PGOFF ((sizeof(unsigned long)*8) - SECTIONS_WIDTH)
-#define NODES_PGOFF(SECTIONS_PGOFF - NODES_WIDTH)
-#define ZONES_PGOFF(NODES_PGOFF - ZONES_WIDTH)
-#define LAST_CPUPID_PGOFF  (ZONES_PGOFF - LAST_CPUPID_WIDTH)
-#define KASAN_TAG_PGOFF(LAST_CPUPID_PGOFF - KASAN_TAG_WIDTH)
-
-/*
- * Define the bit shifts to access each section.  For non-existent
- * sections we define the shift as 0; that plus a 0 mask ensures
- * the compiler will optimise away reference to them.
- */
-#define SECTIONS_PGSHIFT   (SECTIONS_PGOFF * (SECTIONS_WIDTH != 0))
-#define NODES_PGSHIFT  (NODES_PGOFF * (NODES_WIDTH != 0))
-#define ZONES_PGSHIFT  (ZONES_PGOFF * (ZONES_WIDTH != 0))
-#define LAST_CPUPID_PGSHIFT(LAST_CPUPID_PGOFF * (LAST_CPUPID_WIDTH != 0))
-#define KASAN_TAG_PGSHIFT  (KASAN_TAG_PGOFF * (KASAN_TAG_WIDTH != 0))
-
-/* NODE:ZONE or SECTION:ZONE is used to ID a zone for the buddy allocator */
-#ifdef NODE_NOT_IN_PAGE_FLAGS
-#define ZONEID_SHIFT   (SECTIONS_SHIFT + ZONES_SHIFT)
-#define ZONEID_PGOFF   ((SECTIONS_PGOFF < ZONES_PGOFF)? \
-   SECTIONS_PGOFF : ZONES_PGOFF)
-#else
-#define ZONEID_SHIFT   (NODES_SHIFT + ZONES_SHIFT)
-#define ZONEID_PGOFF   ((NODES_PGOFF < ZONES_PGOFF)? \
-   NODES_PGOFF : ZONES_PGOFF)
-#endif
-
-#define ZONEID_PGSHIFT (ZONEID_PGOFF * (ZONEID_SHIFT != 0))
-
-#define ZONES_MASK ((1UL << ZONES_WIDTH) - 1)
-#define NODES_MASK ((1UL << NODES_WIDTH) - 1)
-#define SECTIONS_MASK  ((1UL << SECTIONS_WIDTH) - 1)
-#define LAST_CPUPID_MASK   ((1UL << LAST_CPUPID_SHIFT) - 1)
-#define KASAN_TAG_MASK ((1UL << KASAN_TAG_WIDTH) - 1)
-#define ZONEID_MASK((1UL << ZONEID_SHIFT) - 1)
-
-static inline enum zone_type page_zonenum(const struct page *page)
-{
-   ASSERT_EXCLUSIVE_BITS(page->flags, ZONES_MASK << ZONES_PGSHIFT);
-   return (page->flags >> ZONES_PGSHIFT) & ZONES_MASK;
-}
-
-static inline enum zone_type folio_zonenum(const struct folio *folio)
-{
-   return page_zonenum(>page);
-}
-
-#ifdef CONFIG_ZONE_DEVICE
-static inline bool is_zone_device_page(const struct page *page)
-{
-   return page_zonenum(page) == ZONE_DEVICE;
-}
-extern void memmap_init_zone_device(struct zone *, unsigned long,
-   unsigned long, struct dev_pagemap *);
-#else
-static inline bool is_zone_device_page(const struct page *page)
-{
-   return false;
-}
-#endif
-
-static inline bool folio_is_zone_device(const struct folio *folio)
-{
-   return is_zone_device_page(>page);
-}
-
-static inline bool is_zone_movable_page(const struct page *page)
-{
-   return page_zonenum(page) == ZONE_MOVABLE;
-}
-
 #if defined(CONFIG_ZONE_DEVICE) && defined(CONFIG_FS_DAX)
 DECLARE_STATIC_KEY_FALSE(devmap_managed_key);
 
diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index aab70355d64f..47fc41f43c48 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -730,6 +730,86 @@ static inline bool zone_is_empty(struct zone *zone)
return zone->spanned_pages == 0;
 }
 
+#ifndef BUILD_VDSO32_64
+/*
+ * The zone field is never updated after free_area_init_core()
+ * sets it, so none of the operations on it need to be atomic.
+ */
+
+/* Page flags: | [SECTION] | [NODE] | ZONE | [LAST_CPUPID] | ... | FLAGS | */
+#define SECTIONS_PGOFF ((sizeof(unsigned long)*8) - SECTIONS_WIDTH)
+#define NODES_PGOFF(SECTIONS_PGOFF - NODES_WIDTH)
+#define ZONES_PGOFF(NODES_PGOFF - ZONES_WIDTH)
+#define LAST_CPUPID_PGOFF  (ZONES_PGOFF - LAST_CPUPID_WIDTH)
+#define KASAN_TAG_PGOFF(LAST_CPUPID_PGOFF - KASAN_TAG_WIDTH)
+
+/*
+ * Define the bit shifts to access 

Re: [PATCH -next] drm/amdgpu: double free error and freeing uninitialized null pointer

2022-07-14 Thread André Almeida
Às 12:06 de 14/07/22, Sebin Sebastian escreveu:
> On Tue, Jul 12, 2022 at 12:14:27PM -0300, André Almeida wrote:
>> Hi Sebin,
>>
>> Às 10:29 de 10/07/22, Sebin Sebastian escreveu:
>>> Fix two coverity warning's double free and and an uninitialized pointer
>>> read. Both tmp and new are pointing at same address and both are freed
>>> which leads to double free. Freeing tmp in the condition after new is
>>> assigned with new address fixes the double free issue. new is not
>>> initialized to null which also leads to a free on an uninitialized
>>> pointer.
>>> Coverity issue: 1518665 (uninitialized pointer read)
>>> 1518679 (double free)
>>
>> What are those numbers?
>>
> These numbers are the issue ID's for the errors that are being reported
> by the coverity static analyzer tool.
> 

I see, but I don't know which tool was used, so those seem like random
number to me. I would just remove this part of your commit message, but
if you want to keep it, you need to at least mention what's the tool.

>>>
>>> Signed-off-by: Sebin Sebastian 
>>> ---
>>>  drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 8 +---
>>>  1 file changed, 5 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c 
>>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
>>> index f3b3c688e4e7..d82fe0e1b06b 100644
>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
>>> @@ -1660,7 +1660,7 @@ static ssize_t 
>>> amdgpu_reset_dump_register_list_write(struct file *f,
>>>  {
>>> struct amdgpu_device *adev = (struct amdgpu_device 
>>> *)file_inode(f)->i_private;
>>> char reg_offset[11];
>>> -   uint32_t *new, *tmp = NULL;
>>> +   uint32_t *new = NULL, *tmp = NULL;
>>> int ret, i = 0, len = 0;
>>>  
>>> do {
>>> @@ -1692,17 +1692,19 @@ static ssize_t 
>>> amdgpu_reset_dump_register_list_write(struct file *f,
>>> goto error_free;
>>> }
>>
>> If the `if (!new) {` above this line is true, will be tmp freed?
>>
> Yes, It doesn't seem to free tmp here. Should I free tmp immediately
> after the do while loop and remove `kfree(tmp)` from the `if (ret)`
> block? Thanks for pointing out the errors.

If you free immediately after the while loop, then you would risk a use
after free here:

swap(adev->reset_dump_reg_list, tmp);

So this isn't the solution either.

> 
>>> ret = down_write_killable(>reset_domain->sem);
>>> -   if (ret)
>>> +   if (ret) {
>>> +   kfree(tmp);
>>> goto error_free;
>>> +   }
>>>  
>>> swap(adev->reset_dump_reg_list, tmp);
>>> swap(adev->reset_dump_reg_value, new);
>>> adev->num_regs = i;
>>> up_write(>reset_domain->sem);
>>> +   kfree(tmp);
>>> ret = size;
>>>  
>>>  error_free:
>>> -   kfree(tmp);
>>> kfree(new);
>>> return ret;
>>>  }


Re: [PATCH 01/10] drm/sched: move calling drm_sched_entity_select_rq

2022-07-14 Thread Andrey Grodzovsky
Can you please remind me of the use case that requires this ? I browsed 
through

related mails in the past but haven't found when is that needed. For amdgpu
drm_sched_job_init and drm_sched_job_arm are called together and amdgpu
is the only one who supports modifying entity priority on the fly as far 
as i see.


Andrey

On 2022-07-14 06:38, Christian König wrote:

We already discussed that the call to drm_sched_entity_select_rq() needs
to move to drm_sched_job_arm() to be able to set a new scheduler list
between _init() and _arm(). This was just not applied for some reason.

Signed-off-by: Christian König 
CC: Andrey Grodzovsky 
CC: dri-de...@lists.freedesktop.org
---
  drivers/gpu/drm/scheduler/sched_main.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/scheduler/sched_main.c 
b/drivers/gpu/drm/scheduler/sched_main.c
index 68317d3a7a27..e0ab14e0fb6b 100644
--- a/drivers/gpu/drm/scheduler/sched_main.c
+++ b/drivers/gpu/drm/scheduler/sched_main.c
@@ -592,7 +592,6 @@ int drm_sched_job_init(struct drm_sched_job *job,
   struct drm_sched_entity *entity,
   void *owner)
  {
-   drm_sched_entity_select_rq(entity);
if (!entity->rq)
return -ENOENT;
  
@@ -628,7 +627,7 @@ void drm_sched_job_arm(struct drm_sched_job *job)

struct drm_sched_entity *entity = job->entity;
  
  	BUG_ON(!entity);

-
+   drm_sched_entity_select_rq(entity);
sched = entity->rq->sched;
  
  	job->sched = sched;


Re: [PATCH 07/10] drm/amdgpu: move setting the job resources

2022-07-14 Thread Luben Tuikov
Reviewed-by: Luben Tuikov 

On 2022-07-14 06:38, Christian König wrote:
> Move setting the job resources into amdgpu_job.c
> 
> Signed-off-by: Christian König 
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c  | 21 ++---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 17 +
>  drivers/gpu/drm/amd/amdgpu/amdgpu_job.h |  2 ++
>  3 files changed, 21 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> index dfb7b4f46bc3..88f491dc7ca2 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> @@ -828,9 +828,6 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser 
> *p,
>   struct amdgpu_vm *vm = >vm;
>   struct amdgpu_bo_list_entry *e;
>   struct list_head duplicates;
> - struct amdgpu_bo *gds;
> - struct amdgpu_bo *gws;
> - struct amdgpu_bo *oa;
>   int r;
>  
>   INIT_LIST_HEAD(>validated);
> @@ -947,22 +944,8 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser 
> *p,
>   amdgpu_cs_report_moved_bytes(p->adev, p->bytes_moved,
>p->bytes_moved_vis);
>  
> - gds = p->bo_list->gds_obj;
> - gws = p->bo_list->gws_obj;
> - oa = p->bo_list->oa_obj;
> -
> - if (gds) {
> - p->job->gds_base = amdgpu_bo_gpu_offset(gds) >> PAGE_SHIFT;
> - p->job->gds_size = amdgpu_bo_size(gds) >> PAGE_SHIFT;
> - }
> - if (gws) {
> - p->job->gws_base = amdgpu_bo_gpu_offset(gws) >> PAGE_SHIFT;
> - p->job->gws_size = amdgpu_bo_size(gws) >> PAGE_SHIFT;
> - }
> - if (oa) {
> - p->job->oa_base = amdgpu_bo_gpu_offset(oa) >> PAGE_SHIFT;
> - p->job->oa_size = amdgpu_bo_size(oa) >> PAGE_SHIFT;
> - }
> + amdgpu_job_set_resources(p->job, p->bo_list->gds_obj,
> +  p->bo_list->gws_obj, p->bo_list->oa_obj);
>  
>   if (p->uf_entry.tv.bo) {
>   struct amdgpu_bo *uf = ttm_to_amdgpu_bo(p->uf_entry.tv.bo);
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
> index 36c1be77bf8f..3255b2fca611 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
> @@ -129,6 +129,23 @@ int amdgpu_job_alloc_with_ib(struct amdgpu_device *adev, 
> unsigned size,
>   return r;
>  }
>  
> +void amdgpu_job_set_resources(struct amdgpu_job *job, struct amdgpu_bo *gds,
> +   struct amdgpu_bo *gws, struct amdgpu_bo *oa)
> +{
> + if (gds) {
> + job->gds_base = amdgpu_bo_gpu_offset(gds) >> PAGE_SHIFT;
> + job->gds_size = amdgpu_bo_size(gds) >> PAGE_SHIFT;
> + }
> + if (gws) {
> + job->gws_base = amdgpu_bo_gpu_offset(gws) >> PAGE_SHIFT;
> + job->gws_size = amdgpu_bo_size(gws) >> PAGE_SHIFT;
> + }
> + if (oa) {
> + job->oa_base = amdgpu_bo_gpu_offset(oa) >> PAGE_SHIFT;
> + job->oa_size = amdgpu_bo_size(oa) >> PAGE_SHIFT;
> + }
> +}
> +
>  void amdgpu_job_free_resources(struct amdgpu_job *job)
>  {
>   struct amdgpu_ring *ring = to_amdgpu_ring(job->base.sched);
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.h 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.h
> index d599c0540b46..0bab8fe0d419 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.h
> @@ -77,6 +77,8 @@ int amdgpu_job_alloc(struct amdgpu_device *adev, unsigned 
> num_ibs,
>struct amdgpu_job **job, struct amdgpu_vm *vm);
>  int amdgpu_job_alloc_with_ib(struct amdgpu_device *adev, unsigned size,
>   enum amdgpu_ib_pool_type pool, struct amdgpu_job **job);
> +void amdgpu_job_set_resources(struct amdgpu_job *job, struct amdgpu_bo *gds,
> +   struct amdgpu_bo *gws, struct amdgpu_bo *oa);
>  void amdgpu_job_free_resources(struct amdgpu_job *job);
>  void amdgpu_job_free(struct amdgpu_job *job);
>  int amdgpu_job_submit(struct amdgpu_job *job, struct drm_sched_entity 
> *entity,

Regards,
-- 
Luben


Re: [PATCH -next] drm/amdgpu: double free error and freeing uninitialized null pointer

2022-07-14 Thread Sebin Sebastian
On Tue, Jul 12, 2022 at 12:14:27PM -0300, André Almeida wrote:
> Hi Sebin,
> 
> Às 10:29 de 10/07/22, Sebin Sebastian escreveu:
> > Fix two coverity warning's double free and and an uninitialized pointer
> > read. Both tmp and new are pointing at same address and both are freed
> > which leads to double free. Freeing tmp in the condition after new is
> > assigned with new address fixes the double free issue. new is not
> > initialized to null which also leads to a free on an uninitialized
> > pointer.
> > Coverity issue: 1518665 (uninitialized pointer read)
> > 1518679 (double free)
> 
> What are those numbers?
>
These numbers are the issue ID's for the errors that are being reported
by the coverity static analyzer tool.

> > 
> > Signed-off-by: Sebin Sebastian 
> > ---
> >  drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 8 +---
> >  1 file changed, 5 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c 
> > b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
> > index f3b3c688e4e7..d82fe0e1b06b 100644
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
> > @@ -1660,7 +1660,7 @@ static ssize_t 
> > amdgpu_reset_dump_register_list_write(struct file *f,
> >  {
> > struct amdgpu_device *adev = (struct amdgpu_device 
> > *)file_inode(f)->i_private;
> > char reg_offset[11];
> > -   uint32_t *new, *tmp = NULL;
> > +   uint32_t *new = NULL, *tmp = NULL;
> > int ret, i = 0, len = 0;
> >  
> > do {
> > @@ -1692,17 +1692,19 @@ static ssize_t 
> > amdgpu_reset_dump_register_list_write(struct file *f,
> > goto error_free;
> > }
> 
> If the `if (!new) {` above this line is true, will be tmp freed?
> 
Yes, It doesn't seem to free tmp here. Should I free tmp immediately
after the do while loop and remove `kfree(tmp)` from the `if (ret)`
block? Thanks for pointing out the errors.

> > ret = down_write_killable(>reset_domain->sem);
> > -   if (ret)
> > +   if (ret) {
> > +   kfree(tmp);
> > goto error_free;
> > +   }
> >  
> > swap(adev->reset_dump_reg_list, tmp);
> > swap(adev->reset_dump_reg_value, new);
> > adev->num_regs = i;
> > up_write(>reset_domain->sem);
> > +   kfree(tmp);
> > ret = size;
> >  
> >  error_free:
> > -   kfree(tmp);
> > kfree(new);
> > return ret;
> >  }


Re: [PATCH 02/10] drm/amdgpu: Protect the amdgpu_bo_list list with a mutex v2

2022-07-14 Thread Alex Deucher
On Thu, Jul 14, 2022 at 6:39 AM Christian König
 wrote:
>
> From: Luben Tuikov 
>
> Protect the struct amdgpu_bo_list with a mutex. This is used during command
> submission in order to avoid buffer object corruption as recorded in
> the link below.
>
> v2 (chk): Keep the mutex looked for the whole CS to avoid using the
>   list from multiple CS threads at the same time.
>
> Suggested-by: Christian König 
> Cc: Alex Deucher 
> Cc: Andrey Grodzovsky 
> Cc: Vitaly Prosyak 
> Link: https://gitlab.freedesktop.org/drm/amd/-/issues/2048
> Signed-off-by: Luben Tuikov 
> Signed-off-by: Christian König 

I think this is a valid bug fix on its own for stable.
Reviewed-by: Alex Deucher 

> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c |  3 ++-
>  drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h |  4 
>  drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c  | 16 +---
>  3 files changed, 19 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
> index 714178f1b6c6..2168163aad2d 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
> @@ -40,7 +40,7 @@ static void amdgpu_bo_list_free_rcu(struct rcu_head *rcu)
>  {
> struct amdgpu_bo_list *list = container_of(rcu, struct amdgpu_bo_list,
>rhead);
> -
> +   mutex_destroy(>bo_list_mutex);
> kvfree(list);
>  }
>
> @@ -136,6 +136,7 @@ int amdgpu_bo_list_create(struct amdgpu_device *adev, 
> struct drm_file *filp,
>
> trace_amdgpu_cs_bo_status(list->num_entries, total_size);
>
> +   mutex_init(>bo_list_mutex);
> *result = list;
> return 0;
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h
> index 529d52a204cf..9caea1688fc3 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h
> @@ -47,6 +47,10 @@ struct amdgpu_bo_list {
> struct amdgpu_bo *oa_obj;
> unsigned first_userptr;
> unsigned num_entries;
> +
> +   /* Protect access during command submission.
> +*/
> +   struct mutex bo_list_mutex;
>  };
>
>  int amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id,
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> index b28af04b0c3e..d8f1335bc68f 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> @@ -519,6 +519,8 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser 
> *p,
> return r;
> }
>
> +   mutex_lock(>bo_list->bo_list_mutex);
> +
> /* One for TTM and one for the CS job */
> amdgpu_bo_list_for_each_entry(e, p->bo_list)
> e->tv.num_shared = 2;
> @@ -651,6 +653,7 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser 
> *p,
> kvfree(e->user_pages);
> e->user_pages = NULL;
> }
> +   mutex_unlock(>bo_list->bo_list_mutex);
> }
> return r;
>  }
> @@ -690,9 +693,11 @@ static void amdgpu_cs_parser_fini(struct 
> amdgpu_cs_parser *parser, int error,
>  {
> unsigned i;
>
> -   if (error && backoff)
> +   if (error && backoff) {
> ttm_eu_backoff_reservation(>ticket,
>>validated);
> +   mutex_unlock(>bo_list->bo_list_mutex);
> +   }
>
> for (i = 0; i < parser->num_post_deps; i++) {
> drm_syncobj_put(parser->post_deps[i].syncobj);
> @@ -832,12 +837,16 @@ static int amdgpu_cs_vm_handling(struct 
> amdgpu_cs_parser *p)
> continue;
>
> r = amdgpu_vm_bo_update(adev, bo_va, false);
> -   if (r)
> +   if (r) {
> +   mutex_unlock(>bo_list->bo_list_mutex);
> return r;
> +   }
>
> r = amdgpu_sync_fence(>job->sync, bo_va->last_pt_update);
> -   if (r)
> +   if (r) {
> +   mutex_unlock(>bo_list->bo_list_mutex);
> return r;
> +   }
> }
>
> r = amdgpu_vm_handle_moved(adev, vm);
> @@ -1278,6 +1287,7 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p,
>
> ttm_eu_fence_buffer_objects(>ticket, >validated, p->fence);
> mutex_unlock(>adev->notifier_lock);
> +   mutex_unlock(>bo_list->bo_list_mutex);
>
> return 0;
>
> --
> 2.25.1
>


Re: [PATCH] Revert "drm/amdgpu: add drm buddy support to amdgpu"

2022-07-14 Thread Christian König

Am 14.07.22 um 15:33 schrieb Alex Deucher:

On Thu, Jul 14, 2022 at 9:09 AM Christian König
 wrote:

Hi Mauro,

well the last time I checked drm-tip was clean.

The revert is necessary because we had some problems with the commit
which we couldn't fix in the 5.19 cycle.

Would it be worth reverting the revert and applying the actual fix[1]?
  It's a huge revert unfortunately while the actual fix is like 10
lines of code.  I'm concerned there will be subtle fallout from the
revert due to how extensive it is.


We have other bug fixes and cleanups around that patch which didn't made 
it into 5.19 either. I don't want to create an ever greater mess.


Real question is why building drm-tip work for me but not for others?

Christian.



[1] - 
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgitlab.freedesktop.org%2Fdrm%2Famd%2Fuploads%2F564b2cc2b5ea87357f39e45c3a1a44e2%2F0001-drm-amdgpu-Fix-for-drm-buddy-memory-corruption.patchdata=05%7C01%7Cchristian.koenig%40amd.com%7Cee3322f9e7c54aaabb9f08da659d74a2%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637934024189075602%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7Csdata=cGS2JZt84FMlA4V57pAA2ilXDC5pvr8ryZcUoHpXKXA%3Dreserved=0

Alex



I will double check drm-tip once more.

Regards,
Christian.

Am 14.07.22 um 14:54 schrieb Mauro Carvalho Chehab:

On Fri, 8 Jul 2022 03:21:24 -0700
Arunpravin Paneer Selvam  wrote:


This reverts the following commits:
commit 708d19d9f362 ("drm/amdgpu: move internal vram_mgr function into the C 
file")
commit 5e3f1e7729ec ("drm/amdgpu: fix start calculation in amdgpu_vram_mgr_new")
commit c9cad937c0c5 ("drm/amdgpu: add drm buddy support to amdgpu")

[WHY]
Few users reported garbaged graphics as soon as x starts,
reverting until this can be resolved.

Signed-off-by: Arunpravin Paneer Selvam 

This revert is currently breaking drm-tip. Please revert it ASAP, as it
is preventing CI bots to properly test new patches on the top of current
drm-tip:

drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c: In function ‘amdgpu_vram_mgr_new’:
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c:459:13: error: ‘cur_size’ 
undeclared (first use in this function)
459 | if (cur_size != size) {
| ^~~~
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c:459:13: note: each undeclared 
identifier is reported only once for each function it appears in
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c:459:25: error: ‘size’ undeclared 
(first use in this function); did you mean ‘ksize’?
459 | if (cur_size != size) {
| ^~~~
| ksize
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c:465:30: error: ‘vres’ undeclared 
(first use in this function); did you mean ‘res’?
465 | trim_list = >blocks;
|  ^~~~
|  res
In file included from ./include/linux/bits.h:22,
   from ./include/linux/ratelimit_types.h:5,
   from ./include/linux/ratelimit.h:5,
   from ./include/linux/dev_printk.h:16,
   from ./include/linux/device.h:15,
   from ./include/linux/dma-mapping.h:7,
   from drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c:25:
./include/linux/container_of.h:19:54: error: invalid use of undefined type 
‘struct drm_buddy_block’
 19 | static_assert(__same_type(*(ptr), ((type *)0)->member) || 
  \
|  ^~
./include/linux/build_bug.h:78:56: note: in definition of macro 
‘__static_assert’
 78 | #define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
|^~~~
./include/linux/container_of.h:19:9: note: in expansion of macro ‘static_assert’
 19 | static_assert(__same_type(*(ptr), ((type *)0)->member) || 
  \
| ^
./include/linux/container_of.h:19:23: note: in expansion of macro ‘__same_type’
 19 | static_assert(__same_type(*(ptr), ((type *)0)->member) || 
  \
|   ^~~
./include/linux/list.h:520:9: note: in expansion of macro ‘container_of’
520 | container_of(ptr, type, member)
| ^~~~
./include/linux/list.h:542:9: note: in expansion of macro ‘list_entry’
542 | list_entry((ptr)->prev, type, member)
| ^~
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c:473:33: note: in expansion of 
macro ‘list_last_entry’
473 | block = list_last_entry(>blocks, 
typeof(*block), link);
| ^~~
././include/linux/compiler_types.h:295:27: error: expression in static 
assertion is not an integer
295 | #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), 
typeof(b))

Re: Linux 5.19-rc6

2022-07-14 Thread Geert Uytterhoeven
Hi Günter,

On Thu, Jul 14, 2022 at 3:20 PM Guenter Roeck  wrote:
> On 7/14/22 00:23, Geert Uytterhoeven wrote:
> > On Wed, Jul 13, 2022 at 11:51 PM Linus Torvalds
> >  wrote:
> >> On Wed, Jul 13, 2022 at 2:01 PM Alex Deucher  wrote:
> >>> If you want to apply Guenter's patch original patch:
> >>> https://patchwork.freedesktop.org/patch/490184/
> >>> That's fine with me.
> >>
> >> Honestly, by this time I feel that it's too little, too late.
> >
> > [...]
> >
> >> So considering that the ppc people ignored this whole issue since the
> >> merge window, I think it's entirely unreasonable to then apply a
> >> ppc-specific patch for this at this time, when people literally asked
> >> "why is this needed", and there was no reply from the powerpc side.
> >
> > Oh, it's not just this one. The lists of build regressions between v5.18
> > and v5.19-rc1 [1] resp. v5.19-rc6 [2] look surprisingly similar :-(
> >
> > [1] 
> > https://lore.kernel.org/all/20220606082201.2792145-1-ge...@linux-m68k.org
> > [2] 
> > https://lore.kernel.org/all/20220711064425.3084093-1-ge...@linux-m68k.org
> >
>
> How do you build your images ? I don't see many of the problems you report,
> even if I build the files with W=1. It is odd, since reports such as

I rely on the kisskb build service, and just parse their build logs.

> drivers/mfd/asic3.c:941:23: error: unused variable 'asic'
>
> are real, but I just don't see that. If I build that file, I see that
> it builds with -Wno-unused-but-set-variable, due to
>
> Makefile:KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable)
>
> The override in scripts/Makefile.extrawarn doesn't seem to work even though
> it adds "-Wunused-but-set-variable" to the compile flags. And if I remove
> "-Wno-unused-but-set-variable" from Makefile I still don't get the 
> error/warning.
> Confused. I must be missing something, but what ?

That particular error is seen in the sh4-gcc11/sh-allmodconfig
build[3].  I assume it is fixed by now (see commit d684e0a52d36f893
("sh: convert nommu io{re,un}map() to static inline functions")).

[3] http://kisskb.ellerman.id.au/kisskb/buildresult/14767627/

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- ge...@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds


Re: [PATCH 09/10] drm/amdgpu: add gang submit backend

2022-07-14 Thread Andrey Grodzovsky



On 2022-07-14 06:39, Christian König wrote:

Allows submitting jobs as gang which needs to run on multiple
engines at the same time.

Basic idea is that we have a global gang submit fence representing when the
gang leader is finally pushed to run on the hardware last.

Jobs submitted as gang are never re-submitted in case of a GPU reset since this
won't work and will just deadlock the hardware immediately again.

Signed-off-by: Christian König 
---
  drivers/gpu/drm/amd/amdgpu/amdgpu.h|  3 ++
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 34 ++
  drivers/gpu/drm/amd/amdgpu/amdgpu_job.c| 28 --
  drivers/gpu/drm/amd/amdgpu/amdgpu_job.h|  3 ++
  4 files changed, 66 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index 2871a3e3801f..19308db52984 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -881,6 +881,7 @@ struct amdgpu_device {
u64 fence_context;
unsignednum_rings;
struct amdgpu_ring  *rings[AMDGPU_MAX_RINGS];
+   struct dma_fence __rcu  *gang_submit;
boolib_pool_ready;
struct amdgpu_sa_managerib_pools[AMDGPU_IB_POOL_MAX];
struct amdgpu_sched 
gpu_sched[AMDGPU_HW_IP_NUM][AMDGPU_RING_PRIO_MAX];
@@ -1288,6 +1289,8 @@ u32 amdgpu_device_pcie_port_rreg(struct amdgpu_device 
*adev,
u32 reg);
  void amdgpu_device_pcie_port_wreg(struct amdgpu_device *adev,
u32 reg, u32 v);
+struct dma_fence *amdgpu_device_switch_gang(struct amdgpu_device *adev,
+   struct dma_fence *gang);
  
  /* atpx handler */

  #if defined(CONFIG_VGA_SWITCHEROO)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index e1c9587f659b..f80beb7208c0 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -3499,6 +3499,7 @@ int amdgpu_device_init(struct amdgpu_device *adev,
adev->gmc.gart_size = 512 * 1024 * 1024;
adev->accel_working = false;
adev->num_rings = 0;
+   RCU_INIT_POINTER(adev->gang_submit, dma_fence_get_stub());
adev->mman.buffer_funcs = NULL;
adev->mman.buffer_funcs_ring = NULL;
adev->vm_manager.vm_pte_funcs = NULL;
@@ -3979,6 +3980,7 @@ void amdgpu_device_fini_sw(struct amdgpu_device *adev)
release_firmware(adev->firmware.gpu_info_fw);
adev->firmware.gpu_info_fw = NULL;
adev->accel_working = false;
+   dma_fence_put(rcu_dereference_protected(adev->gang_submit, true));
  
  	amdgpu_reset_fini(adev);
  
@@ -5905,3 +5907,35 @@ void amdgpu_device_pcie_port_wreg(struct amdgpu_device *adev,

(void)RREG32(data);
spin_unlock_irqrestore(>pcie_idx_lock, flags);
  }
+
+/**
+ * amdgpu_device_switch_gang - switch to a new gang
+ * @adev: amdgpu_device pointer
+ * @gang: the gang to switch to
+ *
+ * Try to switch to a new gang or return a reference to the current gang if 
that
+ * isn't possible.
+ * Returns: Either NULL if we switched correctly or a reference to the existing
+ * gang.
+ */
+struct dma_fence *amdgpu_device_switch_gang(struct amdgpu_device *adev,
+   struct dma_fence *gang)
+{
+   struct dma_fence *old = NULL;
+
+   do {
+   dma_fence_put(old);
+   old = dma_fence_get_rcu_safe(>gang_submit);
+
+   if (old == gang)
+   break;
+
+   if (!dma_fence_is_signaled(old))
+   return old;
+
+   } while (cmpxchg((struct dma_fence __force **)>gang_submit,
+old, gang) != old);
+
+   dma_fence_put(old);
+   return NULL;
+}
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
index 3255b2fca611..f3a1fdbd41a3 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
@@ -180,11 +180,29 @@ static void amdgpu_job_free_cb(struct drm_sched_job 
*s_job)
kfree(job);
  }
  
+void amdgpu_job_set_gang_leader(struct amdgpu_job *job,

+   struct amdgpu_job *leader)
+{
+   struct dma_fence *fence = >base.s_fence->scheduled;
+
+   WARN_ON(job->gang_submit);
+
+   /*
+* Don't add a reference when we are the gang leader to avoid circle
+* dependency.
+*/
+   if (job != leader)
+   dma_fence_get(fence);
+   job->gang_submit = fence;
+}
+
  void amdgpu_job_free(struct amdgpu_job *job)
  {
amdgpu_job_free_resources(job);
amdgpu_sync_free(>sync);
amdgpu_sync_free(>sched_sync);
+   if (job->gang_submit != >base.s_fence->scheduled)
+   

Re: [PATCH] Revert "drm/amdgpu: add drm buddy support to amdgpu"

2022-07-14 Thread Mauro Carvalho Chehab
On Thu, 14 Jul 2022 09:33:23 -0400
Alex Deucher  wrote:

> On Thu, Jul 14, 2022 at 9:09 AM Christian König
>  wrote:
> >
> > Hi Mauro,
> >
> > well the last time I checked drm-tip was clean.
> >
> > The revert is necessary because we had some problems with the commit
> > which we couldn't fix in the 5.19 cycle.  
> 
> Would it be worth reverting the revert and applying the actual fix[1]?
>  It's a huge revert unfortunately while the actual fix is like 10
> lines of code.  I'm concerned there will be subtle fallout from the
> revert due to how extensive it is.
> 
> [1] - 
> https://gitlab.freedesktop.org/drm/amd/uploads/564b2cc2b5ea87357f39e45c3a1a44e2/0001-drm-amdgpu-Fix-for-drm-buddy-memory-corruption.patch

The tree now seems to be clean. I re-submitted a CI trybot job to double-check
if everything is ok.

Probably the issue was due to some badly solved merge conflict.

Thank you!
Mauro

> 
> Alex
> 
> 
> >
> > I will double check drm-tip once more.
> >
> > Regards,
> > Christian.
> >
> > Am 14.07.22 um 14:54 schrieb Mauro Carvalho Chehab:  
> > > On Fri, 8 Jul 2022 03:21:24 -0700
> > > Arunpravin Paneer Selvam  wrote:
> > >  
> > >> This reverts the following commits:
> > >> commit 708d19d9f362 ("drm/amdgpu: move internal vram_mgr function into 
> > >> the C file")
> > >> commit 5e3f1e7729ec ("drm/amdgpu: fix start calculation in 
> > >> amdgpu_vram_mgr_new")
> > >> commit c9cad937c0c5 ("drm/amdgpu: add drm buddy support to amdgpu")
> > >>
> > >> [WHY]
> > >> Few users reported garbaged graphics as soon as x starts,
> > >> reverting until this can be resolved.
> > >>
> > >> Signed-off-by: Arunpravin Paneer Selvam 
> > >>   
> > > This revert is currently breaking drm-tip. Please revert it ASAP, as it
> > > is preventing CI bots to properly test new patches on the top of current
> > > drm-tip:
> > >
> > > drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c: In function 
> > > ‘amdgpu_vram_mgr_new’:
> > > drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c:459:13: error: ‘cur_size’ 
> > > undeclared (first use in this function)
> > >459 | if (cur_size != size) {
> > >| ^~~~
> > > drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c:459:13: note: each 
> > > undeclared identifier is reported only once for each function it appears 
> > > in
> > > drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c:459:25: error: ‘size’ 
> > > undeclared (first use in this function); did you mean ‘ksize’?
> > >459 | if (cur_size != size) {
> > >| ^~~~
> > >| ksize
> > > drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c:465:30: error: ‘vres’ 
> > > undeclared (first use in this function); did you mean ‘res’?
> > >465 | trim_list = >blocks;
> > >|  ^~~~
> > >|  res
> > > In file included from ./include/linux/bits.h:22,
> > >   from ./include/linux/ratelimit_types.h:5,
> > >   from ./include/linux/ratelimit.h:5,
> > >   from ./include/linux/dev_printk.h:16,
> > >   from ./include/linux/device.h:15,
> > >   from ./include/linux/dma-mapping.h:7,
> > >   from drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c:25:
> > > ./include/linux/container_of.h:19:54: error: invalid use of undefined 
> > > type ‘struct drm_buddy_block’
> > > 19 | static_assert(__same_type(*(ptr), ((type *)0)->member) 
> > > ||   \
> > >|  ^~
> > > ./include/linux/build_bug.h:78:56: note: in definition of macro 
> > > ‘__static_assert’
> > > 78 | #define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
> > >|^~~~
> > > ./include/linux/container_of.h:19:9: note: in expansion of macro 
> > > ‘static_assert’
> > > 19 | static_assert(__same_type(*(ptr), ((type *)0)->member) 
> > > ||   \
> > >| ^
> > > ./include/linux/container_of.h:19:23: note: in expansion of macro 
> > > ‘__same_type’
> > > 19 | static_assert(__same_type(*(ptr), ((type *)0)->member) 
> > > ||   \
> > >|   ^~~
> > > ./include/linux/list.h:520:9: note: in expansion of macro ‘container_of’
> > >520 | container_of(ptr, type, member)
> > >| ^~~~
> > > ./include/linux/list.h:542:9: note: in expansion of macro ‘list_entry’
> > >542 | list_entry((ptr)->prev, type, member)
> > >| ^~
> > > drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c:473:33: note: in expansion 
> > > of macro ‘list_last_entry’
> > >473 | block = list_last_entry(>blocks, 
> > > typeof(*block), link);
> > >| ^~~
> > > ././include/linux/compiler_types.h:295:27: error: expression in static 
> 

[PATCH] drm/amdgpu: Clarify asics naming in Kconfig options

2022-07-14 Thread André Almeida
Clarify which architecture those asics acronyms refers to.

Signed-off-by: André Almeida 
---
 drivers/gpu/drm/amd/amdgpu/Kconfig | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/Kconfig 
b/drivers/gpu/drm/amd/amdgpu/Kconfig
index 74a8105fd2c0..d55275de 100644
--- a/drivers/gpu/drm/amd/amdgpu/Kconfig
+++ b/drivers/gpu/drm/amd/amdgpu/Kconfig
@@ -4,7 +4,7 @@ config DRM_AMDGPU_SI
depends on DRM_AMDGPU
help
  Choose this option if you want to enable experimental support
- for SI asics.
+ for SI (Southern Islands) asics.
 
  SI is already supported in radeon. Experimental support for SI
  in amdgpu will be disabled by default and is still provided by
@@ -16,7 +16,8 @@ config DRM_AMDGPU_CIK
bool "Enable amdgpu support for CIK parts"
depends on DRM_AMDGPU
help
- Choose this option if you want to enable support for CIK asics.
+ Choose this option if you want to enable support for CIK (Sea
+ Islands) asics.
 
  CIK is already supported in radeon. Support for CIK in amdgpu
  will be disabled by default and is still provided by radeon.
-- 
2.37.0



Re: [PATCH] Revert "drm/amdgpu: add drm buddy support to amdgpu"

2022-07-14 Thread Alex Deucher
On Thu, Jul 14, 2022 at 9:09 AM Christian König
 wrote:
>
> Hi Mauro,
>
> well the last time I checked drm-tip was clean.
>
> The revert is necessary because we had some problems with the commit
> which we couldn't fix in the 5.19 cycle.

Would it be worth reverting the revert and applying the actual fix[1]?
 It's a huge revert unfortunately while the actual fix is like 10
lines of code.  I'm concerned there will be subtle fallout from the
revert due to how extensive it is.

[1] - 
https://gitlab.freedesktop.org/drm/amd/uploads/564b2cc2b5ea87357f39e45c3a1a44e2/0001-drm-amdgpu-Fix-for-drm-buddy-memory-corruption.patch

Alex


>
> I will double check drm-tip once more.
>
> Regards,
> Christian.
>
> Am 14.07.22 um 14:54 schrieb Mauro Carvalho Chehab:
> > On Fri, 8 Jul 2022 03:21:24 -0700
> > Arunpravin Paneer Selvam  wrote:
> >
> >> This reverts the following commits:
> >> commit 708d19d9f362 ("drm/amdgpu: move internal vram_mgr function into the 
> >> C file")
> >> commit 5e3f1e7729ec ("drm/amdgpu: fix start calculation in 
> >> amdgpu_vram_mgr_new")
> >> commit c9cad937c0c5 ("drm/amdgpu: add drm buddy support to amdgpu")
> >>
> >> [WHY]
> >> Few users reported garbaged graphics as soon as x starts,
> >> reverting until this can be resolved.
> >>
> >> Signed-off-by: Arunpravin Paneer Selvam 
> > This revert is currently breaking drm-tip. Please revert it ASAP, as it
> > is preventing CI bots to properly test new patches on the top of current
> > drm-tip:
> >
> > drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c: In function 
> > ‘amdgpu_vram_mgr_new’:
> > drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c:459:13: error: ‘cur_size’ 
> > undeclared (first use in this function)
> >459 | if (cur_size != size) {
> >| ^~~~
> > drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c:459:13: note: each undeclared 
> > identifier is reported only once for each function it appears in
> > drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c:459:25: error: ‘size’ 
> > undeclared (first use in this function); did you mean ‘ksize’?
> >459 | if (cur_size != size) {
> >| ^~~~
> >| ksize
> > drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c:465:30: error: ‘vres’ 
> > undeclared (first use in this function); did you mean ‘res’?
> >465 | trim_list = >blocks;
> >|  ^~~~
> >|  res
> > In file included from ./include/linux/bits.h:22,
> >   from ./include/linux/ratelimit_types.h:5,
> >   from ./include/linux/ratelimit.h:5,
> >   from ./include/linux/dev_printk.h:16,
> >   from ./include/linux/device.h:15,
> >   from ./include/linux/dma-mapping.h:7,
> >   from drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c:25:
> > ./include/linux/container_of.h:19:54: error: invalid use of undefined type 
> > ‘struct drm_buddy_block’
> > 19 | static_assert(__same_type(*(ptr), ((type *)0)->member) ||  
> >  \
> >|  ^~
> > ./include/linux/build_bug.h:78:56: note: in definition of macro 
> > ‘__static_assert’
> > 78 | #define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
> >|^~~~
> > ./include/linux/container_of.h:19:9: note: in expansion of macro 
> > ‘static_assert’
> > 19 | static_assert(__same_type(*(ptr), ((type *)0)->member) ||  
> >  \
> >| ^
> > ./include/linux/container_of.h:19:23: note: in expansion of macro 
> > ‘__same_type’
> > 19 | static_assert(__same_type(*(ptr), ((type *)0)->member) ||  
> >  \
> >|   ^~~
> > ./include/linux/list.h:520:9: note: in expansion of macro ‘container_of’
> >520 | container_of(ptr, type, member)
> >| ^~~~
> > ./include/linux/list.h:542:9: note: in expansion of macro ‘list_entry’
> >542 | list_entry((ptr)->prev, type, member)
> >| ^~
> > drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c:473:33: note: in expansion of 
> > macro ‘list_last_entry’
> >473 | block = list_last_entry(>blocks, 
> > typeof(*block), link);
> >| ^~~
> > ././include/linux/compiler_types.h:295:27: error: expression in static 
> > assertion is not an integer
> >295 | #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), 
> > typeof(b))
> >|   ^~~~
> > ./include/linux/build_bug.h:78:56: note: in definition of macro 
> > ‘__static_assert’
> > 78 | #define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
> >|^~~~
> > 

Re: [PATCH] Revert "drm/amdgpu: add drm buddy support to amdgpu"

2022-07-14 Thread Christian König

Am 14.07.22 um 15:19 schrieb Mauro Carvalho Chehab:

On Thu, 14 Jul 2022 15:08:48 +0200
Christian König  wrote:


Hi Mauro,

well the last time I checked drm-tip was clean.

The revert is necessary because we had some problems with the commit
which we couldn't fix in the 5.19 cycle.

I see. I don't have any issues with the patch itself, provided that drm-tip
build doesn't break ;-)


I will double check drm-tip once more.

Did a new rebase on the top of:
bc04f10d22f7 (drm-tip/drm-tip) drm-tip: 2022y-07m-14d-12h-41m-36s UTC 
integration manifest


I have absolutely no idea what's going wrong here.

After just running "dim rebuild-tip" once more my drm-tip is at:

commit bc04f10d22f7d8a6d76abe431cfb6ef6ba67ad0c (drm-tip/drm-tip, drm-tip)
Author: Christian König 
Date:   Thu Jul 14 14:42:33 2022 +0200

    drm-tip: 2022y-07m-14d-12h-41m-36s UTC integration manifest

And that's compiling perfectly fine.

Regards,
Christian.



And it is still broken on amdgpu_vram_mgr.c, but now with different issues:

drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c: In function ‘amdgpu_vram_mgr_new’:
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c:465:13: error: ‘i’ undeclared 
(first use in this function)
   465 | if (i == 1)
   | ^
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c:465:13: note: each undeclared 
identifier is reported only once for each function it appears in
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c:466:17: error: ‘node’ undeclared 
(first use in this function)
   466 | node->base.placement |= TTM_PL_FLAG_CONTIGUOUS;
   | ^~~~
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c:365:33: error: unused variable 
‘block’ [-Werror=unused-variable]
   365 | struct drm_buddy_block *block;
   | ^
cc1: all warnings being treated as errors

Regards,
Mauro




Re: [PATCH 2/2] drm/amdgpu: re-apply "move internal vram_mgr function into the C file""

2022-07-14 Thread Arunpravin Paneer Selvam

Hi Christian,

I verified the patch.

Reviewed-by: Arunpravin Paneer Selvam 

Thanks,
Arun

On 7/14/2022 6:53 PM, Christian König wrote:

This re-applys commit 708d19d9f362766147cab79eccae60912c6d3068.

The original problem this was reverted for was found and the correct fix
will be merged to drm-misc-next-fixes.

Signed-off-by: Christian König
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 29 
  drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.h | 27 --
  2 files changed, 29 insertions(+), 27 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
index 51d9d3a4456c..7a5e8a7b4a1b 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
@@ -50,6 +50,35 @@ to_amdgpu_device(struct amdgpu_vram_mgr *mgr)
return container_of(mgr, struct amdgpu_device, mman.vram_mgr);
  }
  
+static inline struct drm_buddy_block *

+amdgpu_vram_mgr_first_block(struct list_head *list)
+{
+   return list_first_entry_or_null(list, struct drm_buddy_block, link);
+}
+
+static inline bool amdgpu_is_vram_mgr_blocks_contiguous(struct list_head *head)
+{
+   struct drm_buddy_block *block;
+   u64 start, size;
+
+   block = amdgpu_vram_mgr_first_block(head);
+   if (!block)
+   return false;
+
+   while (head != block->link.next) {
+   start = amdgpu_vram_mgr_block_start(block);
+   size = amdgpu_vram_mgr_block_size(block);
+
+   block = list_entry(block->link.next, struct drm_buddy_block, 
link);
+   if (start + size != amdgpu_vram_mgr_block_start(block))
+   return false;
+   }
+
+   return true;
+}
+
+
+
  /**
   * DOC: mem_info_vram_total
   *
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.h
index 9a2db87186c7..4b267bf1c5db 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.h
@@ -53,33 +53,6 @@ static inline u64 amdgpu_vram_mgr_block_size(struct 
drm_buddy_block *block)
return PAGE_SIZE << drm_buddy_block_order(block);
  }
  
-static inline struct drm_buddy_block *

-amdgpu_vram_mgr_first_block(struct list_head *list)
-{
-   return list_first_entry_or_null(list, struct drm_buddy_block, link);
-}
-
-static inline bool amdgpu_is_vram_mgr_blocks_contiguous(struct list_head *head)
-{
-   struct drm_buddy_block *block;
-   u64 start, size;
-
-   block = amdgpu_vram_mgr_first_block(head);
-   if (!block)
-   return false;
-
-   while (head != block->link.next) {
-   start = amdgpu_vram_mgr_block_start(block);
-   size = amdgpu_vram_mgr_block_size(block);
-
-   block = list_entry(block->link.next, struct drm_buddy_block, 
link);
-   if (start + size != amdgpu_vram_mgr_block_start(block))
-   return false;
-   }
-
-   return true;
-}
-
  static inline struct amdgpu_vram_mgr_resource *
  to_amdgpu_vram_mgr_resource(struct ttm_resource *res)
  {


Re: [PATCH 1/2] drm/amdgpu: reapply "fix start calculation in amdgpu_vram_mgr_new""

2022-07-14 Thread Arunpravin Paneer Selvam

Hi Christian,

I verified the patch.

Reviewed-by: Arunpravin Paneer Selvam 

Regards,
Arun

On 7/14/2022 6:53 PM, Christian König wrote:

This re-applys commit 5e3f1e7729ec7a99e145e9d8ed58963d86cdfb98.

The original problem this was reverted for was found and the correct fix
will be merged to drm-misc-next-fixes.

Signed-off-by: Christian König
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 22 +---
  1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
index 49e4092f447f..51d9d3a4456c 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
@@ -496,16 +496,22 @@ static int amdgpu_vram_mgr_new(struct 
ttm_resource_manager *man,
list_splice_tail(trim_list, >blocks);
}
  
-	list_for_each_entry(block, >blocks, link)

-   vis_usage += amdgpu_vram_mgr_vis_size(adev, block);
+   vres->base.start = 0;
+   list_for_each_entry(block, >blocks, link) {
+   unsigned long start;
  
-	block = amdgpu_vram_mgr_first_block(>blocks);

-   if (!block) {
-   r = -EINVAL;
-   goto error_fini;
-   }
+   start = amdgpu_vram_mgr_block_start(block) +
+   amdgpu_vram_mgr_block_size(block);
+   start >>= PAGE_SHIFT;
  
-	vres->base.start = amdgpu_vram_mgr_block_start(block) >> PAGE_SHIFT;

+   if (start > vres->base.num_pages)
+   start -= vres->base.num_pages;
+   else
+   start = 0;
+   vres->base.start = max(vres->base.start, start);
+
+   vis_usage += amdgpu_vram_mgr_vis_size(adev, block);
+   }
  
  	if (amdgpu_is_vram_mgr_blocks_contiguous(>blocks))

vres->base.placement |= TTM_PL_FLAG_CONTIGUOUS;


Re: Linux 5.19-rc6

2022-07-14 Thread Guenter Roeck

On 7/14/22 00:23, Geert Uytterhoeven wrote:

Hi Linus,

On Wed, Jul 13, 2022 at 11:51 PM Linus Torvalds
 wrote:

On Wed, Jul 13, 2022 at 2:01 PM Alex Deucher  wrote:

If you want to apply Guenter's patch original patch:
https://patchwork.freedesktop.org/patch/490184/
That's fine with me.


Honestly, by this time I feel that it's too little, too late.


[...]


So considering that the ppc people ignored this whole issue since the
merge window, I think it's entirely unreasonable to then apply a
ppc-specific patch for this at this time, when people literally asked
"why is this needed", and there was no reply from the powerpc side.


Oh, it's not just this one. The lists of build regressions between v5.18
and v5.19-rc1 [1] resp. v5.19-rc6 [2] look surprisingly similar :-(

[1] https://lore.kernel.org/all/20220606082201.2792145-1-ge...@linux-m68k.org
[2] https://lore.kernel.org/all/20220711064425.3084093-1-ge...@linux-m68k.org



How do you build your images ? I don't see many of the problems you report,
even if I build the files with W=1. It is odd, since reports such as

drivers/mfd/asic3.c:941:23: error: unused variable 'asic'

are real, but I just don't see that. If I build that file, I see that
it builds with -Wno-unused-but-set-variable, due to

Makefile:KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable)

The override in scripts/Makefile.extrawarn doesn't seem to work even though
it adds "-Wunused-but-set-variable" to the compile flags. And if I remove
"-Wno-unused-but-set-variable" from Makefile I still don't get the 
error/warning.
Confused. I must be missing something, but what ?

Thanks,
Guenter


[PATCH 2/2] drm/amdgpu: re-apply "move internal vram_mgr function into the C file""

2022-07-14 Thread Christian König
This re-applys commit 708d19d9f362766147cab79eccae60912c6d3068.

The original problem this was reverted for was found and the correct fix
will be merged to drm-misc-next-fixes.

Signed-off-by: Christian König 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 29 
 drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.h | 27 --
 2 files changed, 29 insertions(+), 27 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
index 51d9d3a4456c..7a5e8a7b4a1b 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
@@ -50,6 +50,35 @@ to_amdgpu_device(struct amdgpu_vram_mgr *mgr)
return container_of(mgr, struct amdgpu_device, mman.vram_mgr);
 }
 
+static inline struct drm_buddy_block *
+amdgpu_vram_mgr_first_block(struct list_head *list)
+{
+   return list_first_entry_or_null(list, struct drm_buddy_block, link);
+}
+
+static inline bool amdgpu_is_vram_mgr_blocks_contiguous(struct list_head *head)
+{
+   struct drm_buddy_block *block;
+   u64 start, size;
+
+   block = amdgpu_vram_mgr_first_block(head);
+   if (!block)
+   return false;
+
+   while (head != block->link.next) {
+   start = amdgpu_vram_mgr_block_start(block);
+   size = amdgpu_vram_mgr_block_size(block);
+
+   block = list_entry(block->link.next, struct drm_buddy_block, 
link);
+   if (start + size != amdgpu_vram_mgr_block_start(block))
+   return false;
+   }
+
+   return true;
+}
+
+
+
 /**
  * DOC: mem_info_vram_total
  *
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.h
index 9a2db87186c7..4b267bf1c5db 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.h
@@ -53,33 +53,6 @@ static inline u64 amdgpu_vram_mgr_block_size(struct 
drm_buddy_block *block)
return PAGE_SIZE << drm_buddy_block_order(block);
 }
 
-static inline struct drm_buddy_block *
-amdgpu_vram_mgr_first_block(struct list_head *list)
-{
-   return list_first_entry_or_null(list, struct drm_buddy_block, link);
-}
-
-static inline bool amdgpu_is_vram_mgr_blocks_contiguous(struct list_head *head)
-{
-   struct drm_buddy_block *block;
-   u64 start, size;
-
-   block = amdgpu_vram_mgr_first_block(head);
-   if (!block)
-   return false;
-
-   while (head != block->link.next) {
-   start = amdgpu_vram_mgr_block_start(block);
-   size = amdgpu_vram_mgr_block_size(block);
-
-   block = list_entry(block->link.next, struct drm_buddy_block, 
link);
-   if (start + size != amdgpu_vram_mgr_block_start(block))
-   return false;
-   }
-
-   return true;
-}
-
 static inline struct amdgpu_vram_mgr_resource *
 to_amdgpu_vram_mgr_resource(struct ttm_resource *res)
 {
-- 
2.25.1



[PATCH 1/2] drm/amdgpu: reapply "fix start calculation in amdgpu_vram_mgr_new""

2022-07-14 Thread Christian König
This re-applys commit 5e3f1e7729ec7a99e145e9d8ed58963d86cdfb98.

The original problem this was reverted for was found and the correct fix
will be merged to drm-misc-next-fixes.

Signed-off-by: Christian König 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 22 +---
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
index 49e4092f447f..51d9d3a4456c 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
@@ -496,16 +496,22 @@ static int amdgpu_vram_mgr_new(struct 
ttm_resource_manager *man,
list_splice_tail(trim_list, >blocks);
}
 
-   list_for_each_entry(block, >blocks, link)
-   vis_usage += amdgpu_vram_mgr_vis_size(adev, block);
+   vres->base.start = 0;
+   list_for_each_entry(block, >blocks, link) {
+   unsigned long start;
 
-   block = amdgpu_vram_mgr_first_block(>blocks);
-   if (!block) {
-   r = -EINVAL;
-   goto error_fini;
-   }
+   start = amdgpu_vram_mgr_block_start(block) +
+   amdgpu_vram_mgr_block_size(block);
+   start >>= PAGE_SHIFT;
 
-   vres->base.start = amdgpu_vram_mgr_block_start(block) >> PAGE_SHIFT;
+   if (start > vres->base.num_pages)
+   start -= vres->base.num_pages;
+   else
+   start = 0;
+   vres->base.start = max(vres->base.start, start);
+
+   vis_usage += amdgpu_vram_mgr_vis_size(adev, block);
+   }
 
if (amdgpu_is_vram_mgr_blocks_contiguous(>blocks))
vres->base.placement |= TTM_PL_FLAG_CONTIGUOUS;
-- 
2.25.1



Re: [PATCH] Revert "drm/amdgpu: add drm buddy support to amdgpu"

2022-07-14 Thread Mauro Carvalho Chehab
On Thu, 14 Jul 2022 15:08:48 +0200
Christian König  wrote:

> Hi Mauro,
> 
> well the last time I checked drm-tip was clean.
> 
> The revert is necessary because we had some problems with the commit 
> which we couldn't fix in the 5.19 cycle.

I see. I don't have any issues with the patch itself, provided that drm-tip
build doesn't break ;-)

> I will double check drm-tip once more.

Did a new rebase on the top of:
bc04f10d22f7 (drm-tip/drm-tip) drm-tip: 2022y-07m-14d-12h-41m-36s UTC 
integration manifest

And it is still broken on amdgpu_vram_mgr.c, but now with different issues:

drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c: In function ‘amdgpu_vram_mgr_new’:
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c:465:13: error: ‘i’ undeclared 
(first use in this function)
  465 | if (i == 1)
  | ^
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c:465:13: note: each undeclared 
identifier is reported only once for each function it appears in
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c:466:17: error: ‘node’ undeclared 
(first use in this function)
  466 | node->base.placement |= TTM_PL_FLAG_CONTIGUOUS;
  | ^~~~
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c:365:33: error: unused variable 
‘block’ [-Werror=unused-variable]
  365 | struct drm_buddy_block *block;
  | ^
cc1: all warnings being treated as errors

Regards,
Mauro


Re: [PATCH] Revert "drm/amdgpu: add drm buddy support to amdgpu"

2022-07-14 Thread Christian König

Hi Mauro,

well the last time I checked drm-tip was clean.

The revert is necessary because we had some problems with the commit 
which we couldn't fix in the 5.19 cycle.


I will double check drm-tip once more.

Regards,
Christian.

Am 14.07.22 um 14:54 schrieb Mauro Carvalho Chehab:

On Fri, 8 Jul 2022 03:21:24 -0700
Arunpravin Paneer Selvam  wrote:


This reverts the following commits:
commit 708d19d9f362 ("drm/amdgpu: move internal vram_mgr function into the C 
file")
commit 5e3f1e7729ec ("drm/amdgpu: fix start calculation in amdgpu_vram_mgr_new")
commit c9cad937c0c5 ("drm/amdgpu: add drm buddy support to amdgpu")

[WHY]
Few users reported garbaged graphics as soon as x starts,
reverting until this can be resolved.

Signed-off-by: Arunpravin Paneer Selvam 

This revert is currently breaking drm-tip. Please revert it ASAP, as it
is preventing CI bots to properly test new patches on the top of current
drm-tip:

drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c: In function ‘amdgpu_vram_mgr_new’:
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c:459:13: error: ‘cur_size’ 
undeclared (first use in this function)
   459 | if (cur_size != size) {
   | ^~~~
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c:459:13: note: each undeclared 
identifier is reported only once for each function it appears in
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c:459:25: error: ‘size’ undeclared 
(first use in this function); did you mean ‘ksize’?
   459 | if (cur_size != size) {
   | ^~~~
   | ksize
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c:465:30: error: ‘vres’ undeclared 
(first use in this function); did you mean ‘res’?
   465 | trim_list = >blocks;
   |  ^~~~
   |  res
In file included from ./include/linux/bits.h:22,
  from ./include/linux/ratelimit_types.h:5,
  from ./include/linux/ratelimit.h:5,
  from ./include/linux/dev_printk.h:16,
  from ./include/linux/device.h:15,
  from ./include/linux/dma-mapping.h:7,
  from drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c:25:
./include/linux/container_of.h:19:54: error: invalid use of undefined type 
‘struct drm_buddy_block’
19 | static_assert(__same_type(*(ptr), ((type *)0)->member) ||  
 \
   |  ^~
./include/linux/build_bug.h:78:56: note: in definition of macro 
‘__static_assert’
78 | #define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
   |^~~~
./include/linux/container_of.h:19:9: note: in expansion of macro ‘static_assert’
19 | static_assert(__same_type(*(ptr), ((type *)0)->member) ||  
 \
   | ^
./include/linux/container_of.h:19:23: note: in expansion of macro ‘__same_type’
19 | static_assert(__same_type(*(ptr), ((type *)0)->member) ||  
 \
   |   ^~~
./include/linux/list.h:520:9: note: in expansion of macro ‘container_of’
   520 | container_of(ptr, type, member)
   | ^~~~
./include/linux/list.h:542:9: note: in expansion of macro ‘list_entry’
   542 | list_entry((ptr)->prev, type, member)
   | ^~
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c:473:33: note: in expansion of 
macro ‘list_last_entry’
   473 | block = list_last_entry(>blocks, 
typeof(*block), link);
   | ^~~
././include/linux/compiler_types.h:295:27: error: expression in static 
assertion is not an integer
   295 | #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), 
typeof(b))
   |   ^~~~
./include/linux/build_bug.h:78:56: note: in definition of macro 
‘__static_assert’
78 | #define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
   |^~~~
./include/linux/container_of.h:19:9: note: in expansion of macro ‘static_assert’
19 | static_assert(__same_type(*(ptr), ((type *)0)->member) ||  
 \
   | ^
./include/linux/container_of.h:19:23: note: in expansion of macro ‘__same_type’
19 | static_assert(__same_type(*(ptr), ((type *)0)->member) ||  
 \
   |   ^~~
./include/linux/list.h:520:9: note: in expansion of macro ‘container_of’
   520 | container_of(ptr, type, member)
   | ^~~~
./include/linux/list.h:542:9: note: in expansion of macro ‘list_entry’
   542 | list_entry((ptr)->prev, type, member)
   | ^~
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c:473:33: note: in expansion of 
macro ‘list_last_entry’
   473 | 

Re: [PATCH] Revert "drm/amdgpu: add drm buddy support to amdgpu"

2022-07-14 Thread Mauro Carvalho Chehab
On Fri, 8 Jul 2022 03:21:24 -0700
Arunpravin Paneer Selvam  wrote:

> This reverts the following commits:
> commit 708d19d9f362 ("drm/amdgpu: move internal vram_mgr function into the C 
> file")
> commit 5e3f1e7729ec ("drm/amdgpu: fix start calculation in 
> amdgpu_vram_mgr_new")
> commit c9cad937c0c5 ("drm/amdgpu: add drm buddy support to amdgpu")
> 
> [WHY]
> Few users reported garbaged graphics as soon as x starts,
> reverting until this can be resolved.
> 
> Signed-off-by: Arunpravin Paneer Selvam 

This revert is currently breaking drm-tip. Please revert it ASAP, as it
is preventing CI bots to properly test new patches on the top of current
drm-tip:

drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c: In function ‘amdgpu_vram_mgr_new’:
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c:459:13: error: ‘cur_size’ 
undeclared (first use in this function)
  459 | if (cur_size != size) {
  | ^~~~
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c:459:13: note: each undeclared 
identifier is reported only once for each function it appears in
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c:459:25: error: ‘size’ undeclared 
(first use in this function); did you mean ‘ksize’?
  459 | if (cur_size != size) {
  | ^~~~
  | ksize
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c:465:30: error: ‘vres’ undeclared 
(first use in this function); did you mean ‘res’?
  465 | trim_list = >blocks;
  |  ^~~~
  |  res
In file included from ./include/linux/bits.h:22,
 from ./include/linux/ratelimit_types.h:5,
 from ./include/linux/ratelimit.h:5,
 from ./include/linux/dev_printk.h:16,
 from ./include/linux/device.h:15,
 from ./include/linux/dma-mapping.h:7,
 from drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c:25:
./include/linux/container_of.h:19:54: error: invalid use of undefined type 
‘struct drm_buddy_block’
   19 | static_assert(__same_type(*(ptr), ((type *)0)->member) ||   
\
  |  ^~
./include/linux/build_bug.h:78:56: note: in definition of macro 
‘__static_assert’
   78 | #define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
  |^~~~
./include/linux/container_of.h:19:9: note: in expansion of macro ‘static_assert’
   19 | static_assert(__same_type(*(ptr), ((type *)0)->member) ||   
\
  | ^
./include/linux/container_of.h:19:23: note: in expansion of macro ‘__same_type’
   19 | static_assert(__same_type(*(ptr), ((type *)0)->member) ||   
\
  |   ^~~
./include/linux/list.h:520:9: note: in expansion of macro ‘container_of’
  520 | container_of(ptr, type, member)
  | ^~~~
./include/linux/list.h:542:9: note: in expansion of macro ‘list_entry’
  542 | list_entry((ptr)->prev, type, member)
  | ^~
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c:473:33: note: in expansion of 
macro ‘list_last_entry’
  473 | block = list_last_entry(>blocks, 
typeof(*block), link);
  | ^~~
././include/linux/compiler_types.h:295:27: error: expression in static 
assertion is not an integer
  295 | #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), 
typeof(b))
  |   ^~~~
./include/linux/build_bug.h:78:56: note: in definition of macro 
‘__static_assert’
   78 | #define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
  |^~~~
./include/linux/container_of.h:19:9: note: in expansion of macro ‘static_assert’
   19 | static_assert(__same_type(*(ptr), ((type *)0)->member) ||   
\
  | ^
./include/linux/container_of.h:19:23: note: in expansion of macro ‘__same_type’
   19 | static_assert(__same_type(*(ptr), ((type *)0)->member) ||   
\
  |   ^~~
./include/linux/list.h:520:9: note: in expansion of macro ‘container_of’
  520 | container_of(ptr, type, member)
  | ^~~~
./include/linux/list.h:542:9: note: in expansion of macro ‘list_entry’
  542 | list_entry((ptr)->prev, type, member)
  | ^~
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c:473:33: note: in expansion of 
macro ‘list_last_entry’
  473 | block = list_last_entry(>blocks, 
typeof(*block), link);
  | ^~~
In file included from ./include/uapi/linux/posix_types.h:5,
 from ./include/uapi/linux/types.h:14,
 from ./include/linux/types.h:6,
 from 

Re: Linux 5.19-rc6

2022-07-14 Thread Russell King (Oracle)
On Wed, Jul 13, 2022 at 01:42:15PM -0700, Linus Torvalds wrote:
> On Wed, Jul 13, 2022 at 1:40 PM Guenter Roeck  wrote:
> >
> > That patch is (and has been) in linux-next for a long time,
> > as commit d2ca1fd2bc70, and with the following tags.
> >
> >  Fixes: 7719a68b2fa4 ("ARM: 9192/1: amba: fix memory leak in 
> > amba_device_try_add()")
> >  Reported-by: Guenter Roeck 
> >  Tested-by: Guenter Roeck 
> >  Signed-off-by: Kefeng Wang 
> >  Signed-off-by: Russell King (Oracle) 
> >
> > So, yes, it fixes the problem. I don't know where it is pulled from, though.
> > I thought that it is from Russell's tree, given his Signed-off-by:,
> > but I never really checked.
> 
> Heh. Yeah, with that sign-off, I bet it's in Russell's queue, bit it
> just ended up in the "for next release" branch. Russell?

Oh, I see, I never rebased my "misc" branch from the last cycle, so it
looks to me like 9192/1 was due for _this_ merge window - so I merged
the fix for it into that same branch, rather than the "fixes" branch.
I've moved it over to the correct branch now.

Looks like there's another fix that's in that very same state as well.

Expect a pull request shortly.

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!


Re: Linux 5.19-rc6

2022-07-14 Thread Russell King (Oracle)
On Wed, Jul 13, 2022 at 01:40:41PM -0700, Guenter Roeck wrote:
> On 7/13/22 13:21, Linus Torvalds wrote:
> > On Wed, Jul 13, 2022 at 12:49 PM Russell King (Oracle)
> >  wrote:
> > > 
> > > There may be a patch that solves that, but it's never been submitted to
> > > my patch system:
> > > 
> > > https://lore.kernel.org/all/20220524025139.40212-1-wangkefeng.w...@huawei.com/
> > 
> > That patch looks sane to me, but I guess Guenter would need to check
> > ... Guenter?
> > 
> 
> That patch is (and has been) in linux-next for a long time,
> as commit d2ca1fd2bc70, and with the following tags.
> 
> Fixes: 7719a68b2fa4 ("ARM: 9192/1: amba: fix memory leak in 
> amba_device_try_add()")
> Reported-by: Guenter Roeck 
> Tested-by: Guenter Roeck 
> Signed-off-by: Kefeng Wang 
> Signed-off-by: Russell King (Oracle) 
> 
> So, yes, it fixes the problem. I don't know where it is pulled from, though.
> I thought that it is from Russell's tree, given his Signed-off-by:,
> but I never really checked.

Ah, yes, it's in the same bracnh as 9192/1. So if Linus is reporting
that 9192/1 is still a problem in linux-next, then this patch does
_not_ fix it.

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!


Re: Linux 5.19-rc6

2022-07-14 Thread Geert Uytterhoeven
Hi Linus,

On Wed, Jul 13, 2022 at 11:51 PM Linus Torvalds
 wrote:
> On Wed, Jul 13, 2022 at 2:01 PM Alex Deucher  wrote:
> > If you want to apply Guenter's patch original patch:
> > https://patchwork.freedesktop.org/patch/490184/
> > That's fine with me.
>
> Honestly, by this time I feel that it's too little, too late.

[...]

> So considering that the ppc people ignored this whole issue since the
> merge window, I think it's entirely unreasonable to then apply a
> ppc-specific patch for this at this time, when people literally asked
> "why is this needed", and there was no reply from the powerpc side.

Oh, it's not just this one. The lists of build regressions between v5.18
and v5.19-rc1 [1] resp. v5.19-rc6 [2] look surprisingly similar :-(

[1] https://lore.kernel.org/all/20220606082201.2792145-1-ge...@linux-m68k.org
[2] https://lore.kernel.org/all/20220711064425.3084093-1-ge...@linux-m68k.org

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- ge...@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds


Re: [PATCH v8 06/15] mm: remove the vma check in migrate_vma_setup()

2022-07-14 Thread Alistair Popple


David Hildenbrand  writes:

> On 07.07.22 21:03, Alex Sierra wrote:
>> From: Alistair Popple 
>>
>> migrate_vma_setup() checks that a valid vma is passed so that the page
>> tables can be walked to find the pfns associated with a given address
>> range. However in some cases the pfns are already known, such as when
>> migrating device coherent pages during pin_user_pages() meaning a valid
>> vma isn't required.
>
> As raised in my other reply, without a VMA ... it feels odd to use a
> "migrate_vma" API. For an internal (mm/migrate_device.c) use case it is
> ok I guess, but it certainly adds a bit of confusion. For example,
> because migrate_vma_setup() will undo ref+lock not obtained by it.
>
> I guess the interesting point is that
>
> a) Besides migrate_vma_pages() and migrate_vma_setup(), the ->vma is unused.
>
> b) migrate_vma_setup() does collect+unmap+cleanup if unmap failed.
>
> c) With our source page in our hands, we cannot be processing a hole in
> a VMA.
>
>
>
> Not sure if it's better. but I would
>
> a) Enforce in migrate_vma_setup() that there is a VMA. Code outside of
> mm/migrate_device.c shouldn't be doing some hacks like this.
>
> b) Don't call migrate_vma_setup() from migrate_device_page(), but
> directly migrate_vma_unmap() and add a comment.
>
>
> That will leave a single change to this patch (migrate_vma_pages()). But
> is that even required? Because 
>
>> @@ -685,7 +685,7 @@ void migrate_vma_pages(struct migrate_vma *migrate)
>>  continue;
>>  }
>>
>> -if (!page) {
>> +if (!page && migrate->vma) {
>
> How could we ever have !page in case of migrate_device_page()?

Oh good point. This patch was originally part of a larger series I was
working on at the time but you're right - for migrate_device_page() we
should never hit this case. I will respin the next patch (number 7 in
this series) to include this.

> Instead, I think a VM_BUG_ON(migrate->vma); should hold and you can just
> simplify.
>
>>  if (!(migrate->src[i] & MIGRATE_PFN_MIGRATE))
>>  continue;
>>  if (!notified) {


Re: [PATCH v8 07/15] mm/gup: migrate device coherent pages when pinning instead of failing

2022-07-14 Thread Alistair Popple


David Hildenbrand  writes:

> On 07.07.22 21:03, Alex Sierra wrote:
>> From: Alistair Popple 
>>
>> Currently any attempts to pin a device coherent page will fail. This is
>> because device coherent pages need to be managed by a device driver, and
>> pinning them would prevent a driver from migrating them off the device.
>>
>> However this is no reason to fail pinning of these pages. These are
>> coherent and accessible from the CPU so can be migrated just like
>> pinning ZONE_MOVABLE pages. So instead of failing all attempts to pin
>> them first try migrating them out of ZONE_DEVICE.
>>
>> Signed-off-by: Alistair Popple 
>> Acked-by: Felix Kuehling 
>> [hch: rebased to the split device memory checks,
>>   moved migrate_device_page to migrate_device.c]
>> Signed-off-by: Christoph Hellwig 
>> ---
>>  mm/gup.c| 47 +++-
>>  mm/internal.h   |  1 +
>>  mm/migrate_device.c | 53 +
>>  3 files changed, 96 insertions(+), 5 deletions(-)
>>
>> diff --git a/mm/gup.c b/mm/gup.c
>> index b65fe8bf5af4..9b6b9923d22d 100644
>> --- a/mm/gup.c
>> +++ b/mm/gup.c
>> @@ -1891,9 +1891,43 @@ static long check_and_migrate_movable_pages(unsigned 
>> long nr_pages,
>>  continue;
>>  prev_folio = folio;
>>
>> -if (folio_is_longterm_pinnable(folio))
>> +/*
>> + * Device private pages will get faulted in during gup so it
>> + * shouldn't be possible to see one here.
>> + */
>> +if (WARN_ON_ONCE(folio_is_device_private(folio))) {
>> +ret = -EFAULT;
>> +goto unpin_pages;
>> +}
>
> I'd just drop that. Device private pages are never part of a present PTE. So 
> if we
> could actually get a grab of one via GUP we would be in bigger trouble ...
> already before this patch.

Fair.

>> +
>> +/*
>> + * Device coherent pages are managed by a driver and should not
>> + * be pinned indefinitely as it prevents the driver moving the
>> + * page. So when trying to pin with FOLL_LONGTERM instead try
>> + * to migrate the page out of device memory.
>> + */
>> +if (folio_is_device_coherent(folio)) {
>> +WARN_ON_ONCE(PageCompound(>page));
>
> Maybe that belongs into migrate_device_page()?

Ok (noting Matthew's comment there as well).

>> +
>> +/*
>> + * Migration will fail if the page is pinned, so convert
>
> [...]
>
>>  /*
>>   * mm/gup.c
>> diff --git a/mm/migrate_device.c b/mm/migrate_device.c
>> index cf9668376c5a..5decd26dd551 100644
>> --- a/mm/migrate_device.c
>> +++ b/mm/migrate_device.c
>> @@ -794,3 +794,56 @@ void migrate_vma_finalize(struct migrate_vma *migrate)
>>  }
>>  }
>>  EXPORT_SYMBOL(migrate_vma_finalize);
>> +
>> +/*
>> + * Migrate a device coherent page back to normal memory.  The caller should 
>> have
>> + * a reference on page which will be copied to the new page if migration is
>> + * successful or dropped on failure.
>> + */
>> +struct page *migrate_device_page(struct page *page, unsigned int gup_flags)
>
> Function name should most probably indicate that we're dealing with coherent 
> pages here?

Ok.

>> +{
>> +unsigned long src_pfn, dst_pfn = 0;
>> +struct migrate_vma args;
>> +struct page *dpage;
>> +
>> +lock_page(page);
>> +src_pfn = migrate_pfn(page_to_pfn(page)) | MIGRATE_PFN_MIGRATE;
>> +args.src = _pfn;
>> +args.dst = _pfn;
>> +args.cpages = 1;
>> +args.npages = 1;
>> +args.vma = NULL;
>> +migrate_vma_setup();
>> +if (!(src_pfn & MIGRATE_PFN_MIGRATE))
>> +return NULL;
>
> Wow, these refcount and page locking/unlocking rules with this migrate_* api 
> are
> confusing now. And the usage here of sometimes returning and sometimes falling
> trough don't make it particularly easier to understand here.
>
> I'm not 100% happy about reusing migrate_vma_setup() usage if there *is no 
> VMA*.
> That's just absolutely confusing, because usually migrate_vma_setup() itself
> would do the collection step and ref+lock pages. :/
>
> In general, I can see why/how we're reusing the migrate_vma_* API here, but 
> there
> is absolutely no VMA ... not sure what to improve besides providing a second 
> API
> that does a simple single-page migration. But that can be changed later ...

Yeah, as noted in your other response I think it should be ok to just
call migrate_vma_unmap() directly from migrate_device_page() so I assume
that would adequately deal with this.

>> +
>> +dpage = alloc_pages(GFP_USER | __GFP_NOWARN, 0);
>> +
>
> alloc_page()
>
>> +/*
>> + * get/pin the new page now so we don't have to retry gup after
>> + * migrating. We already have a reference so this should never fail.
>> + */
>> +if (dpage && WARN_ON_ONCE(!try_grab_page(dpage, gup_flags))) 

[PATCH][next] drm/amd/display: Fix spelling mistake "supporing" -> "supporting"

2022-07-14 Thread Colin Ian King
There is a spelling mistake in a dml_print message. Fix it.

Signed-off-by: Colin Ian King 
---
 .../gpu/drm/amd/display/dc/dml/dcn314/display_mode_vba_314.c| 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/display/dc/dml/dcn314/display_mode_vba_314.c 
b/drivers/gpu/drm/amd/display/dc/dml/dcn314/display_mode_vba_314.c
index 6101c962ab0a..fc4d7474c111 100644
--- a/drivers/gpu/drm/amd/display/dc/dml/dcn314/display_mode_vba_314.c
+++ b/drivers/gpu/drm/amd/display/dc/dml/dcn314/display_mode_vba_314.c
@@ -2994,7 +2994,7 @@ static void 
DISPCLKDPPCLKDCFCLKDeepSleepPrefetchParametersWatermarksAndPerforman
for (k = 0; k < v->NumberOfActivePlanes; ++k) {
if (v->ImmediateFlipSupportedForPipe[k] == 
false) {
 #ifdef __DML_VBA_DEBUG__
-   dml_print("DML::%s: Pipe %0d not 
supporing iflip\n", __func__, k);
+   dml_print("DML::%s: Pipe %0d not 
supporting iflip\n", __func__, k);
 #endif
v->ImmediateFlipSupported = false;
}
-- 
2.35.3



[bug report] drm/amdgpu/mes: ring aggregatged doorbell when mes queue is unmapped

2022-07-14 Thread Dan Carpenter
Hello Le Ma,

The patch 5fdbff096edb: "drm/amdgpu/mes: ring aggregatged doorbell
when mes queue is unmapped" from Oct 30, 2020, leads to the following
unpublished Smatch static checker warning:

drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c:8552 
gfx_v10_0_ring_set_wptr_gfx()
warn: duplicate check '*is_queue_unmap' (previous on line 8546)

drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c
8525 static void gfx_v10_0_ring_set_wptr_gfx(struct amdgpu_ring *ring)
8526 {
8527 struct amdgpu_device *adev = ring->adev;
8528 uint32_t *wptr_saved;
8529 uint32_t *is_queue_unmap;
8530 uint64_t aggregated_db_index;
8531 uint32_t mqd_size = adev->mqds[AMDGPU_HW_IP_GFX].mqd_size;
8532 uint64_t wptr_tmp;
8533 
8534 if (ring->is_mes_queue) {
8535 wptr_saved = (uint32_t *)(ring->mqd_ptr + mqd_size);
8536 is_queue_unmap = (uint32_t *)(ring->mqd_ptr + mqd_size 
+
8537   sizeof(uint32_t));
8538 aggregated_db_index =
8539 amdgpu_mes_get_aggregated_doorbell_index(adev,
8540 AMDGPU_MES_PRIORITY_LEVEL_NORMAL);
8541 
8542 wptr_tmp = ring->wptr & ring->buf_mask;
8543 atomic64_set((atomic64_t *)ring->wptr_cpu_addr, 
wptr_tmp);
8544 *wptr_saved = wptr_tmp;
8545 /* assume doorbell always being used by mes mapped 
queue */
8546 if (*is_queue_unmap) {
 ^^^

Checked

8547 WDOORBELL64(aggregated_db_index, wptr_tmp);
8548 WDOORBELL64(ring->doorbell_index, wptr_tmp);
8549 } else {
8550 WDOORBELL64(ring->doorbell_index, wptr_tmp);
8551 
--> 8552 if (*is_queue_unmap)
 ^^^

It's possible this is changed inside a function, but it looks suspicious.

8553 WDOORBELL64(aggregated_db_index, 
wptr_tmp);
8554 }
8555 } else {
8556 if (ring->use_doorbell) {
8557 /* XXX check if swapping is necessary on BE */
8558 atomic64_set((atomic64_t *)ring->wptr_cpu_addr,
8559  ring->wptr);
8560 WDOORBELL64(ring->doorbell_index, ring->wptr);
8561 } else {
8562 WREG32_SOC15(GC, 0, mmCP_RB0_WPTR,
8563  lower_32_bits(ring->wptr));
8564 WREG32_SOC15(GC, 0, mmCP_RB0_WPTR_HI,
8565  upper_32_bits(ring->wptr));
8566 }
8567 }
8568 }

regards,
dan carpenter


Re: [PATCH 4/4] drm/amdgpu: drop runpm from amdgpu_device structure

2022-07-14 Thread Lazar, Lijo




On 7/14/2022 2:13 PM, Guchun Chen wrote:

It's redundant, as now switching to rpm_mode to indicate
runtime power management mode.

Suggested-by: Lijo Lazar 
Signed-off-by: Guchun Chen 


Series is:
Reviewed-by: Lijo Lazar 

Thanks,
Lijo


---
  drivers/gpu/drm/amd/amdgpu/amdgpu.h |  1 -
  drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 10 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 23 ++-
  3 files changed, 15 insertions(+), 19 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index 15f290c9523d..9f729a648005 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -1011,7 +1011,6 @@ struct amdgpu_device {
uint64_tdf_perfmon_config_assign_mask[AMDGPU_MAX_DF_PERFMONS];
  
  	/* enable runtime pm on the device */

-   boolrunpm;
boolin_runpm;
boolhas_pr3;
  
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c

index 1cc9260e75de..70a7203a2916 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
@@ -2118,7 +2118,7 @@ static int amdgpu_pci_probe(struct pci_dev *pdev,
if (ret)
DRM_ERROR("Creating debugfs files failed (%d).\n", ret);
  
-	if (adev->runpm) {

+   if (adev->pm.rpm_mode != AMDGPU_RUNPM_NONE) {
/* only need to skip on ATPX */
if (amdgpu_device_supports_px(ddev))
dev_pm_set_driver_flags(ddev->dev, 
DPM_FLAG_NO_DIRECT_COMPLETE);
@@ -2175,7 +2175,7 @@ amdgpu_pci_remove(struct pci_dev *pdev)
  
  	drm_dev_unplug(dev);
  
-	if (adev->runpm) {

+   if (adev->pm.rpm_mode != AMDGPU_RUNPM_NONE) {
pm_runtime_get_sync(dev->dev);
pm_runtime_forbid(dev->dev);
}
@@ -2458,7 +2458,7 @@ static int amdgpu_pmops_runtime_suspend(struct device 
*dev)
struct amdgpu_device *adev = drm_to_adev(drm_dev);
int ret, i;
  
-	if (!adev->runpm) {

+   if (adev->pm.rpm_mode == AMDGPU_RUNPM_NONE) {
pm_runtime_forbid(dev);
return -EBUSY;
}
@@ -2527,7 +2527,7 @@ static int amdgpu_pmops_runtime_resume(struct device *dev)
struct amdgpu_device *adev = drm_to_adev(drm_dev);
int ret;
  
-	if (!adev->runpm)

+   if (adev->pm.rpm_mode == AMDGPU_RUNPM_NONE)
return -EINVAL;
  
  	/* Avoids registers access if device is physically gone */

@@ -2571,7 +2571,7 @@ static int amdgpu_pmops_runtime_idle(struct device *dev)
/* we don't want the main rpm_idle to call suspend - we want to 
autosuspend */
int ret = 1;
  
-	if (!adev->runpm) {

+   if (adev->pm.rpm_mode == AMDGPU_RUNPM_NONE) {
pm_runtime_forbid(dev);
return -EBUSY;
}
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
index 9182e81e3135..a3744c0b632b 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
@@ -147,14 +147,13 @@ int amdgpu_driver_load_kms(struct amdgpu_device *adev, 
unsigned long flags)
goto out;
}
  
+	adev->pm.rpm_mode = AMDGPU_RUNPM_NONE;

if (amdgpu_device_supports_px(dev) &&
-   (amdgpu_runtime_pm != 0)) { /* enable runpm by default for atpx */
-   adev->runpm = true;
+   (amdgpu_runtime_pm != 0)) { /* enable PX as runtime mode */
adev->pm.rpm_mode = AMDGPU_RUNPM_PX;
dev_info(adev->dev, "Using ATPX for runtime pm\n");
} else if (amdgpu_device_supports_boco(dev) &&
-  (amdgpu_runtime_pm != 0)) { /* enable runpm by default for 
boco */
-   adev->runpm = true;
+  (amdgpu_runtime_pm != 0)) { /* enable boco as runtime mode */
adev->pm.rpm_mode = AMDGPU_RUNPM_BOCO;
dev_info(adev->dev, "Using BOCO for runtime pm\n");
} else if (amdgpu_device_supports_baco(dev) &&
@@ -162,25 +161,23 @@ int amdgpu_driver_load_kms(struct amdgpu_device *adev, 
unsigned long flags)
switch (adev->asic_type) {
case CHIP_VEGA20:
case CHIP_ARCTURUS:
-   /* enable runpm if runpm=1 */
+   /* enable BACO as runpm mode if runpm=1 */
if (amdgpu_runtime_pm > 0)
-   adev->runpm = true;
+   adev->pm.rpm_mode = AMDGPU_RUNPM_BACO;
break;
case CHIP_VEGA10:
-   /* turn runpm on if noretry=0 */
+   /* enable BACO as runpm mode if noretry=0 */
if (!adev->gmc.noretry)
-   adev->runpm = true;
+   adev->pm.rpm_mode = 

[PATCH 09/10] drm/amdgpu: add gang submit backend

2022-07-14 Thread Christian König
Allows submitting jobs as gang which needs to run on multiple
engines at the same time.

Basic idea is that we have a global gang submit fence representing when the
gang leader is finally pushed to run on the hardware last.

Jobs submitted as gang are never re-submitted in case of a GPU reset since this
won't work and will just deadlock the hardware immediately again.

Signed-off-by: Christian König 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h|  3 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 34 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_job.c| 28 --
 drivers/gpu/drm/amd/amdgpu/amdgpu_job.h|  3 ++
 4 files changed, 66 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index 2871a3e3801f..19308db52984 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -881,6 +881,7 @@ struct amdgpu_device {
u64 fence_context;
unsignednum_rings;
struct amdgpu_ring  *rings[AMDGPU_MAX_RINGS];
+   struct dma_fence __rcu  *gang_submit;
boolib_pool_ready;
struct amdgpu_sa_managerib_pools[AMDGPU_IB_POOL_MAX];
struct amdgpu_sched 
gpu_sched[AMDGPU_HW_IP_NUM][AMDGPU_RING_PRIO_MAX];
@@ -1288,6 +1289,8 @@ u32 amdgpu_device_pcie_port_rreg(struct amdgpu_device 
*adev,
u32 reg);
 void amdgpu_device_pcie_port_wreg(struct amdgpu_device *adev,
u32 reg, u32 v);
+struct dma_fence *amdgpu_device_switch_gang(struct amdgpu_device *adev,
+   struct dma_fence *gang);
 
 /* atpx handler */
 #if defined(CONFIG_VGA_SWITCHEROO)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index e1c9587f659b..f80beb7208c0 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -3499,6 +3499,7 @@ int amdgpu_device_init(struct amdgpu_device *adev,
adev->gmc.gart_size = 512 * 1024 * 1024;
adev->accel_working = false;
adev->num_rings = 0;
+   RCU_INIT_POINTER(adev->gang_submit, dma_fence_get_stub());
adev->mman.buffer_funcs = NULL;
adev->mman.buffer_funcs_ring = NULL;
adev->vm_manager.vm_pte_funcs = NULL;
@@ -3979,6 +3980,7 @@ void amdgpu_device_fini_sw(struct amdgpu_device *adev)
release_firmware(adev->firmware.gpu_info_fw);
adev->firmware.gpu_info_fw = NULL;
adev->accel_working = false;
+   dma_fence_put(rcu_dereference_protected(adev->gang_submit, true));
 
amdgpu_reset_fini(adev);
 
@@ -5905,3 +5907,35 @@ void amdgpu_device_pcie_port_wreg(struct amdgpu_device 
*adev,
(void)RREG32(data);
spin_unlock_irqrestore(>pcie_idx_lock, flags);
 }
+
+/**
+ * amdgpu_device_switch_gang - switch to a new gang
+ * @adev: amdgpu_device pointer
+ * @gang: the gang to switch to
+ *
+ * Try to switch to a new gang or return a reference to the current gang if 
that
+ * isn't possible.
+ * Returns: Either NULL if we switched correctly or a reference to the existing
+ * gang.
+ */
+struct dma_fence *amdgpu_device_switch_gang(struct amdgpu_device *adev,
+   struct dma_fence *gang)
+{
+   struct dma_fence *old = NULL;
+
+   do {
+   dma_fence_put(old);
+   old = dma_fence_get_rcu_safe(>gang_submit);
+
+   if (old == gang)
+   break;
+
+   if (!dma_fence_is_signaled(old))
+   return old;
+
+   } while (cmpxchg((struct dma_fence __force **)>gang_submit,
+old, gang) != old);
+
+   dma_fence_put(old);
+   return NULL;
+}
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
index 3255b2fca611..f3a1fdbd41a3 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
@@ -180,11 +180,29 @@ static void amdgpu_job_free_cb(struct drm_sched_job 
*s_job)
kfree(job);
 }
 
+void amdgpu_job_set_gang_leader(struct amdgpu_job *job,
+   struct amdgpu_job *leader)
+{
+   struct dma_fence *fence = >base.s_fence->scheduled;
+
+   WARN_ON(job->gang_submit);
+
+   /*
+* Don't add a reference when we are the gang leader to avoid circle
+* dependency.
+*/
+   if (job != leader)
+   dma_fence_get(fence);
+   job->gang_submit = fence;
+}
+
 void amdgpu_job_free(struct amdgpu_job *job)
 {
amdgpu_job_free_resources(job);
amdgpu_sync_free(>sync);
amdgpu_sync_free(>sched_sync);
+   if (job->gang_submit != >base.s_fence->scheduled)
+   dma_fence_put(job->gang_submit);
 
/* only put the hw fence 

[PATCH 10/10] drm/amdgpu: add gang submit frontend v2

2022-07-14 Thread Christian König
Allows submitting jobs as gang which needs to run on multiple engines at the
same time.

All members of the gang get the same implicit, explicit and VM dependencies. So
no gang member will start running until everything else is ready.

The last job is considered the gang leader (usually a submission to the GFX
ring) and used for signaling output dependencies.

Each job is remembered individually as user of a buffer object, so there is no
joining of work at the end.

v2: rebase and fix review comments from Andrey and Yogesh

Signed-off-by: Christian König 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c| 256 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.h|  10 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h |  12 +-
 3 files changed, 183 insertions(+), 95 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
index 88f491dc7ca2..e1c41db20efb 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
@@ -69,6 +69,7 @@ static int amdgpu_cs_p1_ib(struct amdgpu_cs_parser *p,
   unsigned int *num_ibs)
 {
struct drm_sched_entity *entity;
+   unsigned int i;
int r;
 
r = amdgpu_ctx_get_entity(p->ctx, chunk_ib->ip_type,
@@ -77,17 +78,28 @@ static int amdgpu_cs_p1_ib(struct amdgpu_cs_parser *p,
if (r)
return r;
 
-   /* Abort if there is no run queue associated with this entity.
-* Possibly because of disabled HW IP*/
+   /*
+* Abort if there is no run queue associated with this entity.
+* Possibly because of disabled HW IP.
+*/
if (entity->rq == NULL)
return -EINVAL;
 
-   /* Currently we don't support submitting to multiple entities */
-   if (p->entity && p->entity != entity)
+   /* Check if we can add this IB to some existing job */
+   for (i = 0; i < p->gang_size; ++i) {
+   if (p->entities[i] == entity)
+   goto found;
+   }
+
+   /* If not increase the gang size if possible */
+   if (i == AMDGPU_CS_GANG_SIZE)
return -EINVAL;
 
-   p->entity = entity;
-   ++(*num_ibs);
+   p->entities[i] = entity;
+   p->gang_size = i + 1;
+
+found:
+   ++(num_ibs[i]);
return 0;
 }
 
@@ -161,11 +173,12 @@ static int amdgpu_cs_pass1(struct amdgpu_cs_parser *p,
   union drm_amdgpu_cs *cs)
 {
struct amdgpu_fpriv *fpriv = p->filp->driver_priv;
+   unsigned int num_ibs[AMDGPU_CS_GANG_SIZE] = { };
struct amdgpu_vm *vm = >vm;
uint64_t *chunk_array_user;
uint64_t *chunk_array;
-   unsigned size, num_ibs = 0;
uint32_t uf_offset = 0;
+   unsigned int size;
int ret;
int i;
 
@@ -231,7 +244,7 @@ static int amdgpu_cs_pass1(struct amdgpu_cs_parser *p,
if (size < sizeof(struct drm_amdgpu_cs_chunk_ib))
goto free_partial_kdata;
 
-   ret = amdgpu_cs_p1_ib(p, p->chunks[i].kdata, _ibs);
+   ret = amdgpu_cs_p1_ib(p, p->chunks[i].kdata, num_ibs);
if (ret)
goto free_partial_kdata;
break;
@@ -268,21 +281,28 @@ static int amdgpu_cs_pass1(struct amdgpu_cs_parser *p,
}
}
 
-   ret = amdgpu_job_alloc(p->adev, num_ibs, >job, vm);
-   if (ret)
-   goto free_all_kdata;
+   if (!p->gang_size)
+   return -EINVAL;
 
-   ret = drm_sched_job_init(>job->base, p->entity, >vm);
-   if (ret)
-   goto free_all_kdata;
+   for (i = 0; i < p->gang_size; ++i) {
+   ret = amdgpu_job_alloc(p->adev, num_ibs[i], >jobs[i], vm);
+   if (ret)
+   goto free_all_kdata;
+
+   ret = drm_sched_job_init(>jobs[i]->base, p->entities[i],
+>vm);
+   if (ret)
+   goto free_all_kdata;
+   }
+   p->gang_leader = p->jobs[p->gang_size - 1];
 
-   if (p->ctx->vram_lost_counter != p->job->vram_lost_counter) {
+   if (p->ctx->vram_lost_counter != p->gang_leader->vram_lost_counter) {
ret = -ECANCELED;
goto free_all_kdata;
}
 
if (p->uf_entry.tv.bo)
-   p->job->uf_addr = uf_offset;
+   p->gang_leader->uf_addr = uf_offset;
kvfree(chunk_array);
 
/* Use this opportunity to fill in task info for the vm */
@@ -304,22 +324,18 @@ static int amdgpu_cs_pass1(struct amdgpu_cs_parser *p,
return ret;
 }
 
-static int amdgpu_cs_p2_ib(struct amdgpu_cs_parser *p,
-  struct amdgpu_cs_chunk *chunk,
-  unsigned int *num_ibs,
-  unsigned int *ce_preempt,
-  unsigned int *de_preempt)
+static 

[PATCH 07/10] drm/amdgpu: move setting the job resources

2022-07-14 Thread Christian König
Move setting the job resources into amdgpu_job.c

Signed-off-by: Christian König 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c  | 21 ++---
 drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 17 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_job.h |  2 ++
 3 files changed, 21 insertions(+), 19 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
index dfb7b4f46bc3..88f491dc7ca2 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
@@ -828,9 +828,6 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
struct amdgpu_vm *vm = >vm;
struct amdgpu_bo_list_entry *e;
struct list_head duplicates;
-   struct amdgpu_bo *gds;
-   struct amdgpu_bo *gws;
-   struct amdgpu_bo *oa;
int r;
 
INIT_LIST_HEAD(>validated);
@@ -947,22 +944,8 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
amdgpu_cs_report_moved_bytes(p->adev, p->bytes_moved,
 p->bytes_moved_vis);
 
-   gds = p->bo_list->gds_obj;
-   gws = p->bo_list->gws_obj;
-   oa = p->bo_list->oa_obj;
-
-   if (gds) {
-   p->job->gds_base = amdgpu_bo_gpu_offset(gds) >> PAGE_SHIFT;
-   p->job->gds_size = amdgpu_bo_size(gds) >> PAGE_SHIFT;
-   }
-   if (gws) {
-   p->job->gws_base = amdgpu_bo_gpu_offset(gws) >> PAGE_SHIFT;
-   p->job->gws_size = amdgpu_bo_size(gws) >> PAGE_SHIFT;
-   }
-   if (oa) {
-   p->job->oa_base = amdgpu_bo_gpu_offset(oa) >> PAGE_SHIFT;
-   p->job->oa_size = amdgpu_bo_size(oa) >> PAGE_SHIFT;
-   }
+   amdgpu_job_set_resources(p->job, p->bo_list->gds_obj,
+p->bo_list->gws_obj, p->bo_list->oa_obj);
 
if (p->uf_entry.tv.bo) {
struct amdgpu_bo *uf = ttm_to_amdgpu_bo(p->uf_entry.tv.bo);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
index 36c1be77bf8f..3255b2fca611 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
@@ -129,6 +129,23 @@ int amdgpu_job_alloc_with_ib(struct amdgpu_device *adev, 
unsigned size,
return r;
 }
 
+void amdgpu_job_set_resources(struct amdgpu_job *job, struct amdgpu_bo *gds,
+ struct amdgpu_bo *gws, struct amdgpu_bo *oa)
+{
+   if (gds) {
+   job->gds_base = amdgpu_bo_gpu_offset(gds) >> PAGE_SHIFT;
+   job->gds_size = amdgpu_bo_size(gds) >> PAGE_SHIFT;
+   }
+   if (gws) {
+   job->gws_base = amdgpu_bo_gpu_offset(gws) >> PAGE_SHIFT;
+   job->gws_size = amdgpu_bo_size(gws) >> PAGE_SHIFT;
+   }
+   if (oa) {
+   job->oa_base = amdgpu_bo_gpu_offset(oa) >> PAGE_SHIFT;
+   job->oa_size = amdgpu_bo_size(oa) >> PAGE_SHIFT;
+   }
+}
+
 void amdgpu_job_free_resources(struct amdgpu_job *job)
 {
struct amdgpu_ring *ring = to_amdgpu_ring(job->base.sched);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.h
index d599c0540b46..0bab8fe0d419 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.h
@@ -77,6 +77,8 @@ int amdgpu_job_alloc(struct amdgpu_device *adev, unsigned 
num_ibs,
 struct amdgpu_job **job, struct amdgpu_vm *vm);
 int amdgpu_job_alloc_with_ib(struct amdgpu_device *adev, unsigned size,
enum amdgpu_ib_pool_type pool, struct amdgpu_job **job);
+void amdgpu_job_set_resources(struct amdgpu_job *job, struct amdgpu_bo *gds,
+ struct amdgpu_bo *gws, struct amdgpu_bo *oa);
 void amdgpu_job_free_resources(struct amdgpu_job *job);
 void amdgpu_job_free(struct amdgpu_job *job);
 int amdgpu_job_submit(struct amdgpu_job *job, struct drm_sched_entity *entity,
-- 
2.25.1



[PATCH 08/10] drm/amdgpu: revert "fix limiting AV1 to the first instance on VCN3"

2022-07-14 Thread Christian König
This reverts commit 250195ff744f260c169f5427422b6f39c58cb883.

The job should now be initialized when we reach the parser functions.

Signed-off-by: Christian König 
---
 drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c | 17 ++---
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c 
b/drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c
index 39405f0db824..3cabceee5f57 100644
--- a/drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c
@@ -1761,21 +1761,23 @@ static const struct amdgpu_ring_funcs 
vcn_v3_0_dec_sw_ring_vm_funcs = {
.emit_reg_write_reg_wait = amdgpu_ring_emit_reg_write_reg_wait_helper,
 };
 
-static int vcn_v3_0_limit_sched(struct amdgpu_cs_parser *p)
+static int vcn_v3_0_limit_sched(struct amdgpu_cs_parser *p,
+   struct amdgpu_job *job)
 {
struct drm_gpu_scheduler **scheds;
 
/* The create msg must be in the first IB submitted */
-   if (atomic_read(>entity->fence_seq))
+   if (atomic_read(>base.entity->fence_seq))
return -EINVAL;
 
scheds = p->adev->gpu_sched[AMDGPU_HW_IP_VCN_DEC]
[AMDGPU_RING_PRIO_DEFAULT].sched;
-   drm_sched_entity_modify_sched(p->entity, scheds, 1);
+   drm_sched_entity_modify_sched(job->base.entity, scheds, 1);
return 0;
 }
 
-static int vcn_v3_0_dec_msg(struct amdgpu_cs_parser *p, uint64_t addr)
+static int vcn_v3_0_dec_msg(struct amdgpu_cs_parser *p, struct amdgpu_job *job,
+   uint64_t addr)
 {
struct ttm_operation_ctx ctx = { false, false };
struct amdgpu_bo_va_mapping *map;
@@ -1846,7 +1848,7 @@ static int vcn_v3_0_dec_msg(struct amdgpu_cs_parser *p, 
uint64_t addr)
if (create[0] == 0x7 || create[0] == 0x10 || create[0] == 0x11)
continue;
 
-   r = vcn_v3_0_limit_sched(p);
+   r = vcn_v3_0_limit_sched(p, job);
if (r)
goto out;
}
@@ -1860,7 +1862,7 @@ static int vcn_v3_0_ring_patch_cs_in_place(struct 
amdgpu_cs_parser *p,
   struct amdgpu_job *job,
   struct amdgpu_ib *ib)
 {
-   struct amdgpu_ring *ring = to_amdgpu_ring(p->entity->rq->sched);
+   struct amdgpu_ring *ring = to_amdgpu_ring(job->base.sched);
uint32_t msg_lo = 0, msg_hi = 0;
unsigned i;
int r;
@@ -1879,7 +1881,8 @@ static int vcn_v3_0_ring_patch_cs_in_place(struct 
amdgpu_cs_parser *p,
msg_hi = val;
} else if (reg == PACKET0(p->adev->vcn.internal.cmd, 0) &&
   val == 0) {
-   r = vcn_v3_0_dec_msg(p, ((u64)msg_hi) << 32 | msg_lo);
+   r = vcn_v3_0_dec_msg(p, job,
+((u64)msg_hi) << 32 | msg_lo);
if (r)
return r;
}
-- 
2.25.1



[PATCH 06/10] drm/amdgpu: remove SRIOV and MCBP dependencies from the CS

2022-07-14 Thread Christian König
We should not have any different CS constrains based
on the execution environment.

Signed-off-by: Christian König 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
index b9de631a66a3..dfb7b4f46bc3 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
@@ -323,8 +323,7 @@ static int amdgpu_cs_p2_ib(struct amdgpu_cs_parser *p,
return -EINVAL;
 
if (chunk_ib->ip_type == AMDGPU_HW_IP_GFX &&
-   chunk_ib->flags & AMDGPU_IB_FLAG_PREEMPT &&
-   (amdgpu_mcbp || amdgpu_sriov_vf(p->adev))) {
+   chunk_ib->flags & AMDGPU_IB_FLAG_PREEMPT) {
if (chunk_ib->flags & AMDGPU_IB_FLAG_CE)
(*ce_preempt)++;
else
@@ -1084,7 +1083,7 @@ static int amdgpu_cs_vm_handling(struct amdgpu_cs_parser 
*p)
if (r)
return r;
 
-   if (amdgpu_mcbp || amdgpu_sriov_vf(adev)) {
+   if (fpriv->csa_va) {
bo_va = fpriv->csa_va;
r = amdgpu_vm_bo_update(adev, bo_va, false);
if (r)
-- 
2.25.1



[PATCH 05/10] drm/amdgpu: cleanup and reorder amdgpu_cs.c

2022-07-14 Thread Christian König
Sort the functions in the order they are called and cleanup the coding
style and function names to represent the data they process.

Check the size of the IB chunk, initialize resulting entity and scheduler
job much earlier as well.

Signed-off-by: Christian König 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 1641 
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.h |2 +-
 2 files changed, 817 insertions(+), 826 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
index a3b8400c914e..b9de631a66a3 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
@@ -39,9 +39,61 @@
 #include "amdgpu_gem.h"
 #include "amdgpu_ras.h"
 
-static int amdgpu_cs_user_fence_chunk(struct amdgpu_cs_parser *p,
- struct drm_amdgpu_cs_chunk_fence *data,
- uint32_t *offset)
+static int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p,
+struct amdgpu_device *adev,
+struct drm_file *filp,
+union drm_amdgpu_cs *cs)
+{
+   struct amdgpu_fpriv *fpriv = filp->driver_priv;
+
+   if (cs->in.num_chunks == 0)
+   return -EINVAL;
+
+   memset(p, 0, sizeof(*p));
+   p->adev = adev;
+   p->filp = filp;
+
+   p->ctx = amdgpu_ctx_get(fpriv, cs->in.ctx_id);
+   if (!p->ctx)
+   return -EINVAL;
+
+   if (atomic_read(>ctx->guilty)) {
+   amdgpu_ctx_put(p->ctx);
+   return -ECANCELED;
+   }
+   return 0;
+}
+
+static int amdgpu_cs_p1_ib(struct amdgpu_cs_parser *p,
+  struct drm_amdgpu_cs_chunk_ib *chunk_ib,
+  unsigned int *num_ibs)
+{
+   struct drm_sched_entity *entity;
+   int r;
+
+   r = amdgpu_ctx_get_entity(p->ctx, chunk_ib->ip_type,
+ chunk_ib->ip_instance,
+ chunk_ib->ring, );
+   if (r)
+   return r;
+
+   /* Abort if there is no run queue associated with this entity.
+* Possibly because of disabled HW IP*/
+   if (entity->rq == NULL)
+   return -EINVAL;
+
+   /* Currently we don't support submitting to multiple entities */
+   if (p->entity && p->entity != entity)
+   return -EINVAL;
+
+   p->entity = entity;
+   ++(*num_ibs);
+   return 0;
+}
+
+static int amdgpu_cs_p1_user_fence(struct amdgpu_cs_parser *p,
+  struct drm_amdgpu_cs_chunk_fence *data,
+  uint32_t *offset)
 {
struct drm_gem_object *gobj;
struct amdgpu_bo *bo;
@@ -80,11 +132,11 @@ static int amdgpu_cs_user_fence_chunk(struct 
amdgpu_cs_parser *p,
return r;
 }
 
-static int amdgpu_cs_bo_handles_chunk(struct amdgpu_cs_parser *p,
- struct drm_amdgpu_bo_list_in *data)
+static int amdgpu_cs_p1_bo_handles(struct amdgpu_cs_parser *p,
+  struct drm_amdgpu_bo_list_in *data)
 {
+   struct drm_amdgpu_bo_list_entry *info;
int r;
-   struct drm_amdgpu_bo_list_entry *info = NULL;
 
r = amdgpu_bo_create_list_entry_array(data, );
if (r)
@@ -104,7 +156,9 @@ static int amdgpu_cs_bo_handles_chunk(struct 
amdgpu_cs_parser *p,
return r;
 }
 
-static int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, union 
drm_amdgpu_cs *cs)
+/* Copy the data from userspace and go over it the first time */
+static int amdgpu_cs_pass1(struct amdgpu_cs_parser *p,
+  union drm_amdgpu_cs *cs)
 {
struct amdgpu_fpriv *fpriv = p->filp->driver_priv;
struct amdgpu_vm *vm = >vm;
@@ -112,28 +166,17 @@ static int amdgpu_cs_parser_init(struct amdgpu_cs_parser 
*p, union drm_amdgpu_cs
uint64_t *chunk_array;
unsigned size, num_ibs = 0;
uint32_t uf_offset = 0;
-   int i;
int ret;
+   int i;
 
if (cs->in.num_chunks == 0)
return -EINVAL;
 
-   chunk_array = kvmalloc_array(cs->in.num_chunks, sizeof(uint64_t), 
GFP_KERNEL);
+   chunk_array = kvmalloc_array(cs->in.num_chunks, sizeof(uint64_t),
+GFP_KERNEL);
if (!chunk_array)
return -ENOMEM;
 
-   p->ctx = amdgpu_ctx_get(fpriv, cs->in.ctx_id);
-   if (!p->ctx) {
-   ret = -EINVAL;
-   goto free_chunk;
-   }
-
-   /* skip guilty context job */
-   if (atomic_read(>ctx->guilty) == 1) {
-   ret = -ECANCELED;
-   goto free_chunk;
-   }
-
/* get chunks */
chunk_array_user = u64_to_user_ptr(cs->in.chunks);
if (copy_from_user(chunk_array, chunk_array_user,
@@ -168,7 +211,8 @@ static int amdgpu_cs_parser_init(struct amdgpu_cs_parser 
*p, union drm_amdgpu_cs

[PATCH 04/10] drm/amdgpu: use DMA_RESV_USAGE_BOOKKEEP

2022-07-14 Thread Christian König
Use DMA_RESV_USAGE_BOOKKEEP for VM page table updates and KFD preemption fence.

Signed-off-by: Christian König 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c  | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
index 581c7ae41102..c6de30cffa2e 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
@@ -314,7 +314,7 @@ static int amdgpu_amdkfd_remove_eviction_fence(struct 
amdgpu_bo *bo,
 */
replacement = dma_fence_get_stub();
dma_resv_replace_fences(bo->tbo.base.resv, ef->base.context,
-   replacement, DMA_RESV_USAGE_READ);
+   replacement, DMA_RESV_USAGE_BOOKKEEP);
dma_fence_put(replacement);
return 0;
 }
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c
index 1fd3cbca20a2..03ec099d64e0 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c
@@ -112,7 +112,8 @@ static int amdgpu_vm_sdma_commit(struct 
amdgpu_vm_update_params *p,
swap(p->vm->last_unlocked, tmp);
dma_fence_put(tmp);
} else {
-   amdgpu_bo_fence(p->vm->root.bo, f, true);
+   dma_resv_add_fence(p->vm->root.bo->tbo.base.resv, f,
+  DMA_RESV_USAGE_BOOKKEEP);
}
 
if (fence && !p->immediate)
-- 
2.25.1



[PATCH 02/10] drm/amdgpu: Protect the amdgpu_bo_list list with a mutex v2

2022-07-14 Thread Christian König
From: Luben Tuikov 

Protect the struct amdgpu_bo_list with a mutex. This is used during command
submission in order to avoid buffer object corruption as recorded in
the link below.

v2 (chk): Keep the mutex looked for the whole CS to avoid using the
  list from multiple CS threads at the same time.

Suggested-by: Christian König 
Cc: Alex Deucher 
Cc: Andrey Grodzovsky 
Cc: Vitaly Prosyak 
Link: https://gitlab.freedesktop.org/drm/amd/-/issues/2048
Signed-off-by: Luben Tuikov 
Signed-off-by: Christian König 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c |  3 ++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h |  4 
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c  | 16 +---
 3 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
index 714178f1b6c6..2168163aad2d 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
@@ -40,7 +40,7 @@ static void amdgpu_bo_list_free_rcu(struct rcu_head *rcu)
 {
struct amdgpu_bo_list *list = container_of(rcu, struct amdgpu_bo_list,
   rhead);
-
+   mutex_destroy(>bo_list_mutex);
kvfree(list);
 }
 
@@ -136,6 +136,7 @@ int amdgpu_bo_list_create(struct amdgpu_device *adev, 
struct drm_file *filp,
 
trace_amdgpu_cs_bo_status(list->num_entries, total_size);
 
+   mutex_init(>bo_list_mutex);
*result = list;
return 0;
 
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h
index 529d52a204cf..9caea1688fc3 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h
@@ -47,6 +47,10 @@ struct amdgpu_bo_list {
struct amdgpu_bo *oa_obj;
unsigned first_userptr;
unsigned num_entries;
+
+   /* Protect access during command submission.
+*/
+   struct mutex bo_list_mutex;
 };
 
 int amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id,
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
index b28af04b0c3e..d8f1335bc68f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
@@ -519,6 +519,8 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
return r;
}
 
+   mutex_lock(>bo_list->bo_list_mutex);
+
/* One for TTM and one for the CS job */
amdgpu_bo_list_for_each_entry(e, p->bo_list)
e->tv.num_shared = 2;
@@ -651,6 +653,7 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
kvfree(e->user_pages);
e->user_pages = NULL;
}
+   mutex_unlock(>bo_list->bo_list_mutex);
}
return r;
 }
@@ -690,9 +693,11 @@ static void amdgpu_cs_parser_fini(struct amdgpu_cs_parser 
*parser, int error,
 {
unsigned i;
 
-   if (error && backoff)
+   if (error && backoff) {
ttm_eu_backoff_reservation(>ticket,
   >validated);
+   mutex_unlock(>bo_list->bo_list_mutex);
+   }
 
for (i = 0; i < parser->num_post_deps; i++) {
drm_syncobj_put(parser->post_deps[i].syncobj);
@@ -832,12 +837,16 @@ static int amdgpu_cs_vm_handling(struct amdgpu_cs_parser 
*p)
continue;
 
r = amdgpu_vm_bo_update(adev, bo_va, false);
-   if (r)
+   if (r) {
+   mutex_unlock(>bo_list->bo_list_mutex);
return r;
+   }
 
r = amdgpu_sync_fence(>job->sync, bo_va->last_pt_update);
-   if (r)
+   if (r) {
+   mutex_unlock(>bo_list->bo_list_mutex);
return r;
+   }
}
 
r = amdgpu_vm_handle_moved(adev, vm);
@@ -1278,6 +1287,7 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p,
 
ttm_eu_fence_buffer_objects(>ticket, >validated, p->fence);
mutex_unlock(>adev->notifier_lock);
+   mutex_unlock(>bo_list->bo_list_mutex);
 
return 0;
 
-- 
2.25.1



[PATCH 03/10] drm/amdgpu: revert "partial revert "remove ctx->lock" v2"

2022-07-14 Thread Christian König
This reverts commit 94f4c4965e5513ba624488f4b601d6b385635aec.

We found that the bo_list is missing a protection for its list entries.
Since that is fixed now this workaround can be removed again.

Signed-off-by: Christian König 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c  | 21 ++---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c |  2 --
 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h |  1 -
 3 files changed, 6 insertions(+), 18 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
index d8f1335bc68f..a3b8400c914e 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
@@ -128,8 +128,6 @@ static int amdgpu_cs_parser_init(struct amdgpu_cs_parser 
*p, union drm_amdgpu_cs
goto free_chunk;
}
 
-   mutex_lock(>ctx->lock);
-
/* skip guilty context job */
if (atomic_read(>ctx->guilty) == 1) {
ret = -ECANCELED;
@@ -708,7 +706,6 @@ static void amdgpu_cs_parser_fini(struct amdgpu_cs_parser 
*parser, int error,
dma_fence_put(parser->fence);
 
if (parser->ctx) {
-   mutex_unlock(>ctx->lock);
amdgpu_ctx_put(parser->ctx);
}
if (parser->bo_list)
@@ -1161,9 +1158,6 @@ static int amdgpu_cs_dependencies(struct amdgpu_device 
*adev,
 {
int i, r;
 
-   /* TODO: Investigate why we still need the context lock */
-   mutex_unlock(>ctx->lock);
-
for (i = 0; i < p->nchunks; ++i) {
struct amdgpu_cs_chunk *chunk;
 
@@ -1174,34 +1168,32 @@ static int amdgpu_cs_dependencies(struct amdgpu_device 
*adev,
case AMDGPU_CHUNK_ID_SCHEDULED_DEPENDENCIES:
r = amdgpu_cs_process_fence_dep(p, chunk);
if (r)
-   goto out;
+   return r;
break;
case AMDGPU_CHUNK_ID_SYNCOBJ_IN:
r = amdgpu_cs_process_syncobj_in_dep(p, chunk);
if (r)
-   goto out;
+   return r;
break;
case AMDGPU_CHUNK_ID_SYNCOBJ_OUT:
r = amdgpu_cs_process_syncobj_out_dep(p, chunk);
if (r)
-   goto out;
+   return r;
break;
case AMDGPU_CHUNK_ID_SYNCOBJ_TIMELINE_WAIT:
r = amdgpu_cs_process_syncobj_timeline_in_dep(p, chunk);
if (r)
-   goto out;
+   return r;
break;
case AMDGPU_CHUNK_ID_SYNCOBJ_TIMELINE_SIGNAL:
r = amdgpu_cs_process_syncobj_timeline_out_dep(p, 
chunk);
if (r)
-   goto out;
+   return r;
break;
}
}
 
-out:
-   mutex_lock(>ctx->lock);
-   return r;
+   return 0;
 }
 
 static void amdgpu_cs_post_dependencies(struct amdgpu_cs_parser *p)
@@ -1363,7 +1355,6 @@ int amdgpu_cs_ioctl(struct drm_device *dev, void *data, 
struct drm_file *filp)
goto out;
 
r = amdgpu_cs_submit(, cs);
-
 out:
amdgpu_cs_parser_fini(, r, reserved_buffers);
 
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
index 2ef5296216d6..53f9268366f2 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
@@ -286,7 +286,6 @@ static int amdgpu_ctx_init(struct amdgpu_ctx_mgr *mgr, 
int32_t priority,
kref_init(>refcount);
ctx->mgr = mgr;
spin_lock_init(>ring_lock);
-   mutex_init(>lock);
 
ctx->reset_counter = atomic_read(>adev->gpu_reset_counter);
ctx->reset_counter_query = ctx->reset_counter;
@@ -401,7 +400,6 @@ static void amdgpu_ctx_fini(struct kref *ref)
drm_dev_exit(idx);
}
 
-   mutex_destroy(>lock);
kfree(ctx);
 }
 
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h
index cc7c8afff414..0fa0e56daf67 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h
@@ -53,7 +53,6 @@ struct amdgpu_ctx {
boolpreamble_presented;
int32_t init_priority;
int32_t override_priority;
-   struct mutexlock;
atomic_tguilty;
unsigned long   ras_counter_ce;
unsigned long   ras_counter_ue;
-- 
2.25.1



Gang submit v2

2022-07-14 Thread Christian König
Hi guys,

secound round for this patch set. I've fixed the minor comments and bugs
Andrey and Yogesh came up with and rebased everything.

The base is not the current amd-staging-drm-next branch, but rather Alex
rebased version since this depends on the dma-resv usage rework. So
don't bother trying to apply that anywhere.

The patches are also available here 
https://gitlab.freedesktop.org/ckoenig/linux-drm.git
on branch amd-gang-submit.

Please review and comment,
Christian.




[PATCH 01/10] drm/sched: move calling drm_sched_entity_select_rq

2022-07-14 Thread Christian König
We already discussed that the call to drm_sched_entity_select_rq() needs
to move to drm_sched_job_arm() to be able to set a new scheduler list
between _init() and _arm(). This was just not applied for some reason.

Signed-off-by: Christian König 
CC: Andrey Grodzovsky 
CC: dri-de...@lists.freedesktop.org
---
 drivers/gpu/drm/scheduler/sched_main.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/scheduler/sched_main.c 
b/drivers/gpu/drm/scheduler/sched_main.c
index 68317d3a7a27..e0ab14e0fb6b 100644
--- a/drivers/gpu/drm/scheduler/sched_main.c
+++ b/drivers/gpu/drm/scheduler/sched_main.c
@@ -592,7 +592,6 @@ int drm_sched_job_init(struct drm_sched_job *job,
   struct drm_sched_entity *entity,
   void *owner)
 {
-   drm_sched_entity_select_rq(entity);
if (!entity->rq)
return -ENOENT;
 
@@ -628,7 +627,7 @@ void drm_sched_job_arm(struct drm_sched_job *job)
struct drm_sched_entity *entity = job->entity;
 
BUG_ON(!entity);
-
+   drm_sched_entity_select_rq(entity);
sched = entity->rq->sched;
 
job->sched = sched;
-- 
2.25.1



[PATCH] drm/amdgpu: Fix for drm buddy memory corruption

2022-07-14 Thread Arunpravin Paneer Selvam
User reported gpu page fault when running graphics applications
and in some cases garbaged graphics are observed as soon as X
starts. This patch fixes all the issues.

Fixed the typecast issue for fpfn and lpfn variables, thus
preventing the overflow problem which resolves the memory
corruption.

Signed-off-by: Arunpravin Paneer Selvam 
Reported-by: Mike Lothian 
Tested-by: Mike Lothian 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 16 
 drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.h |  2 +-
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
index 49e4092f447f..34d789054ec8 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
@@ -366,11 +366,11 @@ static int amdgpu_vram_mgr_new(struct 
ttm_resource_manager *man,
unsigned long pages_per_block;
int r;
 
-   lpfn = place->lpfn << PAGE_SHIFT;
+   lpfn = (u64)place->lpfn << PAGE_SHIFT;
if (!lpfn)
lpfn = man->size;
 
-   fpfn = place->fpfn << PAGE_SHIFT;
+   fpfn = (u64)place->fpfn << PAGE_SHIFT;
 
max_bytes = adev->gmc.mc_vram_size;
if (tbo->type != ttm_bo_type_kernel)
@@ -410,12 +410,12 @@ static int amdgpu_vram_mgr_new(struct 
ttm_resource_manager *man,
/* Allocate blocks in desired range */
vres->flags |= DRM_BUDDY_RANGE_ALLOCATION;
 
-   remaining_size = vres->base.num_pages << PAGE_SHIFT;
+   remaining_size = (u64)vres->base.num_pages << PAGE_SHIFT;
 
mutex_lock(>lock);
while (remaining_size) {
if (tbo->page_alignment)
-   min_block_size = tbo->page_alignment << PAGE_SHIFT;
+   min_block_size = (u64)tbo->page_alignment << PAGE_SHIFT;
else
min_block_size = mgr->default_page_size;
 
@@ -424,12 +424,12 @@ static int amdgpu_vram_mgr_new(struct 
ttm_resource_manager *man,
/* Limit maximum size to 2GiB due to SG table limitations */
size = min(remaining_size, 2ULL << 30);
 
-   if (size >= pages_per_block << PAGE_SHIFT)
-   min_block_size = pages_per_block << PAGE_SHIFT;
+   if (size >= (u64)pages_per_block << PAGE_SHIFT)
+   min_block_size = (u64)pages_per_block << PAGE_SHIFT;
 
cur_size = size;
 
-   if (fpfn + size != place->lpfn << PAGE_SHIFT) {
+   if (fpfn + size != (u64)place->lpfn << PAGE_SHIFT) {
/*
 * Except for actual range allocation, modify the size 
and
 * min_block_size conforming to continuous flag 
enablement
@@ -469,7 +469,7 @@ static int amdgpu_vram_mgr_new(struct ttm_resource_manager 
*man,
LIST_HEAD(temp);
 
trim_list = >blocks;
-   original_size = vres->base.num_pages << PAGE_SHIFT;
+   original_size = (u64)vres->base.num_pages << PAGE_SHIFT;
 
/*
 * If size value is rounded up to min_block_size, trim the last
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.h
index 9a2db87186c7..bef0f561ba60 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.h
@@ -50,7 +50,7 @@ static inline u64 amdgpu_vram_mgr_block_start(struct 
drm_buddy_block *block)
 
 static inline u64 amdgpu_vram_mgr_block_size(struct drm_buddy_block *block)
 {
-   return PAGE_SIZE << drm_buddy_block_order(block);
+   return (u64)PAGE_SIZE << drm_buddy_block_order(block);
 }
 
 static inline struct drm_buddy_block *
-- 
2.25.1



RE: [PATCH] drm/amd/display: make retrieve_dmi_info() static

2022-07-14 Thread Quan, Evan
[AMD Official Use Only - General]

Reviewed-by: Evan Quan 

> -Original Message-
> From: amd-gfx  On Behalf Of Alex
> Deucher
> Sent: Wednesday, July 13, 2022 11:21 PM
> To: amd-gfx@lists.freedesktop.org
> Cc: Deucher, Alexander ; kernel test robot
> 
> Subject: [PATCH] drm/amd/display: make retrieve_dmi_info() static
> 
> It's not used outside of amdgpu_dm.c.
> 
> Reported-by: kernel test robot 
> Signed-off-by: Alex Deucher 
> ---
>  drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
> b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
> index 21aec55abd1a..c03f300851fa 100644
> --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
> +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
> @@ -1446,7 +1446,7 @@ static const struct dmi_system_id
> hpd_disconnect_quirk_table[] = {
>   {}
>  };
> 
> -void retrieve_dmi_info(struct amdgpu_display_manager *dm)
> +static void retrieve_dmi_info(struct amdgpu_display_manager *dm)
>  {
>   const struct dmi_system_id *dmi_id;
> 
> --
> 2.35.3


RE: [PATCH 4/4] drm/amdgpu: drop runpm from amdgpu_device structure

2022-07-14 Thread Quan, Evan
[AMD Official Use Only - General]

Series is reviewed-by: Evan Quan 

> -Original Message-
> From: Chen, Guchun 
> Sent: Thursday, July 14, 2022 4:43 PM
> To: amd-gfx@lists.freedesktop.org; Deucher, Alexander
> ; Zhang, Hawking
> ; Lazar, Lijo ; Quan, Evan
> ; Feng, Kenneth 
> Cc: Chen, Guchun 
> Subject: [PATCH 4/4] drm/amdgpu: drop runpm from amdgpu_device
> structure
> 
> It's redundant, as now switching to rpm_mode to indicate
> runtime power management mode.
> 
> Suggested-by: Lijo Lazar 
> Signed-off-by: Guchun Chen 
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu.h |  1 -
>  drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 10 +-
>  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 23 ++-
>  3 files changed, 15 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> index 15f290c9523d..9f729a648005 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> @@ -1011,7 +1011,6 @@ struct amdgpu_device {
>   uint64_t
>   df_perfmon_config_assign_mask[AMDGPU_MAX_DF_PERFMONS];
> 
>   /* enable runtime pm on the device */
> - boolrunpm;
>   boolin_runpm;
>   boolhas_pr3;
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> index 1cc9260e75de..70a7203a2916 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> @@ -2118,7 +2118,7 @@ static int amdgpu_pci_probe(struct pci_dev *pdev,
>   if (ret)
>   DRM_ERROR("Creating debugfs files failed (%d).\n", ret);
> 
> - if (adev->runpm) {
> + if (adev->pm.rpm_mode != AMDGPU_RUNPM_NONE) {
>   /* only need to skip on ATPX */
>   if (amdgpu_device_supports_px(ddev))
>   dev_pm_set_driver_flags(ddev->dev,
> DPM_FLAG_NO_DIRECT_COMPLETE);
> @@ -2175,7 +2175,7 @@ amdgpu_pci_remove(struct pci_dev *pdev)
> 
>   drm_dev_unplug(dev);
> 
> - if (adev->runpm) {
> + if (adev->pm.rpm_mode != AMDGPU_RUNPM_NONE) {
>   pm_runtime_get_sync(dev->dev);
>   pm_runtime_forbid(dev->dev);
>   }
> @@ -2458,7 +2458,7 @@ static int amdgpu_pmops_runtime_suspend(struct
> device *dev)
>   struct amdgpu_device *adev = drm_to_adev(drm_dev);
>   int ret, i;
> 
> - if (!adev->runpm) {
> + if (adev->pm.rpm_mode == AMDGPU_RUNPM_NONE) {
>   pm_runtime_forbid(dev);
>   return -EBUSY;
>   }
> @@ -2527,7 +2527,7 @@ static int amdgpu_pmops_runtime_resume(struct
> device *dev)
>   struct amdgpu_device *adev = drm_to_adev(drm_dev);
>   int ret;
> 
> - if (!adev->runpm)
> + if (adev->pm.rpm_mode == AMDGPU_RUNPM_NONE)
>   return -EINVAL;
> 
>   /* Avoids registers access if device is physically gone */
> @@ -2571,7 +2571,7 @@ static int amdgpu_pmops_runtime_idle(struct
> device *dev)
>   /* we don't want the main rpm_idle to call suspend - we want to
> autosuspend */
>   int ret = 1;
> 
> - if (!adev->runpm) {
> + if (adev->pm.rpm_mode == AMDGPU_RUNPM_NONE) {
>   pm_runtime_forbid(dev);
>   return -EBUSY;
>   }
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> index 9182e81e3135..a3744c0b632b 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> @@ -147,14 +147,13 @@ int amdgpu_driver_load_kms(struct
> amdgpu_device *adev, unsigned long flags)
>   goto out;
>   }
> 
> + adev->pm.rpm_mode = AMDGPU_RUNPM_NONE;
>   if (amdgpu_device_supports_px(dev) &&
> - (amdgpu_runtime_pm != 0)) { /* enable runpm by default for atpx
> */
> - adev->runpm = true;
> + (amdgpu_runtime_pm != 0)) { /* enable PX as runtime mode */
>   adev->pm.rpm_mode = AMDGPU_RUNPM_PX;
>   dev_info(adev->dev, "Using ATPX for runtime pm\n");
>   } else if (amdgpu_device_supports_boco(dev) &&
> -(amdgpu_runtime_pm != 0)) { /* enable runpm by default
> for boco */
> - adev->runpm = true;
> +(amdgpu_runtime_pm != 0)) { /* enable boco as runtime
> mode */
>   adev->pm.rpm_mode = AMDGPU_RUNPM_BOCO;
>   dev_info(adev->dev, "Using BOCO for runtime pm\n");
>   } else if (amdgpu_device_supports_baco(dev) &&
> @@ -162,25 +161,23 @@ int amdgpu_driver_load_kms(struct
> amdgpu_device *adev, unsigned long flags)
>   switch (adev->asic_type) {
>   case CHIP_VEGA20:
>   case CHIP_ARCTURUS:
> - /* enable runpm if runpm=1 */
> + /* enable BACO as runpm mode if runpm=1 */
>   if (amdgpu_runtime_pm > 0)
> - adev->runpm = true;
> +

Re: [PATCH] Revert "drm/amdgpu: add drm buddy support to amdgpu"

2022-07-14 Thread Thomas Zimmermann

Hi

Am 08.07.22 um 12:21 schrieb Arunpravin Paneer Selvam:

This reverts the following commits:
commit 708d19d9f362 ("drm/amdgpu: move internal vram_mgr function into the C 
file")
commit 5e3f1e7729ec ("drm/amdgpu: fix start calculation in amdgpu_vram_mgr_new")
commit c9cad937c0c5 ("drm/amdgpu: add drm buddy support to amdgpu")


Does the revert need to be cherry-picked into drm-misc-next-fixes?

Best regards
Thomas



[WHY]
Few users reported garbaged graphics as soon as x starts,
reverting until this can be resolved.

Signed-off-by: Arunpravin Paneer Selvam 
---
  drivers/gpu/drm/Kconfig   |   1 -
  .../gpu/drm/amd/amdgpu/amdgpu_res_cursor.h|  97 +
  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h   |  10 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c  | 394 +++---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.h  |  62 ---
  5 files changed, 176 insertions(+), 388 deletions(-)
  delete mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.h

diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig
index 6c2256e8474b..d438d5ff8b40 100644
--- a/drivers/gpu/drm/Kconfig
+++ b/drivers/gpu/drm/Kconfig
@@ -272,7 +272,6 @@ config DRM_AMDGPU
select HWMON
select BACKLIGHT_CLASS_DEVICE
select INTERVAL_TREE
-   select DRM_BUDDY
help
  Choose this option if you have a recent AMD Radeon graphics card.
  
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_res_cursor.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_res_cursor.h

index 6546552e596c..acfa207cf970 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_res_cursor.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_res_cursor.h
@@ -30,15 +30,12 @@
  #include 
  #include 
  
-#include "amdgpu_vram_mgr.h"

-
  /* state back for walking over vram_mgr and gtt_mgr allocations */
  struct amdgpu_res_cursor {
uint64_tstart;
uint64_tsize;
uint64_tremaining;
-   void*node;
-   uint32_tmem_type;
+   struct drm_mm_node  *node;
  };
  
  /**

@@ -55,63 +52,27 @@ static inline void amdgpu_res_first(struct ttm_resource 
*res,
uint64_t start, uint64_t size,
struct amdgpu_res_cursor *cur)
  {
-   struct drm_buddy_block *block;
-   struct list_head *head, *next;
struct drm_mm_node *node;
  
-	if (!res)

-   goto fallback;
-
-   BUG_ON(start + size > res->num_pages << PAGE_SHIFT);
-
-   cur->mem_type = res->mem_type;
-
-   switch (cur->mem_type) {
-   case TTM_PL_VRAM:
-   head = _amdgpu_vram_mgr_resource(res)->blocks;
-
-   block = list_first_entry_or_null(head,
-struct drm_buddy_block,
-link);
-   if (!block)
-   goto fallback;
-
-   while (start >= amdgpu_vram_mgr_block_size(block)) {
-   start -= amdgpu_vram_mgr_block_size(block);
-
-   next = block->link.next;
-   if (next != head)
-   block = list_entry(next, struct 
drm_buddy_block, link);
-   }
-
-   cur->start = amdgpu_vram_mgr_block_start(block) + start;
-   cur->size = min(amdgpu_vram_mgr_block_size(block) - start, 
size);
-   cur->remaining = size;
-   cur->node = block;
-   break;
-   case TTM_PL_TT:
-   node = to_ttm_range_mgr_node(res)->mm_nodes;
-   while (start >= node->size << PAGE_SHIFT)
-   start -= node++->size << PAGE_SHIFT;
-
-   cur->start = (node->start << PAGE_SHIFT) + start;
-   cur->size = min((node->size << PAGE_SHIFT) - start, size);
+   if (!res || res->mem_type == TTM_PL_SYSTEM) {
+   cur->start = start;
+   cur->size = size;
cur->remaining = size;
-   cur->node = node;
-   break;
-   default:
-   goto fallback;
+   cur->node = NULL;
+   WARN_ON(res && start + size > res->num_pages << PAGE_SHIFT);
+   return;
}
  
-	return;

+   BUG_ON(start + size > res->num_pages << PAGE_SHIFT);
  
-fallback:

-   cur->start = start;
-   cur->size = size;
+   node = to_ttm_range_mgr_node(res)->mm_nodes;
+   while (start >= node->size << PAGE_SHIFT)
+   start -= node++->size << PAGE_SHIFT;
+
+   cur->start = (node->start << PAGE_SHIFT) + start;
+   cur->size = min((node->size << PAGE_SHIFT) - start, size);
cur->remaining = size;
-   cur->node = NULL;
-   WARN_ON(res && start + size > res->num_pages << PAGE_SHIFT);
-   return;
+   cur->node = node;
  }
  
  /**

@@ -124,9 +85,7 @@ static inline void amdgpu_res_first(struct ttm_resource *res,
 

Re: [PATCH 1/3] Revert "drm/amdgpu: move internal vram_mgr function into the C file"

2022-07-14 Thread Thomas Zimmermann

Hi

Am 08.07.22 um 11:30 schrieb Arunpravin Paneer Selvam:

This reverts commit 708d19d9f362766147cab79eccae60912c6d3068.


This commit is only present in drm-misc-next. Should the revert be 
cherry-picked into drm-misc-next-fixes?


Best regards
Thomas



This is part of a revert of the following commits:
commit 708d19d9f362 ("drm/amdgpu: move internal vram_mgr function into the C 
file")
commit 5e3f1e7729ec ("drm/amdgpu: fix start calculation in amdgpu_vram_mgr_new")
commit c9cad937c0c5 ("drm/amdgpu: add drm buddy support to amdgpu")

[WHY]
Few users reported garbaged graphics as soon as x starts,
reverting until this can be resolved.

Signed-off-by: Arunpravin Paneer Selvam 
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 29 
  drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.h | 27 ++
  2 files changed, 27 insertions(+), 29 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
index 7a5e8a7b4a1b..51d9d3a4456c 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
@@ -50,35 +50,6 @@ to_amdgpu_device(struct amdgpu_vram_mgr *mgr)
return container_of(mgr, struct amdgpu_device, mman.vram_mgr);
  }
  
-static inline struct drm_buddy_block *

-amdgpu_vram_mgr_first_block(struct list_head *list)
-{
-   return list_first_entry_or_null(list, struct drm_buddy_block, link);
-}
-
-static inline bool amdgpu_is_vram_mgr_blocks_contiguous(struct list_head *head)
-{
-   struct drm_buddy_block *block;
-   u64 start, size;
-
-   block = amdgpu_vram_mgr_first_block(head);
-   if (!block)
-   return false;
-
-   while (head != block->link.next) {
-   start = amdgpu_vram_mgr_block_start(block);
-   size = amdgpu_vram_mgr_block_size(block);
-
-   block = list_entry(block->link.next, struct drm_buddy_block, 
link);
-   if (start + size != amdgpu_vram_mgr_block_start(block))
-   return false;
-   }
-
-   return true;
-}
-
-
-
  /**
   * DOC: mem_info_vram_total
   *
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.h
index 4b267bf1c5db..9a2db87186c7 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.h
@@ -53,6 +53,33 @@ static inline u64 amdgpu_vram_mgr_block_size(struct 
drm_buddy_block *block)
return PAGE_SIZE << drm_buddy_block_order(block);
  }
  
+static inline struct drm_buddy_block *

+amdgpu_vram_mgr_first_block(struct list_head *list)
+{
+   return list_first_entry_or_null(list, struct drm_buddy_block, link);
+}
+
+static inline bool amdgpu_is_vram_mgr_blocks_contiguous(struct list_head *head)
+{
+   struct drm_buddy_block *block;
+   u64 start, size;
+
+   block = amdgpu_vram_mgr_first_block(head);
+   if (!block)
+   return false;
+
+   while (head != block->link.next) {
+   start = amdgpu_vram_mgr_block_start(block);
+   size = amdgpu_vram_mgr_block_size(block);
+
+   block = list_entry(block->link.next, struct drm_buddy_block, 
link);
+   if (start + size != amdgpu_vram_mgr_block_start(block))
+   return false;
+   }
+
+   return true;
+}
+
  static inline struct amdgpu_vram_mgr_resource *
  to_amdgpu_vram_mgr_resource(struct ttm_resource *res)
  {


--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev


OpenPGP_signature
Description: OpenPGP digital signature


[PATCH 4/4] drm/amdgpu: drop runpm from amdgpu_device structure

2022-07-14 Thread Guchun Chen
It's redundant, as now switching to rpm_mode to indicate
runtime power management mode.

Suggested-by: Lijo Lazar 
Signed-off-by: Guchun Chen 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h |  1 -
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 10 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 23 ++-
 3 files changed, 15 insertions(+), 19 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index 15f290c9523d..9f729a648005 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -1011,7 +1011,6 @@ struct amdgpu_device {
uint64_tdf_perfmon_config_assign_mask[AMDGPU_MAX_DF_PERFMONS];
 
/* enable runtime pm on the device */
-   boolrunpm;
boolin_runpm;
boolhas_pr3;
 
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index 1cc9260e75de..70a7203a2916 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
@@ -2118,7 +2118,7 @@ static int amdgpu_pci_probe(struct pci_dev *pdev,
if (ret)
DRM_ERROR("Creating debugfs files failed (%d).\n", ret);
 
-   if (adev->runpm) {
+   if (adev->pm.rpm_mode != AMDGPU_RUNPM_NONE) {
/* only need to skip on ATPX */
if (amdgpu_device_supports_px(ddev))
dev_pm_set_driver_flags(ddev->dev, 
DPM_FLAG_NO_DIRECT_COMPLETE);
@@ -2175,7 +2175,7 @@ amdgpu_pci_remove(struct pci_dev *pdev)
 
drm_dev_unplug(dev);
 
-   if (adev->runpm) {
+   if (adev->pm.rpm_mode != AMDGPU_RUNPM_NONE) {
pm_runtime_get_sync(dev->dev);
pm_runtime_forbid(dev->dev);
}
@@ -2458,7 +2458,7 @@ static int amdgpu_pmops_runtime_suspend(struct device 
*dev)
struct amdgpu_device *adev = drm_to_adev(drm_dev);
int ret, i;
 
-   if (!adev->runpm) {
+   if (adev->pm.rpm_mode == AMDGPU_RUNPM_NONE) {
pm_runtime_forbid(dev);
return -EBUSY;
}
@@ -2527,7 +2527,7 @@ static int amdgpu_pmops_runtime_resume(struct device *dev)
struct amdgpu_device *adev = drm_to_adev(drm_dev);
int ret;
 
-   if (!adev->runpm)
+   if (adev->pm.rpm_mode == AMDGPU_RUNPM_NONE)
return -EINVAL;
 
/* Avoids registers access if device is physically gone */
@@ -2571,7 +2571,7 @@ static int amdgpu_pmops_runtime_idle(struct device *dev)
/* we don't want the main rpm_idle to call suspend - we want to 
autosuspend */
int ret = 1;
 
-   if (!adev->runpm) {
+   if (adev->pm.rpm_mode == AMDGPU_RUNPM_NONE) {
pm_runtime_forbid(dev);
return -EBUSY;
}
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
index 9182e81e3135..a3744c0b632b 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
@@ -147,14 +147,13 @@ int amdgpu_driver_load_kms(struct amdgpu_device *adev, 
unsigned long flags)
goto out;
}
 
+   adev->pm.rpm_mode = AMDGPU_RUNPM_NONE;
if (amdgpu_device_supports_px(dev) &&
-   (amdgpu_runtime_pm != 0)) { /* enable runpm by default for atpx */
-   adev->runpm = true;
+   (amdgpu_runtime_pm != 0)) { /* enable PX as runtime mode */
adev->pm.rpm_mode = AMDGPU_RUNPM_PX;
dev_info(adev->dev, "Using ATPX for runtime pm\n");
} else if (amdgpu_device_supports_boco(dev) &&
-  (amdgpu_runtime_pm != 0)) { /* enable runpm by default for 
boco */
-   adev->runpm = true;
+  (amdgpu_runtime_pm != 0)) { /* enable boco as runtime mode */
adev->pm.rpm_mode = AMDGPU_RUNPM_BOCO;
dev_info(adev->dev, "Using BOCO for runtime pm\n");
} else if (amdgpu_device_supports_baco(dev) &&
@@ -162,25 +161,23 @@ int amdgpu_driver_load_kms(struct amdgpu_device *adev, 
unsigned long flags)
switch (adev->asic_type) {
case CHIP_VEGA20:
case CHIP_ARCTURUS:
-   /* enable runpm if runpm=1 */
+   /* enable BACO as runpm mode if runpm=1 */
if (amdgpu_runtime_pm > 0)
-   adev->runpm = true;
+   adev->pm.rpm_mode = AMDGPU_RUNPM_BACO;
break;
case CHIP_VEGA10:
-   /* turn runpm on if noretry=0 */
+   /* enable BACO as runpm mode if noretry=0 */
if (!adev->gmc.noretry)
-   adev->runpm = true;
+   adev->pm.rpm_mode = AMDGPU_RUNPM_BACO;
break;
default:
-   

[PATCH 3/4] drm/amdgpu: drop runtime pm disablement quirk on several sienna cichlid cards

2022-07-14 Thread Guchun Chen
This quirk is not needed any more as it's fixed by bypassing
SMU FW reloading in runtime resume.

Signed-off-by: Guchun Chen 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 13 -
 1 file changed, 13 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
index ceecb74842de..9182e81e3135 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
@@ -43,17 +43,6 @@
 #include "amdgpu_display.h"
 #include "amdgpu_ras.h"
 
-static void amdgpu_runtime_pm_quirk(struct amdgpu_device *adev)
-{
-   /*
-* Add below quirk on several sienna_cichlid cards to disable
-* runtime pm to fix EMI failures.
-*/
-   if (((adev->pdev->device == 0x73A1) && (adev->pdev->revision == 0x00)) 
||
-   ((adev->pdev->device == 0x73BF) && (adev->pdev->revision == 0xCF)))
-   adev->runpm = false;
-}
-
 void amdgpu_unregister_gpu_instance(struct amdgpu_device *adev)
 {
struct amdgpu_gpu_instance *gpu_instance;
@@ -188,8 +177,6 @@ int amdgpu_driver_load_kms(struct amdgpu_device *adev, 
unsigned long flags)
break;
}
 
-   amdgpu_runtime_pm_quirk(adev);
-
if (adev->runpm) {
adev->pm.rpm_mode = AMDGPU_RUNPM_BACO;
dev_info(adev->dev, "Using BACO for runtime pm\n");
-- 
2.17.1



[PATCH 2/4] drm/amdgpu: skip SMU FW reloading in runpm BACO case

2022-07-14 Thread Guchun Chen
SMU is always alive, so it's fine to skip SMU FW reloading
when runpm resumed from BACO, this can avoid some race issues
when resuming SMU.

Suggested-by: Evan Quan 
Signed-off-by: Guchun Chen 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
index e9411c28d88b..6540582ecbf8 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
@@ -2348,6 +2348,13 @@ static int psp_load_smu_fw(struct psp_context *psp)
>firmware.ucode[AMDGPU_UCODE_ID_SMC];
struct amdgpu_ras *ras = psp->ras_context.ras;
 
+   /*
+* Skip SMU FW reloading in case of using BACO for runpm only,
+* as SMU is always alive.
+*/
+   if (adev->in_runpm && (adev->pm.rpm_mode == AMDGPU_RUNPM_BACO))
+   return 0;
+
if (!ucode->fw || amdgpu_sriov_vf(psp->adev))
return 0;
 
-- 
2.17.1



[PATCH 1/4] drm/amdgpu: introduce runtime pm mode

2022-07-14 Thread Guchun Chen
It can benefit code consistency in future.

Suggested-by: Lijo Lazar 
Signed-off-by: Guchun Chen 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 6 +-
 drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h | 9 +
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
index 4b663866d33a..ceecb74842de 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
@@ -161,10 +161,12 @@ int amdgpu_driver_load_kms(struct amdgpu_device *adev, 
unsigned long flags)
if (amdgpu_device_supports_px(dev) &&
(amdgpu_runtime_pm != 0)) { /* enable runpm by default for atpx */
adev->runpm = true;
+   adev->pm.rpm_mode = AMDGPU_RUNPM_PX;
dev_info(adev->dev, "Using ATPX for runtime pm\n");
} else if (amdgpu_device_supports_boco(dev) &&
   (amdgpu_runtime_pm != 0)) { /* enable runpm by default for 
boco */
adev->runpm = true;
+   adev->pm.rpm_mode = AMDGPU_RUNPM_BOCO;
dev_info(adev->dev, "Using BOCO for runtime pm\n");
} else if (amdgpu_device_supports_baco(dev) &&
   (amdgpu_runtime_pm != 0)) {
@@ -188,8 +190,10 @@ int amdgpu_driver_load_kms(struct amdgpu_device *adev, 
unsigned long flags)
 
amdgpu_runtime_pm_quirk(adev);
 
-   if (adev->runpm)
+   if (adev->runpm) {
+   adev->pm.rpm_mode = AMDGPU_RUNPM_BACO;
dev_info(adev->dev, "Using BACO for runtime pm\n");
+   }
}
 
/* Call ACPI methods: require modeset init
diff --git a/drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h 
b/drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h
index 524fb09437e5..65624d091ed2 100644
--- a/drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h
+++ b/drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h
@@ -45,6 +45,13 @@ enum amdgpu_int_thermal_type {
THERMAL_TYPE_KV,
 };
 
+enum amdgpu_runpm_mode {
+   AMDGPU_RUNPM_NONE,
+   AMDGPU_RUNPM_PX,
+   AMDGPU_RUNPM_BOCO,
+   AMDGPU_RUNPM_BACO,
+};
+
 struct amdgpu_ps {
u32 caps; /* vbios flags */
u32 class; /* vbios flags */
@@ -355,6 +362,8 @@ struct amdgpu_pm {
struct amdgpu_ctx   *stable_pstate_ctx;
 
struct config_table_setting config_table;
+   /* runtime mode */
+   enum amdgpu_runpm_mode rpm_mode;
 };
 
 int amdgpu_dpm_read_sensor(struct amdgpu_device *adev, enum amd_pp_sensors 
sensor,
-- 
2.17.1



Re: [RFC PATCH 1/1] drm/amdgpu: Protect the amdgpu_bo_list list with a mutex

2022-07-14 Thread Christian König

Hi guys,

I need this fixed for the gang submit branch. So I'm going to pick up 
this patch and make the necessary modifications to make it stable.


Thanks,
Christian.

Am 12.07.22 um 10:07 schrieb Christian König:

Am 12.07.22 um 07:39 schrieb Luben Tuikov:
Protect the struct amdgpu_bo_list with a mutex. This is used during 
command

submission in order to avoid buffer object corruption as recorded in
the link below.

Suggested-by: Christian König 
Cc: Alex Deucher 
Cc: Andrey Grodzovsky 
Cc: Vitaly Prosyak 
Link: 
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgitlab.freedesktop.org%2Fdrm%2Famd%2F-%2Fissues%2F2048data=05%7C01%7Cchristian.koenig%40amd.com%7C1fc0be908ec3423f396c08da63dd8b6d%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637932100428991697%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7Csdata=KzScTABB44b7TxNlbCe2gNU%2F%2F9om5JyvK88SeJ5SBus%3Dreserved=0

Signed-off-by: Luben Tuikov 
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c |  3 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h |  4 +++
  drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c  | 31 +++--
  3 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c

index 714178f1b6c6ed..2168163aad2d38 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
@@ -40,7 +40,7 @@ static void amdgpu_bo_list_free_rcu(struct rcu_head 
*rcu)

  {
  struct amdgpu_bo_list *list = container_of(rcu, struct 
amdgpu_bo_list,

 rhead);
-
+    mutex_destroy(>bo_list_mutex);
  kvfree(list);
  }
  @@ -136,6 +136,7 @@ int amdgpu_bo_list_create(struct amdgpu_device 
*adev, struct drm_file *filp,

    trace_amdgpu_cs_bo_status(list->num_entries, total_size);
  +    mutex_init(>bo_list_mutex);
  *result = list;
  return 0;
  diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h

index 044b41f0bfd9ce..717984d4de6858 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h
@@ -48,6 +48,10 @@ struct amdgpu_bo_list {
  struct amdgpu_bo *oa_obj;
  unsigned first_userptr;
  unsigned num_entries;
+
+    /* Protect access during command submission.
+ */
+    struct mutex bo_list_mutex;
  };
    int amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id,
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c

index 36ac1f1d11e6b4..0b2932c20ec777 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
@@ -517,6 +517,8 @@ static int amdgpu_cs_parser_bos(struct 
amdgpu_cs_parser *p,

  return r;
  }
  +    mutex_lock(>bo_list->bo_list_mutex);


That lock/unlock placement is not correct and probably the reason why 
you still run into trouble with this patch.


You need to grab the lock before the call to amdgpu_bo_list_get_list() 
and drop it either after a call to ttm_eu_backoff_reservation() or 
ttm_eu_fence_buffer_objects().


If the lock is dropped anywhere in between we would have list 
corruption again.


Regards,
Christian.


+
  /* One for TTM and one for the CS job */
  amdgpu_bo_list_for_each_entry(e, p->bo_list)
  e->tv.num_shared = 2;
@@ -544,6 +546,7 @@ static int amdgpu_cs_parser_bos(struct 
amdgpu_cs_parser *p,

  if (!e->user_pages) {
  DRM_ERROR("kvmalloc_array failure\n");
  r = -ENOMEM;
+    mutex_unlock(>bo_list->bo_list_mutex);
  goto out_free_user_pages;
  }
  @@ -551,6 +554,7 @@ static int amdgpu_cs_parser_bos(struct 
amdgpu_cs_parser *p,

  if (r) {
  kvfree(e->user_pages);
  e->user_pages = NULL;
+    mutex_unlock(>bo_list->bo_list_mutex);
  goto out_free_user_pages;
  }
  @@ -568,6 +572,7 @@ static int amdgpu_cs_parser_bos(struct 
amdgpu_cs_parser *p,

  if (unlikely(r != 0)) {
  if (r != -ERESTARTSYS)
  DRM_ERROR("ttm_eu_reserve_buffers failed.\n");
+    mutex_unlock(>bo_list->bo_list_mutex);
  goto out_free_user_pages;
  }
  @@ -580,11 +585,14 @@ static int amdgpu_cs_parser_bos(struct 
amdgpu_cs_parser *p,

  e->chain = dma_fence_chain_alloc();
  if (!e->chain) {
  r = -ENOMEM;
+ mutex_unlock(>bo_list->bo_list_mutex);
  goto error_validate;
  }
  }
  }
  +    mutex_unlock(>bo_list->bo_list_mutex);








+
  /* Move fence waiting after getting reservation lock of
   * PD root. Then there is no need on a ctx mutex lock.
   */
@@ -607,6 +615,7 @@ static int amdgpu_cs_parser_bos(struct 
amdgpu_cs_parser *p,

  goto error_validate;
  }
  +    mutex_lock(>bo_list->bo_list_mutex);
  r = 

[PATCH] drm/amdgpu: limit the number of enabled gfx queues

2022-07-14 Thread Lang Yu
The driver can only support AMDGPU_MAX_GFX_RINGS gfx queues
at the moment. Once enabled gfx queues exceed the limit,
we will run into problems when setting up gfx rings in
gfx_xxx_sw_init().

Signed-off-by: Lang Yu 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
index 222d3d7ea076..ae3fe1d0df04 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
@@ -229,8 +229,9 @@ void amdgpu_gfx_graphics_queue_acquire(struct amdgpu_device 
*adev)
 {
int i, queue, pipe;
bool multipipe_policy = amdgpu_gfx_is_graphics_multipipe_capable(adev);
-   int max_queues_per_me = adev->gfx.me.num_pipe_per_me *
-   adev->gfx.me.num_queue_per_pipe;
+   int max_queues_per_me = min(adev->gfx.me.num_pipe_per_me *
+   adev->gfx.me.num_queue_per_pipe,
+   adev->gfx.num_gfx_rings);
 
if (multipipe_policy) {
/* policy: amdgpu owns the first queue per pipe at this stage
-- 
2.25.1