Compare

803aa6fc2dbea25ab9d3ed19eca1c96d0ab17445..55a67aa89342545b89f469dea6f29bfb6fac6f3d

drm/amd/display: Fix NULL sink dereference in USB4 bandwidth functions

allocate_usb4_bandwidth_for_stream() and allocate_usb4_bandwidth() both
use ASSERT(stream->sink) before dereferencing stream->sink->link. ASSERT
is compiled out in production builds, so a NULL stream->sink causes a
NULL pointer dereference.

link_set_dpms_off() already guards two earlier accesses to stream->sink
with explicit NULL checks, confirming that stream->sink can legitimately
be NULL. The subsequent call to deallocate_usb4_bandwidth() had no
equivalent guard.

Replace the ASSERT() calls with proper NULL checks that return false
early, and add a matching stream->sink guard at the call site in
link_set_dpms_off() consistent with the surrounding pattern.

v2: Keep the existing ASSERT() calls for diagnostics (to report
    unexpected NULL sink), and add explicit NULL checks that return false
    before dereferencing stream->sink. Also add a matching stream->sink
    guard at the deallocation call site in link_set_dpms_off(). (Alex)

Fixes: 8fa813b7fd1e ("drm/amd/display: Remove sink usage from DPMS")
Reported-by: Dan Carpenter <error27@gmail.com>
Cc: Nicholas Kazlauskas <nicholas.kazlauskas@amd.com>
Cc: Dominik Kaszewski <dominik.kaszewski@amd.com>
Cc: George Zhang <george.zhang@amd.com>
Cc: Aurabindo Pillai <aurabindo.pillai@amd.com>
Cc: Roman Li <Roman.Li@amd.com>
Cc: Ivan Lipski <ivan.lipski@amd.com>
Cc: Dan Wheeler <daniel.wheeler@amd.com>
Cc: Alex Hung <alex.hung@amd.com>
Cc: Tom Chung <chiahsuan.chung@amd.com>
Signed-off-by: Srinivasan Shanmugam <srinivasan.shanmugam@amd.com>
Tested-by: Dan Wheeler <daniel.wheeler@amd.com>
Reviewed-by: Roman Li <roman.li@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
(cherry picked from commit 98029a0ce61feb52c563f65349dd9b25f672e355)
Cc: stable@vger.kernel.org

Srinivasan Shanmugam <srinivasan.shanmugam@amd.com> · 2026-09-17 06:14 UTC · committed by Alex Deucher

