linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Hugh Dickins <hughd@google.com>
To: Ming Lin <mlin@kernel.org>
Cc: Hugh Dickins <hughd@google.com>,
	 Linus Torvalds <torvalds@linux-foundation.org>,
	 Simon Ser <contact@emersion.fr>,
	linux-mm@kvack.org,  linux-kernel@vger.kernel.org,
	linux-fsdevel@vger.kernel.org,  linux-api@vger.kernel.org
Subject: Re: [PATCH 2/2] mm: adds NOSIGBUS extension for out-of-band shmem read
Date: Wed, 2 Jun 2021 17:46:02 -0700 (PDT)	[thread overview]
Message-ID: <alpine.LSU.2.11.2106021719500.8333@eggly.anvils> (raw)
In-Reply-To: <79a27014-5450-1345-9eea-12fc9ae25777@kernel.org>

On Wed, 2 Jun 2021, Ming Lin wrote:
> 
> This is what I wrote so far.
> 
> ---
>  include/linux/mm.h                     |  2 ++
>  include/linux/mman.h                   |  1 +
>  include/uapi/asm-generic/mman-common.h |  1 +
>  mm/memory.c                            | 12 ++++++++++++
>  mm/mmap.c                              |  4 ++++
>  5 files changed, 20 insertions(+)

I have not looked at the rest, just looking at mm/memory.c:

> --- a/mm/memory.c
> +++ b/mm/memory.c
> @@ -3676,6 +3676,18 @@ static vm_fault_t __do_fault(struct vm_fault *vmf)
>  	}
>   	ret = vma->vm_ops->fault(vmf);
> +	if (unlikely(ret & VM_FAULT_SIGBUS) && (vma->vm_flags & VM_NOSIGBUS))
> {
> +		/*
> +		 * Get zero page for MAP_NOSIGBUS mapping, which isn't
> +		 * coherent wrt shmem contents that are expanded and
> +		 * filled in later.
> +		 */
> +		vma->vm_flags |= VM_MIXEDMAP;
> +		if (!vm_insert_page(vma, (unsigned long)vmf->address,
> +				ZERO_PAGE(vmf->address)))
> +			return VM_FAULT_NOPAGE;
> +	}
> +
>  	if (unlikely(ret & (VM_FAULT_ERROR | VM_FAULT_NOPAGE | VM_FAULT_RETRY
> |
>  			    VM_FAULT_DONE_COW)))
>  		return ret;

Sorry, I directed you to mm/memory.c without indicating what's
appropriate here.  Please don't attempt to use VM_MIXEDMAP and
vm_insert_page(): they're for special driver mmaps, they're no
better here than they were in mm/shmem.c.

It's do_anonymous_page()'s business to map in the zero page on
read fault (see "my_zero_pfn(vmf->address)" in there), or fill
a freshly allocated page with zeroes on write fault - and now
you're sticking to MAP_PRIVATE, write faults in VM_WRITE areas
are okay for VM_NOSIGBUS.

Ideally you can simply call do_anonymous_page() from __do_fault()
in the VM_FAULT_SIGBUS on VM_NOSIGBUS case.  That's what to start
from anyway: but look to see if there's state to be adjusted to
achieve that; and it won't be surprising if somewhere down in
do_anonymous_page() or something it calls, there's a BUG on it
being called when vma->vm_file is set, or something like that.
May need some tweaking.

Hugh


  reply	other threads:[~2021-06-03  0:46 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-01 23:22 [PATCH 0/2] mm: adds MAP_NOSIGBUS extension for " Ming Lin
2021-06-01 23:22 ` [PATCH 1/2] mm: make "vm_flags" be an u64 Ming Lin
2021-06-02  1:58   ` kernel test robot
2021-06-02  2:06   ` kernel test robot
2021-06-01 23:22 ` [PATCH 2/2] mm: adds NOSIGBUS extension for out-of-band shmem read Ming Lin
2021-06-02  0:16   ` Linus Torvalds
2021-06-02  1:06     ` Ming Lin
2021-06-02  2:13     ` Hugh Dickins
2021-06-02  2:02   ` kernel test robot
2021-06-02  3:49   ` Hugh Dickins
2021-06-03  0:05     ` Ming Lin
2021-06-03  0:46       ` Hugh Dickins [this message]
2021-06-03 18:25         ` Linus Torvalds
2021-06-03 19:07           ` Hugh Dickins
2021-06-03 19:12             ` Linus Torvalds
2021-06-03 19:15               ` Linus Torvalds
2021-06-03 19:24               ` Andy Lutomirski
2021-06-03 19:35                 ` Simon Ser
2021-06-03 19:57         ` Ming Lin
2021-06-02  9:30   ` kernel test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LSU.2.11.2106021719500.8333@eggly.anvils \
    --to=hughd@google.com \
    --cc=contact@emersion.fr \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mlin@kernel.org \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox