Commit 0a98219
drm/xe/hmm: Don't dereference struct page pointers without notifier lock
The pnfs that we obtain from hmm_range_fault() point to pages that
we don't have a reference on, and the guarantee that they are still
in the cpu page-tables is that the notifier lock must be held and the
notifier seqno is still valid.
So while building the sg table and marking the pages accesses / dirty
we need to hold this lock with a validated seqno.
However, the lock is reclaim tainted which makes
sg_alloc_table_from_pages_segment() unusable, since it internally
allocates memory.
Instead build the sg-table manually. For the non-iommu case
this might lead to fewer coalesces, but if that's a problem it can
be fixed up later in the resource cursor code. For the iommu case,
the whole sg-table may still be coalesced to a single contigous
device va region.
This avoids marking pages that we don't own dirty and accessed, and
it also avoid dereferencing struct pages that we don't own.
v2:
- Use assert to check whether hmm pfns are valid (Matthew Auld)
- Take into account that large pages may cross range boundaries
(Matthew Auld)
v3:
- Don't unnecessarily check for a non-freed sg-table. (Matthew Auld)
- Add a missing up_read() in an error path. (Matthew Auld)
Fixes: 81e058a ("drm/xe: Introduce helper to populate userptr")
Cc: Oak Zeng <oak.zeng@intel.com>
Cc: <stable@vger.kernel.org> # v6.10+
Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Reviewed-by: Matthew Auld <matthew.auld@intel.com>
Acked-by: Matthew Brost <matthew.brost@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20250304173342.22009-3-thomas.hellstrom@linux.intel.com
(cherry picked from commit ea3e66d)
Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>1 parent e3e2e7f commit 0a98219
1 file changed
+86
-26
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
45 | 81 | | |
46 | 82 | | |
47 | 83 | | |
| |||
50 | 86 | | |
51 | 87 | | |
52 | 88 | | |
| 89 | + | |
53 | 90 | | |
54 | 91 | | |
55 | 92 | | |
| |||
76 | 113 | | |
77 | 114 | | |
78 | 115 | | |
79 | | - | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
80 | 119 | | |
| 120 | + | |
81 | 121 | | |
82 | | - | |
83 | | - | |
84 | | - | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
85 | 125 | | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
| 126 | + | |
90 | 127 | | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
95 | 131 | | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
100 | 139 | | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
106 | 146 | | |
| 147 | + | |
107 | 148 | | |
108 | | - | |
109 | | - | |
110 | | - | |
| 149 | + | |
| 150 | + | |
111 | 151 | | |
112 | 152 | | |
113 | 153 | | |
| |||
237 | 277 | | |
238 | 278 | | |
239 | 279 | | |
240 | | - | |
| 280 | + | |
241 | 281 | | |
242 | 282 | | |
243 | 283 | | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
244 | 298 | | |
245 | 299 | | |
246 | 300 | | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
247 | 304 | | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
248 | 309 | | |
249 | 310 | | |
250 | 311 | | |
251 | 312 | | |
252 | | - | |
| |||
0 commit comments