Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp1743763iog; Tue, 14 Jun 2022 12:16:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwNNfSVMQH7YeNwLJNEMtoGAds9QmFF1UVtv8Tu3GZO96gmJMZj/7/lW33ELptxdmE2Oj1l X-Received: by 2002:a65:5786:0:b0:3fd:7145:ceef with SMTP id b6-20020a655786000000b003fd7145ceefmr5654188pgr.361.1655234213088; Tue, 14 Jun 2022 12:16:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655234213; cv=none; d=google.com; s=arc-20160816; b=I98TxFM/m1zoIC1n7hvwiPeaPYm18YGfRGmLusTdsmyrjl75lFfXLURs/rNpaX2iFI XSLHVQGCSF/W2ZLz42GkUmcYExSSAV0AEYDOVDDOqW/hs1uai+l/5XFLBURM8ooZo/2p 0DAh997JnXBY75p3cl0AUE0q/nwnKcoB2stDQyGCG1IgyGK8t0btJYNIOmsIjCQLAwFl E2xa6VpGr3PBCubUXKdSQjg+o00I1v5hY4SLpzQxw1x9zLElxkqsEVRIIxI6CqtpIYda Tn9CK5P97JtS2GXuiD6MNvrpAIY+fgZJBjbe2rdM1q8H4Zg+P1axJ8jgXjA8kPc6wmuZ lTBw== 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=WxVFX8SQoTkO2asaGhNARNyU0t4WV/p9VWUwvDYpcsM=; b=rq6DKWZNQf6TKwiE3aAMLSJnDNj0REG+G3fMs+nvCzXmlGJQCltSvbavFliNCg0bp/ eWGUbuxM4pihY2u2nXkQcarAPG7u1ifCHPw6ivel7m4VhetxqeWKW/o7gInExu9KBaI3 4hCgQJuGlmPuTpXqHQPI2wgOLwm4MWjbCayLdaoCHFa5DOvmJGFnPDdmxwc4B4VXdbGD AhmLTQcNE7/+Voen+4IZpZgRBISA7lBzGkwz/lfSH38Dr+8DbEpt3LA2PGtQcmFHUAz4 iGabrRe8QeL79XsPc3EWLi+0u1UjguAf9MMUdVRZPIwgN+pRrmWWtUsF3CjsaSx1Tvad 9NOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Xh80bV+F; 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 t184-20020a6381c1000000b00408c3d94e4csi23568pgd.691.2022.06.14.12.16.38; Tue, 14 Jun 2022 12:16:53 -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=Xh80bV+F; 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 S235010AbiFNTJV (ORCPT + 99 others); Tue, 14 Jun 2022 15:09:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345245AbiFNTJB (ORCPT ); Tue, 14 Jun 2022 15:09:01 -0400 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2677F1E3E8 for ; Tue, 14 Jun 2022 12:09:00 -0700 (PDT) Received: by mail-pf1-x42d.google.com with SMTP id e11so9390191pfj.5 for ; Tue, 14 Jun 2022 12:09:00 -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=WxVFX8SQoTkO2asaGhNARNyU0t4WV/p9VWUwvDYpcsM=; b=Xh80bV+FmkQM9epsA7aMCOshN8wzgXzzNfcH1Mc5l2PMPe+NVyrmidG+ZAIomvJRtU RwgYBZBLNjvMpgnLGqwffyVKFtkt95EvQJE7V+yhNJd4WI+Y0tU/+mvZfD/c+ZQ5IwjW awNyTzTiwwpe/fFELOsgLdQ+96PwyMOQ36VM5zE678kFN78bKFVWurGuCW2jPter6rTJ UnK3MeTmvxnDOMbC1zWiS64QnXHMoJpqeZXS0bwZBWQpiEshgMr7JbhokFHwuNAu5XM4 XGvYYWMpjtxj1AxQuoVI4g6+R6kOiDBnYQeRcjBoiYkH2ZASJ7TlFQcVFSnBSo6YMR1V KAAA== 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=WxVFX8SQoTkO2asaGhNARNyU0t4WV/p9VWUwvDYpcsM=; b=kBQEylu35YW96q7cuzW8XjSdC2AkqU8jxACkr2FfKImWbZ3SZGoic2Sjwe0hd0s2pE xLGOTsGiTbY02pwlXwUaZGfBBqR0D4smMc4aV96oUJ1u1R7toPTcIOFbdxCIO48GjmpO SeOk+UVhfuY6c/JRoKLYjHtFHA1r3oikG/l06vL0s8PWGuc5RsTmen9LTuwUkaOf3vko K0xpDzk2lep/KW+qDmwwZqRuRqKnGkYC+zc7DXEnhFzGaxBu5l555KUNVZw5T05ltL0s utw5fwSNECmgmEnHg+tmQQleJoSA/Gt6TCeP+ByFqTzkYA6Oj7AhVqDTaSE9C7e22Fon cbzw== X-Gm-Message-State: AOAM530m9UAYLsssj9vjyYmVtvsYBQzS9zVH8BzWkH1t8UAUOdVGydl3 SVOvFXXYHQX1udJoWNO5EZBjnw== X-Received: by 2002:a05:6a00:1744:b0:51b:d4d5:f34 with SMTP id j4-20020a056a00174400b0051bd4d50f34mr6274754pfc.0.1655233739275; Tue, 14 Jun 2022 12:08:59 -0700 (PDT) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id s8-20020a170902a50800b00161ac982b9esm7590467plq.185.2022.06.14.12.08.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jun 2022 12:08:58 -0700 (PDT) Date: Tue, 14 Jun 2022 19:08:55 +0000 From: Sean Christopherson To: Andy Lutomirski Cc: Chao Peng , 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" , Jun Nakajima , Dave Hansen , Andi Kleen , David Hildenbrand , aarcange@redhat.com, ddutile@redhat.com, dhildenb@redhat.com, Quentin Perret , Michael Roth , mhocko@suse.com Subject: Re: [PATCH v6 0/8] KVM: mm: fd-based approach for supporting KVM guest private memory Message-ID: 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> 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 Tue, Jun 14, 2022, Andy Lutomirski wrote: > 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. PROT_NONE, a.k.a. mprotect(), has the same vma downsides as munmap(). > 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. That's what I'm angling for with the F_SEAL_FAULT_ALLOCATIONS idea. The issue, unless I'm misreading code, is that punching a hole in the shared memory backing store doesn't prevent reallocating that hole on fault, i.e. a helper process that keeps a valid mapping of guest shared memory can silently fill the hole. What we're hoping to achieve is a way to prevent allocating memory without a very explicit action from userspace, e.g. fallocate().