[PATCH v2 2/2] drm/i915/selftests: Convert atomic_* API calls for i915_active.count refcount_*

2022-12-24 Thread Deepak R Varma
Handle the struct i915_active member variable count transition from
atomic_t type to refcount_t type for selftest use cases. Transition the
atomic_*() API calls to their equivalent refcount_*() API calls.

Reported-by: kernel test robot 
Signed-off-by: Deepak R Varma 
---
Please note:
   1. Proposed changes are compile tested only.
   2. This patch 2/2 is required to be applied after patch 1/2 due to
  inter dependency.

Changes in v2:
   1. Patch added to patch series.
   2. Handle build issues Reported-by: kernel test robot 
  Include changes for i915/selftests use cases for atomic_* to refcount_*
  transition.


 drivers/gpu/drm/i915/selftests/i915_active.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/i915/selftests/i915_active.c 
b/drivers/gpu/drm/i915/selftests/i915_active.c
index b61fe850e924..f1eca59e0180 100644
--- a/drivers/gpu/drm/i915/selftests/i915_active.c
+++ b/drivers/gpu/drm/i915/selftests/i915_active.c
@@ -125,9 +125,9 @@ __live_active_setup(struct drm_i915_private *i915)
pr_err("i915_active retired before submission!\n");
err = -EINVAL;
}
-   if (atomic_read(&active->base.count) != count) {
+   if (refcount_read(&active->base.count) != count) {
pr_err("i915_active not tracking all requests, found %d, 
expected %d\n",
-  atomic_read(&active->base.count), count);
+  refcount_read(&active->base.count), count);
err = -EINVAL;
}

@@ -279,7 +279,7 @@ static struct intel_engine_cs *node_to_barrier(struct 
active_node *it)
 void i915_active_print(struct i915_active *ref, struct drm_printer *m)
 {
drm_printf(m, "active %ps:%ps\n", ref->active, ref->retire);
-   drm_printf(m, "\tcount: %d\n", atomic_read(&ref->count));
+   drm_printf(m, "\tcount: %d\n", refcount_read(&ref->count));
drm_printf(m, "\tpreallocated barriers? %s\n",
   str_yes_no(!llist_empty(&ref->preallocated_barriers)));

@@ -324,7 +324,7 @@ static void active_flush(struct i915_active *ref,
spin_lock_irq(fence->lock);
__list_del_entry(&active->cb.node);
spin_unlock_irq(fence->lock); /* serialise with fence->cb_list */
-   atomic_dec(&ref->count);
+   refcount_dec(&ref->count);

GEM_BUG_ON(!test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags));
 }
--
2.34.1





[PATCH v2 1/2] drm/i915: convert i915_active.count from atomic_t to refcount_t

2022-12-24 Thread Deepak R Varma
The refcount_* APIs are designed to address known issues with the
atomic_t APIs for reference counting. They provide following distinct
advantages:
   - protect the reference counters from overflow/underflow
   - avoid use-after-free errors
   - provide improved memory ordering guarantee schemes
   - neater and safer.
Hence, convert the atomic_t count member variable and associated
atomic_*() API calls to equivalent refcount_t type and refcount_*() API
calls.

This patch proposal address the following warnings generated by
the atomic_as_refcounter.cocci coccinelle script
atomic_add_unless

Signed-off-by: Deepak R Varma 
---
Please note:
   1. Proposed changes are compile tested only.
   2. This patch 1/2 is required to be applied before patch 2/2 due to
  interdependency.

Changes in v2:
   1. Patch added to the patch series.
   2. Handle build issues Reported-by: kernel test robot 
  Earlier a standalone patch was sent for the i915 base driver only. The
  Kernel Test Robot reported build failure for additional atomic_*() calls
  specific to i915 debugging support when enabled. This version now includes
  those changes as well.


 drivers/gpu/drm/i915/i915_active.c   | 28 +---
 drivers/gpu/drm/i915/i915_active.h   |  6 ++---
 drivers/gpu/drm/i915/i915_active_types.h |  4 ++--
 3 files changed, 20 insertions(+), 18 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_active.c 
