Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp2684885pxu; Mon, 7 Dec 2020 12:46:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJymm112tpdyYnNDgb7iUFfEk74vWy5Dnyx20ZElL1W0zyi8s/iV2ZCgOrYaxAqFO4dey1Do X-Received: by 2002:a17:906:b0d8:: with SMTP id bk24mr20288553ejb.113.1607373997978; Mon, 07 Dec 2020 12:46:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607373997; cv=none; d=google.com; s=arc-20160816; b=VqGy3tOIWbY0jiGPQ2KDRt1AqUy7JF/Q+v5d3JVXOWBnrE3cOqfrNF/OAzWIPTAODC VqhYTcMrQmcC0nMcwdDFTlFDp+5NFa1dJ3yy/+YRveh4be7w+mqsAxuNqlJznfEgI3qZ oIiNNji+5DPgDr0O/nkDLHJqeETBFJ7ebA4ZvJ7HE2sijJMrOpC4hxvOfJ9JwTmmgkr+ ks2PJIQGie3ga3Br7VniJKq0iSkYJ+mxbT4BJAHs3O9vOzznsYfUVqO5xzOqwN5g4O7R soPxHFAInZxNfkOQvTvjsaDEkOF1EvAm8r9jb4uzJs41l4vbPFsMAMg4+7RjZzaIUH39 Fv+A== 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=CH8YCzhb8HI7GBPHk9uPWdpCDz/yeRpmZct4IBChnGg=; b=1EvZC7gpcO1IwhZ0x2e4aWwr1FZDBlskTfjZ8JDtJHWClpE3wYWHhXJT1L/mZIdsLJ Z+RmRQDrksz1NQJRJePT8pCYms+pbZaWwCIgI+XT97qzD39U4yAM/wWF+0kztqxySJIU LoCyTaIqHpsr1kouL176TD9YJrqXom/+zJBHvqbS5xvJWXq5xjNKbQcwZmyC7qtlUKKJ LKaDajh1nqPfS3WSS6jVKhpU0GCYz13aQ+KqiZ2OLuWF3TOrKKVgwcYVF8jih6PR0axw xeS96Wc9GS3UmuQ9FC20cHdj/P+3j7UJKmti7RQXkK9VAOaYJM92DbAdyZpVZGpmwOPN tDIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=INO5DAYm; 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 x8si6539944edl.539.2020.12.07.12.46.14; Mon, 07 Dec 2020 12:46:37 -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=INO5DAYm; 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 S1726614AbgLGUmq (ORCPT + 99 others); Mon, 7 Dec 2020 15:42:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726028AbgLGUmq (ORCPT ); Mon, 7 Dec 2020 15:42:46 -0500 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 00788C061793 for ; Mon, 7 Dec 2020 12:42:05 -0800 (PST) Received: by mail-pf1-x444.google.com with SMTP id c12so4263697pfo.10 for ; Mon, 07 Dec 2020 12:42:05 -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:in-reply-to; bh=CH8YCzhb8HI7GBPHk9uPWdpCDz/yeRpmZct4IBChnGg=; b=INO5DAYmf8kU6q7ciFzTXnbrg8EDg6/9S1FUKBhoWy1nhBNtbNIzi460u9jYxCVXrS Y13KL66BKD//SCrnvGOE65/CnrI7nyehabbSB4V9frlRqlK7v8Pqe/Rr2CkTUr/iUbPN HLj15A9VGpPv3UiG8B3tIOvTdf2GyuEbcfu3GND7Ooaag/rLr4fboKCs9kVP1V1nvhv+ 9LlGNncJnfi0tuZo6ZAmv9is5VXRVjlSKQjKPBkoC5obeYR8zQjDmpT0UC5kCZLXComY NT7UjeSi1IW0sVdgegcvnHQZ+2XRZPol4tCwS8QDakqqxcgbHFd+GbCza6b7VOA69mZH oSLQ== 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=CH8YCzhb8HI7GBPHk9uPWdpCDz/yeRpmZct4IBChnGg=; b=N5VNgtPR7+nbGZUbEkebrXGFqysCeOjZLx/U62sFedNtq2/Ib9LYkGvoeIWmz2N1GZ sGbvWtcwKLkJ39f1QzbIDtQLsj09s8JKWir4GbAzI7Y8aTyoblAYmFs4jVJ+rZhxref7 g71vkn5yeY8aR/xomVfLKfUpuChO5ORiNrr0zsVm9F1r0l3dmUd84xhEEOAvxTRzdqg7 rD/ocVb5zD3nLSobVOgxVUppUkwqax05a6v5OTjAhBZ5ebOH8611ENUReUaW0gF7ybCB 9JnbaAOiOYgoSJfRMR619XiEej6tGieMxe0zq8dPxaCif7xUzi7CUCgWyFYdx+Q9ETo9 iVug== X-Gm-Message-State: AOAM532iV3XwIHOZ/XK7uwU4dh+SWGai2VxnoAvtrtaJfJ7JqxA01MMN mMzvVDuVlroUocYNGeWI51j26w== X-Received: by 2002:a17:90a:193:: with SMTP id 19mr187238pjc.45.1607373725342; Mon, 07 Dec 2020 12:42:05 -0800 (PST) Received: from google.com ([2620:15c:f:10:1ea0:b8ff:fe73:50f5]) by smtp.gmail.com with ESMTPSA id x18sm3663814pfr.158.2020.12.07.12.42.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Dec 2020 12:42:04 -0800 (PST) Date: Mon, 7 Dec 2020 12:41:58 -0800 From: Sean Christopherson To: Paolo Bonzini Cc: Ashish Kalra , 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=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Dec 06, 2020, Paolo Bonzini wrote: > On 03/12/20 01:34, Sean Christopherson wrote: > > 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. > > Do you think that it's the guest that should "donate" memory for the bitmap > instead? No. Two things I'd like to explore: 1. Making the hypercall to announce/request private vs. shared common across hypervisors (KVM, Hyper-V, VMware, etc...) and technologies (SEV-* and TDX). I'm concerned that we'll end up with multiple hypercalls that do more or less the same thing, e.g. KVM+SEV, Hyper-V+SEV, TDX, etc... Maybe it's a pipe dream, but I'd like to at least explore options before shoving in KVM- only hypercalls. 2. Tracking shared memory via a list of ranges instead of a using bitmap to track all of guest memory. For most use cases, the vast majority of guest memory will be private, most ranges will be 2mb+, and conversions between private and shared will be uncommon events, i.e. the overhead to walk and split/merge list entries is hopefully not a big concern. I suspect a list would consume far less memory, hopefully without impacting performance.