From: Andrew Cooper Date: Fri, 15 Nov 2019 13:23:03 +0000 (+0000) Subject: idt: Constify the xtf_idte parameter to xtf_set_idte() X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=7482af39dc2c6b9e90fa100cc35e3727283da6e0;p=people%2Fandrewcoop%2Fxen-test-framework.git idt: Constify the xtf_idte parameter to xtf_set_idte() It is only ever read. Take the opportunity to adjust all callers to construct their struct xtf_idte in .rodata. Signed-off-by: Andrew Cooper --- diff --git a/arch/x86/hvm/traps.c b/arch/x86/hvm/traps.c index 1e3df52..ae3d3ef 100644 --- a/arch/x86/hvm/traps.c +++ b/arch/x86/hvm/traps.c @@ -70,7 +70,7 @@ static env_tss tss_DF __aligned(16) = .iopb = X86_TSS_INVALID_IO_BITMAP, }; -int xtf_set_idte(unsigned int vector, struct xtf_idte *idte) +int xtf_set_idte(unsigned int vector, const struct xtf_idte *idte) { pack_intr_gate(&idt[vector], idte->cs, idte->addr, idte->dpl, 0); diff --git a/arch/x86/include/arch/idt.h b/arch/x86/include/arch/idt.h index 0a08f90..02955d5 100644 --- a/arch/x86/include/arch/idt.h +++ b/arch/x86/include/arch/idt.h @@ -40,7 +40,7 @@ struct xtf_idte * @returns 0 for HVM guests, hypercall result for PV guests. */ int xtf_set_idte(unsigned int vector, - struct xtf_idte *idte); + const struct xtf_idte *idte); #endif /* __ASSEMBLY__ */ diff --git a/arch/x86/pv/traps.c b/arch/x86/pv/traps.c index 3ff6cef..e70a680 100644 --- a/arch/x86/pv/traps.c +++ b/arch/x86/pv/traps.c @@ -65,7 +65,7 @@ struct xen_trap_info pv_default_trap_info[] = { 0, 0, 0, 0 }, /* Sentinel. */ }; -int xtf_set_idte(unsigned int vector, struct xtf_idte *idte) +int xtf_set_idte(unsigned int vector, const struct xtf_idte *idte) { struct xen_trap_info ti[2] = { diff --git a/tests/selftest/main.c b/tests/selftest/main.c index e39f1e7..a376df3 100644 --- a/tests/selftest/main.c +++ b/tests/selftest/main.c @@ -266,16 +266,15 @@ asm ("test_idte_handler:;" #endif ); +static const struct xtf_idte idte = { + .addr = _u(test_idte_handler), + /* PV guests need DPL1, HVM need DPL0. */ + .dpl = IS_DEFINED(CONFIG_PV) ? 1 : 0, + .cs = __KERN_CS, +}; + static void test_custom_idte(void) { - struct xtf_idte idte = - { - .addr = _u(test_idte_handler), - /* PV guests need DPL1, HVM need DPL0. */ - .dpl = IS_DEFINED(CONFIG_PV) ? 1 : 0, - .cs = __KERN_CS, - }; - printk("Test: Custom IDT entry\n"); int rc = xtf_set_idte(X86_VEC_AVAIL, &idte); diff --git a/tests/xsa-186/main.c b/tests/xsa-186/main.c index d39eca8..726acf3 100644 --- a/tests/xsa-186/main.c +++ b/tests/xsa-186/main.c @@ -47,6 +47,11 @@ asm(".align 16;" "iret" ); +static const struct xtf_idte idte = { + .addr = _u(test_int_handler), + .cs = __KERN_CS, +}; + /* Stub instruction buffer. */ asm(".align 16;" "insn_stub_start:;" @@ -75,12 +80,6 @@ static bool ex_fault(struct cpu_regs *regs, const struct extable_entry *ex) void test_main(void) { - struct xtf_idte idte = - { - .addr = _u(test_int_handler), - .cs = __KERN_CS, - }; - /* Hook test_int_handler() into the real IDT. */ xtf_set_idte(X86_VEC_AVAIL, &idte); diff --git a/tests/xsa-192/main.c b/tests/xsa-192/main.c index 1cf0f97..326ba20 100644 --- a/tests/xsa-192/main.c +++ b/tests/xsa-192/main.c @@ -36,6 +36,12 @@ asm(".align 16;" "jmp .Ltss_ret_point;" ); +static const struct xtf_idte idte = { + .addr = _u(ret_from_vm86), + .cs = __KERN_CS, + .dpl = 3, +}; + /* Virtual 8068 task. */ env_tss vm86_tss __aligned(16) = { @@ -75,13 +81,6 @@ unsigned long user_ldt_use(void) void test_main(void) { - struct xtf_idte idte = - { - .addr = _u(ret_from_vm86), - .cs = __KERN_CS, - .dpl = 3, - }; - /* Hook ret_from_vm86(). */ xtf_set_idte(X86_VEC_AVAIL, &idte); diff --git a/tests/xsa-196/main.c b/tests/xsa-196/main.c index 272108c..f50c333 100644 --- a/tests/xsa-196/main.c +++ b/tests/xsa-196/main.c @@ -37,6 +37,11 @@ asm(".align 16;" "iretq;" ); +static const struct xtf_idte idte = { + .addr = _u(custom_doublefault_handler), + .cs = __KERN_CS, +}; + unsigned long compat_userspace(void) { exinfo_t fault = 0; @@ -76,13 +81,6 @@ void test_main(void) ASSERT(idt[X86_EXC_OF].dpl == 3); ASSERT(idt[X86_EXC_DF].dpl == 0); - struct xtf_idte idte = - { - .addr = _u(custom_doublefault_handler), - .cs = __KERN_CS, - .dpl = 0, - }; - /* Hook the custom doublefault handler. */ xtf_set_idte(X86_EXC_DF, &idte); diff --git a/tests/xsa-213/main.c b/tests/xsa-213/main.c index a0c8a1b..64e7065 100644 --- a/tests/xsa-213/main.c +++ b/tests/xsa-213/main.c @@ -34,6 +34,12 @@ asm(".align 16;" "jmp multicall_return;" ); +static const struct xtf_idte idte = { + .addr = _u(recover_from_iret), + .cs = __KERN_CS, + .dpl = 3, +}; + /* Target of the __HYPERVISOR_iret hypercall. */ void iret_entry(void); asm (".pushsection .text.user;" @@ -111,13 +117,6 @@ static multicall_entry_t multi[] = { }, }; -static struct xtf_idte idte = -{ - .addr = (unsigned long)recover_from_iret, - .cs = __KERN_CS, - .dpl = 3, -}; - void test_main(void) { long rc, xen_version = hypercall_xen_version(XENVER_version, NULL);