Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp1682486iog; Tue, 14 Jun 2022 10:49:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyYJatSfxJpocmRCbWgPU9wiDGRYCNaDH5zP6Tmyn5pNNypGsZLnyeDQ4dbykKdsWfzhvo5 X-Received: by 2002:aa7:d8d8:0:b0:42d:dbb0:f05b with SMTP id k24-20020aa7d8d8000000b0042ddbb0f05bmr7479044eds.82.1655228989592; Tue, 14 Jun 2022 10:49:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655228989; cv=none; d=google.com; s=arc-20160816; b=bmvss9EuYSa33cR5+tZjtQ7jjb7+nMJub0L/CyXfrkFyXcA5HPyh70+ORRJczBcWie EHA+xaHZNyiLuVJ0fx4s258O4Q8ofa1ARO9eMwUAJfCg+YaC8XORD7yovXYNMlBCmNFy ghIciLUTE96gSKf+hW1kV3TZqhUvmWeXnUo/byAEGamYsUnHfvVNGBkXUuxf8aa3VyRq rTqL8kSkn+cXx2O/QF+fks7Pn4PGwrX0i5orRdi91XiijDbpaQXpABWmv0uxTWJNYX/m DLyNzS3Mzj0T0RZCxzUJf6ka+zO2greVqJdIu2WK6CkysWtvHeLRdKQMTcNgi4Xr3jV3 mKrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=Cxlpi8yJJCnc9DoeD2bqdX9dANX2MxpUNUH29AFWqLk=; b=XwMfCDa7iV0nsOAnSxufqWWSEiQyNZi2Vy0Dl7gfz67/QzJv2LBoHfyzjT2kIee0xv T6wHyHs4TJ0bmb9Est3bN2HIIHpGup0knBKzK23dTHp689hvBtuwU5zaBwOtMScAyxWT oaWdUYPRkUT2IZEu9RJc8wjgFlaJasbCK3XLVLDyjd1xPVKogSJDCagH771epusyRBco K8c6EXzns6D40J2L4pi8saQbHZKKnJrwREKAEdEM/d2sZXTRK/bhimAfi1gcHwwsAXeb /XD54/AS4PZ+EcfkTyICrZwsSX0JUnkzF7d40iwaLkGMa9Vu/0LlHI6UDgc72m27MPoU If6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rVsqTEMC; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v7-20020a056402348700b004262cf3f74asi13322298edc.599.2022.06.14.10.49.23; Tue, 14 Jun 2022 10:49:49 -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=@kernel.org header.s=k20201202 header.b=rVsqTEMC; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343909AbiFNRh6 (ORCPT + 99 others); Tue, 14 Jun 2022 13:37:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241459AbiFNRhx (ORCPT ); Tue, 14 Jun 2022 13:37:53 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83DBBC6A for ; Tue, 14 Jun 2022 10:37:52 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 003696173F for ; Tue, 14 Jun 2022 17:37:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 59EEBC36AFF for ; Tue, 14 Jun 2022 17:37:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1655228271; bh=IfvLnQR788L8QWGOY03Cidk5AO0MFCOejaXVfQOMPCw=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=rVsqTEMCOYtQg0EhaeIyrGXi4SPR+xCja/Zzrm4/rXKs2rHudfxst4/iDfEc7IQHK 231UQkTDY6d6nmdAlt1kRM+zRgLLBDu035jXo5xVowLng3mEh3oiXDy8mQR20Hacmd LnzQlaeG3xrE2iaFi/ZdceqCE70b9VENcDWjU+WHKEa2HJsyqUZj0vCI94Pk49Z42u h/RWzCu6j4a9w8yEsj7rK5e9uiDjc2EiFUc+avH0qZI0dyuzeA/z91zXgiRd7yeSl3 8mOVqXBg2pv8zvUY79qtaym4zlYLKvBcSVb7us+LoO+lJ2erExWSiAMs/ARQBPGhP9 Q8CDnPjgM2DNQ== Received: by mail-ej1-f42.google.com with SMTP id y19so18573839ejq.6 for ; Tue, 14 Jun 2022 10:37:51 -0700 (PDT) X-Gm-Message-State: AOAM5315qJkwrzO/p7dfciH8GW0XlovCBm+oYRjIKwnV6+Us0whkNp3n Hb//RJhO33vPeZ9o9q7ojPWKYv0BT/Wj26/lb1O7nQ== X-Received: by 2002:a17:906:2298:b0:715:7f3d:32ec with SMTP id p24-20020a170906229800b007157f3d32ecmr5255068eja.538.1655228269361; Tue, 14 Jun 2022 10:37:49 -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> <20220614072800.GB1783435@chaop.bj.intel.com> In-Reply-To: <20220614072800.GB1783435@chaop.bj.intel.com> From: Andy Lutomirski Date: Tue, 14 Jun 2022 10:37:37 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v6 0/8] KVM: mm: fd-based approach for supporting KVM guest private memory To: Chao Peng Cc: Sean Christopherson , Vishal Annapurve , 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 , 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" X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 Tue, Jun 14, 2022 at 12:32 AM Chao Peng wrote: > > On Thu, Jun 09, 2022 at 08:29:06PM +0000, Sean Christopherson wrote: > > On Wed, Jun 08, 2022, Vishal Annapurve wrote: > > > > One argument is that userspace can simply rely on cgroups to detect misbehaving > > guests, but (a) those types of OOMs will be a nightmare to debug and (b) an OOM > > kill from the host is typically considered a _host_ issue and will be treated as > > a missed SLO. > > > > An idea for handling this in the kernel without too much complexity would be to > > add F_SEAL_FAULT_ALLOCATIONS (terrible name) that would prevent page faults from > > allocating pages, i.e. holes can only be filled by an explicit fallocate(). Minor > > faults, e.g. due to NUMA balancing stupidity, and major faults due to swap would > > still work, but writes to previously unreserved/unallocated memory would get a > > SIGSEGV on something it has mapped. That would allow the userspace VMM to prevent > > unintentional allocations without having to coordinate unmapping/remapping across > > multiple processes. > > Since this is mainly for shared memory and the motivation is catching > misbehaved access, can we use mprotect(PROT_NONE) for this? We can mark > those range backed by private fd as PROT_NONE during the conversion so > subsequence misbehaved accesses will be blocked instead of causing double > allocation silently. This patch series is fairly close to implementing a rather more efficient solution. I'm not familiar enough with hypervisor userspace to really know if this would work, but: What if shared guest memory could also be file-backed, either in the same fd or with a second fd covering the shared portion of a memslot? This would allow changes to the backing store (punching holes, etc) to be some without mmap_lock or host-userspace TLB flushes? Depending on what the guest is doing with its shared memory, userspace might need the memory mapped or it might not. --Andy