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 65657C4332F for ; Fri, 23 Dec 2022 01:33:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B051D940007; Thu, 22 Dec 2022 20:33:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A8E1C900002; Thu, 22 Dec 2022 20:33:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9075C940007; Thu, 22 Dec 2022 20:33:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 7A587900002 for ; Thu, 22 Dec 2022 20:33:40 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 3B54A120477 for ; Fri, 23 Dec 2022 01:33:40 +0000 (UTC) X-FDA: 80271849000.11.5B490B6 Received: from mail-ed1-f47.google.com (mail-ed1-f47.google.com [209.85.208.47]) by imf08.hostedemail.com (Postfix) with ESMTP id 9B3EC160007 for ; Fri, 23 Dec 2022 01:33:38 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="SxL3/bc7"; spf=pass (imf08.hostedemail.com: domain of zokeefe@google.com designates 209.85.208.47 as permitted sender) smtp.mailfrom=zokeefe@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1671759218; 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=wb1LkXgcJCeo0bQ/ORdTI+IAi3jB4nOTArUQY6xFlbY=; b=be0bZ6lOjPDTHPzEBioQu4nbTG24vM3XxAYEliC9pB9Dmbdc9Zcnf1DIsEwbzJAVE+K/LE Gw7zrtR7DkYTGutY1FtESbAxKi4uAgzNQ1P7DmwAThrSi8Nld2M0rZxzFHvIxgs+7155XQ 4avrd3hhQpqpKruk2Z2r6yQu3xc4RKg= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="SxL3/bc7"; spf=pass (imf08.hostedemail.com: domain of zokeefe@google.com designates 209.85.208.47 as permitted sender) smtp.mailfrom=zokeefe@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1671759218; a=rsa-sha256; cv=none; b=2nNfQhuKLzkEIbo8ufkHKuXmzxnaPWvvgqHb0NoowKisnmn78NVNPew+cOqcOv3GRRhfz+ xblNCHCdc23JeQ/0esWZ0ZI0jOPMymJ8+uWBZOEunK9Nu5SH2GZh+o4HeGVxCqnERkD6Mb jxmKT9UyL3fLE0I3HcBo6eavZJDjnRA= Received: by mail-ed1-f47.google.com with SMTP id r26so81776edc.5 for ; Thu, 22 Dec 2022 17:33:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=wb1LkXgcJCeo0bQ/ORdTI+IAi3jB4nOTArUQY6xFlbY=; b=SxL3/bc76aA4oeGPALKpwh8yli5Whgymf7iurPSZDHvWTQrFlxoi1vbNoiN/Hb9qk6 muOfywFUJFcYV36u4vKV8yCWHfdFa0P1ALTsr6ilqcBlSLYWs6FjXSLkUGmp3QhcmwwY xdYNThF8EyasLH16JzP0dFFv3WrJKUps45E99ABDZ05lgRGSt0NN77zDfvJbF67z9xOd ftXBjWqxRtJDm7DYXUWtiDJZgkPjirz2xHzz4i36Wsb1NNYz5z8Ew4VPZn0Kjem9F9Eq teZ2ICoUlUaugcRoCohEbcC3AGffB1y/Tizg6g1f8q2yE1ZPmmrgjBkABbBO+lR0S2kT Wm/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=wb1LkXgcJCeo0bQ/ORdTI+IAi3jB4nOTArUQY6xFlbY=; b=KiX3pMU95rQHcH9pC5ywZ42jvul+dH5VPackw2ERuhOnN5kRNCw0v3WYPO8gKaBo91 OjkGNxyXXrTsK8XABe3PqQ5G7uM8OEMH47/tdGNCOAHuVgb3QXcSvH034Czat4V3VZDZ WCgcxmhbbpxUwfA5HQrZDn5MLzxIQ1f6VeH9gSOhaXJdBDGfeo8Vb80kDOxtAXBxbF/l VCT1qGQj2dtUzUJxuHITB2Az+16OqpL8wlMsJ941XKRerLh+WDwB2VGj2yhCQwxiJeQ9 3cmuP3BgJyhHo6kkLka2ThNfd7VVDcCFgaJzNQEbautKIfUMqXyMGiDClKW+AzRcyO75 KmJw== X-Gm-Message-State: AFqh2kpLX2KRByq7N3TUmUUXcS2eNNckVVISMr/PhaB1u5CMgiPUdlT1 Ifkaucm5ObVZ/yKYjTm9KBnFSscjnIdnzVqbCwYtKQ== X-Google-Smtp-Source: AMrXdXvREFLyqnb2KltmJOFwdpSk5HVG+Pzs5TNolMK+BCPGZpvYcu8LLu4azQGDpPVMRmfrrDhaVB+v85wYLwynzUc= X-Received: by 2002:a05:6402:2036:b0:46a:b8e0:f73a with SMTP id ay22-20020a056402203600b0046ab8e0f73amr778260edb.425.1671759216935; Thu, 22 Dec 2022 17:33:36 -0800 (PST) MIME-Version: 1.0 References: <20221223003953.2795313-1-zokeefe@google.com> <20221222165652.3775ff5343580e02ffabfa23@linux-foundation.org> <4678bb5a-b417-c3c3-333e-1618694b7653@google.com> In-Reply-To: <4678bb5a-b417-c3c3-333e-1618694b7653@google.com> From: "Zach O'Keefe" Date: Thu, 22 Dec 2022 17:33:00 -0800 Message-ID: Subject: Re: [PATCH] mm/MADV_COLLAPSE: don't expand collapse when vm_end is past requested end To: Hugh Dickins Cc: Andrew Morton , linux-mm@kvack.org, Yang Shi Content-Type: text/plain; charset="UTF-8" X-Stat-Signature: tf1uddow3ekyy89xf8h6aqn4b56ssgzz X-Rspam-User: X-Rspamd-Queue-Id: 9B3EC160007 X-Rspamd-Server: rspam06 X-HE-Tag: 1671759218-582089 X-HE-Meta: U2FsdGVkX18NqrjXW3i7MBTS5Suy3twp7ZCOOdbstKjIJKaNcJFx6Ks2vezVdKOK7JnE1GKGacyDERuzHMRlY4rTohAtKSSV9zJ51IKTvnU+uAcRo8rDuPTuvNivG6VAr2UWjx2HiLBlQkE86GkBc5ea23pvmj4kfSH4g73pXzCvb2l6zDhNbQiE8nMtJIuvmubADSLwh5uOJJMSwGsil7Q9LPKW365gCemMckNBlBTn6evOuNk5fKgRI0L+XfPmY9OgSKmAjKDO7rayOWTT9O0g/CobHW3/o/N17JqNErlFhbONPg/hYWkzM2J3Di6FHonOBK4XCDvCdRwkFe0bnym4CRle9M8O0MjcnJPMmuz8hOcGF2Y67KCh3WMUvjISFZp5QQ+CTVW3oO/nRO/vpGQlWD49VQUHKg+TERUHiYMPL5t9f/0yd+YcbJv20N0FCDiJVBHEjWRbrylZensxHPg/Qstl+CAiSICQlcyprCXQ0G8Hk9u1ccYCgz3XIHANmvInEopvg2ki8e0IM9omkpLUj2YDf9vKwWCutgJb4H0OH2AEd1GNatkXiXD1s/E8FpHXfLzt8PLhQL461CgcBEWCEQUvlb6QI5UPoplqRFu73UQk3bGcawMBC8aFIs381sN6440Y1zjs8rco3zXUiZB5X9Zt43lB+RlJEQ6D1taNq8JFgfa3TJlaiiM/Sf6T/ld1WgZiXFEFc5DjJzFS9X/s2b/eOSCbV6QizqosKYk8j+VYjVxVyPq9OxHMck1ojqrBPV7jVxX9m/0htev2A5tQ4NZfj3EoL0kqHf3iJcUbIeQiBfB1oFboWuACL1btgz3sRBcTYL1FpEtZ2Vspfd7/M9d5GYlDWzbGYsB5oJLmSDC/t4yiFyGXNLAGQ9sgxJnSNT1Z71CY6LxX3w/XhFNM8JSRc6DS58vZ8SsodgB2PpdRd3wCTdbdx9Vl5HUtucg2WQRPYGGddtiecI4 6YuQG7ty CmzgMiJhrjLUFTEhJgMm/q1lWoiiR2ggcmNAvTUCo/WmIOkmxUxmzqsl7Yw== 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 Thu, Dec 22, 2022 at 5:25 PM Hugh Dickins wrote: > > On Thu, 22 Dec 2022, Andrew Morton wrote: > > On Thu, 22 Dec 2022 16:39:53 -0800 "Zach O'Keefe" wrote: > > > > > MADV_COLLAPSE acts on one hugepage-aligned/sized region at a time, until > > > it has collapsed all eligible memory contained within the bounds > > > supplied by the user. > > > > > > At the top of each hugepage iteration we (re)lock mmap_lock and > > > (re)validate the VMA for eligibility and update variables that might > > > have changed while mmap_lock was dropped. One thing that might occur, > > > is that the VMA could be resized, and as such, we refetch vma->vm_end > > > to make sure we don't collapse past the end of the VMA. > > > > > > However, it's possible that during this refetch that we expand the > > > region acted on by MADV_COLLAPSE if vma->vm_end is greater than the end > > > of the user-supplied range. > > > > > > Don't expand the acted-on region when refetching vma->vm_end. > > > > What are the user-visible effects of this? > > Not any kernel crash, I think; but in my case (I was trying to check > something else about MADV_COLLAPSE, and so was first verifying that > it worked in the simple case) I kept getting EINVAL back from it, > even when I'd fixed all my own userspace mistakes. > > It turned out to be that my mmap was bigger than the file itself, and > I was only trying to collapse the file length; but because of the > mis-adjustment to vm_end, it ran off the end of file and got into > EINVAL territory (in a different context, would be EFAULT or SIGBUS). > > So in my case, unexpected failure. But I guess another case would be > too much success: I suppose that if you try to collapse the first 2M > of a 2T file, the mis-adjustment would cause it to spend a very long > time doing much more work than you asked for. Thanks Hugh, Andrew -- I should have clarified this question in the description -- apologies there. As Hugh mentions, I don't believe there is a kernel stability concern here as we always (re)validate the VMA / region accordingly. Also as Hugh mentions, the user-visible effects are: we try to collapse more memory than requested by the user, and/or failing an operation that should have otherwise succeeded. An example is trying to collapse a 4MiB file contained within a 12MiB VMA. > > Fixes: 4d24de9425f7 ("mm: MADV_COLLAPSE: refetch vm_end after reacquiring mmap_lock") > > Should we backport "mm/shmem: restore SHMEM_HUGE_DENY precedence over > MADV_COLLAPSE" and/or this patch into 6.1.x? > > > > > Fixes: 4d24de9425f7 ("mm: MADV_COLLAPSE: refetch vm_end after reacquiring mmap_lock") > > > > Should we backport "mm/shmem: restore SHMEM_HUGE_DENY precedence over > > MADV_COLLAPSE" and/or this patch into 6.1.x? > > Yes, please do Cc stable for them both in 6.1.x: I only just now realized > the nasty "too much success" possibility, which does seem well worth stable; > and I'd particularly like the precedence of SHMEM_HUGE_DENY asserted in > 6.1.x, because doing it later it would become a UAPI change - I'm sorry > I didn't catch it sooner, Zach did ask me to check but I was head down > on other things. Thanks Hugh. Yes, I'm planning to backport these both to 6.1 stable after they were deemed acceptable. > Thanks, > Hugh