Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp8127080rwn; Wed, 14 Sep 2022 09:17:38 -0700 (PDT) X-Google-Smtp-Source: AA6agR7xlqiKzFyAIQ8Mk3p7Ji82DqsCjgyiSPyfPeBCqY4aIdt5Go79M8CNpe5gAouL12auYOml X-Received: by 2002:a17:907:b10:b0:76f:e74f:4f4c with SMTP id h16-20020a1709070b1000b0076fe74f4f4cmr26304683ejl.132.1663172257899; Wed, 14 Sep 2022 09:17:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663172257; cv=none; d=google.com; s=arc-20160816; b=TKx0++oUVESgenz7RpZfr3I2SYLt8CRAOKoUGwPDpVYE6lgyPra1XPOFfiSWVcCEcN LHJw1Kd+jGU1ogN6FHOHxQTu65mw4aNK70lQjRsKMvqiSPT45GZEy6IU/CfPZFF2dZlk bjYALBChhlP0NTdjXReybGe4dZrXnI579axfa4LzvQpRKOxZZ753WOh648nEXjgaq2Y7 AN6p9vdEu7B5sK2WbAHkwXmw2d/6NWM1lvDXTuU+6Izp0ZCVs/BlPWp2zAeoa/EP+Xa5 hU1QYa+fnfC8XiymKBCOsG54RXV0yBJkzDvI3NhsqFPPf+Uavea30AFcqRN3lMcfrZ4K toDQ== 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=8A1QBrYdNqwfKSHedR+VNWdvV9LDIo8DjOKUwjNPjrY=; b=zs6KzZxRLUyW75krYfjgr3Rj5zsYquIvNzf0FCllrV958mHq14FDvk3KA3A7o8xmWC SvqjbM5ynj2DiEyzcyKuJsOkwpCVBwf7QG8IJAEzW3z5lkWRewos/2IAXulzTwLZ47f4 ovVWvFjLXJ26AzkyWBo2rx0UHQZuNKLe7K4Ay4WbKPPSdF+NpmpdTB/MP/rD0lFarz7L uhYDV6Y27qA0+n/Ihcx+H86ljRJ8VJ4ePiBplgxPrP31CjVFdb23oANBZu2lnXmzx6ZP PnkjW4duA2XoTHkpwGdMnm6MJvWDueDmx63AVjhR/3Rqrj75fZGkzdQ0Vkx+ZmUqDpq6 2qeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=mvQUfDz6; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-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 h14-20020a170906584e00b007306645a7absi10765960ejs.849.2022.09.14.09.17.02; Wed, 14 Sep 2022 09:17:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-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=mvQUfDz6; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-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 S229804AbiINQPg (ORCPT + 99 others); Wed, 14 Sep 2022 12:15:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229815AbiINQPe (ORCPT ); Wed, 14 Sep 2022 12:15:34 -0400 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A364F73320 for ; Wed, 14 Sep 2022 09:15:33 -0700 (PDT) Received: by mail-pj1-x1033.google.com with SMTP id fs14so15056171pjb.5 for ; Wed, 14 Sep 2022 09:15:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date; bh=8A1QBrYdNqwfKSHedR+VNWdvV9LDIo8DjOKUwjNPjrY=; b=mvQUfDz6ojr7ZAMyHwdFbIr04Tib8sObkLdz585rF4NjcanR41FcX6tQ1gqbYu4Ttl Fu0XNYqOA8b4p4ooruVgUBMH4SpJKWDKtJPt3NmQ5qog6dHoc6uVRsUrx/4AJhyTV8BP hwwv0WhgV9E9N1JqLQqd/gOzzw/SfL68NBvgFd2yeSjoSquzbymUv9jmX+bDZCpbrcqE IWV85+8F1DZwNxLu7gvOFZS12gaZb6YWoH30BucapjCD5UHnBfWByH/12R4gijybVh8Z 6rzxzDR1nASgbMYDhAOKQnFfdGeCOT2I1IGFSdLfRmwD7NpQfKB6kdhW0x/vCA2l/emH spRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date; bh=8A1QBrYdNqwfKSHedR+VNWdvV9LDIo8DjOKUwjNPjrY=; b=GpMSexLRnPlEZWseqFqWNMkGnaeCSx1EplqsHsVfdNSxrM95X6tzyyLwrvrP6Q4ZRW D9lpS885JH2KujsjPH+JjjbSxkF6WtLogONhBY+2VoPwptWF2zyZnKeNxVEafQ7wKjyV 7M4kvMgwRovs/9VMXxzf6ttzmM4FZmHwYGNp8drm8rRzg9AhXFv+LtOJ0DDXWSNMR6h1 qthAAC9lT2nHYGK99Wh10B6y701UCdkAwHl/ddukAj2z7m26RtPgE3JTQIznWpTe4j2P hoRWZDwsg5GDtj40D1duEhk0ThcE3FHCjKzYgB1R2dLA/7fQfxsc0Igbuk2OMm63fFjy 6RFw== X-Gm-Message-State: ACrzQf2yfzaHaFpPeUF3UoZQZva1BX86dwLDr9Jza44zm4O40LVt96JM OTuJWzR2BRY+mhhSv8MaSFRrFg== X-Received: by 2002:a17:90b:1e0d:b0:202:91ec:e167 with SMTP id pg13-20020a17090b1e0d00b0020291ece167mr5542131pjb.174.1663172132830; Wed, 14 Sep 2022 09:15:32 -0700 (PDT) Received: from google.com (7.104.168.34.bc.googleusercontent.com. [34.168.104.7]) by smtp.gmail.com with ESMTPSA id m3-20020a638c03000000b0042bd73400b6sm9925334pgd.87.2022.09.14.09.15.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Sep 2022 09:15:32 -0700 (PDT) Date: Wed, 14 Sep 2022 16:15:28 +0000 From: Sean Christopherson To: Marc Orr Cc: Michael Roth , Brijesh Singh , x86 , LKML , kvm list , linux-coco@lists.linux.dev, Linux Memory Management List , Linux Crypto Mailing List , Thomas Gleixner , Ingo Molnar , Joerg Roedel , Tom Lendacky , "H. Peter Anvin" , Ard Biesheuvel , Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Andy Lutomirski , Dave Hansen , Sergio Lopez , Peter Gonda , Peter Zijlstra , Srinivas Pandruvada , David Rientjes , Dov Murik , Tobin Feldman-Fitzthum , Borislav Petkov , Vlastimil Babka , "Kirill A . Shutemov" , Andi Kleen , Tony Luck , Sathyanarayanan Kuppuswamy , jarkko@profian.com Subject: Re: [PATCH Part2 v5 39/45] KVM: SVM: Introduce ops for the post gfn map and unmap Message-ID: References: <20210820155918.7518-1-brijesh.singh@amd.com> <20210820155918.7518-40-brijesh.singh@amd.com> <4e41dcff-7c7b-cf36-434a-c7732e7e8ff2@amd.com> <20220908212114.sqne7awimfwfztq7@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-crypto@vger.kernel.org On Wed, Sep 14, 2022, Marc Orr wrote: > On Wed, Sep 14, 2022 at 9:05 AM Sean Christopherson wrote: > > > > On Thu, Sep 08, 2022, Michael Roth wrote: > > > On Fri, Oct 15, 2021 at 05:16:28PM +0000, Sean Christopherson wrote: > > > So in the context of this interim solution, we're trying to look for a > > > solution that's simple enough that it can be used reliably, without > > > introducing too much additional complexity into KVM. There is one > > > approach that seems to fit that bill, that Brijesh attempted in an > > > earlier version of this series (I'm not sure what exactly was the > > > catalyst to changing the approach, as I wasn't really in the loop at > > > the time, but AIUI there weren't any showstoppers there, but please > > > correct me if I'm missing anything): > > > > > > - if the host is writing to a page that it thinks is supposed to be > > > shared, and the guest switches it to private, we get an RMP fault > > > (actually, we will get a !PRESENT fault, since as of v5 we now > > > remove the mapping from the directmap as part of conversion) > > > - in the host #PF handler, if we see that the page is marked private > > > in the RMP table, simply switch it back to shared > > > - if this was a bug on the part of the host, then the guest will see > > > > As discussed off-list, attempting to fix up RMP violations in the host #PF handler > > is not a viable approach. There was also extensive discussion on-list a while back: > > > > https://lore.kernel.org/all/8a244d34-2b10-4cf8-894a-1bf12b59cf92@www.fastmail.com > > I mentioned this during Mike's talk at the micro-conference: For pages > mapped in by the kernel can we disallow them to be converted to > private? In theory, yes. Do we want to do something like this? No. kmap() does something vaguely similar for 32-bit PAE/PSE kernels, but that's a lot of complexity and overhead to take on. And this issue goes far beyond a kmap(); when the kernel gup()s a page, the kernel expects the pfn to be available, no exceptions (pun intended). > Note, userspace accesses are already handled by UPM. I'm confused by the UPM comment. Isn't the gist of this thread about the ability to merge SNP _without_ UPM? Or am I out in left field? > In pseudo-code, I'm thinking something like this: > > kmap_helper() { > // And all other interfaces where the kernel can map a GPA > // into the kernel page tables > mapped_into_kernel_mem_set[hpa] = true; > } > > kunmap_helper() { > // And all other interfaces where the kernel can unmap a GPA > // into the kernel page tables > mapped_into_kernel_mem_set[hpa] = false; > > // Except it's not this simple because we probably need ref counting > // for multiple mappings. Sigh. But you get the idea. A few issues off the top of my head: - It's not just refcounting, there would also likely need to be locking to guarantee sane behavior. - kmap() isn't allowed to fail and RMPUPDATE isn't strictly guaranteed to succeed, which is problematic if the kernel attempts to kmap() a page that's already private, especially for kmap_atomic(), which isn't allowed to sleep. - Not all kernel code is well behaved and bounces through kmap(); undoubtedly some of the 1200+ users of page_address() will be problematic. $ git grep page_address | wc -l 1267 - It's not sufficient for TDX. Merging something this complicated when we know we still need UPM would be irresponsible from a maintenance perspective. - KVM would need to support two separate APIs for SNP, which I very much don't want to do.