Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix driver build for RHEL 7.7/4.13+ w/CONFIG_VIRT_CPU_ACCOUNTING_GEN #1471

Merged
merged 3 commits into from
Aug 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions driver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ set(DRIVER_SOURCES
syscall_table.c
ppm_cputime.c
ppm_compat_unistd_32.h
ppm_version.h
)

foreach(FILENAME IN LISTS DRIVER_SOURCES)
Expand Down
26 changes: 19 additions & 7 deletions driver/ppm_cputime.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ or GPL2.txt for full copies of the license.
#include "ppm_events_public.h"
#include "ppm_events.h"
#include "ppm.h"
#include "ppm_version.h"

#if (defined CONFIG_VIRT_CPU_ACCOUNTING_NATIVE) || (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 30))
void ppm_task_cputime_adjusted(struct task_struct *p, cputime_t *ut, cputime_t *st)
Expand All @@ -48,15 +49,26 @@ void ppm_task_cputime_adjusted(struct task_struct *p, cputime_t *ut, cputime_t *
#endif

#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN

#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 13, 0)) || (PPM_RHEL_RELEASE_CODE > 0 && PPM_RHEL_RELEASE_CODE >= PPM_RHEL_RELEASE_VERSION(7, 7))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment would be nice

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a comment to the PPM_* macros but I'm not sure what I can say here that isn't already expressed by the code. If we're building for >= 4.13 or for RHEL >= 7.7, use the new macros, otherwise use the old ones.

#define ppm_vtime_starttime(tsk) ((tsk)->vtime.starttime)
#define ppm_vtime_seqlock(tsk) (&(tsk)->vtime.seqlock)
#define ppm_vtime_state(tsk) ((tsk)->vtime.state)
#else
#define ppm_vtime_starttime(tsk) ((tsk)->vtime_snap)
#define ppm_vtime_seqlock(tsk) (&(tsk)->vtime_seqlock)
#define ppm_vtime_state(tsk) ((tsk)->vtime_snap_whence)
#endif

static unsigned long long vtime_delta(struct task_struct *tsk)
{
unsigned long long clock;

clock = local_clock();
if (clock < tsk->vtime_snap)
if (clock < ppm_vtime_starttime(tsk))
return 0;

return clock - tsk->vtime_snap;
return clock - ppm_vtime_starttime(tsk);
}

static void
Expand All @@ -72,15 +84,15 @@ fetch_task_cputime(struct task_struct *t,
*udelta = 0;
*sdelta = 0;

seq = read_seqbegin(&t->vtime_seqlock);
seq = read_seqbegin(ppm_vtime_seqlock(t));

if (u_dst)
*u_dst = *u_src;
if (s_dst)
*s_dst = *s_src;

/* Task is sleeping, nothing to add */
if (t->vtime_snap_whence == VTIME_SLEEPING ||
if (t->vtime.state == VTIME_SLEEPING ||
is_idle_task(t))
continue;

Expand All @@ -90,13 +102,13 @@ fetch_task_cputime(struct task_struct *t,
* Task runs either in user or kernel space, add pending nohz time to
* the right place.
*/
if (t->vtime_snap_whence == VTIME_USER || t->flags & PF_VCPU) {
if (t->vtime.state == VTIME_USER || t->flags & PF_VCPU) {
*udelta = delta;
} else {
if (t->vtime_snap_whence == VTIME_SYS)
if (t->vtime.state == VTIME_SYS)
*sdelta = delta;
}
} while (read_seqretry(&t->vtime_seqlock, seq));
} while (read_seqretry(ppm_vtime_seqlock(t), seq));
}

void task_cputime(struct task_struct *t, cputime_t *utime, cputime_t *stime)
Expand Down
7 changes: 4 additions & 3 deletions driver/ppm_events.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ or GPL2.txt for full copies of the license.
#include "ppm_events.h"
#include "ppm.h"
#include "ppm_flag_helpers.h"
#include "ppm_version.h"

/*
* The kernel patched with grsecurity makes the default access_ok trigger a
Expand All @@ -46,10 +47,10 @@ or GPL2.txt for full copies of the license.
#ifdef access_ok_noprefault
#define ppm_access_ok access_ok_noprefault
#else
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 0, 0)
#define ppm_access_ok(type, addr, size) access_ok(type, addr, size)
#else
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 0, 0)) || (PPM_RHEL_RELEASE_CODE > 0 && PPM_RHEL_RELEASE_CODE >= PPM_RHEL_RELEASE_VERSION(8, 1))
#define ppm_access_ok(type, addr, size) access_ok(addr, size)
#else
#define ppm_access_ok(type, addr, size) access_ok(type, addr, size)
#endif
#endif

Expand Down
18 changes: 18 additions & 0 deletions driver/ppm_version.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <linux/version.h>

/**
* for RHEL kernels, export the release code (which is equal to e.g.
* RHEL_RELEASE_CODE(8, 1)) under our own name.
* For other kernels, just use zeros.
*
* We need macros that are always defined to use in preprocessor directives
* to express the required kernel version in a single expression, without
* a multiline #ifdef soup.
*/
#ifdef RHEL_RELEASE_CODE
gnosek marked this conversation as resolved.
Show resolved Hide resolved
#define PPM_RHEL_RELEASE_CODE RHEL_RELEASE_CODE
#define PPM_RHEL_RELEASE_VERSION(x,y) RHEL_RELEASE_VERSION(x,y)
#else
#define PPM_RHEL_RELEASE_CODE 0
#define PPM_RHEL_RELEASE_VERSION(x,y) 0
#endif