Mint a new cookie for each vCPU thread. A vCPU with a unique cookie is never scheduled concurrently on the sibling thread of the same core. So, while one CPU thread runs, the scheduler forces the sibling to idle. The core scheduling mechanism cannot affect isolation. Hardware enforces the requirement that while a vCPU is in the guest mode, the sibling thread is in idle. It does decide whether the guest makes progress even when the vCPU threads are scheduled or pinned on the same core without being stalled in a KVM VMEXIT_IDLE_REQUIRED retry loop. Signed-off-by: Pratik R. Sampat --- target/i386/sev.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/target/i386/sev.c b/target/i386/sev.c index 1b5b833974cc..711d28780983 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -18,6 +18,7 @@ #include #include +#include #include "qapi/error.h" #include "qapi/qapi-type-infos-common.h" @@ -2040,6 +2041,31 @@ static int sev_kvm_init(ConfidentialGuestSupport *cgs, Error **errp) return 0; } +static void smtp_core_sched_setup(CPUState *leader, run_on_cpu_data arg) +{ + CPUState *cpu; + int ret; + + CPU_FOREACH(cpu) { + ret = prctl(PR_SCHED_CORE, PR_SCHED_CORE_CREATE, cpu->thread_id, + PR_SCHED_CORE_SCOPE_THREAD, 0); + if (ret < 0) { + error_report("vCPU %lu: failed to create core-sched cookie: %s", + kvm_arch_vcpu_id(cpu), strerror(errno)); + return; + } + } +} + +static void smtp_core_sched_notify(Notifier *notifier, void *data) +{ + run_on_cpu(first_cpu, smtp_core_sched_setup, RUN_ON_CPU_NULL); +} + +static Notifier sev_snp_smtp_notify = { + .notify = smtp_core_sched_notify, +}; + static int sev_snp_kvm_init(ConfidentialGuestSupport *cgs, Error **errp) { MachineState *ms = MACHINE(qdev_get_machine()); @@ -2058,6 +2084,11 @@ static int sev_snp_kvm_init(ConfidentialGuestSupport *cgs, Error **errp) g_free(sev_snp_guest->kernel_hashes_data); sev_snp_guest->kernel_hashes_data = NULL; + /* Setup core scheduling cookies for SMTP after the vCPUs are all up */ + if (is_sev_feature_set(sev_common, SVM_SEV_FEAT_SMTP)) { + qemu_add_machine_init_done_notifier(&sev_snp_smtp_notify); + } + return 0; } -- 2.43.0