[LTP] [PATCH 2/5] KVM: Add helper function for reading x86 segment registers
Martin Doucha
mdoucha@suse.cz
Fri Apr 21 16:57:43 CEST 2023
Signed-off-by: Martin Doucha <mdoucha@suse.cz>
---
doc/kvm-test-api.txt | 7 +++++++
testcases/kernel/kvm/bootstrap_x86.S | 19 +++++++++++++++++++
testcases/kernel/kvm/bootstrap_x86_64.S | 16 ++++++++++++++++
testcases/kernel/kvm/include/kvm_x86.h | 5 +++++
4 files changed, 47 insertions(+)
diff --git a/doc/kvm-test-api.txt b/doc/kvm-test-api.txt
index f62819764..0aede5eea 100644
--- a/doc/kvm-test-api.txt
+++ b/doc/kvm-test-api.txt
@@ -329,6 +329,10 @@ struct kvm_cpuid {
struct kvm_cregs {
unsigned long cr0, cr2, cr3, cr4;
};
+
+struct kvm_sregs {
+ uint16_t cs, ds, es, fs, gs, ss;
+};
-------------------------------------------------------------------------------
`struct page_table_entry_pae` is the page table entry structure for PAE and
@@ -370,6 +374,9 @@ Developer's Manual, Volume 3, Chapter 4 for explanation of the fields.
- `void kvm_read_cregs(struct kvm_cregs *buf)` – Copies the current values
of control registers to `buf`.
+- `void kvm_read_sregs(struct kvm_sregs *buf)` - Copies the current values
+ of segment registers to `buf`.
+
- `uint64_t kvm_rdmsr(unsigned int msr)` – Returns the current value
of model-specific register `msr`.
diff --git a/testcases/kernel/kvm/bootstrap_x86.S b/testcases/kernel/kvm/bootstrap_x86.S
index 3c17a2b47..89f73eba1 100644
--- a/testcases/kernel/kvm/bootstrap_x86.S
+++ b/testcases/kernel/kvm/bootstrap_x86.S
@@ -197,6 +197,25 @@ kvm_read_cregs:
pop %edi
ret
+.global kvm_read_sregs
+kvm_read_sregs:
+ push %edi
+ mov 8(%esp), %edi
+ mov %cs, %ax
+ movw %ax, (%edi)
+ mov %ds, %ax
+ movw %ax, 2(%edi)
+ mov %es, %ax
+ movw %ax, 4(%edi)
+ mov %fs, %ax
+ movw %ax, 6(%edi)
+ mov %gs, %ax
+ movw %ax, 8(%edi)
+ mov %ss, %ax
+ movw %ax, 10(%edi)
+ pop %edi
+ ret
+
handle_interrupt:
/* save CPU state */
push %ebp
diff --git a/testcases/kernel/kvm/bootstrap_x86_64.S b/testcases/kernel/kvm/bootstrap_x86_64.S
index 3d8c49b10..e4d160b2e 100644
--- a/testcases/kernel/kvm/bootstrap_x86_64.S
+++ b/testcases/kernel/kvm/bootstrap_x86_64.S
@@ -303,6 +303,22 @@ kvm_read_cregs:
mov %rax, 24(%rdi)
retq
+.global kvm_read_sregs
+kvm_read_sregs:
+ mov %cs, %ax
+ movw %ax, (%rdi)
+ mov %ds, %ax
+ movw %ax, 2(%rdi)
+ mov %es, %ax
+ movw %ax, 4(%rdi)
+ mov %fs, %ax
+ movw %ax, 6(%rdi)
+ mov %gs, %ax
+ movw %ax, 8(%rdi)
+ mov %ss, %ax
+ movw %ax, 10(%rdi)
+ retq
+
handle_interrupt:
/* push CPU state */
push %rbp
diff --git a/testcases/kernel/kvm/include/kvm_x86.h b/testcases/kernel/kvm/include/kvm_x86.h
index a655c9834..a94f05451 100644
--- a/testcases/kernel/kvm/include/kvm_x86.h
+++ b/testcases/kernel/kvm/include/kvm_x86.h
@@ -158,6 +158,10 @@ struct kvm_cregs {
unsigned long cr0, cr2, cr3, cr4;
};
+struct kvm_sregs {
+ uint16_t cs, ds, es, fs, gs, ss;
+};
+
extern struct page_table_entry_pae kvm_pagetable[];
extern struct intr_descriptor kvm_idt[X86_INTR_COUNT];
extern struct segment_descriptor kvm_gdt[KVM_GDT_SIZE];
@@ -178,6 +182,7 @@ unsigned int kvm_create_stack_descriptor(struct segment_descriptor *table,
/* Functions for querying CPU info and status */
void kvm_get_cpuid(unsigned int eax, unsigned int ecx, struct kvm_cpuid *buf);
void kvm_read_cregs(struct kvm_cregs *buf);
+void kvm_read_sregs(struct kvm_sregs *buf);
uint64_t kvm_rdmsr(unsigned int msr);
void kvm_wrmsr(unsigned int msr, uint64_t value);
--
2.40.0
More information about the ltp
mailing list