All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Fabio M. De Francesco" <fmdefrancesco@gmail.com>
To: Ira Weiny <ira.weiny@intel.com>
Cc: Benjamin LaHaise <bcrl@kvack.org>,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	Eric Biederman <ebiederm@xmission.com>,
	Kees Cook <keescook@chromium.org>,
	Dan Williams <dan.j.williams@intel.com>,
	Matthew Wilcox <willy@infradead.org>, Jan Kara <jack@suse.cz>,
	Jeff Layton <jlayton@kernel.org>,
	Chuck Lever <chuck.lever@oracle.com>,
	Jens Axboe <axboe@kernel.dk>,
	Pavel Begunkov <asml.silence@gmail.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Paul Walmsley <paul.walmsley@sifive.com>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	Albert Ou <aou@eecs.berkeley.edu>,
	Nathan Chancellor <nathan@kernel.org>,
	Nick Desaulniers <ndesaulniers@google.com>,
	Tom Rix <trix@redhat.com>,
	linux-aio@kvack.org, linux-fsdevel@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	nvdimm@lists.linux.dev, io-uring@vger.kernel.org,
	linux-riscv@lists.infradead.org, llvm@lists.linux.dev
Subject: Re: [PATCH] fs: Call kmap_local_page() in copy_string_kernel()
Date: Sat, 23 Jul 2022 03:02:32 +0200	[thread overview]
Message-ID: <2115146.irdbgypaU6@opensuse> (raw)
In-Reply-To: <Ytnr3IhSkDOjqbZ1@iweiny-desk3>

On venerdì 22 luglio 2022 02:14:20 CEST Ira Weiny wrote:
> On Sun, Jul 10, 2022 at 12:01:36PM +0200, Fabio M. De Francesco wrote:
> > The use of kmap_atomic() is being deprecated in favor of 
kmap_local_page().
> > 
> > With kmap_local_page(), the mappings are per thread, CPU local, not
> > globally visible and can take page faults. Furthermore, the mappings 
can be
> > acquired from any context (including interrupts).
> > 
> > Therefore, use kmap_local_page() in copy_string_kernel() instead of
> > kmap_atomic().
> > 
> > Tested with xfstests on a QEMU + KVM 32-bits VM booting a kernel with
> > HIGHMEM64GB enabled.
> > 
> > Suggested-by: Ira Weiny <ira.weiny@intel.com>
> > Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
> > ---
> > 
> > I sent a first patch to fs/exec.c for converting kmap() and 
kmap_atomic()
> > to kmap_local_page():
> > https://lore.kernel.org/lkml/20220630163527.9776-1-fmdefrancesco@gmail.com/
> > 
> > Some days ago, Ira Weiny, while he was reviewing that patch, made me 
notice
> > that I had overlooked a second kmap_atomic() in the same file (thanks):
> > https://lore.kernel.org/lkml/YsiQptk19txHrG4c@iweiny-desk3/
> > 
> > I've been asked to send this as an additional change. This is why there 
will
> > not be any second version of that previous patch.
> > 
> >  fs/exec.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/fs/exec.c b/fs/exec.c
> > index 4a2129c0d422..5fa652ca5823 100644
> > --- a/fs/exec.c
> > +++ b/fs/exec.c
> > @@ -639,11 +639,11 @@ int copy_string_kernel(const char *arg, struct 
linux_binprm *bprm)
> >  		page = get_arg_page(bprm, pos, 1);
> >  		if (!page)
> >  			return -E2BIG;
> > -		kaddr = kmap_atomic(page);
> > +		kaddr = kmap_local_page(page);
> >  		flush_arg_page(bprm, pos & PAGE_MASK, page);
> 
> I really question why we can't use memcpy_to_page() here and move the
> flush_arg_page() prior to the mapping?
> 
> flush_arg_page() only calls flush_cache_page() which does not need the
> mapping to work correctly AFAICT.

You're right here. I'm sorry for being so lazy and not checking that 
flush_arg_page() does not need to be called while the task holds the local 
mapping :-(

In v2 I'll move flush_arg_page() one line above memcpy_to_page().

Thanks for your comment,

Fabio

> 
> Ira
> 
> >  		memcpy(kaddr + offset_in_page(pos), arg, 
bytes_to_copy);
> >  		flush_dcache_page(page);
> > -		kunmap_atomic(kaddr);
> > +		kunmap_local(kaddr);
> >  		put_arg_page(page);
> >  	}
> >  
> > -- 
> > 2.36.1
> > 
> 





WARNING: multiple messages have this Message-ID (diff)
From: "Fabio M. De Francesco" <fmdefrancesco@gmail.com>
To: Ira Weiny <ira.weiny@intel.com>
Cc: Benjamin LaHaise <bcrl@kvack.org>,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	Eric Biederman <ebiederm@xmission.com>,
	Kees Cook <keescook@chromium.org>,
	Dan Williams <dan.j.williams@intel.com>,
	Matthew Wilcox <willy@infradead.org>, Jan Kara <jack@suse.cz>,
	Jeff Layton <jlayton@kernel.org>,
	Chuck Lever <chuck.lever@oracle.com>,
	Jens Axboe <axboe@kernel.dk>,
	Pavel Begunkov <asml.silence@gmail.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Paul Walmsley <paul.walmsley@sifive.com>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	Albert Ou <aou@eecs.berkeley.edu>,
	Nathan Chancellor <nathan@kernel.org>,
	Nick Desaulniers <ndesaulniers@google.com>,
	Tom Rix <trix@redhat.com>,
	linux-aio@kvack.org, linux-fsdevel@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	nvdimm@lists.linux.dev, io-uring@vger.kernel.org,
	linux-riscv@lists.infradead.org, llvm@lists.linux.dev
