1
0
Files
kernel-49/tools/perf/tests/sample-parsing.c
Greg Kroah-Hartman 54ab1ef534 Merge 4.9.259 into android-4.9-q
Changes in 4.9.259
	HID: make arrays usage and value to be the same
	usb: quirks: add quirk to start video capture on ELMO L-12F document camera reliable
	ntfs: check for valid standard information attribute
	igb: Remove incorrect "unexpected SYS WRAP" log message
	arm64: tegra: Add power-domain for Tegra210 HDA
	NET: usb: qmi_wwan: Adding support for Cinterion MV31
	cifs: Set CIFS_MOUNT_USE_PREFIX_PATH flag on setting cifs_sb->prepath.
	scripts/recordmcount.pl: support big endian for ARCH sh
	kdb: Make memory allocations more robust
	MIPS: vmlinux.lds.S: add missing PAGE_ALIGNED_DATA() section
	random: fix the RNDRESEEDCRNG ioctl
	mm, thp: make do_huge_pmd_wp_page() lock page for testing mapcount
	Bluetooth: Fix initializing response id after clearing struct
	ARM: dts: exynos: correct PMIC interrupt trigger level on Spring
	ARM: dts: exynos: correct PMIC interrupt trigger level on Arndale Octa
	arm64: dts: exynos: correct PMIC interrupt trigger level on Espresso
	Bluetooth: drop HCI device reference before return
	Bluetooth: Put HCI device if inquiry procedure interrupts
	ARM: dts: Configure missing thermal interrupt for 4430
	usb: dwc2: Do not update data length if it is 0 on inbound transfers
	usb: dwc2: Abort transaction after errors with unknown reason
	usb: dwc2: Make "trimming xfer length" a debug message
	arm64: dts: msm8916: Fix reserved and rfsa nodes unit address
	ARM: s3c: fix fiq for clang IAS
	bnxt_en: reverse order of TX disable and carrier off
	xen/netback: fix spurious event detection for common event case
	mac80211: fix potential overflow when multiplying to u32 integers
	b43: N-PHY: Fix the update of coef for the PHY revision >= 3case
	fbdev: aty: SPARC64 requires FB_ATY_CT
	drm/gma500: Fix error return code in psb_driver_load()
	gma500: clean up error handling in init
	MIPS: c-r4k: Fix section mismatch for loongson2_sc_init
	MIPS: lantiq: Explicitly compare LTQ_EBU_PCC_ISTAT against 0
	media: vsp1: Fix an error handling path in the probe function
	media: media/pci: Fix memleak in empress_init
	media: tm6000: Fix memleak in tm6000_start_stream
	ASoC: cs42l56: fix up error handling in probe
	media: lmedm04: Fix misuse of comma
	media: qm1d1c0042: fix error return code in qm1d1c0042_init()
	media: cx25821: Fix a bug when reallocating some dma memory
	media: pxa_camera: declare variable when DEBUG is defined
	media: uvcvideo: Accept invalid bFormatIndex and bFrameIndex values
	ata: ahci_brcm: Add back regulators management
	btrfs: clarify error returns values in __load_free_space_cache
	crypto: ecdh_helper - Ensure 'len >= secret.len' in decode_key()
	fs/jfs: fix potential integer overflow on shift of a int
	jffs2: fix use after free in jffs2_sum_write_data()
	clk: meson: clk-pll: fix initializing the old rate (fallback) for a PLL
	spi: cadence-quadspi: Abort read if dummy cycles required are too many
	HID: core: detect and skip invalid inputs to snto32()
	dmaengine: fsldma: Fix a resource leak in the remove function
	dmaengine: fsldma: Fix a resource leak in an error handling path of the probe function
	fdt: Properly handle "no-map" field in the memory region
	of/fdt: Make sure no-map does not remove already reserved regions
	power: reset: at91-sama5d2_shdwc: fix wkupdbc mask
	clocksource/drivers/mxs_timer: Add missing semicolon when DEBUG is defined
	regulator: axp20x: Fix reference cout leak
	isofs: release buffer head before return
	IB/umad: Return EIO in case of when device disassociated
	powerpc/47x: Disable 256k page size
	mmc: usdhi6rol0: Fix a resource leak in the error handling path of the probe
	ARM: 9046/1: decompressor: Do not clear SCTLR.nTLSMD for ARMv7+ cores
	amba: Fix resource leak for drivers without .remove
	tracepoint: Do not fail unregistering a probe due to memory failure
	perf tools: Fix DSO filtering when not finding a map for a sampled address
	RDMA/rxe: Fix coding error in rxe_recv.c
	mfd: wm831x-auxadc: Prevent use after free in wm831x_auxadc_read_irq()
	powerpc/pseries/dlpar: handle ibm, configure-connector delay status
	spi: pxa2xx: Fix the controller numbering for Wildcat Point
	perf intel-pt: Fix missing CYC processing in PSB
	perf test: Fix unaligned access in sample parsing test
	Input: elo - fix an error code in elo_connect()
	sparc64: only select COMPAT_BINFMT_ELF if BINFMT_ELF is set
	misc: eeprom_93xx46: Fix module alias to enable module autoprobe
	misc: eeprom_93xx46: Add module alias to avoid breaking support for non device tree users
	pwm: rockchip: rockchip_pwm_probe(): Remove superfluous clk_unprepare()
	VMCI: Use set_page_dirty_lock() when unregistering guest memory
	PCI: Align checking of syscall user config accessors
	drm/msm/dsi: Correct io_start for MSM8994 (20nm PHY)
	i40e: Fix flow for IPv6 next header (extension header)
	net/mlx4_core: Add missed mlx4_free_cmd_mailbox()
	ocfs2: fix a use after free on error
	mm/memory.c: fix potential pte_unmap_unlock pte error
	mm/hugetlb: fix potential double free in hugetlb_register_node() error path
	arm64: Add missing ISB after invalidating TLB in __primary_switch
	i2c: brcmstb: Fix brcmstd_send_i2c_cmd condition
	scsi: bnx2fc: Fix Kconfig warning & CNIC build errors
	blk-settings: align max_sectors on "logical_block_size" boundary
	ACPI: configfs: add missing check after configfs_register_default_group()
	Input: raydium_ts_i2c - do not send zero length
	Input: xpad - add support for PowerA Enhanced Wired Controller for Xbox Series X|S
	Input: joydev - prevent potential read overflow in ioctl
	Input: i8042 - add ASUS Zenbook Flip to noselftest list
	USB: serial: option: update interface mapping for ZTE P685M
	usb: musb: Fix runtime PM race in musb_queue_resume_work
	USB: serial: mos7840: fix error code in mos7840_write()
	USB: serial: mos7720: fix error code in mos7720_write()
	usb: dwc3: gadget: Fix setting of DEPCFG.bInterval_m1
	usb: dwc3: gadget: Fix dep->interval for fullspeed interrupt
	KEYS: trusted: Fix migratable=1 failing
	btrfs: abort the transaction if we fail to inc ref in btrfs_copy_root
	btrfs: fix reloc root leak with 0 ref reloc roots on recovery
	btrfs: fix extent buffer leak on failure to copy root
	seccomp: Add missing return in non-void function
	drivers/misc/vmw_vmci: restrict too big queue size in qp_host_alloc_queue
	staging: rtl8188eu: Add Edimax EW-7811UN V2 to device table
	x86/reboot: Force all cpus to exit VMX root if VMX is supported
	floppy: reintroduce O_NDELAY fix
	mtd: spi-nor: hisi-sfc: Put child node np on error path
	mm: hugetlb: fix a race between freeing and dissolving the page
	usb: renesas_usbhs: Clear pipe running flag in usbhs_pkt_pop()
	libnvdimm/dimm: Avoid race between probe and available_slots_show()
	module: Ignore _GLOBAL_OFFSET_TABLE_ when warning for undefined symbols
	mmc: sdhci-esdhc-imx: fix kernel panic when remove module
	gpio: pcf857x: Fix missing first interrupt
	f2fs: fix out-of-repair __setattr_copy()
	sparc32: fix a user-triggerable oops in clear_user()
	gfs2: Don't skip dlm unlock if glock has an lvb
	dm era: Recover committed writeset after crash
	dm era: Verify the data block size hasn't changed
	dm era: Fix bitset memory leaks
	dm era: Use correct value size in equality function of writeset tree
	dm era: Reinitialize bitset cache before digesting a new writeset
	dm era: only resize metadata in preresume
	futex: Fix OWNER_DEAD fixup
	futex: fix dead code in attach_to_pi_owner()
	icmp: introduce helper for nat'd source address in network device context
	icmp: allow icmpv6_ndo_send to work with CONFIG_IPV6=n
	gtp: use icmp_ndo_send helper
	sunvnet: use icmp_ndo_send helper
	ipv6: icmp6: avoid indirect call for icmpv6_send()
	ipv6: silence compilation warning for non-IPV6 builds
	net: icmp: pass zeroed opts from icmp{,v6}_ndo_send before sending
	dm era: Update in-core bitset after committing the metadata
	Linux 4.9.259

Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Change-Id: Icef5fb8e40fc531a932878e86ae352f2d5e71d53
2021-03-16 19:12:45 +03:00

