Skip to content

Commit

Permalink
Single source of truth for version information. (LLNL#168)
Browse files Browse the repository at this point in the history
msr_version.h
	#defines for major, minor, and patch versions of msr-safe
	as well as helper macros to generate _u32 and string
	representation.

Makefile
	Removes CURRENT_VERSION and -DVERSION from build.
	msrsave now gets the version string from msr_version.h

msrsave_main.c
msr_entry.c
	Now #includes msr_version.h and uses MSR_SAFE_VERSION_STR

msr_safe.h
	Repurposes a bit of struct padding to hold a _u32-format
	msr-safe version number.

README.md
	Updates documentation of struct msr_batch_array to note
	the new version field.  Explains how this will remain
	unused in the 1.x.y series.  Version 2.x.y will begin
	checking this version field to make sure what the user
	compiled against is the same version as the loaded
	kernel module.  This is necessary due to anticipated
	batch API changes in version 2.0.0.

Tested on serif (Ubuntu 24.04.1 LTS, Linux 6.8.0, gcc 13.2.0)

* Format cleanup

Per Stephanie.

* remove extra space

* replace tabs with spaces

---------

Co-authored-by: Barry <rountree4@llnl.gov>
Co-authored-by: Stephanie Brink <brink2@llnl.gov>
  • Loading branch information
3 people authored Sep 23, 2024
1 parent d9fd51a commit 401b07f
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 13 deletions.
9 changes: 3 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,14 @@ clean:
check: msrsave/msrsave_test
msrsave/msrsave_test

# current msr-safe/msrsave version
CURRENT_VERSION := -DVERSION=\"1.7.0\"

msrsave/msrsave.o: msrsave/msrsave.c msrsave/msrsave.h
$(CC) $(CFLAGS) $(CURRENT_VERSION) -fPIC -c msrsave/msrsave.c -o $@
$(CC) $(CFLAGS) -fPIC -c msrsave/msrsave.c -o $@

msrsave/msrsave_main.o: msrsave/msrsave_main.c msrsave/msrsave.h
$(CC) $(CFLAGS) $(CURRENT_VERSION) -fPIC -c msrsave/msrsave_main.c -o $@
$(CC) $(CFLAGS) -fPIC -c msrsave/msrsave_main.c -o $@

msrsave/msrsave: msrsave/msrsave_main.o msrsave/msrsave.o
$(CC) $(CFLAGS) $(CURRENT_VERSION) $^ -o $@
$(CC) $(CFLAGS) $^ -o $@

msrsave/msrsave_test.o: msrsave/msrsave_test.c msrsave/msrsave.h

Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,19 @@ being a pointer to a __struct msr_batch_array__.
struct msr_batch_array
{
__u32 numops; // In: # of operations in operations array
__u32 version; // In: MSR_SAFE_VERSION_u32 (see msr_version.h)
struct msr_batch_op *ops; // In: Array[numops] of operations
};
```

The maximum __numops__ is system-dependent, but 30k operations is not
unheard-of. Each op is contained in a __struct msr_batch_op__:
unheard-of.

Starting in version 2.0.0, the __version__ field will be
compared to the version of the loaded kernel module with a mismatch
resulting in an error. Earlier versions do not check this field.

Each op is contained in a __struct msr_batch_op__:

```
struct msr_batch_op
Expand Down
2 changes: 1 addition & 1 deletion msr_entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -411,5 +411,5 @@ module_exit(msr_exit)

MODULE_AUTHOR("M. Fadden, K. Shoga, B. Rountree, H. P. Anvin");
MODULE_DESCRIPTION("x86 generic MSR driver (+LLNL Approved List)");
MODULE_VERSION("1.7");
MODULE_VERSION(MSR_SAFE_VERSION_STR);
MODULE_LICENSE("GPL");
1 change: 1 addition & 0 deletions msr_safe.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ struct msr_batch_op
struct msr_batch_array
{
__u32 numops; // In: # of operations in operations array
__u32 version; // In: MSR_SAFE_VERSION_u32 (see msr_version.h)
struct msr_batch_op *ops; // In: Array[numops] of operations
};

Expand Down
22 changes: 22 additions & 0 deletions msr_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,26 @@ int msr_version_init(int *majordev);

void msr_version_cleanup(int majordev);

#define MSR_SAFE_VERSION_MAJOR 1
#define MSR_SAFE_VERSION_MINOR 8
#define MSR_SAFE_VERSION_PATCH 0

#define MSR_SAFE_VERSION_u32 ( \
( MSR_SAFE_VERSION_MAJOR << 16 ) \
| ( MSR_SAFE_VERSION_MINOR << 8 ) \
| ( MSR_SAFE_VERSION_PATCH << 0 ) )

#define MAKESTRING( s ) #s
#define MAKE_VERSION_STRING(major,minor,patch) \
MAKESTRING( major ) \
"." \
MAKESTRING( minor ) \
"." \
MAKESTRING( patch )

#define MSR_SAFE_VERSION_STR MAKE_VERSION_STRING(\
MSR_SAFE_VERSION_MAJOR,\
MSR_SAFE_VERSION_MINOR,\
MSR_SAFE_VERSION_PATCH)

#endif
7 changes: 2 additions & 5 deletions msrsave/msrsave_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@
#include <unistd.h>

#include "msrsave.h"

#ifndef VERSION
#define VERSION "0.0.0"
#endif
#include "../msr_version.h"

int main(int argc, char **argv)
{
Expand Down Expand Up @@ -59,7 +56,7 @@ int main(int argc, char **argv)

if (argc > 1 && strncmp(argv[1], "--version", strlen("--version") + 1) == 0)
{
printf("%s\n", VERSION);
printf("%s\n", MSR_SAFE_VERSION_STR);
printf("\nCopyright (C) 2016, Intel Corporation. All rights reserved.\n\n");
return 0;
}
Expand Down

0 comments on commit 401b07f

Please sign in to comment.