Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp969160pxb; Wed, 15 Sep 2021 18:21:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxkwzQuEiolvn6ATV7uQ3PFCig6uiQmoi9J8gLISVXURvoJzDSK8UNKYtIl02xUuX68LPP+ X-Received: by 2002:a5d:9e49:: with SMTP id i9mr2261781ioi.125.1631755297965; Wed, 15 Sep 2021 18:21:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631755297; cv=none; d=google.com; s=arc-20160816; b=w2Oa39fREtO5HYdCfvgMBJGaf7iuttIc2p4iAgdrKEL62iPhoPoI2+RkAJwIQ8eSie RxMZQ3oFfjJHEaFjhfC6Htw1tSiyoKJM6Usx0Mo0fGLgCtYn6WOeDJOjcdBG3OQFy10i AbFq25Mr4p8eM9XcwyMj6Js1PfKZdjieE2yXpDuoDL3c2YSRaBe1Tcto3RyXzrYXijom IpDZJBuy5ohXSJBSl69n/UeRcNwG1FPvLeJPT7SI9B7on5GtEHupBskUQVI9PKBlLH+z ZdKf9J3WC6Y9NBYhRQs7L5Xo0J22DUeEPoueP8/Ih2egbfA6JCS75oXhLias+Unp6dPv YDOQ== 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=98g8lms2DPedueMMUyMFLEhxBMdotnHHDVij30AsJmY=; b=U13u7Qu/wNZokg25t9c3Ly9IShP9sNYClBrat7X42CBOiOL9+svdE+f2TTT1wzuhil dJ1X5qCo6mpiXslhgTMqUWGqhE6u0Km7eEGa8BVxY1IJvpNWyWaGJflNDBXRnsxKJepv z7dbq3lRrx2URAoE+wU99suRdO7DmB3dRaI2LtFKCPa7qmLUf21nXshpFsFcp2+RANqp udkGfhbkb2vKiGTgC4gjHWltniQlVlBcfJ3GQOIc9zRShC8YXQYvqEHqv5+ECFYXsxTz QVte9lG6WWadHilf06FoZZ7p5dZ9Q5DtQU6EHze8wH0waVpomjrnEwim4cnjwOpSddV+ Lmog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=aCA9nZNV; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y7si1079835ilb.100.2021.09.15.18.21.26; Wed, 15 Sep 2021 18:21:37 -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=@kernel.org header.s=k20201202 header.b=aCA9nZNV; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231883AbhIPBWG (ORCPT + 99 others); Wed, 15 Sep 2021 21:22:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:39932 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229816AbhIPBWF (ORCPT ); Wed, 15 Sep 2021 21:22:05 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6F3F060F93 for ; Thu, 16 Sep 2021 01:20:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1631755245; bh=N8vdbjyf2kqAOWnVrEA55RFKSMKRgVPo8mZ596qmFTs=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=aCA9nZNVQ69O0f+yv/wo3D1I0gnuAseS7SrmlT9uFmDp4Vas95th0CZqUCQCAYsoE CTd8jk1mSUAARkLeGoMMgxyqSN4DA8ebpmteW2PCI4pP6tdzd+V9YOgT4gaMl5Se1w /bKTV5NcKG2KpZfaAhHXJFTOtRBXSp/b7l1+ex6yQx2o3pRZwoasJEoNUxQuWUszIG mD5fJXz/5k+d/4OBT3u4VtlURFEm9AyBHo62jCl1MmR//eLZ1BMAAw/mF0aMF6V2AJ m56ZvQQ56apZjYrr9k0frhQpss7qtRIJp+2wGN19n/Ntr2hMkR5v+cipoJLJT0rUBF WMRkU+MT1czyw== Received: by mail-lf1-f43.google.com with SMTP id y28so11874617lfb.0 for ; Wed, 15 Sep 2021 18:20:45 -0700 (PDT) X-Gm-Message-State: AOAM533nf6PqwqdjbskEBLQJWIarMynMtOp32PjAC/81XPiCCPkqcZkx uzc1vJe/grm9E5nWoInHZkv3jbYk6aBsoI5/yFo= X-Received: by 2002:a05:651c:1548:: with SMTP id y8mr2571362ljp.507.1631755243805; Wed, 15 Sep 2021 18:20:43 -0700 (PDT) MIME-Version: 1.0 References: <20210911092139.79607-1-guoren@kernel.org> <20210911092139.79607-4-guoren@kernel.org> <20210915074827.GC20024@lst.de> In-Reply-To: <20210915074827.GC20024@lst.de> From: Guo Ren Date: Thu, 16 Sep 2021 09:20:32 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC PATCH V4 3/6] RISC-V: Support a new config option for non-coherent DMA To: Christoph Hellwig Cc: Anup Patel , Atish Patra , Palmer Dabbelt , =?UTF-8?Q?Christoph_M=C3=BCllner?= , Philipp Tomsich , liush , wefu@redhat.com, =?UTF-8?B?V2VpIFd1ICjlkLTkvJ8p?= , Drew Fustini , linux-riscv , Linux Kernel Mailing List , taiten.peng@canonical.com, aniket.ponkshe@canonical.com, heinrich.schuchardt@canonical.com, gordan.markus@canonical.com, Guo Ren Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Sep 15, 2021 at 3:48 PM Christoph Hellwig wrote: > > On Sat, Sep 11, 2021 at 05:21:36PM +0800, guoren@kernel.org wrote: > > + select DMA_GLOBAL_POOL > > + select DMA_DIRECT_REMAP > > No need to select DMA_GLOBAL_POOL when DMA_DIRECT_REMAP is select. If we want to support PBMT & global_dma_pool both in riscv. Could they work together in arch/riscv with [1]? [1]: https://lore.kernel.org/lkml/20210818142715.GA10755@lst.de/T/ > > Also a patch just to add a option that is not selected and won't build > if selected does not make sense. I just want to rebase on Atish's patch and append DMA_DIRECT_REMAP. Okay, DMA_DIRECT_REMAP & DMA_GLOBAL_POOL should be separated from the patch. --- a/kernel/dma/direct.c +++ b/kernel/dma/direct.c @@ -156,9 +156,14 @@ void *dma_direct_alloc(struct device *dev, size_t size, if (!IS_ENABLED(CONFIG_ARCH_HAS_DMA_SET_UNCACHED) && !IS_ENABLED(CONFIG_DMA_DIRECT_REMAP) && + !IS_ENABLED(CONFIG_DMA_GLOBAL_POOL) && !dev_is_dma_coherent(dev)) return arch_dma_alloc(dev, size, dma_handle, gfp, attrs); + if (IS_ENABLED(CONFIG_DMA_GLOBAL_POOL) && + !dev_is_dma_coherent(dev)) + return dma_alloc_from_global_coherent(dev, size, dma_handle); + /* * Remapping or decrypting memory may block. If either is required and * we can't block, allocate the memory from the atomic pools. @@ -255,11 +260,19 @@ void dma_direct_free(struct device *dev, size_t size, if (!IS_ENABLED(CONFIG_ARCH_HAS_DMA_SET_UNCACHED) && !IS_ENABLED(CONFIG_DMA_DIRECT_REMAP) && + !IS_ENABLED(CONFIG_DMA_GLOBAL_POOL) && !dev_is_dma_coherent(dev)) { arch_dma_free(dev, size, cpu_addr, dma_addr, attrs); return; } + if (IS_ENABLED(CONFIG_DMA_GLOBAL_POOL) && + !dev_is_dma_coherent(dev)) { + if (!dma_release_from_global_coherent(page_order, cpu_addr)) + WARN_ON_ONCE(1); + return; + } + Here CONFIG_DMA_GLOBAL_POOL is independent from CONFIG_DMA_DIRECT_REMAP. /* If cpu_addr is not from an atomic pool, dma_free_from_pool() fails */ if (IS_ENABLED(CONFIG_DMA_COHERENT_POOL) && dma_free_from_pool(dev, cpu_addr, PAGE_ALIGN(size))) -- Best Regards Guo Ren ML: https://lore.kernel.org/linux-csky/