On 9/11/2023 6:02 PM, Manali Shukla wrote: > On 9/8/2023 7:01 PM, Peter Zijlstra wrote: >> On Thu, Sep 07, 2023 at 09:19:51PM +0530, Manali Shukla wrote: >> >>>> I'm not sure I'm fluent in virt speak (in fact, I'm sure I'm not). Is >>>> the above saying that a host can never IBS profile a guest? >>> >>> Host can profile a guest with IBS if VIBS is disabled for the guest. This is >>> the default behavior. Host can not profile guest if VIBS is enabled for guest. >>> >>>> >>>> Does the current IBS thing assert perf_event_attr::exclude_guest is set? >>> >>> Unlike AMD core pmu, IBS doesn't have Host/Guest filtering capability, thus >>> perf_event_open() fails if exclude_guest is set for an IBS event. >> >> Then you must not allow VIBS if a host cpu-wide IBS counter exists. >> >> Also, VIBS reads like it can be (ab)used as a filter. > > I think I get your point: If host IBS with exclude_guest=0 doesn't capture > guest samples because of VIBS, it is an unintended behavior. > > But if a guest cannot use IBS because a host is using it, that is also > unacceptable behavior. > > Let me think over it and come back. > > - Manali Hi Peter, Apologies for the delay in response. It took me a while to think about various possible solutions and their feasibility. Problem with current design is, exclude_guest setting of the host IBS event is not honored. Essentially, guest samples become invisible to the host IBS even when exclude_guest=0, when VIBS is enabled on the guest. Solution 1: Enforce exclude_guest=1 for host IBS when hw supports VIBS, i.e. if (cpuid[VIBS]) enforce exclude_guest=1 else enforce exclude_guest=0 Disable/enable host IBS at VM Entry/VM Exit if cpuid[VIBS] is set and an active IBS event exists on that cpu. The major downside of this approach is, it will break all currently working scripts which are using perf_event_open() to start an ibs event, since new kernel will suddenly start failing for IBS events with exclude_guest=0. The other issue is that the host with cpuid[VIBS] set, would not allow profiling any guest from the host. Solution 1.1: This is an extension to Solution 1. Instead of keying off based on just cpuid[VIBS] bit, introduce a kvm-amd module parameter and use both: if (cpuid[VIBS] && kvm-amd.ko loaded with vibs=1) enforce exclude_guest=1 else enforce exclude_guest=0 KVM AMD vibs module parameter determines whether guest will be able to use VIBS or not. The kvm-amd.ko should be loaded with vibs=0, if a host wants to profile guest and the kvm-amd.ko should be loaded with vibs=1, if a guest wants to use VIBS. However, both are mutually exclusive. The issue of digressing from current exclude_guest behavior remains with this solution. Other issues are, 1) If the host IBS is active, with vibs=0, reloading of the kvm-amd.ko with vibs=1 will fail until IBS is running on the host. 2) If the host IBS is active, with vibs=1, reloading of the kvm-amd.ko with vibs=0 will fail until IBS is running on the host. Solution 2: Dynamically disable/enable VIBS per vCPU basis, i.e. when a host IBS is active, guest will not be able to use VIBS _for that vCPU_. If the host is not using IBS, VIBS will be enabled at VM Entry. Although this solution does not digress from existing exclude_guest behavior, it has its own limitations: 1) VIBS inside the guest is unreliable because host IBS can dynamically change VIBS behavior. 2) It works only for SVM and SEV guests, but not for SEV-ES and SEV-SNP guests since there is no way to disable VIBS dynamically. >From all the above solutions, we would be more inclined on implementing solution 1.1. -Manali