1 /*
2 * asid.c: handling ASIDs in SVM.
3 * Copyright (c) 2007, Advanced Micro Devices, Inc.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #include <xen/init.h>
19 #include <xen/lib.h>
20 #include <xen/perfc.h>
21 #include <asm/hvm/svm/asid.h>
22 #include <asm/amd.h>
23 #include <asm/hvm/nestedhvm.h>
24
svm_asid_init(const struct cpuinfo_x86 * c)25 void svm_asid_init(const struct cpuinfo_x86 *c)
26 {
27 int nasids = 0;
28
29 /* Check for erratum #170, and leave ASIDs disabled if it's present. */
30 if ( !cpu_has_amd_erratum(c, AMD_ERRATUM_170) )
31 nasids = cpuid_ebx(0x8000000A);
32
33 hvm_asid_init(nasids);
34 }
35
36 /*
37 * Called directly before VMRUN. Checks if the VCPU needs a new ASID,
38 * assigns it, and if required, issues required TLB flushes.
39 */
svm_asid_handle_vmrun(void)40 void svm_asid_handle_vmrun(void)
41 {
42 struct vcpu *curr = current;
43 struct vmcb_struct *vmcb = curr->arch.hvm_svm.vmcb;
44 struct hvm_vcpu_asid *p_asid =
45 nestedhvm_vcpu_in_guestmode(curr)
46 ? &vcpu_nestedhvm(curr).nv_n2asid : &curr->arch.hvm_vcpu.n1asid;
47 bool_t need_flush = hvm_asid_handle_vmenter(p_asid);
48
49 /* ASID 0 indicates that ASIDs are disabled. */
50 if ( p_asid->asid == 0 )
51 {
52 vmcb_set_guest_asid(vmcb, 1);
53 vmcb->tlb_control = 1;
54 return;
55 }
56
57 if (vmcb_get_guest_asid(vmcb) != p_asid->asid)
58 vmcb_set_guest_asid(vmcb, p_asid->asid);
59 vmcb->tlb_control = need_flush;
60 }
61
62 /*
63 * Local variables:
64 * mode: C
65 * c-file-style: "BSD"
66 * c-basic-offset: 4
67 * tab-width: 4
68 * indent-tabs-mode: nil
69 * End:
70 */
71