All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Thomas Hellström" <thomas.hellstrom@linux.intel.com>
To: dri-devel@lists.freedesktop.org
Cc: "Thomas Hellström" <thomas.hellstrom@linux.intel.com>,
	"Christian König" <christian.koenig@amd.com>,
	"Daniel Vetter" <daniel.vetter@ffwll.ch>,
	"Huang Rui" <ray.huang@amd.com>,
	"Alex Deucher" <alexander.deucher@amd.com>,
	"Felix Kuehling" <Felix.Kuehling@amd.com>,
	"Philip Yang" <Philip.Yang@amd.com>,
	"Qiang Yu" <qiang.yu@amd.com>,
	"Matthew Auld" <matthew.auld@intel.com>,
	"Nirmoy Das" <nirmoy.das@intel.com>,
	"Tvrtko Ursulin" <tvrtko.ursulin@intel.com>,
	"Anshuman Gupta" <anshuman.gupta@intel.com>,
	"Ramalingam C" <ramalingam.c@intel.com>,
	"Arunpravin Paneer Selvam" <Arunpravin.PaneerSelvam@amd.com>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Matthew Wilcox (Oracle)" <willy@infradead.org>,
	"Miaohe Lin" <linmiaohe@huawei.com>,
	"David Hildenbrand" <david@redhat.com>,
	"Johannes Weiner" <hannes@cmpxchg.org>,
	"Peter Xu" <peterx@redhat.com>, NeilBrown <neilb@suse.de>,
	"Dave Airlie" <airlied@redhat.com>,
	"Dave Hansen" <dave.hansen@intel.com>,
	linux-graphics-maintainer@vmware.com, linux-mm@kvack.org,
	intel-gfx@lists.freedesktop.org
Subject: [RFC PATCH 01/16] drm/ttm: Fix a NULL pointer dereference
Date: Wed, 15 Feb 2023 17:13:50 +0100	[thread overview]
Message-ID: <20230215161405.187368-2-thomas.hellstrom@linux.intel.com> (raw)
In-Reply-To: <20230215161405.187368-1-thomas.hellstrom@linux.intel.com>

The LRU mechanism may look up a resource in the process of being removed
from an object. The locking rules here are a bit unclear but it looks
currently like res->bo assignment is protected by the LRU lock, whereas
bo->resource is protected by the object lock, while *clearing* of
bo->resource is also protected by the LRU lock. This means that if
we check that bo->resource points to the LRU resource under the LRU
lock we should be safe.
So perform that check before deciding to swap out a bo. That avoids
dereferencing a NULL bo->resource in ttm_bo_swapout().

Fixes: 6a9b02899402 ("drm/ttm: move the LRU into resource handling v4")
Cc: Christian König <christian.koenig@amd.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Christian Koenig <christian.koenig@amd.com>
Cc: Huang Rui <ray.huang@amd.com>
Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: Felix Kuehling <Felix.Kuehling@amd.com>
Cc: Philip Yang <Philip.Yang@amd.com>
Cc: Qiang Yu <qiang.yu@amd.com>
Cc: Matthew Auld <matthew.auld@intel.com>
Cc: Nirmoy Das <nirmoy.das@intel.com>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Cc: "Thomas Hellström" <thomas.hellstrom@linux.intel.com>
Cc: Anshuman Gupta <anshuman.gupta@intel.com>
Cc: Ramalingam C <ramalingam.c@intel.com>
Cc: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>
Cc: dri-devel@lists.freedesktop.org
Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
---
 drivers/gpu/drm/ttm/ttm_device.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/ttm/ttm_device.c b/drivers/gpu/drm/ttm/ttm_device.c
