Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1938551pxb; Sat, 2 Apr 2022 08:56:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzPJxuzrsFn8u0i94LA8O+h4qagJwKKjiRx9JpepzDnKrHvbOkJfuBw8Li6hX7muWfOFvSW X-Received: by 2002:a17:90b:38d2:b0:1c7:1326:ec98 with SMTP id nn18-20020a17090b38d200b001c71326ec98mr17425940pjb.18.1648914983847; Sat, 02 Apr 2022 08:56:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648914983; cv=none; d=google.com; s=arc-20160816; b=gCdGw0LK5MANgWECOKTtEPXUXArxgI2ybvo8dNt/gK/RjkUbAJMzDDkyK1g87MNVZL U7DoilrUIILfVp+4SKSRHZ4DqFEZXZxCLzQqrmeJxkv4Up5VgRZsqUXmZ0ViDYbT1TZx oWWrsUS7ROU6uH9dpUyh+WT6arvfiIvJL6wssIXzbiC7GxMJd66c/F+4XuhhpieSc3Vp ukIiew8wx3pBlxATBAVTXnJdXbpn4wJTb9P/ry83F3dqMeKNNeYxwKW6ojgGCtVS6zC5 OWU1Lkbs6Dbt0V9kx2YGD6RGYJJPXLfTWHjB/7h8nKqhfNWGv8sySnDvkd+2DbnRLia+ N8Ow== 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=pOFOAOjZHkVIM9Cf5IEXbes0u5Uh/OQeAWWXMddS0Bg=; b=MpRJaC6pS9H3mvqaIeTupt9fwWYGIDsAQCDe7StggYXCT6S706RZUhuEKIqyrBna0M EnuUd0MQGnKHUpbpGojfdEr7JVHACuAH+8viLrQTi4EvYaH3/3XWmIwi16ZknoqgMczZ 3Yt5GLH/3AXQ/VUVrjW3cBCpXBb/lnBEGkTITeIdIg/QJLKVU9O/QRqI7eZaKhzXYDOd Gf1Th5Ek0U0H9ahSjU5YLj9iOJQMyZuSTcaKtFTchyOb+23VS6tXlth2SITyGabYZ+L9 MvrjaF2HMQXRQzMKBL3i3C88XNwRIwSjA4bK3pCgsPFtOmCl145ANP7iPjuHgxAtAvFH pFMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=iOsOoSV9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z42-20020a056a001daa00b004fa3a8e008esi4736378pfw.325.2022.04.02.08.56.08; Sat, 02 Apr 2022 08:56:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=iOsOoSV9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S1351681AbiDAPoz (ORCPT + 99 others); Fri, 1 Apr 2022 11:44:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353857AbiDAPLI (ORCPT ); Fri, 1 Apr 2022 11:11:08 -0400 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CAFFA196089 for ; Fri, 1 Apr 2022 07:54:10 -0700 (PDT) Received: by mail-pl1-x630.google.com with SMTP id i11so2672120plr.1 for ; Fri, 01 Apr 2022 07:54:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=pOFOAOjZHkVIM9Cf5IEXbes0u5Uh/OQeAWWXMddS0Bg=; b=iOsOoSV9OQblL4p1l3OUbmwl/JF8l0v7RCPmXqxWk4Jw8wnbSyNT+BVb9QU8KK/O7S EAHlhqMl9mdfUxz90N4rt8NWEC9EeE2UHAdi47b9XQfmcMgIrx3Bb7PJA9qeWjjGolzJ wk/BjvuXiRgn6TX1CwSGlF36Phq+jBcYdv59dPSjbO0y+6Tg7dcLW6eCJqz7NgFqEzbr 7VNiOESgpDBZKYDQkvYlbXD3BoX2hMUvn7/xM0mYTHGhVQT0g5MMEMy97ZdwVwqkqCPX mxMT7CdHBr7N98iviXLuf1gKPvATXJmvPdKo5kt6EjN6u2zGY3eIHf+6RMKqPGNDAmiG uEeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=pOFOAOjZHkVIM9Cf5IEXbes0u5Uh/OQeAWWXMddS0Bg=; b=QyrhTscth8Xik5Zf4PMnl+9YJ02/IhX+BfjJmn1GhBhDZi+rf54yrCnl9b4XWFLxQ/ esFmPUfphhG1wXQA4MVDiTXatbB0E11WGxZYtye41gVzVBCOWM8LXBBfZjcMNMniYlDk hrLurzWWNPV4O2AgYEUypNvQpQ4TfCxYfP2TixYKJrIfnVrCihYJ32vwAokHJrBJZbC0 hKQw5AvWF2W0AHvfRxmhRcRL1uU0qs5mn1VckdN76ZJX6zh9049P3/t4txBGo5moe0tP yX9joV4ks8vzYOy7mfB1i44Wcg2z1cORhNp7a5tcrivqDXGinud1d0f7zOvGjfXCGDJ6 wrpA== X-Gm-Message-State: AOAM532QSTUpnee2RY4+JyLp7UUe/VZZidXA/nS9CV808Se/8LsdQ9He zi8SRg7e8PANaOQiS8LBMndpgw== X-Received: by 2002:a17:902:7c0d:b0:155:d507:3cf0 with SMTP id x13-20020a1709027c0d00b00155d5073cf0mr10344247pll.103.1648824849356; Fri, 01 Apr 2022 07:54:09 -0700 (PDT) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id u18-20020a056a00125200b004fb112ee9b7sm3012243pfi.75.2022.04.01.07.54.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Apr 2022 07:54:08 -0700 (PDT) Date: Fri, 1 Apr 2022 14:54:05 +0000 From: Sean Christopherson To: "Nikunj A. Dadhania" Cc: Peter Gonda , Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Brijesh Singh , Tom Lendacky , Bharata B Rao , "Maciej S . Szmigiero" , Mingwei Zhang , David Hildenbrand , kvm list , LKML Subject: Re: [PATCH RFC v1 0/9] KVM: SVM: Defer page pinning for SEV guests Message-ID: References: <20220308043857.13652-1-nikunj@amd.com> <5567f4ec-bbcf-4caf-16c1-3621b77a1779@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Apr 01, 2022, Nikunj A. Dadhania wrote: > > On 4/1/2022 12:30 AM, Sean Christopherson wrote: > > On Thu, Mar 31, 2022, Peter Gonda wrote: > >> On Wed, Mar 30, 2022 at 10:48 PM Nikunj A. Dadhania wrote: > >>> So with guest supporting KVM_FEATURE_HC_MAP_GPA_RANGE and host (KVM) supporting > >>> KVM_HC_MAP_GPA_RANGE hypercall, SEV/SEV-ES guest should communicate private/shared > >>> pages to the hypervisor, this information can be used to mark page shared/private. > >> > >> One concern here may be that the VMM doesn't know which guests have > >> KVM_FEATURE_HC_MAP_GPA_RANGE support and which don't. Only once the > >> guest boots does the guest tell KVM that it supports > >> KVM_FEATURE_HC_MAP_GPA_RANGE. If the guest doesn't we need to pin all > >> the memory before we run the guest to be safe to be safe. > > > > Yep, that's a big reason why I view purging the existing SEV memory management as > > a long term goal. The other being that userspace obviously needs to be updated to > > support UPM[*]. I suspect the only feasible way to enable this for SEV/SEV-ES > > would be to restrict it to new VM types that have a disclaimer regarding additional > > requirements. > > For SEV/SEV-ES could we base demand pinning on my first RFC[*]. No, because as David pointed out, elevating the refcount is not the same as actually pinning the page. Things like NUMA balancing will still try to migrate the page, and even go so far as to zap the PTE, before bailing due to the outstanding reference. In other words, not actually pinning makes the mm subsystem less efficient. Would it functionally work? Yes. Is it acceptable KVM behavior? No. > Those patches does not touch the core KVM flow. I don't mind touching core KVM code. If this goes forward, I actually strongly prefer having the x86 MMU code handle the pinning as opposed to burying it in SEV via kvm_x86_ops. The reason I don't think it's worth pursuing this approach is because (a) we know that the current SEV/SEV-ES memory management scheme is flawed and is a deadend, and (b) this is not so trivial as we (or at least I) originally thought/hoped it would be. In other words, it's not that I think demand pinning is a bad idea, nor do I think the issues are unsolvable, it's that I think the cost of getting a workable solution, e.g. code churn, ongoing maintenance, reviewer time, etc..., far outweighs the benefits. > Moreover, it does not expect any guest/firmware changes. > > [*] https://lore.kernel.org/kvm/20220118110621.62462-1-nikunj@amd.com/