linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Hillf Danton <hdanton@sina.com>
To: Lorenzo Stoakes <lstoakes@gmail.com>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	Andrew Morton <akpm@linux-foundation.org>,
	Jason Gunthorpe <jgg@ziepe.ca>,
	Matthew Wilcox <willy@infradead.org>
Subject: Re: [PATCH] mm/gup: disallow GUP writing to file-backed mappings by default
Date: Sun, 23 Apr 2023 08:46:16 +0800	[thread overview]
Message-ID: <20230423004616.1755-1-hdanton@sina.com> (raw)
In-Reply-To: <f86dc089b460c80805e321747b0898fd1efe93d7.1682168199.git.lstoakes@gmail.com>

On 22 Apr 2023 14:37:05 +0100 Lorenzo Stoakes <lstoakes@gmail.com>
> @@ -110,7 +110,8 @@ int qib_get_user_pages(unsigned long start_page, size_t num_pages,
>  	for (got = 0; got < num_pages; got += ret) {
>  		ret = pin_user_pages(start_page + got * PAGE_SIZE,
>  				     num_pages - got,
> -				     FOLL_LONGTERM | FOLL_WRITE,
> +				     FOLL_LONGTERM | FOLL_WRITE |
> +				     FOLL_ALLOW_BROKEN_FILE_MAPPING,
>  				     p + got, NULL);
>  		if (ret < 0) {
>  			mmap_read_unlock(current->mm);

[...]

> +/*
> + * Writing to file-backed mappings using GUP is a fundamentally broken operation
> + * as kernel write access to GUP mappings may not adhere to the semantics
> + * expected by a file system.
> + *
> + * In most instances we disallow this broken behaviour, however there are some
> + * exceptions to this enforced here.
> + */
> +static inline bool can_write_file_mapping(struct vm_area_struct *vma,
> +					  unsigned long gup_flags)
> +{
> +	struct file *file = vma->vm_file;
> +
> +	/* If we aren't pinning then no problematic write can occur. */
> +	if (!(gup_flags & (FOLL_GET | FOLL_PIN)))
> +		return true;
> +
> +	/* Special mappings should pose no problem. */
> +	if (!file)
> +		return true;
> +
> +	/* Has the caller explicitly indicated this case is acceptable? */
> +	if (gup_flags & FOLL_ALLOW_BROKEN_FILE_MAPPING)
> +		return true;

Does the caller mean that PUP for DMA is no longer breaking writeback?
> +
> +	/* shmem and hugetlb mappings do not have problematic semantics. */
> +	return vma_is_shmem(vma) || is_file_hugepages(file);
> +}


  reply	other threads:[~2023-04-23  0:46 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-22 13:37 Lorenzo Stoakes
2023-04-23  0:46 ` Hillf Danton [this message]
2023-04-23 19:32 ` Simon Horman
2023-04-23 19:40   ` Lorenzo Stoakes
2023-04-23 20:02     ` Simon Horman
2023-04-23 22:29 ` Dave Chinner
2023-04-23 22:56   ` Lorenzo Stoakes
2023-04-24 17:49     ` Jason Gunthorpe
2023-04-24  3:41 ` Mika Penttilä
2023-04-24  6:51   ` Lorenzo Stoakes
2023-04-24 12:02 ` Kirill A. Shutemov
2023-04-24 12:31   ` Lorenzo Stoakes
2023-04-24 13:40     ` Kirill A. Shutemov
2023-04-24 17:59       ` Jason Gunthorpe
2023-04-24 16:09 ` Jan Kara
2023-04-24 16:22   ` Lorenzo Stoakes
2023-04-24 17:53   ` Jason Gunthorpe

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=20230423004616.1755-1-hdanton@sina.com \
    --to=hdanton@sina.com \
    --cc=akpm@linux-foundation.org \
    --cc=jgg@ziepe.ca \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lstoakes@gmail.com \
    --cc=willy@infradead.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