index c7a1862f322a..ae2f19dc9f81 100644
--- a/drivers/gpu/drm/ttm/ttm_device.c
+++ b/drivers/gpu/drm/ttm/ttm_device.c
@@ -158,7 +158,7 @@ int ttm_device_swapout(struct ttm_device *bdev, struct ttm_operation_ctx *ctx,
 			struct ttm_buffer_object *bo = res->bo;
 			uint32_t num_pages;
 
-			if (!bo)
+			if (!bo || bo->resource != res)
 				continue;
 
 			num_pages = PFN_UP(bo->base.size);
-- 
2.34.1



WARNING: multiple messages have this Message-ID (diff)
From: "Thomas Hellström" <thomas.hellstrom@linux.intel.com>
To: dri-devel@lists.freedesktop.org
Cc: "Miaohe Lin" <linmiaohe@huawei.com>,
	"Philip Yang" <Philip.Yang@amd.com>, NeilBrown <neilb@suse.de>,
	"Daniel Vetter" <daniel.vetter@ffwll.ch>,
	"Peter Xu" <peterx@redhat.com>,
	linux-mm@kvack.org, "Dave Hansen" <dave.hansen@intel.com>,
	"Huang Rui" <ray.huang@amd.com>,
	"David Hildenbrand" <david@redhat.com>,
	"Matthew Wilcox (Oracle)" <willy@infradead.org>,
	linux-graphics-maintainer@vmware.com,
	"Matthew Auld" <matthew.auld@intel.com>,
	"Ramalingam C" <ramalingam.c@intel.com>,
	"Dave Airlie" <airlied@redhat.com>,
	"Thomas Hellström" <thomas.hellstrom@linux.intel.com>,
	"Arunpravin Paneer Selvam" <Arunpravin.PaneerSelvam@amd.com>,
	"Anshuman Gupta" <anshuman.gupta@intel.com>,
	intel-gfx@lists.freedesktop.org, "Qiang Yu" <qiang.yu@amd.com>,
	"Tvrtko Ursulin" <tvrtko.ursulin@intel.com>,
	"Felix Kuehling" <Felix.Kuehling@amd.com>,
	"Johannes Weiner" <hannes@cmpxchg.org>,
	"Alex Deucher" <alexander.deucher@amd.com>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Christian König" <christian.koenig@amd.com>,
	"Nirmoy Das" <nirmoy.das@intel.com>
Subject: [RFC PATCH 01/16] drm/ttm: Fix a NULL pointer dereference
Date: Wed, 15 Feb 2023 17:13:50 +0100	[thread overview]
Message-ID: <20230215161405.187368-2-thomas.hellstrom@linux.intel.com> (raw)
In-Reply-To: <20230215161405.187368-1-thomas.hellstrom@linux.intel.com>

The LRU mechanism may look up a resource in the process of being removed
from an object. The locking rules here are a bit unclear but it looks
currently like res->bo assignment is protected by the LRU lock, whereas
bo->resource is protected by the object lock, while *clearing* of
bo->resource is also protected by the LRU lock. This means that if
we check that bo->resource points to the LRU resource under the LRU
lock we should be safe.
So perform that check before deciding to swap out a bo. That avoids
dereferencing a NULL bo->resource in ttm_bo_swapout().

Fixes: 6a9b02899402 ("drm/ttm: move the LRU into resource handling v4")
Cc: Christian König <christian.koenig@amd.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Christian Koenig <christian.koenig@amd.com>
Cc: Huang Rui <ray.huang@amd.com>
Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: Felix Kuehling <Felix.Kuehling@amd.com>
Cc: Philip Yang <Philip.Yang@amd.com>
Cc: Qiang Yu <qiang.yu@amd.com>
Cc: Matthew Auld <matthew.auld@intel.com>
Cc: Nirmoy Das <nirmoy.das@intel.com>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Cc: "Thomas Hellström" <thomas.hellstrom@linux.intel.com>
Cc: Anshuman Gupta <anshuman.gupta@intel.com>
Cc: Ramalingam C <ramalingam.c@intel.com>
Cc: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>
Cc: dri-devel@lists.freedesktop.org
Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
---
 drivers/gpu/drm/ttm/ttm_device.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/ttm/ttm_device.c b/drivers/gpu/drm/ttm/ttm_device.c
index c7a1862f322a..ae2f19dc9f81 100644
--- a/drivers/gpu/drm/ttm/ttm_device.c
+++ b/drivers/gpu/drm/ttm/ttm_device.c
@@ -158,7 +158,7 @@ int ttm_device_swapout(struct ttm_device *bdev, struct ttm_operation_ctx *ctx,
 			struct ttm_buffer_object *bo = res->bo;
 			uint32_t num_pages;
 
-			if (!bo)
+			if (!bo || bo->resource != res)
 				continue;
 
 			num_pages = PFN_UP(bo->base.size);
-- 
2.34.1


WARNING: multiple messages have this Message-ID (diff)
From: "Thomas Hellström" <thomas.hellstrom@linux.intel.com>
To: dri-devel@lists.freedesktop.org
Cc: "Miaohe Lin" <linmiaohe@huawei.com>,
	"Philip Yang" <Philip.Yang@amd.com>, NeilBrown <neilb@suse.de>,
	"Daniel Vetter" <daniel.vetter@ffwll.ch>,
	"Peter Xu" <peterx@redhat.com>,
	linux-mm@kvack.org, "Dave Hansen" <dave.hansen@intel.com>,
	"Huang Rui" <ray.huang@amd.com>,
	"David Hildenbrand" <david@redhat.com>,
	"Matthew Wilcox (Oracle)" <willy@infradead.org>,
	linux-graphics-maintainer@vmware.com,
	"Matthew Auld" <matthew.auld@intel.com>,
	"Ramalingam C" <ramalingam.c@intel.com>,
	"Dave Airlie" <airlied@redhat.com>,
	"Thomas Hellström" <thomas.hellstrom@linux.intel.com>,
	"Arunpravin Paneer Selvam" <Arunpravin.PaneerSelvam@amd.com>,
	intel-gfx@lists.freedesktop.org, "Qiang Yu" <qiang.yu@amd.com>,
	"Felix Kuehling" <Felix.Kuehling@amd.com>,
	"Johannes Weiner" <hannes@cmpxchg.org>,
	"Alex Deucher" <alexander.deucher@amd.com>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Christian König" <christian.koenig@amd.com>,
	"Nirmoy Das" <nirmoy.das@intel.com>
Subject: [Intel-gfx] [RFC PATCH 01/16] drm/ttm: Fix a NULL pointer dereference
Date: Wed, 15 Feb 2023 17:13:50 +0100	[thread overview]
Message-ID: <20230215161405.187368-2-thomas.hellstrom@linux.intel.com> (raw)
In-Reply-To: <20230215161405.187368-1-thomas.hellstrom@linux.intel.com>

The LRU mechanism may look up a resource in the process of being removed
from an object. The locking rules here are a bit unclear but it looks
currently like res->bo assignment is protected by the LRU lock, whereas
bo->resource is protected by the object lock, while *clearing* of
bo->resource is also protected by the LRU lock. This means that if
we check that bo->resource points to the LRU resource under the LRU
lock we should be safe.
So perform that check before deciding to swap out a bo. That avoids
dereferencing a NULL bo->resource in ttm_bo_swapout().

Fixes: 6a9b02899402 ("drm/ttm: move the LRU into resource handling v4")
Cc: Christian König <christian.koenig@amd.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Christian Koenig <christian.koenig@amd.com>
Cc: Huang Rui <ray.huang@amd.com>
Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: Felix Kuehling <Felix.Kuehling@amd.com>
Cc: Philip Yang <Philip.Yang@amd.com>
Cc: Qiang Yu <qiang.yu@amd.com>
Cc: Matthew Auld <matthew.auld@intel.com>
Cc: Nirmoy Das <nirmoy.das@intel.com>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Cc: "Thomas Hellström" <thomas.hellstrom@linux.intel.com>
Cc: Anshuman Gupta <anshuman.gupta@intel.com>
Cc: Ramalingam C <ramalingam.c@intel.com>
Cc: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>
Cc: dri-devel@lists.freedesktop.org
Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
---
 drivers/gpu/drm/ttm/ttm_device.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/ttm/ttm_device.c b/drivers/gpu/drm/ttm/ttm_device.c
index c7a1862f322a..ae2f19dc9f81 100644
--- a/drivers/gpu/drm/ttm/ttm_device.c
+++ b/drivers/gpu/drm/ttm/ttm_device.c
@@ -158,7 +158,7 @@ int ttm_device_swapout(struct ttm_device *bdev, struct ttm_operation_ctx *ctx,
 			struct ttm_buffer_object *bo = res->bo;
 			uint32_t num_pages;
 
-			if (!bo)
+			if (!bo || bo->resource != res)
 				continue;
 
 			num_pages = PFN_UP(bo->base.size);
-- 
2.34.1


  reply	other threads:[~2023-02-15 16:14 UTC|newest]

Thread overview: 104+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-15 16:13 [RFC PATCH 00/16] Add a TTM shrinker Thomas Hellström
2023-02-15 16:13 ` [Intel-gfx] " Thomas Hellström
2023-02-15 16:13 ` Thomas Hellström
2023-02-15 16:13 ` Thomas Hellström [this message]
2023-02-15 16:13   ` [Intel-gfx] [RFC PATCH 01/16] drm/ttm: Fix a NULL pointer dereference Thomas Hellström
2023-02-15 16:13   ` Thomas Hellström
2023-02-15 17:25   ` Christian König
2023-02-15 17:25     ` [Intel-gfx] " Christian König
2023-02-15 17:25     ` Christian König
2023-02-15 16:13 ` [RFC PATCH 02/16] drm/ttm/pool: Fix ttm_pool_alloc error path Thomas Hellström
2023-02-15 16:13   ` [Intel-gfx] " Thomas Hellström
2023-02-15 16:13   ` Thomas Hellström
2023-02-15 17:31   ` Christian König
2023-02-15 17:31     ` [Intel-gfx] " Christian König
2023-02-15 17:31     ` Christian König
2023-02-15 18:02     ` Thomas Hellström
2023-02-15 18:02       ` [Intel-gfx] " Thomas Hellström
2023-02-15 18:02       ` Thomas Hellström
2023-02-15 18:26       ` Christian König
2023-02-15 18:26         ` [Intel-gfx] " Christian König
2023-02-15 18:26         ` Christian König
2023-02-15 18:51         ` Thomas Hellström
2023-02-15 18:51           ` [Intel-gfx] " Thomas Hellström
2023-02-15 18:51           ` Thomas Hellström
2023-02-15 16:13 ` [RFC PATCH 03/16] drm/ttm: Use the BIT macro for the TTM_TT_FLAGs Thomas Hellström
2023-02-15 16:13   ` [Intel-gfx] " Thomas Hellström
2023-02-15 16:13   ` Thomas Hellström
2023-02-15 17:33   ` Christian König
2023-02-15 17:33     ` [Intel-gfx] " Christian König
2023-02-15 17:33     ` Christian König
2023-02-15 16:13 ` [RFC PATCH 04/16] drm/ttm, drm/vmwgfx: Update the TTM swapout interface Thomas Hellström
2023-02-15 16:13   ` [Intel-gfx] " Thomas Hellström
2023-02-15 16:13   ` Thomas Hellström
2023-02-15 17:39   ` Christian König
2023-02-15 17:39     ` [Intel-gfx] " Christian König
2023-02-15 17:39     ` Christian König
2023-02-15 18:19     ` Thomas Hellström
2023-02-15 18:19       ` [Intel-gfx] " Thomas Hellström
2023-02-15 18:19       ` Thomas Hellström
2023-02-15 18:32       ` Christian König
2023-02-15 18:32         ` [Intel-gfx] " Christian König
2023-02-15 18:32         ` Christian König
2023-02-15 16:13 ` [RFC PATCH 05/16] drm/ttm: Unexport ttm_global_swapout() Thomas Hellström
2023-02-15 16:13   ` [Intel-gfx] " Thomas Hellström
2023-02-15 16:13   ` Thomas Hellström
2023-02-15 16:13 ` [RFC PATCH 06/16] drm/ttm: Don't use watermark accounting on shrinkable pools Thomas Hellström
2023-02-15 16:13   ` [Intel-gfx] " Thomas Hellström
2023-02-15 16:13   ` Thomas Hellström
2023-02-15 16:13 ` [RFC PATCH 07/16] drm/ttm: Reduce the number of used allocation orders for TTM pages Thomas Hellström
2023-02-15 16:13   ` [Intel-gfx] " Thomas Hellström
2023-02-15 16:13   ` Thomas Hellström
2023-02-15 17:42   ` Christian König
2023-02-15 17:42     ` [Intel-gfx] " Christian König
2023-02-15 17:42     ` Christian König
2023-02-15 18:12     ` Thomas Hellström
2023-02-15 18:12       ` [Intel-gfx] " Thomas Hellström
2023-02-15 18:12       ` Thomas Hellström
2023-02-15 18:30       ` Christian König
2023-02-15 18:30         ` [Intel-gfx] " Christian König
2023-02-15 18:30         ` Christian König
2023-02-15 19:00         ` Thomas Hellström
2023-02-15 19:00           ` [Intel-gfx] " Thomas Hellström
2023-02-15 19:00           ` Thomas Hellström
2023-02-16  7:11           ` Christian König
2023-02-16  7:11             ` [Intel-gfx] " Christian König
2023-02-16  7:11             ` Christian König
2023-02-16  7:24             ` Thomas Hellström
2023-02-16  7:24               ` [Intel-gfx] " Thomas Hellström
2023-02-16  7:24               ` Thomas Hellström
2023-02-15 18:15   ` kernel test robot
2023-02-15 20:07   ` kernel test robot
2023-02-15 16:13 ` [Intel-gfx] [RFC PATCH 08/16] drm/ttm: Add a shrinker and shrinker accounting Thomas Hellström
2023-02-15 16:13   ` Thomas Hellström
2023-02-15 16:13   ` Thomas Hellström
2023-02-15 16:13 ` [RFC PATCH 09/16] drm/ttm: Introduce shrink throttling Thomas Hellström
2023-02-15 16:13   ` [Intel-gfx] " Thomas Hellström
2023-02-15 16:13   ` Thomas Hellström
2023-02-15 16:13 ` [RFC PATCH 10/16] drm/ttm: Remove pinned bos from shrinkable accounting Thomas Hellström
2023-02-15 16:13   ` [Intel-gfx] " Thomas Hellström
2023-02-15 16:13   ` Thomas Hellström
2023-02-15 16:14 ` [RFC PATCH 11/16] drm/ttm: Add a simple api to set / clear purgeable ttm_tt content Thomas Hellström
2023-02-15 16:14   ` [Intel-gfx] " Thomas Hellström
2023-02-15 16:14   ` Thomas Hellström
2023-02-15 16:14 ` [RFC PATCH 12/16] mm: Add interfaces to back up and recover folio contents using swap Thomas Hellström
2023-02-15 16:14   ` [Intel-gfx] " Thomas Hellström
2023-02-15 16:14   ` Thomas Hellström
2023-02-15 16:14 ` [RFC PATCH 13/16] drm/ttm: Make the call to ttm_tt_populate() interruptible when faulting Thomas Hellström
2023-02-15 16:14   ` [Intel-gfx] " Thomas Hellström
2023-02-15 16:14   ` Thomas Hellström
2023-02-15 16:14 ` [RFC PATCH 14/16] drm/ttm: Provide helpers for shrinking Thomas Hellström
2023-02-15 16:14   ` [Intel-gfx] " Thomas Hellström
2023-02-15 16:14   ` Thomas Hellström
2023-02-15 22:00   ` [Intel-gfx] " kernel test robot
2023-02-16  5:41   ` kernel test robot
2023-02-16 16:23   ` kernel test robot
2023-02-15 16:14 ` [RFC PATCH 15/16] drm/ttm: Use fault-injection to test error paths Thomas Hellström
2023-02-15 16:14   ` [Intel-gfx] " Thomas Hellström
2023-02-15 16:14   ` Thomas Hellström
2023-02-15 16:14 ` [RFC PATCH 16/16] drm/i915, drm/ttm: Use the TTM shrinker rather than the external shmem pool Thomas Hellström
2023-02-15 16:14   ` [Intel-gfx] " Thomas Hellström
2023-02-15 16:14   ` Thomas Hellström
2023-02-15 19:31 ` [Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for Add a TTM shrinker Patchwork
2023-02-15 19:58 ` [Intel-gfx] ✓ Fi.CI.BAT: success " Patchwork
2023-02-16 15:34 ` [Intel-gfx] ✗ Fi.CI.IGT: failure " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230215161405.187368-2-thomas.hellstrom@linux.intel.com \
    --to=thomas.hellstrom@linux.intel.com \
    --cc=Arunpravin.PaneerSelvam@amd.com \
    --cc=Felix.Kuehling@amd.com \
    --cc=Philip.Yang@amd.com \
    --cc=airlied@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=alexander.deucher@amd.com \
    --cc=anshuman.gupta@intel.com \
    --cc=christian.koenig@amd.com \
    --cc=daniel.vetter@ffwll.ch \
    --cc=dave.hansen@intel.com \
    --cc=david@redhat.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=hannes@cmpxchg.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=linmiaohe@huawei.com \
    --cc=linux-graphics-maintainer@vmware.com \
    --cc=linux-mm@kvack.org \
    --cc=matthew.auld@intel.com \
    --cc=neilb@suse.de \
    --cc=nirmoy.das@intel.com \
    --cc=peterx@redhat.com \
    --cc=qiang.yu@amd.com \
    --cc=ramalingam.c@intel.com \
    --cc=ray.huang@amd.com \
    --cc=tvrtko.ursulin@intel.com \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.