mbox series

[kvm-unit-tests,v5,0/8] Move npt test cases and NPT code improvements

Message ID 20220628113853.392569-1-manali.shukla@amd.com (mailing list archive)
Headers show
Series Move npt test cases and NPT code improvements | expand

Message

Manali Shukla June 28, 2022, 11:38 a.m. UTC
If __setup_vm() is changed to setup_vm(), KUT will build tests with PT_USER_MASK
set on all PTEs. It is a better idea to move nNPT tests to their own file so
that tests don't need to fiddle with page tables midway.

The quick approach to do this would be to turn the current main into a small
helper, without calling __setup_vm() from helper.

setup_mmu_range() function in vm.c was modified to allocate new user pages to
implement nested page table.

Current implementation of nested page table does the page table build up
statically with 2048 PTEs and one pml4 entry. With newly implemented routine,
nested page table can be implemented dynamically based on the RAM size of VM
which enables us to have separate memory ranges to test various npt test cases.

Based on this implementation, minimal changes were required to be done in
below mentioned existing APIs:
npt_get_pde(), npt_get_pte(), npt_get_pdpe().

v1 -> v2
Added new patch for building up a nested page table dynamically and did minimal
changes required to make it adaptable with old test cases.

v2 -> v3
Added new patch to change setup_mmu_range to use it in implementation of
nested page table.
Added new patches to correct indentation errors in svm.c, svm_npt.c and
svm_tests.c.
Used scripts/Lindent from linux source code to fix indentation errors.

v3 -> v4
Lindent script was not working as expected. So corrected indentation errors in
svm.c and svm_tests.c without using Lindent

v4 -> v5
Corrected commit messages for patches.
Incorporated comments provided in setup_mmu_range() function.

Manali Shukla (8):
  x86: nSVM: Move common functionality of the main() to helper
    run_svm_tests
  x86: nSVM: Move all nNPT test cases from svm_tests.c to a separate
    file.
  x86: nSVM: Allow nSVM tests run with PT_USER_MASK enabled
  x86: Improve set_mmu_range() to implement npt
  x86: nSVM: Build up the nested page table dynamically
  x86: nSVM: Correct indentation for svm.c
  x86: nSVM: Correct indentation for svm_tests.c part-1
  x86: nSVM: Correct indentation for svm_tests.c part-2

 lib/x86/vm.c        |   25 +-
 lib/x86/vm.h        |    8 +
 x86/Makefile.common |    2 +
 x86/Makefile.x86_64 |    2 +
 x86/svm.c           |  227 ++-
 x86/svm.h           |    5 +-
 x86/svm_npt.c       |  391 +++++
 x86/svm_tests.c     | 3365 +++++++++++++++++++------------------------
 x86/unittests.cfg   |    6 +
 9 files changed, 2034 insertions(+), 1997 deletions(-)
 create mode 100644 x86/svm_npt.c

Comments

