-
Notifications
You must be signed in to change notification settings - Fork 13
[spyre] Update the ulimit for the sentient group #37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: spyre
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,6 +59,30 @@ def is_applicable(cls): | |
|
|
||
| return Spyre.is_spyre_card_exists() | ||
|
|
||
| @classmethod | ||
| def get_number_of_spyre_cards(cls): | ||
| """Returns number of spyre cards in the device""" | ||
|
|
||
| number_of_cards = 0 | ||
| context = pyudev.Context() | ||
| # IBM vendor ID | ||
| spyre_vendor_ids = ["0x1014"] | ||
| # Spyre device IDs | ||
| spyre_device_ids = ["0x06a7", "0x06a8"] | ||
|
|
||
| for device in context.list_devices(subsystem='pci'): | ||
| vendor_id = device.attributes.get("vendor").decode("utf-8").strip() | ||
| if vendor_id not in spyre_vendor_ids: | ||
| continue | ||
|
|
||
| device_id = device.attributes.get("device").decode("utf-8").strip() | ||
| if device_id not in spyre_device_ids: | ||
| continue | ||
|
|
||
| number_of_cards+=1 | ||
|
|
||
| return number_of_cards | ||
|
|
||
| def check_driver_config(self): | ||
| """VFIO Driver configuration""" | ||
|
|
||
|
|
@@ -136,10 +160,59 @@ def check_udev_rule(self): | |
| conf_check.set_status(status) | ||
| return conf_check | ||
|
|
||
|
|
||
| def is_mem_limit_config_valid(self, conf_check, | ||
| line, vfio_mem_conf): | ||
| """ is mem limit config valid | ||
|
|
||
| This helper function parses an existing configuration line against | ||
| VFIO memory configuration entries to be added. If an existing | ||
| configuration satisfies or supersedes a corresponding VFIO memory | ||
| configuration, the matched entry is removed from the VFIO configuration | ||
| list. | ||
|
|
||
| Args: | ||
| conf_check (ConfigurationFileCheck): Configuration check object | ||
| used to record validation results. | ||
| line (str): Existing configuration line. | ||
| vfio_mem_conf (list[str]): List of VFIO memory configuration | ||
| entries to be validated and potentially added. | ||
|
|
||
| Returns: | ||
| None | ||
| """ | ||
|
|
||
| # Example strings matching the pattern: | ||
| # "sentient 1234", "memlock unlimited", "memlock 7890", | ||
| # "sentient memlock unlimited" | ||
| pattern = r'^(.+?)\s+(unlimited|\d+)$' | ||
|
|
||
| for conf in vfio_mem_conf[:]: | ||
| if line == conf: | ||
| conf_check.add_attribute(line, True, None, None) | ||
| vfio_mem_conf.remove(conf) | ||
| continue | ||
|
|
||
| line_match = re.match(pattern, line) | ||
| conf_match = re.match(pattern, conf) | ||
| if line_match and conf_match: | ||
| line_str = line_match.group(1) | ||
| line_value = line_match.group(2) | ||
| conf_str = conf_match.group(1) | ||
| conf_value = conf_match.group(2) | ||
|
|
||
| if line_str == conf_str: | ||
| if (line_value == "unlimited" | ||
| or (int(line_value) >= int(conf_value))): | ||
| conf_check.add_attribute(line, True, None, None) | ||
| vfio_mem_conf.remove(conf) | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like this function is more that just verify the config. I expect the verify function to return bool. Please improve the function name, add some empty lines after every logical code blocks.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added and improved |
||
| def check_memlock_conf(self): | ||
| """User memlock configuration""" | ||
|
|
||
| vfio_mem_conf = ["@sentient - memlock 134217728"] | ||
| num_cards = Spyre.get_number_of_spyre_cards() | ||
| memlimit = num_cards * 134234112 | ||
| vfio_mem_conf = [f"@sentient - memlock {memlimit}"] | ||
| config_file = "/etc/security/limits.d/memlock.conf" | ||
|
|
||
| conf_check = ConfigurationFileCheck(self.check_memlock_conf.__doc__, | ||
|
|
@@ -150,9 +223,10 @@ def check_memlock_conf(self): | |
| with open(config_file, "r", encoding="utf-8") as file: | ||
| for line in file: | ||
| line = line.strip() | ||
| if line in vfio_mem_conf: | ||
| conf_check.add_attribute(line, True, None, None) | ||
| vfio_mem_conf.remove(line) | ||
| if not line: | ||
| continue | ||
| self.is_mem_limit_config_valid(conf_check, | ||
| line, vfio_mem_conf) | ||
|
|
||
| except FileNotFoundError: | ||
| self.log.error("File not found : %s", config_file) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add example string that matches the above patter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added