-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
236 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
require "yast" | ||
|
||
require "cfa/matcher" | ||
require "cfa/placer" | ||
|
||
module Bootloader | ||
# Specialized class to handle CPU mitigation settings. | ||
# @see https://www.suse.com/support/kb/doc/?id=7023836 | ||
class CpuMitigations | ||
include Yast::Logger | ||
include Yast::I18n | ||
extend Yast::I18n | ||
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 | ||
|
||
attr_reader :value | ||
|
||
def initialize(value) | ||
textdomain "bootloader" | ||
|
||
@value = value | ||
end | ||
|
||
# Note: order of ALL is used also in UI as order of combobox. | ||
ALL = KERNEL_MAPPING.keys.map { |k| CpuMitigations.new(k) } | ||
DEFAULT = CpuMitigations.new(:auto) | ||
|
||
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 | ||
raise "Unknown mitigations value #{param.inspect}" if !reverse_mapping.key?(param) | ||
|
||
new(reverse_mapping[param]) | ||
end | ||
|
||
def self.from_string(string) | ||
raise "Unknown mitigations value #{string.inspect}" unless KERNEL_MAPPING.key?(string.to_sym) | ||
|
||
new(string.to_sym) | ||
end | ||
|
||
def to_human_string | ||
_(HUMAN_MAPPING[value]) | ||
end | ||
|
||
def kernel_value | ||
KERNEL_MAPPING[value] or raise "Invalid value #{value.inspect}" | ||
end | ||
|
||
def modify_kernel_params(kernel_params) | ||
matcher = CFA::Matcher.new(key: "mitigations") | ||
|
||
kernel_params.remove_parameter(matcher) | ||
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 | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.