Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp467193pxj; Thu, 10 Jun 2021 05:20:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzkzY+OU1gQw8Nh2d4AgFFD+DlJ/vBlI9q5th2prbEXOhpEAwLdAyFUn2QeVKLNIUK7YR6x X-Received: by 2002:a17:907:62a7:: with SMTP id nd39mr4273058ejc.502.1623327600211; Thu, 10 Jun 2021 05:20:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623327600; cv=none; d=google.com; s=arc-20160816; b=kmGx7BbkUB5hj3/dkezIFKf5sUser6E39kTlDulgHuZU9LnmquciuQ7kIYDR7oL7LK sCZ3udj2ka0GPnqz7oulOoJksEJy6GMZkzVjQ/7kydBdWX1LZK2y97BdvyBRYVEIKj85 PiIC6/+Gh0Ci/rD7x7IH2V+UYyLLWRuczAnc5QNwR5RleNQPyH61chQg4ouESpo8WnD/ G7kpB0XuWgjoH6BeIufP0Gg1ySQMdBaxHvyYPbAFcvzgq2josfzJmjSqQ5YnyBMPztqj v5fsycIpSOYND4lEpjgiQYEmW78nuIkyTJ5pDVAyJTemOL9gf0SWFXT4VEKcAhhn739g EeNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=BEHGV38tYEPn87F7ElGb2eufRjx+4X3yWFCCfxgeqDk=; b=y97jdkW8eXluNAtRmDcQpc6pJoirMX0/inR5+1mIYKApBtw7PUx/qYeVtIe2bj9pYy Z0SdSyBGMqcQZ+KcK7pZf1fiMWiv7ML5PouVmiOqPkj5G8OKoBv0ceoB87atQaZmg6rU YBRGMBJTt4b2I2iGndaag5IHYhSw0iX1h1mL5Lt2GFgJubYvo+vBIRGjczdy4MUvgHG/ 6xA3CkREL9g1xWQszKonNUH0pUOk0PLGy1g/iJ40+2JuEcr7eqEu6EHdT4bYFQErEP+O Ny+Wl9c0y7zdu+HrnpLEHzFJlsasW745edSJrkjJ5L4qtHpGBTYHdAY70wZN0gSHQAQ0 A5mg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Ln6RW2k/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hq27si2195575ejc.34.2021.06.10.05.19.36; Thu, 10 Jun 2021 05:20:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Ln6RW2k/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230130AbhFJMSS (ORCPT + 99 others); Thu, 10 Jun 2021 08:18:18 -0400 Received: from mail-lf1-f52.google.com ([209.85.167.52]:38588 "EHLO mail-lf1-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230343AbhFJMSS (ORCPT ); Thu, 10 Jun 2021 08:18:18 -0400 Received: by mail-lf1-f52.google.com with SMTP id r5so2904720lfr.5 for ; Thu, 10 Jun 2021 05:16:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=BEHGV38tYEPn87F7ElGb2eufRjx+4X3yWFCCfxgeqDk=; b=Ln6RW2k/ezYgUxzfevzOB7aA62Gl4OBWbiCqXt7hsqErTgvEh4iYeu8GBZbc5xLP6W xW2NA29qk/4xxoHrXYO9DH/A8JKq1XANimnfGoicLulDRjN7ZD5gBPiZ/LtF0L6t7J+r J6VT/I9oxzSCnmzVM/dZWH1CHRQxRZBS7gcF4EPn+OGtzngGBFvJdJB+YUJ1xZZLSB/a pXa9ju508CJ/8yjqly2u5tGrLQRcvfRWY8lIf7TZpzIWiu/B/c8i/5q/9oJNWsQSUWmW azX1kTMRL/AdnvdLCmoeA1fUZYlJ1yydIoL8dc5r3IuI3dZGrRYGpHIQSLGIdOp77cwy ZkEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=BEHGV38tYEPn87F7ElGb2eufRjx+4X3yWFCCfxgeqDk=; b=oAQ1BrgzIyhX4pa36cHorRbv6AiFLAr5zmvjlXNKgcMOl4si2N4ph96Hd9Tit2UjeM QQvjt7YL4VhBqcfz1XeXPW2L5s19xvn0t0sA7TBF7hm3DcwwWUvoQzjPjhWwFJ420b/L KF8UzCb9xNVUWOuH0U1S11cYpcekP81S4t418fchOesO8D15lR8qfKKHapvp0jj+nekg SQu9+Osh9Zher02iybzdBScMB8/m0UnBuzntFRwWfGLUUai2PM9/jpyeQhTQJ6G70gHh epbqzLCYHOU3xWHMXkHd3IfJcca/2UE5m3GJPvuDFVDA0FCRHOWsgxQD6E1RObqjYZ6A 1sBg== X-Gm-Message-State: AOAM531MMjOcYJFRXe1CZyjldlRwuY30zezz28rFqbf9VQ2mwTB+qGNP YF4aCsnvsR47wdDihF4+NIEmNMzKQIr6V4Sr654VMA== X-Received: by 2002:a19:7d89:: with SMTP id y131mr1714908lfc.108.1623327307719; Thu, 10 Jun 2021 05:15:07 -0700 (PDT) MIME-Version: 1.0 References: <20210609002326.210024-1-tyhicks@linux.microsoft.com> <20210609002326.210024-6-tyhicks@linux.microsoft.com> <20210609054621.GB4910@sequoia> <20210610071812.GA2753553@jade> In-Reply-To: <20210610071812.GA2753553@jade> From: Sumit Garg Date: Thu, 10 Jun 2021 17:44:56 +0530 Message-ID: Subject: Re: [PATCH v3 5/7] tee: Support shm registration without dma-buf backing To: Jens Wiklander Cc: Tyler Hicks , Rijo-john.Thomas@amd.com, Allen Pais , Peter Huewe , Jarkko Sakkinen , Jason Gunthorpe , Vikas Gupta , Thirupathaiah Annapureddy , Pavel Tatashin , =?UTF-8?B?UmFmYcWCIE1pxYJlY2tp?= , op-tee@lists.trustedfirmware.org, linux-integrity , bcm-kernel-feedback-list@broadcom.com, linux-mips@vger.kernel.org, Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Jens, On Thu, 10 Jun 2021 at 12:48, Jens Wiklander wrote: > > On Wed, Jun 09, 2021 at 04:22:49PM +0530, Sumit Garg wrote: > > + Rijo > > > > On Wed, 9 Jun 2021 at 11:16, Tyler Hicks wrote: > [snip] > > > > > - tee_shm_alloc() performs allocations using contiguous pages > > > from alloc_pages() while tee_shm_register() performs non-contiguous > > > allocations with kcalloc(). I suspect this would be fine but I don't > > > know the secure world side of these things well enough to assess the > > > risk involved with such a change on the kernel side. > > > > > > > I don't think that would make any difference. > > Agree. > > > > > > I should have mentioned this in the cover letter but my hope was that > > > these minimal changes would be accepted and then additional work could > > > be done to merge tee_shm_alloc() and tee_shm_register() in a way that > > > would allow the caller to request contiguous or non-contiguous pages, > > > fix up the additional issues mentioned above, and then adjust the > > > call sites in ftpm and tee_bnxt_fw as appropriate. > > > > > > I think that's a bigger set of changes because there are several things > > > that still confuse/concern me: > > > > > > - Why does tee_shm_alloc() use TEE_SHM_MAPPED while tee_shm_register() > > > uses TEE_SHM_KERNEL_MAPPED or TEE_SHM_USER_MAPPED? Why do all three > > > exist? > > > > AFAIK, its due the the inherent nature of tee_shm_alloc() and > > tee_shm_register() where tee_shm_alloc() doesn't need to know whether > > its a kernel or user-space memory since it is the one that allocates > > whereas tee_shm_register() need to know that since it has to register > > pre-allocated client memory. > > > > > - Why does tee_shm_register() unconditionally use non-contiguous > > > allocations without ever taking into account whether or not > > > OPTEE_SMC_SEC_CAP_DYNAMIC_SHM was set? It sounds like that's required > > > from my reading of https://optee.readthedocs.io/en/latest/architecture/core.html#noncontiguous-shared-buffers. > > > > Yeah, but do we have platforms in OP-TEE that don't support dynamic > > shared memory? I guess it has become the sane default which is a > > mandatory requirement when it comes to OP-TEE driver in u-boot. > > > > > - Why is TEE_SHM_REGISTER implemented at the TEE driver level when it is > > > specific to OP-TEE? How to better abstract that away? > > > > > > > I would like you to go through Section "3.2.4. Shared Memory" in TEE > > Client API Specification. There are two standard ways for shared > > memory approach with TEE: > > > > 1. A Shared Memory block can either be existing Client Application > > memory (kernel driver in our case) which is subsequently registered > > with the TEE Client API (using tee_shm_register() in our case). > > > > 2. Or memory which is allocated on behalf of the Client Application > > using the TEE > > Client API (using tee_shm_alloc() in our case). > > > > > Let me know if you agree with the more minimal approach that I took for > > > these bug fix series or still feel like tee_shm_register() should be > > > fixed up so that it is usable. Thanks! > > > > From drivers perspective I think the change should be: > > > > tee_shm_alloc() > > > > to > > > > kcalloc() > > tee_shm_register() > > I had another approach in mind in "[PATCH 0/7] tee: shared memory updates", > https://lore.kernel.org/lkml/20210609102324.2222332-1-jens.wiklander@linaro.org/ > > The flags needed by tee_shm_alloc() and tee_shm_register() aren't > very intuitive and in fact only accept quite few combinations. So my > idea was to hide those flags from callers outside of the TEE subsystem > with tee_shm_alloc_kernel_buf(). > That looks like a good idea to hide flags from users. BTW, my only objection earlier with Tyler's and your patch-set is the usage of TEE_SHM_REGISTER flag in generic TEE methods: tee_shm_alloc*. AFAIU, the only reason for such an additional flag is in case of OP-TEE only because the OP-TEE driver could implement allocated shared memory via re-using dynamic shared memory approach as well. And that additional flag is only needed to differentiate that OP-TEE driver's private memory shouldn't be registered with OP-TEE. If this understanding is correct then we should introduce a separate flag as TEE_SHM_PRIV that should only be set inside tee_shm_alloc_anon_kernel_buf(). As otherwise passing TEE_SHM_REGISTER flag for shared memory alloc API for other TEEs like AMD-TEE etc. would be useless. > The approach with tee_shm_register() you suggest above has the drawback > that the TEE driver is forced to be able to handle any kernel memory. That's the value-add in the problem that Tyler is trying to resolve that driver should be able to free up the memory as needed as a private buffer. > This is OK with OP-TEE and dynamic shared memory enabled, but there are > platforms where dynamic shared memory isn't enabled. In those case must > the memory be allocated from a special pool. Is there any limitation for those platforms to not support dynamic shared memory in OP-TEE? If there isn't then we should able to handle this via match for TEE_GEN_CAP_REG_MEM in the ftpm_tee_match() and optee_ctx_match() APIs. > > Do you see any problem with instead replacing tee_shm_alloc() > with tee_shm_alloc_kernel_buf()? I don't see any problems apart from one mentioned above. -Sumit > > Cheers, > Jens