From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FSL_HELO_FAKE, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D8B8BC433FE for ; Mon, 7 Dec 2020 20:42:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8AD57238A0 for ; Mon, 7 Dec 2020 20:42:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726766AbgLGUmq (ORCPT ); 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-Google-Smtp-Source: ABdhPJxKnvYSQUDE2dtTbW4EIlJgai5ChGkpNkdcQ1jvxCZKFuMEspMLKN57sXKhzppEB0rLjEUYug== 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.