Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp2480067pxk; Mon, 14 Sep 2020 14:47:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxXJZDPP5F6gC/hS2cTdc1EsPZbTUyhIetSGxA6dfoTsqDDEWnBRj0wCyVW2cuxRArr2RQi X-Received: by 2002:aa7:cb05:: with SMTP id s5mr19029795edt.212.1600120024317; Mon, 14 Sep 2020 14:47:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600120024; cv=none; d=google.com; s=arc-20160816; b=FP/KWmoxrGksW9a3cyYCNK3ZO7iLkDRz5NSbFBejWb09XqYanMiphIGr98Qkk71dNS gJbWpweQD9wLFDGlhnPBsQBT8ZYVoxWWlvTRb1Yet3Crsbiv53xyBPX1BxmRy5Ip5HZc 1IQdj7AGsYGfUlBzgioECpskfekvm3E1p5rf/ieJpsO7thbRL5PAJnzeS+9xvlFZoiDX 8PRFa2SxY1JsFpK6PjK9CAofAFqr5ybTcV25R4DinTYQpKRfM5D6Eg50xT+nhvuagb9K J9KnRxEejE+60fvvk9fSMj23sOxUOw4u4gMJ6NHFSTMzbYDVClJ40YrLsxex5gCyvW1x TITg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=SLwWWkWYloCCIXMZGzZbZUI4mujYjYejt5GlWh0KFuM=; b=dcdGpOeUC9G6S38vjhMHjd8l52vQIpU/qoPwhv9xZK0aWPBUiPmSgdEaNGtsH5gmwr eF6B+EBrG/zv8vzO0EsUANCWSyVNSGwmOC4te22qdSZaXQSiYg0PyPlrRPXYJj40Uy+t I/VouX2DN7maKyNuIne5/XDB0083ZevT+iN2TsdTtrtv++E78g0bgvLBu0x1/4Bs5OtS EnxPLALpvhy8XInP1E3Arzvr3/FHHg1hFc/5sLgziUQAJbXtXhxiFo5UviQME3B7vRFI PZOwZf0eeHr5ft2ksnaaZ0DCdnZGRfNVcj493jvBuK61nUzuO54//OAqu8bK/WJ5upmm BWLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2l8Ws3d8; 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 r11si7972190ejs.214.2020.09.14.14.46.41; Mon, 14 Sep 2020 14:47:04 -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=default header.b=2l8Ws3d8; 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 S1726253AbgINVpi (ORCPT + 99 others); Mon, 14 Sep 2020 17:45:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:44784 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726228AbgINVp0 (ORCPT ); Mon, 14 Sep 2020 17:45:26 -0400 Received: from kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com (unknown [163.114.132.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id EAB2C208DB; Mon, 14 Sep 2020 21:45:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600119925; bh=MrKDcm4QhfS4JW43IvNQBg7V7LnF4erm6voWMCdgFxA=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=2l8Ws3d83rQUjHn8OWu7OLJJ9jrIvf/33FT9bhBB937ks0x1wrhlqmPy8Y+fpCbHZ PTrSYaHfIZ+R89c4huMs3KO6KnGNWhjr+79O0DvdGWhwAq6I75hNRVD1b7IZAbrlLX Ikr/yBUEVfESQZPk/B4Lf+O2tsLmwfMyjx4jTmQc= Date: Mon, 14 Sep 2020 14:45:22 -0700 From: Jakub Kicinski To: Huazhong Tan Cc: , , , , , , Yunsheng Lin Subject: Re: [PATCH net-next 5/6] net: hns3: use writel() to optimize the barrier operation Message-ID: <20200914144522.02d469a8@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com> In-Reply-To: <1600085217-26245-6-git-send-email-tanhuazhong@huawei.com> References: <1600085217-26245-1-git-send-email-tanhuazhong@huawei.com> <1600085217-26245-6-git-send-email-tanhuazhong@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 14 Sep 2020 20:06:56 +0800 Huazhong Tan wrote: > From: Yunsheng Lin > > writel() can be used to order I/O vs memory by default when > writing portable drivers. Use writel() to replace wmb() + > writel_relaxed(), and writel() is dma_wmb() + writel_relaxed() > for ARM64, so there is an optimization here because dma_wmb() > is a lighter barrier than wmb(). Cool, although lots of drivers will need a change like this now. And looks like memory-barriers.txt is slightly, eh, not coherent there, between the documentation of writeX() and dma_wmb() :S 3. A writeX() by a CPU thread to the peripheral will first wait for the completion of all prior writes to memory either issued by, or propagated to, the same thread. This ensures that writes by the CPU to an outbound DMA buffer allocated by dma_alloc_coherent() will be visible to a DMA engine when the CPU writes to its MMIO control register to trigger the transfer. (*) dma_wmb(); (*) dma_rmb(); These are for use with consistent memory to guarantee the ordering of writes or reads of shared memory accessible to both the CPU and a DMA capable device. For example, consider a device driver that shares memory with a device and uses a descriptor status value to indicate if the descriptor belongs to the device or the CPU, and a doorbell to notify it when new descriptors are available: if (desc->status != DEVICE_OWN) { /* do not read data until we own descriptor */ dma_rmb(); /* read/modify data */ read_data = desc->data; desc->data = write_data; /* flush modifications before status update */ dma_wmb(); /* assign ownership */ desc->status = DEVICE_OWN; /* notify device of new descriptors */ writel(DESC_NOTIFY, doorbell); } The dma_rmb() allows us guarantee the device has released ownership before we read the data from the descriptor, and the dma_wmb() allows us to guarantee the data is written to the descriptor before the device can see it now has ownership. Note that, when using writel(), a prior wmb() is not needed to guarantee that the cache coherent memory writes have completed before writing to the MMIO region. The cheaper writel_relaxed() does not provide this guarantee and must not be used here.