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 lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D0B6BC3A5A7 for ; Thu, 8 Dec 2022 13:32:27 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.457153.715015 (Exim 4.92) (envelope-from ) id 1p3H0X-0003uE-PV; Thu, 08 Dec 2022 13:32:13 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 457153.715015; Thu, 08 Dec 2022 13:32:13 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p3H0X-0003u7-Ky; Thu, 08 Dec 2022 13:32:13 +0000 Received: by outflank-mailman (input) for mailman id 457153; Thu, 08 Dec 2022 13:32:12 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p3H0W-0003tz-TU for xen-devel@lists.xenproject.org; Thu, 08 Dec 2022 13:32:12 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p3H0T-00018k-DZ; Thu, 08 Dec 2022 13:32:09 +0000 Received: from 54-240-197-239.amazon.com ([54.240.197.239] helo=[192.168.4.36]) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1p3H0T-0000Td-7i; Thu, 08 Dec 2022 13:32:09 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:Content-Type:In-Reply-To:From: References:Cc:To:Subject:MIME-Version:Date:Message-ID; bh=hU/8o5abnCvdKS8tUtfEjTj+WbOaKMJpdo+9jkN2Y4o=; b=25CYbO/QB/v3eAnmdnq2q3H/OM IGb0aMoJuDAJKC3+Fe0p8HKxiWFdXacEHoGDiNCdynfYiytAFQnKI8Qv9EOP2YEDsLJr/9EyelaD6 sDOKJE3Wa+1JJPIX4RRUENDsz9O3bEFcU/baTM+R+qmYuJlj1IP/rzVE3j8SdQbrm60A=; Message-ID: <79d2a073-ddcf-8a1d-3415-e73d9162b3a5@xen.org> Date: Thu, 8 Dec 2022 13:32:07 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.5.1 Subject: Re: [BUG]SMMU-V3 queue need no-cache memory Content-Language: en-US To: sisyphean , Stefano Stabellini , Rahul Singh Cc: "xen-devel@lists.xenproject.org" References: <75D89B2C-BBE4-419A-80B7-FEE39445ABB2@arm.com> <5f850be6-a256-86fa-7c37-1964442bc36c@zlw.email> From: Julien Grall In-Reply-To: <5f850be6-a256-86fa-7c37-1964442bc36c@zlw.email> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hi, On 08/12/2022 13:27, sisyphean wrote: > > 在 2022/12/8 21:21, Julien Grall 写道: >> Hi, >> >> On 08/12/2022 03:22, sisyphean wrote: >>> 在 2022/12/8 06:22, Stefano Stabellini 写道: >>> >>>> On Wed, 7 Dec 2022, Julien Grall wrote: >>>>> Hi, >>>>> >>>>> I only noticed this e-mail because I was skimming xen-devel. If you >>>>> want to >>>>> get our attention, then I would suggest to CC both of us because I >>>>> (and I >>>>> guess Stefano) have filter rules so those e-mails land directly in >>>>> my inbox. >>>>> >>>>> On 07/12/2022 10:24, Rahul Singh wrote: >>>>>>> On 7 Dec 2022, at 2:04 am, sisyphean wrote: >>>>>>> >>>>>>> Hi, >>>>>>> >>>>>>>       I try to run XEN on my ARM board(Sorry, for some commercial >>>>>>> reasons, >>>>>>> I can't tell you >>>>>>>       on which platform I run XEN)  and enable SMMU-V3, but all >>>>>>> cmds in >>>>>>> cmdq failed when XEN started. >>>>>>> >>>>>>>       After using the debugger to track debugging, the reason for >>>>>>> this >>>>>>> problem is that >>>>>>>       the queue in the smmu-v3 driver is not no-cache, so after the >>>>>>> function arm_smmu_cmdq_build_cmd >>>>>>>       is executed, the cmd is still in cache.Therefore, the SMMU-V3 >>>>>>> hardware cannot obtain the correct cmd >>>>>>>       from the memory for execution. >>>>>> Yes you are right as of now we are allocating the memory for >>>>>> cmdqueue via >>>>>> _xzalloc() which is cached >>>>>> memory because of that you are observing the issue. We have tested >>>>>> the Xen >>>>>> SMMUv3 driver on SOC >>>>>> where SMMUv3 HW is in the coherency domain, and because of that we >>>>>> have not >>>>>> encountered this issue. >>>>>> >>>>>> I think In your case SMMUv3 HW is not in the coherency domain. Please >>>>>> confirm from your side if the >>>>>> "dma-coherent” property is not set in DT. >>>>>> >>>>>> I think there is no function available as of now to request Xen to >>>>>> allocate >>>>>> memory that is not cached. >>>>> You are correct. >>>>> >>>>>> @Julien and @Stefano do you have any suggestion on how we can >>>>>> request memory >>>>>> from Xen that is not >>>>>> cached something like dma_alloc_coherent() in Linux. >>>>> At the moment all the RAM is mapped cacheable in Xen. So it will >>>>> require some >>>>> work to have some memory uncacheable. >>>>> >>>>> There are two options: >>>>>   1) Allocate a pool of memory at boot time that will be mapped >>>>> with different >>>>> memory attribute. This means we would need a separate pool and the >>>>> user will >>>>> have to size it. >>>>>   2) Modify after the allocation the caching attribute in the >>>>> memory and then >>>>> revert back after freeing. The cons is we would end up to shatter >>>>> superpage. >>>>> We also can't re-create superpage (yet), but that might be fine if >>>>> the memory >>>>> is never freed. >>>>> >>>>> Option two would probably the best. But before going that route I >>>>> have one >>>>> question... >>>>> >>>>>> The temporary solution I use is to execute function clean_dcache >>>>>> every >>>>>> time cmd is copied to cmdq in function queue_write. But it is obvious >>>>>> that this will seriously affect the efficiency. >>>>> I agree you will see some performance impact in micro-benchmark. >>>>> But I am not >>>>> sure about normal use-cases. How often do you expect the command >>>>> queue to be >>>>> used? >>>> That is a good question. But even for the micro-benchmark, is the >>>> difference significant? >>>> >>>> My gut feeling (to be discussed and confirmed) is that for this >>>> use-case >>>> it might not be worth to do option 1) or option 2) above. Clean_dcache >>>> as needed might be good enough? >>>> >>>> >>>>> Also, I am a bit surprised you are seing issue with the command >>>>> queue but not >>>>> with the stage-2 page-tables. Does your SMMU support coherent walk >>>>> but cannot >>>>> snoop for the command queue? >>> >>> Hi, >>> >>> I'm sorry that my statement made you misunderstand. I haven't >>> conducted micro-benchmark yet. >>> >>> I found this problem because "CMD_SYNC timeout" was frequently >>> prompted when initializing >>> SMMUv3 during XEN startup. >>> >>> As for the usage frequency of the command queue, I'm trying to >>> passthrough PCIE devices to the DomU. >>> According to my understanding, all operations on the device will be >>> performed through SMMUv3 after >>> the device passesthrough? Therefore, queues will be used frequently. >> "all operations on the device" is a bit vague. From what Rahul just >> wrote this is a command queue is for controlling the SMMU (e.g. assign >> the device, flush the TLBs...). Anything related to the access (e.g. >> accessing the BAR, configuration space...) are not going through it. >> >> Cheers, >> > So does this mean that operations on smmu queues are not frequent? There > are still some problems with PCIE device passthrough. > I will conduct some benchmark tests after completing PCIE device > passthrough. Are there any test cases for my reference? See my reply to Rahul. I have provided some ideas how to benchmark it. Cheers, -- Julien Grall