From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C3EE6199E89 for ; Tue, 2 Jun 2026 20:10:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780431051; cv=none; b=eCTzEiP06qWtx8+QWmqb5YRwC7ICYf2ML4sE74RRVGQAjghouu60v4RhIu/sE7p8SZg3/0Dpr3OXejwMioAeMJ2GxfmbBfe3e1TXtx+FCaL6bCFbG27tQuCEFpmjojb0Wi5GqicDcQFk+dNoZKfmcCuxdNDCO95bra7XvkIoJNM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780431051; c=relaxed/simple; bh=TwDK0tFwoHCwmAFf4IDwYwASZnp0PlqPVKN8mxLAYIM=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=RBkdvdH5U3EcQZ8hfM0ImxRAhge7uqM7LV8o8bpnqW7eOlmUz64Avg7v4McdlwrAtVZjfV9hYVNG64xi7ZXfP4BNIYCuB62gu2w8nYpo16RftUqHjGB9swbVrbJf0tI4gD3TUI0b6wJVb7D2WJmRB6SaLfHkA02lIqBrHy7usoM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=FlQf+5kL; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="FlQf+5kL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 15A6C1F00893; Tue, 2 Jun 2026 20:10:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1780431050; bh=NRCYIXk5xTkfp82OQZJovt45Ucm7r0SKmvk+xAm+PCY=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=FlQf+5kLpzBZVFvOeRcxtB8F6UOvyf1jDzq9+3UuWxdF3xkWE2UAV996mFLpzOrjQ EQQCrzBuG6yPBC2nBhYYIkj54I/oym5OyAKtWYfmcRDpTd+vUBy5sFuPaCJWJiROO2 4V85lGSfsE0NPzeBweamgMvxTUhJ0838w2S9ZOD8= Date: Tue, 2 Jun 2026 13:10:49 -0700 From: Andrew Morton To: Lorenzo Stoakes Cc: Arnd Bergmann , Greg Kroah-Hartman , David Hildenbrand , "Liam R . Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Jann Horn , Pedro Falcato , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH v3 0/3] remove mmap_action success, error hooks Message-Id: <20260602131049.74177bbb6d85fe01ff6512ff@linux-foundation.org> In-Reply-To: References: X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Tue, 2 Jun 2026 12:06:24 +0100 Lorenzo Stoakes wrote: > The mmap_action->success_hook was a strange beast added to enable code > which appeared to absolutely require access to a VMA pointer to work > correctly. > > Primarily this was for hugetlb, however a different approach will be taken > there, as clearly more work is required to figure out a sensible way of > converting hugetlb to use mmap_prepare. > > The other user was the memory char driver, specifically /dev/zero which has > the unusual property of explicitly setting file-backed VMAs anonymous. > > Providing the success hook was always foolish, as it allowed drivers a way > to workaround the restriction that they should not access a pointer to a > not-yet-correctly-initialised VMA - which defeats the purpose of the > mmap_prepare work. > > We can achieve the same thing in memory char driver without needing the > success hook, so this series removes that, then removes the success hook > altogether. > > The error hook is also unnecessary - the motivation for this was for > functions which need to override the error code when performing an mmap > action in order to avoid breaking userspace. > > We can achieve this by just providing a field for the error code. Doing > this means we don't have to worry about the hook doing anything odd. > > We also add a check to ensure the error code is in fact valid. > > Again the memory char driver is the only current user of this, so this > series updates it to use that. > > After this change mmap_action has no custom hooks at all, which seems > rather more cromulent than before. Updated, thanks. > v3: > * Rename error_filter -> errror_override + update commit message as per > David. Here's how v3 altered mm.git: drivers/char/mem.c | 2 +- include/linux/mm_types.h | 6 +++--- mm/util.c | 6 +++--- tools/testing/vma/include/dup.h | 6 +++--- 4 files changed, 10 insertions(+), 10 deletions(-) --- a/drivers/char/mem.c~b +++ a/drivers/char/mem.c @@ -357,7 +357,7 @@ static int mmap_mem_prepare(struct vm_ar /* Remap-pfn-range will mark the range with the I/O flag. */ mmap_action_remap_full(desc, desc->pgoff); - desc->action.error_filter = -EAGAIN; + desc->action.error_override = -EAGAIN; return 0; } --- a/include/linux/mm_types.h~b +++ a/include/linux/mm_types.h @@ -844,10 +844,10 @@ struct mmap_action { enum mmap_action_type type; /* - * If non-zero, filter errors that arise from mmap actions such that we - * return error_filter instead. Only valid error codes may be specified. + * If non-zero, replace errors that arise from mmap actions with this + * value instead. Only valid error codes may be specified. */ - int error_filter; + int error_override; /* * This should be set in rare instances where the operation required --- a/mm/util.c~b +++ a/mm/util.c @@ -1415,16 +1415,16 @@ static int mmap_action_finish(struct vm_ len = vma_pages(vma) << PAGE_SHIFT; do_munmap(current->mm, vma->vm_start, len, NULL); - return action->error_filter ?: err; + return action->error_override ?: err; } #ifdef CONFIG_MMU static int check_mmap_action(struct mmap_action *action) { - const unsigned long filter = action->error_filter; + const unsigned long override = action->error_override; - if (WARN_ON_ONCE(filter && !IS_ERR_VALUE(filter))) + if (WARN_ON_ONCE(override && !IS_ERR_VALUE(override))) return -EINVAL; return 0; --- a/tools/testing/vma/include/dup.h~b +++ a/tools/testing/vma/include/dup.h @@ -483,10 +483,10 @@ struct mmap_action { enum mmap_action_type type; /* - * If non-zero, filter errors that arise from mmap actions such that we - * return error_filter instead. Only valid error codes may be specified. + * If non-zero, replace errors that arise from mmap actions with this + * value instead. Only valid error codes may be specified. */ - int error_filter; + int error_override; /* * This should be set in rare instances where the operation required _