From b8e3ead111e8e3c0ced8bfb50f1741afaf3bd656 Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Eranian?= Date: Mon, 20 Oct 2003 02:25:31 -0700 Subject: [PATCH] [PATCH] ia64: two perfmon fixes - converts hdr_cur_pos into hdr_cur_offs to avoid leaking kernel addresses to userland. As a consequence hdr_last_pos is gone. - correct buffer saturation mode bug by which the hdr_count would be reset, leading to no visible samples collected. --- arch/ia64/kernel/perfmon_default_smpl.c | 21 ++++++++++----------- include/asm-ia64/perfmon_default_smpl.h | 5 +++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/arch/ia64/kernel/perfmon_default_smpl.c b/arch/ia64/kernel/perfmon_default_smpl.c index aedf99212c826..92f58ab8834f3 100644 --- a/arch/ia64/kernel/perfmon_default_smpl.c +++ b/arch/ia64/kernel/perfmon_default_smpl.c @@ -93,17 +93,17 @@ default_init(struct task_struct *task, void *buf, unsigned int flags, int cpu, v hdr->hdr_version = PFM_DEFAULT_SMPL_VERSION; hdr->hdr_buf_size = arg->buf_size; - hdr->hdr_cur_pos = (void *)((unsigned long)buf)+sizeof(*hdr); - hdr->hdr_last_pos = (void *)((unsigned long)buf)+arg->buf_size; + hdr->hdr_cur_offs = sizeof(*hdr); hdr->hdr_overflows = 0UL; hdr->hdr_count = 0UL; - DPRINT(("[%d] buffer=%p buf_size=%lu hdr_size=%lu hdr_version=%u\n", + DPRINT(("[%d] buffer=%p buf_size=%lu hdr_size=%lu hdr_version=%u cur_offs=%lu\n", task->pid, buf, hdr->hdr_buf_size, sizeof(*hdr), - hdr->hdr_version)); + hdr->hdr_version, + hdr->hdr_cur_offs)); return 0; } @@ -125,8 +125,8 @@ default_handler(struct task_struct *task, void *buf, pfm_ovfl_arg_t *arg, struct } hdr = (pfm_default_smpl_hdr_t *)buf; - cur = hdr->hdr_cur_pos; - last = hdr->hdr_last_pos; + cur = buf+hdr->hdr_cur_offs; + last = buf+hdr->hdr_buf_size; ovfl_pmd = arg->ovfl_pmd; ovfl_notify = arg->ovfl_notify; @@ -191,7 +191,7 @@ default_handler(struct task_struct *task, void *buf, pfm_ovfl_arg_t *arg, struct /* * update position for next entry */ - hdr->hdr_cur_pos = cur + sizeof(*ent) + (npmds << 3); + hdr->hdr_cur_offs += sizeof(*ent) + (npmds << 3); /* * keep same ovfl_pmds, ovfl_notify @@ -212,10 +212,9 @@ full: hdr->hdr_overflows++; /* - * if no notification is needed, then we saturate the buffer + * if no notification requested, then we saturate the buffer */ if (ovfl_notify == 0) { - hdr->hdr_count = 0UL; arg->ovfl_ctrl.bits.notify_user = 0; arg->ovfl_ctrl.bits.block_task = 0; arg->ovfl_ctrl.bits.mask_monitoring = 1; @@ -236,8 +235,8 @@ default_restart(struct task_struct *task, pfm_ovfl_ctrl_t *ctrl, void *buf, stru hdr = (pfm_default_smpl_hdr_t *)buf; - hdr->hdr_count = 0UL; - hdr->hdr_cur_pos = (void *)((unsigned long)buf)+sizeof(*hdr); + hdr->hdr_count = 0UL; + hdr->hdr_cur_offs = sizeof(*hdr); ctrl->bits.mask_monitoring = 0; ctrl->bits.reset_ovfl_pmds = 1; /* uses long-reset values */ diff --git a/include/asm-ia64/perfmon_default_smpl.h b/include/asm-ia64/perfmon_default_smpl.h index 1c63c7cf7f49f..9abd84d873f50 100644 --- a/include/asm-ia64/perfmon_default_smpl.h +++ b/include/asm-ia64/perfmon_default_smpl.h @@ -36,11 +36,12 @@ typedef struct { */ typedef struct { unsigned long hdr_count; /* how many valid entries */ - void *hdr_cur_pos; /* current position in the buffer */ - void *hdr_last_pos; /* first byte beyond buffer */ + unsigned long hdr_cur_offs; /* current offset from top of buffer */ + unsigned long hdr_reserved2; /* reserved for future use */ unsigned long hdr_overflows; /* how many times the buffer overflowed */ unsigned long hdr_buf_size; /* how many bytes in the buffer */ + unsigned int hdr_version; /* contains perfmon version (smpl format diffs) */ unsigned int hdr_reserved1; /* for future use */ unsigned long hdr_reserved[10]; /* for future use */ -- 2.53.0