Message ID | 20220628113853.392569-2-manali.shukla@amd.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Move npt test cases and NPT code improvements | expand |
On Tue, Jun 28, 2022, Manali Shukla wrote: > Move common functionalities of main() to run_svm_tests(), so that > nNPT tests can be moved to their own file to make other test cases run > without nNPT test cases fiddling with page table midway. > > The quick and dirty approach would be to turn the current main() > into a small helper, minus its call to __setup_vm() and call the > helper function run_svm_tests() from main() function. > > No functional change intended. > > Suggested-by: Sean Christopherson <seanjc@google.com> > Signed-off-by: Manali Shukla <manali.shukla@amd.com> > --- > x86/svm.c | 14 +++++++++----- > x86/svm.h | 1 + > 2 files changed, 10 insertions(+), 5 deletions(-) > > diff --git a/x86/svm.c b/x86/svm.c > index 93794fd..36ba05e 100644 > --- a/x86/svm.c > +++ b/x86/svm.c > @@ -397,17 +397,13 @@ test_wanted(const char *name, char *filters[], int filter_count) > } > } > > -int main(int ac, char **av) > +int run_svm_tests(int ac, char **av) > { > - /* Omit PT_USER_MASK to allow tested host.CR4.SMEP=1. */ > - pteval_t opt_mask = 0; > int i = 0; > > ac--; > av++; > > - __setup_vm(&opt_mask); > - > if (!this_cpu_has(X86_FEATURE_SVM)) { > printf("SVM not available\n"); > return report_summary(); > @@ -444,3 +440,11 @@ int main(int ac, char **av) > > return report_summary(); > } > + > +int main(int ac, char **av) > +{ > + pteval_t opt_mask = 0; > + > + __setup_vm(&opt_mask); > + return run_svm_tests(ac, av); Indentation is wrong. Yeah, the rest of the file has issues and this gets cleaned up in future patches, but that's no excuse for introducing _new_ badness. > +} > diff --git a/x86/svm.h b/x86/svm.h > index e93822b..123e64f 100644 > --- a/x86/svm.h > +++ b/x86/svm.h > @@ -403,6 +403,7 @@ struct regs { > > typedef void (*test_guest_func)(struct svm_test *); > > +int run_svm_tests(int ac, char **av); > u64 *npt_get_pte(u64 address); > u64 *npt_get_pde(u64 address); > u64 *npt_get_pdpe(void); > -- > 2.30.2 >
On Tue, Jun 28, 2022, Manali Shukla wrote: > Move common functionalities of main() to run_svm_tests(), so that > nNPT tests can be moved to their own file to make other test cases run > without nNPT test cases fiddling with page table midway. > > The quick and dirty approach would be to turn the current main() > into a small helper, minus its call to __setup_vm() and call the > helper function run_svm_tests() from main() function. > > No functional change intended. > > Suggested-by: Sean Christopherson <seanjc@google.com> > Signed-off-by: Manali Shukla <manali.shukla@amd.com> > --- > x86/svm.c | 14 +++++++++----- > x86/svm.h | 1 + > 2 files changed, 10 insertions(+), 5 deletions(-) > > diff --git a/x86/svm.c b/x86/svm.c > index 93794fd..36ba05e 100644 > --- a/x86/svm.c > +++ b/x86/svm.c > @@ -397,17 +397,13 @@ test_wanted(const char *name, char *filters[], int filter_count) > } > } > > -int main(int ac, char **av) > +int run_svm_tests(int ac, char **av) > { > - /* Omit PT_USER_MASK to allow tested host.CR4.SMEP=1. */ > - pteval_t opt_mask = 0; > int i = 0; > > ac--; > av++; > > - __setup_vm(&opt_mask); > - > if (!this_cpu_has(X86_FEATURE_SVM)) { > printf("SVM not available\n"); > return report_summary(); > @@ -444,3 +440,11 @@ int main(int ac, char **av) > > return report_summary(); > } > + > +int main(int ac, char **av) > +{ > + pteval_t opt_mask = 0; > + > + __setup_vm(&opt_mask); > + return run_svm_tests(ac, av); Pass in the test array instead of using a global svm_tests that needs to be defined in each file, which is gross and confusing. > +} > diff --git a/x86/svm.h b/x86/svm.h > index e93822b..123e64f 100644 > --- a/x86/svm.h > +++ b/x86/svm.h > @@ -403,6 +403,7 @@ struct regs { > > typedef void (*test_guest_func)(struct svm_test *); > > +int run_svm_tests(int ac, char **av); > u64 *npt_get_pte(u64 address); > u64 *npt_get_pde(u64 address); > u64 *npt_get_pdpe(void); > -- > 2.30.2 >
diff --git a/x86/svm.c b/x86/svm.c index 93794fd..36ba05e 100644 --- a/x86/svm.c +++ b/x86/svm.c @@ -397,17 +397,13 @@ test_wanted(const char *name, char *filters[], int filter_count) } } -int main(int ac, char **av) +int run_svm_tests(int ac, char **av) { - /* Omit PT_USER_MASK to allow tested host.CR4.SMEP=1. */ - pteval_t opt_mask = 0; int i = 0; ac--; av++; - __setup_vm(&opt_mask); - if (!this_cpu_has(X86_FEATURE_SVM)) { printf("SVM not available\n"); return report_summary(); @@ -444,3 +440,11 @@ int main(int ac, char **av) return report_summary(); } + +int main(int ac, char **av) +{ + pteval_t opt_mask = 0; + + __setup_vm(&opt_mask); + return run_svm_tests(ac, av); +} diff --git a/x86/svm.h b/x86/svm.h index e93822b..123e64f 100644 --- a/x86/svm.h +++ b/x86/svm.h @@ -403,6 +403,7 @@ struct regs { typedef void (*test_guest_func)(struct svm_test *); +int run_svm_tests(int ac, char **av); u64 *npt_get_pte(u64 address); u64 *npt_get_pde(u64 address); u64 *npt_get_pdpe(void);
Move common functionalities of main() to run_svm_tests(), so that nNPT tests can be moved to their own file to make other test cases run without nNPT test cases fiddling with page table midway. The quick and dirty approach would be to turn the current main() into a small helper, minus its call to __setup_vm() and call the helper function run_svm_tests() from main() function. No functional change intended. Suggested-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Manali Shukla <manali.shukla@amd.com> --- x86/svm.c | 14 +++++++++----- x86/svm.h | 1 + 2 files changed, 10 insertions(+), 5 deletions(-)