sys-hypervisor.c (4f2c0a4acffbec01079c28f839422e64ddeff004) sys-hypervisor.c (415dab3c179632d098aadc756b39cebceb977978)
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * copyright (c) 2006 IBM Corporation
4 * Authored by: Mike D. Day <ncmike@us.ibm.com>
5 */
6
7#include <linux/slab.h>
8#include <linux/kernel.h>

--- 17 unchanged lines hidden (view full) ---

26
27#define HYPERVISOR_ATTR_RW(_name) \
28static struct hyp_sysfs_attr _name##_attr = __ATTR_RW(_name)
29
30struct hyp_sysfs_attr {
31 struct attribute attr;
32 ssize_t (*show)(struct hyp_sysfs_attr *, char *);
33 ssize_t (*store)(struct hyp_sysfs_attr *, const char *, size_t);
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * copyright (c) 2006 IBM Corporation
4 * Authored by: Mike D. Day <ncmike@us.ibm.com>
5 */
6
7#include <linux/slab.h>
8#include <linux/kernel.h>

--- 17 unchanged lines hidden (view full) ---

26
27#define HYPERVISOR_ATTR_RW(_name) \
28static struct hyp_sysfs_attr _name##_attr = __ATTR_RW(_name)
29
30struct hyp_sysfs_attr {
31 struct attribute attr;
32 ssize_t (*show)(struct hyp_sysfs_attr *, char *);
33 ssize_t (*store)(struct hyp_sysfs_attr *, const char *, size_t);
34 void *hyp_attr_data;
34 union {
35 void *hyp_attr_data;
36 unsigned long hyp_attr_value;
37 };
35};
36
37static ssize_t type_show(struct hyp_sysfs_attr *attr, char *buffer)
38{
39 return sprintf(buffer, "xen\n");
40}
41
42HYPERVISOR_ATTR_RO(type);

--- 351 unchanged lines hidden (view full) ---

394 .attrs = xen_properties_attrs,
395};
396
397static int __init xen_sysfs_properties_init(void)
398{
399 return sysfs_create_group(hypervisor_kobj, &xen_properties_group);
400}
401
38};
39
40static ssize_t type_show(struct hyp_sysfs_attr *attr, char *buffer)
41{
42 return sprintf(buffer, "xen\n");
43}
44
45HYPERVISOR_ATTR_RO(type);

--- 351 unchanged lines hidden (view full) ---

