From 4b5b18f0cfbbad795afa505ace37e2e5654ee1c0 Mon Sep 17 00:00:00 2001 From: Mark Johnston Date: Wed, 4 Oct 2023 12:24:19 -0400 Subject: bhyve: Move AP startup code to amd64/ This code is only invoked via MD vmexit handlers. No functional change intended. Reviewed by: corvink, jhb MFC after: 1 week Sponsored by: Innovate UK Differential Revision: https://reviews.freebsd.org/D40737 (cherry picked from commit c7c5d3e3888aa9018297794285dcd884e6182bd5) --- usr.sbin/bhyve/Makefile | 1 - usr.sbin/bhyve/amd64/Makefile.inc | 1 + usr.sbin/bhyve/amd64/spinup_ap.c | 85 +++++++++++++++++++++++++++++++++++++++ usr.sbin/bhyve/amd64/spinup_ap.h | 34 ++++++++++++++++ usr.sbin/bhyve/spinup_ap.c | 85 --------------------------------------- usr.sbin/bhyve/spinup_ap.h | 34 ---------------- 6 files changed, 120 insertions(+), 120 deletions(-) create mode 100644 usr.sbin/bhyve/amd64/spinup_ap.c create mode 100644 usr.sbin/bhyve/amd64/spinup_ap.h delete mode 100644 usr.sbin/bhyve/spinup_ap.c delete mode 100644 usr.sbin/bhyve/spinup_ap.h diff --git a/usr.sbin/bhyve/Makefile b/usr.sbin/bhyve/Makefile index d510c32fccd0..f6db03a3358b 100644 --- a/usr.sbin/bhyve/Makefile +++ b/usr.sbin/bhyve/Makefile @@ -62,7 +62,6 @@ SRCS= \ rfb.c \ smbiostbl.c \ sockstream.c \ - spinup_ap.c \ tpm_device.c \ tpm_emul_passthru.c \ tpm_intf_crb.c \ diff --git a/usr.sbin/bhyve/amd64/Makefile.inc b/usr.sbin/bhyve/amd64/Makefile.inc index 5caecb35a620..824f12861923 100644 --- a/usr.sbin/bhyve/amd64/Makefile.inc +++ b/usr.sbin/bhyve/amd64/Makefile.inc @@ -10,6 +10,7 @@ SRCS+= \ ps2kbd.c \ ps2mouse.c \ rtc.c \ + spinup_ap.c \ task_switch.c \ xmsr.c diff --git a/usr.sbin/bhyve/amd64/spinup_ap.c b/usr.sbin/bhyve/amd64/spinup_ap.c new file mode 100644 index 000000000000..f874efcd374b --- /dev/null +++ b/usr.sbin/bhyve/amd64/spinup_ap.c @@ -0,0 +1,85 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2012 NetApp, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#include +#include + +#include +#include + +#include +#include +#include + +#include "bhyverun.h" +#include "spinup_ap.h" + +static void +spinup_ap_realmode(struct vcpu *newcpu, uint64_t rip) +{ + int vector, error; + uint16_t cs; + uint64_t desc_base; + uint32_t desc_limit, desc_access; + + vector = rip >> PAGE_SHIFT; + + /* + * Update the %cs and %rip of the guest so that it starts + * executing real mode code at at 'vector << 12'. + */ + error = vm_set_register(newcpu, VM_REG_GUEST_RIP, 0); + assert(error == 0); + + error = vm_get_desc(newcpu, VM_REG_GUEST_CS, &desc_base, + &desc_limit, &desc_access); + assert(error == 0); + + desc_base = vector << PAGE_SHIFT; + error = vm_set_desc(newcpu, VM_REG_GUEST_CS, + desc_base, desc_limit, desc_access); + assert(error == 0); + + cs = (vector << PAGE_SHIFT) >> 4; + error = vm_set_register(newcpu, VM_REG_GUEST_CS, cs); + assert(error == 0); +} + +void +spinup_ap(struct vcpu *newcpu, uint64_t rip) +{ + int error; + + error = vcpu_reset(newcpu); + assert(error == 0); + + spinup_ap_realmode(newcpu, rip); + + vm_resume_cpu(newcpu); +} diff --git a/usr.sbin/bhyve/amd64/spinup_ap.h b/usr.sbin/bhyve/amd64/spinup_ap.h new file mode 100644 index 000000000000..5877446297c2 --- /dev/null +++ b/usr.sbin/bhyve/amd64/spinup_ap.h @@ -0,0 +1,34 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2012 NetApp, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef _SPINUP_AP_H_ +#define _SPINUP_AP_H_ + +void spinup_ap(struct vcpu *newcpu, uint64_t rip); + +#endif diff --git a/usr.sbin/bhyve/spinup_ap.c b/usr.sbin/bhyve/spinup_ap.c deleted file mode 100644 index f874efcd374b..000000000000 --- a/usr.sbin/bhyve/spinup_ap.c +++ /dev/null @@ -1,85 +0,0 @@ -/*- - * SPDX-License-Identifier: BSD-2-Clause - * - * Copyright (c) 2012 NetApp, Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include -#include - -#include -#include - -#include -#include -#include - -#include "bhyverun.h" -#include "spinup_ap.h" - -static void -spinup_ap_realmode(struct vcpu *newcpu, uint64_t rip) -{ - int vector, error; - uint16_t cs; - uint64_t desc_base; - uint32_t desc_limit, desc_access; - - vector = rip >> PAGE_SHIFT; - - /* - * Update the %cs and %rip of the guest so that it starts - * executing real mode code at at 'vector << 12'. - */ - error = vm_set_register(newcpu, VM_REG_GUEST_RIP, 0); - assert(error == 0); - - error = vm_get_desc(newcpu, VM_REG_GUEST_CS, &desc_base, - &desc_limit, &desc_access); - assert(error == 0); - - desc_base = vector << PAGE_SHIFT; - error = vm_set_desc(newcpu, VM_REG_GUEST_CS, - desc_base, desc_limit, desc_access); - assert(error == 0); - - cs = (vector << PAGE_SHIFT) >> 4; - error = vm_set_register(newcpu, VM_REG_GUEST_CS, cs); - assert(error == 0); -} - -void -spinup_ap(struct vcpu *newcpu, uint64_t rip) -{ - int error; - - error = vcpu_reset(newcpu); - assert(error == 0); - - spinup_ap_realmode(newcpu, rip); - - vm_resume_cpu(newcpu); -} diff --git a/usr.sbin/bhyve/spinup_ap.h b/usr.sbin/bhyve/spinup_ap.h deleted file mode 100644 index 5877446297c2..000000000000 --- a/usr.sbin/bhyve/spinup_ap.h +++ /dev/null @@ -1,34 +0,0 @@ -/*- - * SPDX-License-Identifier: BSD-2-Clause - * - * Copyright (c) 2012 NetApp, Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef _SPINUP_AP_H_ -#define _SPINUP_AP_H_ - -void spinup_ap(struct vcpu *newcpu, uint64_t rip); - -#endif -- cgit v1.2.3