Browse files
16 files changed, +149 −128
modified drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
@@ -1431,6 +1431,7 @@ static void amdgpu_cs_parser_fini(struct amdgpu_cs_parser *parser)
1431 1431 int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
1432 1432 {
1433 1433 struct amdgpu_device *adev = drm_to_adev(dev);
1434 + struct amdgpu_bo_list_entry *e;
1434 1435 struct amdgpu_cs_parser parser;
1435 1436 int r;
1436 1437
@@ -1465,25 +1466,31 @@ int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
1465 1466
1466 1467 r = amdgpu_cs_patch_jobs(&parser);
1467 1468 if (r)
1468 - goto error_fini;
1469 + goto error_free_user_pages;
1469 1470
1470 1471 r = amdgpu_cs_vm_handling(&parser);
1471 1472 if (r)
1472 - goto error_fini;
1473 + goto error_free_user_pages;
1473 1474
1474 1475 r = amdgpu_cs_sync_rings(&parser);
1475 1476 if (r)
1476 - goto error_fini;
1477 + goto error_free_user_pages;
1477 1478
1478 1479 trace_amdgpu_cs_ibs(&parser);
1479 1480
1480 1481 r = amdgpu_cs_submit(&parser, data);
1481 1482 if (r)
1482 - goto error_fini;
1483 + goto error_free_user_pages;
1483 1484
1484 1485 amdgpu_cs_parser_fini(&parser);
1485 1486 return 0;
1486 1487
1488 + error_free_user_pages:
1489 + /* amdgpu_cs_submit() only drops the ranges once it got that far. */
1490 + amdgpu_bo_list_for_each_userptr_entry(e, parser.bo_list) {
1491 + amdgpu_hmm_range_free(e->range);
1492 + e->range = NULL;
1493 + }
1487 1494 error_fini:
1488 1495 amdgpu_cs_parser_fini(&parser);
1489 1496 return r;
modified drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
@@ -1266,7 +1266,6 @@ static ssize_t amdgpu_debugfs_gpr_read(struct file *f, char __user *buf,
1266 1266 {
1267 1267 struct amdgpu_device *adev = f->f_inode->i_private;
1268 1268 int r;
1269 - ssize_t result = 0;
1270 1269 uint32_t offset, se, sh, cu, wave, simd, thread, bank, *data;
1271 1270
1272 1271 if (size > 4096 || size & 3 || *pos & 3)
@@ -1310,25 +1309,11 @@ static ssize_t amdgpu_debugfs_gpr_read(struct file *f, char __user *buf,
1310 1309 mutex_unlock(&adev->grbm_idx_mutex);
1311 1310
1312 1311 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
1312 + amdgpu_virt_disable_access_debugfs(adev);
1313 1313
1314 - while (size) {
1315 - uint32_t value;
1316 -
1317 - value = data[result >> 2];
1318 - r = put_user(value, (uint32_t *)buf);
1319 - if (r) {
1320 - amdgpu_virt_disable_access_debugfs(adev);
1321 - goto err;
1322 - }
1323 -
1324 - result += 4;
1325 - buf += 4;
1326 - size -= 4;
1327 - }
1328 -
1314 + r = copy_to_user(buf, data, size) ? -EFAULT : size;
1329 1315 kfree(data);
1330 - amdgpu_virt_disable_access_debugfs(adev);
1331 - return result;
1316 + return r;
1332 1317
1333 1318 err:
1334 1319 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
modified drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
@@ -567,8 +567,10 @@ int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data,
567 567
568 568 if (args->flags & AMDGPU_GEM_USERPTR_VALIDATE) {
569 569 range = amdgpu_hmm_range_alloc(NULL);
570 - if (unlikely(!range))
571 - return -ENOMEM;
570 + if (unlikely(!range)) {
571 + r = -ENOMEM;
572 + goto release_object;
573 + }
572 574 r = amdgpu_ttm_tt_get_user_pages(bo, range);
573 575 if (r) {
574 576 amdgpu_hmm_range_free(range);
@@ -1236,7 +1238,7 @@ int amdgpu_gem_list_handles_ioctl(struct drm_device *dev, void *data,
1236 1238 bo_entry->alloc_flags = bo->flags & AMDGPU_GEM_CREATE_SETTABLE_MASK;
1237 1239 bo_entry->preferred_domains = bo->preferred_domains;
1238 1240 bo_entry->gem_handle = id;
1239 - bo_entry->alignment = bo->tbo.page_alignment;
1241 + bo_entry->alignment = (u64)bo->tbo.page_alignment << PAGE_SHIFT;
1240 1242
1241 1243 if (bo->tbo.base.import_attach)
1242 1244 bo_entry->flags |= AMDGPU_GEM_LIST_HANDLES_FLAG_IS_IMPORT;
modified drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -2065,14 +2065,15 @@ static int amdgpu_ttm_buffer_entity_init(struct amdgpu_gtt_mgr *mgr,
2065 2065 int i, r, num_pages;
2066 2066 const u64 GTT_MAX_PAGES = (AMDGPU_GTT_MAX_TRANSFER_SIZE >> PAGE_SHIFT);
2067 2067
2068 + if (ARRAY_SIZE(entity->gart_window_offs) < num_gart_windows)
2069 + return -EINVAL;
2070 +
2068 2071 r = drm_sched_entity_init(&entity->base, prio, scheds, num_schedulers, NULL);
2069 2072 if (r)
2070 2073 return r;
2071 2074
2072 2075 mutex_init(&entity->lock);
2073 2076
2074 - if (ARRAY_SIZE(entity->gart_window_offs) < num_gart_windows)
2075 - return -EINVAL;
2076 2077 if (num_gart_windows == 0)
2077 2078 return 0;
2078 2079
@@ -2080,6 +2081,7 @@ static int amdgpu_ttm_buffer_entity_init(struct amdgpu_gtt_mgr *mgr,
2080 2081 r = amdgpu_gtt_mgr_alloc_entries(mgr, &entity->gart_node, num_pages,
2081 2082 DRM_MM_INSERT_BEST);
2082 2083 if (r) {
2084 + mutex_destroy(&entity->lock);
2083 2085 drm_sched_entity_destroy(&entity->base);
2084 2086 return r;
2085 2087 }
@@ -2097,6 +2099,7 @@ static void amdgpu_ttm_buffer_entity_fini(struct amdgpu_gtt_mgr *mgr,
2097 2099 struct amdgpu_ttm_buffer_entity *entity)
2098 2100 {
2099 2101 amdgpu_gtt_mgr_free_entries(mgr, &entity->gart_node);
2102 + mutex_destroy(&entity->lock);
2100 2103 drm_sched_entity_destroy(&entity->base);
2101 2104 }
2102 2105
modified drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
@@ -980,19 +980,21 @@ amdgpu_userq_bo_validate(struct amdgpu_device *adev, struct drm_exec *exec,
980 980 {
981 981 struct ttm_operation_ctx ctx = { false, false };
982 982 struct amdgpu_bo_va *bo_va;
983 - struct amdgpu_bo *bo;
983 + struct amdgpu_bo *bo, *tmp;
984 984 int ret;
985 985
986 986 spin_lock(&vm->individual_lock);
987 - while (!list_empty(&vm->always_valid.evicted)) {
988 - bo_va = list_first_entry(&vm->always_valid.evicted,
987 + while (!list_empty(&vm->individual.evicted)) {
988 + bo_va = list_first_entry(&vm->individual.evicted,
989 989 struct amdgpu_bo_va,
990 990 base.vm_status);
991 + bo = bo_va->base.bo;
992 + tmp = amdgpu_bo_ref(bo);
991 993 spin_unlock(&vm->individual_lock);
992 994
993 - bo = bo_va->base.bo;
994 995 ret = drm_exec_prepare_obj(exec, &bo->tbo.base,
995 996 TTM_NUM_MOVE_FENCES + 1);
997 + amdgpu_bo_unref(&tmp);
996 998 if (unlikely(ret))
997 999 return ret;
998 1000
modified drivers/gpu/drm/amd/amdgpu/uvd_v3_1.c
@@ -288,7 +288,7 @@ static int uvd_v3_1_fw_validate(struct amdgpu_device *adev)
288 288 int i;
289 289 uint32_t keysel = adev->uvd.keyselect;
290 290
291 - if (RREG32(mmUVD_FW_START) & UVD_FW_STATUS__PASS_MASK) {
291 + if (RREG32(mmUVD_FW_START)) {
292 292 dev_dbg(adev->dev, "UVD keyselect already set: 0x%x (on CPU: 0x%x)\n",
293 293 RREG32(mmUVD_FW_START), adev->uvd.keyselect);
294 294 return 0;
modified drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0_2_ppt.c
@@ -89,6 +89,7 @@ static const struct smu_feature_bits smu_v14_0_2_dpm_features = {
89 89 #define PP_OD_FEATURE_FAN_TARGET_TEMPERATURE 9
90 90 #define PP_OD_FEATURE_FAN_MINIMUM_PWM 10
91 91 #define PP_OD_FEATURE_FAN_ZERO_RPM_ENABLE 11
92 + #define PP_OD_FEATURE_FAN_ZERO_RPM_STOP_TEMP 12
92 93
93 94 static struct cmn2asic_msg_mapping smu_v14_0_2_message_map[SMU_MSG_MAX_COUNT] = {
94 95 MSG_MAP(TestMessage, PPSMC_MSG_TestMessage, 1),
@@ -1020,6 +1021,10 @@ static void smu_v14_0_2_get_od_setting_limits(struct smu_context *smu,
1020 1021 od_min_setting = overdrive_lowerlimits->FanZeroRpmEnable;
1021 1022 od_max_setting = overdrive_upperlimits->FanZeroRpmEnable;
1022 1023 break;
1024 + case PP_OD_FEATURE_FAN_ZERO_RPM_STOP_TEMP:
1025 + od_min_setting = pptable->SkuTable.MsgLimits.FanStopTempMin;
1026 + od_max_setting = pptable->SkuTable.MsgLimits.FanStopTempMax;
1027 + break;
1023 1028 default:
1024 1029 od_min_setting = od_max_setting = INT_MAX;
1025 1030 break;
@@ -1244,6 +1249,24 @@ static int smu_v14_0_2_emit_clk_levels(struct smu_context *smu,
1244 1249 min_value, max_value);
1245 1250 break;
1246 1251
1252 + case SMU_OD_FAN_ZERO_RPM_STOP_TEMP:
1253 + if (!smu_v14_0_2_is_od_feature_supported(smu,
1254 + PP_OD_FEATURE_ZERO_FAN_BIT))
1255 + break;
1256 +
1257 + size += sysfs_emit_at(buf, size, "FAN_ZERO_RPM_STOP_TEMPERATURE:\n");
1258 + size += sysfs_emit_at(buf, size, "%d\n",
1259 + (int)od_table->OverDriveTable.FanZeroRpmStopTemp);
1260 +
1261 + size += sysfs_emit_at(buf, size, "%s:\n", "OD_RANGE");
1262 + smu_v14_0_2_get_od_setting_limits(smu,
1263 + PP_OD_FEATURE_FAN_ZERO_RPM_STOP_TEMP,
1264 + &min_value,
1265 + &max_value);
1266 + size += sysfs_emit_at(buf, size, "ZERO_RPM_STOP_TEMPERATURE: %u %u\n",
1267 + min_value, max_value);
1268 + break;
1269 +
1247 1270 case SMU_OD_RANGE:
1248 1271 if (!smu_v14_0_2_is_od_feature_supported(smu, PP_OD_FEATURE_GFXCLK_BIT) &&
1249 1272 !smu_v14_0_2_is_od_feature_supported(smu, PP_OD_FEATURE_UCLK_BIT) &&
@@ -2311,7 +2334,9 @@ static void smu_v14_0_2_set_supported_od_feature_mask(struct smu_context *smu)
2311 2334 OD_OPS_SUPPORT_FAN_MINIMUM_PWM_RETRIEVE |
2312 2335 OD_OPS_SUPPORT_FAN_MINIMUM_PWM_SET |
2313 2336 OD_OPS_SUPPORT_FAN_ZERO_RPM_ENABLE_RETRIEVE |
2314 - OD_OPS_SUPPORT_FAN_ZERO_RPM_ENABLE_SET;
2337 + OD_OPS_SUPPORT_FAN_ZERO_RPM_ENABLE_SET |
2338 + OD_OPS_SUPPORT_FAN_ZERO_RPM_STOP_TEMP_RETRIEVE |
2339 + OD_OPS_SUPPORT_FAN_ZERO_RPM_STOP_TEMP_SET;
2315 2340 }
2316 2341
2317 2342 static int smu_v14_0_2_get_overdrive_table(struct smu_context *smu,
@@ -2392,6 +2417,8 @@ static int smu_v14_0_2_set_default_od_settings(struct smu_context *smu)
2392 2417 user_od_table_bak.OverDriveTable.FanMinimumPwm;
2393 2418 user_od_table->OverDriveTable.FanZeroRpmEnable =
2394 2419 user_od_table_bak.OverDriveTable.FanZeroRpmEnable;
2420 + user_od_table->OverDriveTable.FanZeroRpmStopTemp =
2421 + user_od_table_bak.OverDriveTable.FanZeroRpmStopTemp;
2395 2422 }
2396 2423
2397 2424 smu_v14_0_2_set_supported_od_feature_mask(smu);
@@ -2446,6 +2473,11 @@ static int smu_v14_0_2_od_restore_table_single(struct smu_context *smu, long inp
2446 2473 boot_overdrive_table->OverDriveTable.FanZeroRpmEnable;
2447 2474 od_table->OverDriveTable.FeatureCtrlMask |= BIT(PP_OD_FEATURE_ZERO_FAN_BIT);
2448 2475 break;
2476 + case PP_OD_EDIT_FAN_ZERO_RPM_STOP_TEMP:
2477 + od_table->OverDriveTable.FanZeroRpmStopTemp =
2478 + boot_overdrive_table->OverDriveTable.FanZeroRpmStopTemp;
2479 + od_table->OverDriveTable.FeatureCtrlMask |= BIT(PP_OD_FEATURE_ZERO_FAN_BIT);
2480 + break;
2449 2481 case PP_OD_EDIT_ACOUSTIC_LIMIT:
2450 2482 od_table->OverDriveTable.AcousticLimitRpmThreshold =
2451 2483 boot_overdrive_table->OverDriveTable.AcousticLimitRpmThreshold;
@@ -2752,6 +2784,27 @@ static int smu_v14_0_2_od_edit_dpm_table(struct smu_context *smu,
2752 2784 od_table->OverDriveTable.FeatureCtrlMask |= BIT(PP_OD_FEATURE_ZERO_FAN_BIT);
2753 2785 break;
2754 2786
2787 + case PP_OD_EDIT_FAN_ZERO_RPM_STOP_TEMP:
2788 + if (!smu_v14_0_2_is_od_feature_supported(smu, PP_OD_FEATURE_ZERO_FAN_BIT)) {
2789 + dev_warn(adev->dev, "Zero RPM setting not supported!\n");
2790 + return -ENOTSUPP;
2791 + }
2792 +
2793 + smu_v14_0_2_get_od_setting_limits(smu,
2794 + PP_OD_FEATURE_FAN_ZERO_RPM_STOP_TEMP,
2795 + &minimum,
2796 + &maximum);
2797 + if (input[0] < minimum ||
2798 + input[0] > maximum) {
2799 + dev_info(adev->dev, "zero RPM stop temperature setting(%ld) must be within [%d, %d]!\n",
2800 + input[0], minimum, maximum);
2801 + return -EINVAL;
2802 + }
2803 +
2804 + od_table->OverDriveTable.FanZeroRpmStopTemp = input[0];
2805 + od_table->OverDriveTable.FeatureCtrlMask |= BIT(PP_OD_FEATURE_ZERO_FAN_BIT);
2806 + break;
2807 +
2755 2808 case PP_OD_RESTORE_DEFAULT_TABLE:
2756 2809 if (size == 1) {
2757 2810 ret = smu_v14_0_2_od_restore_table_single(smu, input[0]);
modified fs/tracefs/event_inode.c
@@ -91,14 +91,6 @@ static void free_ei_rcu(struct rcu_head *rcu)
91 91 }
92 92 }
93 93
94 - /* read under eventfs_srcu and, by tracefs_d_revalidate(), in rcu pathwalk */
95 - static void free_ei_srcu(struct rcu_head *rcu)
96 - {
97 - struct eventfs_inode *ei = container_of(rcu, struct eventfs_inode, rcu);
98 -
99 - call_rcu(&ei->rcu, free_ei_rcu);
100 - }
101 -
102 94 /*
103 95 * eventfs_inode reference count management.
104 96 *
@@ -120,7 +112,7 @@ static void release_ei(struct kref *ref)
120 112 entry->release(entry->name, ei->data);
121 113 }
122 114
123 - call_srcu(&eventfs_srcu, &ei->rcu, free_ei_srcu);
115 + call_srcu(&eventfs_srcu, &ei->rcu, free_ei_rcu);
124 116 }
125 117
126 118 static inline void put_ei(struct eventfs_inode *ei)
modified kernel/trace/Makefile
@@ -146,12 +146,11 @@ KASAN_SANITIZE_undefsyms_base.o := y
146 146
147 147 UNDEFINED_ALLOWLIST = __asan __gcov __kasan __kcsan __hwasan __sancov __sanitizer __tsan __ubsan __msan \
148 148 __aeabi_unwind_cpp __s390_indirect_jump __x86_indirect_thunk simple_ring_buffer \
149 - current_thread_info_reg \
150 - $(shell $(NM) -u $(obj)/undefsyms_base.o 2>/dev/null | awk '$$2 {print $$2}')
149 + $(shell $(NM) -u $(obj)/undefsyms_base.o 2>/dev/null | awk '{print $$2}')
151 150
152 151 quiet_cmd_check_undefined = NM $<
153 152 cmd_check_undefined = \
154 - undefsyms=$$($(NM) -u $< | awk '$$2 {print $$2}' | grep -v $(addprefix -e , $(UNDEFINED_ALLOWLIST)) || true); \
153 + undefsyms=$$($(NM) -u $< | grep -v $(addprefix -e , $(UNDEFINED_ALLOWLIST)) || true); \
155 154 if [ -n "$$undefsyms" ]; then \
156 155 echo "Unexpected symbols in $<:" >&2; \
157 156 echo "$$undefsyms" >&2; \
modified kernel/trace/ring_buffer.c
@@ -2380,9 +2380,6 @@ int ring_buffer_meta_seq_init(struct file *file, struct trace_buffer *buffer, in
2380 2380 struct seq_file *m;
2381 2381 int ret;
2382 2382
2383 - if (!cpumask_test_cpu(cpu, buffer->cpumask))
2384 - return -ENODEV;
2385 -
2386 2383 ret = seq_open(file, &rb_meta_seq_ops);
2387 2384 if (ret)
2388 2385 return ret;
@@ -2443,33 +2440,22 @@ static int __rb_allocate_pages(struct ring_buffer_per_cpu *cpu_buffer,
2443 2440 unsigned long nr_pages, struct list_head *pages)
2444 2441 {
2445 2442 struct trace_buffer *buffer = cpu_buffer->buffer;
2446 - unsigned int subbuf_order = buffer->subbuf_order;
2447 2443 struct ring_buffer_cpu_meta *meta = NULL;
2448 2444 struct buffer_page *bpage, *tmp;
2445 + bool user_thread = current->mm != NULL;
2449 2446 struct ring_buffer_desc *desc = NULL;
2450 - bool user_thread = false;
2451 2447 long i;
2452 2448
2453 - if (buffer->range_addr_start) {
2454 - meta = rb_range_meta(buffer, nr_pages, cpu_buffer->cpu);
2455 - } else if (buffer->remote) {
2456 - desc = ring_buffer_desc(buffer->remote->desc, cpu_buffer->cpu);
2457 - if (!desc || WARN_ON(desc->nr_page_va != (nr_pages + 1)))
2458 - return -EINVAL;
2459 - } else {
2460 - /*
2461 - * Check if the available memory is there first.
2462 - * Note, si_mem_available() only gives us a rough estimate of available
2463 - * memory. It may not be accurate. But we don't care, we just want
2464 - * to prevent doing any allocation when it is obvious that it is
2465 - * not going to succeed.
2466 - */
2467 - i = si_mem_available();
2468 - if (i < (nr_pages << subbuf_order))
2469 - return -ENOMEM;
2470 -
2471 - user_thread = current->mm != NULL;
2472 - }
2449 + /*
2450 + * Check if the available memory is there first.
2451 + * Note, si_mem_available() only gives us a rough estimate of available
2452 + * memory. It may not be accurate. But we don't care, we just want
2453 + * to prevent doing any allocation when it is obvious that it is
2454 + * not going to succeed.
2455 + */
2456 + i = si_mem_available();
2457 + if (i < nr_pages)
2458 + return -ENOMEM;
2473 2459
2474 2460 /*
2475 2461 * If a user thread allocates too much, and si_mem_available()
@@ -2483,6 +2469,15 @@ static int __rb_allocate_pages(struct ring_buffer_per_cpu *cpu_buffer,
2483 2469 if (user_thread)
2484 2470 set_current_oom_origin();
2485 2471
2472 + if (buffer->range_addr_start)
2473 + meta = rb_range_meta(buffer, nr_pages, cpu_buffer->cpu);
2474 +
2475 + if (buffer->remote) {
2476 + desc = ring_buffer_desc(buffer->remote->desc, cpu_buffer->cpu);
2477 + if (!desc || WARN_ON(desc->nr_page_va != (nr_pages + 1)))
2478 + return -EINVAL;
2479 + }
2480 +
2486 2481 for (i = 0; i < nr_pages; i++) {
2487 2482
2488 2483 bpage = alloc_cpu_page(cpu_buffer->cpu);
@@ -2518,11 +2513,12 @@ static int __rb_allocate_pages(struct ring_buffer_per_cpu *cpu_buffer,
2518 2513 bpage->id = i + 1;
2519 2514 cpu_buffer->subbuf_ids[i + 1] = bpage;
2520 2515 } else {
2521 - bpage->page = alloc_cpu_data(cpu_buffer->cpu, subbuf_order);
2516 + bpage->page = alloc_cpu_data(cpu_buffer->cpu,
2517 + cpu_buffer->buffer->subbuf_order);
2522 2518 if (!bpage->page)
2523 2519 goto free_pages;
2524 2520 }
2525 - bpage->order = subbuf_order;
2521 + bpage->order = cpu_buffer->buffer->subbuf_order;
2526 2522
2527 2523 if (user_thread && fatal_signal_pending(current))
2528 2524 goto free_pages;
@@ -3631,8 +3627,10 @@ static void rb_inc_iter(struct ring_buffer_iter *iter)
3631 3627 /* Return the index into the sub-buffers for a given sub-buffer */
3632 3628 static int rb_meta_subbuf_idx(struct ring_buffer_cpu_meta *meta, void *subbuf)
3633 3629 {
3634 - void *subbuf_array = rb_subbufs_from_meta(meta);
3630 + void *subbuf_array;
3635 3631
3632 + subbuf_array = (void *)meta + sizeof(int) * meta->nr_subbufs;
3633 + subbuf_array = (void *)ALIGN((unsigned long)subbuf_array, meta->subbuf_size);
3636 3634 return (subbuf - subbuf_array) / meta->subbuf_size;
3637 3635 }
3638 3636
@@ -7999,8 +7997,12 @@ consume:
7999 7997 goto out;
8000 7998 }
8001 7999
8000 + /* Did the reader catch up with the writer? */
8001 + if (cpu_buffer->reader_page == cpu_buffer->commit_page)
8002 + goto out;
8003 +
8002 8004 reader = rb_get_reader_page(cpu_buffer);
8003 - if (!reader)
8005 + if (WARN_ON(!reader))
8004 8006 goto out;
8005 8007
8006 8008 /* Check if any events were dropped */
modified kernel/trace/trace.c
@@ -99,12 +99,6 @@ struct tracers {
99 99 struct tracer_flags *flags;
100 100 };
101 101
102 - /*
103 - * Tracers that do not define their own flags use these empty flags,
104 - * as tr->current_trace_flags must never be NULL.
105 - */
106 - static struct tracer_flags no_tracer_flags;
107 -
108 102 /*
109 103 * To prevent the comm cache from being overwritten when no
110 104 * tracing is active, only save the comm when a trace event
@@ -1324,12 +1318,7 @@ static int run_tracer_selftest(struct tracer *type)
1324 1318 tracing_reset_online_cpus(&tr->array_buffer);
1325 1319
1326 1320 tr->current_trace = type;
1327 - if (type->flags)
1328 - tr->current_trace_flags = type->flags;
1329 - else if (type->default_flags)
1330 - tr->current_trace_flags = type->default_flags;
1331 - else
1332 - tr->current_trace_flags = &no_tracer_flags;
1321 + tr->current_trace_flags = type->flags ? : type->default_flags;
1333 1322
1334 1323 #ifdef CONFIG_TRACER_MAX_TRACE
1335 1324 if (tracer_uses_snapshot(type)) {
@@ -5100,12 +5089,7 @@ int tracing_set_tracer(struct trace_array *tr, const char *buf)
5100 5089 return ret;
5101 5090 }
5102 5091
5103 - if (t->flags)
5104 - tr->current_trace_flags = t->flags;
5105 - else if (t->tracer->flags)
5106 - tr->current_trace_flags = t->tracer->flags;
5107 - else
5108 - tr->current_trace_flags = &no_tracer_flags;
5092 + tr->current_trace_flags = t->flags ? : t->tracer->flags;
5109 5093
5110 5094 if (trace->init) {
5111 5095 ret = tracer_init(trace, tr);
@@ -5897,7 +5881,7 @@ static int tracing_buffer_meta_open(struct inode *inode, struct file *filp)
5897 5881
5898 5882 ret = ring_buffer_meta_seq_init(filp, tr->array_buffer.buffer, cpu);
5899 5883 if (ret < 0)
5900 - trace_array_put(tr);
5884 + __trace_array_put(tr);
5901 5885 return ret;
5902 5886 }
5903 5887
@@ -9303,12 +9287,6 @@ static struct notifier_block trace_module_nb = {
9303 9287
9304 9288 static __init void tracer_init_tracefs_work_func(struct work_struct *work)
9305 9289 {
9306 - /*
9307 - * Do not attempt to initialize tracefs if tracing was disabled or
9308 - * failed to allocate
9309 - */
9310 - if (tracing_disabled)
9311 - return;
9312 9290
9313 9291 event_trace_init();
9314 9292
modified kernel/trace/trace_events_filter.c
@@ -482,17 +482,18 @@ predicate_parse(const char *str, int nr_parens, int nr_preds,
482 482 int len;
483 483 int N = 0;
484 484 int i;
485 - int nr_preds_alloc = nr_preds + 2; /* For TRUE and FALSE */
485 +
486 + nr_preds += 2; /* For TRUE and FALSE */
486 487
487 488 op_stack = kmalloc_objs(*op_stack, nr_parens);
488 489 if (!op_stack)
489 490 return ERR_PTR(-ENOMEM);
490 - prog_stack = kzalloc_objs(*prog_stack, nr_preds_alloc);
491 + prog_stack = kzalloc_objs(*prog_stack, nr_preds);
491 492 if (!prog_stack) {
492 493 parse_error(pe, -ENOMEM, 0);
493 494 goto out_free;
494 495 }
495 - inverts = kmalloc_array(nr_preds_alloc, sizeof(*inverts), GFP_KERNEL);
496 + inverts = kmalloc_array(nr_preds, sizeof(*inverts), GFP_KERNEL);
496 497 if (!inverts) {
497 498 parse_error(pe, -ENOMEM, 0);
498 499 goto out_free;
modified kernel/trace/trace_events_hist.c
@@ -289,7 +289,7 @@ static u64 hist_field_log2(struct hist_field *hist_field,
289 289
290 290 u64 val = hist_fn_call(operand, elt, buffer, rbe, event);
291 291
292 - return order_base_2(val);
292 + return (u64) ilog2(roundup_pow_of_two(val));
293 293 }
294 294
295 295 static u64 hist_field_bucket(struct hist_field *hist_field,
@@ -873,7 +873,7 @@ static u64 hist_field_timestamp(struct hist_field *hist_field,
873 873 struct hist_trigger_data *hist_data = hist_field->hist_data;
874 874 struct trace_array *tr = hist_data->event_file->tr;
875 875
876 - u64 ts = tracing_event_time_stamp(buffer, rbe);
876 + u64 ts = ring_buffer_event_time_stamp(buffer, rbe);
877 877
878 878 if (hist_data->attrs->ts_in_usecs && trace_clock_in_ns(tr))
879 879 ts = ns2usecs(ts);
@@ -2121,8 +2121,7 @@ static int init_var_ref(struct hist_field *ref_field,
2121 2121 ref_field->size = var_field->size;
2122 2122 ref_field->is_signed = var_field->is_signed;
2123 2123 ref_field->flags |= var_field->flags &
2124 - (HIST_FIELD_FL_TIMESTAMP | HIST_FIELD_FL_TIMESTAMP_USECS |
2125 - HIST_FIELD_FL_STACKTRACE);
2124 + (HIST_FIELD_FL_TIMESTAMP | HIST_FIELD_FL_TIMESTAMP_USECS);
2126 2125
2127 2126 if (system) {
2128 2127 ref_field->system = kstrdup(system, GFP_KERNEL);
@@ -3091,7 +3090,7 @@ create_field_var_hist(struct hist_trigger_data *target_hist_data,
3091 3090 key_field = hist_data->fields[i];
3092 3091 if (!first)
3093 3092 seq_buf_putc(&s, ',');
3094 - expr_field_str(key_field, &s);
3093 + seq_buf_puts(&s, key_field->field->name);
3095 3094 first = false;
3096 3095 }
3097 3096
@@ -3319,7 +3318,6 @@ static struct field_var *create_field_var(struct hist_trigger_data *hist_data,
3319 3318 ret = PTR_ERR(var);
3320 3319 goto err;
3321 3320 }
3322 - var->flags |= val->flags & HIST_FIELD_FL_STACKTRACE;
3323 3321
3324 3322 field_var = kzalloc_obj(struct field_var);
3325 3323 if (!field_var) {
@@ -3948,10 +3946,7 @@ static int check_synth_field(struct synth_event *event,
3948 3946 && field->is_dynamic)
3949 3947 return 0;
3950 3948
3951 - if (!!(hist_field->flags & HIST_FIELD_FL_STACKTRACE) != field->is_stack)
3952 - return -EINVAL;
3953 -
3954 - if (field->is_stack)
3949 + if (strstr(hist_field->type, "long[") && field->is_stack)
3955 3950 return 0;
3956 3951
3957 3952 if (strcmp(field->type, hist_field->type) != 0) {
@@ -4492,8 +4487,7 @@ static int create_var_field(struct hist_trigger_data *hist_data,
4492 4487 if (!ret && hist_data->fields[val_idx]->flags & HIST_FIELD_FL_EXECNAME)
4493 4488 update_var_execname(hist_data->fields[val_idx]);
4494 4489
4495 - if (!ret && !(hist_data->fields[val_idx]->flags & HIST_FIELD_FL_ALIAS) &&
4496 - hist_data->fields[val_idx]->flags &
4490 + if (!ret && hist_data->fields[val_idx]->flags &
4497 4491 (HIST_FIELD_FL_STRING | HIST_FIELD_FL_STACKTRACE))
4498 4492 hist_data->fields[val_idx]->var_str_idx = hist_data->n_var_str++;
4499 4493
@@ -5234,8 +5228,7 @@ static void hist_trigger_elt_update(struct hist_trigger_data *hist_data,
5234 5228 if (hist_field->flags & HIST_FIELD_FL_VAR) {
5235 5229 var_idx = hist_field->var.idx;
5236 5230
5237 - if (!(hist_field->flags & HIST_FIELD_FL_ALIAS) &&
5238 - hist_field->flags &
5231 + if (hist_field->flags &
5239 5232 (HIST_FIELD_FL_STRING | HIST_FIELD_FL_STACKTRACE)) {
5240 5233 unsigned int str_start, var_str_idx, idx;
5241 5234 char *str, *val_str;
modified kernel/trace/trace_snapshot.c
@@ -675,12 +675,9 @@ tracing_snapshot_write(struct file *filp, const char __user *ubuf, size_t cnt,
675 675 if (iter->cpu_file != RING_BUFFER_ALL_CPUS)
676 676 return -EINVAL;
677 677 #endif
678 - if (tr->allocated_snapshot) {
678 + if (tr->allocated_snapshot)
679 679 ret = resize_buffer_duplicate_size(&tr->snapshot_buffer,
680 680 &tr->array_buffer, iter->cpu_file);
681 - if (ret < 0)
682 - return ret;
683 - }
684 681
685 682 ret = tracing_arm_snapshot_locked(tr);
686 683 if (ret)
modified kernel/trace/undefsyms_base.c
@@ -9,7 +9,6 @@
9 9
10 10 #include <linux/atomic.h>
11 11 #include <linux/string.h>
12 - #include <asm/local.h>
13 12 #include <asm/page.h>
14 13
15 14 void undefsyms_base(void *p, int n);
@@ -19,13 +18,11 @@ static char page[PAGE_SIZE] __aligned(PAGE_SIZE);
19 18 void undefsyms_base(void *p, int n)
20 19 {
21 20 char buffer[256] = { 0 };
22 - u32 u = 0;
23 21
22 + u32 u = 0;
24 23 memset((char * volatile)page, 8, PAGE_SIZE);
25 24 memset((char * volatile)buffer, 8, sizeof(buffer));
26 25 memcpy((void * volatile)p, buffer, sizeof(buffer));
27 26 cmpxchg((u32 * volatile)&u, 0, 8);
28 - cmpxchg((unsigned long *)p, 0, 8);
29 - local_set((local_t *)p, 8);
30 27 WARN_ON(n == 0xdeadbeef);
31 28 }