From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7EA51378D9B for ; Fri, 29 May 2026 11:20:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780053628; cv=none; b=CmyOzno9KbZ9yV5VFPJQEVO4OQEtU5rxcx4zqrtZ/diBTDbKf0wcLBqLMhoDNl3Sna2hLPyb6J6nh/G5K8sKdUDZ5SpxFRH3/ejpDC2eaYvsVj6KAIZf88+J+/Er/J63ictzicA6fvDtU0mHKivdq1RbzSQfZBWdT17u3LbNGVw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780053628; c=relaxed/simple; bh=pd32XOCS7yV5a9RhUSykxcYh8xaJJjXibHtl2zqWdHA=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=bv3zRoZ0PMku/V+7OZFyaWC2WS+IzB6XOB/SoBYs9PidKZWXXkgO/yVCcDfsgUYKOqTMnVzgLesxzk1v0qqkx/C1tbhM/1wboPP8RH/ZznyJX0o8ORBJ0KEUUAJgZPCSvRtnL01CLyegrDRBnsmtUHyODxGP1cEroXtkILKtxEI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=q8DVz5W5; arc=none smtp.client-ip=209.85.128.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="q8DVz5W5" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-48984d29fe3so144007915e9.0 for ; Fri, 29 May 2026 04:20:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1780053625; x=1780658425; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=mRQnl4cL1WBl6UH6DzyzccF/izxjjWzeBGgbQMxLsH4=; b=q8DVz5W5d7DRvIpVlwz0JxelhelTwuDSjKuMjztDr0m4rhaDAdap+7Bmwlwc7X2qPn cFSQUqMWBzaNGVV5cToPLfzXMZBwYJIzGEXJMZ+00upyPjdhiFf2+njDt4NouUBzHJec IHM9quopiOWKyiPXEu4fQuTgRTNhAdfSt3xe9dbhmQAgE/sYPL+ghdz2ScQqUByz7QBz OnGXfZMr8Z+/zoz2GakZgd92vHZekP+yby3+S4b4KnFI0dS/Wqkdj7q8LtXKY/Vegb2s aByE1SMcQhKHb1lZvKOU/MlwNAOpSeVpniw5+f1K85xXpBGRg+BdGWEbyWLbvxP/UFQe Pb7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780053625; x=1780658425; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=mRQnl4cL1WBl6UH6DzyzccF/izxjjWzeBGgbQMxLsH4=; b=tYW9TU0gX7oEtF7o+86/D9dik7pqMu9XQILTO7AmAd02jxvnheX3ZfDGOa+qf7bkvJ l9dwUnI1JrwwaJYuKsC6nztuIB5YoP4Fgif3sbKQfGPMclmFPuuN+O5aasAvEexdZVOa zWZo47UWftaM1Qubm8R+jTNL07BinNjw7pJ6Bn1TNUw35RF2EL4NQAWWgrR7hEn6zCLd /XW2vTK0MA/sXBbeAdUuQb1igNoIhUWeN0/PtxeRqqzjofkUHZgNYzlCuHTw5weSeC0T kMql/pst+3dUbr5XtA8ekSavTNucOpe/OrmDj5cNBjGV4BuECpxpdsLxADraVHhojwD5 Nsfw== X-Gm-Message-State: AOJu0YzJEhBuF1UNPK6cQHGYoXYx09CbfGNhuS0TrZK2ViZLiPb+dItr F/lsDBibXuGp3csvcfVNM2uoupckkcqSLIC5BY9Fc3Rnw1zCajTBcNCF5QGLGkjCPo48zCzYRqN OW70mVyRmMQ== X-Gm-Gg: Acq92OHwrFec43+IrFxPHSc6LxwtkgvSjQwrdQQonqWcdpQ4heiOxBqpWbcEs2lso2f l/kkePwG/xBaeZQ46qWNYfTF2yGIptchfnbWdyfisY90a+u2bGg8S/E9s3Ry0kw32kaILCjViqJ a4dzLfSrmInQqZ4nktVR9Eb3PEJ5yaUi3M1Zb3j8lRZyUNvqynUZq1KGHK0yeqzCt+GGVqVYhLg Oi/2FApDlzcXFvmHT1pccA351M/uoCk1p0tWKYNBzQeTVrMfrwYWdbpyPhRm9gQM7J5aaEGruH5 aP3zUYmfcuNdQYT3foLHfizxyPb67/AnplynTEMDf2gMiIzX/agB11bS7GWlVAqQa03v+bsqRdX c2ctB1QrTNdtA/RDvIuaYFVLjZueifJtX6pgAr2lTW8XqkjmTJjuVvanXY0nIQdKjBo/XO4qyKM liQWsU8YzZG7ObK0cuvqo1ETqj4b8RwCcQ6Zd1bKJjww== X-Received: by 2002:a05:600c:560d:b0:490:4ee0:82f9 with SMTP id 5b1f17b1804b1-4909c0920c0mr32909035e9.7.1780053624779; Fri, 29 May 2026 04:20:24 -0700 (PDT) Received: from [10.11.12.110] ([82.76.215.73]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-45ef34c50f6sm3257061f8f.16.2026.05.29.04.20.23 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 29 May 2026 04:20:24 -0700 (PDT) Message-ID: Date: Fri, 29 May 2026 14:20:22 +0300 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v5 4/7] firmware: samsung: acpm: Add memory barrier before advancing RX pointer To: Arnd Bergmann , Krzysztof Kozlowski , Alim Akhtar Cc: linux-kernel@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Peter Griffin , =?UTF-8?Q?Andr=C3=A9_Draszik?= , jyescas@google.com, kernel-team@android.com, stable@vger.kernel.org References: <20260505-acpm-fixes-sashiko-reports-v5-0-43b5ee7f1674@linaro.org> <20260505-acpm-fixes-sashiko-reports-v5-4-43b5ee7f1674@linaro.org> <26e9c700-c519-4888-8739-c48c73b8a39f@app.fastmail.com> Content-Language: en-US From: Tudor Ambarus In-Reply-To: <26e9c700-c519-4888-8739-c48c73b8a39f@app.fastmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 5/29/26 11:25 AM, Arnd Bergmann wrote: > On Fri, May 29, 2026, at 09:47, Krzysztof Kozlowski wrote: >> On 28/05/2026 19:44, Arnd Bergmann wrote: >>> On Tue, May 5, 2026, at 15:13, Tudor Ambarus wrote: >>>> Sashiko identified a silent data corruption in [1]. >>>> >>>> In acpm_get_rx(), the driver reads the response payload from SRAM using >>>> __ioread32_copy() and subsequently updates the hardware RX rear pointer >>>> via writel(). >>>> >>>> On weakly ordered architectures like ARM64, writel() provides a write >>>> memory barrier (wmb()), which strictly orders prior writes against >>>> subsequent writes. However, it does not order prior reads against >>>> subsequent writes. Consequently, the CPU is permitted to reorder the >>>> writel() store to become globally visible before the payload reads >>>> have completed. >>> >>> I am very confused by this after seeing it in the Exynos fixes pull >>> request. How would anything get reordered here? What I see is that >>> >>> - The SRAM is device memory, so any access to it is architecturally >>> ordered against other accesses to the same device. Even on >>> architectures that don't guarantee this, Linux I/O accessors >>> do. >> >> Well, __ioread32_copy does not guarantee that, I think. That's the >> relaxed version. > > __ioread32_copy() certainly does not guarantee the ordering within > the block, and I think you are right that we don't properly document > the ordering between a __raw_readl() and following writel(), but > as far as I can tell all implementations do provide strict > ordering here because either the MMIO load/store instructions are > architecturally ordered (x86, arm64, ...) or there are sufficient > barriers in the writel() to serialize the __raw_readl() as well > (mips, alpha, ...). > > [side note: there is a difference between __raw_readl() and > readl_relaxed() here. The _relaxed MMIO operations are required > to to be serialized with each other but not against memory > accesses, while the __raw_ version used here provides neither > guarantee] > >>> after the read (because of the data dependency). >> >> I don't see the data dependency regarding the write. We read 'rx_front' >> and 'i' in the loop. The 'i' is used for subsequent read (addr = base + >> mlen*i) and that's dependency, but that 'addr' is not used in any >> further writes. > > What I meant is that the store into the target memory buffer > (xfer->rxd or rx_data->cmd) depends on the data being read from > MMIO first. The writel() guarantees that this buffer is visible > to all DMA masters in the system and that can only happen when > the __raw_readl() has provided the data first. > Thanks both for the detailed explanations. I missed the data dependency chain. I focused too much on the read part in __ioread32_copy() that I missed the RAM store implications in it. The RAM store is forced to wait for its SRAM load, and the writel is forced to wait for all the RAM stores. So the entire payload is guaranteed to be visible in memory RAM before the writel. Maybe I thought about the reordering of the final __raw_readl() loop iteration with the writel(). But the dma_wmb() -> __dma_wmb() -> dmb(oshst) from writel has a compiler barrier, so the compiler can't reorder the code. And given the ARM64 device memory accesses ordering, the ordering is protected. My bad, sorry. We shall either drop or revert the patch. Please let me know if you prefer a revert. Thanks, ta