b/drivers/gpu/drm/i915/i915_active.c
index 7412abf166a8..5e58d8b1e947 100644
--- a/drivers/gpu/drm/i915/i915_active.c
+++ b/drivers/gpu/drm/i915/i915_active.c
@@ -92,14 +92,14 @@ static void debug_active_init(struct i915_active *ref)
 static void debug_active_activate(struct i915_active *ref)
 {
lockdep_assert_held(&ref->tree_lock);
-   if (!atomic_read(&ref->count)) /* before the first inc */
+   if (!refcount_read(&ref->count)) /* before the first inc */
debug_object_activate(ref, &active_debug_desc);
 }

 static void debug_active_deactivate(struct i915_active *ref)
 {
lockdep_assert_held(&ref->tree_lock);
-   if (!atomic_read(&ref->count)) /* after the last dec */
+   if (!refcount_read(&ref->count)) /* after the last dec */
debug_object_deactivate(ref, &active_debug_desc);
 }

@@ -133,7 +133,7 @@ __active_retire(struct i915_active *ref)
GEM_BUG_ON(i915_active_is_idle(ref));

/* return the unused nodes to our slabcache -- flushing the allocator */
-   if (!atomic_dec_and_lock_irqsave(&ref->count, &ref->tree_lock, flags))
+   if (!refcount_dec_and_lock_irqsave(&ref->count, &ref->tree_lock, 
&flags))
return;