397 .attrs = xen_properties_attrs,
398};
399
400static int __init xen_sysfs_properties_init(void)
401{
402 return sysfs_create_group(hypervisor_kobj, &xen_properties_group);
403}
404
405#define FLAG_UNAME "unknown"
406#define FLAG_UNAME_FMT FLAG_UNAME "%02u"
407#define FLAG_UNAME_MAX sizeof(FLAG_UNAME "XX")
408#define FLAG_COUNT (sizeof(xen_start_flags) * BITS_PER_BYTE)
409static_assert(sizeof(xen_start_flags) <=
410 sizeof_field(struct hyp_sysfs_attr, hyp_attr_value));
411
412static ssize_t flag_show(struct hyp_sysfs_attr *attr, char *buffer)
413{
414 char *p = buffer;
415
416 *p++ = '0' + ((xen_start_flags & attr->hyp_attr_value) != 0);
417 *p++ = '\n';
418 return p - buffer;
419}
420
421#define FLAG_NODE(flag, node) \
422 [ilog2(flag)] = { \
423 .attr = { .name = #node, .mode = 0444 },\
424 .show = flag_show, \
425 .hyp_attr_value = flag \
426 }
427
428/*
429 * Add new, known flags here. No other changes are required, but
430 * note that each known flag wastes one entry in flag_unames[].
431 * The code/complexity machinations to avoid this isn't worth it
432 * for a few entries, but keep it in mind.
433 */
434static struct hyp_sysfs_attr flag_attrs[FLAG_COUNT] = {
435 FLAG_NODE(SIF_PRIVILEGED, privileged),
436 FLAG_NODE(SIF_INITDOMAIN, initdomain)
437};
438static struct attribute_group xen_flags_group = {
439 .name = "start_flags",
440 .attrs = (struct attribute *[FLAG_COUNT + 1]){}
441};
442static char flag_unames[FLAG_COUNT][FLAG_UNAME_MAX];
443
444static int __init xen_sysfs_flags_init(void)
445{
446 for (unsigned fnum = 0; fnum != FLAG_COUNT; fnum++) {
447 if (likely(flag_attrs[fnum].attr.name == NULL)) {
448 sprintf(flag_unames[fnum], FLAG_UNAME_FMT, fnum);
449 flag_attrs[fnum].attr.name = flag_unames[fnum];
450 flag_attrs[fnum].attr.mode = 0444;
451 flag_attrs[fnum].show = flag_show;
452 flag_attrs[fnum].hyp_attr_value = 1 << fnum;
453 }
454 xen_flags_group.attrs[fnum] = &flag_attrs[fnum].attr;
455 }
456 return sysfs_create_group(hypervisor_kobj, &xen_flags_group);
457}
458
402#ifdef CONFIG_XEN_HAVE_VPMU
403struct pmu_mode {
404 const char *name;
405 uint32_t mode;
406};
407
408static struct pmu_mode pmu_modes[] = {
409 {"off", XENPMU_MODE_OFF},

--- 124 unchanged lines hidden (view full) ---

534 if (ret)
535 goto comp_out;
536 ret = xen_sysfs_uuid_init();
537 if (ret)
538 goto uuid_out;
539 ret = xen_sysfs_properties_init();
540 if (ret)
541 goto prop_out;
459#ifdef CONFIG_XEN_HAVE_VPMU
460struct pmu_mode {
461 const char *name;
462 uint32_t mode;
463};
464
465static struct pmu_mode pmu_modes[] = {
466 {"off", XENPMU_MODE_OFF},

--- 124 unchanged lines hidden (view full) ---

591 if (ret)
592 goto comp_out;
593 ret = xen_sysfs_uuid_init();
594 if (ret)
595 goto uuid_out;
596 ret = xen_sysfs_properties_init();
597 if (ret)
598 goto prop_out;
599 ret = xen_sysfs_flags_init();
600 if (ret)
601 goto flags_out;
542#ifdef CONFIG_XEN_HAVE_VPMU
543 if (xen_initial_domain()) {
544 ret = xen_sysfs_pmu_init();
545 if (ret) {
602#ifdef CONFIG_XEN_HAVE_VPMU
603 if (xen_initial_domain()) {
604 ret = xen_sysfs_pmu_init();
605 if (ret) {
546 sysfs_remove_group(hypervisor_kobj,
547 &xen_properties_group);
548 goto prop_out;
606 sysfs_remove_group(hypervisor_kobj, &xen_flags_group);
607 goto flags_out;
549 }
550 }
551#endif
552 goto out;
553
608 }
609 }
610#endif
611 goto out;
612
613flags_out:
614 sysfs_remove_group(hypervisor_kobj, &xen_properties_group);
554prop_out:
555 sysfs_remove_file(hypervisor_kobj, &uuid_attr.attr);
556uuid_out:
557 sysfs_remove_group(hypervisor_kobj, &xen_compilation_group);
558comp_out:
559 sysfs_remove_group(hypervisor_kobj, &version_group);
560version_out:
561 sysfs_remove_file(hypervisor_kobj, &guest_type_attr.attr);

--- 48 unchanged lines hidden ---
615prop_out:
616 sysfs_remove_file(hypervisor_kobj, &uuid_attr.attr);
617uuid_out:
618 sysfs_remove_group(hypervisor_kobj, &xen_compilation_group);
619comp_out:
620 sysfs_remove_group(hypervisor_kobj, &version_group);
621version_out:
622 sysfs_remove_file(hypervisor_kobj, &guest_type_attr.attr);

--- 48 unchanged lines hidden ---