linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Ira Weiny <ira.weiny@intel.com>
To: Jens Wiklander <jens.wiklander@linaro.org>
Cc: "Linus Torvalds" <torvalds@linux-foundation.org>,
	"Sumit Garg" <sumit.garg@linaro.org>,
	"Phil Chang (張世勳)" <Phil.Chang@mediatek.com>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Al Viro" <viro@zeniv.linux.org.uk>,
	"Fabio M. De Francesco" <fmdefrancesco@gmail.com>,
	"Christoph Hellwig" <hch@lst.de>,
	"op-tee@lists.trustedfirmware.org"
	<op-tee@lists.trustedfirmware.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-mm@kvack.org" <linux-mm@kvack.org>
Subject: Re: [PATCH 2/4] tee: Remove vmalloc page support
Date: Thu, 15 Dec 2022 16:41:04 -0800	[thread overview]
Message-ID: <Y5u+oOLkJs6jehik@iweiny-desk3> (raw)
In-Reply-To: <CAHUa44GkTLCzuSij5FbjBXFBM1CCQROtrCtHHtj70ZRi-3K7uA@mail.gmail.com>

On Fri, Oct 07, 2022 at 10:12:57AM +0200, Jens Wiklander wrote:
> On Thu, Oct 6, 2022 at 8:20 PM Linus Torvalds
> <torvalds@linux-foundation.org> wrote:
> >
> > On Wed, Oct 5, 2022 at 11:24 PM Sumit Garg <sumit.garg@linaro.org> wrote:
> > >
> > > Sorry but you need to get your driver mainline in order to support
> > > vmalloc interface.
> >
> > Actually, I think even then we shouldn't support vmalloc - and
> > register_shm_helper() just needs to be changed to pass in an array of
> > actual page pointers instead.
> 
> register_shm_helper() is an internal function, I suppose it's what's
> passed to tee_shm_register_user_buf() and especially
> tee_shm_register_kernel_buf() in this case.
> 
> So the gain is that in the kernel it becomes the caller's
> responsibility to provide the array of page pointers and the TEE
> subsystem doesn't need to care about what kind of kernel memory it is
> any longer. Yes, that should avoid eventual complexities with
> vmalloc() etc.

I finally spent some time digging into this again.

Overall I'm not opposed to trying to clean up the code more but I feel like the
removal of TEE_SHM_USER_MAPPED is too complex for the main goal; to remove a
caller of kmap_to_page().

Not only is that flag used in release_registered_pages() but it is also used in
tee_shm_fop_mmap().  I'm not following exactly why.  I think this is to allow
mmap of the tee_shm's allocated by kernel users?  Which I _think_ is
orthogonal to the callers of tee_shm_register_kernel_buf()?

> 
> >
> > At that point TEE_SHM_USER_MAPPED should also go away, because then
> > it's the caller that should just do either the user space page
> > pinning, or pass in the kernel page pointer.
> >
> > JensW, is there some reason that wouldn't work?
> 
> We still need to know if it's kernel or user pages in
> release_registered_pages().

Yes.

As I dug into this it seemed ok to define a tee_shm_kernel_free().  Pull out
the allocation of the page array from register_shm_helper() such that it could
be handled by tee_shm_register_kernel_buf() and this new tee_shm_kernel_free().

This seems reasonable because the only callers of tee_shm_register_kernel_buf()
are in trusted_tee.c and they all call tee_shm_free() on the registered memory
prior to returning.

Other callers[*] of tee_shm_free() obtained tee_shm from
tee_shm_alloc_kernel_buf() which AFAICT avoids all this nonsense.

[*] such as .../drivers/firmware/broadcom/tee_bnxt_fw.c.

> 
> The struct tee_shm:s acquired with syscalls from user space are
> reference counted. As are the kernel tee_shm:s, but I believe we could
> separate them to avoid reference counting tee_shm:s used by kernel
> clients if needed. I'll need to look closer at this if we're going to
> use that approach.
> 
> Without reference counting the caller of tee_shm_free() can be certain
> that the secure world is done with the memory so we could delegate the
> kernel pages part of release_registered_pages() to the caller instead.
> 

I'm not sure I follow you here.  Would this be along the lines of creating a
tee_shm_free_kernel() to be used in trusted_tee.c for those specific kernel
data?

Overall I feel like submitting this series again with Christoph and Al's
comments addressed is the best way forward to get rid of kmap_to_page().  I
would really like to get moving on that to avoid any further issues with the
kmap conversions.

But if folks feel strongly enough about removing that flag I can certainly try
to do so.

Ira

> Cheers,
> Jens
> 
> >
> >                  Linus


  reply	other threads:[~2022-12-16  0:41 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-02  0:23 [PATCH 0/4] Remove get_kernel_pages() ira.weiny
2022-10-02  0:23 ` [PATCH 1/4] highmem: Enhance is_kmap_addr() to check kmap_local_page() mappings ira.weiny
2022-10-02  0:23 ` [PATCH 2/4] tee: Remove vmalloc page support ira.weiny
2022-10-03  6:41   ` Jens Wiklander
2022-10-03  6:57   ` Sumit Garg
2022-10-05  3:28     ` Phil Chang (張世勳)
2022-10-06  6:23       ` Sumit Garg
2022-10-06 18:19         ` Ira Weiny
2022-10-06 18:20         ` Linus Torvalds
2022-10-07  8:12           ` Jens Wiklander
2022-12-16  0:41             ` Ira Weiny [this message]
2022-12-16  5:09               ` Sumit Garg
2022-12-16  8:45                 ` Sumit Garg
2022-12-16  7:06               ` Christoph Hellwig
2022-10-10  7:42           ` Christoph Hellwig
2022-10-10 17:20             ` Linus Torvalds
2022-10-10 17:57               ` Al Viro
2022-10-02  0:23 ` [PATCH 3/4] tee: Remove call to get_kernel_pages() ira.weiny
2022-10-02  0:46   ` Al Viro
2022-10-02  2:30     ` Ira Weiny
2022-10-03  7:17     ` Christoph Hellwig
2022-10-03 15:02       ` Ira Weiny
2022-10-02  0:23 ` [PATCH 4/4] mm: Remove get_kernel_pages() ira.weiny
2022-10-03 20:28   ` John Hubbard
2022-10-03  9:25 ` [PATCH 0/4] " Sumit Garg
2022-10-03 15:22   ` Ira Weiny
2022-10-04  6:32     ` Sumit Garg

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=Y5u+oOLkJs6jehik@iweiny-desk3 \
    --to=ira.weiny@intel.com \
    --cc=Phil.Chang@mediatek.com \
    --cc=akpm@linux-foundation.org \
    --cc=fmdefrancesco@gmail.com \
    --cc=hch@lst.de \
    --cc=jens.wiklander@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=op-tee@lists.trustedfirmware.org \
    --cc=sumit.garg@linaro.org \
    --cc=torvalds@linux-foundation.org \
    --cc=viro@zeniv.linux.org.uk \
    /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