From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4AEA217A2ED for ; Thu, 27 Feb 2025 01:25:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740619552; cv=none; b=PKDV1yzVCwEnlLp8qSdnYQ7+SSXsjW1dmbGOUCISRnORIOK32eev0Rl6Cnr8g6T2fJyOsCNcZE4UnclbprygW3y87eAZs3WNQam5Ly87/EJpC3TsAFanSwbeMN5eTRca5entxmWNvCwIfG+869DXYnw5tAYOD3P2/O43t6yvPsc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740619552; c=relaxed/simple; bh=Ewaz9FSthSc+aO9YPlgCWiZASwxM0Q3IHNbCrYZLtjE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=kGE47uO6kJuQcpazWKd8EECRwYQZ45AWOX7BfttPcexyUFoBugZ13pqhxj6NHU7enZcsRrQhds3JDo5fT/uA/byJAj7x8eqfAAep+A6oc/sC368/THvj2RiqNZZ1wMFvO4cGKgkz8S2xF2LhrRhXMdriIyvEMZnXXfP1Hhh2GLo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ImvSxEue; arc=none smtp.client-ip=209.85.216.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ImvSxEue" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-2fce2954a10so1399927a91.1 for ; Wed, 26 Feb 2025 17:25:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1740619551; x=1741224351; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=sGOwbvJmfkCQ/c7rRacZC8cGcdWEXYUj8tUGbmEnuuE=; b=ImvSxEueIAH4AOmrXFYV2IcuZtNnCapc0pNkrVWrOiqXXZtDcPrkyDfcVYIWWTRrAS uPARJMNA2kUev5LdmFd/mnNkb3JLTFON1kGj2gTceIkPduV8JuQ6lQqTNZZNuiDW3N4V U9Z8Zohb63sxYcvniUoj0PdqH+aOrgr0y4u0H1fyOoSFHAWce9X09N27ov8We47D4mP5 2f8udvpxvvuF3DNtq1cE/AAJHMe00N0rudyXnuQlxReudj7duckLRdZkONPKFGBlDbRx 9SUau9LHho3HrBtUWmaWYcU2Y1x55qBa66FC33jW97Tul0bkf98VQksi205GvsXTIYRG 8+JA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740619551; x=1741224351; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=sGOwbvJmfkCQ/c7rRacZC8cGcdWEXYUj8tUGbmEnuuE=; b=JDoRc0KAefbTkXsCWECaxzqSlcAZAhxmNh6UM5/JQn+YDkW6orL5KvugE3KKvvdQIo GeWkhii+oCFMMF9Vd+2X+TMtKfJ031ttgoEUYRAQRXkIZqqayLwCkZ/xZpYo6D2Qe88F Uag9ukDg2ripEVUpCwY4n7d+M4op+tmJKLSkTABZk9wjDm5x7G1VKj3/w7VTrYfKHEik hHZkYILkqR+zKGWMrpojcQFqZnBZwAilpiakMf2+i/msPr6Zs2rsdIzLpLlatlVm1xta jTMp+Ddrxibz0OvwiJ4xf3aETi+ITBBPCEp0lpNPqYlz7gTCNYupGQM9J0hfFMG8nSa5 qWOw== X-Forwarded-Encrypted: i=1; AJvYcCVhLq4N72bOH39ft9AnNK+atIyKee2Ap/F9r62UMz5qbXbEoJ4dUtXXFQnUZ8PukPlYlpUlHY1ZLXyASWo=@vger.kernel.org X-Gm-Message-State: AOJu0Yzh6f+801rTeMoaTKvbHw9psYU3ajNNcPaTnuBNSgJsC5yfK+6j le/PjCpT/ZonklBdsSC20KGxUxZSs2mj7azJcPADCIk/qPLaAzoBEpjAHfKSano2bey7ZgzXoV9 ZMA== X-Google-Smtp-Source: AGHT+IFyryo7Y/u0uoVmOAJ5RVcaLpqcG1z9HpmL8i/TdRHGqTe/axQ2uqXYM/vYbUj6f5PszfDahrT6N+s= X-Received: from pjtu16.prod.google.com ([2002:a17:90a:c890:b0:2ee:3128:390f]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:3c84:b0:2fc:c262:ef4b with SMTP id 98e67ed59e1d1-2fce86cf0e0mr42713073a91.18.1740619550877; Wed, 26 Feb 2025 17:25:50 -0800 (PST) Reply-To: Sean Christopherson Date: Wed, 26 Feb 2025 17:25:35 -0800 In-Reply-To: <20250227012541.3234589-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250227012541.3234589-1-seanjc@google.com> X-Mailer: git-send-email 2.48.1.711.g2feabab25a-goog Message-ID: <20250227012541.3234589-5-seanjc@google.com> Subject: [PATCH v2 04/10] KVM: SVM: Don't change target vCPU state on AP Creation VMGEXIT error From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Naveen N Rao , Kim Phillips , Tom Lendacky , Alexey Kardashevskiy , Pankaj Gupta Content-Type: text/plain; charset="UTF-8" If KVM rejects an AP Creation event, leave the target vCPU state as-is. Nothing in the GHCB suggests the hypervisor is *allowed* to muck with vCPU state on failure, let alone required to do so. Furthermore, kicking only in the !ON_INIT case leads to divergent behavior, and even the "kick" case is non-deterministic. E.g. if an ON_INIT request fails, the guest can successfully retry if the fixed AP Creation request is made prior to sending INIT. And if a !ON_INIT fails, the guest can successfully retry if the fixed AP Creation request is handled before the target vCPU processes KVM's KVM_REQ_UPDATE_PROTECTED_GUEST_STATE. Fixes: e366f92ea99e ("KVM: SEV: Support SEV-SNP AP Creation NAE event") Cc: stable@vger.kernel.org Reviewed-by: Tom Lendacky Signed-off-by: Sean Christopherson --- arch/x86/kvm/svm/sev.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 218738a360ba..9aad0dae3a80 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -3957,16 +3957,12 @@ static int sev_snp_ap_creation(struct vcpu_svm *svm) /* * The target vCPU is valid, so the vCPU will be kicked unless the - * request is for CREATE_ON_INIT. For any errors at this stage, the - * kick will place the vCPU in an non-runnable state. + * request is for CREATE_ON_INIT. */ kick = true; mutex_lock(&target_svm->sev_es.snp_vmsa_mutex); - target_svm->sev_es.snp_vmsa_gpa = INVALID_PAGE; - target_svm->sev_es.snp_ap_waiting_for_reset = true; - /* Interrupt injection mode shouldn't change for AP creation */ if (request < SVM_VMGEXIT_AP_DESTROY) { u64 sev_features; @@ -4012,20 +4008,23 @@ static int sev_snp_ap_creation(struct vcpu_svm *svm) target_svm->sev_es.snp_vmsa_gpa = svm->vmcb->control.exit_info_2; break; case SVM_VMGEXIT_AP_DESTROY: + target_svm->sev_es.snp_vmsa_gpa = INVALID_PAGE; break; default: vcpu_unimpl(vcpu, "vmgexit: invalid AP creation request [%#x] from guest\n", request); ret = -EINVAL; - break; + goto out; } -out: + target_svm->sev_es.snp_ap_waiting_for_reset = true; + if (kick) { kvm_make_request(KVM_REQ_UPDATE_PROTECTED_GUEST_STATE, target_vcpu); kvm_vcpu_kick(target_vcpu); } +out: mutex_unlock(&target_svm->sev_es.snp_vmsa_mutex); return ret; -- 2.48.1.711.g2feabab25a-goog