Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp863492rdb; Fri, 20 Oct 2023 01:17:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFXo2HOIhTP+VpoaC18mbH/2H7poYfnhFfiX9jeuP61oHWpBgbpJUNZkiwGiUJhPYd6LCDO X-Received: by 2002:a17:90a:e409:b0:27d:1126:1ff6 with SMTP id hv9-20020a17090ae40900b0027d11261ff6mr6492765pjb.8.1697789853440; Fri, 20 Oct 2023 01:17:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697789853; cv=none; d=google.com; s=arc-20160816; b=PUe2GW33sUaVObp6hDUesY9Ptf5ZrIslZzt5v2ThrNVdJ+pYqPouuj0Ys5tuqnaaTT Dp+m5W44SdGPojMLX2zdjHv+HarNu+ce4v/KWLLTzgi2vgRZkZAz8oZFOYCUCttrXG1K +oQeangRGNJPhon3YRO+K4LfznYjGvBslD9emqPe5M0BMNg9Vmqsv0s4sM35ZxbiUw6a pw9QWE/ifbaVns7bnT+QsnVSrfu7vvUNeipzqfRMgo96559k0fSIT1WEAkupHLfcBpUQ LSpJ7e+aS2LKjW82j6vVl2qqPULUxtlTXGX0iOlpzUezoN7pV1uzZJ+bYHDBs+WrGGWQ TAiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:cms-type:content-transfer-encoding :in-reply-to:from:cc:to:content-language:subject:user-agent :mime-version:date:message-id:dkim-signature:dkim-filter; bh=wzSstyDCnGvRKqkLCoU0yVZL9DxpC55aNBQ7a5fvoqQ=; fh=bs1o5ot74HzQP4t7ocQ4hZL3xD6qf4fgjFAfvlJFlWI=; b=JIRyafr7FcGmLcSyMYMAgEQO4wnd9QPD34LxHcImq8C1HvisLKJJ+dNgTOd7PlkMEd yWYWiKWfcF7SLtekKumT+0AG++lnEMnvbV10Kksi9ctdoxqrk+8CjL5puqWGbnIFQ8vU n9puMod+o8hBMebF6+9j7fisbeB2Q+BhwImBCxXyTTtslw7s/m8VUteHxPzHbomVJf0a 8vvxvdWIn9m+EePD9jjlisjIyBTHdj9481FNmfpOdRRob6EeBkE06kvgMwPKGl+wtIB5 NOetW/Yh7sxeyi+8MSu6uv1h4LUqPz+GUNnFe7L8QakWYftMGLVkBxZp2mveDSSOxUXG bixA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=r3hkpYaC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id s17-20020a639251000000b005ae99bb5c03si1338485pgn.41.2023.10.20.01.17.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 01:17:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=r3hkpYaC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 4B312804C1B7; Fri, 20 Oct 2023 01:17:01 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233541AbjJTIQ6 (ORCPT + 99 others); Fri, 20 Oct 2023 04:16:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230217AbjJTIQ5 (ORCPT ); Fri, 20 Oct 2023 04:16:57 -0400 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A2C3E8 for ; Fri, 20 Oct 2023 01:16:53 -0700 (PDT) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20231020081649euoutp016f5ca737d7dba5a9747d469300cc17c7~PwtYdmNS90704407044euoutp01S for ; Fri, 20 Oct 2023 08:16:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20231020081649euoutp016f5ca737d7dba5a9747d469300cc17c7~PwtYdmNS90704407044euoutp01S DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1697789809; bh=wzSstyDCnGvRKqkLCoU0yVZL9DxpC55aNBQ7a5fvoqQ=; h=Date:Subject:To:Cc:From:In-Reply-To:References:From; b=r3hkpYaCxPfshPQyMD0xct9u5H7T4muH8haj5P8AFFGq86lG4FuvQxTpjzzl+dfj0 Ifmjtrx95kiM4XvbISEU99xdkRBqI1lczANWz+m80MVrrNdTEnSTX8457cUEJFvmwo GL9ZNTe2etefF5sbM4hSW//NR2W8P9ttc8OOS+nI= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20231020081648eucas1p163b5f631c1f5fdac38d071af52abe179~PwtYCFLf11288412884eucas1p1p; Fri, 20 Oct 2023 08:16:48 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id 69.76.42423.07732356; Fri, 20 Oct 2023 09:16:48 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20231020081648eucas1p17d2572cfca5762d2f5cbc560dd648564~PwtXgMVcS1169311693eucas1p1v; Fri, 20 Oct 2023 08:16:48 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20231020081648eusmtrp25a731dd1b01fccb768dc918808a88fa8~PwtXfVxCq2171621716eusmtrp2d; Fri, 20 Oct 2023 08:16:48 +0000 (GMT) X-AuditID: cbfec7f2-a3bff7000002a5b7-e6-6532377091e2 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 8E.2E.10549.07732356; Fri, 20 Oct 2023 09:16:48 +0100 (BST) Received: from [106.210.134.192] (unknown [106.210.134.192]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20231020081646eusmtip19e42584464e04ee4d77d2df44f266c5b~PwtWMLgPR1066210662eusmtip1h; Fri, 20 Oct 2023 08:16:46 +0000 (GMT) Message-ID: <3515448c-8a4b-4669-9f80-2f55c5100674@samsung.com> Date: Fri, 20 Oct 2023 10:16:46 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v1 1/1] ARM: Select DMA_DIRECT_REMAP to fix restricted DMA Content-Language: en-US To: Christoph Hellwig , Jim Quinlan Cc: Linus Walleij , bcm-kernel-feedback-list@broadcom.com, jim2101024@gmail.com, Russell King , Arnd Bergmann , Geert Uytterhoeven , "Russell King (Oracle)" , Andrew Morton , Jonathan Corbet , Thomas Gleixner , Sebastian Reichel , "Mike Rapoport (IBM)" , Eric DeVolder , Nathan Chancellor , "Kirill A. Shutemov" , Christophe Leroy , "moderated list:ARM PORT" , open list From: Marek Szyprowski In-Reply-To: <20231006074045.GA15303@lst.de> Content-Transfer-Encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA01SbUxbVRj29F5uP0LxtqvryUZCJELCPsqYU49ah4qam2xxW9L9WYxbs14p kxZs18H8mIVsdEM22tJms5SJo+OjIpB2GxT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/78LtN+pa6m+cSizkCtHXMNOLuNWY9WdOZFWEIp/aLTWR2fcP25twNK10 OMFw5YXF55bch3p3XeVE3vzWnXC/bIevEEOfytE2F6uv5W/Tg/7ztfRw7Z20esGRuCXpW+TK 5iXzalyfohyd7vmksMxY++iHTelvwvV3NKja3gtImsF2Opt91zYJraKT3DXX0kpueey/1KB+ Jzaa84Vq0LGPIQ1MhyPUmrfZnfwrfa32cY4SS3FGoqEWc1FxIgBtpaFzuQMAAA== X-CMS-MailID: 20231020081648eucas1p17d2572cfca5762d2f5cbc560dd648564 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20231020081648eucas1p17d2572cfca5762d2f5cbc560dd648564 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20231020081648eucas1p17d2572cfca5762d2f5cbc560dd648564 References: <20230926175208.9298-1-james.quinlan@broadcom.com> <20230926175208.9298-2-james.quinlan@broadcom.com> <20231002061628.GC911@lst.de> <20231006074045.GA15303@lst.de> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Fri, 20 Oct 2023 01:17:01 -0700 (PDT) Dear All, I didn't have enough time to follow the whole discussion, but it looks I can add some comments. On 06.10.2023 09:40, Christoph Hellwig wrote: > On Thu, Oct 05, 2023 at 01:53:33PM -0400, Jim Quinlan wrote: >>> Yes, DMA_DIRECT_REMAP should only be used for platforms using the >>> generic generic remap that plus straight into dma-direct and >>> bypasses arch_dma_alloc. >>> >>> ARM first needs support to directly set the uncached/wc bits on >>> the direct mapping for CMA, which should be fairly simple but require >>> wide spread testing. >>> >>> I'd be happy to work with anyone who wants to look into this. >> I'd like to look into this and help make it work for ARCH=arm but you >> seem to be saying that you also need help from ARM the company? > No, I don't care about companies. I just need someone (singular or > plural) to test a wide range of arm systems. > > Here is my idea for the attack plan: > > As step 1 ignore the whole CMA direct map issue, and just to the > trivial generic dma remap conversion. This should involved: > > - select DMA_DIRECT_REMAP > - provide arch_dma_prep_coherent to flush out all dirty data by > calling __dma_clear_buffer > - remove the existing arch_dma_alloc/arch_dma_free and all their > infrastructure > > With this things should work fine on any system not using CMA This won't be that easy. For historical reasons (performance and limitations of the pre-ARM v7 cores), on the 32bit ARM the whole kernel's direct mapping is done using so called 'sections' (1MiB size afair). Those sections are created in the per-process MMU page tables (there are no separate MMU table for the kernel mappings), so altering those mappings requires updating bits in all processes in the system. Practically this means that those mappings has to be static once created during boot time. That's why when no CMA is selected, the whole dma_alloc_coherent() allocations are limited to rather small region, which is already remapped as non-cached during boot. This is a serious limitation, that's why some other approach was needed and it turned out that CMA can resolve that issue too. CMA limits the DMA allocations to the specific memory regions, thus each such region (part of the kernel's direct map) CAN be easily remapped during boot time with standard 4K pages and then altered/updated on-demand when coherent allocation is performed. This slightly lowers the performance of the memory related operation on that region (access to 4K pages is a bit slower compared to the memory mapped with sections), but CMA is mainly used on the newer ARMv7 systems which often have a decent cache, which mitigates such performance drop. > Then attack the CMA direct mapping: > > - modify the core DMA mapping code so that the > ARCH_HAS_DMA_SET_UNCACHED code is only used conditionally > I'm not quite sure what the right checks and right place is, > but the intent is that it should allow arm to only use that > path for CMA allocations. For all existing users of > CONFIG_ARCH_HAS_DMA_SET_UNCACHED it should evaluate to > a compile-time true to not change the behavior or code > generation > - then in arm select ARCH_HAS_DMA_SET_UNCACHED and implement > arch_dma_set_uncached, arch_dma_clear_uncached and the new > helper above The plan for the CMA related case sounds good. If you need any ARM related tests, let me know. I have a bunch of ARM based test machines, which I use for the tests of the linux-next on the day-to-day basis. Best regards -- Marek Szyprowski, PhD Samsung R&D Institute Poland