Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp2531261pxt; Mon, 9 Aug 2021 02:48:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxTLExAL7pKLVJ0LeWqV2UJXEJyEdLSkqk3ZZ0Gnu8KRqQHPfaPFPMiP65BwWrwpDoLVqwD X-Received: by 2002:aa7:c795:: with SMTP id n21mr28605320eds.182.1628502510287; Mon, 09 Aug 2021 02:48:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628502510; cv=none; d=google.com; s=arc-20160816; b=srnyyjM9q13Ap7/JhVTzwrHBHRwDI82HVFJ6WBvIenyBclb3n+32+8aEgphyH1LljQ 6TorICjEo6Vo0oZgW1n6ynDgNnCRBk0tv8fejuhupzrlbJqiW3kckr8/D+s+BdJP/klG LYo8xklFuP74O1XSCuPr4lm74v3jPQjhNY5NY6m18F7vjbAdTCxZMzyHhOhQqHx5LhdF WTm5v6w0irjAnPaqhx3I/Cc1z4fSGzXLGI5CqXLcLhpxEQJTi5855viQ0kvRyfhd9rEb AyWbpySnvBQkmlRqWFo+xBCySzkqcEQccl5DpvCh7jQ/KRcLPQH9QoojZqd1VXY5/ZXK XaJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:references:cc:to :subject; bh=d5Pdop/dEaR6ginYgR1xKTmWh7fJ5rQgaCxcv9ixTyk=; b=s5wQS83qxH3cymnqfz59hq/u5//Zqg1Cl6UZVFl6lLbCBbKWg8m9M+HjxOBV8cMvYe ch550EP7ZLAeVkxpqO712DkfzIQjCn8ogtLZ0cdD9kCtBc4wEjeNO88T7jbvWjd2Tm3t zOUjaYuoKd0swNuIwZtr2+SDfLSWYI3jEIUWo+lpKoKreP5mXHs3pfXTQDRnQF8Yarph +XxR9DbZwcDtg2bkt6IC2D5nuGTtNgVy20y83gCawCmzaV3a2j4CiVXrkMqJXouGKrMh oWn6pP/Ro6m5d+NB1Dfb5JCm/g4qbW4ppMMGGkdKPigsyeNZe1bBSaGMUjlfacV/JayZ jXVQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l1si9077330ejo.68.2021.08.09.02.48.05; Mon, 09 Aug 2021 02:48:30 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233212AbhHIGU2 (ORCPT + 99 others); Mon, 9 Aug 2021 02:20:28 -0400 Received: from out30-131.freemail.mail.aliyun.com ([115.124.30.131]:37294 "EHLO out30-131.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233210AbhHIGU2 (ORCPT ); Mon, 9 Aug 2021 02:20:28 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R471e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04423;MF=xianting.tian@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0UiMSubG_1628490005; Received: from B-LB6YLVDL-0141.local(mailfrom:xianting.tian@linux.alibaba.com fp:SMTPD_---0UiMSubG_1628490005) by smtp.aliyun-inc.com(127.0.0.1); Mon, 09 Aug 2021 14:20:05 +0800 Subject: Re: [PATCH] riscv: add ARCH_DMA_MINALIGN support To: Jisheng Zhang Cc: paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org References: <20210807145537.124744-1-xianting.tian@linux.alibaba.com> <20210809003044.6692ddce@xhacker> From: Xianting TIan Message-ID: Date: Mon, 9 Aug 2021 14:20:05 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: <20210809003044.6692ddce@xhacker> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 在 2021/8/9 上午12:30, Jisheng Zhang 写道: > On Sat, 7 Aug 2021 22:55:37 +0800 > Xianting Tian wrote: > >> Introduce ARCH_DMA_MINALIGN to riscv arch. >> >> Signed-off-by: Xianting Tian >> --- >> arch/riscv/include/asm/cache.h | 2 ++ >> 1 file changed, 2 insertions(+) >> >> diff --git a/arch/riscv/include/asm/cache.h b/arch/riscv/include/asm/cache.h >> index 9b58b1045..2945bbe2b 100644 >> --- a/arch/riscv/include/asm/cache.h >> +++ b/arch/riscv/include/asm/cache.h >> @@ -11,6 +11,8 @@ >> >> #define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT) >> >> +#define ARCH_DMA_MINALIGN L1_CACHE_BYTES > It's not a good idea to blindly set this for all riscv. For "coherent" > platforms, this is not necessary and will waste memory. I checked ARCH_DMA_MINALIGN definition,  "If an architecture isn't fully DMA-coherent, ARCH_DMA_MINALIGN must be set". so that the memory allocator makes sure that kmalloc'ed buffer doesn't share a cache line with the others. Documentation/core-api/dma-api-howto.rst 2) ARCH_DMA_MINALIGN    Architectures must ensure that kmalloc'ed buffer is    DMA-safe. Drivers and subsystems depend on it. If an architecture    isn't fully DMA-coherent (i.e. hardware doesn't ensure that data in    the CPU cache is identical to data in main memory),    ARCH_DMA_MINALIGN must be set so that the memory allocator    makes sure that kmalloc'ed buffer doesn't share a cache line with    the others. See arch/arm/include/asm/cache.h as an example.    Note that ARCH_DMA_MINALIGN is about DMA memory alignment    constraints. You don't need to worry about the architecture data    alignment constraints (e.g. the alignment constraints about 64-bit    objects). > >> + >> /* >> * RISC-V requires the stack pointer to be 16-byte aligned, so ensure that >> * the flat loader aligns it accordingly.