Class: Bootloader::CpuMitigations

Inherits:
Object
  • Object
show all
Extended by:
Yast::I18n
Includes:
Yast::I18n, Yast::Logger
Defined in:
src/lib/bootloader/cpu_mitigations.rb

Overview

Specialized class to handle CPU mitigation settings.

Constant Summary collapse

KERNEL_MAPPING =
{
  nosmt:  "auto,nosmt",
  auto:   "auto",
  off:    "off",
  manual: nil
}.freeze
HUMAN_MAPPING =
{
  nosmt:  N_("Auto + No SMT"),
  auto:   N_("Auto"),
  off:    N_("Off"),
  manual: N_("Manually")
}.freeze
ALL =

NOTE: order of ALL is used also in UI as order of combobox.

KERNEL_MAPPING.keys.map { |k| CpuMitigations.new(k) }
DEFAULT =
CpuMitigations.new(:auto)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ CpuMitigations

Returns a new instance of CpuMitigations.



31
32
33
34
35
# File 'src/lib/bootloader/cpu_mitigations.rb', line 31

def initialize(value)
  textdomain "bootloader"

  @value = value
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



29
30
31
# File 'src/lib/bootloader/cpu_mitigations.rb', line 29

def value
  @value
end

Class Method Details

.from_kernel_params(kernel_params) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'src/lib/bootloader/cpu_mitigations.rb', line 41

def self.from_kernel_params(kernel_params)
  log.info "kernel params #{kernel_params.inspect}"
  param = kernel_params.parameter("mitigations")
  log.info "mitigation param #{param.inspect}"
  param = nil if param == false
  reverse_mapping = KERNEL_MAPPING.invert

  if !reverse_mapping.key?(param)
    raise "Unknown mitigations value #{param.inspect} in the kernel command line, " \
          "supported values are: #{KERNEL_MAPPING.values.compact.map(&:inspect).join(", ")}."
  end

  new(reverse_mapping[param])
end

.from_string(string) ⇒ Object



56
57
58
59
60
# File 'src/lib/bootloader/cpu_mitigations.rb', line 56

def self.from_string(string)
  raise "Unknown mitigations value #{string.inspect}" unless KERNEL_MAPPING.key?(string.to_sym)

  new(string.to_sym)
end

Instance Method Details

#kernel_valueObject



66
67
68
# File 'src/lib/bootloader/cpu_mitigations.rb', line 66

def kernel_value
  KERNEL_MAPPING[value] or raise "Invalid value #{value.inspect}"
end

#modify_kernel_params(kernel_params) ⇒ Object



70
71
72
73
74
75
76
77
78
79
# File 'src/lib/bootloader/cpu_mitigations.rb', line 70

def modify_kernel_params(kernel_params)
  matcher = CFA::Matcher.new(key: "mitigations")

  kernel_params.remove_parameter(matcher)
  return if value == :manual

  # TODO: fix cfa_grub2 with replace placer
  kernel_params.add_parameter("mitigations", kernel_value)
  log.info "replacing old config with #{kernel_value}: #{kernel_params.inspect}"
end

#to_human_stringObject



62
63
64
# File 'src/lib/bootloader/cpu_mitigations.rb', line 62

def to_human_string
  _(HUMAN_MAPPING[value])
end