4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
26 * mdb dcmds for selected structures from
27 * usr/src/uts/common/sys/crypto/impl.h
30 #include <sys/mdb_modapi.h>
31 #include <sys/modctl.h>
32 #include <sys/types.h>
33 #include <sys/crypto/api.h>
34 #include <sys/crypto/common.h>
35 #include <sys/crypto/impl.h>
36 #include "crypto_cmds.h"
38 static const char *prov_states
[] = {
41 "KCF_PROV_UNVERIFIED",
42 "KCF_PROV_VERIFICATION_FAILED",
47 "KCF_PROV_UNREGISTERING",
48 "KCF_PROV_UNREGISTERED"
53 kcf_provider_desc(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
55 kcf_provider_desc_t desc
;
56 kcf_provider_desc_t
*ptr
;
57 char string
[MAXNAMELEN
+ 1];
59 crypto_mech_info_t
*mech_pointer
;
61 uint64_t dtotal
, ftotal
, btotal
;
64 if ((flags
& DCMD_ADDRSPEC
) != DCMD_ADDRSPEC
)
66 ptr
= (kcf_provider_desc_t
*)addr
;
69 mdb_printf("DEBUG: reading kcf_provider_desc at %p\n", ptr
);
72 if (mdb_vread(&desc
, sizeof (kcf_provider_desc_t
), (uintptr_t)ptr
)
74 mdb_warn("cannot read at address %p", (uintptr_t)ptr
);
77 mdb_printf("%<b>kcf_provider_desc at %p%</b>\n", ptr
);
79 switch (desc
.pd_prov_type
) {
80 case CRYPTO_HW_PROVIDER
:
81 mdb_printf("pd_prov_type:\t\tCRYPTO_HW_PROVIDER\n");
83 case CRYPTO_SW_PROVIDER
:
84 mdb_printf("pd_prov_type:\t\tCRYPTO_SW_PROVIDER\n");
86 case CRYPTO_LOGICAL_PROVIDER
:
87 mdb_printf("pd_prov_type:\t\tCRYPTO_LOGICAL_PROVIDER\n");
90 mdb_printf("bad pd_prov_type:\t%d\n", desc
.pd_prov_type
);
93 mdb_printf("pd_prov_id:\t\t%u\n", desc
.pd_prov_id
);
94 if (desc
.pd_description
== NULL
)
95 mdb_printf("pd_description:\t\tNULL\n");
96 else if (mdb_readstr(string
, MAXNAMELEN
+ 1,
97 (uintptr_t)desc
.pd_description
) == -1) {
98 mdb_warn("cannot read %p", desc
.pd_description
);
100 mdb_printf("pd_description:\t\t%s\n", string
);
102 mdb_printf("pd_sid:\t\t\t%u\n", desc
.pd_sid
);
103 mdb_printf("pd_taskq:\t\t%p\n", desc
.pd_taskq
);
104 mdb_printf("pd_nbins:\t\t%u\n", desc
.pd_nbins
);
105 mdb_printf("pd_percpu_bins:\t\t%p\n", desc
.pd_percpu_bins
);
107 dtotal
= ftotal
= btotal
= 0;
108 holdcnt
= jobcnt
= 0;
109 for (i
= 0; i
< desc
.pd_nbins
; i
++) {
110 if (mdb_vread(&stats
, sizeof (kcf_prov_cpu_t
),
111 (uintptr_t)(desc
.pd_percpu_bins
+ i
)) == -1) {
112 mdb_warn("cannot read addr %p",
113 desc
.pd_percpu_bins
+ i
);
117 holdcnt
+= stats
.kp_holdcnt
;
118 jobcnt
+= stats
.kp_jobcnt
;
119 dtotal
+= stats
.kp_ndispatches
;
120 ftotal
+= stats
.kp_nfails
;
121 btotal
+= stats
.kp_nbusy_rval
;
124 mdb_printf("total kp_holdcnt:\t\t%d\n", holdcnt
);
125 mdb_printf("total kp_jobcnt:\t\t%u\n", jobcnt
);
126 mdb_printf("total kp_ndispatches:\t%llu\n", dtotal
);
127 mdb_printf("total kp_nfails:\t\t%llu\n", ftotal
);
128 mdb_printf("total kp_nbusy_rval:\t%llu\n", btotal
);
131 mdb_printf("pd_prov_handle:\t\t%p\n", desc
.pd_prov_handle
);
132 mdb_printf("pd_kcf_prov_handle:\t%u\n", desc
.pd_kcf_prov_handle
);
134 mdb_printf("pd_ops_vector:\t\t%p\n", desc
.pd_ops_vector
);
135 mdb_printf("pd_mech_list_count:\t%u\n", desc
.pd_mech_list_count
);
138 for (i
= 0; i
< desc
.pd_mech_list_count
; i
++) {
139 mech_pointer
= desc
.pd_mechanisms
+ i
;
140 mdb_call_dcmd("crypto_mech_info",
141 (uintptr_t)mech_pointer
, DCMD_ADDRSPEC
, 0, NULL
);
144 mdb_printf("pd_mech_indx:\n");
146 for (i
= 0; i
< KCF_OPS_CLASSSIZE
; i
++) {
147 for (j
= 0; j
< KCF_MAXMECHTAB
; j
++) {
148 if (desc
.pd_mech_indx
[i
][j
] == KCF_INVALID_INDX
)
151 mdb_printf("%u ", desc
.pd_mech_indx
[i
][j
]);
157 if (desc
.pd_name
== NULL
)
158 mdb_printf("pd_name:\t\t NULL\n");
159 else if (mdb_readstr(string
, MAXNAMELEN
+ 1, (uintptr_t)desc
.pd_name
)
161 mdb_warn("could not read pd_name from %X\n", desc
.pd_name
);
163 mdb_printf("pd_name:\t\t%s\n", string
);
165 mdb_printf("pd_instance:\t\t%u\n", desc
.pd_instance
);
166 mdb_printf("pd_module_id:\t\t%d\n", desc
.pd_module_id
);
167 mdb_printf("pd_mctlp:\t\t%p\n", desc
.pd_mctlp
);
168 mdb_printf("pd_lock:\t\t%p\n", desc
.pd_lock
);
169 if (desc
.pd_state
< KCF_PROV_ALLOCATED
||
170 desc
.pd_state
> KCF_PROV_UNREGISTERED
)
171 mdb_printf("pd_state is invalid:\t%d\n", desc
.pd_state
);
173 mdb_printf("pd_state:\t%s\n", prov_states
[desc
.pd_state
]);
174 mdb_printf("pd_provider_list:\t%p\n", desc
.pd_provider_list
);
176 mdb_printf("pd_resume_cv:\t\t%hd\n", desc
.pd_resume_cv
._opaque
);
177 mdb_printf("pd_flags:\t\t%s %s %s %s %s\n",
178 (desc
.pd_flags
& CRYPTO_HIDE_PROVIDER
) ?
179 "CRYPTO_HIDE_PROVIDER" : " ",
180 (desc
.pd_flags
& CRYPTO_HASH_NO_UPDATE
) ?
181 "CRYPTO_HASH_NO_UPDATE" : " ",
182 (desc
.pd_flags
& CRYPTO_HMAC_NO_UPDATE
) ?
183 "CRYPTO_HMAC_NO_UPDATE" : " ",
184 (desc
.pd_flags
& CRYPTO_SYNCHRONOUS
) ?
185 "CRYPTO_SYNCHRONOUS" : " ",
186 (desc
.pd_flags
& KCF_LPROV_MEMBER
) ?
187 "KCF_LPROV_MEMBER" : " ");
188 if (desc
.pd_flags
& CRYPTO_HASH_NO_UPDATE
)
189 mdb_printf("pd_hash_limit:\t\t%u\n", desc
.pd_hash_limit
);
190 if (desc
.pd_flags
& CRYPTO_HMAC_NO_UPDATE
)
191 mdb_printf("pd_hmac_limit:\t\t%u\n", desc
.pd_hmac_limit
);
193 mdb_printf("pd_kstat:\t\t%p\n", desc
.pd_kstat
);
198 #define GOT_NONE (-2)
202 prov_tab(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
204 kcf_provider_desc_t
**tab
;
205 kcf_provider_desc_t desc
;
206 kcf_provider_desc_t
*ptr
;
209 int gotzero
= GOT_NONE
;
210 char string
[MAXNAMELEN
+ 1];
212 if ((flags
& DCMD_ADDRSPEC
) == DCMD_ADDRSPEC
) {
214 } else if (mdb_readsym(&ptr
, sizeof (void *), "prov_tab")
216 mdb_warn("cannot read prov_tab");
219 } else if (mdb_readvar(&prov_tab_max
, "prov_tab_max") == -1) {
220 mdb_warn("cannot read prov_tab_max");
223 mdb_printf("%<b>prov_tab = %p%</b>\n", ptr
);
224 tab
= mdb_zalloc(prov_tab_max
* sizeof (kcf_provider_desc_t
*),
228 mdb_printf("DEBUG: tab = %p, prov_tab_max = %d\n", tab
, prov_tab_max
);
231 if (mdb_vread(tab
, prov_tab_max
* sizeof (kcf_provider_desc_t
*),
232 (uintptr_t)ptr
) == -1) {
233 mdb_warn("cannot read prov_tab");
237 mdb_printf("DEBUG: got past mdb_vread of tab\n");
238 mdb_printf("DEBUG: *tab = %p\n", *tab
);
240 for (i
= 0; i
< prov_tab_max
; i
++) {
241 /* save space, only print range for long list of nulls */
242 if (tab
[i
] == NULL
) {
243 if (gotzero
== GOT_NONE
) {
244 mdb_printf("prov_tab[%d", i
);
248 /* first non-null in awhile, print index of prev null */
249 if (gotzero
!= GOT_NONE
) {
250 if (gotzero
== (i
- 1))
251 mdb_printf("] = NULL\n", i
- 1);
253 mdb_printf(" - %d] = NULL\n", i
- 1);
256 /* interesting value, print it */
257 mdb_printf("prov_tab[%d] = %p ", i
, tab
[i
]);
259 if (mdb_vread(&desc
, sizeof (kcf_provider_desc_t
),
260 (uintptr_t)tab
[i
]) == -1) {
261 mdb_warn("cannot read at address %p",
266 (void) mdb_readstr(string
, MAXNAMELEN
+ 1,
267 (uintptr_t)desc
.pd_name
);
268 mdb_printf("(%s\t%s)\n", string
,
269 prov_states
[desc
.pd_state
]);
272 /* if we've printed the first of many nulls but left the brace open */
273 if ((i
> 0) && (tab
[i
-1] == NULL
)) {
274 if (gotzero
== GOT_NONE
)
275 mdb_printf("] = NULL\n");
277 mdb_printf(" - %d] = NULL\n", i
- 1);
285 policy_tab(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
287 kcf_policy_desc_t
**tab
;
288 kcf_policy_desc_t
*ptr
;
289 uint_t policy_tab_max
;
291 int gotzero
= GOT_NONE
;
293 if ((flags
& DCMD_ADDRSPEC
) == DCMD_ADDRSPEC
) {
295 } else if (mdb_readsym(&ptr
, sizeof (void *), "policy_tab")
297 mdb_warn("cannot read policy_tab");
300 } else if (mdb_readvar(&policy_tab_max
, "policy_tab_max") == -1) {
301 mdb_warn("cannot read policy_tab_max");
305 /* get the current number of descriptors in the table */
306 if (mdb_readvar(&num
, "policy_tab_num") == -1) {
307 mdb_warn("cannot read policy_tab_num");
310 mdb_printf("%<b>policy_tab = %p%</b> \tpolicy_tab_num = %d\n",
313 tab
= mdb_zalloc(policy_tab_max
* sizeof (kcf_policy_desc_t
*),
316 if (mdb_vread(tab
, policy_tab_max
* sizeof (kcf_policy_desc_t
*),
317 (uintptr_t)ptr
) == -1) {
318 mdb_warn("cannot read policy_tab");
322 mdb_printf("DEBUG: got past mdb_vread of tab\n");
323 mdb_printf("DEBUG: *tab = %p\n", *tab
);
325 for (i
= 0; i
< policy_tab_max
; i
++) {
326 /* save space, only print range for long list of nulls */
327 if (tab
[i
] == NULL
) {
328 if (gotzero
== GOT_NONE
) {
329 mdb_printf("policy_tab[%d", i
);
333 /* first non-null in awhile, print index of prev null */
334 if (gotzero
!= GOT_NONE
) {
335 if (gotzero
== (i
- 1))
336 mdb_printf("] = NULL\n", i
- 1);
338 mdb_printf(" - %d] = NULL\n", i
- 1);
341 /* interesting value, print it */
342 mdb_printf("policy_tab[%d] = %p\n", i
, tab
[i
]);
345 /* if we've printed the first of many nulls but left the brace open */
346 if ((i
> 0) && (tab
[i
-1] == NULL
)) {
347 if (gotzero
== GOT_NONE
)
348 mdb_printf("] = NULL\n");
350 mdb_printf(" - %d] = NULL\n", i
- 1);
357 prt_mechs(int count
, crypto_mech_name_t
*mechs
)
360 char name
[CRYPTO_MAX_MECH_NAME
+ 1];
361 char name2
[CRYPTO_MAX_MECH_NAME
+ 3];
363 for (i
= 0; i
< count
; i
++) {
364 if (mdb_readstr(name
, CRYPTO_MAX_MECH_NAME
,
365 (uintptr_t)((char *)mechs
)) == -1)
368 (void) mdb_snprintf(name2
, sizeof (name2
), "\"%s\"", name
);
369 /* yes, length is 32, but then it will wrap */
370 /* this shorter size formats nicely for most cases */
371 mdb_printf("mechs[%d]=%-28s", i
, name2
);
372 mdb_printf("%s", i
%2 ? "\n" : " "); /* 2-columns */
379 prt_soft_conf_entry(kcf_soft_conf_entry_t
*addr
, kcf_soft_conf_entry_t
*entry
,
382 char name
[MAXNAMELEN
+ 1];
384 mdb_printf("\n%<b>kcf_soft_conf_entry_t at %p:%</b>\n", addr
);
385 mdb_printf("ce_next: %p", entry
->ce_next
);
387 if (entry
->ce_name
== NULL
)
388 mdb_printf("\tce_name: NULL\n");
389 else if (mdb_readstr(name
, MAXNAMELEN
, (uintptr_t)entry
->ce_name
)
391 mdb_printf("could not read ce_name from %p\n",
394 mdb_printf("\tce_name: %s\n", name
);
396 mdb_printf("ce_count: %d\n", entry
->ce_count
);
397 prt_mechs(entry
->ce_count
, entry
->ce_mechs
);
402 soft_conf_walk_init(mdb_walk_state_t
*wsp
)
406 if (mdb_readsym(&soft
, sizeof (kcf_soft_conf_entry_t
*),
407 "soft_config_list") == -1) {
408 mdb_warn("failed to find 'soft_config_list'");
411 wsp
->walk_addr
= (uintptr_t)soft
;
412 wsp
->walk_data
= mdb_alloc(sizeof (kcf_soft_conf_entry_t
), UM_SLEEP
);
413 wsp
->walk_callback
= (mdb_walk_cb_t
)prt_soft_conf_entry
;
418 * At each step, read a kcf_soft_conf_entry_t into our private storage, then
419 * invoke the callback function. We terminate when we reach a NULL ce_next
423 soft_conf_walk_step(mdb_walk_state_t
*wsp
)
427 if (wsp
->walk_addr
== NULL
) /* then we're done */
431 mdb_printf("DEBUG: wsp->walk_addr == %p\n", wsp
->walk_addr
);
434 if (mdb_vread(wsp
->walk_data
, sizeof (kcf_soft_conf_entry_t
),
435 wsp
->walk_addr
) == -1) {
436 mdb_warn("failed to read kcf_soft_conf_entry at %p",
441 status
= wsp
->walk_callback(wsp
->walk_addr
, wsp
->walk_data
,
445 (uintptr_t)(((kcf_soft_conf_entry_t
*)wsp
->walk_data
)->ce_next
);
450 * The walker's fini function is invoked at the end of each walk. Since we
451 * dynamically allocated a kcf_soft_conf_entry_t in soft_conf_walk_init,
452 * we must free it now.
455 soft_conf_walk_fini(mdb_walk_state_t
*wsp
)
458 mdb_printf("...end of kcf_soft_conf_entry walk\n");
460 mdb_free(wsp
->walk_data
, sizeof (kcf_soft_conf_entry_t
));
464 kcf_soft_conf_entry(uintptr_t addr
, uint_t flags
, int argc
,
465 const mdb_arg_t
*argv
)
467 kcf_soft_conf_entry_t entry
;
468 kcf_soft_conf_entry_t
*ptr
;
470 if ((flags
& DCMD_ADDRSPEC
) == DCMD_ADDRSPEC
) {
471 if (addr
== NULL
) /* not allowed with DCMD_ADDRSPEC */
474 ptr
= (kcf_soft_conf_entry_t
*)addr
;
475 } else if (mdb_readsym(&ptr
, sizeof (void *), "soft_config_list")
477 mdb_warn("cannot read soft_config_list");
480 mdb_printf("soft_config_list = %p\n", ptr
);
485 if (mdb_vread(&entry
, sizeof (kcf_soft_conf_entry_t
), (uintptr_t)ptr
)
487 mdb_warn("cannot read at address %p", (uintptr_t)ptr
);
491 /* this could change in the future to have more than one ret val */
492 if (prt_soft_conf_entry(ptr
, &entry
, NULL
) != WALK_ERR
)
499 kcf_policy_desc(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
501 kcf_policy_desc_t desc
;
502 char name
[MAXNAMELEN
+ 1];
505 if ((flags
& DCMD_ADDRSPEC
) != DCMD_ADDRSPEC
)
508 if (mdb_vread(&desc
, sizeof (kcf_policy_desc_t
), (uintptr_t)addr
)
510 mdb_warn("Could not read kcf_policy_desc_t at %p\n", addr
);
513 mdb_printf("pd_prov_type: %s",
514 desc
.pd_prov_type
== CRYPTO_HW_PROVIDER
? "CRYPTO_HW_PROVIDER" :
515 "CRYPTO_SW_PROVIDER");
517 if (desc
.pd_name
== NULL
)
518 mdb_printf("\tpd_name: NULL\n");
519 else if (mdb_readstr(name
, MAXNAMELEN
, (uintptr_t)desc
.pd_name
)
521 mdb_printf("could not read pd_name from %p\n",
524 mdb_printf("\tpd_name: %s\n", name
);
526 mdb_printf("pd_instance: %d ", desc
.pd_instance
);
527 mdb_printf("\t\tpd_refcnt: %d\n", desc
.pd_refcnt
);
528 mdb_printf("pd_mutex: %p", desc
.pd_mutex
);
529 mdb_printf("\t\tpd_disabled_count: %d", desc
.pd_disabled_count
);
530 mdb_printf("\npd_disabled_mechs:\n");
532 prt_mechs(desc
.pd_disabled_count
, desc
.pd_disabled_mechs
);