347 lines
8.0 KiB
C

#include <stdbool.h>
#include <linux/types.h>
#include "util.h"
#include "event.h"
#include "evsel.h"
#include "debug.h"
#include "tests.h"
#define COMP(m) do { \
if (s1->m != s2->m) { \
pr_debug("Samples differ at '"#m"'\n"); \
return false; \
} \
} while (0)
#define MCOMP(m) do { \
if (memcmp(&s1->m, &s2->m, sizeof(s1->m))) { \
pr_debug("Samples differ at '"#m"'\n"); \
return false; \
} \
} while (0)
static bool samples_same(const struct perf_sample *s1,
const struct perf_sample *s2,
u64 type, u64 read_format)
{
size_t i;
if (type & PERF_SAMPLE_IDENTIFIER)
COMP(id);
if (type & PERF_SAMPLE_IP)
COMP(ip);
if (type & PERF_SAMPLE_TID) {
COMP(pid);
COMP(tid);
}
if (type & PERF_SAMPLE_TIME)
COMP(time);
if (type & PERF_SAMPLE_ADDR)
COMP(addr);
if (type & PERF_SAMPLE_ID)
COMP(id);
if (type & PERF_SAMPLE_STREAM_ID)
COMP(stream_id);
if (type & PERF_SAMPLE_CPU)
COMP(cpu);
if (type & PERF_SAMPLE_PERIOD)
COMP(period);
if (type & PERF_SAMPLE_READ) {
if (read_format & PERF_FORMAT_GROUP)
COMP(read.group.nr);
else
COMP(read.one.value);
if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED)
COMP(read.time_enabled);
if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING)
COMP(read.time_running);
/* PERF_FORMAT_ID is forced for PERF_SAMPLE_READ */
if (read_format & PERF_FORMAT_GROUP) {
for (i = 0; i < s1->read.group.nr; i++)
MCOMP(read.group.values[i]);
} else {
COMP(read.one.id);
}
}
if (type & PERF_SAMPLE_CALLCHAIN) {
COMP(callchain->nr);
for (i = 0; i < s1->callchain->nr; i++)
COMP(callchain->ips[i]);
}
if (type & PERF_SAMPLE_RAW) {
COMP(raw_size);
if (memcmp(s1->raw_data, s2->raw_data, s1->raw_size)) {
pr_debug("Samples differ at 'raw_data'\n");
return false;
}
}
if (type & PERF_SAMPLE_BRANCH_STACK) {
COMP(branch_stack->nr);
for (i = 0; i < s1->branch_stack->nr; i++)
MCOMP(branch_stack->entries[i]);
}
if (type & PERF_SAMPLE_REGS_USER) {
size_t sz = hweight_long(s1->user_regs.mask) * sizeof(u64);
COMP(user_regs.mask);
COMP(user_regs.abi);
if (s1->user_regs.abi &&
(!s1->user_regs.regs || !s2->user_regs.regs ||
memcmp(s1->user_regs.regs, s2->user_regs.regs, sz))) {
pr_debug("Samples differ at 'user_regs'\n");
return false;
}
}
if (type & PERF_SAMPLE_STACK_USER) {
COMP(user_stack.size);
if (memcmp(s1->user_stack.data, s2->user_stack.data,
s1->user_stack.size)) {
pr_debug("Samples differ at 'user_stack'\n");
return false;
}
}
if (type & PERF_SAMPLE_WEIGHT)
COMP(weight);
if (type & PERF_SAMPLE_DATA_SRC)
COMP(data_src);
if (type & PERF_SAMPLE_TRANSACTION)
COMP(transaction);
if (type & PERF_SAMPLE_REGS_INTR) {
size_t sz = hweight_long(s1->intr_regs.mask) * sizeof(u64);
COMP(intr_regs.mask);
COMP(intr_regs.abi);
if (s1->intr_regs.abi &&
(!s1->intr_regs.regs || !s2->intr_regs.regs ||
memcmp(s1->intr_regs.regs, s2->intr_regs.regs, sz))) {
pr_debug("Samples differ at 'intr_regs'\n");
return false;
}
}
return true;
}
static int do_test(u64 sample_type, u64 sample_regs, u64 read_format)
{
struct perf_evsel evsel = {
.needs_swap = false,
.attr = {
.sample_type = sample_type,
.read_format = read_format,
},
};
union perf_event *event;
union {
struct ip_callchain callchain;
u64 data[64];
} callchain = {
/* 3 ips */
.data = {3, 201, 202, 203},
};
union {
struct branch_stack branch_stack;
u64 data[64];
} branch_stack = {
/* 1 branch_entry */
.data = {1, 211, 212, 213},
};
u64 regs[64];
const u32 raw_data[] = {0x12345678, 0x0a0b0c0d, 0x11020304, 0x05060708, 0 };
const u64 data[] = {0x2211443366558877ULL, 0, 0xaabbccddeeff4321ULL};
struct perf_sample sample = {
.ip = 101,
.pid = 102,
.tid = 103,
.time = 104,
.addr = 105,
.id = 106,
.stream_id = 107,
.period = 108,
.weight = 109,
.cpu = 110,
.raw_size = sizeof(raw_data),
.data_src = 111,
.transaction = 112,
.raw_data = (void *)raw_data,
.callchain = &callchain.callchain,
.branch_stack = &branch_stack.branch_stack,
.user_regs = {
.abi = PERF_SAMPLE_REGS_ABI_64,
.mask = sample_regs,
.regs = regs,
},
.user_stack = {
.size = sizeof(data),
.data = (void *)data,
},
.read = {
.time_enabled = 0x030a59d664fca7deULL,
.time_running = 0x011b6ae553eb98edULL,
},
.intr_regs = {
.abi = PERF_SAMPLE_REGS_ABI_64,
.mask = sample_regs,
.regs = regs,
},
};
struct sample_read_value values[] = {{1, 5}, {9, 3}, {2, 7}, {6, 4},};
struct perf_sample sample_out;
size_t i, sz, bufsz;
int err, ret = -1;
if (sample_type & PERF_SAMPLE_REGS_USER)
evsel.attr.sample_regs_user = sample_regs;
if (sample_type & PERF_SAMPLE_REGS_INTR)
evsel.attr.sample_regs_intr = sample_regs;
for (i = 0; i < sizeof(regs); i++)
*(i + (u8 *)regs) = i & 0xfe;
if (read_format & PERF_FORMAT_GROUP) {
sample.read.group.nr = 4;
sample.read.group.values = values;
} else {
sample.read.one.value = 0x08789faeb786aa87ULL;
sample.read.one.id = 99;
}
sz = perf_event__sample_event_size(&sample, sample_type, read_format);
bufsz = sz + 4096; /* Add a bit for overrun checking */
event = malloc(bufsz);
if (!event) {
pr_debug("malloc failed\n");
return -1;
}
memset(event, 0xff, bufsz);
event->header.type = PERF_RECORD_SAMPLE;
event->header.misc = 0;
event->header.size = sz;
err = perf_event__synthesize_sample(event, sample_type, read_format,
&sample, false);
if (err) {
pr_debug("%s failed for sample_type %#"PRIx64", error %d\n",
"perf_event__synthesize_sample", sample_type, err);
goto out_free;
}
/* The data does not contain 0xff so we use that to check the size */
for (i = bufsz; i > 0; i--) {
if (*(i - 1 + (u8 *)event) != 0xff)
break;
}
if (i != sz) {
pr_debug("Event size mismatch: actual %zu vs expected %zu\n",
i, sz);
goto out_free;
}
evsel.sample_size = __perf_evsel__sample_size(sample_type);
err = perf_evsel__parse_sample(&evsel, event, &sample_out);
if (err) {
pr_debug("%s failed for sample_type %#"PRIx64", error %d\n",
"perf_evsel__parse_sample", sample_type, err);
goto out_free;
}
if (!samples_same(&sample, &sample_out, sample_type, read_format)) {
pr_debug("parsing failed for sample_type %#"PRIx64"\n",
sample_type);
goto out_free;
}
ret = 0;
out_free:
free(event);
if (ret && read_format)
pr_debug("read_format %#"PRIx64"\n", read_format);
return ret;
}
/**
* test__sample_parsing - test sample parsing.
*
* This function implements a test that synthesizes a sample event, parses it
* and then checks that the parsed sample matches the original sample. The test
* checks sample format bits separately and together. If the test passes %0 is
* returned, otherwise %-1 is returned.
*/
int test__sample_parsing(int subtest __maybe_unused)
{
const u64 rf[] = {4, 5, 6, 7, 12, 13, 14, 15};
u64 sample_type;
u64 sample_regs;
size_t i;
int err;
/*
* Fail the test if it has not been updated when new sample format bits
* were added. Please actually update the test rather than just change
* the condition below.
*/
if (PERF_SAMPLE_MAX > PERF_SAMPLE_REGS_INTR << 1) {
pr_debug("sample format has changed, some new PERF_SAMPLE_ bit was introduced - test needs updating\n");
return -1;
}
/* Test each sample format bit separately */
for (sample_type = 1; sample_type != PERF_SAMPLE_MAX;
sample_type <<= 1) {
/* Test read_format variations */
if (sample_type == PERF_SAMPLE_READ) {
for (i = 0; i < ARRAY_SIZE(rf); i++) {
err = do_test(sample_type, 0, rf[i]);
if (err)
return err;
}
continue;
}
sample_regs = 0;
if (sample_type == PERF_SAMPLE_REGS_USER)
sample_regs = 0x3fff;
if (sample_type == PERF_SAMPLE_REGS_INTR)
sample_regs = 0xff0fff;
err = do_test(sample_type, sample_regs, 0);
if (err)
return err;
}
/* Test all sample format bits together */
sample_type = PERF_SAMPLE_MAX - 1;
sample_regs = 0x3fff; /* shared yb intr and user regs */
for (i = 0; i < ARRAY_SIZE(rf); i++) {
err = do_test(sample_type, sample_regs, rf[i]);
if (err)
return err;
}
return 0;
}