Skip to content
Snippets Groups Projects
  1. Mar 29, 2023
  2. Nov 09, 2022
    • Rong Tao's avatar
      tools/kvm_stat: update exit reasons for vmx/svm/aarch64/userspace · 2c1b5434
      Rong Tao authored
      
      Update EXIT_REASONS from source, including VMX_EXIT_REASONS,
      SVM_EXIT_REASONS, AARCH64_EXIT_REASONS, USERSPACE_EXIT_REASONS.
      
      Signed-off-by: default avatarRong Tao <rongtao@cestc.cn>
      Message-Id: <tencent_00082C8BFA925A65E11570F417F1CD404505@qq.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      2c1b5434
    • Matthias Gerstner's avatar
      tools/kvm_stat: fix incorrect detection of debugfs · 8e1071d0
      Matthias Gerstner authored
      
      The first field in /proc/mounts can be influenced by unprivileged users
      through the widespread `fusermount` setuid-root program. Example:
      
      ```
      user$ mkdir ~/mydebugfs
      user$ export _FUSE_COMMFD=0
      user$ fusermount ~/mydebugfs -ononempty,fsname=debugfs
      user$ grep debugfs /proc/mounts
      debugfs /home/user/mydebugfs fuse rw,nosuid,nodev,relatime,user_id=1000,group_id=100 0 0
      ```
      
      If there is no debugfs already mounted in the system then this can be
      used by unprivileged users to trick kvm_stat into using a user
      controlled file system location for obtaining KVM statistics.
      Even though the root user is not allowed to access non-root FUSE mounts
      for security reasons, the unprivileged user can unmount the FUSE mount
      before kvm_stat uses the mounted path.  If it wins the race, kvm_stat
      will read from the location where the FUSE mount resided.
      
      Note that the files in debugfs are only opened for reading, so the
      attacker can cause very large data to be read in by kvm_stat, or fake
      data to be processed, but there should be no viable way to turn this
      into a privilege escalation.
      
      The fix is simply to use the file system type field instead. Whitespace
      in the mount path is escaped in /proc/mounts thus no further safety
      measures in the parsing should be necessary to make this correct.
      
      Message-Id: <20221103135927.13656-1-matthias.gerstner@suse.de>
      Signed-off-by: default avatarMatthias Gerstner <matthias.gerstner@suse.de>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      8e1071d0
  3. Jun 15, 2022
    • Dmitry Klochkov's avatar
      tools/kvm_stat: fix display of error when multiple processes are found · 933b5f9f
      Dmitry Klochkov authored
      
      Instead of printing an error message, kvm_stat script fails when we
      restrict statistics to a guest by its name and there are multiple guests
      with such name:
      
        # kvm_stat -g my_vm
        Traceback (most recent call last):
          File "/usr/bin/kvm_stat", line 1819, in <module>
            main()
          File "/usr/bin/kvm_stat", line 1779, in main
            options = get_options()
          File "/usr/bin/kvm_stat", line 1718, in get_options
            options = argparser.parse_args()
          File "/usr/lib64/python3.10/argparse.py", line 1825, in parse_args
            args, argv = self.parse_known_args(args, namespace)
          File "/usr/lib64/python3.10/argparse.py", line 1858, in parse_known_args
            namespace, args = self._parse_known_args(args, namespace)
          File "/usr/lib64/python3.10/argparse.py", line 2067, in _parse_known_args
            start_index = consume_optional(start_index)
          File "/usr/lib64/python3.10/argparse.py", line 2007, in consume_optional
            take_action(action, args, option_string)
          File "/usr/lib64/python3.10/argparse.py", line 1935, in take_action
            action(self, namespace, argument_values, option_string)
          File "/usr/bin/kvm_stat", line 1649, in __call__
            ' to specify the desired pid'.format(" ".join(pids)))
        TypeError: sequence item 0: expected str instance, int found
      
      To avoid this, it's needed to convert pids int values to strings before
      pass them to join().
      
      Signed-off-by: default avatarDmitry Klochkov <kdmitry556@gmail.com>
      Message-Id: <20220614121141.160689-1-kdmitry556@gmail.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      933b5f9f
  4. Oct 18, 2021
  5. May 07, 2021
  6. Mar 30, 2021
    • Stefan Raspl's avatar
      tools/kvm_stat: Add restart delay · 75f94ecb
      Stefan Raspl authored
      
      If this service is enabled and the system rebooted, Systemd's initial
      attempt to start this unit file may fail in case the kvm module is not
      loaded. Since we did not specify a delay for the retries, Systemd
      restarts with a minimum delay a number of times before giving up and
      disabling the service. Which means a subsequent kvm module load will
      have kvm running without monitoring.
      Adding a delay to fix this.
      
      Signed-off-by: default avatarStefan Raspl <raspl@linux.ibm.com>
      Message-Id: <20210325122949.1433271-1-raspl@linux.ibm.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      75f94ecb
  7. Dec 12, 2020
  8. Apr 21, 2020
    • Stefan Raspl's avatar
      tools/kvm_stat: add sample systemd unit file · 997b7e98
      Stefan Raspl authored
      
      Add a sample unit file as a basis for systemd integration of kvm_stat
      logs.
      
      Signed-off-by: default avatarStefan Raspl <raspl@de.ibm.com>
      Message-Id: <20200402085705.61155-4-raspl@linux.ibm.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      997b7e98
    • Stefan Raspl's avatar
      tools/kvm_stat: Add command line switch '-L' to log to file · 3754afe7
      Stefan Raspl authored
      
      To integrate with logrotate, we have a signal handler that will re-open
      the logfile.
      Assuming we have a systemd unit file with
           ExecStart=kvm_stat -dtc -s 10 -L /var/log/kvm_stat.csv
           ExecReload=/bin/kill -HUP $MAINPID
      and a logrotate config featuring
           postrotate
              /bin/systemctl reload kvm_stat.service
           endscript
      Then the overall flow will look like this:
      (1) systemd starts kvm_stat, logging to A.
      (2) At some point, logrotate runs, moving A to B.
          kvm_stat continues to write to B at this point.
      (3) After rotating, logrotate restarts the kvm_stat unit via systemctl.
      (4) The kvm_stat unit sends a SIGHUP to kvm_stat, finally making it
          switch over to writing to A again.
      Note that in order to keep the structure of the cvs output in tact, we
      make sure to, in contrast to the standard log format, only write the
      header once at the beginning of a file. This implies that the header is
      suppressed when appending to an existing file. Unlike with the standard
      format, where we append to an existing file by starting out with a
      header.
      
      Signed-off-by: default avatarStefan Raspl <raspl@de.ibm.com>
      Message-Id: <20200402085705.61155-3-raspl@linux.ibm.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      3754afe7
    • Stefan Raspl's avatar
      tools/kvm_stat: add command line switch '-z' to skip zero records · da1fda28
      Stefan Raspl authored
      
      When running in logging mode, skip records with all zeros (=empty records)
      to preserve space when logging to files.
      
      Signed-off-by: default avatarStefan Raspl <raspl@de.ibm.com>
      Message-Id: <20200402085705.61155-2-raspl@linux.ibm.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      da1fda28
  9. Mar 23, 2020
  10. Jan 23, 2020
  11. Jun 19, 2019
  12. May 24, 2019
    • Stefan Raspl's avatar
      tools/kvm_stat: fix fields filter for child events · 883d25e7
      Stefan Raspl authored
      
      The fields filter would not work with child fields, as the respective
      parents would not be included. No parents displayed == no childs displayed.
      To reproduce, run on s390 (would work on other platforms, too, but would
      require a different filter name):
      - Run 'kvm_stat -d'
      - Press 'f'
      - Enter 'instruct'
      Notice that events like instruction_diag_44 or instruction_diag_500 are not
      displayed - the output remains empty.
      With this patch, we will filter by matching events and their parents.
      However, consider the following example where we filter by
      instruction_diag_44:
      
        kvm statistics - summary
                         regex filter: instruction_diag_44
         Event                                         Total %Total CurAvg/s
         exit_instruction                                276  100.0       12
           instruction_diag_44                           256   92.8       11
         Total                                           276              12
      
      Note that the parent ('exit_instruction') displays the total events, but
      the childs listed do not match its total (256 instead of 276). This is
      intended (since we're filtering all but one child), but might be confusing
      on first sight.
      
      Signed-off-by: default avatarStefan Raspl <raspl@linux.ibm.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      883d25e7
  13. Nov 27, 2018
  14. Oct 01, 2018
  15. Aug 30, 2018
  16. Mar 28, 2018
  17. Feb 24, 2018
Loading