@@ -1108,20 +1108,20 @@ static void setup_pebs_sample_data(struct perf_event *event,
11081108 }
11091109
11101110 /*
1111- * We use the interrupt regs as a base because the PEBS record
1112- * does not contain a full regs set, specifically it seems to
1113- * lack segment descriptors, which get used by things like
1114- * user_mode().
1111+ * We use the interrupt regs as a base because the PEBS record does not
1112+ * contain a full regs set, specifically it seems to lack segment
1113+ * descriptors, which get used by things like user_mode().
11151114 *
1116- * In the simple case fix up only the IP and BP,SP regs, for
1117- * PERF_SAMPLE_IP and PERF_SAMPLE_CALLCHAIN to function properly.
1118- * A possible PERF_SAMPLE_REGS will have to transfer all regs.
1115+ * In the simple case fix up only the IP for PERF_SAMPLE_IP.
1116+ *
1117+ * We must however always use BP,SP from iregs for the unwinder to stay
1118+ * sane; the record BP,SP can point into thin air when the record is
1119+ * from a previous PMI context or an (I)RET happend between the record
1120+ * and PMI.
11191121 */
11201122 * regs = * iregs ;
11211123 regs -> flags = pebs -> flags ;
11221124 set_linear_ip (regs , pebs -> ip );
1123- regs -> bp = pebs -> bp ;
1124- regs -> sp = pebs -> sp ;
11251125
11261126 if (sample_type & PERF_SAMPLE_REGS_INTR ) {
11271127 regs -> ax = pebs -> ax ;
@@ -1130,10 +1130,21 @@ static void setup_pebs_sample_data(struct perf_event *event,
11301130 regs -> dx = pebs -> dx ;
11311131 regs -> si = pebs -> si ;
11321132 regs -> di = pebs -> di ;
1133- regs -> bp = pebs -> bp ;
1134- regs -> sp = pebs -> sp ;
11351133
1136- regs -> flags = pebs -> flags ;
1134+ /*
1135+ * Per the above; only set BP,SP if we don't need callchains.
1136+ *
1137+ * XXX: does this make sense?
1138+ */
1139+ if (!(sample_type & PERF_SAMPLE_CALLCHAIN )) {
1140+ regs -> bp = pebs -> bp ;
1141+ regs -> sp = pebs -> sp ;
1142+ }
1143+
1144+ /*
1145+ * Preserve PERF_EFLAGS_VM from set_linear_ip().
1146+ */
1147+ regs -> flags = pebs -> flags | (regs -> flags & PERF_EFLAGS_VM );
11371148#ifndef CONFIG_X86_32
11381149 regs -> r8 = pebs -> r8 ;
11391150 regs -> r9 = pebs -> r9 ;
0 commit comments