1bf21cd93STycho Nightingale /*- 2*32640292SAndy Fiddaman * SPDX-License-Identifier: BSD-2-Clause 34c87aefeSPatrick Mooney * 4bf21cd93STycho Nightingale * Copyright (c) 2011 NetApp, Inc. 5bf21cd93STycho Nightingale * All rights reserved. 6bf21cd93STycho Nightingale * 7bf21cd93STycho Nightingale * Redistribution and use in source and binary forms, with or without 8bf21cd93STycho Nightingale * modification, are permitted provided that the following conditions 9bf21cd93STycho Nightingale * are met: 10bf21cd93STycho Nightingale * 1. Redistributions of source code must retain the above copyright 11bf21cd93STycho Nightingale * notice, this list of conditions and the following disclaimer. 12bf21cd93STycho Nightingale * 2. Redistributions in binary form must reproduce the above copyright 13bf21cd93STycho Nightingale * notice, this list of conditions and the following disclaimer in the 14bf21cd93STycho Nightingale * documentation and/or other materials provided with the distribution. 15bf21cd93STycho Nightingale * 16bf21cd93STycho Nightingale * THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND 17bf21cd93STycho Nightingale * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18bf21cd93STycho Nightingale * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19bf21cd93STycho Nightingale * ARE DISCLAIMED. IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE 20bf21cd93STycho Nightingale * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21bf21cd93STycho Nightingale * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22bf21cd93STycho Nightingale * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23bf21cd93STycho Nightingale * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24bf21cd93STycho Nightingale * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25bf21cd93STycho Nightingale * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26bf21cd93STycho Nightingale * SUCH DAMAGE. 27bf21cd93STycho Nightingale */ 286b641d7aSPatrick Mooney /* 296b641d7aSPatrick Mooney * Copyright 2021 Oxide Computer Company 306b641d7aSPatrick Mooney */ 31bf21cd93STycho Nightingale 32bf21cd93STycho Nightingale #ifndef _VMX_MSR_H_ 33bf21cd93STycho Nightingale #define _VMX_MSR_H_ 34bf21cd93STycho Nightingale 35bf21cd93STycho Nightingale void vmx_msr_init(void); 36bf21cd93STycho Nightingale void vmx_msr_guest_init(struct vmx *vmx, int vcpuid); 37bf21cd93STycho Nightingale void vmx_msr_guest_enter(struct vmx *vmx, int vcpuid); 38bf21cd93STycho Nightingale void vmx_msr_guest_exit(struct vmx *vmx, int vcpuid); 39d2f938fdSPatrick Mooney vm_msr_result_t vmx_rdmsr(struct vmx *, int, uint32_t, uint64_t *); 40d2f938fdSPatrick Mooney vm_msr_result_t vmx_wrmsr(struct vmx *, int, uint32_t, uint64_t); 41bf21cd93STycho Nightingale 42bf21cd93STycho Nightingale int vmx_set_ctlreg(int ctl_reg, int true_ctl_reg, uint32_t ones_mask, 432699b94cSPatrick Mooney uint32_t zeros_mask, uint32_t *retval); 44bf21cd93STycho Nightingale 45bf21cd93STycho Nightingale /* 46bf21cd93STycho Nightingale * According to Section 21.10.4 "Software Access to Related Structures", 47bf21cd93STycho Nightingale * changes to data structures pointed to by the VMCS must be made only when 48bf21cd93STycho Nightingale * there is no logical processor with a current VMCS that points to the 49bf21cd93STycho Nightingale * data structure. 50bf21cd93STycho Nightingale * 51bf21cd93STycho Nightingale * This pretty much limits us to configuring the MSR bitmap before VMCS 52bf21cd93STycho Nightingale * initialization for SMP VMs. Unless of course we do it the hard way - which 53bf21cd93STycho Nightingale * would involve some form of synchronization between the vcpus to vmclear 54bf21cd93STycho Nightingale * all VMCSs' that point to the bitmap. 55bf21cd93STycho Nightingale */ 56bf21cd93STycho Nightingale #define MSR_BITMAP_ACCESS_NONE 0x0 57bf21cd93STycho Nightingale #define MSR_BITMAP_ACCESS_READ 0x1 58bf21cd93STycho Nightingale #define MSR_BITMAP_ACCESS_WRITE 0x2 59bf21cd93STycho Nightingale #define MSR_BITMAP_ACCESS_RW (MSR_BITMAP_ACCESS_READ|MSR_BITMAP_ACCESS_WRITE) 606b641d7aSPatrick Mooney void vmx_msr_bitmap_initialize(struct vmx *); 616b641d7aSPatrick Mooney void vmx_msr_bitmap_destroy(struct vmx *); 626b641d7aSPatrick Mooney void vmx_msr_bitmap_change_access(struct vmx *, int, uint_t, int); 63bf21cd93STycho Nightingale 646b641d7aSPatrick Mooney #define guest_msr_rw(vmx, vcpuid, msr) \ 656b641d7aSPatrick Mooney vmx_msr_bitmap_change_access((vmx), (vcpuid), (msr), MSR_BITMAP_ACCESS_RW) 66bf21cd93STycho Nightingale 676b641d7aSPatrick Mooney #define guest_msr_ro(vmx, vcpuid, msr) \ 686b641d7aSPatrick Mooney vmx_msr_bitmap_change_access((vmx), (vcpuid), (msr), MSR_BITMAP_ACCESS_READ) 69bf21cd93STycho Nightingale 70bf21cd93STycho Nightingale #endif 71