Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp2686246ybk; Mon, 18 May 2020 05:37:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyxQjZ7VCTa8WkmSH4JfQ6PiBq0qAWc/e7zI1L8TsiRtV4mGG84BJ2ZkW7659f/ikVjrWTK X-Received: by 2002:a50:cd57:: with SMTP id d23mr13561513edj.181.1589805430764; Mon, 18 May 2020 05:37:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589805430; cv=none; d=google.com; s=arc-20160816; b=FXYaa74opnlvfatcGSm/aukiL34rGflnZCukUQwjG8iJrMMvdIfIh9+okBWAhjALOP v42Y8Ac+wvODXCfrCBRuja3jasU0x1wQ3QtoDC/0ubHdhG0bca2WbORkI1dBowhN0SQs Ph2ctSY8Oiv/MuY2vRAk3FiekNftPTz+5qt74E7EK/i0CMfXnYN1b9PL4Hk2Fo69ztpI pQydPXy/gK3SJhtIYjSlQFkdFyb+cPKZvdlkcsliImfW+C4UelgljTOkTLgBLb/v57QL V+8OFfBhnt0ix5pWFweAQKCr74RSgxW84zKX2UEojg9kyrYe5mbSQZA/PAunJeyMpK8V cTVQ== 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=eSPwRcqIEUzwnsX+6a1/rCx7QnyIswo4ef56fDP+XJQ=; b=YwXU6BGd0j9153IINhzn/+5ampw7YAx7+XnHq+hDYv7ONrHu0LB2d6gmoi3zclwC2U kuf04+xIAttx51go5IOXM4BirpGireB1PVloy4Dy8AkZ/PdRP8jtxkrsdIIKqj9+XCgu j+9plkfimS2BKHT80mAmNxP2l6a7mRBUMiWj4f50u7mc2V1xrPf1pg3M+1alEdMlMnby aRkgZthSNJMpUmTjxuO0FNGMtF8FfLS6s2Z9HqOzzVoDvglAjnre8sBbhlu0kVdwqG8s reLTXG/qcEBR96WVBc/f8HWbg/hP9sLknptAnObTPoeItqq2Qex8+tcyodgrKhdDl31D 5AoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=K5o1+Kcx; 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 4si6858100edh.424.2020.05.18.05.36.47; Mon, 18 May 2020 05:37:10 -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=K5o1+Kcx; 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 S1727801AbgERMer (ORCPT + 99 others); Mon, 18 May 2020 08:34:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726797AbgERMer (ORCPT ); Mon, 18 May 2020 08:34:47 -0400 Received: from mail-lf1-x142.google.com (mail-lf1-x142.google.com [IPv6:2a00:1450:4864:20::142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DFC28C061A0C for ; Mon, 18 May 2020 05:34:45 -0700 (PDT) Received: by mail-lf1-x142.google.com with SMTP id a4so7870824lfh.12 for ; Mon, 18 May 2020 05:34:45 -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=eSPwRcqIEUzwnsX+6a1/rCx7QnyIswo4ef56fDP+XJQ=; b=K5o1+KcxWilzNS0/SHukgu2PTQNU5j8LR+M3EH4/fEeODROqMFQoC76wWoJBmhBpXG RCBTfGFDxGdjpmagjAIg+equaPzVEMYnkG/2633Hx6g2L5TUtj23TsKnKhiXDBNo75Tl 4y+1kjuBhiFaLihUT6IFqaPVvWs/atx4NBW6DlS7TtduLkn8HFxbYyVOPHxSUgTnunJi k2N5tNWUA5wG7YMcMXiuAeEotdrDot3DhcXCUtNPk3MYOS1OMcO12tGm2Vx7l3ySESB7 /nKzRc9AUCrVtwxKkhfNgr3CffJDXT/jfqMuPdup0aTR5kMK7z6oUTP8dUrqQTv2N1/t yiUg== 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=eSPwRcqIEUzwnsX+6a1/rCx7QnyIswo4ef56fDP+XJQ=; b=WBS3X+pkdxZDBu0/nkZimGfmUyoQXF3RdJjnMxibNFbkRZ3Q+snUXplz7ZVuV2KpuX 7pAu7r39nXYBH6kcTEbekeuOMiYeUNntU6WJuaEcB+RL1AW/GHRtURJqERMTjwZLzDp6 wPZf/oKsfjacziTaPzDgNg7NOhzkjU5eRQeSVZn/aHRvrnmG2Ew0TZagqIgmQszXZmZT UmTg3pafRJJboWQH6N1f8P1XDf31Lhm4WA62K3Jp5jxxE+TEoh9GSLOJmYrh8zvqOQ5e rxO/dRhT05RgnISS7haOD8uRfSi2fFvOiV8NaXvVRvtINiqAOwgy5atsGY/Zl1ZPPd9i RYwg== X-Gm-Message-State: AOAM532FAO9xXq9/B/q7CFCoRL6kQh1pEletUxphFrhSdeSi5FSQB7VB eY5ZywJAh5RRCaa2yA2SZXPFPkPEL/rR48No4OrxOQ== X-Received: by 2002:ac2:560f:: with SMTP id v15mr6415706lfd.160.1589805284317; Mon, 18 May 2020 05:34:44 -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: Mon, 18 May 2020 18:04:32 +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 Mon, 18 May 2020 at 15:57, Volodymyr Babchuk wrote: > > Hi Sumit, > > On Fri, 15 May 2020 at 07:55, Sumit Garg wrote: > > > > Hi Volodymyr, > > > > On Fri, 15 May 2020 at 06:32, Volodymyr Babchuk wrote: > > > > > > Hi Sumit, > > > > > > On Thu, 14 May 2020 at 08:38, Sumit Garg wrote: > > > > > > > > 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 > > > > > > Actually, I have this patch in my tree. So, it does not fixes the > > > issue. Which is weird, actually. I'm planning to look deeper into > > > this. > > > > AFAICT, the only difference here is that it's the kernel memory > > registered rather than user-space memory. But I am not very conversant > > with the Xen environment. So I hope you will be able to find the root > > cause as to why Xen is blocking this invocation. > > Yes. I have found issue in Xen mediator code. It didn't allowed TMEM > with NULL buf_ptr and without ATTR_NONCONTIG flag. This is clearly > a bug and I already sent the patch to Xen ML. > Glad to hear that you were able to find the bug and fix it. BTW, I guess the reason you didn't notice this bug in user-space (xtest 1025) is due to missing kernel patch [1] (not yet in upstream) from your kernel tree. [1] https://github.com/linaro-swg/linux/commit/1149e7d06a009e5dacf6aaa29bd087da64bfbed2 -Sumit > -- > WBR Volodymyr Babchuk aka lorc [+380976646013] > mailto: vlad.babchuk@gmail.com