Received: by 2002:a05:6a10:144:0:0:0:0 with SMTP id 4csp1074396pxw; Sat, 9 Apr 2022 10:19:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwEf3VoKhD2K7xOwURhmrPSqna/E7Yu9YMczkVeudwfn5HcrO/okvL1u4i+PrfWWLgCF6hr X-Received: by 2002:a05:6402:10d5:b0:408:f881:f0f3 with SMTP id p21-20020a05640210d500b00408f881f0f3mr24831972edu.112.1649524765940; Sat, 09 Apr 2022 10:19:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649524765; cv=none; d=google.com; s=arc-20160816; b=hinjalHL1+rn0YZPR4oemUVxXEU1KTJBjNFX+AruRkYNCArH8Ki17Hu9pzIO86miIs ZURCzyRUIby8KXyk6wF9rqJdY8cHpfyluLTJ2YOu/rUxhPs1cYw7rwqqrcsXUWX7Tyzk 6xABgdRtehBX7cdsrRN1gy4Z5ULNf7sooW8LEKSgF+19m8NDnCiRLjEWceiRfMoiSXyl agbP7TaWapKNNkhYTQsUjd+lyhgtHJM6c7ZIRBjBUB1FP8P1DwYYvEvyZxC6Ws6jVL52 7BdFx/GJ9aJEJC2Zhbb9umJkGMhkp1hbTyuMgB9AFUq/wpLBJIL/2nEVeTwOUg/czDr4 izGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:subject :organization:from:references:cc:to:content-language:user-agent :mime-version:date:message-id:dkim-signature; bh=9uyU2VFoeBsyhZOJQIlctyu40TJSn7XsF2RPXyVl1do=; b=ag4nFLlgRBUbOXeH1+u+eXD9q1pSuUmiwGEhbvnKHxjx8YexoryOdnm8gE/NNY9ZE9 X5x4IYxOgchpf1e9gh7d+wRYlstayccJfpUBOfxen5oUyoXWXhyiryEmapCpm+mZPvSy ovUfu4Udt9ZoiTjLOe1rWogZBJPRMNKfsVBWyPpYqySjrA806muzEEH7pjrou4KDH5v+ G4o9rwZwSAfiKfxrI2eE9gNcjaX7PB789ldKcVXdLNRQ6YQw/xxRhTVCvr0MP7pp1oe+ hJHAOkNrDLJRvJtB54wn6vvK4HUej1q8UAs2M61D1Td9OAXC7x5us+Z2xa73b7wukgsR AX6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=bPbJpzFT; 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=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id pv22-20020a170907209600b006e00eb3a62bsi3170574ejb.101.2022.04.09.10.18.51; Sat, 09 Apr 2022 10:19:25 -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=@redhat.com header.s=mimecast20190719 header.b=bPbJpzFT; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230450AbiDHS4S (ORCPT + 99 others); Fri, 8 Apr 2022 14:56:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230098AbiDHS4M (ORCPT ); Fri, 8 Apr 2022 14:56:12 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EEFE53C30F9 for ; Fri, 8 Apr 2022 11:54:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649444047; h=from:from: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9uyU2VFoeBsyhZOJQIlctyu40TJSn7XsF2RPXyVl1do=; b=bPbJpzFTWJ1kz+HbNC8CputV4kqjt3EqDmVP0l7nUYx4EsrhnA6u0XW00SgrmliA8NjrS6 Z00od8mtowCCuTEsXKXNA5/iNoZKTpKJzUFSquw7JcFOWojwUqSYA0azShz0qBGpN2IC2K 7KD05f5tQd02w3Ol4O/n4BAOCl4OHaE= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-354-s0gkpkHvOtuJ0g1lbFeUhA-1; Fri, 08 Apr 2022 14:54:06 -0400 X-MC-Unique: s0gkpkHvOtuJ0g1lbFeUhA-1 Received: by mail-wr1-f71.google.com with SMTP id v3-20020adf8b43000000b00205e463b017so2417869wra.10 for ; Fri, 08 Apr 2022 11:54:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent :content-language:to:cc:references:from:organization:subject :in-reply-to:content-transfer-encoding; bh=9uyU2VFoeBsyhZOJQIlctyu40TJSn7XsF2RPXyVl1do=; b=j31DLRwlGOEzHnoBXBZjJ7OKvkkhr33XgStw2vyZRFvvZifpOeLvpsVBSUkT7DqW3Z El425MTn2RBMT7P2aHMBU9Bv8J/p1NiknKz1bsWmV0H3uOlx1ojCAUmys8vI39Ys5tYa TqAXKLmbaofcXiiG4dQz3AbiYy16GErTwUJMYPjpV4QoxUgjKduru4FxAYa6Y8VJful3 LkcZzWKICSZsJiueL88zpUl6Muf03buH42V+SnDnYTej5xhmoVlglV6qo1/QgXJOGnf5 HIXXpyf67H9XwrvNKlt7o35I/x9Wvvfjw+WwjST7/HD2wHBDWwUF92eEX3k6rTfUieLh slsg== X-Gm-Message-State: AOAM531VB7OKOkq0Bn1Z7DJUy0b6levj4nWrGnkmvUveHpswkjtQ8hou KXhRXewcMkonEMEt35KIj3k/bNpDj+lDpRrqWbbEJ5rhiFb8CuE5tWydQxCZyZCcEnnflM7T3sU nACIfjLRg+yfkRMf5Gs39CbhR X-Received: by 2002:a05:600c:4f96:b0:38e:7dbf:f80b with SMTP id n22-20020a05600c4f9600b0038e7dbff80bmr18613225wmq.2.1649444044836; Fri, 08 Apr 2022 11:54:04 -0700 (PDT) X-Received: by 2002:a05:600c:4f96:b0:38e:7dbf:f80b with SMTP id n22-20020a05600c4f9600b0038e7dbff80bmr18613189wmq.2.1649444044533; Fri, 08 Apr 2022 11:54:04 -0700 (PDT) Received: from ?IPV6:2003:cb:c704:fd00:612:f12b:a4a2:26b0? (p200300cbc704fd000612f12ba4a226b0.dip0.t-ipconnect.de. [2003:cb:c704:fd00:612:f12b:a4a2:26b0]) by smtp.gmail.com with ESMTPSA id o19-20020a05600c511300b0038d0d8f67e5sm10994785wms.16.2022.04.08.11.54.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 08 Apr 2022 11:54:04 -0700 (PDT) Message-ID: <7ab689e7-e04d-5693-f899-d2d785b09892@redhat.com> Date: Fri, 8 Apr 2022 20:54:02 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.6.2 Content-Language: en-US To: Sean Christopherson , Andy Lutomirski Cc: Chao Peng , kvm list , Linux Kernel Mailing List , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, Linux API , qemu-devel@nongnu.org, Paolo Bonzini , Jonathan Corbet , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , the arch/x86 maintainers , "H. Peter Anvin" , Hugh Dickins , Jeff Layton , "J . Bruce Fields" , Andrew Morton , Mike Rapoport , Steven Price , "Maciej S . Szmigiero" , Vlastimil Babka , Vishal Annapurve , Yu Zhang , "Kirill A. Shutemov" , "Nakajima, Jun" , Dave Hansen , Andi Kleen References: <20220310140911.50924-1-chao.p.peng@linux.intel.com> <20220310140911.50924-5-chao.p.peng@linux.intel.com> <02e18c90-196e-409e-b2ac-822aceea8891@www.fastmail.com> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH v5 04/13] mm/shmem: Restrict MFD_INACCESSIBLE memory against RLIMIT_MEMLOCK In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-5.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham 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 08.04.22 19:56, Sean Christopherson wrote: > On Thu, Apr 07, 2022, Andy Lutomirski wrote: >> >> On Thu, Apr 7, 2022, at 9:05 AM, Sean Christopherson wrote: >>> On Thu, Mar 10, 2022, Chao Peng wrote: >>>> Since page migration / swapping is not supported yet, MFD_INACCESSIBLE >>>> memory behave like longterm pinned pages and thus should be accounted to >>>> mm->pinned_vm and be restricted by RLIMIT_MEMLOCK. >>>> >>>> Signed-off-by: Chao Peng >>>> --- >>>> mm/shmem.c | 25 ++++++++++++++++++++++++- >>>> 1 file changed, 24 insertions(+), 1 deletion(-) >>>> >>>> diff --git a/mm/shmem.c b/mm/shmem.c >>>> index 7b43e274c9a2..ae46fb96494b 100644 >>>> --- a/mm/shmem.c >>>> +++ b/mm/shmem.c >>>> @@ -915,14 +915,17 @@ static void notify_fallocate(struct inode *inode, pgoff_t start, pgoff_t end) >>>> static void notify_invalidate_page(struct inode *inode, struct folio *folio, >>>> pgoff_t start, pgoff_t end) >>>> { >>>> -#ifdef CONFIG_MEMFILE_NOTIFIER >>>> struct shmem_inode_info *info = SHMEM_I(inode); >>>> >>>> +#ifdef CONFIG_MEMFILE_NOTIFIER >>>> start = max(start, folio->index); >>>> end = min(end, folio->index + folio_nr_pages(folio)); >>>> >>>> memfile_notifier_invalidate(&info->memfile_notifiers, start, end); >>>> #endif >>>> + >>>> + if (info->xflags & SHM_F_INACCESSIBLE) >>>> + atomic64_sub(end - start, ¤t->mm->pinned_vm); >>> >>> As Vishal's to-be-posted selftest discovered, this is broken as current->mm >>> may be NULL. Or it may be a completely different mm, e.g. AFAICT there's >>> nothing that prevents a different process from punching hole in the shmem >>> backing. >>> >> >> How about just not charging the mm in the first place? There’s precedent: >> ramfs and hugetlbfs (at least sometimes — I’ve lost track of the current >> status). >> >> In any case, for an administrator to try to assemble the various rlimits into >> a coherent policy is, and always has been, quite messy. ISTM cgroup limits, >> which can actually add across processes usefully, are much better. >> >> So, aside from the fact that these fds aren’t in a filesystem and are thus >> available by default, I’m not convinced that this accounting is useful or >> necessary. >> >> Maybe we could just have some switch require to enable creation of private >> memory in the first place, and anyone who flips that switch without >> configuring cgroups is subject to DoS. > > I personally have no objection to that, and I'm 99% certain Google doesn't rely > on RLIMIT_MEMLOCK. > It's unnacceptable for distributions to have random unprivileged users be able to allocate an unlimited amount of unmovable memory. And any kind of these "switches" won't help a thing because the distribution will have to enable them either way. I raised in the past that accounting might be challenging, so it's no surprise that something popped up now. RLIMIT_MEMLOCK was the obvious candidate, but as we discovered int he past already with secretmem, it's not 100% that good of a fit (unmovable is worth than mlocked). But it gets the job done for now at least. So I'm open for alternative to limit the amount of unmovable memory we might allocate for user space, and then we could convert seretmem as well. Random switches are not an option. -- Thanks, David / dhildenb