Skip to content

Commit 35f50c9

Browse files
mdrothsean-jc
authored andcommitted
KVM: selftests: Make sparsebit structs const where appropriate
Make all sparsebit struct pointers "const" where appropriate. This will allow adding a bitmap to track protected/encrypted physical memory that tests can access in a read-only fashion. Cc: Paolo Bonzini <[email protected]> Cc: Sean Christopherson <[email protected]> Cc: Vishal Annapurve <[email protected]> Cc: Ackerley Tng <[email protected]> Cc: Andrew Jones <[email protected]> Cc: Tom Lendacky <[email protected]> Cc: Michael Roth <[email protected]> Tested-by: Carlos Bilbao <[email protected]> Signed-off-by: Michael Roth <[email protected]> Signed-off-by: Peter Gonda <[email protected]> [sean: massage changelog] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent 1261903 commit 35f50c9

File tree

2 files changed

+42
-42
lines changed

2 files changed

+42
-42
lines changed

tools/testing/selftests/kvm/include/sparsebit.h

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,26 @@ typedef uint64_t sparsebit_num_t;
3030

3131
struct sparsebit *sparsebit_alloc(void);
3232
void sparsebit_free(struct sparsebit **sbitp);
33-
void sparsebit_copy(struct sparsebit *dstp, struct sparsebit *src);
33+
void sparsebit_copy(struct sparsebit *dstp, const struct sparsebit *src);
3434

