Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp874658pxj; Fri, 21 May 2021 00:50:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxj+JTJsoFrDnh8B/Xn1hh3xZSPrQl8K3ePmhWXhnOlY2jam7n08yZge9Pfa/Tql9ws7wAw X-Received: by 2002:a17:906:dfc1:: with SMTP id jt1mr8954192ejc.473.1621583446270; Fri, 21 May 2021 00:50:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621583446; cv=none; d=google.com; s=arc-20160816; b=IGmx6x+CseEBcnv9b5OWO4J1BWLQeWGpcvtGLizIiWGl0rzmDCtX0KQp2kpFXSStCK FXX9+vvhV7nOJUr3EYfBeGHKm2Iz2keBS24sFF69m+zs0ZpX1wRHl0lxpB/IOTB4KVmG 6x+5lLebu5RyBlMauDkArZQjIalCN10TQJPmRK2TOj30IaPmn7mNkWXandbnfCVCI28+ /bDlVswLF4oieGpOsvCXVQDbEqKbvI9rUHzCWfCvWKwiGgT3GD8j1GkbyIucLDsG7JJv zf5wfkTtJQ83tm+gn4+M+GSRmzMvjL41G8dCD69zqRufiAWDXBecgUELAAM6M3hMzBMI S12A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=0kHUdBz9cuFf2vqxAG3Pc3rwFQXdOdHIp65C2b34hQI=; b=qN+M1r5rF4FOVR9AjaQNx7pVGSO0vQX/Jq9xioEUC3OPMPP9uPKQ/e4dYDBQkklesr ckBVRjDUXCckk4mHLVg5mUX8PHnTsL6kxHwDUsdR019NM/CM0WOkamfY2ZH7p9W7yu1B 6B/apLajagXzufdoq+88BnaRqz6RJDi8YXnk8vSp1sChrYqG/aH4oLkRWZ6RvSjuhN8W rlWfzJrEfyWDjMxywThyqWzu8cJgAH4PmNKMe+hB9bEBcfMp+TmYgaOuD3M++/oC+dKt UUYcGn2vhM+PVUU3bPaxq7TIZ8FUD4WEgoCYth38SiZD5bdTXPr5mymSr41BikqfklFO duIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=dEbYyegV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o32si4548398eda.316.2021.05.21.00.50.22; Fri, 21 May 2021 00:50:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=dEbYyegV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236062AbhETUXh (ORCPT + 99 others); Thu, 20 May 2021 16:23:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236245AbhETUXe (ORCPT ); Thu, 20 May 2021 16:23:34 -0400 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8845AC061574 for ; Thu, 20 May 2021 13:22:11 -0700 (PDT) Received: by mail-pf1-x42f.google.com with SMTP id x18so8931285pfi.9 for ; Thu, 20 May 2021 13:22:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=0kHUdBz9cuFf2vqxAG3Pc3rwFQXdOdHIp65C2b34hQI=; b=dEbYyegVNncUJt/SGH/oedIn1Atx8b0ygTK3+FvgB7epKgdgC9Dr0BsUcCu0DxDONy nOdkHnRrc3EBQFs4KDXJ2K2uXczhWNN1TvwwnypClxAMhk225QAwV9ZAelVesgPg4gEr 31hxAUaGEeNvn6+euCcc++hR4Xgw1fdJ0bpe9gijjtkWvhSXD/tHe5v0KrdOqvGiZ5NY P6OGPy2PbFW56a9XMokoEoRNtE8kgoqlejBFIcr1DWdGvlU9ZNvYJlWfmLN53bOLE3SM zedriT9bXOz/nINIc4gsQfjJhak9v4hEdPX055ElQy+ecm56rMsB3X+mLdo/0q44EAj4 wjHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=0kHUdBz9cuFf2vqxAG3Pc3rwFQXdOdHIp65C2b34hQI=; b=S6HdC1pehjloiRl1dAJn2rbWlJDuNRcCI7llbl+8L7V8y8PkGIVB6hMEcnHKUdh7Cq Po1MbnUdDK/RPMAIQrxdVq4oeGl2arZUw+cRQk8q7Wc93Ms9PL2AJn8uYcddevSlM+Ck Mmm7eQLJ9Jl9RBYyhGW+RY3n4aoNHKxOYu0wX7zYPsfEhh6NUIlWfqzhNPAE5wKmDsSW fHMBCImSmziRwOBA0WxQZIjX4DahqbPgW9SgM5sY4PGKpUFve3vhEhU7gP0nlhiLKViS 3ns2WR8e7pwf1ku6lTWnMh/yd3rsjuy6js/nfOdT7ns6j0E9ynJeAudCBJTnQ+0K65RH 8bDg== X-Gm-Message-State: AOAM532rXGjxribhRIMYD5hjnu5eO1iqxCgsbj6UZ1t1+uL5bLT9rBeE xuDCGSROFHNLtJpkmoywg6YOmw== X-Received: by 2002:a63:224d:: with SMTP id t13mr6260936pgm.283.1621542130812; Thu, 20 May 2021 13:22:10 -0700 (PDT) Received: from google.com (240.111.247.35.bc.googleusercontent.com. [35.247.111.240]) by smtp.gmail.com with ESMTPSA id x203sm2612206pfc.86.2021.05.20.13.22.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 May 2021 13:22:10 -0700 (PDT) Date: Thu, 20 May 2021 20:22:06 +0000 From: Sean Christopherson To: Tom Lendacky Cc: Peter Gonda , kvm list , linux-kernel@vger.kernel.org, x86@kernel.org, Paolo Bonzini , Jim Mattson , Joerg Roedel , Vitaly Kuznetsov , Wanpeng Li , Borislav Petkov , Ingo Molnar , Thomas Gleixner , Brijesh Singh Subject: Re: [PATCH] KVM: SVM: Do not terminate SEV-ES guests on GHCB validation failure Message-ID: References: <324d9228-03e9-0fe2-59c0-5e41e449211b@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 20, 2021, Sean Christopherson wrote: > On Thu, May 20, 2021, Sean Christopherson wrote: > > On Mon, May 17, 2021, Tom Lendacky wrote: > > > On 5/14/21 6:06 PM, Peter Gonda wrote: > > > > On Fri, May 14, 2021 at 1:22 PM Tom Lendacky wrote: > > > >> > > > >> Currently, an SEV-ES guest is terminated if the validation of the VMGEXIT > > > >> exit code and parameters fail. Since the VMGEXIT instruction can be issued > > > >> from userspace, even though userspace (likely) can't update the GHCB, > > > >> don't allow userspace to be able to kill the guest. > > > >> > > > >> Return a #GP request through the GHCB when validation fails, rather than > > > >> terminating the guest. > > > > > > > > Is this a gap in the spec? I don't see anything that details what > > > > should happen if the correct fields for NAE are not set in the first > > > > couple paragraphs of section 4 'GHCB Protocol'. > > > > > > No, I don't think the spec needs to spell out everything like this. The > > > hypervisor is free to determine its course of action in this case. > > > > The hypervisor can decide whether to inject/return an error or kill the guest, > > but what errors can be returned and how they're returned absolutely needs to be > > ABI between guest and host, and to make the ABI vendor agnostic the GHCB spec > > is the logical place to define said ABI. > > > > For example, "injecting" #GP if the guest botched the GHCB on #VMGEXIT(CPUID) is > > completely nonsensical. As is, a Linux guest appears to blindly forward the #GP, > > which means if something does go awry KVM has just made debugging the guest that > > much harder, e.g. imagine the confusion that will ensue if the end result is a > > SIGBUS to userspace on CPUID. > > > > There needs to be an explicit error code for "you gave me bad data", otherwise > > we're signing ourselves up for future pain. > > More concretely, I think the best course of action is to define a new return code > in SW_EXITINFO1[31:0], e.g. '2', with additional information in SW_EXITINFO2. > > In theory, an old-but-sane guest will interpret the unexpected return code as > fatal to whatever triggered the #VMGEXIT, e.g. SIGBUS to userspace. Unfortunately > Linux isn't sane because sev_es_ghcb_hv_call() assumes any non-'1' result means > success, but that's trivial to fix and IMO should be fixed irrespective of where > this goes. One last thing (hopefully): Erdem pointed out that if the GCHB GPA (or any derferenced pointers within the GHCB) is invalid or is set to a private GPA (mostly in the context of SNP) then the VMM will likely have no choice but to kill the guest in response to #VMGEXIT. It's probably a good idea to add a blurb in one of the specs explicitly calling out that #VMGEXIT can be executed from userspace, and that before returning to uesrspace the guest kernel must always ensure that the GCHB points at a legal GPA _and_ all primary fields are marked invalid.