From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2D9ACC4332F for ; Fri, 16 Dec 2022 05:09:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 793B48E0003; Fri, 16 Dec 2022 00:09:58 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 743BE8E0002; Fri, 16 Dec 2022 00:09:58 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 60B5C8E0003; Fri, 16 Dec 2022 00:09:58 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 51A488E0002 for ; Fri, 16 Dec 2022 00:09:58 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 227621A02EF for ; Fri, 16 Dec 2022 05:09:58 +0000 (UTC) X-FDA: 80246992476.08.9E02310 Received: from mail-vk1-f176.google.com (mail-vk1-f176.google.com [209.85.221.176]) by imf26.hostedemail.com (Postfix) with ESMTP id 936EF140009 for ; Fri, 16 Dec 2022 05:09:56 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=linaro.org header.s=google header.b=M1w027DT; dmarc=pass (policy=none) header.from=linaro.org; spf=pass (imf26.hostedemail.com: domain of sumit.garg@linaro.org designates 209.85.221.176 as permitted sender) smtp.mailfrom=sumit.garg@linaro.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1671167396; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Sgu7X5BHX9sTfJbpXF2aHjOSGbnmcd7dkZy4Cb0etJk=; b=j3lwihq/y+Z3/o2c6JbieVJiOzG28VPisI519DJik1Q+8Zq/D37DkKFCgIw9cPSmBvgUfD pxENPexbW1VB3ZukGMWZI3deYoHKXEDxsIkuJJzeKXFtpDat8HrcRhFlWlv3py3BjKK9QD gQVXoT8GYms7hN9APyu8nDEZlZ/kH40= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=linaro.org header.s=google header.b=M1w027DT; dmarc=pass (policy=none) header.from=linaro.org; spf=pass (imf26.hostedemail.com: domain of sumit.garg@linaro.org designates 209.85.221.176 as permitted sender) smtp.mailfrom=sumit.garg@linaro.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1671167396; a=rsa-sha256; cv=none; b=AUHprTcFK6exKMCGyTv6rPCShOok2cJSz5WzlbsovHiqqrfIMZP4e3/tNz74JZAhrnRlIG ECqelwC7vsD41NvCPV19DhPG+IypjnI8WnRE8SIw+TcyuYtzt+rKrC3VFmJEikvnjO0Z4g GJPFlI38shetCKEbKjeKgtRFhEtfrxE= Received: by mail-vk1-f176.google.com with SMTP id l17so662975vkk.3 for ; Thu, 15 Dec 2022 21:09:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=Sgu7X5BHX9sTfJbpXF2aHjOSGbnmcd7dkZy4Cb0etJk=; b=M1w027DTaUSOaUT+L0Q2TD5xvofS9C+uRrhU6fy9jmJTJ5XKICEYETUFU7LCyVvJA6 ZQuO4aVw7Q00TnyOzLx0vBWJhGbWOADFrkWM4miPXND6LquO5OlLRjYgB9RhC7q9MQ/Y EPb7anG9uNw51P/mZVpFfY5s05mI73Aj4v2luZFlLfuGaX1Xk0s/mcP5+XI2tQRd3fKs XdvPXlZll9xO/MZD/p9PJ+vnz+9n/Dpcl3gRe2RHBqLRvtlqKphWHPRO0gHbGYW3updE ZY89H7SFkuoU/pT37Z6+pYgT9jZYsM/7eMqO2DfMAdWtKeoMl8JZ7GY+TWM7qa33AI6H a0mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Sgu7X5BHX9sTfJbpXF2aHjOSGbnmcd7dkZy4Cb0etJk=; b=TMaALpE6qpt4d+mFgmB3xnmMj8Joohv74ZU43qpAdm4+uJV6GjrGRedcsjO52MwwXq jTI5QPYtiQLAGiDgugfht4+IVdYrEFg5791781BPzIqpog+jya1twTKlq4O0vPe3Qztj PoSdOGJAKbB+sQMdC3D1/ygcqfUOj06yxrZ0J2Ar44ixudb2uIyaTtXhl7ILcaftBhLf Ryo7rmq49pCaqReYG2/OHHgeCRVExdUIO3Ej/cth6s/X+JcLBStLcRobEKz6M2w47aR/ FXPX4I8E40tQWHMO+Zi7E15LvWKxhuKlBrko6uLM/YksZE5MdAG0pfe1VftYhhR8AtnU n4Iw== X-Gm-Message-State: ANoB5pkinSDtB+3hLTC6Qr0bqFHL6GDcL1vcjgalzmhI8PdY18imceaW l5qSFiCABASWNra3UlG/CUKi2B+HfQwKBvHWHpJ4eg== X-Google-Smtp-Source: AA0mqf4Tnqsv1nPsCoELHu7nULwdsh55iwL8noXBFP2vaVOSypvSridY498rb7ry9fMro1J8aFbQyed5l/AvCnPCAgg= X-Received: by 2002:a05:6122:41e:b0:3bd:ad7c:b3ec with SMTP id e30-20020a056122041e00b003bdad7cb3ecmr12932777vkd.0.1671167395589; Thu, 15 Dec 2022 21:09:55 -0800 (PST) MIME-Version: 1.0 References: <20221002002326.946620-1-ira.weiny@intel.com> <20221002002326.946620-3-ira.weiny@intel.com> In-Reply-To: From: Sumit Garg Date: Fri, 16 Dec 2022 10:39:44 +0530 Message-ID: Subject: Re: [PATCH 2/4] tee: Remove vmalloc page support To: Ira Weiny Cc: Jens Wiklander , Linus Torvalds , =?UTF-8?B?UGhpbCBDaGFuZyAo5by15LiW5YuzKQ==?= , Andrew Morton , Al Viro , "Fabio M. De Francesco" , Christoph Hellwig , "op-tee@lists.trustedfirmware.org" , "linux-kernel@vger.kernel.org" , "linux-mm@kvack.org" Content-Type: text/plain; charset="UTF-8" X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 936EF140009 X-Stat-Signature: jotbofycpmhsx3c3ho31ohmxku3rgckm X-HE-Tag: 1671167396-213157 X-HE-Meta: U2FsdGVkX19E8+V5rgqwfTFUfrQKp2Nf/t7t5BX7/qEA6Wl1oZURvZRWRjdrxEuyGfP9RD/naqAfffUjcOYJ/pZK2wJ43JSLH1OsmgbzFVDP0xgT2KBd92G9/ZfNJAlCceSx6dwY5SWHeQIqEW6OcrfY7t4YWJC+vdBtWeLoIruOXj6ePxQ2wIGJMCBH20K11Dfurncg8GPcYhru0+IxrteSDsxsVdTcVC31t7NsoroOVb9rsDmY0bJSnzGqRxcJQWLVXtpJgx8NGpCWoP05DRSZnvcqvKzOkXvw4ORhHKVdwYQ/guEwh3IuAz3IvEzTx0WbqLb5ljFjt+LIg5jd+Aer33QUbgBGSWHLK4X9y34aOa8I03SCHzSCWDT/3asaQtNsKsFE77odZtp0JRlitWXJyaEXzjZx5q7TBgl20KALdXlYZBxOp4LmLfc6OJLuCB0/BLA+pYHa+dTuG6E9vqInBdO85K/o2GOo+pL5uUCTJnPBgLpBU8f001ASDFoOphGH8Bo4Mck7vTbVYtzVKXpcLmHzf0+z4LFgiIpsZnbKoP/JUdxI3vDerWkR5177of9NJCW8yvFeKlI2teiV62AbUzQGyqIxi/YfcJiyxzMnlBmN6oKR1VsoO015O9GdXHV658o1qTLw2H5As1s+fvJcXwIETEfsEoebvWB3o99811D1BRzIHdBADlGIgXeC/ThcPSNwqQiZPP7Lpbrj/tXiMkM9fuvhVI5QIRYpqkD1GMxOefKmGCQHlu990/LmhgvjCPbxDxj3wZDW6+2JB6xP9AodUtyNHeX8GpCSynq6n1sW2Uuw9Lb1F9GeKKl3lGJEvm6oH78r/cljcoIbXoI25X1mPjCn0eHnp18gwNp2r+D3+6FdIzD9WmJr8c/d2saPoeDoMS4/p0MhkVdhWILH0uYOIjHOfZdqca1bNjOZ0iDlNG2Ll45sfMwK0XMblpyL3ITtxKhXGVl0LUL u08TGAWs oq4YFQrOED+t3gP80TzPo/S9yA3AOh2AAdLrRbZo3bkbCBqI= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Fri, 16 Dec 2022 at 06:11, Ira Weiny wrote: > > On Fri, Oct 07, 2022 at 10:12:57AM +0200, Jens Wiklander wrote: > > On Thu, Oct 6, 2022 at 8:20 PM Linus Torvalds > > wrote: > > > > > > On Wed, Oct 5, 2022 at 11:24 PM Sumit Garg 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? No, its rather to allow mmap of tee_shm allocated via tee_shm_alloc_user_buf(). Have a look at its user-space usage here [1]. So overall I agree here that we can't get rid of TEE_SHM_USER_MAPPED completely as it has a valid mmap use-case. [1] https://github.com/OP-TEE/optee_client/blob/master/libteec/src/tee_client_api.c#L907 > 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(). > +1 > 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? I can't find a reason/use-case for the TEE subsystem to keep a refcount of memory registered by other kernel drivers like trusted_tee.c. So yes I think it should be safe to directly free that shm via tee_shm_free_kernel(). Also with that we can simplify shm registration by kernel clients via directly passing page pointers to tee_shm_register_kernel_buf() (I would rather rename this API as tee_shm_register_kernel_pages()). -Sumit > > 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