Merge tag 'perf-core-2024-01-08' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6-block.git] / kernel / events / core.c
index 9efd0d7775e7ce400a1c966ba09af73ec3887f3d..f0f0f71213a1d387753a3d37a79ed7bddd44cc43 100644 (file)
@@ -7397,6 +7397,14 @@ void perf_output_sample(struct perf_output_handle *handle,
                        if (branch_sample_hw_index(event))
                                perf_output_put(handle, data->br_stack->hw_idx);
                        perf_output_copy(handle, data->br_stack->entries, size);
+                       /*
+                        * Add the extension space which is appended
+                        * right after the struct perf_branch_stack.
+                        */
+                       if (data->br_stack_cntr) {
+                               size = data->br_stack->nr * sizeof(u64);
+                               perf_output_copy(handle, data->br_stack_cntr, size);
+                       }
                } else {
                        /*
                         * we always store at least the value of nr
@@ -11425,9 +11433,30 @@ static DEVICE_ATTR_RW(perf_event_mux_interval_ms);
 static struct attribute *pmu_dev_attrs[] = {
        &dev_attr_type.attr,
        &dev_attr_perf_event_mux_interval_ms.attr,
+       &dev_attr_nr_addr_filters.attr,
+       NULL,
+};
+
+static umode_t pmu_dev_is_visible(struct kobject *kobj, struct attribute *a, int n)
+{
+       struct device *dev = kobj_to_dev(kobj);
+       struct pmu *pmu = dev_get_drvdata(dev);
+
+       if (n == 2 && !pmu->nr_addr_filters)
+               return 0;
+
+       return a->mode;
+}
+
+static struct attribute_group pmu_dev_attr_group = {
+       .is_visible = pmu_dev_is_visible,
+       .attrs = pmu_dev_attrs,
+};
+
+static const struct attribute_group *pmu_dev_groups[] = {
+       &pmu_dev_attr_group,
        NULL,
 };
-ATTRIBUTE_GROUPS(pmu_dev);
 
 static int pmu_bus_running;
 static struct bus_type pmu_bus = {
@@ -11464,18 +11493,11 @@ static int pmu_dev_alloc(struct pmu *pmu)
        if (ret)
                goto free_dev;
 
-       /* For PMUs with address filters, throw in an extra attribute: */
-       if (pmu->nr_addr_filters)
-               ret = device_create_file(pmu->dev, &dev_attr_nr_addr_filters);
-
-       if (ret)
-               goto del_dev;
-
-       if (pmu->attr_update)
+       if (pmu->attr_update) {
                ret = sysfs_update_groups(&pmu->dev->kobj, pmu->attr_update);
-
-       if (ret)
-               goto del_dev;
+               if (ret)
+                       goto del_dev;
+       }
 
 out:
        return ret;