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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ED239C43334 for ; Wed, 8 Jun 2022 19:37:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235416AbiFHThe (ORCPT ); Wed, 8 Jun 2022 15:37:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234781AbiFHTha (ORCPT ); Wed, 8 Jun 2022 15:37:30 -0400 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 887C42347D7 for ; Wed, 8 Jun 2022 12:37:29 -0700 (PDT) Received: by mail-pj1-x1034.google.com with SMTP id a10so19510477pju.3 for ; Wed, 08 Jun 2022 12:37:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=wh6/XuxZPZUDwyzy5Eh7VeXfArKnNs6YeEjpbWE+j5g=; b=ZAG/K6D48l0KrmmRn1p2FTmiQngI/15yOkQ8MG3uOIp2K2v36XwQ2z8ZERlay6GUnj f6Sg6s8FFS/vw4GmKlcbDU92NrHn2K9bSARE4ICPUYhAVS3ymvr75ETolLgVKsl3A513 oscCyM1WP/DK5242tikPCpr2E/rKOv00sX5olq99qElwq471NkYsjKcAWArALuZx2UmC CgiqYG3dwPpKqe4lLXhreFySMsEDe8d4kPNvglQIKziVC1KrNkNXJk21EPdQMbqcRvJ6 v8IdnFTEPtFo6VDq8R+YkUgfipwAH1spS4CjC2hG/IiGlAv6nPBHFnuhil0CZaWyp+5b sSXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=wh6/XuxZPZUDwyzy5Eh7VeXfArKnNs6YeEjpbWE+j5g=; b=La2RapDYWyF4E4M0K2oe70XzdwQdfpB50PfF8dGKfdK6Op31WRfjWxz9NspHApSzyF ajqF4AkmgIDNSgqrNR6Ifvexdz9nvNeuSmeuX7UhzWVOTiSsAmP97r43BGCmlT1yXZDS lUpQeDRBPCuU+jE2eRod1g0iqaqnSpdqc88xKXWRMghVWfEG+PPC0TKB5Sh1Rta6H1Hp q6lGYdxsHTmA9f0pdIpnv3spHRhzeISfVans+zxsHDfEn7XPI8845tdbzKG2+tVZ+3Ji /JdztSUy0FQwfA2B8aYVhIeQ1pDsCuWwkjSxsBXF32E1aes3ZLnvCHBKL+y19d3y0SND 7eCQ== X-Gm-Message-State: AOAM530wtaR5hCbq8he+gjQ2/uucK1bneZwuh3DsrvU1yyogW+XI8wQo +4IyhrTyNtpZ1mw1IqD/pczLm5IXMCBPYayjSIOxqQ== X-Google-Smtp-Source: ABdhPJyfhv1kDe3gJcgewOBnTs26+Uc6YFkqzaIMBY+Sas+MZKd5jC6EwNSmICRKaXBZxv4CUZaYAZlNhfXBPpTEGHU= X-Received: by 2002:a17:902:f710:b0:15f:165f:b50b with SMTP id h16-20020a170902f71000b0015f165fb50bmr36739481plo.158.1654717048302; Wed, 08 Jun 2022 12:37:28 -0700 (PDT) MIME-Version: 1.0 References: <20220519153713.819591-1-chao.p.peng@linux.intel.com> <20220607065749.GA1513445@chaop.bj.intel.com> <20220608021820.GA1548172@chaop.bj.intel.com> In-Reply-To: <20220608021820.GA1548172@chaop.bj.intel.com> From: Vishal Annapurve Date: Wed, 8 Jun 2022 12:37:17 -0700 Message-ID: Subject: Re: [PATCH v6 0/8] KVM: mm: fd-based approach for supporting KVM guest private memory To: Chao Peng Cc: Marc Orr , kvm list , LKML , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, linux-doc@vger.kernel.org, qemu-devel@nongnu.org, Paolo Bonzini , Jonathan Corbet , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86 , "H . Peter Anvin" , Hugh Dickins , Jeff Layton , "J . Bruce Fields" , Andrew Morton , Mike Rapoport , Steven Price , "Maciej S . Szmigiero" , Vlastimil Babka , Yu Zhang , "Kirill A . Shutemov" , Andy Lutomirski , Jun Nakajima , Dave Hansen , Andi Kleen , David Hildenbrand , aarcange@redhat.com, ddutile@redhat.com, dhildenb@redhat.com, Quentin Perret , Michael Roth , mhocko@suse.com Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ... > With this patch series, it's actually even not possible for userspace VMM > to allocate private page by a direct write, it's basically unmapped from > there. If it really wants to, it should so something special, by intention, > that's basically the conversion, which we should allow. > A VM can pass GPA backed by private pages to userspace VMM and when Userspace VMM accesses the backing hva there will be pages allocated to back the shared fd causing 2 sets of pages backing the same guest memory range. > Thanks for bringing this up. But in my mind I still think userspace VMM > can do and it's its responsibility to guarantee that, if that is hard > required. By design, userspace VMM is the decision-maker for page > conversion and has all the necessary information to know which page is > shared/private. It also has the necessary knobs to allocate/free the > physical pages for guest memory. Definitely, we should make userspace > VMM more robust. Making Userspace VMM more robust to avoid double allocation can get complex, it will have to keep track of all in-use (by Userspace VMM) shared fd memory to disallow conversion from shared to private and will have to ensure that all guest supplied addresses belong to shared GPA ranges. A coarser but simpler alternative could be to always allow shared to private conversion with unbacking the memory from shared fd and exit if the VMM runs in double allocation scenarios. In either cases, unbacking shared fd memory ideally should prevent memory allocation on subsequent write accesses to ensure double allocation scenarios are caught early. Regards, Vishal