1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef __xpv
#error "This file is for i86xpv only"
#endif
#include <sys/types.h>
#include <sys/mca_x86.h>
#include <sys/archsystm.h>
#include <sys/hypervisor.h>
#include "../../i86pc/cpu/generic_cpu/gcpu.h"
extern xpv_mca_panic_data_t *xpv_mca_panic_data;
mc_info_t gcpu_mce_data;
enum mctelem_direction {
MCTELEM_FORWARD,
MCTELEM_REVERSE
};
static uint32_t gcpu_xpv_hdl_lookupfails;
static uint32_t gcpu_xpv_bankhdr_found;
static uint32_t gcpu_xpv_spechdr_found;
static uint32_t gcpu_xpv_mca_hcall_fails[16];
static uint32_t gcpu_xpv_globalhdr_found;
static cmi_mca_regs_t *gcpu_xpv_bankregs;
size_t gcpu_xpv_bankregs_sz;
#define GCPU_XPV_ARCH_NREGS 3
void
gcpu_xpv_mca_init(int nbanks)
{
if (gcpu_xpv_bankregs == NULL) {
gcpu_xpv_bankregs_sz = nbanks * GCPU_XPV_ARCH_NREGS *
sizeof (cmi_mca_regs_t);
gcpu_xpv_bankregs = kmem_zalloc(gcpu_xpv_bankregs_sz, KM_SLEEP);
}
}
static void
gcpu_xpv_proxy_logout(int what, struct mc_info *mi, struct mcinfo_common **micp,
int *idxp, cmi_mca_regs_t *bankregs, size_t bankregs_sz)
{
struct mcinfo_global *mgi = (struct mcinfo_global *)(uintptr_t)*micp;
struct mcinfo_common *mic;
struct mcinfo_bank *mib;
cmi_hdl_t hdl = NULL;
cmi_mca_regs_t *mcrp;
int idx = *idxp;
int tried = 0;
int j;
/* Skip over the MC_TYPE_GLOBAL record */
ASSERT(mgi->common.type == MC_TYPE_GLOBAL);
mcrp = NULL;
mic = x86_mcinfo_next((struct mcinfo_common *)(uintptr_t)mgi);
idx++;
/*
* Process all MC_TYPE_BANK and MC_TYPE_EXTENDED records that
* follow the MC_TYPE_GLOBAL record, ending when we reach any
* other record type or when we're out of record.
*
* We skip over MC_TYPE_EXTENDED for now - nothing consumes
* the extended MSR data even in native Solaris.
*/
while (idx < x86_mcinfo_nentries(mi) &&
(mic->type == MC_TYPE_BANK || mic->type == MC_TYPE_EXTENDED)) {
if (mic->type == MC_TYPE_EXTENDED) {
gcpu_xpv_spechdr_found++;
goto next_record;
} else {
gcpu_xpv_bankhdr_found++;
}
if (hdl == NULL && !tried++) {
if ((hdl = cmi_hdl_lookup(CMI_HDL_SOLARIS_xVM_MCA,
mgi->mc_socketid, mgi->mc_coreid,
mgi->mc_core_threadid)) == NULL) {
gcpu_xpv_hdl_lookupfails++;
goto next_record;
} else {
bzero(bankregs, bankregs_sz);
mcrp = bankregs;
}
}
mib = (struct mcinfo_bank *)(uintptr_t)mic;
mcrp->cmr_msrnum = IA32_MSR_MC(mib->mc_bank, STATUS);
mcrp->cmr_msrval = mib->mc_status;
mcrp++;
mcrp->cmr_msrnum = IA32_MSR_MC(mib->mc_bank, ADDR);
mcrp->cmr_msrval = mib->mc_addr;
mcrp++;
mcrp->cmr_msrnum = IA32_MSR_MC(mib->mc_bank, MISC);
mcrp->cmr_msrval = mib->mc_misc;
mcrp++;
next_record:
idx++;
mic = x86_mcinfo_next(mic);
}
/*
* If we found some telemetry and a handle to associate it with
* then "forward" that telemetry into the MSR interpose layer
* and then request logout which will find that interposed
* telemetry. Indicate that logout code should clear bank
* status registers so that it can invalidate them in the interpose
* layer - they won't actually make it as far as real MSR writes.
*/
if (hdl != NULL) {
cmi_mca_regs_t gsr;
gcpu_mce_status_t mce;
gsr.cmr_msrnum = IA32_MSR_MCG_STATUS;
gsr.cmr_msrval = mgi->mc_gstatus;
cmi_hdl_msrforward(hdl, &gsr, 1);
cmi_hdl_msrforward(hdl, bankregs, mcrp - bankregs);
gcpu_mca_logout(hdl, NULL, (uint64_t)-1, &mce, B_TRUE, what);
cmi_hdl_rele(hdl);
}
/*
* We must move the index on at least one record or our caller
* may loop forever; our initial increment over the global
* record assures this.
*/
ASSERT(idx > *idxp);
*idxp = idx;
*micp = mic;
}
/*
* Process a struct mc_info.
*
* There are x86_mcinfo_nentries(mi) entries. An entry of type
* MC_TYPE_GLOBAL precedes a number (potentially zero) of
* entries of type MC_TYPE_BANK for telemetry from MCA banks
* of the resource identified in the MC_TYPE_GLOBAL entry.
* I think there can be multiple MC_TYPE_GLOBAL entries per buffer.
*/
void
gcpu_xpv_mci_process(mc_info_t *mi, int type,
cmi_mca_regs_t *bankregs, size_t bankregs_sz)
{
struct mcinfo_common *mic;
int idx;
mic = x86_mcinfo_first(mi);
idx = 0;
while (idx < x86_mcinfo_nentries(mi)) {
if (mic->type == MC_TYPE_GLOBAL) {
gcpu_xpv_globalhdr_found++;
gcpu_xpv_proxy_logout(type == XEN_MC_URGENT ?
GCPU_MPT_WHAT_MC_ERR : GCPU_MPT_WHAT_XPV_VIRQ,
mi, &mic, &idx, bankregs, bankregs_sz);
} else {
idx++;
mic = x86_mcinfo_next(mic);
}
}
}
int
gcpu_xpv_telem_read(mc_info_t *mci, int type, uint64_t *idp)
{
xen_mc_t xmc;
xen_mc_fetch_t *mcf = &xmc.u.mc_fetch;
long err;
mcf->flags = type;
set_xen_guest_handle(mcf->data, mci);
if ((err = HYPERVISOR_mca(XEN_MC_fetch, &xmc)) != 0) {
gcpu_xpv_mca_hcall_fails[err < 16 ? err : 0]++;
return (0);
}
if (mcf->flags == XEN_MC_OK) {
*idp = mcf->fetch_id;
return (1);
} else {
*idp = 0;
return (0);
}
}
void
gcpu_xpv_telem_ack(int type, uint64_t fetch_id)
{
xen_mc_t xmc;
struct xen_mc_fetch *mcf = &xmc.u.mc_fetch;
mcf->flags = type | XEN_MC_ACK;
mcf->fetch_id = fetch_id;
(void) HYPERVISOR_mca(XEN_MC_fetch, &xmc);
}
static void
mctelem_traverse(void *head, enum mctelem_direction direction,
boolean_t urgent)
{
char *tep = head, **ntepp;
int noff = (direction == MCTELEM_FORWARD) ?
xpv_mca_panic_data->mpd_fwdptr_offset :
xpv_mca_panic_data->mpd_revptr_offset;
while (tep != NULL) {
struct mc_info **mcip = (struct mc_info **)
(tep + xpv_mca_panic_data->mpd_dataptr_offset);
gcpu_xpv_mci_process(*mcip,
urgent ? XEN_MC_URGENT : XEN_MC_NONURGENT,
gcpu_xpv_bankregs, gcpu_xpv_bankregs_sz);
ntepp = (char **)(tep + noff);
tep = *ntepp;
}
}
/*
* Callback made from panicsys. We may have reached panicsys from a
* Solaris-initiated panic or a hypervisor-initiated panic; for the
* latter we may not perform any hypercalls. Our task is to retrieve
* unprocessed MCA telemetry from the hypervisor and shovel it into
* errorqs for later processing during panic.
*/
void
gcpu_xpv_panic_callback(void)
{
if (IN_XPV_PANIC()) {
xpv_mca_panic_data_t *ti = xpv_mca_panic_data;
if (ti == NULL ||
ti->mpd_magic != MCA_PANICDATA_MAGIC ||
ti->mpd_version != MCA_PANICDATA_VERS)
return;
mctelem_traverse(ti->mpd_urgent_processing, MCTELEM_FORWARD,
B_TRUE);
mctelem_traverse(ti->mpd_urgent_dangling, MCTELEM_REVERSE,
B_TRUE);
mctelem_traverse(ti->mpd_urgent_committed, MCTELEM_REVERSE,
B_TRUE);
mctelem_traverse(ti->mpd_nonurgent_processing, MCTELEM_FORWARD,
B_FALSE);
mctelem_traverse(ti->mpd_nonurgent_dangling, MCTELEM_REVERSE,
B_FALSE);
mctelem_traverse(ti->mpd_nonurgent_committed, MCTELEM_REVERSE,
B_FALSE);
} else {
int types[] = { XEN_MC_URGENT, XEN_MC_NONURGENT };
uint64_t fetch_id;
int i;
for (i = 0; i < sizeof (types) / sizeof (types[0]); i++) {
while (gcpu_xpv_telem_read(&gcpu_mce_data,
types[i], &fetch_id)) {
gcpu_xpv_mci_process(&gcpu_mce_data, types[i],
gcpu_xpv_bankregs, gcpu_xpv_bankregs_sz);
gcpu_xpv_telem_ack(types[i], fetch_id);
}
}
}
}
|