From nobody Fri Dec 19 09:59:23 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 43C2FEE14A5 for ; Wed, 6 Sep 2023 15:15:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242413AbjIFPPF (ORCPT ); Wed, 6 Sep 2023 11:15:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231874AbjIFPO7 (ORCPT ); Wed, 6 Sep 2023 11:14:59 -0400 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 007FBE64 for ; Wed, 6 Sep 2023 08:14:55 -0700 (PDT) Received: by mail-pf1-x44a.google.com with SMTP id d2e1a72fcca58-68a6cd7c6c0so4240294b3a.3 for ; Wed, 06 Sep 2023 08:14:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1694013295; x=1694618095; darn=vger.kernel.org; h=cc:to:from:subject:mime-version:message-id:date:from:to:cc:subject :date:message-id:reply-to; bh=SGtKf8yShh4CSFb6KNk0X1Y8UQuGAFVHPS1RsqL9uvw=; b=e9OJlsja2yDVUsaaJcouDggemXncgGbjGgSdKaU2OQc/fZW18llLTRmppaEqg2zJId WgjMSNVdYroxuVxHfJiKm8eV6npBenKh6vl5+83bzalJX+N9s02y3u4uEu8bK7gvSRUF ROI880OEzxIHfIIN3EwOUqk+qwOav76FC1Pr/JG4P3aKEMMCBYP1ZEH+BM+Od8KLhGXC jV+BePOO9IowjiEJz0aCvXzf0ijggERaF03w5Hz4cbBFB89ZE3jtjT3hWHxSq4f6vGUu ocVjqmayJXeTnUU/DAwdNxKGeFZGopW18H7cmAuADwlcQeVeEm5QI6xNRIwcdxPkhr/R wGuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1694013295; x=1694618095; h=cc:to:from:subject:mime-version:message-id:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=SGtKf8yShh4CSFb6KNk0X1Y8UQuGAFVHPS1RsqL9uvw=; b=PKfj33FlwkKXalVQGWesBjZU50Jt2rdXhuGBp2ZFvTxIyAdKlcnIcOx0tSZKRxSzqv kmWZhc8FP3xHcyxhWxxe+Ts75WVoHsTL7XgGGbltsmjXWufWRpgfeIPSTlZlfkRvliHx ZdNu+EoIcHqLoo+HpYNzXpcGxa39eFXh/FlGikoUHcF/5t/dyuw6kovidVbpp+aOsae4 mjrsmTGsnYwXS3GHTm70TFZNOAv3tl8WIn3X0q6tpCTglP5QrXHvgyXeYMDVyjia2a/9 J+YMlcQ1p9+4mCwN6ZModwCV0zqHuS4pYQNzxZBBEvkKgN4nc6hIS79vNBy7qvRN37j+ ARZA== X-Gm-Message-State: AOJu0Yyuc3UmS1TbuMG5KtuLNI66uvfj+D17nEydzAKT+z5+DhSK3m50 cuSlHIz+d3wDsd07xNifl/Hws/a0hl4= X-Google-Smtp-Source: AGHT+IE/tnuG+PBjEOm9KRjhb810rtGMR0faOhyMhq/4H9d1Hbu0eGVfxaqNx9WupFQMz6s1rtWrHx2cwxI= X-Received: from pgonda1.kir.corp.google.com ([2620:0:1008:15:e3bb:5424:b689:5e16]) (user=pgonda job=sendgmr) by 2002:a17:902:ced2:b0:1b8:95fc:d0f with SMTP id d18-20020a170902ced200b001b895fc0d0fmr5800744plg.7.1694013295413; Wed, 06 Sep 2023 08:14:55 -0700 (PDT) Date: Wed, 6 Sep 2023 08:14:49 -0700 Message-Id: <20230906151449.18312-1-pgonda@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.42.0.283.g2d96d420d3-goog Subject: [PATCH V2] KVM: SEV: Update SEV-ES shutdown intercepts with more metadata From: Peter Gonda To: kvm@vger.kernel.org Cc: Peter Gonda , Paolo Bonzini , Sean Christopherson , Tom Lendacky , Joerg Roedel , Borislav Petkov , x86@kernel.org, linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Currently if an SEV-ES VM shuts down userspace sees KVM_RUN struct with only the INVALID_ARGUMENT. This is a very limited amount of information to debug the situation. Instead KVM can return a KVM_EXIT_SHUTDOWN to alert userspace the VM is shutting down and is not usable any further. Signed-off-by: Peter Gonda Cc: Paolo Bonzini Cc: Sean Christopherson Cc: Tom Lendacky Cc: Joerg Roedel Cc: Borislav Petkov Cc: x86@kernel.org Cc: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Acked-by: Tom Lendacky --- arch/x86/kvm/svm/svm.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 956726d867aa..cecf6a528c9b 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -2131,12 +2131,14 @@ static int shutdown_interception(struct kvm_vcpu *v= cpu) * The VM save area has already been encrypted so it * cannot be reinitialized - just terminate. */ - if (sev_es_guest(vcpu->kvm)) - return -EINVAL; + if (sev_es_guest(vcpu->kvm)) { + kvm_run->exit_reason =3D KVM_EXIT_SHUTDOWN; + return 0; + } =20 /* * VMCB is undefined after a SHUTDOWN intercept. INIT the vCPU to put - * the VMCB in a known good state. Unfortuately, KVM doesn't have + * the VMCB in a known good state. Unfortunately, KVM doesn't have * KVM_MP_STATE_SHUTDOWN and can't add it without potentially breaking * userspace. At a platform view, INIT is acceptable behavior as * there exist bare metal platforms that automatically INIT the CPU --=20 2.42.0.283.g2d96d420d3-goog