GEM_BUG_ON(rcu_access_pointer(ref->excl.fence));
@@ -179,8 +179,8 @@ active_work(struct work_struct *wrk)
 {
struct i915_active *ref = container_of(wrk, typeof(*ref), work);

-   GEM_BUG_ON(!atomic_read(&ref->count));
-   if (atomic_add_unless(&ref->count, -1, 1))
+   GEM_BUG_ON(!refcount_read(&ref->count));
+   if (refcount_dec_not_one(&ref->count))
return;

__active_retire(ref);
@@ -189,8 +189,8 @@ active_work(struct work_struct *wrk)
 static void
 active_retire(struct i915_active *ref)
 {
-   GEM_BUG_ON(!atomic_read(&ref->count));
-   if (atomic_add_unless(&ref->count, -1, 1))
+   GEM_BUG_ON(!refcount_read(&ref->count));
+   if (refcount_dec_not_one(&ref->count))
return;

if (ref->flags & I915_ACTIVE_RETIRE_SLEEPS) {
@@ -354,7 +354,7 @@ void __i915_active_init(struct i915_active *ref,
ref->cache = NULL;

init_llist_head(&ref->preallocated_barriers);
-   atomic_set(&ref->count, 0);
+   refcount_set(&ref->count, 0);
__mutex_init(&ref->mutex, "i915_active", mkey);
__i915_active_fence_init(&ref->excl, NULL, excl_retire);
INIT_WORK(&ref->work, active_work);
@@ -445,7 +445,7 @@ int i915_active_add_request(struct i915_active *ref, struct 
i915_request *rq)

if (replace_barrier(ref, active)) {
RCU_INIT_POINTER(active->fence, NULL);
-   atomic_dec(&ref->count);
+   refcount_dec(&ref->count);
}
if (!__i915_active_fence_set(active, fence))
__i915_active_acquire(ref);
@@ -488,14 +488,16 @@ i915_active_set_exclusive(struct i915_active *ref, struct 
dma_fence *f)
 bool i915_active_acquire_if_busy(struct i915_active *ref)
 {
debug_active_assert(ref);
-   return atomic_add_unless(&ref->count, 1, 0);
+   return refcount_add_not_zero(1, &ref->count);
 }

 static void __i915_active_activate(struct i915_active *ref)
 {
spin_lock_irq(&ref->tree_lock); /* __active_retire() */
-   if (!atomic_fetch_inc(&ref->count))
+   if (!refcount_inc_not_zero(&ref->count)) {
+   refcount_inc(&ref->count);
debug_active_activate(ref);
+   }
spin_unlock_irq(&ref->tree_lock);
 }

@@ -757,7 +759,7 @@ int i915_sw_fence_

[PATCH v2 0/2] convert i915_active.count from atomic_t to refcount_t

2022-12-24 Thread Deepak R Varma
Transition the reference count member variable count of struct i915_active from
atomic_t type to refcount_t type. This proposal is based on issues identified
using the atomic_as_refcounter.cocci Coccinelle semantic patch script.

Patch 1/2: proposes to convert the base implementation of variable count from
   atomic_t to refcount_t. This also includes the transition of
   atomic_*() API calls to their equivalent refcount_*() API calls.

Patch 2/2: proposes to transition the atomic_*() API calls in i915 selftest
   use cases to their equivalent refcount_*() API calls.

Please Note:
   1. Patch 1/2 should be applied before patch 2/2 due to interdependency.
   2. I did not enable to the selftest and debug configurations earlier while
  building the i915 base driver. With the build failures reported by the
  Kernel Test Robot, I have now included those changes. I did not find any
  other configurations that required additional atomic_* API call transition
  for this member variable of struct i915_active. Please let me know if 
there
  are other related disabled configurations that I should be enable for
  additional code coverage.
   3. Any guidance on working with i915/selftests would be very helpful for my
  learning.

Changes in v2:
   1. Patch series introduced.
   2. Handle build issues Reported-by: kernel test robot 
  Earlier a standalone patch was sent for the i915 base driver only. The
  Kernel Test Robot reported failure for additional atomic_*() calls 
specific
  to i915 debugging support when enabled. This version now includes those
  changes as well.
   3. Handle build issues Reported-by: kernel test robot  for 
i915/selftests
  Include changes for i915/selftests use cases for atomic_* to refcount_*
  transition.


Deepak R Varma (2):
  drm/i915: convert i915_active.count from atomic_t to refcount_t
  drm/i915/selftests: Convert atomic_* API calls for i915_active.count
refcount_*

 drivers/gpu/drm/i915/i915_active.c   | 28 +++-
 drivers/gpu/drm/i915/i915_active.h   |  6 ++---
 drivers/gpu/drm/i915/i915_active_types.h |  4 +--
 drivers/gpu/drm/i915/selftests/i915_active.c |  8 +++---
 4 files changed, 24 insertions(+), 22 deletions(-)

--
2.34.1





Re: [PATCH] drm/i915: convert i915_active.count from atomic_t to refcount_t

2022-12-24 Thread kernel test robot
Hi Deepak,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on drm-intel/for-linux-next]
[also build test ERROR on drm-intel/for-linux-next-fixes linus/master v6.1 
next-20221220]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:
https://github.com/intel-lab-lkp/linux/commits/Deepak-R-Varma/drm-i915-convert-i915_active-count-from-atomic_t-to-refcount_t/20221225-055105
base:   git://anongit.freedesktop.org/drm-intel for-linux-next
patch link:https://lore.kernel.org/r/Y6d0EDmyqJILVoRw%40qemulion
patch subject: [PATCH] drm/i915: convert i915_active.count from atomic_t to 
refcount_t
config: x86_64-randconfig-c002
compiler: gcc-11 (Debian 11.3.0-8) 11.3.0
reproduce (this is a W=1 build):
# 
https://github.com/intel-lab-lkp/linux/commit/04a191f9a3d0f02bbd37735a47401bc92d685234
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review 
Deepak-R-Varma/drm-i915-convert-i915_active-count-from-atomic_t-to-refcount_t/20221225-055105
git checkout 04a191f9a3d0f02bbd37735a47401bc92d685234
# save the config file
mkdir build_dir && cp config build_dir/.config
make W=1 O=build_dir ARCH=x86_64 olddefconfig
make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash drivers/gpu/drm/i915/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot 

All errors (new ones prefixed by >>):

   drivers/gpu/drm/i915/i915_active.c: In function 'debug_active_activate':
>> drivers/gpu/drm/i915/i915_active.c:95:26: error: passing argument 1 of 
>> 'atomic_read' from incompatible pointer type 
>> [-Werror=incompatible-pointer-types]
  95 | if (!atomic_read(&ref->count)) /* before the first inc */
 |  ^~~
 |  |
 |  refcount_t * {aka struct refcount_struct *}
   In file included from include/linux/atomic.h:82,
from include/linux/jump_label.h:254,
from include/linux/static_key.h:1,
from arch/x86/include/asm/nospec-branch.h:6,
from arch/x86/include/asm/paravirt_types.h:40,
from arch/x86/include/asm/ptrace.h:97,
from arch/x86/include/asm/math_emu.h:5,
from arch/x86/include/asm/processor.h:13,
from arch/x86/include/asm/cpufeature.h:5,
from arch/x86/include/asm/thread_info.h:53,
from include/linux/thread_info.h:60,
from arch/x86/include/asm/preempt.h:7,
from include/linux/preempt.h:78,
from include/linux/spinlock.h:56,
from include/linux/debugobjects.h:6,
from drivers/gpu/drm/i915/i915_active.c:7:
   include/linux/atomic/atomic-instrumented.h:25:29: note: expected 'const 
atomic_t *' but argument is of type 'refcount_t *' {aka 'struct refcount_struct 
*'}
  25 | atomic_read(const atomic_t *v)
 | ^
   drivers/gpu/drm/i915/i915_active.c: In function 'debug_active_deactivate':
   drivers/gpu/drm/i915/i915_active.c:102:26: error: passing argument 1 of 
'atomic_read' from incompatible pointer type 
[-Werror=incompatible-pointer-types]
 102 | if (!atomic_read(&ref->count)) /* after the last dec */
 |  ^~~
 |  |
 |  refcount_t * {aka struct refcount_struct *}
   In file included from include/linux/atomic.h:82,
from include/linux/jump_label.h:254,
from include/linux/static_key.h:1,
from arch/x86/include/asm/nospec-branch.h:6,
from arch/x86/include/asm/paravirt_types.h:40,
from arch/x86/include/asm/ptrace.h:97,
from arch/x86/include/asm/math_emu.h:5,
from arch/x86/include/asm/processor.h:13,
from arch/x86/include/asm/cpufeature.h:5,
from arch/x86/include/asm/thread_info.h:53,
from include/linux/thread_info.h:60,
from arch/x86/include/asm/preempt.h:7,
from include/linux/preempt.h:78,
from include/linux/spinlock.h:56,
from include/linux/debugobjects.h:6,
from drivers/gpu/drm/i915/i915_active.c:7:
   include/linux/atomic/atomic-instrumented.h:25:29: note: expected 'const 
atomic_t *' but argument is of type 'refcount_t *' {aka 'struct refcount_struct 
*'}
  25 | atomic_read(const atomic_t *v)
 | ^
   cc1: all warnings being treated a

Re: [PATCH v2 3/9] drm/print: Fix support for NULL as first argument of drm_dbg_*

2022-12-24 Thread kernel test robot
Hi Siddh,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on next-20221220]
[also build test WARNING on linus/master]
[cannot apply to drm-misc/drm-misc-next v6.1 v6.1-rc8 v6.1-rc7 v6.1]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:
https://github.com/intel-lab-lkp/linux/commits/Siddh-Raman-Pant/drm-Remove-usage-of-deprecated-DRM_INFO/20221222-235336
patch link:
https://lore.kernel.org/r/cd397a877b94ec8062440e3ae6a6a4f1af82d854.1671723195.git.code%40siddh.me
patch subject: [PATCH v2 3/9] drm/print: Fix support for NULL as first argument 
of drm_dbg_*
reproduce:
# 
https://github.com/intel-lab-lkp/linux/commit/5b7a52481bf09de1326e265c6a8024de14cfc01a
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review 
Siddh-Raman-Pant/drm-Remove-usage-of-deprecated-DRM_INFO/20221222-235336
git checkout 5b7a52481bf09de1326e265c6a8024de14cfc01a
make menuconfig
# enable CONFIG_COMPILE_TEST, CONFIG_WARN_MISSING_DOCUMENTS, 
CONFIG_WARN_ABI_ERRORS
make htmldocs

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot 

All warnings (new ones prefixed by >>):

>> Documentation/gpu/drm-internals:194: ./include/drm/drm_print.h:459: WARNING: 
>> Inline emphasis start-string without end-string.

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp
#
# Automatically generated file; DO NOT EDIT.
# Linux/x86_64 6.1.0 Kernel Configuration
#
CONFIG_CC_VERSION_TEXT="gcc-11 (Debian 11.3.0-8) 11.3.0"
CONFIG_CC_IS_GCC=y
CONFIG_GCC_VERSION=110300
CONFIG_CLANG_VERSION=0
CONFIG_AS_IS_GNU=y
CONFIG_AS_VERSION=23900
CONFIG_LD_IS_BFD=y
CONFIG_LD_VERSION=23900
CONFIG_LLD_VERSION=0
CONFIG_CC_CAN_LINK=y
CONFIG_CC_CAN_LINK_STATIC=y
CONFIG_CC_HAS_ASM_GOTO_OUTPUT=y
CONFIG_CC_HAS_ASM_GOTO_TIED_OUTPUT=y
CONFIG_CC_HAS_ASM_INLINE=y
CONFIG_CC_HAS_NO_PROFILE_FN_ATTR=y
CONFIG_PAHOLE_VERSION=123
CONFIG_IRQ_WORK=y
CONFIG_BUILDTIME_TABLE_SORT=y
CONFIG_THREAD_INFO_IN_TASK=y

#
# General setup
#
CONFIG_BROKEN_ON_SMP=y
CONFIG_INIT_ENV_ARG_LIMIT=32
CONFIG_COMPILE_TEST=y
# CONFIG_WERROR is not set
CONFIG_LOCALVERSION=""
CONFIG_BUILD_SALT=""
CONFIG_HAVE_KERNEL_GZIP=y
CONFIG_HAVE_KERNEL_BZIP2=y
CONFIG_HAVE_KERNEL_LZMA=y
CONFIG_HAVE_KERNEL_XZ=y
CONFIG_HAVE_KERNEL_LZO=y
CONFIG_HAVE_KERNEL_LZ4=y
CONFIG_HAVE_KERNEL_ZSTD=y
CONFIG_KERNEL_GZIP=y
# CONFIG_KERNEL_BZIP2 is not set
# CONFIG_KERNEL_LZMA is not set
# CONFIG_KERNEL_XZ is not set
# CONFIG_KERNEL_LZO is not set
# CONFIG_KERNEL_LZ4 is not set
# CONFIG_KERNEL_ZSTD is not set
CONFIG_DEFAULT_INIT=""
CONFIG_DEFAULT_HOSTNAME="(none)"
# CONFIG_SYSVIPC is not set
# CONFIG_WATCH_QUEUE is not set
# CONFIG_CROSS_MEMORY_ATTACH is not set
# CONFIG_USELIB is not set
CONFIG_HAVE_ARCH_AUDITSYSCALL=y

#
# IRQ subsystem
#
CONFIG_GENERIC_IRQ_PROBE=y
CONFIG_GENERIC_IRQ_SHOW=y
CONFIG_HARDIRQS_SW_RESEND=y
CONFIG_IRQ_DOMAIN=y
CONFIG_IRQ_DOMAIN_HIERARCHY=y
CONFIG_GENERIC_IRQ_MATRIX_ALLOCATOR=y
CONFIG_GENERIC_IRQ_RESERVATION_MODE=y
CONFIG_IRQ_FORCED_THREADING=y
CONFIG_SPARSE_IRQ=y
# end of IRQ subsystem

CONFIG_CLOCKSOURCE_WATCHDOG=y
CONFIG_ARCH_CLOCKSOURCE_INIT=y
CONFIG_CLOCKSOURCE_VALIDATE_LAST_CYCLE=y
CONFIG_GENERIC_TIME_VSYSCALL=y
CONFIG_GENERIC_CLOCKEVENTS=y
CONFIG_GENERIC_CLOCKEVENTS_BROADCAST=y
CONFIG_GENERIC_CLOCKEVENTS_MIN_ADJUST=y
CONFIG_GENERIC_CMOS_UPDATE=y
CONFIG_HAVE_POSIX_CPU_TIMERS_TASK_WORK=y
CONFIG_POSIX_CPU_TIMERS_TASK_WORK=y

#
# Timers subsystem
#
CONFIG_HZ_PERIODIC=y
# CONFIG_NO_HZ_IDLE is not set
# CONFIG_NO_HZ is not set
# CONFIG_HIGH_RES_TIMERS is not set
CONFIG_CLOCKSOURCE_WATCHDOG_MAX_SKEW_US=100
# end of Timers subsystem

CONFIG_HAVE_EBPF_JIT=y
CONFIG_ARCH_WANT_DEFAULT_BPF_JIT=y

#
# BPF subsystem
#
# CONFIG_BPF_SYSCALL is not set
# end of BPF subsystem

CONFIG_PREEMPT_NONE_BUILD=y
CONFIG_PREEMPT_NONE=y
# CONFIG_PREEMPT_VOLUNTARY is not set
# CONFIG_PREEMPT is not set
# CONFIG_PREEMPT_DYNAMIC is not set

#
# CPU/Task time and stats accounting
#
CONFIG_TICK_CPU_ACCOUNTING=y
# CONFIG_VIRT_CPU_ACCOUNTING_GEN is not set
# CONFIG_IRQ_TIME_ACCOUNTING is not set
# CONFIG_BSD_PROCESS_ACCT is not set
# CONFIG_PSI is not set
# end of CPU/Task time and stats accounting

CONFIG_CPU_ISOLATION=y

#
# RCU Subsystem
#
CONFIG_TINY_RCU=y
# CONFIG_RCU_EXPERT is not set
CONFIG_SRCU=y
CONFIG_TINY_SRCU=y
# end of RCU Subsystem

# CONFIG_IKCONFIG is not set
# CONFIG_IKHEADERS is not set
CONFIG_LOG_BUF_SHIFT=17
CONFIG_PRINTK_SAFE_LOG_BUF_SHIFT=13
CONFIG_HAVE_UNSTABLE_SCHED_CLOCK=y

#
# Scheduler features
#
# end of Scheduler features

CONFIG_ARCH_SUPPORTS_NUMA_BALANCING=y
CONFIG_ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH=y
CONFIG_CC_HAS_INT128=y
CONFIG_CC_IMPLICIT_FALLTHROUGH="-Wimplicit-fallthrough=5"
CONFIG_GCC12_NO_ARRAY_BOUNDS=y
CONFIG_ARCH_SUPPORTS_INT128=y
# CONFIG_CGROUPS is not set
CONFIG_NAMES

[PATCH] drm/i915: convert i915_active.count from atomic_t to refcount_t

2022-12-24 Thread Deepak R Varma
The refcount_* APIs are designed to address known issues with the
atomic_t APIs for reference counting. They provide following distinct
advantages:
   - protect the reference counters from overflow/underflow
   - avoid use-after-free errors
   - provide improved memory ordering guarantee schemes
   - neater and safer.
Hence, convert the atomic_t count member variable and associated
atomic_*() API calls to equivalent refcount_t type and refcount_*() API
calls.

This patch proposal address the following warnings generated by
the atomic_as_refcounter.cocci coccinelle script
atomic_add_unless

Signed-off-by: Deepak R Varma 
---
Please note: Proposed changes are compile tested only.

 drivers/gpu/drm/i915/i915_active.c   | 24 +---
 drivers/gpu/drm/i915/i915_active.h   |  6 +++---
 drivers/gpu/drm/i915/i915_active_types.h |  4 ++--
 3 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_active.c 
b/drivers/gpu/drm/i915/i915_active.c
index 7412abf166a8..4a8d873b4347 100644
--- a/drivers/gpu/drm/i915/i915_active.c
+++ b/drivers/gpu/drm/i915/i915_active.c
@@ -133,7 +133,7 @@ __active_retire(struct i915_active *ref)
GEM_BUG_ON(i915_active_is_idle(ref));

/* return the unused nodes to our slabcache -- flushing the allocator */
-   if (!atomic_dec_and_lock_irqsave(&ref->count, &ref->tree_lock, flags))
+   if (!refcount_dec_and_lock_irqsave(&ref->count, &ref->tree_lock, 
&flags))
return;

GEM_BUG_ON(rcu_access_pointer(ref->excl.fence));
@@ -179,8 +179,8 @@ active_work(struct work_struct *wrk)
 {
struct i915_active *ref = container_of(wrk, typeof(*ref), work);

-   GEM_BUG_ON(!atomic_read(&ref->count));
-   if (atomic_add_unless(&ref->count, -1, 1))
+   GEM_BUG_ON(!refcount_read(&ref->count));
+   if (refcount_dec_not_one(&ref->count))
return;

__active_retire(ref);
@@ -189,8 +189,8 @@ active_work(struct work_struct *wrk)
 static void
 active_retire(struct i915_active *ref)
 {
-   GEM_BUG_ON(!atomic_read(&ref->count));
-   if (atomic_add_unless(&ref->count, -1, 1))
+   GEM_BUG_ON(!refcount_read(&ref->count));
+   if (refcount_dec_not_one(&ref->count))
return;

if (ref->flags & I915_ACTIVE_RETIRE_SLEEPS) {
@@ -354,7 +354,7 @@ void __i915_active_init(struct i915_active *ref,
ref->cache = NULL;

init_llist_head(&ref->preallocated_barriers);
-   atomic_set(&ref->count, 0);
+   refcount_set(&ref->count, 0);
__mutex_init(&ref->mutex, "i915_active", mkey);
__i915_active_fence_init(&ref->excl, NULL, excl_retire);
INIT_WORK(&ref->work, active_work);
@@ -445,7 +445,7 @@ int i915_active_add_request(struct i915_active *ref, struct 
i915_request *rq)

if (replace_barrier(ref, active)) {
RCU_INIT_POINTER(active->fence, NULL);
-   atomic_dec(&ref->count);
+   refcount_dec(&ref->count);
}
if (!__i915_active_fence_set(active, fence))
__i915_active_acquire(ref);
@@ -488,14 +488,16 @@ i915_active_set_exclusive(struct i915_active *ref, struct 
dma_fence *f)
 bool i915_active_acquire_if_busy(struct i915_active *ref)
 {
debug_active_assert(ref);
-   return atomic_add_unless(&ref->count, 1, 0);
+   return refcount_add_not_zero(1, &ref->count);
 }

 static void __i915_active_activate(struct i915_active *ref)
 {
spin_lock_irq(&ref->tree_lock); /* __active_retire() */
-   if (!atomic_fetch_inc(&ref->count))
+   if (!refcount_inc_not_zero(&ref->count)) {
+   refcount_inc(&ref->count);
debug_active_activate(ref);
+   }
spin_unlock_irq(&ref->tree_lock);
 }

@@ -757,7 +759,7 @@ int i915_sw_fence_await_active(struct i915_sw_fence *fence,
 void i915_active_fini(struct i915_active *ref)
 {
debug_active_fini(ref);
-   GEM_BUG_ON(atomic_read(&ref->count));
+   GEM_BUG_ON(refcount_read(&ref->count));
GEM_BUG_ON(work_pending(&ref->work));
mutex_destroy(&ref->mutex);

@@ -927,7 +929,7 @@ int i915_active_acquire_preallocate_barrier(struct 
i915_active *ref,

first = first->next;

-   atomic_dec(&ref->count);
+   refcount_dec(&ref->count);
intel_engine_pm_put(barrier_to_engine(node));

kmem_cache_free(slab_cache, node);
diff --git a/drivers/gpu/drm/i915/i915_active.h 
b/drivers/gpu/drm/i915/i915_active.h
index 7eb44132183a..116c7c28466a 100644
--- a/drivers/gpu/drm/i915/i915_active.h
+++ b/drivers/gpu/drm/i915/i915_active.h
@@ -193,14 +193,14 @@ void i915_active_release(struct i915_active *ref);

 static inline void __i915_active_acquire(struct i915_active *ref)
 {
-   GEM_BUG_ON(!atomic_read(&ref->count));
-   atomic_inc(&ref->count);
+   GEM_BUG_ON(!refcount_read(&ref->count));
+   refcount_inc(&ref->count);
 }

 static inline bool
 i915_a

[Bug 216840] AMDGPU trace message at boot

2022-12-24 Thread bugzilla-daemon
https://bugzilla.kernel.org/show_bug.cgi?id=216840

Artem S. Tashkinov (a...@gmx.com) changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution|--- |ANSWERED

--- Comment #1 from Artem S. Tashkinov (a...@gmx.com) ---
Please look for dupes and if there are none file a new bug report here,

https://gitlab.freedesktop.org/drm/amd/-/issues

Thanks!

-- 
You may reply to this email to add a comment.

You are receiving this mail because:
You are watching the assignee of the bug.

Re: [PATCH 0/2] Recover from failure to probe GPU

2022-12-24 Thread Thomas Zimmermann

Hi

Am 22.12.22 um 19:30 schrieb Mario Limonciello:

One of the first thing that KMS drivers do during initialization is
destroy the system firmware framebuffer by means of
`drm_aperture_remove_conflicting_pci_framebuffers`

This means that if for any reason the GPU failed to probe the user
will be stuck with at best a screen frozen at the last thing that
was shown before the KMS driver continued it's probe.

The problem is most pronounced when new GPU support is introduced
because users will need to have a recent linux-firmware snapshot
on their system when they boot a kernel with matching support.

However the problem is further exaggerated in the case of amdgpu because
it has migrated to "IP discovery" where amdgpu will attempt to load
on "ALL" AMD GPUs even if the driver is missing support for IP blocks
contained in that GPU.

IP discovery requires some probing and isn't run until after the
framebuffer has been destroyed.

This means a situation can occur where a user purchases a new GPU not
yet supported by a distribution and when booting the installer it will
"freeze" even if the distribution doesn't have the matching kernel support
for those IP blocks.

The perfect example of this is Ubuntu 21.10 and the new dGPUs just
launched by AMD.  The installation media ships with kernel 5.19 (which
has IP discovery) but the amdgpu support for those IP blocks landed in
kernel 6.0. The matching linux-firmware was released after 21.10's launch.
The screen will freeze without nomodeset. Even if a user manages to install
and then upgrades to kernel 6.0 after install they'll still have the
problem of missing firmware, and the same experience.

This is quite jarring for users, particularly if they don't know
that they have to use "nomodeset" to install.

To help the situation, allow drivers to re-run the init process for the
firmware framebuffer during a failed probe. As this problem is most
pronounced with amdgpu, this is the only driver changed.

But if this makes sense more generally for other KMS drivers, the call
can be added to the cleanup routine for those too.


Just a quick drive-by comment: as Javier noted, at some point while 
probing, your driver has changed the device' state and the system FB 
will be gone. you cannot reestablish the sysfb after that.


You are, however free to read device state at any time, as long as it 
has no side effects.


So why not just move the call to 
drm_aperture_remove_conflicting_pci_framebuffers() to a later point when 
you know that your driver supports the hardware? That's the solution we 
always proposed to this kind of problem. It's safe and won't require any 
changes to the aperture helpers.


Best regards
Thomas



Here is a sample of what happens with missing GPU firmware and this
series:

[5.950056] amdgpu :63:00.0: vgaarb: deactivate vga console
[5.950114] amdgpu :63:00.0: enabling device (0006 -> 0007)
[5.950883] [drm] initializing kernel modesetting (YELLOW_CARP 0x1002:0x1681 
0x17AA:0x22F1 0xD2).
[5.952954] [drm] register mmio base: 0xB0A0
[5.952958] [drm] register mmio size: 524288
[5.954633] [drm] add ip block number 0 
[5.954636] [drm] add ip block number 1 
[5.954637] [drm] add ip block number 2 
[5.954638] [drm] add ip block number 3 
[5.954639] [drm] add ip block number 4 
[5.954641] [drm] add ip block number 5 
[5.954642] [drm] add ip block number 6 
[5.954643] [drm] add ip block number 7 
[5.954644] [drm] add ip block number 8 
[5.954645] [drm] add ip block number 9 
[5.954663] amdgpu :63:00.0: amdgpu: Fetched VBIOS from VFCT
[5.954666] amdgpu: ATOM BIOS: 113-REMBRANDT-X37
[5.954677] [drm] VCN(0) decode is enabled in VM mode
[5.954678] [drm] VCN(0) encode is enabled in VM mode
[5.954680] [drm] JPEG decode is enabled in VM mode
[5.954681] amdgpu :63:00.0: amdgpu: Trusted Memory Zone (TMZ) feature 
disabled as experimental (default)
[5.954683] amdgpu :63:00.0: amdgpu: PCIE atomic ops is not supported
[5.954724] [drm] vm size is 262144 GB, 4 levels, block size is 9-bit, 
fragment size is 9-bit
[5.954732] amdgpu :63:00.0: amdgpu: VRAM: 512M 0x00F4 - 
0x00F41FFF (512M used)
[5.954735] amdgpu :63:00.0: amdgpu: GART: 1024M 0x - 
0x3FFF
[5.954738] amdgpu :63:00.0: amdgpu: AGP: 267419648M 0x00F8 
- 0x
[5.954747] [drm] Detected VRAM RAM=512M, BAR=512M
[5.954750] [drm] RAM width 256bits LPDDR5
[5.954834] [drm] amdgpu: 512M of VRAM memory ready
[5.954838] [drm] amdgpu: 15680M of GTT memory ready.
[5.954873] [drm] GART: num cpu pages 262144, num gpu pages 262144
[5.955333] [drm] PCIE GART of 1024M enabled (table at 0x00F41FC0).
[5.955502] amdgpu :63:00.0: Direct firmware load for 
amdgpu/yellow_carp_toc.bin failed with error -2
[5.955505] amdgpu :63:00.0: amdgpu: fail to request/validate toc 
microcode
[