# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2019-2021 Mikhail Morfikov
# Copyright (C) 2021-2024 Alexandre Pujol <alexandre@pujol.io>
# SPDX-License-Identifier: GPL-2.0-only

abi <abi/4.0>,

include <tunables/global>

@{exec_path} = @{bin}/cpupower
profile cpupower /{,usr/}{,s}bin/cpupower flags=(complain) {
  include <abstractions/base>

  # Needed to read the /dev/cpu/@{int}/msr device, and hence remove the following error:
  #  Could not read perf-bias value[-1]
  capability sys_rawio,

  # Needed to operate on CPU IDLE states
  capability sys_admin,

  @{exec_path} mr,

  @{sh_path}        rix,
  @{bin}/kmod       rCx -> kmod,
  @{bin}/man        rPx,

  @{sys}/devices/system/cpu/{cpufreq,cpuidle}/ r,
  @{sys}/devices/system/cpu/{cpufreq,cpuidle}/** r,
  @{sys}/devices/system/cpu/cpu@{int}/{cpufreq,cpuidle}/ r,
  @{sys}/devices/system/cpu/cpu@{int}/{cpufreq,cpuidle}/** r,

  @{sys}/devices/system/cpu/cpufreq/policy@{int}/scaling_{min,max}_freq rw,
  @{sys}/devices/system/cpu/cpufreq/policy@{int}/scaling_governor rw,
  @{sys}/devices/system/cpu/cpufreq/policy@{int}/scaling_setspeed rw,
  @{sys}/devices/system/cpu/cpu@{int}/cpuidle/state[0-9]/disable rw,

  @{sys}/devices/system/cpu/cpu@{int}/topology/{physical_package_id,core_id} r,

  @{sys}/devices/system/cpu/cpu@{int}/online r,

  /dev/cpu/@{int}/msr r,


  profile kmod flags=(complain) {
    include <abstractions/base>

    @{bin}/kmod mr,

    @{PROC}/cmdline r,
    #@{PROC}/modules r,

    /etc/modprobe.d/ r,
    /etc/modprobe.d/*.conf r,

  }

  include if exists <local/cpupower>
}
