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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 004D3C43334 for ; Tue, 14 Jun 2022 19:09:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 68FA16B0071; Tue, 14 Jun 2022 15:09:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6410C6B0072; Tue, 14 Jun 2022 15:09:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4B91D6B0073; Tue, 14 Jun 2022 15:09:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 390486B0071 for ; Tue, 14 Jun 2022 15:09:01 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id 089FD120D07 for ; Tue, 14 Jun 2022 19:09:01 +0000 (UTC) X-FDA: 79577778882.18.C5E3B7D Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) by imf17.hostedemail.com (Postfix) with ESMTP id 9A5D2400A9 for ; Tue, 14 Jun 2022 19:09:00 +0000 (UTC) Received: by mail-pg1-f170.google.com with SMTP id z14so5197814pgh.0 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=a4qovBunLEpr/2taSYRqCjRqMrdfexa/7Dr7Lf1QBtKxo716w/kAgkj+Q9EQaw+Q5x buhThFMzFQNDQOTHg2jlnT9mf4MQuMuFHOIklDMqIRNHIDPmpD9t7dcuAwcKa8OpaErH 1boLubIUvg34Bv8o2NHNqZuZTj6thhO1XooTnjXd/ii9c1uSpaTrragglzZXP5eSe+nj palHbqdFiPIn+oVfFUedhcITycBKSgAdUxSkngKzrGnkS5SDtdy49s7yh6W+/WFfLjZX HWe0A5FCWUUKoUs55EwcR7N7TCp096Py9h0twYpzPh+L2uO2F1+Huz3YEb0zx4YUCxr7 /o9Q== X-Gm-Message-State: AOAM532Li9elgfoMf6wD6elSo42tlo0UWh5krxPg8fgwff7q6Oeibrrf kDTvLQaFC+SJbyc5LVaqh6XydQ== X-Google-Smtp-Source: ABdhPJzHn2Ye3YjC05M4BzToAcQNR5uLK5arwJemtulnC/fJwq6gRuGbN+I9cWXJrKe2+YDZm5QL5w== 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: ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655233740; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=WxVFX8SQoTkO2asaGhNARNyU0t4WV/p9VWUwvDYpcsM=; b=lzh5uqtlF834ESt4jUsPCy/+3UH1lw+CK1Gm6oCcktUk31kcGkto22vjZ8jidWhvHbsedl btLRiCl93MQLp6XSgBrVvuyDpjNMIJBQgaqmUYshWDTHYO3HCYfgmzWm85abbu6yNFra1K CXwztMqaISj9vzlcLwdvPSAmS7tVdyY= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=Xh80bV+F; spf=pass (imf17.hostedemail.com: domain of seanjc@google.com designates 209.85.215.170 as permitted sender) smtp.mailfrom=seanjc@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655233740; a=rsa-sha256; cv=none; b=6IdMJ+CgEbX843Rj12qC6wFC9rBKL8qcVufjzTMG43BW2q/eYmYpJVwCiWQzrZ1+sfir74 VDMCoeJX+4HDA3gYUWvmRoW6/316nTjIYsfwoHwIDduVfhIvWYVLC6ITeU2L9QrXMhdw3+ kIPZc4A+V87h8+YdgUAFtpo4hBE5tlY= X-Stat-Signature: a6ani6yb1heuj98r9kasrcwibsefihi4 X-Rspamd-Queue-Id: 9A5D2400A9 X-Rspamd-Server: rspam11 X-Rspam-User: Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=Xh80bV+F; spf=pass (imf17.hostedemail.com: domain of seanjc@google.com designates 209.85.215.170 as permitted sender) smtp.mailfrom=seanjc@google.com; dmarc=pass (policy=reject) header.from=google.com X-HE-Tag: 1655233740-807772 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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().