qemu-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-commits] [qemu/qemu] 13be92: target/i386: do not crash if microvm


From: Richard Henderson
Subject: [Qemu-commits] [qemu/qemu] 13be92: target/i386: do not crash if microvm guest uses SG...
Date: Tue, 23 Jul 2024 18:31:43 -0700

  Branch: refs/heads/staging
  Home:   https://github.com/qemu/qemu
  Commit: 13be929aff804581b21e69087a9caf3698fd5c3c
      
https://github.com/qemu/qemu/commit/13be929aff804581b21e69087a9caf3698fd5c3c
  Author: Paolo Bonzini <pbonzini@redhat.com>
  Date:   2024-07-22 (Mon, 22 Jul 2024)

  Changed paths:
    M hw/i386/sgx.c

  Log Message:
  -----------
  target/i386: do not crash if microvm guest uses SGX CPUID leaves

sgx_epc_get_section assumes a PC platform is in use:

bool sgx_epc_get_section(int section_nr, uint64_t *addr, uint64_t *size)
{
    PCMachineState *pcms = PC_MACHINE(qdev_get_machine());

However, sgx_epc_get_section is called by CPUID regardless of whether
SGX state has been initialized or which platform is in use.  Check
whether the machine has the right QOM class and if not behave as if
there are no EPC sections.

Fixes: 1dec2e1f19f ("i386: Update SGX CPUID info according to hardware/KVM/user 
input", 2021-09-30)
Cc: qemu-stable@nongnu.org
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2142
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>


  Commit: 95fa0c79a04f3ebebb9f3b68cc05b4b8082b5444
      
https://github.com/qemu/qemu/commit/95fa0c79a04f3ebebb9f3b68cc05b4b8082b5444
  Author: Anthony Harivel <aharivel@redhat.com>
  Date:   2024-07-22 (Mon, 22 Jul 2024)

  Changed paths:
    M include/io/channel.h
    M io/channel-socket.c
    M io/channel.c

  Log Message:
  -----------
  qio: add support for SO_PEERCRED for socket channel

The function qio_channel_get_peercred() returns a pointer to the
credentials of the peer process connected to this socket.

This credentials structure is defined in <sys/socket.h> as follows:

struct ucred {
        pid_t pid;    /* Process ID of the sending process */
        uid_t uid;    /* User ID of the sending process */
        gid_t gid;    /* Group ID of the sending process */
};

The use of this function is possible only for connected AF_UNIX stream
sockets and for AF_UNIX stream and datagram socket pairs.

On platform other than Linux, the function return 0.

Signed-off-by: Anthony Harivel <aharivel@redhat.com>
Link: https://lore.kernel.org/r/20240522153453.1230389-2-aharivel@redhat.com
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>


  Commit: 84369d762127157137006e29a971bb08a1bd17cd
      
https://github.com/qemu/qemu/commit/84369d762127157137006e29a971bb08a1bd17cd
  Author: Anthony Harivel <aharivel@redhat.com>
  Date:   2024-07-22 (Mon, 22 Jul 2024)

  Changed paths:
    M MAINTAINERS
    A contrib/systemd/qemu-vmsr-helper.service
    A contrib/systemd/qemu-vmsr-helper.socket
    M docs/tools/index.rst
    A docs/tools/qemu-vmsr-helper.rst
    M meson.build
    A tools/i386/qemu-vmsr-helper.c
    A tools/i386/rapl-msr-index.h

  Log Message:
  -----------
  tools: build qemu-vmsr-helper

Introduce a privileged helper to access RAPL MSR.

The privileged helper tool, qemu-vmsr-helper, is designed to provide
virtual machines with the ability to read specific RAPL (Running Average
Power Limit) MSRs without requiring CAP_SYS_RAWIO privileges or relying
on external, out-of-tree patches.

The helper tool leverages Unix permissions and SO_PEERCRED socket
options to enforce access control, ensuring that only processes
explicitly requesting read access via readmsr() from a valid Thread ID
can access these MSRs.

The list of RAPL MSRs that are allowed to be read by the helper tool is
defined in rapl-msr-index.h. This list corresponds to the RAPL MSRs that
will be supported in the next commit titled "Add support for RAPL MSRs
in KVM/QEMU."

The tool is intentionally designed to run on the Linux x86 platform.
This initial implementation is tailored for Intel CPUs but can be
extended to support AMD CPUs in the future.

Signed-off-by: Anthony Harivel <aharivel@redhat.com>
Link: https://lore.kernel.org/r/20240522153453.1230389-3-aharivel@redhat.com
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>


  Commit: 0418f90809aea5b375c859e744c8e8610e9be446
      
https://github.com/qemu/qemu/commit/0418f90809aea5b375c859e744c8e8610e9be446
  Author: Anthony Harivel <aharivel@redhat.com>
  Date:   2024-07-22 (Mon, 22 Jul 2024)

  Changed paths:
    M accel/kvm/kvm-all.c
    M docs/specs/index.rst
    A docs/specs/rapl-msr.rst
    M include/sysemu/kvm_int.h
    M target/i386/cpu.h
    M target/i386/kvm/kvm.c
    M target/i386/kvm/meson.build
    A target/i386/kvm/vmsr_energy.c
    A target/i386/kvm/vmsr_energy.h

  Log Message:
  -----------
  Add support for RAPL MSRs in KVM/Qemu

Starting with the "Sandy Bridge" generation, Intel CPUs provide a RAPL
interface (Running Average Power Limit) for advertising the accumulated
energy consumption of various power domains (e.g. CPU packages, DRAM,
etc.).

The consumption is reported via MSRs (model specific registers) like
MSR_PKG_ENERGY_STATUS for the CPU package power domain. These MSRs are
64 bits registers that represent the accumulated energy consumption in
micro Joules. They are updated by microcode every ~1ms.

For now, KVM always returns 0 when the guest requests the value of
these MSRs. Use the KVM MSR filtering mechanism to allow QEMU handle
these MSRs dynamically in userspace.

To limit the amount of system calls for every MSR call, create a new
thread in QEMU that updates the "virtual" MSR values asynchronously.

Each vCPU has its own vMSR to reflect the independence of vCPUs. The
thread updates the vMSR values with the ratio of energy consumed of
the whole physical CPU package the vCPU thread runs on and the
thread's utime and stime values.

All other non-vCPU threads are also taken into account. Their energy
consumption is evenly distributed among all vCPUs threads running on
the same physical CPU package.

To overcome the problem that reading the RAPL MSR requires priviliged
access, a socket communication between QEMU and the qemu-vmsr-helper is
mandatory. You can specified the socket path in the parameter.

This feature is activated with -accel kvm,rapl=true,path=/path/sock.sock

Actual limitation:
- Works only on Intel host CPU because AMD CPUs are using different MSR
  adresses.

- Only the Package Power-Plane (MSR_PKG_ENERGY_STATUS) is reported at
  the moment.

Signed-off-by: Anthony Harivel <aharivel@redhat.com>
Link: https://lore.kernel.org/r/20240522153453.1230389-4-aharivel@redhat.com
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>


  Commit: f0ccf770789e48b7a73497b465fdc892d28c1339
      
https://github.com/qemu/qemu/commit/f0ccf770789e48b7a73497b465fdc892d28c1339
  Author: Paolo Bonzini <pbonzini@redhat.com>
  Date:   2024-07-22 (Mon, 22 Jul 2024)

  Changed paths:
    M hw/timer/hpet.c

  Log Message:
  -----------
  hpet: fix and cleanup persistence of interrupt status

There are several bugs in the handling of the ISR register:

- switching level->edge was not lowering the interrupt and
  clearing ISR

- switching on the enable bit was not raising a level-triggered
  interrupt if the timer had fired

- the timer must be kept running even if not enabled, in
  order to set the ISR flag, so writes to HPET_TN_CFG must
  not call hpet_del_timer()

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>


  Commit: 9eb7fad3546a89ee7cf0e90f5b1daccf89725cea
      
https://github.com/qemu/qemu/commit/9eb7fad3546a89ee7cf0e90f5b1daccf89725cea
  Author: Paolo Bonzini <pbonzini@redhat.com>
  Date:   2024-07-22 (Mon, 22 Jul 2024)

  Changed paths:
    M hw/timer/hpet.c
    M hw/timer/trace-events

  Log Message:
  -----------
  hpet: ignore high bits of comparator in 32-bit mode

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>


  Commit: 5895879aca252f4ebb2d1078eaf836c61ec54e9b
      
https://github.com/qemu/qemu/commit/5895879aca252f4ebb2d1078eaf836c61ec54e9b
  Author: Paolo Bonzini <pbonzini@redhat.com>
  Date:   2024-07-22 (Mon, 22 Jul 2024)

  Changed paths:
    M hw/timer/hpet.c

  Log Message:
  -----------
  hpet: remove unnecessary variable "index"

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>


  Commit: ba88935b0fac2588b0a739f810b58dfabf7f92c8
      
https://github.com/qemu/qemu/commit/ba88935b0fac2588b0a739f810b58dfabf7f92c8
  Author: Paolo Bonzini <pbonzini@redhat.com>
  Date:   2024-07-22 (Mon, 22 Jul 2024)

  Changed paths:
    M hw/timer/hpet.c

  Log Message:
  -----------
  hpet: place read-only bits directly in "new_val"

The variable "val" is used for two different purposes.  As an intermediate
value when writing configuration registers, and to store the cleared bits
when writing ISR.

Use "new_val" for the former, and rename the variable so that it is clearer
for the latter case.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>


  Commit: c2366567378dd8fb89329816003801f54e30e6f3
      
https://github.com/qemu/qemu/commit/c2366567378dd8fb89329816003801f54e30e6f3
  Author: Paolo Bonzini <pbonzini@redhat.com>
  Date:   2024-07-22 (Mon, 22 Jul 2024)

  Changed paths:
    M hw/timer/hpet.c
    M hw/timer/trace-events

  Log Message:
  -----------
  hpet: accept 64-bit reads and writes

Declare the MemoryRegionOps so that 64-bit reads and writes to the HPET
are received directly.  This makes it possible to unify the code to
process low and high parts: for 32-bit reads, extract the desired word;
for 32-bit writes, just merge the desired part into the old value and
proceed as with a 64-bit write.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>


  Commit: 242d665396407f83a6acbffc804882eeb21cfdad
      
https://github.com/qemu/qemu/commit/242d665396407f83a6acbffc804882eeb21cfdad
  Author: Paolo Bonzini <pbonzini@redhat.com>
  Date:   2024-07-22 (Mon, 22 Jul 2024)

  Changed paths:
    M hw/timer/hpet.c

  Log Message:
  -----------
  hpet: store full 64-bit target value of the counter

Store the full 64-bit value at which the timer should fire.

This makes it possible to skip the imprecise hpet_calculate_diff()
step, and to remove the clamping of the period to 31 or 63 bits.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>


  Commit: 7c912ffb59e8137091894d767433e65c3df8b0bf
      
https://github.com/qemu/qemu/commit/7c912ffb59e8137091894d767433e65c3df8b0bf
  Author: Paolo Bonzini <pbonzini@redhat.com>
  Date:   2024-07-22 (Mon, 22 Jul 2024)

  Changed paths:
    M hw/timer/hpet.c

  Log Message:
  -----------
  hpet: avoid timer storms on periodic timers

If the period is set to a value that is too low, there could be no
time left to run the rest of QEMU.  Do not trigger interrupts faster
than 1 MHz.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>


  Commit: 43f59bf76535b8842a762f8625b96091611aac11
      
https://github.com/qemu/qemu/commit/43f59bf76535b8842a762f8625b96091611aac11
  Author: Richard Henderson <richard.henderson@linaro.org>
  Date:   2024-07-24 (Wed, 24 Jul 2024)

  Changed paths:
    M MAINTAINERS
    M accel/kvm/kvm-all.c
    A contrib/systemd/qemu-vmsr-helper.service
    A contrib/systemd/qemu-vmsr-helper.socket
    M docs/specs/index.rst
    A docs/specs/rapl-msr.rst
    M docs/tools/index.rst
    A docs/tools/qemu-vmsr-helper.rst
    M hw/i386/sgx.c
    M hw/timer/hpet.c
    M hw/timer/trace-events
    M include/io/channel.h
    M include/sysemu/kvm_int.h
    M io/channel-socket.c
    M io/channel.c
    M meson.build
    M target/i386/cpu.h
    M target/i386/kvm/kvm.c
    M target/i386/kvm/meson.build
    A target/i386/kvm/vmsr_energy.c
    A target/i386/kvm/vmsr_energy.h
    A tools/i386/qemu-vmsr-helper.c
    A tools/i386/rapl-msr-index.h

  Log Message:
  -----------
  Merge tag 'for-upstream' of https://gitlab.com/bonzini/qemu into staging

* target/i386/kvm: support for reading RAPL MSRs using a helper program
* hpet: emulation improvements

# -----BEGIN PGP SIGNATURE-----
#
# iQFIBAABCAAyFiEE8TM4V0tmI4mGbHaCv/vSX3jHroMFAmaelL4UHHBib256aW5p
# QHJlZGhhdC5jb20ACgkQv/vSX3jHroMXoQf+K77lNlHLETSgeeP3dr7yZPOmXjjN
# qFY/18jiyLw7MK1rZC09fF+n9SoaTH8JDKupt0z9M1R10HKHLIO04f8zDE+dOxaE
# Rou3yKnlTgFPGSoPPFr1n1JJfxtYlLZRoUzaAcHUaa4W7JR/OHJX90n1Rb9MXeDk
# jV6P0v1FWtIDdM6ERm9qBGoQdYhj6Ra2T4/NZKJFXwIhKEkxgu4yO7WXv8l0dxQz
# jE4fKotqAvrkYW1EsiVZm30lw/19duhvGiYeQXoYhk8KKXXjAbJMblLITSNWsCio
# 3l6Uud/lOxekkJDAq5nH3H9hCBm0WwvwL+0vRf3Mkr+/xRGvrhtmUdp8NQ==
# =00mB
# -----END PGP SIGNATURE-----
# gpg: Signature made Tue 23 Jul 2024 03:19:58 AM AEST
# gpg:                using RSA key F13338574B662389866C7682BFFBD25F78C7AE83
# gpg:                issuer "pbonzini@redhat.com"
# gpg: Good signature from "Paolo Bonzini <bonzini@gnu.org>" [full]
# gpg:                 aka "Paolo Bonzini <pbonzini@redhat.com>" [full]

* tag 'for-upstream' of https://gitlab.com/bonzini/qemu:
  hpet: avoid timer storms on periodic timers
  hpet: store full 64-bit target value of the counter
  hpet: accept 64-bit reads and writes
  hpet: place read-only bits directly in "new_val"
  hpet: remove unnecessary variable "index"
  hpet: ignore high bits of comparator in 32-bit mode
  hpet: fix and cleanup persistence of interrupt status
  Add support for RAPL MSRs in KVM/Qemu
  tools: build qemu-vmsr-helper
  qio: add support for SO_PEERCRED for socket channel
  target/i386: do not crash if microvm guest uses SGX CPUID leaves

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>


Compare: https://github.com/qemu/qemu/compare/5885bcef3d76...43f59bf76535

To unsubscribe from these emails, change your notification settings at 
https://github.com/qemu/qemu/settings/notifications



reply via email to

[Prev in Thread] Current Thread [Next in Thread]