Shukla, Manali July 12, 2022, 4:35 p.m. UTC | #1
On 6/28/2022 5:08 PM, Manali Shukla wrote:
> If __setup_vm() is changed to setup_vm(), KUT will build tests with PT_USER_MASK
> set on all PTEs. It is a better idea to move nNPT tests to their own file so
> that tests don't need to fiddle with page tables midway.
> 
> The quick approach to do this would be to turn the current main into a small
> helper, without calling __setup_vm() from helper.
> 
> setup_mmu_range() function in vm.c was modified to allocate new user pages to
> implement nested page table.
> 
> Current implementation of nested page table does the page table build up
> statically with 2048 PTEs and one pml4 entry. With newly implemented routine,
> nested page table can be implemented dynamically based on the RAM size of VM
> which enables us to have separate memory ranges to test various npt test cases.
> 
> Based on this implementation, minimal changes were required to be done in
> below mentioned existing APIs:
> npt_get_pde(), npt_get_pte(), npt_get_pdpe().
> 
> v1 -> v2
> Added new patch for building up a nested page table dynamically and did minimal
> changes required to make it adaptable with old test cases.
> 
> v2 -> v3
> Added new patch to change setup_mmu_range to use it in implementation of
> nested page table.
> Added new patches to correct indentation errors in svm.c, svm_npt.c and
> svm_tests.c.
> Used scripts/Lindent from linux source code to fix indentation errors.
> 
> v3 -> v4
> Lindent script was not working as expected. So corrected indentation errors in
> svm.c and svm_tests.c without using Lindent
> 
> v4 -> v5
> Corrected commit messages for patches.
> Incorporated comments provided in setup_mmu_range() function.
> 
> Manali Shukla (8):
>   x86: nSVM: Move common functionality of the main() to helper
>     run_svm_tests
>   x86: nSVM: Move all nNPT test cases from svm_tests.c to a separate
>     file.
>   x86: nSVM: Allow nSVM tests run with PT_USER_MASK enabled
>   x86: Improve set_mmu_range() to implement npt
>   x86: nSVM: Build up the nested page table dynamically
>   x86: nSVM: Correct indentation for svm.c
>   x86: nSVM: Correct indentation for svm_tests.c part-1
>   x86: nSVM: Correct indentation for svm_tests.c part-2
> 
>  lib/x86/vm.c        |   25 +-
>  lib/x86/vm.h        |    8 +
>  x86/Makefile.common |    2 +
>  x86/Makefile.x86_64 |    2 +
>  x86/svm.c           |  227 ++-
>  x86/svm.h           |    5 +-
>  x86/svm_npt.c       |  391 +++++
>  x86/svm_tests.c     | 3365 +++++++++++++++++++------------------------
>  x86/unittests.cfg   |    6 +
>  9 files changed, 2034 insertions(+), 1997 deletions(-)
>  create mode 100644 x86/svm_npt.c
> 

A gentle reminder

Thank you,
Manali
Sean Christopherson July 21, 2022, 7:15 p.m. UTC | #2
On Tue, Jun 28, 2022, Manali Shukla wrote:
> If __setup_vm() is changed to setup_vm(), KUT will build tests with PT_USER_MASK
> set on all PTEs. It is a better idea to move nNPT tests to their own file so
> that tests don't need to fiddle with page tables midway.
> 
> The quick approach to do this would be to turn the current main into a small
> helper, without calling __setup_vm() from helper.
> 
> setup_mmu_range() function in vm.c was modified to allocate new user pages to
> implement nested page table.
> 
> Current implementation of nested page table does the page table build up
> statically with 2048 PTEs and one pml4 entry. With newly implemented routine,
> nested page table can be implemented dynamically based on the RAM size of VM
> which enables us to have separate memory ranges to test various npt test cases.
> 
> Based on this implementation, minimal changes were required to be done in
> below mentioned existing APIs:
> npt_get_pde(), npt_get_pte(), npt_get_pdpe().

I have a variety of nits and minor complaints, but no need to send another version,
I'll fix things up as I go.  I'm going to send Paolo a pull request for KUT, there's
a big pile of outstanding changes that have been languishing.
Shukla, Manali July 22, 2022, 1 p.m. UTC | #3
On 7/22/2022 12:45 AM, Sean Christopherson wrote:
> On Tue, Jun 28, 2022, Manali Shukla wrote:
>> If __setup_vm() is changed to setup_vm(), KUT will build tests with PT_USER_MASK
>> set on all PTEs. It is a better idea to move nNPT tests to their own file so
>> that tests don't need to fiddle with page tables midway.
>>
>> The quick approach to do this would be to turn the current main into a small
>> helper, without calling __setup_vm() from helper.
>>
>> setup_mmu_range() function in vm.c was modified to allocate new user pages to
>> implement nested page table.
>>
>> Current implementation of nested page table does the page table build up
>> statically with 2048 PTEs and one pml4 entry. With newly implemented routine,
>> nested page table can be implemented dynamically based on the RAM size of VM
>> which enables us to have separate memory ranges to test various npt test cases.
>>
>> Based on this implementation, minimal changes were required to be done in
>> below mentioned existing APIs:
>> npt_get_pde(), npt_get_pte(), npt_get_pdpe().
> 
> I have a variety of nits and minor complaints, but no need to send another version,
> I'll fix things up as I go.  I'm going to send Paolo a pull request for KUT, there's
> a big pile of outstanding changes that have been languishing.

Sure Sean,
Thank you for the review.

-Manali