Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1068170ybk; Wed, 13 May 2020 22:42:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxdzwyPyKIPlQhXgOLuXTWmjixDc4NQivaAC0cU/jqLbKqa0ZkcBP4JaQn7YT6ykQS7Sbpk X-Received: by 2002:aa7:c401:: with SMTP id j1mr2456475edq.31.1589434976220; Wed, 13 May 2020 22:42:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589434976; cv=none; d=google.com; s=arc-20160816; b=KgVuB8C7OFsYqPnKrWGK13R5ePHUTM/mu4TnQtp3JUK+EvEYCZfJWCSJpxpICl8Noi UA6LWrnrbgPBK7YwKQ5reelszQdyjeKK0W81EGgsuf7nQMUlFUjmOSm/MsVdaPiPB3ZO XWnX5QYGEXT3GMoTf1MXCOPZde19YH3KD6bmoq+lD1vlsCN/tR78HT6DtkQHy5F/Xc8E sldXgbrp8oCy3EktNwhiK5JK668gVu9VoUWuC5ChAGp0aWyMthwSL/4EbyoYfBQ9mLoK 549k+fQvk0Vz7AXrWk93zlwEV1Ukq01j9SYJBdTXB662QJWH21DU2qGxgtrF5kQ99Hr2 3UPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=cYvOOmKt6CqklOdp6kTHUSl02OGvdRFZjOL384iDoRM=; b=XBq7NLO+/2IIONLWQWIsi1NJu5BVK8oGb+Pm0DX37zZkiGnvWggVVpyy7sjdu7TiUk g3ji90KpQTgfZmp+7uIxCmf15pCjMC8Ya18q99GJou+SKUA16fiT2q9Jbnpiy5njNc6c 9xSbzoJ7QJkpiseqq+FE9f3bZ2HwK85tqz+2irjMHHGV2eLAO2xgcIUedfjUU0mc6USb dHXBYzy5OqQprgVXCqSuSbGwaJWCZcM0mxQXtyUyF42nGursPlBzfpCv8z7CMGN3XZtm hRdIHQJx1K12ccv77fJjRY5UU65CLBVQIJDRS3Ipg7S0Sp8PYVy6lItehlhvSwsDyxwh 6MNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ol61+9Lb; 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 du1si1441531ejc.474.2020.05.13.22.42.33; Wed, 13 May 2020 22:42:56 -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=ol61+9Lb; 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 S1726125AbgENFjA (ORCPT + 99 others); Thu, 14 May 2020 01:39:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726122AbgENFi6 (ORCPT ); Thu, 14 May 2020 01:38:58 -0400 Received: from mail-lf1-x143.google.com (mail-lf1-x143.google.com [IPv6:2a00:1450:4864:20::143]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB13AC061A0C for ; Wed, 13 May 2020 22:38:56 -0700 (PDT) Received: by mail-lf1-x143.google.com with SMTP id 188so1487536lfa.10 for ; Wed, 13 May 2020 22:38:56 -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=cYvOOmKt6CqklOdp6kTHUSl02OGvdRFZjOL384iDoRM=; b=ol61+9LbEU7e8ijqyRqzUAIXynlhyJzhn/SkOgfM4ArdMEfcX7r4ihczbl64mYkMKF vvh85KomqcXA9IeSCihweH7ET/JVCQwEY2fPyCuvakqDemSWoX3wBLhD0EMnZ8xRGr+7 RXX/B0DalcH82UeNskfR9FshI39wMZMtVqGfkrvKQGhyJM04gaQpePcqNSiW7lSlTmQ+ xrg5vjYXadAv7TA5RBVn449jPcgXVdwXAMkIwPnSfd6SFcb6jmDZP1I4C9BmWIqsa2Wb zqhgD07r2ni5fkODZE/yaWepJs7I2r0YleKbY+vbTaPYzHmzD8Po2oc2rApl0woJZSi+ HCfQ== 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=cYvOOmKt6CqklOdp6kTHUSl02OGvdRFZjOL384iDoRM=; b=RTTC8YHSt7yHs01rgIRad3hnqFesqNMVS4gelO4ek/HjhwVyyjQ0bt/dAw6bZ5jMK9 MODJ105Vrw5UcqeZ7ONFgVFAtmCwV7AF9UIf+YvSWyajGrjdVH8mwaRi5ktxrAEnvxOs 0Q+FuuaHSMIaqd33uRmV1z7lzbvLjlAo+vqgV+cZYWw8pUIFkQ11i55wqhEVp8Hc1K6r r+dBIRxtUbCXWAQgtiOkNyD50sKwdAbePOG5lPkJkwvBBE7MzthD5wWTWKUvWSkMLnVq T4ouTOkuZUoky/EGCVS8flZChcX/rUk2KBMNONHt/fJL38Zfc8iP7rmqvWk6o3klvyrV 2ieg== X-Gm-Message-State: AOAM532YvNlgejTSlEI+5R8+NKZWRC+/JLJ+5/8eEFsQUmvSYGjvAt0j O6+pHz3P7r5e3vT6tX0jYxGhJaNgE0N39V7xmf1kOA== X-Received: by 2002:ac2:4945:: with SMTP id o5mr2000757lfi.21.1589434735336; Wed, 13 May 2020 22:38:55 -0700 (PDT) MIME-Version: 1.0 References: <20200513003430.651232-1-vlad.babchuk@gmail.com> <20200513003625.651340-1-vlad.babchuk@gmail.com> In-Reply-To: From: Sumit Garg Date: Thu, 14 May 2020 11:08:43 +0530 Message-ID: Subject: Re: [PATCH] optee: don't fail on unsuccessful device enumeration To: Volodymyr Babchuk Cc: Jens Wiklander , open list , "tee-dev @ lists . linaro . org" , Jerome Forissier Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Volodymyr, On Thu, 14 May 2020 at 06:48, Volodymyr Babchuk wrote: > > Hi Sumit, > > On Wed, 13 May 2020 at 11:24, Sumit Garg wrote: > > > > Hi Volodymyr, > > > > On Wed, 13 May 2020 at 13:30, Jens Wiklander wrote: > > > > > > Hi Volodymyr, > > > > > > On Wed, May 13, 2020 at 2:36 AM Volodymyr Babchuk > > > wrote: > > > > > > > > optee_enumerate_devices() can fail for multiple of reasons. For > > > > example, I encountered issue when Xen OP-TEE mediator NACKed > > > > PTA_CMD_GET_DEVICES call. > > > > Could you share a detailed description of the issue which you are > > facing? optee_enumerate_devices() is a simple invocation of pseudo TA > > and cases where OP-TEE doesn't provide corresponding pseudo TA are > > handled very well. > > Yes, I did some research and looks like issue is broader, than I > expected. It is my fault, that I wasn't paying attention to the tee > client support in the kernel. Basically, it is incompatible with the > virtualization feature. You see, the main issue with virtual machines > is the second stage MMU. Intermediate physical address, that appear to > be contiguous for the kernel may be not contiguous in the real > physical memory due to 2nd stage MMU mappings. This is the reason I > introduced OPTEE_MSG_ATTR_NONCONTIG in the kernel driver. > > But, looks like kernel-side optee client does not use this feature. It > tries to provide SHM buffer as a simple contiguous span of memory. Xen > blocks calls with OPTEE_MSG_ATTR_TYPE_TMEM_* but without > OPTEE_MSG_ATTR_NONCONTIG , because it can't translate IPAs to PAs for > such buffers. This is why call to PTA_CMD_GET_DEVICES fails. > > Valid fix would be to use OPTEE_MSG_ATTR_NONCONTIG whenever possible. > Thanks for the detailed analysis. It looks like you are missing the following fix patch in your tree which basically fixed broken tee_shm_alloc() in case dynamic shared memory is enabled (IIRC virtualization only supports dynamic shared memory). commit a249dd200d03791cab23e47571f3e13d9c72af6c Author: Sumit Garg Date: Fri Nov 8 16:57:14 2019 +0530 tee: optee: Fix dynamic shm pool allocations In case of dynamic shared memory pool, kernel memory allocated using dmabuf_mgr pool needs to be registered with OP-TEE prior to its usage during optee_open_session() or optee_invoke_func(). So fix dmabuf_mgr pool allocations via an additional call to optee_shm_register(). Also, allow kernel pages to be registered as shared memory with OP-TEE. Fixes: 9733b072a12a ("optee: allow to work without static shared memory") Signed-off-by: Sumit Garg Signed-off-by: Jens Wiklander After this fix, your issue should be resolved as it uses OPTEE_MSG_ATTR_NONCONTIG attribute for kernel memory allocated via tee_shm_alloc(). > > > > > > This should not result in driver > > > > initialization error because this is an optional feature. > > > > I wouldn't call it an optional feature as there might be real kernel > > drivers dependent on this enumeration. Also, it is a simple example to > > self test OP-TEE functionality too. So I am not sure how much > > functional OP-TEE would be if this basic TA invocation fails. > > Well, it fixed case when Xen is involved. I think, this is valid > combination, when platform have the newest OP-TEE, but slightly older > kernel. So, imagine that OP-TEE provides PTA_CMD_GET_DEVICES, but > kernel can't use because it uses plain TMEM arguments,which are not > supported in virtualized environment. > > If there are kernel drivers, that depend on this PTA, they would not > work in any case. But at least userspace clients still be able to use > OP-TEE. This is why I call this feature "optional". As you can see above, tee_shm_alloc() being broken in your case was detected via this simple pseudo TA invocation. So IMO, it would be better to keep the existing behaviour as it provides a kind of basic OP-TEE driver runtime self test too. Also, I think it would be a better user experience to have every OP-TEE interface working rather than a partially broken interface. -Sumit > > -- > WBR Volodymyr Babchuk aka lorc [+380976646013] > mailto: vlad.babchuk@gmail.com