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

Toss4 cleanup #166

Merged
merged 6 commits into from
Sep 23, 2024
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
30 changes: 20 additions & 10 deletions msr_allowlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,15 +359,25 @@ static int parse_next_allowlist_entry(char *inbuf, char **nextinbuf, struct allo
return *nextinbuf - inbuf;
}

#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,39)
static char *msr_allowlist_nodename(struct device *dev, mode_t *mode)
#else
#if LINUX_VERSION_CODE <= KERNEL_VERSION(6,2,0)
static char *msr_allowlist_nodename(struct device *dev, umode_t *mode)
#else
static char *msr_allowlist_nodename(const struct device *dev, umode_t *mode)
#endif
#endif

#define msr_allowlist_nodename_selector _Generic(\
(((struct class *)0)->devnode),\
char* (*) (struct device *, mode_t *) : msr_allowlist_nodename1,\
char* (*) (struct device *, umode_t *) : msr_allowlist_nodename2,\
char* (*) (const struct device *, umode_t *) : msr_allowlist_nodename3 \
)

static char *msr_allowlist_nodename1(struct device *dev, mode_t *mode)
{
return kasprintf(GFP_KERNEL, "cpu/msr_allowlist");
}
slabasan marked this conversation as resolved.
Show resolved Hide resolved

static char *msr_allowlist_nodename2(struct device *dev, umode_t *mode)
{
return kasprintf(GFP_KERNEL, "cpu/msr_allowlist");
}

static char *msr_allowlist_nodename3(const struct device *dev, umode_t *mode)
{
return kasprintf(GFP_KERNEL, "cpu/msr_allowlist");
}
Expand Down Expand Up @@ -427,7 +437,7 @@ int msr_allowlist_init(int *majordev)
}
cdev_class_created = 1;

cdev_class->devnode = msr_allowlist_nodename;
cdev_class->devnode = msr_allowlist_nodename_selector;

dev = device_create(cdev_class, NULL, MKDEV(*majordev, 0), NULL, "msr_allowlist");
if (IS_ERR(dev))
Expand Down
29 changes: 19 additions & 10 deletions msr_batch.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,24 @@ void msrbatch_cleanup(int majordev)
}
}

#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,39)
static char *msrbatch_nodename(struct device *dev, mode_t *mode)
#else
#if LINUX_VERSION_CODE <= KERNEL_VERSION(6,2,0)
static char *msrbatch_nodename(struct device *dev, umode_t *mode)
#else
static char *msrbatch_nodename(const struct device *dev, umode_t *mode)
#endif
#endif
#define msrbatch_nodename_selector _Generic(\
(((struct class *)0)->devnode),\
char* (*) ( struct device *, mode_t *) : msrbatch_nodename1,\
char* (*) ( struct device *, umode_t *) : msrbatch_nodename2,\
char* (*) (const struct device *, umode_t *) : msrbatch_nodename3 \
)

static char *msrbatch_nodename1(struct device *dev, mode_t *mode)
{
return kasprintf(GFP_KERNEL, "cpu/msr_batch");
}

static char *msrbatch_nodename2(struct device *dev, umode_t *mode)
{
return kasprintf(GFP_KERNEL, "cpu/msr_batch");
}

static char *msrbatch_nodename3(const struct device *dev, umode_t *mode)
{
return kasprintf(GFP_KERNEL, "cpu/msr_batch");
}
Expand Down Expand Up @@ -224,7 +233,7 @@ int msrbatch_init(int *majordev)
}
cdev_class_created = 1;

cdev_class->devnode = msrbatch_nodename;
cdev_class->devnode = msrbatch_nodename_selector;

dev = device_create(cdev_class, NULL, MKDEV(*majordev, 0), NULL, "msr_batch");
if (IS_ERR(dev))
Expand Down
35 changes: 25 additions & 10 deletions msr_entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,15 +254,30 @@ static struct notifier_block __refdata msr_class_cpu_notifier =
};
#endif

#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,39)
static char *msr_devnode(struct device *dev, mode_t *mode)
#else
#if LINUX_VERSION_CODE <= KERNEL_VERSION(6,2,0)
static char *msr_devnode(struct device *dev, umode_t *mode)
#else
static char *msr_devnode(const struct device *dev, umode_t *mode)
#endif
#endif
/* The type of (((struct class *)0)->devnode) has changed at least
* twice in the mainline linux kernel. Trying to pin these changes
* to specific mainline kernel versions runs into the problem of
* distros backporting features to older kernels. Instead, we are
* now keying off of the change in the parameter types.*/

#define msr_devnode_selector _Generic(\
(((struct class *)0)->devnode),\
char * (*) (struct device *, mode_t *) : msr_devnode1,\
char * (*) (struct device *, umode_t *) : msr_devnode2,\
char * (*) (const struct device *, umode_t *) : msr_devnode3\
)

static char *msr_devnode1(struct device *dev, mode_t *mode)
{
return kasprintf(GFP_KERNEL, "cpu/%u/msr_safe", MINOR(dev->devt));
}

static char *msr_devnode2(struct device *dev, umode_t *mode)
{
return kasprintf(GFP_KERNEL, "cpu/%u/msr_safe", MINOR(dev->devt));
}

static char *msr_devnode3(const struct device *dev, umode_t *mode)
{
return kasprintf(GFP_KERNEL, "cpu/%u/msr_safe", MINOR(dev->devt));
}
Expand Down Expand Up @@ -329,7 +344,7 @@ static int __init msr_init(void)
err = PTR_ERR(msr_class);
goto out_chrdev;
}
msr_class->devnode = msr_devnode;
msr_class->devnode = msr_devnode_selector;

#if LINUX_VERSION_CODE < KERNEL_VERSION(4,10,0)
i = 0;
Expand Down
37 changes: 27 additions & 10 deletions msr_version.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,32 @@ static const struct file_operations fops =
.open = open_version
};

#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,39)
static char *msr_version_nodename(struct device *dev, mode_t *mode)
#else
#if LINUX_VERSION_CODE <= KERNEL_VERSION(6,2,0)
static char *msr_version_nodename(struct device *dev, umode_t *mode)
#else
static char *msr_version_nodename(const struct device *dev, umode_t *mode)
#endif
#endif
#define msr_version_nodename_selector _Generic(\
(((struct class *)0)->devnode),\
char * (*) ( struct device *, mode_t *) : msr_version_nodename1,\
char * (*) ( struct device *, umode_t *) : msr_version_nodename2,\
char * (*) (const struct device *, umode_t *) : msr_version_nodename3 \
)

static char *msr_version_nodename1(struct device *dev, mode_t *mode)
{
if (mode)
{
*mode = 0400; // read-only
}
return kasprintf(GFP_KERNEL, "cpu/msr_safe_version");
}

static char *msr_version_nodename2(struct device *dev, umode_t *mode)
{
if (mode)
{
*mode = 0400; // read-only
}
return kasprintf(GFP_KERNEL, "cpu/msr_safe_version");
}

static char *msr_version_nodename3(const struct device *dev, umode_t *mode)
{
if (mode)
{
Expand Down Expand Up @@ -120,7 +137,7 @@ int msr_version_init(int *majordev)
}
cdev_class_created = 1;

cdev_class->devnode = msr_version_nodename;
cdev_class->devnode = msr_version_nodename_selector;

dev = device_create(cdev_class, NULL, MKDEV(*majordev, 0), NULL, "msr_safe_version");
if (IS_ERR(dev))
Expand Down
Loading