35-
bool sparsebit_is_set(struct sparsebit *sbit, sparsebit_idx_t idx);
36-
bool sparsebit_is_set_num(struct sparsebit *sbit,
35+
bool sparsebit_is_set(const struct sparsebit *sbit, sparsebit_idx_t idx);
36+
bool sparsebit_is_set_num(const struct sparsebit *sbit,
3737
sparsebit_idx_t idx, sparsebit_num_t num);
38-
bool sparsebit_is_clear(struct sparsebit *sbit, sparsebit_idx_t idx);
39-
bool sparsebit_is_clear_num(struct sparsebit *sbit,
38+
bool sparsebit_is_clear(const struct sparsebit *sbit, sparsebit_idx_t idx);
39+
bool sparsebit_is_clear_num(const struct sparsebit *sbit,
4040
sparsebit_idx_t idx, sparsebit_num_t num);
41-
sparsebit_num_t sparsebit_num_set(struct sparsebit *sbit);
42-
bool sparsebit_any_set(struct sparsebit *sbit);
43-
bool sparsebit_any_clear(struct sparsebit *sbit);
44-
bool sparsebit_all_set(struct sparsebit *sbit);
45-
bool sparsebit_all_clear(struct sparsebit *sbit);
46-
sparsebit_idx_t sparsebit_first_set(struct sparsebit *sbit);
47-
sparsebit_idx_t sparsebit_first_clear(struct sparsebit *sbit);
48-
sparsebit_idx_t sparsebit_next_set(struct sparsebit *sbit, sparsebit_idx_t prev);
49-
sparsebit_idx_t sparsebit_next_clear(struct sparsebit *sbit, sparsebit_idx_t prev);
50-
sparsebit_idx_t sparsebit_next_set_num(struct sparsebit *sbit,
41+
sparsebit_num_t sparsebit_num_set(const struct sparsebit *sbit);
42+
bool sparsebit_any_set(const struct sparsebit *sbit);
43+
bool sparsebit_any_clear(const struct sparsebit *sbit);
44+
bool sparsebit_all_set(const struct sparsebit *sbit);
45+
bool sparsebit_all_clear(const struct sparsebit *sbit);
46+
sparsebit_idx_t sparsebit_first_set(const struct sparsebit *sbit);
47+
sparsebit_idx_t sparsebit_first_clear(const struct sparsebit *sbit);
48+
sparsebit_idx_t sparsebit_next_set(const struct sparsebit *sbit, sparsebit_idx_t prev);
49+
sparsebit_idx_t sparsebit_next_clear(const struct sparsebit *sbit, sparsebit_idx_t prev);
50+
sparsebit_idx_t sparsebit_next_set_num(const struct sparsebit *sbit,
5151
sparsebit_idx_t start, sparsebit_num_t num);
52-
sparsebit_idx_t sparsebit_next_clear_num(struct sparsebit *sbit,
52+
sparsebit_idx_t sparsebit_next_clear_num(const struct sparsebit *sbit,
5353
sparsebit_idx_t start, sparsebit_num_t num);
5454

5555
void sparsebit_set(struct sparsebit *sbitp, sparsebit_idx_t idx);
@@ -62,9 +62,9 @@ void sparsebit_clear_num(struct sparsebit *sbitp,
6262
sparsebit_idx_t start, sparsebit_num_t num);
6363
void sparsebit_clear_all(struct sparsebit *sbitp);
6464

65-
void sparsebit_dump(FILE *stream, struct sparsebit *sbit,
65+
void sparsebit_dump(FILE *stream, const struct sparsebit *sbit,
6666
unsigned int indent);
67-
void sparsebit_validate_internal(struct sparsebit *sbit);
67+
void sparsebit_validate_internal(const struct sparsebit *sbit);
6868

6969
#ifdef __cplusplus
7070
}

tools/testing/selftests/kvm/lib/sparsebit.c

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ static sparsebit_num_t node_num_set(struct node *nodep)
202202
/* Returns a pointer to the node that describes the
203203
* lowest bit index.
204204
*/
205-
static struct node *node_first(struct sparsebit *s)
205+
static struct node *node_first(const struct sparsebit *s)
206206
{
207207
struct node *nodep;
208208

@@ -216,7 +216,7 @@ static struct node *node_first(struct sparsebit *s)
216216
* lowest bit index > the index of the node pointed to by np.
217217
* Returns NULL if no node with a higher index exists.
218218
*/
219-
static struct node *node_next(struct sparsebit *s, struct node *np)
219+
static struct node *node_next(const struct sparsebit *s, struct node *np)
220220
{
221221
struct node *nodep = np;
222222

@@ -244,7 +244,7 @@ static struct node *node_next(struct sparsebit *s, struct node *np)
244244
* highest index < the index of the node pointed to by np.
245245
* Returns NULL if no node with a lower index exists.
246246
*/
247-
static struct node *node_prev(struct sparsebit *s, struct node *np)
247+
static struct node *node_prev(const struct sparsebit *s, struct node *np)
248248
{
249249
struct node *nodep = np;
250250

@@ -273,7 +273,7 @@ static struct node *node_prev(struct sparsebit *s, struct node *np)
273273
* subtree and duplicates the bit settings to the newly allocated nodes.
274274
* Returns the newly allocated copy of subtree.
275275
*/
276-
static struct node *node_copy_subtree(struct node *subtree)
276+
static struct node *node_copy_subtree(const struct node *subtree)
277277
{
278278
struct node *root;
279279

@@ -307,7 +307,7 @@ static struct node *node_copy_subtree(struct node *subtree)
307307
* index is within the bits described by the mask bits or the number of
308308
* contiguous bits set after the mask. Returns NULL if there is no such node.
309309
*/
310-
static struct node *node_find(struct sparsebit *s, sparsebit_idx_t idx)
310+
static struct node *node_find(const struct sparsebit *s, sparsebit_idx_t idx)
311311
{
312312
struct node *nodep;
313313

@@ -393,7 +393,7 @@ static struct node *node_add(struct sparsebit *s, sparsebit_idx_t idx)
393393
}
394394

395395
/* Returns whether all the bits in the sparsebit array are set. */
396-
bool sparsebit_all_set(struct sparsebit *s)
396+
bool sparsebit_all_set(const struct sparsebit *s)
397397
{
398398
/*
399399
* If any nodes there must be at least one bit set. Only case
@@ -775,7 +775,7 @@ static void node_reduce(struct sparsebit *s, struct node *nodep)
775775
/* Returns whether the bit at the index given by idx, within the
776776
* sparsebit array is set or not.
777777
*/
778-
bool sparsebit_is_set(struct sparsebit *s, sparsebit_idx_t idx)
778+
bool sparsebit_is_set(const struct sparsebit *s, sparsebit_idx_t idx)
779779
{
780780
struct node *nodep;
781781

@@ -921,7 +921,7 @@ static inline sparsebit_idx_t node_first_clear(struct node *nodep, int start)
921921
* used by test cases after they detect an unexpected condition, as a means
922922
* to capture diagnostic information.
923923
*/
924-
static void sparsebit_dump_internal(FILE *stream, struct sparsebit *s,
924+
static void sparsebit_dump_internal(FILE *stream, const struct sparsebit *s,
925925
unsigned int indent)
926926
{
927927
/* Dump the contents of s */
@@ -969,7 +969,7 @@ void sparsebit_free(struct sparsebit **sbitp)
969969
* sparsebit_alloc(). It can though already have bits set, which
970970
* if different from src will be cleared.
971971
*/
972-
void sparsebit_copy(struct sparsebit *d, struct sparsebit *s)
972+
void sparsebit_copy(struct sparsebit *d, const struct sparsebit *s)
973973
{
974974
/* First clear any bits already set in the destination */
975975
sparsebit_clear_all(d);
@@ -981,7 +981,7 @@ void sparsebit_copy(struct sparsebit *d, struct sparsebit *s)
981981
}
982982

983983
/* Returns whether num consecutive bits starting at idx are all set. */
984-
bool sparsebit_is_set_num(struct sparsebit *s,
984+
bool sparsebit_is_set_num(const struct sparsebit *s,
985985
sparsebit_idx_t idx, sparsebit_num_t num)
986986
{
987987
sparsebit_idx_t next_cleared;
@@ -1005,14 +1005,14 @@ bool sparsebit_is_set_num(struct sparsebit *s,
10051005
}
10061006

10071007
/* Returns whether the bit at the index given by idx. */
1008-
bool sparsebit_is_clear(struct sparsebit *s,
1008+
bool sparsebit_is_clear(const struct sparsebit *s,
10091009
sparsebit_idx_t idx)
10101010
{
10111011
return !sparsebit_is_set(s, idx);
10121012
}
10131013

10141014
/* Returns whether num consecutive bits starting at idx are all cleared. */
1015-
bool sparsebit_is_clear_num(struct sparsebit *s,
1015+
bool sparsebit_is_clear_num(const struct sparsebit *s,
10161016
sparsebit_idx_t idx, sparsebit_num_t num)
10171017
{
10181018
sparsebit_idx_t next_set;
@@ -1041,13 +1041,13 @@ bool sparsebit_is_clear_num(struct sparsebit *s,
10411041
* value. Use sparsebit_any_set(), instead of sparsebit_num_set() > 0,
10421042
* to determine if the sparsebit array has any bits set.
10431043
*/
1044-
sparsebit_num_t sparsebit_num_set(struct sparsebit *s)
1044+
sparsebit_num_t sparsebit_num_set(const struct sparsebit *s)
10451045
{
10461046
return s->num_set;
10471047
}
10481048

10491049
/* Returns whether any bit is set in the sparsebit array. */
1050-
bool sparsebit_any_set(struct sparsebit *s)
1050+
bool sparsebit_any_set(const struct sparsebit *s)
10511051
{
10521052
/*
10531053
* Nodes only describe set bits. If any nodes then there
@@ -1070,20 +1070,20 @@ bool sparsebit_any_set(struct sparsebit *s)
10701070
}
10711071

10721072
/* Returns whether all the bits in the sparsebit array are cleared. */
1073-
bool sparsebit_all_clear(struct sparsebit *s)
1073+
bool sparsebit_all_clear(const struct sparsebit *s)
10741074
{
10751075
return !sparsebit_any_set(s);
10761076
}
10771077

10781078
/* Returns whether all the bits in the sparsebit array are set. */
1079-
bool sparsebit_any_clear(struct sparsebit *s)
1079+
bool sparsebit_any_clear(const struct sparsebit *s)
10801080
{
10811081
return !sparsebit_all_set(s);
10821082
}
10831083

10841084
/* Returns the index of the first set bit. Abort if no bits are set.
10851085
*/
1086-
sparsebit_idx_t sparsebit_first_set(struct sparsebit *s)
1086+
sparsebit_idx_t sparsebit_first_set(const struct sparsebit *s)
10871087
{
10881088
struct node *nodep;
10891089

@@ -1097,7 +1097,7 @@ sparsebit_idx_t sparsebit_first_set(struct sparsebit *s)
10971097
/* Returns the index of the first cleared bit. Abort if
10981098
* no bits are cleared.
10991099
*/
1100-
sparsebit_idx_t sparsebit_first_clear(struct sparsebit *s)
1100+
sparsebit_idx_t sparsebit_first_clear(const struct sparsebit *s)
11011101
{
11021102
struct node *nodep1, *nodep2;
11031103

@@ -1151,7 +1151,7 @@ sparsebit_idx_t sparsebit_first_clear(struct sparsebit *s)
11511151
/* Returns index of next bit set within s after the index given by prev.
11521152
* Returns 0 if there are no bits after prev that are set.
11531153
*/
1154-
sparsebit_idx_t sparsebit_next_set(struct sparsebit *s,
1154+
sparsebit_idx_t sparsebit_next_set(const struct sparsebit *s,
11551155
sparsebit_idx_t prev)
11561156
{
11571157
sparsebit_idx_t lowest_possible = prev + 1;
@@ -1244,7 +1244,7 @@ sparsebit_idx_t sparsebit_next_set(struct sparsebit *s,
12441244
/* Returns index of next bit cleared within s after the index given by prev.
12451245
* Returns 0 if there are no bits after prev that are cleared.
12461246
*/
1247-
sparsebit_idx_t sparsebit_next_clear(struct sparsebit *s,
1247+
sparsebit_idx_t sparsebit_next_clear(const struct sparsebit *s,
12481248
sparsebit_idx_t prev)
12491249
{
12501250
sparsebit_idx_t lowest_possible = prev + 1;
@@ -1300,7 +1300,7 @@ sparsebit_idx_t sparsebit_next_clear(struct sparsebit *s,
13001300
* and returns the index of the first sequence of num consecutively set
13011301
* bits. Returns a value of 0 of no such sequence exists.
13021302
*/
1303-
sparsebit_idx_t sparsebit_next_set_num(struct sparsebit *s,
1303+
sparsebit_idx_t sparsebit_next_set_num(const struct sparsebit *s,
13041304
sparsebit_idx_t start, sparsebit_num_t num)
13051305
{
13061306
sparsebit_idx_t idx;
@@ -1335,7 +1335,7 @@ sparsebit_idx_t sparsebit_next_set_num(struct sparsebit *s,
13351335
* and returns the index of the first sequence of num consecutively cleared
13361336
* bits. Returns a value of 0 of no such sequence exists.
13371337
*/
1338-
sparsebit_idx_t sparsebit_next_clear_num(struct sparsebit *s,
1338+
sparsebit_idx_t sparsebit_next_clear_num(const struct sparsebit *s,
13391339
sparsebit_idx_t start, sparsebit_num_t num)
13401340
{
13411341
sparsebit_idx_t idx;
@@ -1583,7 +1583,7 @@ static size_t display_range(FILE *stream, sparsebit_idx_t low,
15831583
* contiguous bits. This is done because '-' is used to specify command-line
15841584
* options, and sometimes ranges are specified as command-line arguments.
15851585
*/
1586-
void sparsebit_dump(FILE *stream, struct sparsebit *s,
1586+
void sparsebit_dump(FILE *stream, const struct sparsebit *s,
15871587
unsigned int indent)
15881588
{
15891589
size_t current_line_len = 0;
@@ -1681,7 +1681,7 @@ void sparsebit_dump(FILE *stream, struct sparsebit *s,
16811681
* s. On error, diagnostic information is printed to stderr and
16821682
* abort is called.
16831683
*/
1684-
void sparsebit_validate_internal(struct sparsebit *s)
1684+
void sparsebit_validate_internal(const struct sparsebit *s)
16851685
{
16861686
bool error_detected = false;
16871687
struct node *nodep, *prev = NULL;

0 commit comments

Comments
 (0)