Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp1553828pxy; Fri, 23 Apr 2021 10:45:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyvkC6FxZI0CtbHsFF42Y0BfrR02GMr4An46jqHjelnzn+fOzNSxvhq40j52tNOAD4j0Zo3 X-Received: by 2002:a63:4942:: with SMTP id y2mr4882910pgk.256.1619199958281; Fri, 23 Apr 2021 10:45:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619199958; cv=none; d=google.com; s=arc-20160816; b=SCqf/bKLgjwklymCLqY8sjM0l0twHECHhRPu8kzCSKCMCqyroi/IaqKPy/cL6ltHRc exuU9yzYU+5NLu9tUMLyOQpAbwSbcxjRuWUGqs2XOCqltHcNW0S57skHrgS/UQEga/tu 2hEyFm0OhA7qVqy6xNOg4Cxa39F90pp360wtp+ux+cj8i5zVt2oejlS52ocbR/h4PVet 5niEWEQe5IK4MrpsscN4VaKmpfvUu5hB48Or2NE8P7BUlRuH1HJBQxPttK5OdhznadmA 4gdPOQYhZF3y+IAe5ClDnHBL2/OD3+Qfg9JqvetEu99lHd6tfL4/stvR9CpCr2gkT9MN GVAQ== 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=5RxMUwaNVhtTOHbRnIuRT1gcBdSG2y4cCkyp6iGC3r0=; b=0IHXe6rFulSayfNlk84QywIXKM3hGUQpR4qRTOewWGWoPb9ZG1mh3nhcA4qZ3XF+Jo S7pVSbVdwkOQ5oQTLZW49P5A0OPhLOlSAuo3Sdpo+X8JY3ENzKlDLTxtHSXCg2UQXmvh S/MiJg6kOOgSo9b5VDzZndvAg4sILvwsyZf6XnFlWPYueu2TNkJAUpZdZMjrLpPaUlmf fgw7HFMsz1tOFh7HJOFGVIkrR0MEw5xTmq2zDdMZcYSJX5SieYp6JjHF3EKXbrSieZmu hR0ybBASVlRZ3wvpuUUgF+5AW6iiw2k9Zq23prB5gCUcH82acexaSqXktBo9jhDXG0QX 08xA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=EEH3Wien; 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 e20si7097732pjt.93.2021.04.23.10.45.44; Fri, 23 Apr 2021 10:45:58 -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=EEH3Wien; 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 S232163AbhDWRpO (ORCPT + 99 others); Fri, 23 Apr 2021 13:45:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231522AbhDWRpN (ORCPT ); Fri, 23 Apr 2021 13:45:13 -0400 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 038AEC061574 for ; Fri, 23 Apr 2021 10:44:37 -0700 (PDT) Received: by mail-pj1-x102f.google.com with SMTP id y22-20020a17090a8b16b0290150ae1a6d2bso1688528pjn.0 for ; Fri, 23 Apr 2021 10:44:36 -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=5RxMUwaNVhtTOHbRnIuRT1gcBdSG2y4cCkyp6iGC3r0=; b=EEH3WienSxGlm5zSNY+62F2L+KCXVtwMTq8LpudqnF1poYn0PwrAOsHZUMt1nuhHgb m0IWPyypg4mNWp45rG5LnCgEjY7VATzj0tIkcQsfgkTWwCWFOsfnCrhljxezwIdD3rIF eJa+uf1ORQvRxImibK8MnhC/LkCS+j6NeKke4Q2xi3Fk/4z8Q+dxqQYSYnp8ODyCryhU RjZXZuCiG9wR3EE2a5zT++EEI/2S5FAdnLIGkXUY/wG0vpo4OKXgzcvpSNLr3a2KtGuk 3KXtcaS5V+zLqXJ7GypwOMWWYjbgmQnjv1HEgDbaMf9CtsA+c7HKdfzRs/x0i+DcGSa3 Lw2A== 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=5RxMUwaNVhtTOHbRnIuRT1gcBdSG2y4cCkyp6iGC3r0=; b=gpWBbci7pKAYe8YB5RXrilswkjSSF8mAc5gRpMBGWOvPmjOIB21aRzCCfmaEay+lgs uS1E5nKHBazwajHzn2LtvbEaeolrMSt+s0Kdvvy50adVAx0RO5kSnnhEiG9cpaPt8WtA GE0yMxucF1EOMOHuLRWjfHBR1PjC/OU/aVMGLpgVrnm1F7y8gCrqXDhNewoiQxQB44y+ y5zWZ/JCmchZDyKv3J7scSPBXgi+0C9E23/xIvdEJ2N/f/hwA3XqMPyZZdcMyYAzxk8/ gWdCp38tzw2B8g2KXMPJWbjHIWhA6oZpK138A3reDocpAyDfC1gFhCdaddEOM+zkJzXh aRcg== X-Gm-Message-State: AOAM533lrvGyQVjGNVrY0/1L85somlFlka1HeQgzbi94nNptsZpcOF68 bkyLwukEhKHbem7hCN1HHAo6nA== X-Received: by 2002:a17:902:b785:b029:eb:7a1b:5016 with SMTP id e5-20020a170902b785b02900eb7a1b5016mr4831326pls.51.1619199876334; Fri, 23 Apr 2021 10:44:36 -0700 (PDT) Received: from google.com (240.111.247.35.bc.googleusercontent.com. [35.247.111.240]) by smtp.gmail.com with ESMTPSA id m20sm4654058pfk.133.2021.04.23.10.44.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Apr 2021 10:44:35 -0700 (PDT) Date: Fri, 23 Apr 2021 17:44:32 +0000 From: Sean Christopherson To: Jim Mattson Cc: Ashish Kalra , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , "H . Peter Anvin" , Joerg Roedel , Borislav Petkov , Tom Lendacky , the arch/x86 maintainers , kvm list , LKML , Steve Rutherford , venu.busireddy@oracle.com, Brijesh Singh Subject: Re: [PATCH v2 1/4] KVM: x86: invert KVM_HYPERCALL to default to VMMCALL Message-ID: References: <76ad1a3f7ce817e8d269a6d58293fc128678affc.1619193043.git.ashish.kalra@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 Fri, Apr 23, 2021, Jim Mattson wrote: > On Fri, Apr 23, 2021 at 9:00 AM Ashish Kalra wrote: > > > > From: Ashish Kalra > > > > KVM hypercall framework relies on alternative framework to patch the > > VMCALL -> VMMCALL on AMD platform. If a hypercall is made before > > apply_alternative() is called then it defaults to VMCALL. The approach > > works fine on non SEV guest. A VMCALL would causes #UD, and hypervisor > > will be able to decode the instruction and do the right things. But > > when SEV is active, guest memory is encrypted with guest key and > > hypervisor will not be able to decode the instruction bytes. > > > > So invert KVM_HYPERCALL and X86_FEATURE_VMMCALL to default to VMMCALL > > and opt into VMCALL. > > > > Cc: Thomas Gleixner > > Cc: Ingo Molnar > > Cc: "H. Peter Anvin" > > Cc: Paolo Bonzini > > Cc: Joerg Roedel > > Cc: Borislav Petkov > > Cc: Tom Lendacky > > Cc: x86@kernel.org > > Cc: kvm@vger.kernel.org > > Cc: linux-kernel@vger.kernel.org > > Signed-off-by: Brijesh Singh > > Signed-off-by: Ashish Kalra > > --- > > arch/x86/include/asm/kvm_para.h | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/arch/x86/include/asm/kvm_para.h b/arch/x86/include/asm/kvm_para.h > > index 338119852512..fda2fe0d1b10 100644 > > --- a/arch/x86/include/asm/kvm_para.h > > +++ b/arch/x86/include/asm/kvm_para.h > > @@ -19,7 +19,7 @@ static inline bool kvm_check_and_clear_guest_paused(void) > > #endif /* CONFIG_KVM_GUEST */ > > > > #define KVM_HYPERCALL \ > > - ALTERNATIVE("vmcall", "vmmcall", X86_FEATURE_VMMCALL) > > + ALTERNATIVE("vmmcall", "vmcall", X86_FEATURE_VMCALL) > > > > /* For KVM hypercalls, a three-byte sequence of either the vmcall or the vmmcall > > * instruction. The hypervisor may replace it with something else but only the > > -- > > 2.17.1 > > > > Won't this result in the same problem when Intel implements full VM encryption? TDX uses yet another opcode, TDCALL, along with a different ABI. The existing KVM hypercalls are then tunneled through that ABI. TDX-specific hypercalls, which will handle the private vs. shared conversions, will not go through the KVM defined hypercalls because Intel has defined an ABI for guest/host communication to handle hypercalls that will be needed by all guest+VMM combos. E.g. to allow Linux/Windows guests to run on KVM/HyperV/VMware without having to have additional enlightment for the "basic" functionality. TL;DR: TDX won't use kvm_hypercall() before apply_alternative().