Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp110987pxu; Wed, 2 Dec 2020 16:37:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJzOHXM9ubGaEHYnsEeuKPHlUjTo2FmBfKY/lnQ6WtvJabqG2fViRSb5pBuSmqcObq03RVN9 X-Received: by 2002:a17:906:ae41:: with SMTP id lf1mr331429ejb.369.1606955866785; Wed, 02 Dec 2020 16:37:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606955866; cv=none; d=google.com; s=arc-20160816; b=MSBfKmeeskrJ/CHZrFP/yqFLU9HN61XZoEqV5cj0DAWdAGhepVuBMeQGJnDT11VSkl ln4uWMqPHjqCBCyFe6moRJ1NZrZtuUsunpg3CPis5myrnu3v/fmep8v/aJZKDx3VNAQa j3cewS+s2cpE63dlDWBFZqAg1W3CXjPnft0laj3A3+rOwabKS2mgq18OuT4dzIrP8xeo tveX6bkJ5DP6sm4EFH9wjzYZus+Gz3hHdiMnypufKJQNjlaPGUaiynDu13ucMbq+OA/O fbttKuA7bJHCSN5ljPunOHvnlJiLYdu/3V5WzzZ1BSwklQFmJnWQqSnkFTOJ52Aut+vz ZXNQ== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=L56VCJacW1q2c0bHUonnqO3sZEHGpPYCKrI7PJZeV18=; b=spl9DBlfvjNQuYkGd8Bj3fUgflYkRFfDiCcyndMLGR96dWcEeBKtLIC1P7v4DzynB6 bykbqva0HFwGGrvNBiUF5crCjiliAzSm9OftUaNIyR7nqbLwrQFfGzW56SX6XXZtNLug d90YJ9a2sehKrVj2tZVrTgTV0kC5zeg3EKEUiklk76jqx+7q6dk6jV8U3GbUImPJbMwA ewFlqX91FvSgR5UFZhYfjBQBCT0aephDmy7e3MJyP16N/c1EjoEsMY8pMkJ7gQwhtKHZ FMkgDPI6iXdfmNGmTGUzdmaGh1Z+YzX8eymSwtnkpjALz4DaYT63NFtcm1FmdXns1Iz/ 3HaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=bzscgACW; 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 a16si277120edn.109.2020.12.02.16.37.23; Wed, 02 Dec 2020 16:37:46 -0800 (PST) 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=bzscgACW; 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 S2387408AbgLCAfB (ORCPT + 99 others); Wed, 2 Dec 2020 19:35:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726024AbgLCAfB (ORCPT ); Wed, 2 Dec 2020 19:35:01 -0500 Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13BB2C0617A7 for ; Wed, 2 Dec 2020 16:34:21 -0800 (PST) Received: by mail-pj1-x1042.google.com with SMTP id iq13so125084pjb.3 for ; Wed, 02 Dec 2020 16:34:21 -0800 (PST) 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:content-transfer-encoding:in-reply-to; bh=L56VCJacW1q2c0bHUonnqO3sZEHGpPYCKrI7PJZeV18=; b=bzscgACWYc3NUKhdAGji4SgKcfDJVJkF+yXxV6yxbdh1qhcafmxgf4Pu5euI16pCgT kDAbPD/T8/TxwCo7vykXENNbWhmbWyLjTiY1+uJQzQPDFvZG4BhxDeVSWs28CkCSoO7G slUhuLp3WEnD9UZHpRMUZFcc2juBUh9I3gybu70uOsPke6hmk4nq/WAIDiz7xsItS+OO Ix5X3TxPKvD79KclsDJOi3H/MvnD3HtNmqPMU4PxttgGYhB4WKLuRV/WpSIlXccZ0sG6 R1fvITBHAzw0SdT34EpjWpjLZeKHyL8bBBwkjDeg6e2dmpdF6EooIzDpLZo5/eQfK2w1 LeAA== 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:content-transfer-encoding :in-reply-to; bh=L56VCJacW1q2c0bHUonnqO3sZEHGpPYCKrI7PJZeV18=; b=NdxECLCJBxZDeyYM/tOPJp0+994t3RvMdLz/7FOgh9x+k7j4ItwRxJBUnDZfCMf7wA sgtFU9YRsIAkRwRfNowilkDIJr2Gq4Am3RSu2Wu96Fad78w8ny3GavieYXY62c9pIgJH YNntn9rBWGV/qAGzjnPjux9lxDXjQBod9Dpl547eeafS75D+coLnj0cyMxPgenPNhnKw vCM+hDnbPonWGCtNURUVSsG2edRS2MzhamLLBh/sdg+8h+O8mrABDfYAdc3NduWPHosc 4n4uvn6oTXXxQxBLsJefYzLKYLWyeYPCe8mWSHRN1zyAVguBEYXY8y6AKqbgxG+5IyJY 2MRw== X-Gm-Message-State: AOAM5300RiCnaMLQYvVCXSyX1Y2BNtyxPKFrgHoiOWhHGoyQbdXGk7N3 DiUWddgCoAGk8lDIs3xexIjLWg== X-Received: by 2002:a17:90a:e2ce:: with SMTP id fr14mr527792pjb.89.1606955660397; Wed, 02 Dec 2020 16:34:20 -0800 (PST) Received: from google.com ([2620:15c:f:10:1ea0:b8ff:fe73:50f5]) by smtp.gmail.com with ESMTPSA id e2sm83742pjv.10.2020.12.02.16.34.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2020 16:34:19 -0800 (PST) Date: Wed, 2 Dec 2020 16:34:12 -0800 From: Sean Christopherson To: Ashish Kalra Cc: pbonzini@redhat.com, tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, joro@8bytes.org, bp@suse.de, thomas.lendacky@amd.com, x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, srutherford@google.com, brijesh.singh@amd.com, dovmurik@linux.vnet.ibm.com, tobin@ibm.com, jejb@linux.ibm.com, frankeh@us.ibm.com, dgilbert@redhat.com Subject: Re: [PATCH v2 1/9] KVM: x86: Add AMD SEV specific Hypercall3 Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Dec 01, 2020, Ashish Kalra wrote: > From: Brijesh Singh > > 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. > > Add SEV specific hypercall3, it unconditionally uses VMMCALL. The hypercall > will be used by the SEV guest to notify encrypted pages to the hypervisor. What if we invert KVM_HYPERCALL and X86_FEATURE_VMMCALL to default to VMMCALL and opt into VMCALL? It's a synthetic feature flag either way, and I don't think there are any existing KVM hypercalls that happen before alternatives are patched, i.e. it'll be a nop for sane kernel builds. I'm also skeptical that a KVM specific hypercall is the right approach for the encryption behavior, but I'll take that up in the patches later in the series. > Cc: Thomas Gleixner > Cc: Ingo Molnar > Cc: "H. Peter Anvin" > Cc: Paolo Bonzini > Cc: "Radim Krčmář" > Cc: Joerg Roedel > Cc: Borislav Petkov > Cc: Tom Lendacky > Cc: x86@kernel.org > Cc: kvm@vger.kernel.org > Cc: linux-kernel@vger.kernel.org > Reviewed-by: Steve Rutherford > Reviewed-by: Venu Busireddy > Signed-off-by: Brijesh Singh > Signed-off-by: Ashish Kalra > --- > arch/x86/include/asm/kvm_para.h | 12 ++++++++++++ > 1 file changed, 12 insertions(+) > > diff --git a/arch/x86/include/asm/kvm_para.h b/arch/x86/include/asm/kvm_para.h > index 338119852512..bc1b11d057fc 100644 > --- a/arch/x86/include/asm/kvm_para.h > +++ b/arch/x86/include/asm/kvm_para.h > @@ -85,6 +85,18 @@ static inline long kvm_hypercall4(unsigned int nr, unsigned long p1, > return ret; > } > > +static inline long kvm_sev_hypercall3(unsigned int nr, unsigned long p1, > + unsigned long p2, unsigned long p3) > +{ > + long ret; > + > + asm volatile("vmmcall" > + : "=a"(ret) > + : "a"(nr), "b"(p1), "c"(p2), "d"(p3) > + : "memory"); > + return ret; > +} > + > #ifdef CONFIG_KVM_GUEST > bool kvm_para_available(void); > unsigned int kvm_arch_para_features(void); > -- > 2.17.1 >