Subject: Re: [PATCH] fs: Call kmap_local_page() in copy_string_kernel()
Date: Sat, 23 Jul 2022 03:02:32 +0200	[thread overview]
Message-ID: <2115146.irdbgypaU6@opensuse> (raw)
In-Reply-To: <Ytnr3IhSkDOjqbZ1@iweiny-desk3>

On venerdì 22 luglio 2022 02:14:20 CEST Ira Weiny wrote:
> On Sun, Jul 10, 2022 at 12:01:36PM +0200, Fabio M. De Francesco wrote:
> > The use of kmap_atomic() is being deprecated in favor of 
kmap_local_page().
> > 
> > With kmap_local_page(), the mappings are per thread, CPU local, not
> > globally visible and can take page faults. Furthermore, the mappings 
can be
> > acquired from any context (including interrupts).
> > 
> > Therefore, use kmap_local_page() in copy_string_kernel() instead of
> > kmap_atomic().
> > 
> > Tested with xfstests on a QEMU + KVM 32-bits VM booting a kernel with
> > HIGHMEM64GB enabled.
> > 
> > Suggested-by: Ira Weiny <ira.weiny@intel.com>
> > Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
> > ---
> > 
> > I sent a first patch to fs/exec.c for converting kmap() and 
kmap_atomic()
> > to kmap_local_page():
> > https://lore.kernel.org/lkml/20220630163527.9776-1-fmdefrancesco@gmail.com/
> > 
> > Some days ago, Ira Weiny, while he was reviewing that patch, made me 
notice
> > that I had overlooked a second kmap_atomic() in the same file (thanks):
> > https://lore.kernel.org/lkml/YsiQptk19txHrG4c@iweiny-desk3/
> > 
> > I've been asked to send this as an additional change. This is why there 
will
> > not be any second version of that previous patch.
> > 
> >  fs/exec.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/fs/exec.c b/fs/exec.c
> > index 4a2129c0d422..5fa652ca5823 100644
> > --- a/fs/exec.c
> > +++ b/fs/exec.c
> > @@ -639,11 +639,11 @@ int copy_string_kernel(const char *arg, struct 
linux_binprm *bprm)
> >  		page = get_arg_page(bprm, pos, 1);
> >  		if (!page)
> >  			return -E2BIG;
> > -		kaddr = kmap_atomic(page);
> > +		kaddr = kmap_local_page(page);
> >  		flush_arg_page(bprm, pos & PAGE_MASK, page);
> 
> I really question why we can't use memcpy_to_page() here and move the
> flush_arg_page() prior to the mapping?
> 
> flush_arg_page() only calls flush_cache_page() which does not need the
> mapping to work correctly AFAICT.

You're right here. I'm sorry for being so lazy and not checking that 
flush_arg_page() does not need to be called while the task holds the local 
mapping :-(

In v2 I'll move flush_arg_page() one line above memcpy_to_page().

Thanks for your comment,

Fabio

> 
> Ira
> 
> >  		memcpy(kaddr + offset_in_page(pos), arg, 
bytes_to_copy);
> >  		flush_dcache_page(page);
> > -		kunmap_atomic(kaddr);
> > +		kunmap_local(kaddr);
> >  		put_arg_page(page);
> >  	}
> >  
> > -- 
> > 2.36.1
> > 
> 





_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

  reply	other threads:[~2022-07-23  1:02 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-10 10:01 [PATCH] fs: Call kmap_local_page() in copy_string_kernel() Fabio M. De Francesco
2022-07-10 10:01 ` Fabio M. De Francesco
2022-07-22  0:14 ` Ira Weiny
2022-07-22  0:14   ` Ira Weiny
2022-07-23  1:02   ` Fabio M. De Francesco [this message]
2022-07-23  1:02     ` Fabio M. De Francesco

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=2115146.irdbgypaU6@opensuse \
    --to=fmdefrancesco@gmail.com \
    --cc=aou@eecs.berkeley.edu \
    --cc=asml.silence@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=bcrl@kvack.org \
    --cc=chuck.lever@oracle.com \
    --cc=dan.j.williams@intel.com \
    --cc=ebiederm@xmission.com \
    --cc=io-uring@vger.kernel.org \
    --cc=ira.weiny@intel.com \
    --cc=jack@suse.cz \
    --cc=jlayton@kernel.org \
    --cc=keescook@chromium.org \
    --cc=linux-aio@kvack.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=llvm@lists.linux.dev \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=nvdimm@lists.linux.dev \
    --cc=palmer@dabbelt.com \
    --cc=paul.walmsley@sifive.com \
    --cc=tglx@linutronix.de \
    --cc=trix@redhat.com \
    --cc=viro@zeniv.linux.org.uk \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.